blob: 88f0e2ed86b0d5acbe54627abadbcc2a2b2cf05e [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';
Jouni Malinen0572a742020-10-08 13:53:25 +03002506 pos = strchr(buf, '\r');
2507 if (pos)
2508 *pos = '\0';
Jouni Malinen53264f62019-05-03 13:04:40 +03002509 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2510 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2511 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002512
2513 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2514 if (file_exists(buf)) {
2515 sigma_dut_print(dut, DUT_MSG_DEBUG,
2516 "TOD policy enabled for the configured ServerCert hash");
2517 dut->sta_tod_policy = 1;
2518 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002519 }
2520
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002521 if (domain &&
2522 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002523 return ERROR_SEND_STATUS;
2524
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002525 if (domain_suffix &&
2526 set_network_quoted(ifname, id, "domain_suffix_match",
2527 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002528 return ERROR_SEND_STATUS;
2529
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302530 if (username_identity) {
2531 val = get_param(cmd, "username");
2532 if (val) {
2533 if (set_network_quoted(ifname, id, "identity", val) < 0)
2534 return -2;
2535 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002536
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302537 val = get_param(cmd, "password");
2538 if (val) {
2539 if (set_network_quoted(ifname, id, "password", val) < 0)
2540 return -2;
2541 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002542 }
2543
Jouni Malinen8179fee2019-03-28 03:19:47 +02002544 if (dut->akm_values &
2545 ((1 << AKM_FILS_SHA256) |
2546 (1 << AKM_FILS_SHA384) |
2547 (1 << AKM_FT_FILS_SHA256) |
2548 (1 << AKM_FT_FILS_SHA384)))
2549 erp = 1;
2550 if (erp && set_network(ifname, id, "erp", "1") < 0)
2551 return ERROR_SEND_STATUS;
2552
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002553 dut->sta_associate_wait_connect = 1;
2554
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002555 return id;
2556}
2557
2558
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002559static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2560{
2561 const char *val;
2562
2563 if (!cipher)
2564 return 0;
2565
2566 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2567 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2568 else if (strcasecmp(cipher,
2569 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2570 val = "ECDHE-RSA-AES256-GCM-SHA384";
2571 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2572 val = "DHE-RSA-AES256-GCM-SHA384";
2573 else if (strcasecmp(cipher,
2574 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2575 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2576 else
2577 return -1;
2578
2579 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2580 set_network_quoted(ifname, id, "phase1", "");
2581
2582 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2583}
2584
2585
Jouni Malinenf7222712019-06-13 01:50:21 +03002586static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2587 struct sigma_conn *conn,
2588 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002589{
2590 const char *intf = get_param(cmd, "Interface");
2591 const char *ifname, *val;
2592 int id;
2593 char buf[200];
2594#ifdef ANDROID
2595 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2596 int length;
2597 int jb_or_newer = 0;
2598 char prop[PROPERTY_VALUE_MAX];
2599#endif /* ANDROID */
2600
2601 if (intf == NULL)
2602 return -1;
2603
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002604 if (strcmp(intf, get_main_ifname(dut)) == 0)
2605 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002606 else
2607 ifname = intf;
2608
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302609 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002610 if (id < 0)
2611 return id;
2612
2613 if (set_network(ifname, id, "eap", "TLS") < 0)
2614 return -2;
2615
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302616 if (!get_param(cmd, "username") &&
2617 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002618 "wifi-user@wifilabs.local") < 0)
2619 return -2;
2620
2621 val = get_param(cmd, "clientCertificate");
2622 if (val == NULL)
2623 return -1;
2624#ifdef ANDROID
2625 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2626 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2627 if (length < 0) {
2628 /*
2629 * JB started reporting keystore type mismatches, so retry with
2630 * the GET_PUBKEY command if the generic GET fails.
2631 */
2632 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2633 buf, kvalue);
2634 }
2635
2636 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2637 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2638 if (strncmp(prop, "4.0", 3) != 0)
2639 jb_or_newer = 1;
2640 } else
2641 jb_or_newer = 1; /* assume newer */
2642
2643 if (jb_or_newer && length > 0) {
2644 sigma_dut_print(dut, DUT_MSG_INFO,
2645 "Use Android keystore [%s]", buf);
2646 if (set_network(ifname, id, "engine", "1") < 0)
2647 return -2;
2648 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2649 return -2;
2650 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2651 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2652 return -2;
2653 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2654 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2655 return -2;
2656 return 1;
2657 } else if (length > 0) {
2658 sigma_dut_print(dut, DUT_MSG_INFO,
2659 "Use Android keystore [%s]", buf);
2660 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2661 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2662 return -2;
2663 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2664 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2665 return -2;
2666 return 1;
2667 }
2668#endif /* ANDROID */
2669
2670 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2671#ifdef __linux__
2672 if (!file_exists(buf)) {
2673 char msg[300];
2674 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2675 "(%s) not found", buf);
2676 send_resp(dut, conn, SIGMA_ERROR, msg);
2677 return -3;
2678 }
2679#endif /* __linux__ */
2680 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2681 return -2;
2682 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2683 return -2;
2684
2685 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2686 return -2;
2687
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002688 val = get_param(cmd, "keyMgmtType");
2689 if (val && strcasecmp(val, "SuiteB") == 0) {
2690 val = get_param(cmd, "CertType");
2691 if (val && strcasecmp(val, "RSA") == 0) {
2692 if (set_network_quoted(ifname, id, "phase1",
2693 "tls_suiteb=1") < 0)
2694 return -2;
2695 } else {
2696 if (set_network_quoted(ifname, id, "openssl_ciphers",
2697 "SUITEB192") < 0)
2698 return -2;
2699 }
2700
2701 val = get_param(cmd, "TLSCipher");
2702 if (set_tls_cipher(ifname, id, val) < 0) {
2703 send_resp(dut, conn, SIGMA_ERROR,
2704 "ErrorCode,Unsupported TLSCipher value");
2705 return -3;
2706 }
2707 }
2708
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002709 return 1;
2710}
2711
2712
Jouni Malinenf7222712019-06-13 01:50:21 +03002713static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2714 struct sigma_conn *conn,
2715 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002716{
2717 const char *intf = get_param(cmd, "Interface");
2718 const char *ifname;
2719 int id;
2720
2721 if (intf == NULL)
2722 return -1;
2723
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002724 if (strcmp(intf, get_main_ifname(dut)) == 0)
2725 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002726 else
2727 ifname = intf;
2728
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302729 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002730 if (id < 0)
2731 return id;
2732
2733 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2734 send_resp(dut, conn, SIGMA_ERROR,
2735 "errorCode,Failed to set TTLS method");
2736 return 0;
2737 }
2738
2739 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2740 send_resp(dut, conn, SIGMA_ERROR,
2741 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2742 return 0;
2743 }
2744
2745 return 1;
2746}
2747
2748
Jouni Malinenf7222712019-06-13 01:50:21 +03002749static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2750 struct sigma_conn *conn,
2751 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002752{
2753 const char *intf = get_param(cmd, "Interface");
2754 const char *ifname;
2755 int id;
2756
2757 if (intf == NULL)
2758 return -1;
2759
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002760 if (strcmp(intf, get_main_ifname(dut)) == 0)
2761 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002762 else
2763 ifname = intf;
2764
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302765 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002766 if (id < 0)
2767 return id;
2768
2769 if (set_network(ifname, id, "eap", "SIM") < 0)
2770 return -2;
2771
2772 return 1;
2773}
2774
2775
Jouni Malinenf7222712019-06-13 01:50:21 +03002776static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2777 struct sigma_conn *conn,
2778 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779{
2780 const char *intf = get_param(cmd, "Interface");
2781 const char *ifname, *val;
2782 int id;
2783 char buf[100];
2784
2785 if (intf == NULL)
2786 return -1;
2787
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002788 if (strcmp(intf, get_main_ifname(dut)) == 0)
2789 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002790 else
2791 ifname = intf;
2792
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302793 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002794 if (id < 0)
2795 return id;
2796
2797 if (set_network(ifname, id, "eap", "PEAP") < 0)
2798 return -2;
2799
2800 val = get_param(cmd, "innerEAP");
2801 if (val) {
2802 if (strcasecmp(val, "MSCHAPv2") == 0) {
2803 if (set_network_quoted(ifname, id, "phase2",
2804 "auth=MSCHAPV2") < 0)
2805 return -2;
2806 } else if (strcasecmp(val, "GTC") == 0) {
2807 if (set_network_quoted(ifname, id, "phase2",
2808 "auth=GTC") < 0)
2809 return -2;
2810 } else
2811 return -1;
2812 }
2813
2814 val = get_param(cmd, "peapVersion");
2815 if (val) {
2816 int ver = atoi(val);
2817 if (ver < 0 || ver > 1)
2818 return -1;
2819 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2820 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2821 return -2;
2822 }
2823
2824 return 1;
2825}
2826
2827
Jouni Malinenf7222712019-06-13 01:50:21 +03002828static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2829 struct sigma_conn *conn,
2830 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002831{
2832 const char *intf = get_param(cmd, "Interface");
2833 const char *ifname, *val;
2834 int id;
2835 char buf[100];
2836
2837 if (intf == NULL)
2838 return -1;
2839
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002840 if (strcmp(intf, get_main_ifname(dut)) == 0)
2841 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002842 else
2843 ifname = intf;
2844
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302845 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002846 if (id < 0)
2847 return id;
2848
2849 if (set_network(ifname, id, "eap", "FAST") < 0)
2850 return -2;
2851
2852 val = get_param(cmd, "innerEAP");
2853 if (val) {
2854 if (strcasecmp(val, "MSCHAPV2") == 0) {
2855 if (set_network_quoted(ifname, id, "phase2",
2856 "auth=MSCHAPV2") < 0)
2857 return -2;
2858 } else if (strcasecmp(val, "GTC") == 0) {
2859 if (set_network_quoted(ifname, id, "phase2",
2860 "auth=GTC") < 0)
2861 return -2;
2862 } else
2863 return -1;
2864 }
2865
2866 val = get_param(cmd, "validateServer");
2867 if (val) {
2868 /* TODO */
2869 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2870 "validateServer=%s", val);
2871 }
2872
2873 val = get_param(cmd, "pacFile");
2874 if (val) {
2875 snprintf(buf, sizeof(buf), "blob://%s", val);
2876 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2877 return -2;
2878 }
2879
2880 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2881 0)
2882 return -2;
2883
2884 return 1;
2885}
2886
2887
Jouni Malinenf7222712019-06-13 01:50:21 +03002888static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2889 struct sigma_conn *conn,
2890 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002891{
2892 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302893 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 const char *ifname;
2895 int id;
2896
2897 if (intf == NULL)
2898 return -1;
2899
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002900 if (strcmp(intf, get_main_ifname(dut)) == 0)
2901 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002902 else
2903 ifname = intf;
2904
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302905 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002906 if (id < 0)
2907 return id;
2908
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302909 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2910 * hexadecimal).
2911 */
2912 if (username && username[0] == '6') {
2913 if (set_network(ifname, id, "eap", "AKA'") < 0)
2914 return -2;
2915 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002916 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302917 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002918
2919 return 1;
2920}
2921
2922
Jouni Malinenf7222712019-06-13 01:50:21 +03002923static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2924 struct sigma_conn *conn,
2925 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002926{
2927 const char *intf = get_param(cmd, "Interface");
2928 const char *ifname;
2929 int id;
2930
2931 if (intf == NULL)
2932 return -1;
2933
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002934 if (strcmp(intf, get_main_ifname(dut)) == 0)
2935 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002936 else
2937 ifname = intf;
2938
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302939 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002940 if (id < 0)
2941 return id;
2942
2943 if (set_network(ifname, id, "eap", "AKA'") < 0)
2944 return -2;
2945
2946 return 1;
2947}
2948
2949
2950static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2951 struct sigma_cmd *cmd)
2952{
2953 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002954 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002955 const char *ifname;
2956 int id;
2957
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002958 if (strcmp(intf, get_main_ifname(dut)) == 0)
2959 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002960 else
2961 ifname = intf;
2962
2963 id = add_network_common(dut, conn, ifname, cmd);
2964 if (id < 0)
2965 return id;
2966
2967 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2968 return -2;
2969
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002970 if (dut->program == PROGRAM_60GHZ && network_mode &&
2971 strcasecmp(network_mode, "PBSS") == 0 &&
2972 set_network(ifname, id, "pbss", "1") < 0)
2973 return -2;
2974
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002975 return 1;
2976}
2977
2978
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002979static enum sigma_cmd_result sta_set_owe(struct sigma_dut *dut,
2980 struct sigma_conn *conn,
2981 struct sigma_cmd *cmd)
Jouni Malinen47dcc952017-10-09 16:43:24 +03002982{
2983 const char *intf = get_param(cmd, "Interface");
2984 const char *ifname, *val;
2985 int id;
2986
2987 if (intf == NULL)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03002988 return INVALID_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03002989
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002990 if (strcmp(intf, get_main_ifname(dut)) == 0)
2991 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002992 else
2993 ifname = intf;
2994
2995 id = set_wpa_common(dut, conn, ifname, cmd);
2996 if (id < 0)
2997 return id;
2998
2999 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003000 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003001
Hu Wangdd5eed22020-07-16 12:18:03 +08003002 if (dut->owe_ptk_workaround &&
3003 set_network(ifname, id, "owe_ptk_workaround", "1") < 0) {
3004 sigma_dut_print(dut, DUT_MSG_ERROR,
3005 "Failed to set owe_ptk_workaround to 1");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003006 return ERROR_SEND_STATUS;
Hu Wangdd5eed22020-07-16 12:18:03 +08003007 }
3008
Jouni Malinen47dcc952017-10-09 16:43:24 +03003009 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003010 if (val && strcmp(val, "0") == 0) {
3011 if (wpa_command(ifname,
3012 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
3013 sigma_dut_print(dut, DUT_MSG_ERROR,
3014 "Failed to set OWE DH Param element override");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003015 return ERROR_SEND_STATUS;
Jouni Malinenfac9cad2017-10-10 18:35:55 +03003016 }
Hu Wangdd5eed22020-07-16 12:18:03 +08003017 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03003018 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08003019 "Failed to set owe_group");
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003020 return ERROR_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003021 }
3022
Jouni Malinen8e3f8812020-10-05 10:02:03 +03003023 return SUCCESS_SEND_STATUS;
Jouni Malinen47dcc952017-10-09 16:43:24 +03003024}
3025
3026
Jouni Malinenf7222712019-06-13 01:50:21 +03003027static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
3028 struct sigma_conn *conn,
3029 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003030{
3031 const char *type = get_param(cmd, "Type");
3032
3033 if (type == NULL) {
3034 send_resp(dut, conn, SIGMA_ERROR,
3035 "ErrorCode,Missing Type argument");
3036 return 0;
3037 }
3038
3039 if (strcasecmp(type, "OPEN") == 0)
3040 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03003041 if (strcasecmp(type, "OWE") == 0)
3042 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03003043 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03003044 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03003045 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003046 return cmd_sta_set_psk(dut, conn, cmd);
3047 if (strcasecmp(type, "EAPTLS") == 0)
3048 return cmd_sta_set_eaptls(dut, conn, cmd);
3049 if (strcasecmp(type, "EAPTTLS") == 0)
3050 return cmd_sta_set_eapttls(dut, conn, cmd);
3051 if (strcasecmp(type, "EAPPEAP") == 0)
3052 return cmd_sta_set_peap(dut, conn, cmd);
3053 if (strcasecmp(type, "EAPSIM") == 0)
3054 return cmd_sta_set_eapsim(dut, conn, cmd);
3055 if (strcasecmp(type, "EAPFAST") == 0)
3056 return cmd_sta_set_eapfast(dut, conn, cmd);
3057 if (strcasecmp(type, "EAPAKA") == 0)
3058 return cmd_sta_set_eapaka(dut, conn, cmd);
3059 if (strcasecmp(type, "EAPAKAPRIME") == 0)
3060 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08003061 if (strcasecmp(type, "wep") == 0)
3062 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003063
3064 send_resp(dut, conn, SIGMA_ERROR,
3065 "ErrorCode,Unsupported Type value");
3066 return 0;
3067}
3068
3069
3070int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
3071{
3072#ifdef __linux__
3073 /* special handling for ath6kl */
3074 char path[128], fname[128], *pos;
3075 ssize_t res;
3076 FILE *f;
3077
Jouni Malinene39cd562019-05-29 23:39:56 +03003078 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3079 intf);
3080 if (res < 0 || res >= sizeof(fname))
3081 return 0;
3082 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003083 if (res < 0)
3084 return 0; /* not ath6kl */
3085
3086 if (res >= (int) sizeof(path))
3087 res = sizeof(path) - 1;
3088 path[res] = '\0';
3089 pos = strrchr(path, '/');
3090 if (pos == NULL)
3091 pos = path;
3092 else
3093 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003094 res = snprintf(fname, sizeof(fname),
3095 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3096 "create_qos", pos);
3097 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003098 return 0; /* not ath6kl */
3099
3100 if (uapsd) {
3101 f = fopen(fname, "w");
3102 if (f == NULL)
3103 return -1;
3104
3105 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3106 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3107 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3108 "20000 0\n");
3109 fclose(f);
3110 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003111 res = snprintf(fname, sizeof(fname),
3112 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3113 "delete_qos", pos);
3114 if (res < 0 || res >= sizeof(fname))
3115 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003116
3117 f = fopen(fname, "w");
3118 if (f == NULL)
3119 return -1;
3120
3121 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3122 fprintf(f, "2 4\n");
3123 fclose(f);
3124 }
3125#endif /* __linux__ */
3126
3127 return 0;
3128}
3129
3130
Jouni Malinenf7222712019-06-13 01:50:21 +03003131static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3132 struct sigma_conn *conn,
3133 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003134{
3135 const char *intf = get_param(cmd, "Interface");
3136 /* const char *ssid = get_param(cmd, "ssid"); */
3137 const char *val;
3138 int max_sp_len = 4;
3139 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3140 char buf[100];
3141 int ret1, ret2;
3142
3143 val = get_param(cmd, "maxSPLength");
3144 if (val) {
3145 max_sp_len = atoi(val);
3146 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3147 max_sp_len != 4)
3148 return -1;
3149 }
3150
3151 val = get_param(cmd, "acBE");
3152 if (val)
3153 ac_be = atoi(val);
3154
3155 val = get_param(cmd, "acBK");
3156 if (val)
3157 ac_bk = atoi(val);
3158
3159 val = get_param(cmd, "acVI");
3160 if (val)
3161 ac_vi = atoi(val);
3162
3163 val = get_param(cmd, "acVO");
3164 if (val)
3165 ac_vo = atoi(val);
3166
3167 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3168
3169 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3170 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3171 ret1 = wpa_command(intf, buf);
3172
3173 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3174 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3175 ret2 = wpa_command(intf, buf);
3176
3177 if (ret1 && ret2) {
3178 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3179 "UAPSD parameters.");
3180 return -2;
3181 }
3182
3183 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3184 send_resp(dut, conn, SIGMA_ERROR,
3185 "ErrorCode,Failed to set ath6kl QoS parameters");
3186 return 0;
3187 }
3188
3189 return 1;
3190}
3191
3192
Jouni Malinenf7222712019-06-13 01:50:21 +03003193static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3194 struct sigma_conn *conn,
3195 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003196{
3197 char buf[1000];
3198 const char *intf = get_param(cmd, "Interface");
3199 const char *grp = get_param(cmd, "Group");
3200 const char *act = get_param(cmd, "Action");
3201 const char *tid = get_param(cmd, "Tid");
3202 const char *dir = get_param(cmd, "Direction");
3203 const char *psb = get_param(cmd, "Psb");
3204 const char *up = get_param(cmd, "Up");
3205 const char *fixed = get_param(cmd, "Fixed");
3206 const char *size = get_param(cmd, "Size");
3207 const char *msize = get_param(cmd, "Maxsize");
3208 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3209 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3210 const char *inact = get_param(cmd, "Inactivity");
3211 const char *sus = get_param(cmd, "Suspension");
3212 const char *mindr = get_param(cmd, "Mindatarate");
3213 const char *meandr = get_param(cmd, "Meandatarate");
3214 const char *peakdr = get_param(cmd, "Peakdatarate");
3215 const char *phyrate = get_param(cmd, "Phyrate");
3216 const char *burstsize = get_param(cmd, "Burstsize");
3217 const char *sba = get_param(cmd, "Sba");
3218 int direction;
3219 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003220 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003221 int fixed_int;
3222 int psb_ts;
3223
3224 if (intf == NULL || grp == NULL || act == NULL )
3225 return -1;
3226
3227 if (strcasecmp(act, "addts") == 0) {
3228 if (tid == NULL || dir == NULL || psb == NULL ||
3229 up == NULL || fixed == NULL || size == NULL)
3230 return -1;
3231
3232 /*
3233 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3234 * possible values, but WMM-AC and V-E test scripts use "UP,
3235 * "DOWN", and "BIDI".
3236 */
3237 if (strcasecmp(dir, "uplink") == 0 ||
3238 strcasecmp(dir, "up") == 0) {
3239 direction = 0;
3240 } else if (strcasecmp(dir, "downlink") == 0 ||
3241 strcasecmp(dir, "down") == 0) {
3242 direction = 1;
3243 } else if (strcasecmp(dir, "bidi") == 0) {
3244 direction = 2;
3245 } else {
3246 sigma_dut_print(dut, DUT_MSG_ERROR,
3247 "Direction %s not supported", dir);
3248 return -1;
3249 }
3250
3251 if (strcasecmp(psb, "legacy") == 0) {
3252 psb_ts = 0;
3253 } else if (strcasecmp(psb, "uapsd") == 0) {
3254 psb_ts = 1;
3255 } else {
3256 sigma_dut_print(dut, DUT_MSG_ERROR,
3257 "PSB %s not supported", psb);
3258 return -1;
3259 }
3260
3261 if (atoi(tid) < 0 || atoi(tid) > 7) {
3262 sigma_dut_print(dut, DUT_MSG_ERROR,
3263 "TID %s not supported", tid);
3264 return -1;
3265 }
3266
3267 if (strcasecmp(fixed, "true") == 0) {
3268 fixed_int = 1;
3269 } else {
3270 fixed_int = 0;
3271 }
3272
Peng Xu93319622017-10-04 17:58:16 -07003273 if (sba)
3274 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003275
3276 dut->dialog_token++;
3277 handle = 7000 + dut->dialog_token;
3278
3279 /*
3280 * size: convert to hex
3281 * maxsi: convert to hex
3282 * mindr: convert to hex
3283 * meandr: convert to hex
3284 * peakdr: convert to hex
3285 * burstsize: convert to hex
3286 * phyrate: convert to hex
3287 * sba: convert to hex with modification
3288 * minsi: convert to integer
3289 * sus: convert to integer
3290 * inact: convert to integer
3291 * maxsi: convert to integer
3292 */
3293
3294 /*
3295 * The Nominal MSDU Size field is 2 octets long and contains an
3296 * unsigned integer that specifies the nominal size, in octets,
3297 * of MSDUs belonging to the traffic under this traffic
3298 * specification and is defined in Figure 16. If the Fixed
3299 * subfield is set to 1, then the size of the MSDU is fixed and
3300 * is indicated by the Size Subfield. If the Fixed subfield is
3301 * set to 0, then the size of the MSDU might not be fixed and
3302 * the Size indicates the nominal MSDU size.
3303 *
3304 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3305 * and specifies the excess allocation of time (and bandwidth)
3306 * over and above the stated rates required to transport an MSDU
3307 * belonging to the traffic in this TSPEC. This field is
3308 * represented as an unsigned binary number with an implicit
3309 * binary point after the leftmost 3 bits. For example, an SBA
3310 * of 1.75 is represented as 0x3800. This field is included to
3311 * account for retransmissions. As such, the value of this field
3312 * must be greater than unity.
3313 */
3314
3315 snprintf(buf, sizeof(buf),
3316 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3317 " 0x%X 0x%X 0x%X"
3318 " 0x%X 0x%X 0x%X"
3319 " 0x%X %d %d %d %d"
3320 " %d %d",
3321 intf, handle, tid, direction, psb_ts, up,
3322 (unsigned int) ((fixed_int << 15) | atoi(size)),
3323 msize ? atoi(msize) : 0,
3324 mindr ? atoi(mindr) : 0,
3325 meandr ? atoi(meandr) : 0,
3326 peakdr ? atoi(peakdr) : 0,
3327 burstsize ? atoi(burstsize) : 0,
3328 phyrate ? atoi(phyrate) : 0,
3329 sba ? ((unsigned int) (((int) sba_fv << 13) |
3330 (int)((sba_fv - (int) sba_fv) *
3331 8192))) : 0,
3332 minsi ? atoi(minsi) : 0,
3333 sus ? atoi(sus) : 0,
3334 0, 0,
3335 inact ? atoi(inact) : 0,
3336 maxsi ? atoi(maxsi) : 0);
3337
3338 if (system(buf) != 0) {
3339 sigma_dut_print(dut, DUT_MSG_ERROR,
3340 "iwpriv addtspec request failed");
3341 send_resp(dut, conn, SIGMA_ERROR,
3342 "errorCode,Failed to execute addTspec command");
3343 return 0;
3344 }
3345
3346 sigma_dut_print(dut, DUT_MSG_INFO,
3347 "iwpriv addtspec request send");
3348
3349 /* Mapping handle to a TID */
3350 dut->tid_to_handle[atoi(tid)] = handle;
3351 } else if (strcasecmp(act, "delts") == 0) {
3352 if (tid == NULL)
3353 return -1;
3354
3355 if (atoi(tid) < 0 || atoi(tid) > 7) {
3356 sigma_dut_print(dut, DUT_MSG_ERROR,
3357 "TID %s not supported", tid);
3358 send_resp(dut, conn, SIGMA_ERROR,
3359 "errorCode,Unsupported TID");
3360 return 0;
3361 }
3362
3363 handle = dut->tid_to_handle[atoi(tid)];
3364
3365 if (handle < 7000 || handle > 7255) {
3366 /* Invalid handle ie no mapping for that TID */
3367 sigma_dut_print(dut, DUT_MSG_ERROR,
3368 "handle-> %d not found", handle);
3369 }
3370
3371 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3372 intf, handle);
3373
3374 if (system(buf) != 0) {
3375 sigma_dut_print(dut, DUT_MSG_ERROR,
3376 "iwpriv deltspec request failed");
3377 send_resp(dut, conn, SIGMA_ERROR,
3378 "errorCode,Failed to execute delTspec command");
3379 return 0;
3380 }
3381
3382 sigma_dut_print(dut, DUT_MSG_INFO,
3383 "iwpriv deltspec request send");
3384
3385 dut->tid_to_handle[atoi(tid)] = 0;
3386 } else {
3387 sigma_dut_print(dut, DUT_MSG_ERROR,
3388 "Action type %s not supported", act);
3389 send_resp(dut, conn, SIGMA_ERROR,
3390 "errorCode,Unsupported Action");
3391 return 0;
3392 }
3393
3394 return 1;
3395}
3396
3397
vamsi krishna52e16f92017-08-29 12:37:34 +05303398static int find_network(struct sigma_dut *dut, const char *ssid)
3399{
3400 char list[4096];
3401 char *pos;
3402
3403 sigma_dut_print(dut, DUT_MSG_DEBUG,
3404 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003405 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303406 list, sizeof(list)) < 0)
3407 return -1;
3408 pos = strstr(list, ssid);
3409 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3410 return -1;
3411
3412 while (pos > list && pos[-1] != '\n')
3413 pos--;
3414 dut->infra_network_id = atoi(pos);
3415 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3416 return 0;
3417}
3418
3419
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303420/**
3421 * enum qca_sta_helper_config_params - This helper enum defines the config
3422 * parameters which can be delivered to sta.
3423 */
3424enum qca_sta_helper_config_params {
3425 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE */
3426 STA_SET_RSNIE,
3427
3428 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC */
3429 STA_SET_LDPC,
3430
3431 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC */
3432 STA_SET_TX_STBC,
3433
3434 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC */
3435 STA_SET_RX_STBC,
3436
3437 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION */
3438 STA_SET_TX_MSDU,
3439
3440 /* For the attribute QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION */
3441 STA_SET_RX_MSDU,
3442};
3443
3444
3445static int sta_config_params(struct sigma_dut *dut, const char *intf,
3446 enum qca_sta_helper_config_params config_cmd,
3447 int value)
Sunil Dutt44595082018-02-12 19:41:45 +05303448{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303449#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05303450 struct nl_msg *msg;
3451 int ret;
3452 struct nlattr *params;
3453 int ifindex;
3454
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303455 ifindex = if_nametoindex(intf);
3456 if (ifindex == 0) {
3457 sigma_dut_print(dut, DUT_MSG_ERROR,
3458 "%s: Interface %s does not exist",
3459 __func__, intf);
3460 return -1;
3461 }
3462
Sunil Dutt44595082018-02-12 19:41:45 +05303463 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3464 NL80211_CMD_VENDOR)) ||
3465 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3466 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3467 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3468 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303469 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)))
3470 goto fail;
3471
3472 switch (config_cmd) {
3473 case STA_SET_RSNIE:
3474 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, value))
3475 goto fail;
3476 break;
3477 case STA_SET_LDPC:
3478 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_LDPC, value))
3479 goto fail;
3480 break;
3481 case STA_SET_TX_STBC:
3482 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TX_STBC, value))
3483 goto fail;
3484 break;
3485 case STA_SET_RX_STBC:
3486 if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RX_STBC, value))
3487 goto fail;
3488 break;
3489 case STA_SET_TX_MSDU:
3490 if (nla_put_u8(msg,
3491 QCA_WLAN_VENDOR_ATTR_CONFIG_TX_MSDU_AGGREGATION,
3492 value))
3493 goto fail;
3494 break;
3495 case STA_SET_RX_MSDU:
3496 if (nla_put_u8(msg,
3497 QCA_WLAN_VENDOR_ATTR_CONFIG_RX_MSDU_AGGREGATION,
3498 value))
3499 goto fail;
3500 break;
Sunil Dutt44595082018-02-12 19:41:45 +05303501 }
3502 nla_nest_end(msg, params);
3503
3504 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3505 if (ret) {
3506 sigma_dut_print(dut, DUT_MSG_ERROR,
3507 "%s: err in send_and_recv_msgs, ret=%d",
3508 __func__, ret);
3509 return ret;
3510 }
3511
3512 return 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303513
3514fail:
3515 sigma_dut_print(dut, DUT_MSG_ERROR,
3516 "%s: err in adding vendor_cmd and vendor_data",
3517 __func__);
3518 nlmsg_free(msg);
Sunil Dutt44595082018-02-12 19:41:45 +05303519#endif /* NL80211_SUPPORT */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303520 return -1;
3521}
Sunil Dutt44595082018-02-12 19:41:45 +05303522
3523
Jouni Malinenf7222712019-06-13 01:50:21 +03003524static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3525 struct sigma_conn *conn,
3526 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003527{
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303528#ifdef NL80211_SUPPORT
3529 const char *intf = get_param(cmd, "Interface");
3530#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003531 const char *ssid = get_param(cmd, "ssid");
3532 const char *wps_param = get_param(cmd, "WPS");
3533 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003534 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003535 const char *network_mode = get_param(cmd, "network_mode");
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303536 const char *ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003537 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003538 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003539 int e;
3540 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3541 struct wpa_ctrl *ctrl = NULL;
3542 int num_network_not_found = 0;
3543 int num_disconnected = 0;
3544 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003545
3546 if (ssid == NULL)
3547 return -1;
3548
Jouni Malinen37d5c692019-08-19 16:56:55 +03003549 dut->server_cert_tod = 0;
3550
Jouni Malinen3c367e82017-06-23 17:01:47 +03003551 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303552#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003553 if (get_driver_type(dut) == DRIVER_WCN) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05303554 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Sunil Dutt44595082018-02-12 19:41:45 +05303555 dut->config_rsnie = 1;
3556 }
3557#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003558 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3559 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003560 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003561 send_resp(dut, conn, SIGMA_ERROR,
3562 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3563 return 0;
3564 }
3565 }
3566
Jouni Malinen68143132017-09-02 02:34:08 +03003567 if (dut->sae_commit_override) {
3568 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3569 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003570 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003571 send_resp(dut, conn, SIGMA_ERROR,
3572 "ErrorCode,Failed to set SAE commit override");
3573 return 0;
3574 }
3575 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303576#ifdef ANDROID
3577 if (dut->fils_hlp)
3578 process_fils_hlp(dut);
3579#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003580
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003581 if (wps_param &&
3582 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3583 wps = 1;
3584
Vamsi Krishnac1633d22020-05-06 18:31:21 +05303585 if (dut->ocvc &&
3586 set_network(get_station_ifname(dut), dut->infra_network_id,
3587 "ocv", "1") < 0)
3588 return ERROR_SEND_STATUS;
3589
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003590 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003591 if (dut->program == PROGRAM_60GHZ && network_mode &&
3592 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003593 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003594 "pbss", "1") < 0)
3595 return -2;
3596
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003597 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3598 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3599 "parameters not yet set");
3600 return 0;
3601 }
3602 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003603 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003604 return -2;
3605 } else {
3606 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3607 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003608 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003609 return -2;
3610 }
3611 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303612 if (strcmp(ssid, dut->infra_ssid) == 0) {
3613 sigma_dut_print(dut, DUT_MSG_DEBUG,
3614 "sta_associate for the most recently added network");
3615 } else if (find_network(dut, ssid) < 0) {
3616 sigma_dut_print(dut, DUT_MSG_DEBUG,
3617 "sta_associate for a previously stored network profile");
3618 send_resp(dut, conn, SIGMA_ERROR,
3619 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003620 return 0;
3621 }
3622
3623 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003624 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003625 "bssid", bssid) < 0) {
3626 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3627 "Invalid bssid argument");
3628 return 0;
3629 }
3630
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303631 if ((dut->program == PROGRAM_WPA3 &&
3632 dut->sta_associate_wait_connect) ||
3633 dut->program == PROGRAM_QM) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003634 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003635 if (!ctrl)
3636 return ERROR_SEND_STATUS;
3637 }
3638
Jouni Malinen46a19b62017-06-23 14:31:27 +03003639 extra[0] = '\0';
3640 if (chan)
3641 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003642 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003643 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3644 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003645 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003646 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3647 "network id %d on %s",
3648 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003649 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003650 ret = ERROR_SEND_STATUS;
3651 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003652 }
3653 }
3654
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003655 if (!ctrl)
3656 return SUCCESS_SEND_STATUS;
3657
3658 /* Wait for connection result to be able to store server certificate
3659 * hash for trust root override testing
3660 * (dev_exec_action,ServerCertTrust). */
3661
3662 for (e = 0; e < 20; e++) {
3663 const char *events[] = {
3664 "CTRL-EVENT-EAP-PEER-CERT",
3665 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3666 "CTRL-EVENT-DISCONNECTED",
3667 "CTRL-EVENT-CONNECTED",
3668 "CTRL-EVENT-NETWORK-NOT-FOUND",
3669 NULL
3670 };
3671 char buf[1024];
3672 int res;
3673
3674 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3675 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003676 send_resp(dut, conn, SIGMA_COMPLETE,
3677 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003678 ret = STATUS_SENT_ERROR;
3679 break;
3680 }
3681 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3682 buf);
3683
3684 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3685 strstr(buf, " depth=0")) {
3686 char *pos = strstr(buf, " hash=");
3687
3688 if (pos) {
3689 char *end;
3690
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003691 if (strstr(buf, " tod=1"))
3692 tod = 1;
3693 else if (strstr(buf, " tod=2"))
3694 tod = 2;
3695 else
3696 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003697 sigma_dut_print(dut, DUT_MSG_DEBUG,
3698 "Server certificate TOD policy: %d",
3699 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003700 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003701
3702 pos += 6;
3703 end = strchr(pos, ' ');
3704 if (end)
3705 *end = '\0';
3706 strlcpy(dut->server_cert_hash, pos,
3707 sizeof(dut->server_cert_hash));
3708 sigma_dut_print(dut, DUT_MSG_DEBUG,
3709 "Server certificate hash: %s",
3710 dut->server_cert_hash);
3711 }
3712 }
3713
3714 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3715 send_resp(dut, conn, SIGMA_COMPLETE,
3716 "Result,TLS server certificate validation failed");
3717 ret = STATUS_SENT_ERROR;
3718 break;
3719 }
3720
3721 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3722 num_network_not_found++;
3723
3724 if (num_network_not_found > 2) {
3725 send_resp(dut, conn, SIGMA_COMPLETE,
3726 "Result,Network not found");
3727 ret = STATUS_SENT_ERROR;
3728 break;
3729 }
3730 }
3731
3732 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3733 num_disconnected++;
3734
3735 if (num_disconnected > 2) {
3736 send_resp(dut, conn, SIGMA_COMPLETE,
3737 "Result,Connection failed");
3738 ret = STATUS_SENT_ERROR;
3739 break;
3740 }
3741 }
3742
3743 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3744 if (tod >= 0) {
3745 sigma_dut_print(dut, DUT_MSG_DEBUG,
3746 "Network profile TOD policy update: %d -> %d",
3747 dut->sta_tod_policy, tod);
3748 dut->sta_tod_policy = tod;
3749 }
Veerendranath Jakkama082e342020-05-16 00:19:21 +05303750 if (dut->program == PROGRAM_QM) {
3751 unsigned char iface_mac_addr[ETH_ALEN];
3752 char ipv6[100];
3753
3754 if (get_hwaddr(ifname, iface_mac_addr) < 0) {
3755 sigma_dut_print(dut, DUT_MSG_ERROR,
3756 "%s: get_hwaddr %s failed",
3757 __func__, ifname);
3758 ret = ERROR_SEND_STATUS;
3759 break;
3760 }
3761
3762 convert_mac_addr_to_ipv6_lladdr(iface_mac_addr,
3763 ipv6,
3764 sizeof(ipv6));
3765
3766 if (set_ipv6_addr(dut, ipv6, "64", ifname) !=
3767 0) {
3768 ret = ERROR_SEND_STATUS;
3769 break;
3770 }
3771 }
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003772 break;
3773 }
3774 }
3775done:
3776 if (ctrl) {
3777 wpa_ctrl_detach(ctrl);
3778 wpa_ctrl_close(ctrl);
3779 }
3780 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003781}
3782
3783
3784static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3785{
3786 char buf[500], cmd[200];
3787 int res;
3788
3789 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3790 * default path */
3791 res = snprintf(cmd, sizeof(cmd),
3792 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3793 file_exists("./hs20-osu-client") ?
3794 "./hs20-osu-client" : "hs20-osu-client",
3795 sigma_wpas_ctrl,
3796 dut->summary_log ? "-s " : "",
3797 dut->summary_log ? dut->summary_log : "");
3798 if (res < 0 || res >= (int) sizeof(cmd))
3799 return -1;
3800
3801 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3802 if (res < 0 || res >= (int) sizeof(buf))
3803 return -1;
3804 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3805
3806 if (system(buf) != 0) {
3807 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3808 return -1;
3809 }
3810 sigma_dut_print(dut, DUT_MSG_DEBUG,
3811 "Completed hs20-osu-client operation");
3812
3813 return 0;
3814}
3815
3816
3817static int download_ppsmo(struct sigma_dut *dut,
3818 struct sigma_conn *conn,
3819 const char *intf,
3820 struct sigma_cmd *cmd)
3821{
3822 const char *name, *path, *val;
3823 char url[500], buf[600], fbuf[100];
3824 char *fqdn = NULL;
3825
3826 name = get_param(cmd, "FileName");
3827 path = get_param(cmd, "FilePath");
3828 if (name == NULL || path == NULL)
3829 return -1;
3830
3831 if (strcasecmp(path, "VendorSpecific") == 0) {
3832 snprintf(url, sizeof(url), "PPS/%s", name);
3833 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3834 "from the device (%s)", url);
3835 if (!file_exists(url)) {
3836 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3837 "PPS MO file does not exist");
3838 return 0;
3839 }
3840 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3841 if (system(buf) != 0) {
3842 send_resp(dut, conn, SIGMA_ERROR,
3843 "errorCode,Failed to copy PPS MO");
3844 return 0;
3845 }
3846 } else if (strncasecmp(path, "http:", 5) != 0 &&
3847 strncasecmp(path, "https:", 6) != 0) {
3848 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3849 "Unsupported FilePath value");
3850 return 0;
3851 } else {
3852 snprintf(url, sizeof(url), "%s/%s", path, name);
3853 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3854 url);
3855 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3856 remove("pps-tnds.xml");
3857 if (system(buf) != 0) {
3858 send_resp(dut, conn, SIGMA_ERROR,
3859 "errorCode,Failed to download PPS MO");
3860 return 0;
3861 }
3862 }
3863
3864 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3865 send_resp(dut, conn, SIGMA_ERROR,
3866 "errorCode,Failed to parse downloaded PPSMO");
3867 return 0;
3868 }
3869 unlink("pps-tnds.xml");
3870
3871 val = get_param(cmd, "managementTreeURI");
3872 if (val) {
3873 const char *pos, *end;
3874 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3875 val);
3876 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3877 send_resp(dut, conn, SIGMA_ERROR,
3878 "errorCode,Invalid managementTreeURI prefix");
3879 return 0;
3880 }
3881 pos = val + 8;
3882 end = strchr(pos, '/');
3883 if (end == NULL ||
3884 strcmp(end, "/PerProviderSubscription") != 0) {
3885 send_resp(dut, conn, SIGMA_ERROR,
3886 "errorCode,Invalid managementTreeURI postfix");
3887 return 0;
3888 }
3889 if (end - pos >= (int) sizeof(fbuf)) {
3890 send_resp(dut, conn, SIGMA_ERROR,
3891 "errorCode,Too long FQDN in managementTreeURI");
3892 return 0;
3893 }
3894 memcpy(fbuf, pos, end - pos);
3895 fbuf[end - pos] = '\0';
3896 fqdn = fbuf;
3897 sigma_dut_print(dut, DUT_MSG_INFO,
3898 "FQDN from managementTreeURI: %s", fqdn);
3899 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3900 FILE *f = fopen("pps-fqdn", "r");
3901 if (f) {
3902 if (fgets(fbuf, sizeof(fbuf), f)) {
3903 fbuf[sizeof(fbuf) - 1] = '\0';
3904 fqdn = fbuf;
3905 sigma_dut_print(dut, DUT_MSG_DEBUG,
3906 "Use FQDN %s", fqdn);
3907 }
3908 fclose(f);
3909 }
3910 }
3911
3912 if (fqdn == NULL) {
3913 send_resp(dut, conn, SIGMA_ERROR,
3914 "errorCode,No FQDN specified");
3915 return 0;
3916 }
3917
3918 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3919 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3920 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3921
3922 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3923 if (rename("pps.xml", buf) < 0) {
3924 send_resp(dut, conn, SIGMA_ERROR,
3925 "errorCode,Could not move PPS MO");
3926 return 0;
3927 }
3928
3929 if (strcasecmp(path, "VendorSpecific") == 0) {
3930 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3931 fqdn);
3932 if (system(buf)) {
3933 send_resp(dut, conn, SIGMA_ERROR,
3934 "errorCode,Failed to copy OSU CA cert");
3935 return 0;
3936 }
3937
3938 snprintf(buf, sizeof(buf),
3939 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3940 fqdn);
3941 if (system(buf)) {
3942 send_resp(dut, conn, SIGMA_ERROR,
3943 "errorCode,Failed to copy AAA CA cert");
3944 return 0;
3945 }
3946 } else {
3947 snprintf(buf, sizeof(buf),
3948 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3949 fqdn, fqdn);
3950 if (run_hs20_osu(dut, buf) < 0) {
3951 send_resp(dut, conn, SIGMA_ERROR,
3952 "errorCode,Failed to download OSU CA cert");
3953 return 0;
3954 }
3955
3956 snprintf(buf, sizeof(buf),
3957 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3958 fqdn, fqdn);
3959 if (run_hs20_osu(dut, buf) < 0) {
3960 sigma_dut_print(dut, DUT_MSG_INFO,
3961 "Failed to download AAA CA cert");
3962 }
3963 }
3964
3965 if (file_exists("next-client-cert.pem")) {
3966 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3967 if (rename("next-client-cert.pem", buf) < 0) {
3968 send_resp(dut, conn, SIGMA_ERROR,
3969 "errorCode,Could not move client certificate");
3970 return 0;
3971 }
3972 }
3973
3974 if (file_exists("next-client-key.pem")) {
3975 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3976 if (rename("next-client-key.pem", buf) < 0) {
3977 send_resp(dut, conn, SIGMA_ERROR,
3978 "errorCode,Could not move client key");
3979 return 0;
3980 }
3981 }
3982
3983 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3984 if (run_hs20_osu(dut, buf) < 0) {
3985 send_resp(dut, conn, SIGMA_ERROR,
3986 "errorCode,Failed to configure credential from "
3987 "PPSMO");
3988 return 0;
3989 }
3990
3991 return 1;
3992}
3993
3994
3995static int download_cert(struct sigma_dut *dut,
3996 struct sigma_conn *conn,
3997 const char *intf,
3998 struct sigma_cmd *cmd)
3999{
4000 const char *name, *path;
4001 char url[500], buf[600];
4002
4003 name = get_param(cmd, "FileName");
4004 path = get_param(cmd, "FilePath");
4005 if (name == NULL || path == NULL)
4006 return -1;
4007
4008 if (strcasecmp(path, "VendorSpecific") == 0) {
4009 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
4010 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4011 "certificate from the device (%s)", url);
4012 if (!file_exists(url)) {
4013 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4014 "certificate file does not exist");
4015 return 0;
4016 }
4017 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
4018 if (system(buf) != 0) {
4019 send_resp(dut, conn, SIGMA_ERROR,
4020 "errorCode,Failed to copy client "
4021 "certificate");
4022 return 0;
4023 }
4024
4025 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
4026 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
4027 "private key from the device (%s)", url);
4028 if (!file_exists(url)) {
4029 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
4030 "private key file does not exist");
4031 return 0;
4032 }
4033 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
4034 if (system(buf) != 0) {
4035 send_resp(dut, conn, SIGMA_ERROR,
4036 "errorCode,Failed to copy client key");
4037 return 0;
4038 }
4039 } else if (strncasecmp(path, "http:", 5) != 0 &&
4040 strncasecmp(path, "https:", 6) != 0) {
4041 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
4042 "Unsupported FilePath value");
4043 return 0;
4044 } else {
4045 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
4046 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
4047 "certificate/key from %s", url);
4048 snprintf(buf, sizeof(buf),
4049 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
4050 if (system(buf) != 0) {
4051 send_resp(dut, conn, SIGMA_ERROR,
4052 "errorCode,Failed to download client "
4053 "certificate");
4054 return 0;
4055 }
4056
4057 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
4058 {
4059 send_resp(dut, conn, SIGMA_ERROR,
4060 "errorCode,Failed to copy client key");
4061 return 0;
4062 }
4063 }
4064
4065 return 1;
4066}
4067
4068
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004069static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
4070 struct sigma_conn *conn,
4071 struct sigma_cmd *cmd)
4072{
4073 const char *val;
4074 const char *intf = get_param(cmd, "interface");
4075
4076 if (!intf)
4077 return -1;
4078
4079 val = get_param(cmd, "WscIEFragment");
4080 if (val && strcasecmp(val, "enable") == 0) {
4081 sigma_dut_print(dut, DUT_MSG_DEBUG,
4082 "Enable WSC IE fragmentation");
4083
4084 dut->wsc_fragment = 1;
4085 /* set long attributes to force fragmentation */
4086 if (wpa_command(intf, "SET device_name "
4087 WPS_LONG_DEVICE_NAME) < 0)
4088 return -2;
4089 if (wpa_command(intf, "SET manufacturer "
4090 WPS_LONG_MANUFACTURER) < 0)
4091 return -2;
4092 if (wpa_command(intf, "SET model_name "
4093 WPS_LONG_MODEL_NAME) < 0)
4094 return -2;
4095 if (wpa_command(intf, "SET model_number "
4096 WPS_LONG_MODEL_NUMBER) < 0)
4097 return -2;
4098 if (wpa_command(intf, "SET serial_number "
4099 WPS_LONG_SERIAL_NUMBER) < 0)
4100 return -2;
4101 }
4102
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02004103 val = get_param(cmd, "RSN_IE");
4104 if (val) {
4105 if (strcasecmp(val, "disable") == 0)
4106 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
4107 else if (strcasecmp(val, "enable") == 0)
4108 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
4109 }
4110
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02004111 val = get_param(cmd, "WpsVersion");
4112 if (val)
4113 dut->wps_forced_version = get_wps_forced_version(dut, val);
4114
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02004115 val = get_param(cmd, "WscEAPFragment");
4116 if (val && strcasecmp(val, "enable") == 0)
4117 dut->eap_fragment = 1;
4118
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004119 return 1;
4120}
4121
4122
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004123static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
4124 struct sigma_conn *conn,
4125 const char *intf,
4126 struct sigma_cmd *cmd)
4127{
4128 const char *val;
4129
4130 val = get_param(cmd, "FileType");
4131 if (val && strcasecmp(val, "PPSMO") == 0)
4132 return download_ppsmo(dut, conn, intf, cmd);
4133 if (val && strcasecmp(val, "CERT") == 0)
4134 return download_cert(dut, conn, intf, cmd);
4135 if (val) {
4136 send_resp(dut, conn, SIGMA_ERROR,
4137 "ErrorCode,Unsupported FileType");
4138 return 0;
4139 }
4140
4141 return 1;
4142}
4143
4144
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304145static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
4146 struct sigma_conn *conn,
4147 const char *intf,
4148 struct sigma_cmd *cmd)
4149{
4150 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304151 char buf[1000];
4152 char text[20];
4153 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304154
4155 val = get_param(cmd, "OCESupport");
4156 if (val && strcasecmp(val, "Disable") == 0) {
4157 if (wpa_command(intf, "SET oce 0") < 0) {
4158 send_resp(dut, conn, SIGMA_ERROR,
4159 "ErrorCode,Failed to disable OCE");
4160 return 0;
4161 }
4162 } else if (val && strcasecmp(val, "Enable") == 0) {
4163 if (wpa_command(intf, "SET oce 1") < 0) {
4164 send_resp(dut, conn, SIGMA_ERROR,
4165 "ErrorCode,Failed to enable OCE");
4166 return 0;
4167 }
4168 }
4169
vamsi krishnaa2799492017-12-05 14:28:01 +05304170 val = get_param(cmd, "FILScap");
4171 if (val && (atoi(val) == 1)) {
4172 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4173 send_resp(dut, conn, SIGMA_ERROR,
4174 "ErrorCode,Failed to enable FILS");
4175 return 0;
4176 }
4177 } else if (val && (atoi(val) == 0)) {
4178 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4179 send_resp(dut, conn, SIGMA_ERROR,
4180 "ErrorCode,Failed to disable FILS");
4181 return 0;
4182 }
4183 }
4184
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304185 val = get_param(cmd, "FILSHLP");
4186 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004187 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304188 sizeof(text)) < 0)
4189 return -2;
4190 hwaddr_aton(text, addr);
4191 snprintf(buf, sizeof(buf),
4192 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4193 "080045100140000040004011399e00000000ffffffff00440043"
4194 "012cb30001010600fd4f46410000000000000000000000000000"
4195 "000000000000"
4196 "%02x%02x%02x%02x%02x%02x"
4197 "0000000000000000000000000000000000000000000000000000"
4198 "0000000000000000000000000000000000000000000000000000"
4199 "0000000000000000000000000000000000000000000000000000"
4200 "0000000000000000000000000000000000000000000000000000"
4201 "0000000000000000000000000000000000000000000000000000"
4202 "0000000000000000000000000000000000000000000000000000"
4203 "0000000000000000000000000000000000000000000000000000"
4204 "0000000000000000000000000000000000000000638253633501"
4205 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4206 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4207 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4208 if (wpa_command(intf, buf)) {
4209 send_resp(dut, conn, SIGMA_ERROR,
4210 "ErrorCode,Failed to add HLP");
4211 return 0;
4212 }
4213 dut->fils_hlp = 1;
4214 }
4215
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304216 return 1;
4217}
4218
4219
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004220static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4221 const char *val)
4222{
4223 int counter = 0;
4224 char token[50];
4225 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304226 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004227
Peng Xub8fc5cc2017-05-10 17:27:28 -07004228 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004229 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304230 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004231 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004232 if (strcmp(result, "disable") == 0)
4233 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4234 else
4235 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304236 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004237 counter++;
4238 }
4239}
4240
4241
4242static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4243 const char *val)
4244{
4245 char buf[100];
4246
4247 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4248 if (system(buf) != 0) {
4249 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4250 }
4251}
4252
4253
4254static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4255 const char *val)
4256{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004257 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004258 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004259 }
4260}
4261
4262
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004263static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4264 const char *val)
4265{
4266#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004267 int wmmenable = 1;
4268
4269 if (val &&
4270 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4271 wmmenable = 0;
4272
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304273 return wcn_wifi_test_config_set_u8(
4274 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4275 wmmenable);
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004276#else /* NL80211_SUPPORT */
4277 sigma_dut_print(dut, DUT_MSG_ERROR,
4278 "WMM cannot be changed without NL80211_SUPPORT defined");
4279 return -1;
4280#endif /* NL80211_SUPPORT */
4281}
4282
4283
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004284static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4285 const char *val)
4286{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004287 int sgi20;
4288
4289 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4290
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004291 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004292}
4293
4294
4295static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4296 const char *val)
4297{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304298 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004299
4300 /* Disable Tx Beam forming when using a fixed rate */
4301 ath_disable_txbf(dut, intf);
4302
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304303 v = atoi(val);
4304 if (v < 0 || v > 32) {
4305 sigma_dut_print(dut, DUT_MSG_ERROR,
4306 "Invalid Fixed MCS rate: %d", v);
4307 return;
4308 }
4309 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004310
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004311 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004312
4313 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004314 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004315}
4316
4317
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004318static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4319 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004320{
4321 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304322 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004323
4324 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4325 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4326 else
4327 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4328
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304329 ret = system(buf);
4330#ifdef NL80211_SUPPORT
4331 if (ret) {
4332 int value = (strcasecmp(val, "Enable") == 0) ? 2 : 1;
4333
4334 ret = sta_config_params(dut, intf, STA_SET_TX_MSDU, value);
4335 ret |= sta_config_params(dut, intf, STA_SET_RX_MSDU, value);
4336 }
4337#endif /* NL80211_SUPPORT */
4338 if (ret)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004339 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4340}
4341
4342
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004343static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4344 int ampdu)
4345{
4346 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004347 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004348
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004349 if (ampdu)
4350 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004351 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4352 if (system(buf) != 0) {
4353 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4354 return -1;
4355 }
4356
4357 return 0;
4358}
4359
4360
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004361static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4362 const char *val)
4363{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004364 run_iwpriv(dut, intf, "tx_stbc %s", val);
4365 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004366}
4367
4368
4369static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4370 const char *val)
4371{
4372 char buf[60];
4373
Peng Xucc317ed2017-05-18 16:44:37 -07004374 if (strcmp(val, "160") == 0) {
4375 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4376 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4378 } else if (strcmp(val, "40") == 0) {
4379 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4380 } else if (strcmp(val, "20") == 0) {
4381 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4382 } else if (strcasecmp(val, "Auto") == 0) {
4383 buf[0] = '\0';
4384 } else {
4385 sigma_dut_print(dut, DUT_MSG_ERROR,
4386 "WIDTH/CTS_WIDTH value not supported");
4387 return -1;
4388 }
4389
4390 if (buf[0] != '\0' && system(buf) != 0) {
4391 sigma_dut_print(dut, DUT_MSG_ERROR,
4392 "Failed to set WIDTH/CTS_WIDTH");
4393 return -1;
4394 }
4395
4396 return 0;
4397}
4398
4399
4400int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4401 const char *intf, const char *val)
4402{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004403 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004404 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004405 dut->chwidth = 0;
4406 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004407 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004408 dut->chwidth = 0;
4409 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004410 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004411 dut->chwidth = 1;
4412 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004413 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004414 dut->chwidth = 2;
4415 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004416 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004417 dut->chwidth = 3;
4418 } else {
4419 send_resp(dut, conn, SIGMA_ERROR,
4420 "ErrorCode,WIDTH not supported");
4421 return -1;
4422 }
4423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004424 return 0;
4425}
4426
4427
4428static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4429 const char *val)
4430{
4431 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004432 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004433
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004434 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004435 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004436 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004437 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004439 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004440 } else {
4441 sigma_dut_print(dut, DUT_MSG_ERROR,
4442 "SP_STREAM value not supported");
4443 return -1;
4444 }
4445
4446 if (system(buf) != 0) {
4447 sigma_dut_print(dut, DUT_MSG_ERROR,
4448 "Failed to set SP_STREAM");
4449 return -1;
4450 }
4451
Arif Hussainac6c5112018-05-25 17:34:00 -07004452 dut->sta_nss = sta_nss;
4453
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004454 return 0;
4455}
4456
4457
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304458static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4459 const char *val)
4460{
4461 char buf[60];
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304462 int ret;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304463
4464 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304465 ret = system(buf);
4466#ifdef NL80211_SUPPORT
4467 if (ret)
4468 ret = sta_config_params(dut, intf, STA_SET_TX_STBC,
4469 strcmp(val, "0") == 0 ? 0 : 1);
4470#endif /* NL80211_SUPPORT */
4471 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304472 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4473
4474 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05304475 ret = system(buf);
4476#ifdef NL80211_SUPPORT
4477 if (ret)
4478 ret = sta_config_params(dut, intf, STA_SET_RX_STBC,
4479 strcmp(val, "0") == 0 ? 0 : 1);
4480#endif /* NL80211_SUPPORT */
4481 if (ret)
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304482 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4483}
4484
4485
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304486static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4487 struct sigma_conn *conn,
4488 const char *intf, int capa)
4489{
4490 char buf[32];
4491
4492 if (capa > 0 && capa < 4) {
4493 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4494 if (wpa_command(intf, buf) < 0) {
4495 send_resp(dut, conn, SIGMA_ERROR,
4496 "ErrorCode, Failed to set cellular data capability");
4497 return 0;
4498 }
4499 return 1;
4500 }
4501
4502 sigma_dut_print(dut, DUT_MSG_ERROR,
4503 "Invalid Cellular data capability: %d", capa);
4504 send_resp(dut, conn, SIGMA_INVALID,
4505 "ErrorCode,Invalid cellular data capability");
4506 return 0;
4507}
4508
4509
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304510static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4511 const char *intf, const char *val)
4512{
4513 if (strcasecmp(val, "Disable") == 0) {
4514 if (wpa_command(intf, "SET roaming 0") < 0) {
4515 send_resp(dut, conn, SIGMA_ERROR,
4516 "ErrorCode,Failed to disable roaming");
4517 return 0;
4518 }
4519 return 1;
4520 }
4521
4522 if (strcasecmp(val, "Enable") == 0) {
4523 if (wpa_command(intf, "SET roaming 1") < 0) {
4524 send_resp(dut, conn, SIGMA_ERROR,
4525 "ErrorCode,Failed to enable roaming");
4526 return 0;
4527 }
4528 return 1;
4529 }
4530
4531 sigma_dut_print(dut, DUT_MSG_ERROR,
4532 "Invalid value provided for roaming: %s", val);
4533 send_resp(dut, conn, SIGMA_INVALID,
4534 "ErrorCode,Unknown value provided for Roaming");
4535 return 0;
4536}
4537
4538
Ashwini Patila75de5a2017-04-13 16:35:05 +05304539static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4540 struct sigma_conn *conn,
4541 const char *intf, const char *val)
4542{
4543 if (strcasecmp(val, "Disable") == 0) {
4544 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4545 send_resp(dut, conn, SIGMA_ERROR,
4546 "ErrorCode,Failed to disable Assoc_disallow");
4547 return 0;
4548 }
4549 return 1;
4550 }
4551
4552 if (strcasecmp(val, "Enable") == 0) {
4553 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,Failed to enable Assoc_disallow");
4556 return 0;
4557 }
4558 return 1;
4559 }
4560
4561 sigma_dut_print(dut, DUT_MSG_ERROR,
4562 "Invalid value provided for Assoc_disallow: %s", val);
4563 send_resp(dut, conn, SIGMA_INVALID,
4564 "ErrorCode,Unknown value provided for Assoc_disallow");
4565 return 0;
4566}
4567
4568
Ashwini Patilc63161e2017-04-13 16:30:23 +05304569static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4570 const char *intf, const char *val)
4571{
4572 if (strcasecmp(val, "Reject") == 0) {
4573 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4574 send_resp(dut, conn, SIGMA_ERROR,
4575 "ErrorCode,Failed to Reject BTM Request");
4576 return 0;
4577 }
4578 return 1;
4579 }
4580
4581 if (strcasecmp(val, "Accept") == 0) {
4582 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4583 send_resp(dut, conn, SIGMA_ERROR,
4584 "ErrorCode,Failed to Accept BTM Request");
4585 return 0;
4586 }
4587 return 1;
4588 }
4589
4590 sigma_dut_print(dut, DUT_MSG_ERROR,
4591 "Invalid value provided for BSS_Transition: %s", val);
4592 send_resp(dut, conn, SIGMA_INVALID,
4593 "ErrorCode,Unknown value provided for BSS_Transition");
4594 return 0;
4595}
4596
4597
Ashwini Patil00402582017-04-13 12:29:39 +05304598static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4599 struct sigma_conn *conn,
4600 const char *intf,
4601 struct sigma_cmd *cmd)
4602{
4603 const char *ch, *pref, *op_class, *reason;
4604 char buf[120];
4605 int len, ret;
4606
4607 pref = get_param(cmd, "Ch_Pref");
4608 if (!pref)
4609 return 1;
4610
4611 if (strcasecmp(pref, "clear") == 0) {
4612 free(dut->non_pref_ch_list);
4613 dut->non_pref_ch_list = NULL;
4614 } else {
4615 op_class = get_param(cmd, "Ch_Op_Class");
4616 if (!op_class) {
4617 send_resp(dut, conn, SIGMA_INVALID,
4618 "ErrorCode,Ch_Op_Class not provided");
4619 return 0;
4620 }
4621
4622 ch = get_param(cmd, "Ch_Pref_Num");
4623 if (!ch) {
4624 send_resp(dut, conn, SIGMA_INVALID,
4625 "ErrorCode,Ch_Pref_Num not provided");
4626 return 0;
4627 }
4628
4629 reason = get_param(cmd, "Ch_Reason_Code");
4630 if (!reason) {
4631 send_resp(dut, conn, SIGMA_INVALID,
4632 "ErrorCode,Ch_Reason_Code not provided");
4633 return 0;
4634 }
4635
4636 if (!dut->non_pref_ch_list) {
4637 dut->non_pref_ch_list =
4638 calloc(1, NON_PREF_CH_LIST_SIZE);
4639 if (!dut->non_pref_ch_list) {
4640 send_resp(dut, conn, SIGMA_ERROR,
4641 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4642 return 0;
4643 }
4644 }
4645 len = strlen(dut->non_pref_ch_list);
4646 ret = snprintf(dut->non_pref_ch_list + len,
4647 NON_PREF_CH_LIST_SIZE - len,
4648 " %s:%s:%s:%s", op_class, ch, pref, reason);
4649 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4650 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4651 dut->non_pref_ch_list);
4652 } else {
4653 sigma_dut_print(dut, DUT_MSG_ERROR,
4654 "snprintf failed for non_pref_list, ret = %d",
4655 ret);
4656 send_resp(dut, conn, SIGMA_ERROR,
4657 "ErrorCode,snprintf failed");
4658 free(dut->non_pref_ch_list);
4659 dut->non_pref_ch_list = NULL;
4660 return 0;
4661 }
4662 }
4663
4664 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4665 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4666 if (ret < 0 || ret >= (int) sizeof(buf)) {
4667 sigma_dut_print(dut, DUT_MSG_DEBUG,
4668 "snprintf failed for set non_pref_chan, ret: %d",
4669 ret);
4670 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4671 return 0;
4672 }
4673
4674 if (wpa_command(intf, buf) < 0) {
4675 send_resp(dut, conn, SIGMA_ERROR,
4676 "ErrorCode,Failed to set non-preferred channel list");
4677 return 0;
4678 }
4679
4680 return 1;
4681}
4682
4683
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004684#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004685
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004686static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4687 uint8_t cfg)
4688{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304689 return wcn_wifi_test_config_set_u8(
4690 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4691 cfg);
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004692}
4693
4694
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004695static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4696 enum he_fragmentation_val frag)
4697{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304698 return wcn_wifi_test_config_set_u8(
4699 dut, intf,
4700 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION, frag);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004701}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004702
4703
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004704int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4705 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004706{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05304707 return wcn_wifi_test_config_set_u8(
4708 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF, ltf);
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004709}
4710
4711
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004712static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4713 int noack, enum qca_wlan_ac_type ac)
4714{
4715 struct nl_msg *msg;
4716 int ret = 0;
4717 struct nlattr *params;
4718 int ifindex;
4719
4720 ifindex = if_nametoindex(intf);
4721 if (ifindex == 0) {
4722 sigma_dut_print(dut, DUT_MSG_ERROR,
4723 "%s: Index for interface %s failed",
4724 __func__, intf);
4725 return -1;
4726 }
4727
4728 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4729 NL80211_CMD_VENDOR)) ||
4730 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4731 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4732 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4733 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4734 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4735 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4736 noack) ||
4737 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4738 ac)) {
4739 sigma_dut_print(dut, DUT_MSG_ERROR,
4740 "%s: err in adding vendor_cmd and vendor_data",
4741 __func__);
4742 nlmsg_free(msg);
4743 return -1;
4744 }
4745 nla_nest_end(msg, params);
4746
4747 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4748 if (ret) {
4749 sigma_dut_print(dut, DUT_MSG_ERROR,
4750 "%s: err in send_and_recv_msgs, ret=%d",
4751 __func__, ret);
4752 }
4753 return ret;
4754}
4755
4756
4757static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4758 const char *val)
4759{
4760 int noack, ret;
4761 char token[100];
4762 char *result;
4763 char *saveptr;
4764 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4765
4766 strlcpy(token, val, sizeof(token));
4767 token[sizeof(token) - 1] = '\0';
4768 result = strtok_r(token, ":", &saveptr);
4769 while (result) {
4770 noack = strcasecmp(result, "Disable") != 0;
4771 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4772 if (ret) {
4773 sigma_dut_print(dut, DUT_MSG_ERROR,
4774 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4775 ac, ret);
4776 }
4777 result = strtok_r(NULL, ":", &saveptr);
4778 ac++;
4779 }
4780}
4781
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304782
4783static int nlvendor_sta_set_phymode(struct sigma_dut *dut, const char *intf,
4784 enum qca_wlan_vendor_phy_mode val)
4785{
4786 struct nl_msg *msg;
4787 struct nlattr *params;
4788 int ifindex, ret;
4789
4790 ifindex = if_nametoindex(intf);
4791 if (ifindex == 0) {
4792 sigma_dut_print(dut, DUT_MSG_ERROR,
4793 "%s: Index for interface %s not found",
4794 __func__, intf);
4795 return -1;
4796 }
4797
4798 msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4799 NL80211_CMD_VENDOR);
4800 if (!msg) {
4801 sigma_dut_print(dut, DUT_MSG_ERROR,
4802 "%s: err in adding vendor_cmd", __func__);
4803 return -1;
4804 }
4805
4806 if (nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4807 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4808 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) {
4809 sigma_dut_print(dut, DUT_MSG_ERROR,
4810 "%s: err in adding vendor_attr", __func__);
4811 nlmsg_free(msg);
4812 return -1;
4813 }
4814
4815 params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
4816 if (!params || nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_PHY_MODE,
4817 val)) {
4818 sigma_dut_print(dut, DUT_MSG_ERROR,
4819 "%s: err in adding vendor_data", __func__);
4820 nlmsg_free(msg);
4821 return -1;
4822 }
4823
4824 nla_nest_end(msg, params);
4825 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4826 if (ret) {
4827 sigma_dut_print(dut, DUT_MSG_ERROR,
4828 "%s: err in send_and_recv_msgs, ret=%d (%s)",
4829 __func__, ret, strerror(-ret));
4830 return ret;
4831 }
4832
4833 return 0;
4834}
4835
4836
4837static enum qca_wlan_vendor_phy_mode get_qca_vendor_phymode(const char *val)
4838{
4839 if (strcmp(val, "11a") == 0) {
4840 /* IEEE80211_MODE_11A */
4841 return QCA_WLAN_VENDOR_PHY_MODE_11A;
4842 }
4843
4844 if (strcmp(val, "11g") == 0) {
4845 /* IEEE80211_MODE_11G */
4846 return QCA_WLAN_VENDOR_PHY_MODE_11G;
4847 }
4848
4849 if (strcmp(val, "11b") == 0) {
4850 /* IEEE80211_MODE_11B */
4851 return QCA_WLAN_VENDOR_PHY_MODE_11B;
4852 }
4853
4854 if (strcmp(val, "11n") == 0 ||
4855 strcmp(val, "11nl") == 0 ||
4856 strcmp(val, "11nl(nabg)") == 0) {
4857 /* IEEE80211_MODE_11AGN */
4858 return QCA_WLAN_VENDOR_PHY_MODE_11AGN;
4859 }
4860
4861 if (strcmp(val, "11ng") == 0) {
4862 /* IEEE80211_MODE_11NG_HT40 */
4863 return QCA_WLAN_VENDOR_PHY_MODE_11NG_HT40;
4864 }
4865
4866 if (strcmp(val, "AC") == 0 ||
4867 strcasecmp(val, "11AC") == 0) {
4868 /* IEEE80211_MODE_11AC_VHT80 */
4869 return QCA_WLAN_VENDOR_PHY_MODE_11AC_VHT80;
4870 }
4871
4872 if (strcmp(val, "11na") == 0 ||
4873 strcasecmp(val, "11an") == 0) {
4874 /* IEEE80211_MODE_11NA_HT40 */
4875 return QCA_WLAN_VENDOR_PHY_MODE_11NA_HT40;
4876 }
4877
4878 if (strcmp(val, "11ax") == 0 ||
4879 strcmp(val, "auto") == 0) {
4880 /* IEEE80211_MODE_AUTO */
4881 return QCA_WLAN_VENDOR_PHY_MODE_AUTO;
4882 }
4883
4884 return -1;
4885}
4886
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004887#endif /* NL80211_SUPPORT */
4888
4889
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304890static int get_phymode(const char *val)
4891{
4892 if (strcmp(val, "11a") == 0)
4893 return 1; /* IEEE80211_MODE_11A */
4894 if (strcmp(val, "11g") == 0)
4895 return 3; /* IEEE80211_MODE_11G */
4896 if (strcmp(val, "11b") == 0)
4897 return 2; /* IEEE80211_MODE_11B */
4898 if (strcmp(val, "11n") == 0 ||
4899 strcmp(val, "11nl") == 0 ||
4900 strcmp(val, "11nl(nabg)") == 0)
4901 return 22; /* IEEE80211_MODE_11AGN */
4902 if (strcmp(val, "11ng") == 0)
4903 return 13; /* IEEE80211_MODE_11NG_HT40 */
4904 if (strcmp(val, "AC") == 0 ||
4905 strcasecmp(val, "11AC") == 0)
4906 return 19; /* IEEE80211_MODE_11AC_VHT80 */
4907 if (strcmp(val, "11na") == 0 ||
4908 strcasecmp(val, "11an") == 0)
4909 return 14; /* IEEE80211_MODE_11NA_HT40 */
4910 if (strcmp(val, "11ax") == 0 ||
4911 strcmp(val, "auto") == 0)
4912 return 0; /* IEEE80211_MODE_AUTO */
4913 return -1;
4914}
4915
4916
4917static void sta_set_phymode(struct sigma_dut *dut, const char *intf,
4918 const char *val)
4919{
4920 char buf[100];
4921 int len, phymode;
Vinita S. Maloo7462e812020-05-22 15:16:04 +05304922#ifdef NL80211_SUPPORT
4923 enum qca_wlan_vendor_phy_mode qca_phymode;
4924
4925 qca_phymode = get_qca_vendor_phymode(val);
4926 if (qca_phymode == -1) {
4927 sigma_dut_print(dut, DUT_MSG_DEBUG,
4928 "Ignoring mode change for mode: %s",
4929 val);
4930 return;
4931 }
4932
4933 if (nlvendor_sta_set_phymode(dut, intf, qca_phymode) == 0)
4934 return;
4935#endif /* NL80211_SUPPORT */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05304936
4937 phymode = get_phymode(val);
4938 if (phymode == -1) {
4939 sigma_dut_print(dut, DUT_MSG_DEBUG,
4940 "Ignoring mode change for mode: %s",
4941 val);
4942 return;
4943 }
4944
4945 len = snprintf(buf, sizeof(buf), "iwpriv %s setphymode %d", intf,
4946 phymode);
4947 if (len < 0 || len >= sizeof(buf)) {
4948 sigma_dut_print(dut, DUT_MSG_ERROR,
4949 "Failed to set phymode");
4950 return;
4951 }
4952
4953 if (system(buf) != 0)
4954 sigma_dut_print(dut, DUT_MSG_ERROR,
4955 "iwpriv setting of phymode failed");
4956}
4957
4958
Jouni Malinenf7222712019-06-13 01:50:21 +03004959static enum sigma_cmd_result
4960cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4961 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004962{
4963 const char *intf = get_param(cmd, "Interface");
4964 const char *val;
4965
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004966 val = get_param(cmd, "FT_DS");
4967 if (val) {
4968 if (strcasecmp(val, "Enable") == 0) {
4969 dut->sta_ft_ds = 1;
4970 } else if (strcasecmp(val, "Disable") == 0) {
4971 dut->sta_ft_ds = 0;
4972 } else {
4973 send_resp(dut, conn, SIGMA_ERROR,
4974 "errorCode,Unsupported value for FT_DS");
4975 return STATUS_SENT_ERROR;
4976 }
4977 }
4978
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004979 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004980 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4981 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004982 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4983 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004984
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004985 if (val && strcasecmp(val, "LOC") == 0)
4986 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004987 if (val && strcasecmp(val, "60GHZ") == 0) {
4988 val = get_param(cmd, "WPS");
4989 if (val && strcasecmp(val, "disable") == 0) {
4990 dut->wps_disable = 1;
4991 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4992 } else {
4993 /* wps_disable can have other value from the previous
4994 * test, so make sure it has the correct value.
4995 */
4996 dut->wps_disable = 0;
4997 }
4998
4999 val = get_param(cmd, "P2P");
5000 if (val && strcasecmp(val, "disable") == 0)
5001 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
5002 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07005003
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02005004 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
5005 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
5006
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005007#ifdef ANDROID_NAN
5008 if (val && strcasecmp(val, "NAN") == 0)
5009 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
5010#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005011#ifdef MIRACAST
5012 if (val && (strcasecmp(val, "WFD") == 0 ||
5013 strcasecmp(val, "DisplayR2") == 0))
5014 return miracast_preset_testparameters(dut, conn, cmd);
5015#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005016
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07005017 if (val &&
5018 (strcasecmp(val, "MBO") == 0 || strcasecmp(val, "HE") == 0)) {
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305019 val = get_param(cmd, "Cellular_Data_Cap");
5020 if (val &&
5021 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
5022 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05305023
5024 val = get_param(cmd, "Ch_Pref");
5025 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
5026 return 0;
5027
Ashwini Patilc63161e2017-04-13 16:30:23 +05305028 val = get_param(cmd, "BSS_Transition");
5029 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
5030 return 0;
5031
Ashwini Patila75de5a2017-04-13 16:35:05 +05305032 val = get_param(cmd, "Assoc_Disallow");
5033 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
5034 return 0;
5035
Ashwini Patil9183fdb2017-04-13 16:58:25 +05305036 val = get_param(cmd, "Roaming");
5037 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
5038 return 0;
5039
Ashwini Patil68d02cd2017-01-10 15:39:16 +05305040 return 1;
5041 }
5042
Ankita Bajaja2cb5672017-10-25 16:08:28 +05305043 if (val && strcasecmp(val, "OCE") == 0)
5044 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
5045
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005046#if 0
5047 val = get_param(cmd, "Supplicant");
5048 if (val && strcasecmp(val, "Default") != 0) {
5049 send_resp(dut, conn, SIGMA_ERROR,
5050 "ErrorCode,Only default(Vendor) supplicant "
5051 "supported");
5052 return 0;
5053 }
5054#endif
5055
5056 val = get_param(cmd, "RTS");
5057 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005058 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059 case DRIVER_ATHEROS:
5060 ath_sta_set_rts(dut, intf, val);
5061 break;
5062 default:
5063#if 0
5064 send_resp(dut, conn, SIGMA_ERROR,
5065 "ErrorCode,Setting RTS not supported");
5066 return 0;
5067#else
5068 sigma_dut_print(dut, DUT_MSG_DEBUG,
5069 "Setting RTS not supported");
5070 break;
5071#endif
5072 }
5073 }
5074
5075#if 0
5076 val = get_param(cmd, "FRGMNT");
5077 if (val) {
5078 /* TODO */
5079 send_resp(dut, conn, SIGMA_ERROR,
5080 "ErrorCode,Setting FRGMNT not supported");
5081 return 0;
5082 }
5083#endif
5084
5085#if 0
5086 val = get_param(cmd, "Preamble");
5087 if (val) {
5088 /* TODO: Long/Short */
5089 send_resp(dut, conn, SIGMA_ERROR,
5090 "ErrorCode,Setting Preamble not supported");
5091 return 0;
5092 }
5093#endif
5094
5095 val = get_param(cmd, "Mode");
5096 if (val) {
5097 if (strcmp(val, "11b") == 0 ||
5098 strcmp(val, "11g") == 0 ||
5099 strcmp(val, "11a") == 0 ||
5100 strcmp(val, "11n") == 0 ||
5101 strcmp(val, "11ng") == 0 ||
5102 strcmp(val, "11nl") == 0 ||
5103 strcmp(val, "11nl(nabg)") == 0 ||
5104 strcmp(val, "AC") == 0 ||
5105 strcmp(val, "11AC") == 0 ||
5106 strcmp(val, "11ac") == 0 ||
5107 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08005108 strcmp(val, "11an") == 0 ||
5109 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005110 /* STA supports all modes by default */
5111 } else {
5112 send_resp(dut, conn, SIGMA_ERROR,
5113 "ErrorCode,Setting Mode not supported");
5114 return 0;
5115 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005116
5117 /* Change the mode only in case of testbed for HE program
5118 * and for 11a and 11g modes only. */
5119 if (dut->program == PROGRAM_HE &&
5120 dut->device_type == STA_testbed) {
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05305121 sta_set_phymode(dut, intf, val);
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08005122 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005123 }
5124
5125 val = get_param(cmd, "wmm");
5126 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005127 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005128 case DRIVER_ATHEROS:
5129 ath_sta_set_wmm(dut, intf, val);
5130 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08005131 case DRIVER_WCN:
5132 wcn_sta_set_wmm(dut, intf, val);
5133 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005134 default:
5135 sigma_dut_print(dut, DUT_MSG_DEBUG,
5136 "Setting wmm not supported");
5137 break;
5138 }
5139 }
5140
5141 val = get_param(cmd, "Powersave");
5142 if (val) {
5143 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005144 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305145 if (set_power_save_wcn(dut, intf, 2) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005146 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005147 }
5148
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005149 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005150 "P2P_SET ps 0") < 0)
5151 return -2;
5152 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005153 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5154 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005155 } else if (strcmp(val, "1") == 0 ||
5156 strcasecmp(val, "PSPoll") == 0 ||
5157 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005158 if (get_driver_type(dut) == DRIVER_WCN) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +05305159 if (set_power_save_wcn(dut, intf, 1) < 0)
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005160 return 0;
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08005161 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005162 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005163 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005164 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005165 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005166 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005167 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005168 "P2P_SET ps 99") < 0)
5169 return -2;
5170 } else if (strcmp(val, "2") == 0 ||
5171 strcasecmp(val, "Fast") == 0) {
5172 /* TODO */
5173 send_resp(dut, conn, SIGMA_ERROR,
5174 "ErrorCode,Powersave=Fast not supported");
5175 return 0;
5176 } else if (strcmp(val, "3") == 0 ||
5177 strcasecmp(val, "PSNonPoll") == 0) {
5178 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005179 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
5180 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005181
5182 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005183 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005184 "P2P_SET ps 1") < 0)
5185 return -2;
5186 } else
5187 return -1;
5188 }
5189
5190 val = get_param(cmd, "NoAck");
5191 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005192 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005193 case DRIVER_ATHEROS:
5194 ath_sta_set_noack(dut, intf, val);
5195 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005196#ifdef NL80211_SUPPORT
5197 case DRIVER_WCN:
5198 wcn_sta_set_noack(dut, intf, val);
5199 break;
5200#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005201 default:
5202 send_resp(dut, conn, SIGMA_ERROR,
5203 "ErrorCode,Setting NoAck not supported");
5204 return 0;
5205 }
5206 }
5207
5208 val = get_param(cmd, "IgnoreChswitchProhibit");
5209 if (val) {
5210 /* TODO: Enabled/disabled */
5211 if (strcasecmp(val, "Enabled") == 0) {
5212 send_resp(dut, conn, SIGMA_ERROR,
5213 "ErrorCode,Enabling IgnoreChswitchProhibit "
5214 "not supported");
5215 return 0;
5216 }
5217 }
5218
5219 val = get_param(cmd, "TDLS");
5220 if (val) {
5221 if (strcasecmp(val, "Disabled") == 0) {
5222 if (wpa_command(intf, "SET tdls_disabled 1")) {
5223 send_resp(dut, conn, SIGMA_ERROR,
5224 "ErrorCode,Failed to disable TDLS");
5225 return 0;
5226 }
5227 } else if (strcasecmp(val, "Enabled") == 0) {
5228 if (wpa_command(intf, "SET tdls_disabled 0")) {
5229 send_resp(dut, conn, SIGMA_ERROR,
5230 "ErrorCode,Failed to enable TDLS");
5231 return 0;
5232 }
5233 } else {
5234 send_resp(dut, conn, SIGMA_ERROR,
5235 "ErrorCode,Unsupported TDLS value");
5236 return 0;
5237 }
5238 }
5239
5240 val = get_param(cmd, "TDLSmode");
5241 if (val) {
5242 if (strcasecmp(val, "Default") == 0) {
5243 wpa_command(intf, "SET tdls_testing 0");
5244 } else if (strcasecmp(val, "APProhibit") == 0) {
5245 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5246 send_resp(dut, conn, SIGMA_ERROR,
5247 "ErrorCode,Failed to enable ignore "
5248 "APProhibit TDLS mode");
5249 return 0;
5250 }
5251 } else if (strcasecmp(val, "HiLoMac") == 0) {
5252 /* STA should respond with TDLS setup req for a TDLS
5253 * setup req */
5254 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5255 send_resp(dut, conn, SIGMA_ERROR,
5256 "ErrorCode,Failed to enable HiLoMac "
5257 "TDLS mode");
5258 return 0;
5259 }
5260 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5261 /*
5262 * Since all security modes are enabled by default when
5263 * Sigma control is used, there is no need to do
5264 * anything here.
5265 */
5266 } else if (strcasecmp(val, "ExistLink") == 0) {
5267 /*
5268 * Since we allow new TDLS Setup Request even if there
5269 * is an existing link, nothing needs to be done for
5270 * this.
5271 */
5272 } else {
5273 /* TODO:
5274 * ExistLink: STA should send TDLS setup req even if
5275 * direct link already exists
5276 */
5277 send_resp(dut, conn, SIGMA_ERROR,
5278 "ErrorCode,Unsupported TDLSmode value");
5279 return 0;
5280 }
5281 }
5282
5283 val = get_param(cmd, "FakePubKey");
5284 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5285 send_resp(dut, conn, SIGMA_ERROR,
5286 "ErrorCode,Failed to enable FakePubKey");
5287 return 0;
5288 }
5289
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005290#ifdef NL80211_SUPPORT
5291 val = get_param(cmd, "FrgmntSupport");
5292 if (val) {
5293 if (strcasecmp(val, "Enable") == 0) {
5294 if (sta_set_he_fragmentation(dut, intf,
5295 HE_FRAG_LEVEL1)) {
5296 send_resp(dut, conn, SIGMA_ERROR,
5297 "ErrorCode,Failed to enable HE Fragmentation");
5298 return 0;
5299 }
5300 } else if (strcasecmp(val, "Disable") == 0) {
5301 if (sta_set_he_fragmentation(dut, intf,
5302 HE_FRAG_DISABLE)) {
5303 send_resp(dut, conn, SIGMA_ERROR,
5304 "ErrorCode,Failed to disable HE Fragmentation");
5305 return 0;
5306 }
5307 }
5308 }
5309#endif /* NL80211_SUPPORT */
5310
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305311 val = get_param(cmd, "IncludeMSCSDescriptor");
5312 if (val && strcasecmp(val, "1") == 0) {
5313 char buf[128];
5314 int len;
5315
5316 len = snprintf(buf, sizeof(buf),
Veerendranath Jakkam62cde372020-08-19 18:03:06 +05305317 "MSCS add up_bitmap=F0 up_limit=7 stream_timeout=60000 frame_classifier=045F%032x",
Vinita S. Maloo8a4779c2020-06-22 19:32:37 +05305318 0);
5319
5320 if (len < 0 || len >= sizeof(buf)) {
5321 sigma_dut_print(dut, DUT_MSG_ERROR,
5322 "Failed to build MSCS Descriptor IE");
5323 return ERROR_SEND_STATUS;
5324 }
5325
5326 if (wpa_command(intf, buf) != 0) {
5327 send_resp(dut, conn, SIGMA_ERROR,
5328 "ErrorCode,Failed to include MSCS descriptor");
5329 return STATUS_SENT_ERROR;
5330 }
5331 }
5332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005333 return 1;
5334}
5335
5336
5337static const char * ath_get_radio_name(const char *radio_name)
5338{
5339 if (radio_name == NULL)
5340 return "wifi0";
5341 if (strcmp(radio_name, "wifi1") == 0)
5342 return "wifi1";
5343 if (strcmp(radio_name, "wifi2") == 0)
5344 return "wifi2";
5345 return "wifi0";
5346}
5347
5348
5349static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5350 const char *val)
5351{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005352 unsigned int vht_mcsmap = 0;
5353 int txchainmask = 0;
5354 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5355
5356 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5357 if (dut->testbed_flag_txsp == 1) {
5358 vht_mcsmap = 0xfffc;
5359 dut->testbed_flag_txsp = 0;
5360 } else {
5361 vht_mcsmap = 0xfffe;
5362 }
5363 txchainmask = 1;
5364 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5365 if (dut->testbed_flag_txsp == 1) {
5366 vht_mcsmap = 0xfff0;
5367 dut->testbed_flag_txsp = 0;
5368 } else {
5369 vht_mcsmap = 0xfffa;
5370 }
5371 txchainmask = 3;
5372 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5373 if (dut->testbed_flag_txsp == 1) {
5374 vht_mcsmap = 0xffc0;
5375 dut->testbed_flag_txsp = 0;
5376 } else {
5377 vht_mcsmap = 0xffea;
5378 }
5379 txchainmask = 7;
5380 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5381 if (dut->testbed_flag_txsp == 1) {
5382 vht_mcsmap = 0xff00;
5383 dut->testbed_flag_txsp = 0;
5384 } else {
5385 vht_mcsmap = 0xffaa;
5386 }
5387 txchainmask = 15;
5388 } else {
5389 if (dut->testbed_flag_txsp == 1) {
5390 vht_mcsmap = 0xffc0;
5391 dut->testbed_flag_txsp = 0;
5392 } else {
5393 vht_mcsmap = 0xffea;
5394 }
5395 }
5396
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005397 if (txchainmask)
5398 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005399
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005400 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005401}
5402
5403
5404static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5405 const char *val)
5406{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005407 unsigned int vht_mcsmap = 0;
5408 int rxchainmask = 0;
5409 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5410
5411 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5412 if (dut->testbed_flag_rxsp == 1) {
5413 vht_mcsmap = 0xfffc;
5414 dut->testbed_flag_rxsp = 0;
5415 } else {
5416 vht_mcsmap = 0xfffe;
5417 }
5418 rxchainmask = 1;
5419 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5420 if (dut->testbed_flag_rxsp == 1) {
5421 vht_mcsmap = 0xfff0;
5422 dut->testbed_flag_rxsp = 0;
5423 } else {
5424 vht_mcsmap = 0xfffa;
5425 }
5426 rxchainmask = 3;
5427 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5428 if (dut->testbed_flag_rxsp == 1) {
5429 vht_mcsmap = 0xffc0;
5430 dut->testbed_flag_rxsp = 0;
5431 } else {
5432 vht_mcsmap = 0xffea;
5433 }
5434 rxchainmask = 7;
5435 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5436 if (dut->testbed_flag_rxsp == 1) {
5437 vht_mcsmap = 0xff00;
5438 dut->testbed_flag_rxsp = 0;
5439 } else {
5440 vht_mcsmap = 0xffaa;
5441 }
5442 rxchainmask = 15;
5443 } else {
5444 if (dut->testbed_flag_rxsp == 1) {
5445 vht_mcsmap = 0xffc0;
5446 dut->testbed_flag_rxsp = 0;
5447 } else {
5448 vht_mcsmap = 0xffea;
5449 }
5450 }
5451
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005452 if (rxchainmask)
5453 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005454
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005455 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005456}
5457
5458
5459void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5460{
5461 if (strcasecmp(val, "enable") == 0) {
5462 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5463 != 0) {
5464 sigma_dut_print(dut, DUT_MSG_ERROR,
5465 "Disable BB_VHTSIGB_CRC_CALC failed");
5466 }
5467
5468 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5469 != 0) {
5470 sigma_dut_print(dut, DUT_MSG_ERROR,
5471 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5472 }
5473 } else {
5474 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5475 != 0) {
5476 sigma_dut_print(dut, DUT_MSG_ERROR,
5477 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5478 }
5479
5480 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5481 != 0) {
5482 sigma_dut_print(dut, DUT_MSG_ERROR,
5483 "Enable BB_VHTSIGB_CRC_CALC failed");
5484 }
5485 }
5486}
5487
5488
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005489static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5490 const char *val)
5491{
5492 char buf[60];
5493
5494 if (strcmp(val, "20") == 0) {
5495 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5496 dut->chwidth = 0;
5497 } else if (strcmp(val, "40") == 0) {
5498 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5499 dut->chwidth = 1;
5500 } else if (strcmp(val, "80") == 0) {
5501 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5502 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305503 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005504 buf[0] = '\0';
5505 } else {
5506 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5507 val);
5508 return -1;
5509 }
5510
5511 if (buf[0] != '\0' && system(buf) != 0) {
5512 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5513 return -1;
5514 }
5515
5516 return 0;
5517}
5518
5519
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005520static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5521 const char *intf, int addbareject)
5522{
5523#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305524 return wcn_wifi_test_config_set_u8(
5525 dut, intf,
5526 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5527 !addbareject);
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005528#else /* NL80211_SUPPORT */
5529 sigma_dut_print(dut, DUT_MSG_ERROR,
5530 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5531 return -1;
5532#endif /* NL80211_SUPPORT */
5533}
5534
5535
5536static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5537 int addbareject)
5538{
5539 int ret;
5540
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005541 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005542 case DRIVER_WCN:
5543 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5544 if (ret) {
5545 sigma_dut_print(dut, DUT_MSG_ERROR,
5546 "nlvendor_sta_set_addba_reject failed, ret:%d",
5547 ret);
5548 return ret;
5549 }
5550 break;
5551 default:
5552 sigma_dut_print(dut, DUT_MSG_ERROR,
5553 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5554 ret = -1;
5555 break;
5556 }
5557
5558 return ret;
5559}
5560
5561
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005562static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5563 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005564{
5565#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05305566 return wcn_wifi_test_config_set_u8(
5567 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
5568 enable);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005569#else /* NL80211_SUPPORT */
5570 sigma_dut_print(dut, DUT_MSG_ERROR,
5571 "Disable addba not possible without NL80211_SUPPORT defined");
5572 return -1;
5573#endif /* NL80211_SUPPORT */
5574}
5575
5576
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305577#ifdef NL80211_SUPPORT
5578static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5579{
5580 struct nl_msg *msg;
5581 int ret = 0;
5582 int ifindex;
5583
5584 ifindex = if_nametoindex(intf);
5585 if (ifindex == 0) {
5586 sigma_dut_print(dut, DUT_MSG_ERROR,
5587 "%s: Index for interface %s failed",
5588 __func__, intf);
5589 return -1;
5590 }
5591
5592 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5593 NL80211_CMD_SET_WIPHY)) ||
5594 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5595 sigma_dut_print(dut, DUT_MSG_ERROR,
5596 "%s: err in adding RTS threshold",
5597 __func__);
5598 nlmsg_free(msg);
5599 return -1;
5600 }
5601
5602 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5603 if (ret) {
5604 sigma_dut_print(dut, DUT_MSG_ERROR,
5605 "%s: err in send_and_recv_msgs, ret=%d",
5606 __func__, ret);
5607 }
5608 return ret;
5609}
5610#endif /* NL80211_SUPPORT */
5611
5612
5613static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5614{
5615 char buf[100];
5616
5617#ifdef NL80211_SUPPORT
5618 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5619 return 0;
5620 sigma_dut_print(dut, DUT_MSG_DEBUG,
5621 "Fall back to using iwconfig for setting RTS threshold");
5622#endif /* NL80211_SUPPORT */
5623
5624 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5625 if (system(buf) != 0) {
5626 sigma_dut_print(dut, DUT_MSG_ERROR,
5627 "Failed to set RTS threshold %d", val);
5628 return -1;
5629 }
5630 return 0;
5631}
5632
5633
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005634static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5635 struct sigma_conn *conn,
5636 struct sigma_cmd *cmd)
5637{
5638 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005639 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005640 char buf[128];
5641 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005642
5643 val = get_param(cmd, "40_INTOLERANT");
5644 if (val) {
5645 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5646 /* TODO: iwpriv ht40intol through wpa_supplicant */
5647 send_resp(dut, conn, SIGMA_ERROR,
5648 "ErrorCode,40_INTOLERANT not supported");
5649 return 0;
5650 }
5651 }
5652
5653 val = get_param(cmd, "ADDBA_REJECT");
5654 if (val) {
5655 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5656 /* reject any ADDBA with status "decline" */
5657 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005658 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005659 } else {
5660 /* accept ADDBA */
5661 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005662 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005663 }
5664 }
5665
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005666 if (addbareject >= 0 &&
5667 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5668 send_resp(dut, conn, SIGMA_ERROR,
5669 "ErrorCode,set addba_reject failed");
5670 return 0;
5671 }
5672
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005673 val = get_param(cmd, "AMPDU");
5674 if (val) {
5675 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5676 /* enable AMPDU Aggregation */
5677 if (ampdu == 0) {
5678 send_resp(dut, conn, SIGMA_ERROR,
5679 "ErrorCode,Mismatch in "
5680 "addba_reject/ampdu - "
5681 "not supported");
5682 return 0;
5683 }
5684 ampdu = 1;
5685 } else {
5686 /* disable AMPDU Aggregation */
5687 if (ampdu == 1) {
5688 send_resp(dut, conn, SIGMA_ERROR,
5689 "ErrorCode,Mismatch in "
5690 "addba_reject/ampdu - "
5691 "not supported");
5692 return 0;
5693 }
5694 ampdu = 0;
5695 }
5696 }
5697
5698 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005699 int ret;
5700
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005701 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5702 ampdu ? "Enabling" : "Disabling");
5703 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005704 if (wpa_command(intf, buf) < 0 &&
5705 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005706 send_resp(dut, conn, SIGMA_ERROR,
5707 "ErrorCode,set aggr failed");
5708 return 0;
5709 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005710
5711 if (ampdu == 0) {
5712 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005713 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005714 if (ret) {
5715 sigma_dut_print(dut, DUT_MSG_ERROR,
5716 "Failed to disable addba, ret:%d",
5717 ret);
5718 }
5719 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005720 }
5721
5722 val = get_param(cmd, "AMSDU");
5723 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005724 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005725 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005726 case DRIVER_WCN:
5727 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005728 break;
5729 default:
5730 if (strcmp(val, "1") == 0 ||
5731 strcasecmp(val, "Enable") == 0) {
5732 /* Enable AMSDU Aggregation */
5733 send_resp(dut, conn, SIGMA_ERROR,
5734 "ErrorCode,AMSDU aggregation not supported");
5735 return 0;
5736 }
5737 break;
5738 }
5739 }
5740
5741 val = get_param(cmd, "STBC_RX");
5742 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005743 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005744 case DRIVER_ATHEROS:
5745 ath_sta_set_stbc(dut, intf, val);
5746 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305747 case DRIVER_WCN:
5748 wcn_sta_set_stbc(dut, intf, val);
5749 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005750 default:
5751 send_resp(dut, conn, SIGMA_ERROR,
5752 "ErrorCode,STBC_RX not supported");
5753 return 0;
5754 }
5755 }
5756
5757 val = get_param(cmd, "WIDTH");
5758 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005759 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005760 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005761 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762 send_resp(dut, conn, SIGMA_ERROR,
5763 "ErrorCode,Failed to set WIDTH");
5764 return 0;
5765 }
5766 break;
5767 case DRIVER_ATHEROS:
5768 if (ath_set_width(dut, conn, intf, val) < 0)
5769 return 0;
5770 break;
5771 default:
5772 sigma_dut_print(dut, DUT_MSG_ERROR,
5773 "Setting WIDTH not supported");
5774 break;
5775 }
5776 }
5777
5778 val = get_param(cmd, "SMPS");
5779 if (val) {
5780 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5781 send_resp(dut, conn, SIGMA_ERROR,
5782 "ErrorCode,SMPS not supported");
5783 return 0;
5784 }
5785
5786 val = get_param(cmd, "TXSP_STREAM");
5787 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005788 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005789 case DRIVER_WCN:
5790 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5791 send_resp(dut, conn, SIGMA_ERROR,
5792 "ErrorCode,Failed to set TXSP_STREAM");
5793 return 0;
5794 }
5795 break;
5796 case DRIVER_ATHEROS:
5797 ath_sta_set_txsp_stream(dut, intf, val);
5798 break;
5799 default:
5800 sigma_dut_print(dut, DUT_MSG_ERROR,
5801 "Setting TXSP_STREAM not supported");
5802 break;
5803 }
5804 }
5805
5806 val = get_param(cmd, "RXSP_STREAM");
5807 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005808 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005809 case DRIVER_WCN:
5810 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5811 send_resp(dut, conn, SIGMA_ERROR,
5812 "ErrorCode,Failed to set RXSP_STREAM");
5813 return 0;
5814 }
5815 break;
5816 case DRIVER_ATHEROS:
5817 ath_sta_set_rxsp_stream(dut, intf, val);
5818 break;
5819 default:
5820 sigma_dut_print(dut, DUT_MSG_ERROR,
5821 "Setting RXSP_STREAM not supported");
5822 break;
5823 }
5824 }
5825
5826 val = get_param(cmd, "DYN_BW_SGNL");
5827 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005828 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005829 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005830 if (strcasecmp(val, "enable") == 0) {
5831 snprintf(buf, sizeof(buf),
5832 "iwpriv %s cwmenable 1", intf);
5833 if (system(buf) != 0) {
5834 sigma_dut_print(dut, DUT_MSG_ERROR,
5835 "iwpriv cwmenable 1 failed");
5836 return 0;
5837 }
5838 } else if (strcasecmp(val, "disable") == 0) {
5839 snprintf(buf, sizeof(buf),
5840 "iwpriv %s cwmenable 0", intf);
5841 if (system(buf) != 0) {
5842 sigma_dut_print(dut, DUT_MSG_ERROR,
5843 "iwpriv cwmenable 0 failed");
5844 return 0;
5845 }
5846 } else {
5847 sigma_dut_print(dut, DUT_MSG_ERROR,
5848 "Unsupported DYN_BW_SGL");
5849 }
5850
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005851 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5852 if (system(buf) != 0) {
5853 sigma_dut_print(dut, DUT_MSG_ERROR,
5854 "Failed to set cts_cbw in DYN_BW_SGNL");
5855 return 0;
5856 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005857 break;
5858 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005859 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005860 ath_config_dyn_bw_sig(dut, intf, val);
5861 break;
5862 default:
5863 sigma_dut_print(dut, DUT_MSG_ERROR,
5864 "Failed to set DYN_BW_SGNL");
5865 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005866 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867 }
5868
5869 val = get_param(cmd, "RTS_FORCE");
5870 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005871 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005872 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305873 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005874 sigma_dut_print(dut, DUT_MSG_ERROR,
5875 "Failed to set RTS_FORCE 64");
5876 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005877 res = snprintf(buf, sizeof(buf),
5878 "wifitool %s beeliner_fw_test 100 1",
5879 intf);
5880 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005881 sigma_dut_print(dut, DUT_MSG_ERROR,
5882 "wifitool beeliner_fw_test 100 1 failed");
5883 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005884 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305885 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005886 sigma_dut_print(dut, DUT_MSG_ERROR,
5887 "Failed to set RTS_FORCE 2347");
5888 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005889 } else {
5890 send_resp(dut, conn, SIGMA_ERROR,
5891 "ErrorCode,RTS_FORCE value not supported");
5892 return 0;
5893 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005894 }
5895
5896 val = get_param(cmd, "CTS_WIDTH");
5897 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005898 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005899 case DRIVER_WCN:
5900 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5901 send_resp(dut, conn, SIGMA_ERROR,
5902 "ErrorCode,Failed to set CTS_WIDTH");
5903 return 0;
5904 }
5905 break;
5906 case DRIVER_ATHEROS:
5907 ath_set_cts_width(dut, intf, val);
5908 break;
5909 default:
5910 sigma_dut_print(dut, DUT_MSG_ERROR,
5911 "Setting CTS_WIDTH not supported");
5912 break;
5913 }
5914 }
5915
5916 val = get_param(cmd, "BW_SGNL");
5917 if (val) {
5918 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005919 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005920 } else if (strcasecmp(val, "Disable") == 0) {
5921 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005922 } else {
5923 send_resp(dut, conn, SIGMA_ERROR,
5924 "ErrorCode,BW_SGNL value not supported");
5925 return 0;
5926 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005927 }
5928
5929 val = get_param(cmd, "Band");
5930 if (val) {
5931 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5932 /* STA supports all bands by default */
5933 } else {
5934 send_resp(dut, conn, SIGMA_ERROR,
5935 "ErrorCode,Unsupported Band");
5936 return 0;
5937 }
5938 }
5939
5940 val = get_param(cmd, "zero_crc");
5941 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005942 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005943 case DRIVER_ATHEROS:
5944 ath_set_zero_crc(dut, val);
5945 break;
5946 default:
5947 break;
5948 }
5949 }
5950
5951 return 1;
5952}
5953
5954
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005955static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5956{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005957 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005958#ifdef __linux__
5959 case DRIVER_WIL6210:
5960 return wil6210_set_force_mcs(dut, force, mcs);
5961#endif /* __linux__ */
5962 default:
5963 sigma_dut_print(dut, DUT_MSG_ERROR,
5964 "Unsupported sta_set_force_mcs with the current driver");
5965 return -1;
5966 }
5967}
5968
5969
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005970static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5971{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005972 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005973#ifdef __linux__
5974 case DRIVER_WIL6210:
5975 return wil6210_force_rsn_ie(dut, state);
5976#endif /* __linux__ */
5977 default:
5978 sigma_dut_print(dut, DUT_MSG_ERROR,
5979 "Unsupported sta_60g_force_rsn_ie with the current driver");
5980 return -1;
5981 }
5982}
5983
5984
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005985static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5986 struct sigma_cmd *cmd)
5987{
5988 const char *val;
5989 char buf[100];
5990
5991 val = get_param(cmd, "MSDUSize");
5992 if (val) {
5993 int mtu;
5994
5995 dut->amsdu_size = atoi(val);
5996 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5997 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5998 sigma_dut_print(dut, DUT_MSG_ERROR,
5999 "MSDUSize %d is above max %d or below min %d",
6000 dut->amsdu_size,
6001 IEEE80211_MAX_DATA_LEN_DMG,
6002 IEEE80211_SNAP_LEN_DMG);
6003 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006004 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006005 }
6006
6007 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
6008 sigma_dut_print(dut, DUT_MSG_DEBUG,
6009 "Setting amsdu_size to %d", mtu);
6010 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006011 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006012
6013 if (system(buf) != 0) {
6014 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
6015 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006016 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006017 }
6018 }
6019
6020 val = get_param(cmd, "BAckRcvBuf");
6021 if (val) {
6022 dut->back_rcv_buf = atoi(val);
6023 if (dut->back_rcv_buf == 0) {
6024 sigma_dut_print(dut, DUT_MSG_ERROR,
6025 "Failed to convert %s or value is 0",
6026 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006027 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006028 }
6029
6030 sigma_dut_print(dut, DUT_MSG_DEBUG,
6031 "Setting BAckRcvBuf to %s", val);
6032 }
6033
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006034 val = get_param(cmd, "MCS_FixedRate");
6035 if (val) {
6036 if (sta_set_force_mcs(dut, 1, atoi(val))) {
6037 sigma_dut_print(dut, DUT_MSG_ERROR,
6038 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006039 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02006040 }
6041 }
6042
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006043 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006044}
6045
6046
6047static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
6048 struct sigma_cmd *cmd)
6049{
6050 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006051 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006052 const char *val;
6053 char buf[100];
6054
6055 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006056 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006057 if (wpa_command(ifname, "PING") != 0) {
6058 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006059 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006060 }
6061
6062 wpa_command(ifname, "FLUSH");
6063 net_id = add_network_common(dut, conn, ifname, cmd);
6064 if (net_id < 0) {
6065 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
6066 return net_id;
6067 }
6068
6069 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
6070 if (set_network(ifname, net_id, "mode", "2") < 0) {
6071 sigma_dut_print(dut, DUT_MSG_ERROR,
6072 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006073 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006074 }
6075
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02006076 if (set_network(ifname, net_id, "pbss", "1") < 0)
6077 return -2;
6078
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006079 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006080 "Supplicant set network with mode 2. network_id %d",
6081 net_id);
6082
6083 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
6084 sigma_dut_print(dut, DUT_MSG_INFO,
6085 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006086 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02006087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006088
6089 val = get_param(cmd, "Security");
6090 if (val && strcasecmp(val, "OPEN") == 0) {
6091 dut->ap_key_mgmt = AP_OPEN;
6092 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
6093 sigma_dut_print(dut, DUT_MSG_ERROR,
6094 "Failed to set supplicant to %s security",
6095 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006096 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006097 }
6098 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
6099 dut->ap_key_mgmt = AP_WPA2_PSK;
6100 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
6101 sigma_dut_print(dut, DUT_MSG_ERROR,
6102 "Failed to set supplicant to %s security",
6103 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006104 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006105 }
6106
6107 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
6108 sigma_dut_print(dut, DUT_MSG_ERROR,
6109 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006110 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006111 }
6112 } else if (val) {
6113 sigma_dut_print(dut, DUT_MSG_ERROR,
6114 "Requested Security %s is not supported on 60GHz",
6115 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006116 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006117 }
6118
6119 val = get_param(cmd, "Encrypt");
6120 if (val && strcasecmp(val, "AES-GCMP") == 0) {
6121 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
6122 sigma_dut_print(dut, DUT_MSG_ERROR,
6123 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006124 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006125 }
6126 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
6127 sigma_dut_print(dut, DUT_MSG_ERROR,
6128 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006129 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006130 }
6131 } else if (val) {
6132 sigma_dut_print(dut, DUT_MSG_ERROR,
6133 "Requested Encrypt %s is not supported on 60 GHz",
6134 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006135 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006136 }
6137
6138 val = get_param(cmd, "PSK");
6139 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6140 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6141 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006142 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006143 }
6144
6145 /* Convert 60G channel to freq */
6146 switch (dut->ap_channel) {
6147 case 1:
6148 val = "58320";
6149 break;
6150 case 2:
6151 val = "60480";
6152 break;
6153 case 3:
6154 val = "62640";
6155 break;
6156 default:
6157 sigma_dut_print(dut, DUT_MSG_ERROR,
6158 "Failed to configure channel %d. Not supported",
6159 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006160 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006161 }
6162
6163 if (set_network(ifname, net_id, "frequency", val) < 0) {
6164 sigma_dut_print(dut, DUT_MSG_ERROR,
6165 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006166 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006167 }
6168
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006169 if (dut->eap_fragment) {
6170 sigma_dut_print(dut, DUT_MSG_DEBUG,
6171 "Set EAP fragment size to 128 bytes.");
6172 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6173 return ERROR_SEND_STATUS;
6174 }
6175
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006176 sigma_dut_print(dut, DUT_MSG_DEBUG,
6177 "Supplicant set network with frequency");
6178
6179 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6180 if (wpa_command(ifname, buf) < 0) {
6181 sigma_dut_print(dut, DUT_MSG_INFO,
6182 "Failed to select network id %d on %s",
6183 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006184 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006185 }
6186
6187 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6188
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006189 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006190}
6191
6192
Lior David67543f52017-01-03 19:04:22 +02006193static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6194{
6195 char buf[128], fname[128];
6196 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006197 int res;
Lior David67543f52017-01-03 19:04:22 +02006198
6199 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6200 sigma_dut_print(dut, DUT_MSG_ERROR,
6201 "failed to get wil6210 debugfs dir");
6202 return -1;
6203 }
6204
Jouni Malinen3aa72862019-05-29 23:14:51 +03006205 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6206 if (res < 0 || res >= sizeof(fname))
6207 return -1;
Lior David67543f52017-01-03 19:04:22 +02006208 f = fopen(fname, "w");
6209 if (!f) {
6210 sigma_dut_print(dut, DUT_MSG_ERROR,
6211 "failed to open: %s", fname);
6212 return -1;
6213 }
6214
6215 fprintf(f, "%d\n", abft_len);
6216 fclose(f);
6217
6218 return 0;
6219}
6220
6221
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006222int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6223 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006224{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006225 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006226 case DRIVER_WIL6210:
6227 return wil6210_set_abft_len(dut, abft_len);
6228 default:
6229 sigma_dut_print(dut, DUT_MSG_ERROR,
6230 "set abft_len not supported");
6231 return -1;
6232 }
6233}
6234
6235
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006236static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6237 struct sigma_cmd *cmd)
6238{
6239 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006240 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006241
6242 if (dut->dev_role != DEVROLE_PCP) {
6243 send_resp(dut, conn, SIGMA_INVALID,
6244 "ErrorCode,Invalid DevRole");
6245 return 0;
6246 }
6247
6248 val = get_param(cmd, "SSID");
6249 if (val) {
6250 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6251 send_resp(dut, conn, SIGMA_INVALID,
6252 "ErrorCode,Invalid SSID");
6253 return -1;
6254 }
6255
Peng Xub8fc5cc2017-05-10 17:27:28 -07006256 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 }
6258
6259 val = get_param(cmd, "CHANNEL");
6260 if (val) {
6261 const char *pos;
6262
6263 dut->ap_channel = atoi(val);
6264 pos = strchr(val, ';');
6265 if (pos) {
6266 pos++;
6267 dut->ap_channel_1 = atoi(pos);
6268 }
6269 }
6270
6271 switch (dut->ap_channel) {
6272 case 1:
6273 case 2:
6274 case 3:
6275 break;
6276 default:
6277 sigma_dut_print(dut, DUT_MSG_ERROR,
6278 "Channel %d is not supported", dut->ap_channel);
6279 send_resp(dut, conn, SIGMA_ERROR,
6280 "Requested channel is not supported");
6281 return -1;
6282 }
6283
6284 val = get_param(cmd, "BCNINT");
6285 if (val)
6286 dut->ap_bcnint = atoi(val);
6287
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006288 val = get_param(cmd, "AllocType");
6289 if (val) {
6290 send_resp(dut, conn, SIGMA_ERROR,
6291 "ErrorCode,AllocType is not supported yet");
6292 return -1;
6293 }
6294
6295 val = get_param(cmd, "PercentBI");
6296 if (val) {
6297 send_resp(dut, conn, SIGMA_ERROR,
6298 "ErrorCode,PercentBI is not supported yet");
6299 return -1;
6300 }
6301
6302 val = get_param(cmd, "CBAPOnly");
6303 if (val) {
6304 send_resp(dut, conn, SIGMA_ERROR,
6305 "ErrorCode,CBAPOnly is not supported yet");
6306 return -1;
6307 }
6308
6309 val = get_param(cmd, "AMPDU");
6310 if (val) {
6311 if (strcasecmp(val, "Enable") == 0)
6312 dut->ap_ampdu = 1;
6313 else if (strcasecmp(val, "Disable") == 0)
6314 dut->ap_ampdu = 2;
6315 else {
6316 send_resp(dut, conn, SIGMA_ERROR,
6317 "ErrorCode,AMPDU value is not Enable nor Disabled");
6318 return -1;
6319 }
6320 }
6321
6322 val = get_param(cmd, "AMSDU");
6323 if (val) {
6324 if (strcasecmp(val, "Enable") == 0)
6325 dut->ap_amsdu = 1;
6326 else if (strcasecmp(val, "Disable") == 0)
6327 dut->ap_amsdu = 2;
6328 }
6329
6330 val = get_param(cmd, "NumMSDU");
6331 if (val) {
6332 send_resp(dut, conn, SIGMA_ERROR,
6333 "ErrorCode, NumMSDU is not supported yet");
6334 return -1;
6335 }
6336
6337 val = get_param(cmd, "ABFTLRang");
6338 if (val) {
6339 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006340 "ABFTLRang parameter %s", val);
6341 if (strcmp(val, "Gt1") == 0)
6342 abft_len = 2; /* 2 slots in this case */
6343 }
6344
6345 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6346 send_resp(dut, conn, SIGMA_ERROR,
6347 "ErrorCode, Can't set ABFT length");
6348 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006349 }
6350
6351 if (sta_pcp_start(dut, conn, cmd) < 0) {
6352 send_resp(dut, conn, SIGMA_ERROR,
6353 "ErrorCode, Can't start PCP role");
6354 return -1;
6355 }
6356
6357 return sta_set_60g_common(dut, conn, cmd);
6358}
6359
6360
6361static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6362 struct sigma_cmd *cmd)
6363{
6364 const char *val = get_param(cmd, "DiscoveryMode");
6365
6366 if (dut->dev_role != DEVROLE_STA) {
6367 send_resp(dut, conn, SIGMA_INVALID,
6368 "ErrorCode,Invalid DevRole");
6369 return 0;
6370 }
6371
6372 if (val) {
6373 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6374 /* Ignore Discovery mode till Driver expose API. */
6375#if 0
6376 if (strcasecmp(val, "1") == 0) {
6377 send_resp(dut, conn, SIGMA_INVALID,
6378 "ErrorCode,DiscoveryMode 1 not supported");
6379 return 0;
6380 }
6381
6382 if (strcasecmp(val, "0") == 0) {
6383 /* OK */
6384 } else {
6385 send_resp(dut, conn, SIGMA_INVALID,
6386 "ErrorCode,DiscoveryMode not supported");
6387 return 0;
6388 }
6389#endif
6390 }
6391
6392 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006393 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394 return sta_set_60g_common(dut, conn, cmd);
6395}
6396
6397
Jouni Malinenf7222712019-06-13 01:50:21 +03006398static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6399 struct sigma_conn *conn,
6400 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006401{
6402 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006403 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306404
Jouni Malinened77e672018-01-10 16:45:13 +02006405 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006406 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006407 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306408 wpa_command(intf, "DISCONNECT");
6409 return 1;
6410 }
6411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006412 disconnect_station(dut);
6413 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6414 * due to cached results. */
6415 wpa_command(intf, "SET ignore_old_scan_res 1");
6416 wpa_command(intf, "BSS_FLUSH");
6417 return 1;
6418}
6419
6420
Jouni Malinenf7222712019-06-13 01:50:21 +03006421static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6422 struct sigma_conn *conn,
6423 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006424{
6425 const char *intf = get_param(cmd, "Interface");
6426 const char *bssid = get_param(cmd, "bssid");
6427 const char *val = get_param(cmd, "CHANNEL");
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006428 const char *freq_val = get_param(cmd, "ChnlFreq");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006429 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306430 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306431 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006432 int res;
6433 int chan = 0;
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006434 int freq = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006435 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306436 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006437 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006438
6439 if (bssid == NULL) {
6440 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6441 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006442 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006443 }
6444
6445 if (val)
6446 chan = atoi(val);
6447
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006448 if (freq_val)
6449 freq = atoi(freq_val);
6450
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006451 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6452 /* The current network may be from sta_associate or
6453 * sta_hs2_associate
6454 */
6455 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6456 0 ||
6457 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006458 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459 }
6460
6461 ctrl = open_wpa_mon(intf);
6462 if (ctrl == NULL) {
6463 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6464 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006465 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006466 }
6467
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006468 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306469 sizeof(result)) < 0 ||
6470 strncmp(result, "COMPLETED", 9) != 0) {
6471 sigma_dut_print(dut, DUT_MSG_DEBUG,
6472 "sta_reassoc: Not connected");
6473 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006474 } else if (dut->sta_ft_ds) {
6475 sigma_dut_print(dut, DUT_MSG_DEBUG,
6476 "sta_reassoc: Use FT-over-DS");
6477 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306478 }
6479
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306480 if (dut->rsne_override) {
6481#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006482 if (get_driver_type(dut) == DRIVER_WCN &&
6483 dut->config_rsnie == 0) {
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05306484 sta_config_params(dut, intf, STA_SET_RSNIE, 1);
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306485 dut->config_rsnie = 1;
6486 }
6487#endif /* NL80211_SUPPORT */
6488 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6489 dut->rsne_override);
6490 if (wpa_command(intf, buf) < 0) {
6491 send_resp(dut, conn, SIGMA_ERROR,
6492 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6493 return 0;
6494 }
6495 }
6496
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006497 if (ft_ds) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006498 if (chan || freq) {
6499 if (!freq)
6500 freq = channel_to_freq(dut, chan);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006501 if (!freq) {
6502 sigma_dut_print(dut, DUT_MSG_ERROR,
6503 "Invalid channel number provided: %d",
6504 chan);
6505 send_resp(dut, conn, SIGMA_INVALID,
6506 "ErrorCode,Invalid channel number");
6507 goto close_mon_conn;
6508 }
6509 res = snprintf(buf, sizeof(buf),
6510 "SCAN TYPE=ONLY freq=%d", freq);
6511 } else {
6512 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6513 }
6514 if (res < 0 || res >= (int) sizeof(buf)) {
6515 send_resp(dut, conn, SIGMA_ERROR,
6516 "ErrorCode,snprintf failed");
6517 goto close_mon_conn;
6518 }
6519 if (wpa_command(intf, buf) < 0) {
6520 sigma_dut_print(dut, DUT_MSG_INFO,
6521 "Failed to start scan");
6522 send_resp(dut, conn, SIGMA_ERROR,
6523 "ErrorCode,scan failed");
6524 goto close_mon_conn;
6525 }
6526
6527 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6528 buf, sizeof(buf));
6529 if (res < 0) {
6530 sigma_dut_print(dut, DUT_MSG_INFO,
6531 "Scan did not complete");
6532 send_resp(dut, conn, SIGMA_ERROR,
6533 "ErrorCode,scan did not complete");
6534 goto close_mon_conn;
6535 }
6536
6537 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6538 if (res > 0 && res < (int) sizeof(buf))
6539 res = wpa_command(intf, buf);
6540
6541 if (res < 0 || res >= (int) sizeof(buf)) {
6542 send_resp(dut, conn, SIGMA_ERROR,
6543 "errorCode,FT_DS command failed");
6544 status = STATUS_SENT_ERROR;
6545 goto close_mon_conn;
6546 }
6547 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Kiran Kumar Lokere94a86b52020-06-03 23:25:19 -07006548 if (chan || freq) {
6549 if (!freq)
6550 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306551 if (!freq) {
6552 sigma_dut_print(dut, DUT_MSG_ERROR,
6553 "Invalid channel number provided: %d",
6554 chan);
6555 send_resp(dut, conn, SIGMA_INVALID,
6556 "ErrorCode,Invalid channel number");
6557 goto close_mon_conn;
6558 }
6559 res = snprintf(buf, sizeof(buf),
6560 "SCAN TYPE=ONLY freq=%d", freq);
6561 } else {
6562 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6563 }
6564 if (res < 0 || res >= (int) sizeof(buf)) {
6565 send_resp(dut, conn, SIGMA_ERROR,
6566 "ErrorCode,snprintf failed");
6567 goto close_mon_conn;
6568 }
6569 if (wpa_command(intf, buf) < 0) {
6570 sigma_dut_print(dut, DUT_MSG_INFO,
6571 "Failed to start scan");
6572 send_resp(dut, conn, SIGMA_ERROR,
6573 "ErrorCode,scan failed");
6574 goto close_mon_conn;
6575 }
6576
6577 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6578 buf, sizeof(buf));
6579 if (res < 0) {
6580 sigma_dut_print(dut, DUT_MSG_INFO,
6581 "Scan did not complete");
6582 send_resp(dut, conn, SIGMA_ERROR,
6583 "ErrorCode,scan did not complete");
6584 goto close_mon_conn;
6585 }
6586
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006587 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6588 < 0) {
6589 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6590 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006591 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306592 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593 }
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306594 res = snprintf(buf, sizeof(buf), "FASTREASSOC %s %d",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006595 bssid, chan);
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306596 if (res < 0 || res >= (int) sizeof(buf) ||
6597 wcn_driver_cmd(intf, buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006598 send_resp(dut, conn, SIGMA_ERROR,
Vinita Maloo54b78cf2020-03-30 12:18:19 +05306599 "errorCode,Failed to run FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306600 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006601 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006602 sigma_dut_print(dut, DUT_MSG_INFO,
6603 "sta_reassoc: Run %s successful", buf);
6604 } else if (wpa_command(intf, "REASSOCIATE")) {
6605 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6606 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306607 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006608 }
6609
6610 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6611 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306612 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006613 send_resp(dut, conn, SIGMA_ERROR,
6614 "errorCode,Connection did not complete");
6615 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306616 goto close_mon_conn;
6617 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006618 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619
Ashwini Patil467efef2017-05-25 12:18:27 +05306620close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006621 wpa_ctrl_detach(ctrl);
6622 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306623 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006624}
6625
6626
6627static void hs2_clear_credentials(const char *intf)
6628{
6629 wpa_command(intf, "REMOVE_CRED all");
6630}
6631
6632
Lior Davidcc88b562017-01-03 18:52:09 +02006633#ifdef __linux__
6634static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6635 unsigned int *aid)
6636{
Lior David0fe101e2017-03-09 16:09:50 +02006637 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006638
Lior David0fe101e2017-03-09 16:09:50 +02006639 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006640}
6641#endif /* __linux__ */
6642
6643
6644static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6645 unsigned int *aid)
6646{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006647 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006648#ifdef __linux__
6649 case DRIVER_WIL6210:
6650 return wil6210_get_aid(dut, bssid, aid);
6651#endif /* __linux__ */
6652 default:
6653 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6654 return -1;
6655 }
6656}
6657
6658
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006659static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6660 struct sigma_cmd *cmd)
6661{
6662 char buf[MAX_CMD_LEN];
6663 char bss_list[MAX_CMD_LEN];
6664 const char *parameter = get_param(cmd, "Parameter");
6665
6666 if (parameter == NULL)
6667 return -1;
6668
Lior Davidcc88b562017-01-03 18:52:09 +02006669 if (strcasecmp(parameter, "AID") == 0) {
6670 unsigned int aid = 0;
6671 char bssid[20];
6672
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006673 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006674 bssid, sizeof(bssid)) < 0) {
6675 sigma_dut_print(dut, DUT_MSG_ERROR,
6676 "could not get bssid");
6677 return -2;
6678 }
6679
6680 if (sta_get_aid_60g(dut, bssid, &aid))
6681 return -2;
6682
6683 snprintf(buf, sizeof(buf), "aid,%d", aid);
6684 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6685 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6686 return 0;
6687 }
6688
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006689 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6690 char *bss_line;
6691 char *bss_id = NULL;
6692 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306693 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006694
6695 if (ifname == NULL) {
6696 sigma_dut_print(dut, DUT_MSG_INFO,
6697 "For get DiscoveredDevList need Interface name.");
6698 return -1;
6699 }
6700
6701 /*
6702 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6703 * of BSSIDs in "bssid=<BSSID>\n"
6704 */
6705 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6706 bss_list,
6707 sizeof(bss_list)) < 0) {
6708 sigma_dut_print(dut, DUT_MSG_ERROR,
6709 "Failed to get bss list");
6710 return -1;
6711 }
6712
6713 sigma_dut_print(dut, DUT_MSG_DEBUG,
6714 "bss list for ifname:%s is:%s",
6715 ifname, bss_list);
6716
6717 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306718 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006719 while (bss_line) {
6720 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6721 bss_id) {
6722 int len;
6723
6724 len = snprintf(buf + strlen(buf),
6725 sizeof(buf) - strlen(buf),
6726 ",%s", bss_id);
6727 free(bss_id);
6728 bss_id = NULL;
6729 if (len < 0) {
6730 sigma_dut_print(dut,
6731 DUT_MSG_ERROR,
6732 "Failed to read BSSID");
6733 send_resp(dut, conn, SIGMA_ERROR,
6734 "ErrorCode,Failed to read BSS ID");
6735 return 0;
6736 }
6737
6738 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6739 sigma_dut_print(dut,
6740 DUT_MSG_ERROR,
6741 "Response buf too small for list");
6742 send_resp(dut, conn,
6743 SIGMA_ERROR,
6744 "ErrorCode,Response buf too small for list");
6745 return 0;
6746 }
6747 }
6748
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306749 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006750 }
6751
6752 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6753 buf);
6754 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6755 return 0;
6756 }
6757
6758 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6759 return 0;
6760}
6761
6762
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006763static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6764 struct sigma_cmd *cmd)
6765{
6766 char buf[MAX_CMD_LEN];
6767 const char *parameter = get_param(cmd, "Parameter");
6768
6769 if (!parameter)
6770 return -1;
6771
6772 if (strcasecmp(parameter, "RSSI") == 0) {
6773 char rssi[10];
6774
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006775 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006776 rssi, sizeof(rssi)) < 0) {
6777 sigma_dut_print(dut, DUT_MSG_ERROR,
6778 "Could not get RSSI");
6779 return -2;
6780 }
6781
6782 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6783 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6784 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6785 return 0;
6786 }
6787
6788 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6789 return 0;
6790}
6791
6792
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05306793#ifdef NL80211_SUPPORT
6794
6795struct station_info {
6796 uint64_t filled;
6797 uint32_t beacon_mic_error_count;
6798 uint32_t beacon_replay_count;
6799};
6800
6801
6802static int qca_get_sta_info_handler(struct nl_msg *msg, void *arg)
6803{
6804 struct nlattr *tb[NL80211_ATTR_MAX + 1];
6805 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
6806 struct station_info *data = arg;
6807 struct nlattr *info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1];
6808 static struct nla_policy info_policy[
6809 QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX + 1] = {
6810 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT] = {
6811 .type = NLA_U32
6812 },
6813 [QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT] = {
6814 .type = NLA_U32
6815 },
6816 };
6817
6818 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
6819 genlmsg_attrlen(gnlh, 0), NULL);
6820
6821 if (!tb[NL80211_ATTR_VENDOR_DATA])
6822 return NL_SKIP;
6823
6824 if (nla_parse_nested(info, QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_MAX,
6825 tb[NL80211_ATTR_VENDOR_DATA], info_policy)) {
6826 return NL_SKIP;
6827 }
6828
6829 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]) {
6830 data->filled |=
6831 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT);
6832 data->beacon_mic_error_count =
6833 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT]);
6834 }
6835
6836 if (info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]) {
6837 data->filled |=
6838 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT);
6839 data->beacon_replay_count =
6840 nla_get_u32(info[QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT]);
6841 }
6842
6843 return NL_SKIP;
6844}
6845
6846
6847static int qca_nl80211_get_sta_info(struct sigma_dut *dut, const char *intf,
6848 struct station_info *sta_data)
6849{
6850 struct nl_msg *msg;
6851 int ifindex, ret;
6852
6853 ifindex = if_nametoindex(intf);
6854 if (ifindex == 0) {
6855 sigma_dut_print(dut, DUT_MSG_ERROR,
6856 "%s: Index for interface %s not found",
6857 __func__, intf);
6858 return -1;
6859 }
6860
6861 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6862 NL80211_CMD_VENDOR)) ||
6863 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6864 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6865 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6866 QCA_NL80211_VENDOR_SUBCMD_GET_STA_INFO)) {
6867 sigma_dut_print(dut, DUT_MSG_ERROR,
6868 "%s: err in adding vendor_cmd", __func__);
6869 nlmsg_free(msg);
6870 return -1;
6871 }
6872
6873 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg,
6874 qca_get_sta_info_handler, sta_data);
6875 if (ret) {
6876 sigma_dut_print(dut, DUT_MSG_ERROR,
6877 "%s: err in send_and_recv_msgs, ret=%d",
6878 __func__, ret);
6879 }
6880 return ret;
6881}
6882#endif /* NL80211_SUPPORT */
6883
6884
6885static int get_bip_mic_error_count(struct sigma_dut *dut,
6886 const char *ifname,
6887 unsigned int *count)
6888{
6889#ifdef NL80211_SUPPORT
6890 struct station_info sta_data;
6891#endif /* NL80211_SUPPORT */
6892
6893 if (get_driver_type(dut) != DRIVER_WCN) {
6894 sigma_dut_print(dut, DUT_MSG_ERROR,
6895 "BIP MIC error count not supported");
6896 return -1;
6897 }
6898
6899#ifdef NL80211_SUPPORT
6900 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6901 !(sta_data.filled &
6902 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_MIC_ERROR_COUNT))) {
6903 sigma_dut_print(dut, DUT_MSG_ERROR,
6904 "BIP MIC error count fetching failed");
6905 return -1;
6906 }
6907
6908 *count = sta_data.beacon_mic_error_count;
6909 return 0;
6910#else /* NL80211_SUPPORT */
6911 sigma_dut_print(dut, DUT_MSG_ERROR,
6912 "BIP MIC error count cannot be fetched without NL80211_SUPPORT defined");
6913 return -1;
6914#endif /* NL80211_SUPPORT */
6915}
6916
6917
6918static int get_cmac_replay_count(struct sigma_dut *dut, const char *ifname,
6919 unsigned int *count)
6920{
6921#ifdef NL80211_SUPPORT
6922 struct station_info sta_data;
6923#endif /* NL80211_SUPPORT */
6924
6925 if (get_driver_type(dut) != DRIVER_WCN) {
6926 sigma_dut_print(dut, DUT_MSG_ERROR,
6927 "CMAC reply count not supported");
6928 return -1;
6929 }
6930
6931#ifdef NL80211_SUPPORT
6932 if (qca_nl80211_get_sta_info(dut, ifname, &sta_data) != 0 ||
6933 !(sta_data.filled &
6934 BIT_ULL(QCA_WLAN_VENDOR_ATTR_GET_STA_INFO_BEACON_REPLAY_COUNT))) {
6935 sigma_dut_print(dut, DUT_MSG_ERROR,
6936 "CMAC replay count fetching failed");
6937 return -1;
6938 }
6939
6940 *count = sta_data.beacon_replay_count;
6941 return 0;
6942#else /* NL80211_SUPPORT */
6943 sigma_dut_print(dut, DUT_MSG_ERROR,
6944 "CMAC replay count cannot be fetched without NL80211_SUPPORT defined");
6945 return -1;
6946#endif /* NL80211_SUPPORT */
6947}
6948
6949
6950static enum sigma_cmd_result sta_get_parameter_wpa3(struct sigma_dut *dut,
6951 struct sigma_conn *conn,
6952 struct sigma_cmd *cmd)
6953{
6954 char buf[MAX_CMD_LEN];
6955 const char *ifname = get_param(cmd, "interface");
6956 const char *parameter = get_param(cmd, "Parameter");
6957 unsigned int val;
6958
6959 if (!ifname || !parameter)
6960 return INVALID_SEND_STATUS;
6961
6962 if (strcasecmp(parameter, "BIPMICErrors") == 0) {
6963 if (get_bip_mic_error_count(dut, ifname, &val)) {
6964 send_resp(dut, conn, SIGMA_ERROR,
6965 "ErrorCode,Failed to get BIPMICErrors");
6966 return STATUS_SENT_ERROR;
6967 }
6968 snprintf(buf, sizeof(buf), "BIPMICErrors,%d", val);
6969 sigma_dut_print(dut, DUT_MSG_INFO, "BIPMICErrors %s", buf);
6970 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6971 return STATUS_SENT;
6972 }
6973
6974 if (strcasecmp(parameter, "CMACReplays") == 0) {
6975 if (get_cmac_replay_count(dut, ifname, &val)) {
6976 send_resp(dut, conn, SIGMA_ERROR,
6977 "ErrorCode,Failed to get CMACReplays");
6978 return STATUS_SENT_ERROR;
6979 }
6980 snprintf(buf, sizeof(buf), "CMACReplays,%d", val);
6981 sigma_dut_print(dut, DUT_MSG_INFO, "CMACReplays %s", buf);
6982 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6983 return STATUS_SENT;
6984 }
6985
6986 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6987 return STATUS_SENT_ERROR;
6988}
6989
6990
Jouni Malinenca0abd32020-02-09 20:18:10 +02006991static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6992 struct sigma_conn *conn,
6993 struct sigma_cmd *cmd)
6994{
6995 const char *intf = get_param(cmd, "Interface");
6996 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6997
6998 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6999 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
7000 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
7001 send_resp(dut, conn, SIGMA_ERROR,
7002 "ErrorCode,PMKSA_GET not supported");
7003 return STATUS_SENT_ERROR;
7004 }
7005
7006 if (strncmp(buf, "FAIL", 4) == 0 ||
7007 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
7008 send_resp(dut, conn, SIGMA_ERROR,
7009 "ErrorCode,Could not find current network");
7010 return STATUS_SENT_ERROR;
7011 }
7012
7013 pos = buf;
7014 while (pos) {
7015 if (strncmp(pos, bssid, 17) == 0) {
7016 pos = strchr(pos, ' ');
7017 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307018 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007019 pos++;
7020 pos = strchr(pos, ' ');
7021 if (!pos)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307022 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007023 pos++;
7024 tmp = strchr(pos, ' ');
7025 if (!tmp)
Mohammad Asaad Akram956bfc32020-04-08 16:26:18 +05307026 break;
Jouni Malinenca0abd32020-02-09 20:18:10 +02007027 *tmp = '\0';
7028 break;
7029 }
Jouni Malinenca0abd32020-02-09 20:18:10 +02007030 pos = strchr(pos, '\n');
7031 if (pos)
7032 pos++;
7033 }
7034
7035 if (!pos) {
7036 send_resp(dut, conn, SIGMA_ERROR,
7037 "ErrorCode,PMK not available");
7038 return STATUS_SENT_ERROR;
7039 }
7040
7041 snprintf(resp, sizeof(resp), "PMK,%s", pos);
7042 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7043 return STATUS_SENT;
7044}
7045
7046
Jouni Malinenf7222712019-06-13 01:50:21 +03007047static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
7048 struct sigma_conn *conn,
7049 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007050{
7051 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02007052 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007053
Jouni Malinenca0abd32020-02-09 20:18:10 +02007054 if (!parameter)
7055 return INVALID_SEND_STATUS;
7056
7057 if (strcasecmp(parameter, "PMK") == 0)
7058 return sta_get_pmk(dut, conn, cmd);
7059
7060 if (!program)
7061 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007062
7063 if (strcasecmp(program, "P2PNFC") == 0)
7064 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
7065
7066 if (strcasecmp(program, "60ghz") == 0)
7067 return sta_get_parameter_60g(dut, conn, cmd);
7068
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07007069 if (strcasecmp(program, "he") == 0)
7070 return sta_get_parameter_he(dut, conn, cmd);
7071
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007072#ifdef ANDROID_NAN
7073 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07007074 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007075#endif /* ANDROID_NAN */
7076
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007077#ifdef MIRACAST
7078 if (strcasecmp(program, "WFD") == 0 ||
7079 strcasecmp(program, "DisplayR2") == 0)
7080 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
7081#endif /* MIRACAST */
Veerendranath Jakkamd0ad6ef2020-05-21 17:09:26 +05307082 if (strcasecmp(program, "WPA3") == 0)
7083 return sta_get_parameter_wpa3(dut, conn, cmd);
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007084
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007085 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7086 return 0;
7087}
7088
7089
7090static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
7091 const char *type)
7092{
7093 char buf[100];
7094
7095 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007096 run_iwpriv(dut, intf, "chwidth 2");
7097 run_iwpriv(dut, intf, "mode 11ACVHT80");
7098 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007099 }
7100
7101 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007102 run_iwpriv(dut, intf, "chwidth 0");
7103 run_iwpriv(dut, intf, "mode 11naht40");
7104 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007105 }
7106
7107 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007108 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007109
7110 /* Reset CTS width */
7111 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
7112 intf);
7113 if (system(buf) != 0) {
7114 sigma_dut_print(dut, DUT_MSG_ERROR,
7115 "wifitool %s beeliner_fw_test 54 0 failed",
7116 intf);
7117 }
7118
7119 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007120 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007121
7122 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
7123 if (system(buf) != 0) {
7124 sigma_dut_print(dut, DUT_MSG_ERROR,
7125 "iwpriv rts failed");
7126 }
7127 }
7128
7129 if (type && strcasecmp(type, "Testbed") == 0) {
7130 dut->testbed_flag_txsp = 1;
7131 dut->testbed_flag_rxsp = 1;
7132 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007133 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007134
7135 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007136 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007137
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007138 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007139
7140 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007141 run_iwpriv(dut, intf, "tx_stbc 0");
7142 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007143
7144 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007145 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007146 }
7147
7148 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007149 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07007150 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07007152 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007153 }
7154}
7155
7156
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007157#ifdef NL80211_SUPPORT
7158static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
7159 enum he_mcs_config mcs)
7160{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307161 return wcn_wifi_test_config_set_u8(
7162 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS, mcs);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007163}
7164#endif /* NL80211_SUPPORT */
7165
7166
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007167static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
7168 const char *intf, int enable)
7169{
7170#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307171 return wcn_wifi_test_config_set_u8(
7172 dut, intf,
7173 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
7174 enable);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007175#else /* NL80211_SUPPORT */
7176 sigma_dut_print(dut, DUT_MSG_ERROR,
7177 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
7178 return -1;
7179#endif /* NL80211_SUPPORT */
7180}
7181
7182
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007183static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
7184 const char *intf, int enable)
7185{
7186#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307187 return wcn_wifi_test_config_set_u8(
7188 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
7189 enable);
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007190#else /* NL80211_SUPPORT */
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
7193 return -1;
7194#endif /* NL80211_SUPPORT */
7195}
7196
7197
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007198#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007199
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007200static int sta_set_he_testbed_def(struct sigma_dut *dut,
7201 const char *intf, int cfg)
7202{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307203 return wcn_wifi_test_config_set_u8(
7204 dut, intf,
7205 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
7206 cfg);
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007207}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007208
7209
7210static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7211{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307212 return wcn_wifi_test_config_set_u8(
7213 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7214 cfg);
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007215}
7216
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007217#endif /* NL80211_SUPPORT */
7218
7219
Qiwei Caib6806972020-01-15 13:52:11 +08007220int sta_set_addba_buf_size(struct sigma_dut *dut,
7221 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007222{
7223#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307224 return wcn_wifi_test_config_set_u16(
7225 dut, intf,
7226 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE, bufsize);
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007227#else /* NL80211_SUPPORT */
7228 sigma_dut_print(dut, DUT_MSG_ERROR,
7229 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7230 return -1;
7231#endif /* NL80211_SUPPORT */
7232}
7233
7234
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007235static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7236 int enable)
7237{
7238#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307239 return wcn_wifi_test_config_set_u8(
7240 dut, intf,
7241 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7242 enable);
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007243#else /* NL80211_SUPPORT */
7244 sigma_dut_print(dut, DUT_MSG_ERROR,
7245 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7246 return -1;
7247#endif /* NL80211_SUPPORT */
7248}
7249
7250
Arif Hussain9765f7d2018-07-03 08:28:26 -07007251static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7252 int val)
7253{
7254#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307255 return wcn_wifi_test_config_set_u8(
7256 dut, intf,
7257 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7258 val);
Arif Hussain9765f7d2018-07-03 08:28:26 -07007259#else /* NL80211_SUPPORT */
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7262 return -1;
7263#endif /* NL80211_SUPPORT */
7264}
7265
7266
Arif Hussain68d23f52018-07-11 13:39:08 -07007267#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007268static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7269 enum qca_wlan_he_mac_padding_dur val)
7270{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307271 return wcn_wifi_test_config_set_u8(
7272 dut, intf,
7273 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR, val);
Arif Hussain68d23f52018-07-11 13:39:08 -07007274}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007275#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007276
7277
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007278static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7279 int val)
7280{
7281#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307282 return wcn_wifi_test_config_set_u8(
7283 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7284 val);
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007285#else /* NL80211_SUPPORT */
7286 sigma_dut_print(dut, DUT_MSG_ERROR,
7287 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7288 return -1;
7289#endif /* NL80211_SUPPORT */
7290}
7291
7292
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007293#ifdef NL80211_SUPPORT
7294static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7295{
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307296 return wcn_wifi_test_config_set_flag(
7297 dut, intf,
7298 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG);
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007299}
7300#endif /* NL80211_SUPPORT */
7301
7302
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007303static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7304 int val)
7305{
7306#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307307 return wcn_wifi_test_config_set_u8(
7308 dut, intf,
7309 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA, val);
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007310#else /* NL80211_SUPPORT */
7311 sigma_dut_print(dut, DUT_MSG_ERROR,
7312 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7313 return -1;
7314#endif /* NL80211_SUPPORT */
7315}
7316
7317
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007318static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7319 int val)
7320{
7321#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307322 return wcn_wifi_test_config_set_u8(
7323 dut, intf,
7324 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP, val);
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007325#else /* NL80211_SUPPORT */
7326 sigma_dut_print(dut, DUT_MSG_ERROR,
7327 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7328 return -1;
7329#endif /* NL80211_SUPPORT */
7330}
7331
7332
Arif Hussain480d5f42019-03-12 14:40:42 -07007333static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7334 int val)
7335{
7336#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +05307337 return wcn_wifi_test_config_set_u8(
7338 dut, intf,
7339 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT, val);
Arif Hussain480d5f42019-03-12 14:40:42 -07007340#else /* NL80211_SUPPORT */
7341 sigma_dut_print(dut, DUT_MSG_ERROR,
7342 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7343 return -1;
7344#endif /* NL80211_SUPPORT */
7345}
7346
7347
Srinivas Girigowda0525e292020-11-12 13:28:21 -08007348static int sta_set_fullbw_ulmumimo(struct sigma_dut *dut, const char *intf,
7349 int val)
7350{
7351#ifdef NL80211_SUPPORT
7352 return wcn_wifi_test_config_set_u8(
7353 dut, intf,
7354 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FULL_BW_UL_MU_MIMO, val);
7355#else /* NL80211_SUPPORT */
7356 sigma_dut_print(dut, DUT_MSG_ERROR,
7357 "Full BW UL MU MIMO cannot be changed without NL80211_SUPPORT defined");
7358 return -1;
7359#endif /* NL80211_SUPPORT */
7360}
7361
7362
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007363static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7364 const char *type)
7365{
7366 char buf[60];
7367
7368 if (dut->program == PROGRAM_HE) {
7369 /* resetting phymode to auto in case of HE program */
Vinita S. Maloo13a5cf72020-05-22 14:45:06 +05307370 sta_set_phymode(dut, intf, "auto");
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007371
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007372 /* reset the rate to Auto rate */
7373 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7374 intf);
7375 if (system(buf) != 0) {
7376 sigma_dut_print(dut, DUT_MSG_ERROR,
7377 "iwpriv %s set_11ax_rate 0xff failed",
7378 intf);
7379 }
7380
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007381 /* reset the LDPC setting */
7382 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7383 if (system(buf) != 0) {
7384 sigma_dut_print(dut, DUT_MSG_ERROR,
7385 "iwpriv %s ldpc 1 failed", intf);
7386 }
7387
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007388 /* reset the power save setting */
Vinita S. Malooa8b62722020-04-23 01:45:41 +05307389 set_power_save_wcn(dut, intf, 2);
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007390
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007391 /* remove all network profiles */
7392 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007393
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007394 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7395 sta_set_addba_buf_size(dut, intf, 64);
7396
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007397#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007398 /* Reset the device HE capabilities to its default supported
7399 * configuration. */
7400 sta_set_he_testbed_def(dut, intf, 0);
7401
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007402 /* Disable noackpolicy for all AC */
7403 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7404 sigma_dut_print(dut, DUT_MSG_ERROR,
7405 "Disable of noackpolicy for all AC failed");
7406 }
7407#endif /* NL80211_SUPPORT */
7408
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007409 /* Enable WMM by default */
7410 if (wcn_sta_set_wmm(dut, intf, "on")) {
7411 sigma_dut_print(dut, DUT_MSG_ERROR,
7412 "Enable of WMM in sta_reset_default_wcn failed");
7413 }
7414
7415 /* Disable ADDBA_REJECT by default */
7416 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7417 sigma_dut_print(dut, DUT_MSG_ERROR,
7418 "Disable of addba_reject in sta_reset_default_wcn failed");
7419 }
7420
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007421 /* Enable sending of ADDBA by default */
7422 if (nlvendor_config_send_addba(dut, intf, 1)) {
7423 sigma_dut_print(dut, DUT_MSG_ERROR,
7424 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7425 }
7426
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007427 /* Enable AMPDU by default */
7428 iwpriv_sta_set_ampdu(dut, intf, 1);
7429
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007430#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007431 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007432 sigma_dut_print(dut, DUT_MSG_ERROR,
7433 "Set LTF config to default in sta_reset_default_wcn failed");
7434 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007435
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007436 /* set the beamformee NSTS(maximum number of
7437 * space-time streams) to default DUT config
7438 */
7439 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007440 sigma_dut_print(dut, DUT_MSG_ERROR,
7441 "Failed to set BeamformeeSTS");
7442 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007443
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007444 if (sta_set_mac_padding_duration(
7445 dut, intf,
7446 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007447 sigma_dut_print(dut, DUT_MSG_ERROR,
7448 "Failed to set MAC padding duration");
7449 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007450
7451 if (sta_set_mu_edca_override(dut, intf, 0)) {
7452 sigma_dut_print(dut, DUT_MSG_ERROR,
7453 "ErrorCode,Failed to set MU EDCA override disable");
7454 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007455
7456 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7457 sigma_dut_print(dut, DUT_MSG_ERROR,
7458 "Failed to set OM ctrl supp");
7459 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007460
7461 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7462 sigma_dut_print(dut, DUT_MSG_ERROR,
7463 "Failed to set Tx SU PPDU enable");
7464 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007465
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007466 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7467 sigma_dut_print(dut, DUT_MSG_ERROR,
7468 "failed to send TB PPDU Tx cfg");
7469 }
7470
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007471 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7472 sigma_dut_print(dut, DUT_MSG_ERROR,
7473 "Failed to set OM ctrl reset");
7474 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007475
7476 /* +HTC-HE support default on */
7477 if (sta_set_he_htc_supp(dut, intf, 1)) {
7478 sigma_dut_print(dut, DUT_MSG_ERROR,
7479 "Setting of +HTC-HE support failed");
7480 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007481#endif /* NL80211_SUPPORT */
7482
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007483 if (sta_set_tx_beamformee(dut, intf, 1)) {
7484 sigma_dut_print(dut, DUT_MSG_ERROR,
7485 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7486 }
7487
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007488 wpa_command(intf, "SET oce 1");
7489
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007490 /* Set nss to 1 and MCS 0-7 in case of testbed */
7491 if (type && strcasecmp(type, "Testbed") == 0) {
7492#ifdef NL80211_SUPPORT
7493 int ret;
7494#endif /* NL80211_SUPPORT */
7495
Kiran Kumar Lokereb55ff442020-07-15 00:20:40 -07007496 wpa_command(intf, "SET oce 0");
7497
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007498 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7499 if (system(buf) != 0) {
7500 sigma_dut_print(dut, DUT_MSG_ERROR,
7501 "iwpriv %s nss failed", intf);
7502 }
7503
7504#ifdef NL80211_SUPPORT
7505 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7506 if (ret) {
7507 sigma_dut_print(dut, DUT_MSG_ERROR,
7508 "Setting of MCS failed, ret:%d",
7509 ret);
7510 }
7511#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007512
7513 /* Disable STBC as default */
7514 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007515
7516 /* Disable AMSDU as default */
7517 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007518
7519#ifdef NL80211_SUPPORT
7520 /* HE fragmentation default off */
7521 if (sta_set_he_fragmentation(dut, intf,
7522 HE_FRAG_DISABLE)) {
7523 sigma_dut_print(dut, DUT_MSG_ERROR,
7524 "Setting of HE fragmentation failed");
7525 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007526
7527 /* set the beamformee NSTS(maximum number of
7528 * space-time streams) to default testbed config
7529 */
7530 if (sta_set_beamformee_sts(dut, intf, 3)) {
7531 sigma_dut_print(dut, DUT_MSG_ERROR,
7532 "Failed to set BeamformeeSTS");
7533 }
7534
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007535 /* +HTC-HE support default off */
7536 if (sta_set_he_htc_supp(dut, intf, 0)) {
7537 sigma_dut_print(dut, DUT_MSG_ERROR,
7538 "Setting of +HTC-HE support failed");
7539 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007540
7541 /* Set device HE capabilities to testbed default
7542 * configuration. */
7543 if (sta_set_he_testbed_def(dut, intf, 1)) {
7544 sigma_dut_print(dut, DUT_MSG_DEBUG,
7545 "Failed to set HE defaults");
7546 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007547
7548 /* Disable VHT support in 2.4 GHz for testbed */
7549 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007550#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007551
7552 /* Enable WEP/TKIP with HE capability in testbed */
7553 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7554 sigma_dut_print(dut, DUT_MSG_ERROR,
7555 "Enabling HE config with WEP/TKIP failed");
7556 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007557 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007558
7559 /* Defaults in case of DUT */
7560 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007561 /* Enable STBC by default */
7562 wcn_sta_set_stbc(dut, intf, "1");
7563
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007564 /* set nss to 2 */
7565 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7566 if (system(buf) != 0) {
7567 sigma_dut_print(dut, DUT_MSG_ERROR,
7568 "iwpriv %s nss 2 failed", intf);
7569 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007570 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007571
7572#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007573 /* Set HE_MCS to 0-11 */
7574 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007575 sigma_dut_print(dut, DUT_MSG_ERROR,
7576 "Setting of MCS failed");
7577 }
7578#endif /* NL80211_SUPPORT */
7579
7580 /* Disable WEP/TKIP with HE capability in DUT */
7581 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7582 sigma_dut_print(dut, DUT_MSG_ERROR,
7583 "Enabling HE config with WEP/TKIP failed");
7584 }
7585 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007586 }
7587}
7588
7589
Jouni Malinenf7222712019-06-13 01:50:21 +03007590static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7591 struct sigma_conn *conn,
7592 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007593{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007594 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007595 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007596 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007597 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307598 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007599
Jouni Malinenb21f0542019-11-04 17:53:38 +02007600 if (dut->station_ifname_2g &&
7601 strcmp(dut->station_ifname_2g, intf) == 0)
7602 dut->use_5g = 0;
7603 else if (dut->station_ifname_5g &&
7604 strcmp(dut->station_ifname_5g, intf) == 0)
7605 dut->use_5g = 1;
7606
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007607 if (!program)
7608 program = get_param(cmd, "prog");
7609 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007610 dut->device_type = STA_unknown;
7611 type = get_param(cmd, "type");
7612 if (type && strcasecmp(type, "Testbed") == 0)
7613 dut->device_type = STA_testbed;
7614 if (type && strcasecmp(type, "DUT") == 0)
7615 dut->device_type = STA_dut;
7616
7617 if (dut->program == PROGRAM_TDLS) {
7618 /* Clear TDLS testing mode */
7619 wpa_command(intf, "SET tdls_disabled 0");
7620 wpa_command(intf, "SET tdls_testing 0");
7621 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007622 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307623 /* Enable the WCN driver in TDLS Explicit trigger mode
7624 */
7625 wpa_command(intf, "SET tdls_external_control 0");
7626 wpa_command(intf, "SET tdls_trigger_control 0");
7627 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007628 }
7629
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007630#ifdef MIRACAST
7631 if (dut->program == PROGRAM_WFD ||
7632 dut->program == PROGRAM_DISPLAYR2)
7633 miracast_sta_reset_default(dut, conn, cmd);
7634#endif /* MIRACAST */
7635
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007636 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007637 case DRIVER_ATHEROS:
7638 sta_reset_default_ath(dut, intf, type);
7639 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007640 case DRIVER_WCN:
7641 sta_reset_default_wcn(dut, intf, type);
7642 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007643 default:
7644 break;
7645 }
7646
7647#ifdef ANDROID_NAN
7648 if (dut->program == PROGRAM_NAN)
7649 nan_cmd_sta_reset_default(dut, conn, cmd);
7650#endif /* ANDROID_NAN */
7651
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307652 if (dut->program == PROGRAM_LOC &&
7653 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7654 return ERROR_SEND_STATUS;
7655
Jouni Malinenba630452018-06-22 11:49:59 +03007656 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007657 unlink("SP/wi-fi.org/pps.xml");
7658 if (system("rm -r SP/*") != 0) {
7659 }
7660 unlink("next-client-cert.pem");
7661 unlink("next-client-key.pem");
7662 }
7663
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007664 /* For WPS program of the 60 GHz band the band type needs to be saved */
7665 if (dut->program == PROGRAM_WPS) {
7666 if (band && strcasecmp(band, "60GHz") == 0) {
7667 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007668 /* For 60 GHz enable WPS for WPS TCs */
7669 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007670 } else {
7671 dut->band = WPS_BAND_NON_60G;
7672 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007673 } else if (dut->program == PROGRAM_60GHZ) {
7674 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7675 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007676 }
7677
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007678 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007679 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007680 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007681
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007682 sigma_dut_print(dut, DUT_MSG_INFO,
7683 "WPS 60 GHz program, wps_disable = %d",
7684 dut->wps_disable);
7685
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007686 if (!dev_role) {
7687 send_resp(dut, conn, SIGMA_ERROR,
7688 "errorCode,Missing DevRole argument");
7689 return 0;
7690 }
7691
7692 if (strcasecmp(dev_role, "STA") == 0)
7693 dut->dev_role = DEVROLE_STA;
7694 else if (strcasecmp(dev_role, "PCP") == 0)
7695 dut->dev_role = DEVROLE_PCP;
7696 else {
7697 send_resp(dut, conn, SIGMA_ERROR,
7698 "errorCode,Unknown DevRole");
7699 return 0;
7700 }
7701
7702 if (dut->device_type == STA_unknown) {
7703 sigma_dut_print(dut, DUT_MSG_ERROR,
7704 "Device type is not STA testbed or DUT");
7705 send_resp(dut, conn, SIGMA_ERROR,
7706 "errorCode,Unknown device type");
7707 return 0;
7708 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007709
7710 sigma_dut_print(dut, DUT_MSG_DEBUG,
7711 "Setting msdu_size to MAX: 7912");
7712 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007713 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007714
7715 if (system(buf) != 0) {
7716 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7717 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007718 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007719 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007720
7721 if (sta_set_force_mcs(dut, 0, 1)) {
7722 sigma_dut_print(dut, DUT_MSG_ERROR,
7723 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007724 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007725 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007726 }
7727
7728 wpa_command(intf, "WPS_ER_STOP");
7729 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307730 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007731 wpa_command(intf, "SET radio_disabled 0");
7732
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007733 dut->wps_forced_version = 0;
7734
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007735 if (dut->wsc_fragment) {
7736 dut->wsc_fragment = 0;
7737 wpa_command(intf, "SET device_name Test client");
7738 wpa_command(intf, "SET manufacturer ");
7739 wpa_command(intf, "SET model_name ");
7740 wpa_command(intf, "SET model_number ");
7741 wpa_command(intf, "SET serial_number ");
7742 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007743 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7744 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7745 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7746 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007747
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007748 if (dut->tmp_mac_addr && dut->set_macaddr) {
7749 dut->tmp_mac_addr = 0;
7750 if (system(dut->set_macaddr) != 0) {
7751 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7752 "temporary MAC address");
7753 }
7754 }
7755
7756 set_ps(intf, dut, 0);
7757
Jouni Malinenba630452018-06-22 11:49:59 +03007758 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7759 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007760 wpa_command(intf, "SET interworking 1");
7761 wpa_command(intf, "SET hs20 1");
7762 }
7763
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007764 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007765 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007766 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007767 wpa_command(intf, "SET pmf 1");
7768 } else {
7769 wpa_command(intf, "SET pmf 0");
7770 }
7771
7772 hs2_clear_credentials(intf);
7773 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7774 wpa_command(intf, "SET access_network_type 15");
7775
7776 static_ip_file(0, NULL, NULL, NULL);
7777 kill_dhcp_client(dut, intf);
7778 clear_ip_addr(dut, intf);
7779
7780 dut->er_oper_performed = 0;
7781 dut->er_oper_bssid[0] = '\0';
7782
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007783 if (dut->program == PROGRAM_LOC) {
7784 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007785 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007786 }
7787
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -07007788 if (dut->program == PROGRAM_MBO || dut->program == PROGRAM_HE) {
Ashwini Patil00402582017-04-13 12:29:39 +05307789 free(dut->non_pref_ch_list);
7790 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307791 free(dut->btm_query_cand_list);
7792 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307793 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307794 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307795 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307796 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307797 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307798 }
7799
Jouni Malinen3c367e82017-06-23 17:01:47 +03007800 free(dut->rsne_override);
7801 dut->rsne_override = NULL;
7802
Jouni Malinen68143132017-09-02 02:34:08 +03007803 free(dut->sae_commit_override);
7804 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007805 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02007806 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03007807
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007808 dut->sta_associate_wait_connect = 0;
7809 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007810 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007811 dut->sta_tod_policy = 0;
7812
Jouni Malinend86e5822017-08-29 03:55:32 +03007813 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007814 free(dut->dpp_peer_uri);
7815 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007816 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007817 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinen90776b12020-05-04 15:34:46 +03007818 wpa_command(intf, "SET dpp_mud_url ");
Jouni Malinend86e5822017-08-29 03:55:32 +03007819
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007820 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7821
vamsi krishnaa2799492017-12-05 14:28:01 +05307822 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307823 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307824 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307825 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7826 dut->fils_hlp = 0;
7827#ifdef ANDROID
7828 hlp_thread_cleanup(dut);
7829#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307830 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307831
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05307832 if (dut->program == PROGRAM_QM)
7833 wpa_command(intf, "SET interworking 1");
7834
Jouni Malinen8179fee2019-03-28 03:19:47 +02007835 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007836 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007837
Sunil Dutt076081f2018-02-05 19:45:50 +05307838#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007839 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307840 dut->config_rsnie == 1) {
7841 dut->config_rsnie = 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05307842 sta_config_params(dut, intf, STA_SET_RSNIE, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307843 }
7844#endif /* NL80211_SUPPORT */
7845
Sunil Duttfebf8a82018-02-09 18:50:13 +05307846 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7847 dut->dev_role = DEVROLE_STA_CFON;
7848 return sta_cfon_reset_default(dut, conn, cmd);
7849 }
7850
Jouni Malinen439352d2018-09-13 03:42:23 +03007851 wpa_command(intf, "SET setband AUTO");
7852
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307853 dut->ocvc = 0;
Jouni Malinen67433fc2020-06-26 22:50:33 +03007854 dut->client_privacy = 0;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05307855 dut->saquery_oci_freq = 0;
Vamsi Krishnac1633d22020-05-06 18:31:21 +05307856
Sunil Duttfebf8a82018-02-09 18:50:13 +05307857 if (dut->program != PROGRAM_VHT)
7858 return cmd_sta_p2p_reset(dut, conn, cmd);
7859
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007860 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007861}
7862
7863
Jouni Malinenf7222712019-06-13 01:50:21 +03007864static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7865 struct sigma_conn *conn,
7866 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007867{
7868 const char *program = get_param(cmd, "Program");
7869
7870 if (program == NULL)
7871 return -1;
7872#ifdef ANDROID_NAN
7873 if (strcasecmp(program, "NAN") == 0)
7874 return nan_cmd_sta_get_events(dut, conn, cmd);
7875#endif /* ANDROID_NAN */
7876 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7877 return 0;
7878}
7879
7880
Jouni Malinen82905202018-04-29 17:20:10 +03007881static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7882 struct sigma_cmd *cmd)
7883{
7884 const char *url = get_param(cmd, "url");
7885 const char *method = get_param(cmd, "method");
7886 pid_t pid;
7887 int status;
7888
7889 if (!url || !method)
7890 return -1;
7891
7892 /* TODO: Add support for method,post */
7893 if (strcasecmp(method, "get") != 0) {
7894 send_resp(dut, conn, SIGMA_ERROR,
7895 "ErrorCode,Unsupported method");
7896 return 0;
7897 }
7898
7899 pid = fork();
7900 if (pid < 0) {
7901 perror("fork");
7902 return -1;
7903 }
7904
7905 if (pid == 0) {
7906 char * argv[5] = { "wget", "-O", "/dev/null",
7907 (char *) url, NULL };
7908
7909 execv("/usr/bin/wget", argv);
7910 perror("execv");
7911 exit(0);
7912 return -1;
7913 }
7914
7915 if (waitpid(pid, &status, 0) < 0) {
7916 perror("waitpid");
7917 return -1;
7918 }
7919
7920 if (WIFEXITED(status)) {
7921 const char *errmsg;
7922
7923 if (WEXITSTATUS(status) == 0)
7924 return 1;
7925 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7926 WEXITSTATUS(status));
7927 switch (WEXITSTATUS(status)) {
7928 case 4:
7929 errmsg = "errmsg,Network failure";
7930 break;
7931 case 8:
7932 errmsg = "errmsg,Server issued an error response";
7933 break;
7934 default:
7935 errmsg = "errmsg,Unknown failure from wget";
7936 break;
7937 }
7938 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7939 return 0;
7940 }
7941
7942 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7943 return 0;
7944}
7945
7946
Jouni Malinenf7222712019-06-13 01:50:21 +03007947static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7948 struct sigma_conn *conn,
7949 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007950{
7951 const char *program = get_param(cmd, "Prog");
7952
Jouni Malinen82905202018-04-29 17:20:10 +03007953 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007954 return -1;
7955#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007956 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007957 return nan_cmd_sta_exec_action(dut, conn, cmd);
7958#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007959
7960 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007961 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007962
7963 if (get_param(cmd, "url"))
7964 return sta_exec_action_url(dut, conn, cmd);
7965
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007966 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7967 return 0;
7968}
7969
7970
Jouni Malinenf7222712019-06-13 01:50:21 +03007971static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7972 struct sigma_conn *conn,
7973 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007974{
7975 const char *intf = get_param(cmd, "Interface");
7976 const char *val, *mcs32, *rate;
7977
7978 val = get_param(cmd, "GREENFIELD");
7979 if (val) {
7980 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7981 /* Enable GD */
7982 send_resp(dut, conn, SIGMA_ERROR,
7983 "ErrorCode,GF not supported");
7984 return 0;
7985 }
7986 }
7987
7988 val = get_param(cmd, "SGI20");
7989 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007990 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007991 case DRIVER_ATHEROS:
7992 ath_sta_set_sgi(dut, intf, val);
7993 break;
7994 default:
7995 send_resp(dut, conn, SIGMA_ERROR,
7996 "ErrorCode,SGI20 not supported");
7997 return 0;
7998 }
7999 }
8000
8001 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8002 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8003 if (mcs32 && rate) {
8004 /* TODO */
8005 send_resp(dut, conn, SIGMA_ERROR,
8006 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8007 return 0;
8008 } else if (mcs32 && !rate) {
8009 /* TODO */
8010 send_resp(dut, conn, SIGMA_ERROR,
8011 "ErrorCode,MCS32 not supported");
8012 return 0;
8013 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008014 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008015 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008016 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008017 ath_sta_set_11nrates(dut, intf, rate);
8018 break;
8019 default:
8020 send_resp(dut, conn, SIGMA_ERROR,
8021 "ErrorCode,MCS32_FIXEDRATE not supported");
8022 return 0;
8023 }
8024 }
8025
8026 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8027}
8028
8029
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008030static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8031 int mcs_config)
8032{
8033#ifdef NL80211_SUPPORT
8034 int ret;
8035
8036 switch (mcs_config) {
8037 case HE_80_MCS0_7:
8038 case HE_80_MCS0_9:
8039 case HE_80_MCS0_11:
8040 ret = sta_set_he_mcs(dut, intf, mcs_config);
8041 if (ret) {
8042 sigma_dut_print(dut, DUT_MSG_ERROR,
8043 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8044 mcs_config, ret);
8045 }
8046 break;
8047 default:
8048 sigma_dut_print(dut, DUT_MSG_ERROR,
8049 "cmd_set_max_he_mcs: Invalid mcs %d",
8050 mcs_config);
8051 break;
8052 }
8053#else /* NL80211_SUPPORT */
8054 sigma_dut_print(dut, DUT_MSG_ERROR,
8055 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8056#endif /* NL80211_SUPPORT */
8057}
8058
8059
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008060static int sta_twt_send_suspend(struct sigma_dut *dut, struct sigma_conn *conn,
8061 struct sigma_cmd *cmd)
8062{
8063#ifdef NL80211_SUPPORT
8064 struct nlattr *attr, *attr1;
8065 struct nl_msg *msg;
8066 int ifindex, ret;
8067 const char *intf = get_param(cmd, "Interface");
8068
8069 ifindex = if_nametoindex(intf);
8070 if (ifindex == 0) {
8071 sigma_dut_print(dut, DUT_MSG_ERROR,
8072 "%s: Index for interface %s failed",
8073 __func__, intf);
8074 return ERROR_SEND_STATUS;
8075 }
8076
8077 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8078 NL80211_CMD_VENDOR)) ||
8079 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8080 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8081 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8082 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8083 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8084 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8085 QCA_WLAN_TWT_SUSPEND) ||
8086 !(attr1 = nla_nest_start(msg,
8087 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8088 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_FLOW_ID, 0)) {
8089 sigma_dut_print(dut, DUT_MSG_ERROR,
8090 "%s: err in adding vendor_cmd and vendor_data",
8091 __func__);
8092 nlmsg_free(msg);
8093 return ERROR_SEND_STATUS;
8094 }
8095 nla_nest_end(msg, attr1);
8096 nla_nest_end(msg, attr);
8097
8098 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8099 if (ret) {
8100 sigma_dut_print(dut, DUT_MSG_ERROR,
8101 "%s: err in send_and_recv_msgs, ret=%d",
8102 __func__, ret);
8103 }
8104
8105 return ret;
8106#else /* NL80211_SUPPORT */
8107 sigma_dut_print(dut, DUT_MSG_ERROR,
8108 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8109 return ERROR_SEND_STATUS;
8110#endif /* NL80211_SUPPORT */
8111}
8112
8113
8114static int sta_twt_send_nudge(struct sigma_dut *dut, struct sigma_conn *conn,
8115 struct sigma_cmd *cmd,
8116 unsigned int suspend_duration)
8117{
8118#ifdef NL80211_SUPPORT
8119 struct nlattr *attr, *attr1;
8120 struct nl_msg *msg;
8121 int ifindex, ret;
8122 const char *intf = get_param(cmd, "Interface");
8123 int next_twt_size = 1;
8124
8125 ifindex = if_nametoindex(intf);
8126 if (ifindex == 0) {
8127 sigma_dut_print(dut, DUT_MSG_ERROR,
8128 "%s: Index for interface %s failed",
8129 __func__, intf);
8130 return ERROR_SEND_STATUS;
8131 }
8132
8133 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8134 NL80211_CMD_VENDOR)) ||
8135 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8136 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8137 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8138 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8139 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8140 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8141 QCA_WLAN_TWT_NUDGE) ||
8142 !(attr1 = nla_nest_start(msg,
8143 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8144 (suspend_duration &&
8145 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_WAKE_TIME,
8146 suspend_duration)) ||
8147 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_NUDGE_NEXT_TWT_SIZE,
8148 next_twt_size)) {
8149 sigma_dut_print(dut, DUT_MSG_ERROR,
8150 "%s: err in adding vendor_cmd and vendor_data",
8151 __func__);
8152 nlmsg_free(msg);
8153 return ERROR_SEND_STATUS;
8154 }
8155 nla_nest_end(msg, attr1);
8156 nla_nest_end(msg, attr);
8157
8158 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8159 if (ret) {
8160 sigma_dut_print(dut, DUT_MSG_ERROR,
8161 "%s: err in send_and_recv_msgs, ret=%d",
8162 __func__, ret);
8163 }
8164
8165 return ret;
8166#else /* NL80211_SUPPORT */
8167 sigma_dut_print(dut, DUT_MSG_ERROR,
8168 "TWT suspend cannot be done without NL80211_SUPPORT defined");
8169 return ERROR_SEND_STATUS;
8170#endif /* NL80211_SUPPORT */
8171}
8172
8173
8174static int sta_twt_suspend_or_nudge(struct sigma_dut *dut,
8175 struct sigma_conn *conn,
8176 struct sigma_cmd *cmd)
8177{
8178 const char *val;
8179
8180 val = get_param(cmd, "TWT_SuspendDuration");
8181 if (val) {
8182 unsigned int suspend_duration;
8183
8184 suspend_duration = atoi(val);
8185 suspend_duration = suspend_duration * 1000 * 1000;
8186 return sta_twt_send_nudge(dut, conn, cmd, suspend_duration);
8187 }
8188
8189 return sta_twt_send_suspend(dut, conn, cmd);
8190}
8191
8192
8193static int sta_twt_resume(struct sigma_dut *dut, struct sigma_conn *conn,
8194 struct sigma_cmd *cmd)
8195{
8196#ifdef NL80211_SUPPORT
8197 struct nlattr *attr, *attr1;
8198 struct nl_msg *msg;
8199 int ifindex, ret;
8200 const char *intf = get_param(cmd, "Interface");
8201 int next2_twt_size = 1;
8202 unsigned int resume_duration = 0;
8203 const char *val;
8204
8205 ifindex = if_nametoindex(intf);
8206 if (ifindex == 0) {
8207 sigma_dut_print(dut, DUT_MSG_ERROR,
8208 "%s: Index for interface %s failed",
8209 __func__, intf);
8210 return ERROR_SEND_STATUS;
8211 }
8212
8213 val = get_param(cmd, "TWT_ResumeDuration");
8214 if (val) {
8215 resume_duration = atoi(val);
8216 resume_duration = resume_duration * 1000 * 1000;
8217 }
8218
8219 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8220 NL80211_CMD_VENDOR)) ||
8221 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8222 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8223 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8224 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
8225 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8226 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8227 QCA_WLAN_TWT_RESUME) ||
8228 !(attr1 = nla_nest_start(msg,
8229 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
8230 (resume_duration &&
8231 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT2_TWT,
8232 resume_duration)) ||
8233 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_RESUME_NEXT_TWT_SIZE,
8234 next2_twt_size)) {
8235 sigma_dut_print(dut, DUT_MSG_ERROR,
8236 "%s: err in adding vendor_cmd and vendor_data",
8237 __func__);
8238 nlmsg_free(msg);
8239 return ERROR_SEND_STATUS;
8240 }
8241 nla_nest_end(msg, attr1);
8242 nla_nest_end(msg, attr);
8243
8244 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8245 if (ret) {
8246 sigma_dut_print(dut, DUT_MSG_ERROR,
8247 "%s: err in send_and_recv_msgs, ret=%d",
8248 __func__, ret);
8249 }
8250
8251 return ret;
8252#else /* NL80211_SUPPORT */
8253 sigma_dut_print(dut, DUT_MSG_ERROR,
8254 "TWT resume cannot be done without NL80211_SUPPORT defined");
8255 return ERROR_SEND_STATUS;
8256#endif /* NL80211_SUPPORT */
8257}
8258
8259
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008260#define TWT_REQUEST_CMD 0
8261#define TWT_SUGGEST_CMD 1
8262#define TWT_DEMAND_CMD 2
8263
Arif Hussain480d5f42019-03-12 14:40:42 -07008264static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8265 struct sigma_cmd *cmd)
8266{
8267#ifdef NL80211_SUPPORT
8268 struct nlattr *params;
8269 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07008270 struct nl_msg *msg;
8271 int ifindex, ret;
8272 const char *val;
8273 const char *intf = get_param(cmd, "Interface");
8274 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8275 wake_interval_mantissa = 512;
8276 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008277 protection = 0, cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
Arif Hussain480d5f42019-03-12 14:40:42 -07008278
8279 ifindex = if_nametoindex(intf);
8280 if (ifindex == 0) {
8281 sigma_dut_print(dut, DUT_MSG_ERROR,
8282 "%s: Index for interface %s failed",
8283 __func__, intf);
8284 return -1;
8285 }
8286
8287 val = get_param(cmd, "FlowType");
8288 if (val) {
8289 flow_type = atoi(val);
8290 if (flow_type != 0 && flow_type != 1) {
8291 sigma_dut_print(dut, DUT_MSG_ERROR,
8292 "TWT: Invalid FlowType %d", flow_type);
8293 return -1;
8294 }
8295 }
8296
8297 val = get_param(cmd, "TWT_Trigger");
8298 if (val) {
8299 twt_trigger = atoi(val);
8300 if (twt_trigger != 0 && twt_trigger != 1) {
8301 sigma_dut_print(dut, DUT_MSG_ERROR,
8302 "TWT: Invalid TWT_Trigger %d",
8303 twt_trigger);
8304 return -1;
8305 }
8306 }
8307
8308 val = get_param(cmd, "Protection");
8309 if (val) {
8310 protection = atoi(val);
8311 if (protection != 0 && protection != 1) {
8312 sigma_dut_print(dut, DUT_MSG_ERROR,
8313 "TWT: Invalid Protection %d",
8314 protection);
8315 return -1;
8316 }
8317 }
8318
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008319 val = get_param(cmd, "SetupCommand");
8320 if (val) {
8321 cmd_type = atoi(val);
8322 if (cmd_type == TWT_REQUEST_CMD)
8323 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_REQUEST;
8324 else if (cmd_type == TWT_SUGGEST_CMD)
8325 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_SUGGEST;
8326 else if (cmd_type == TWT_DEMAND_CMD)
8327 cmd_type = QCA_WLAN_VENDOR_TWT_SETUP_DEMAND;
8328 else
8329 sigma_dut_print(dut, DUT_MSG_ERROR,
8330 "Default suggest is used for cmd %d",
8331 cmd_type);
8332 }
8333
Arif Hussain480d5f42019-03-12 14:40:42 -07008334 val = get_param(cmd, "TargetWakeTime");
8335 if (val)
8336 target_wake_time = atoi(val);
8337
8338 val = get_param(cmd, "WakeIntervalMantissa");
8339 if (val)
8340 wake_interval_mantissa = atoi(val);
8341
8342 val = get_param(cmd, "WakeIntervalExp");
8343 if (val)
8344 wake_interval_exp = atoi(val);
8345
8346 val = get_param(cmd, "NominalMinWakeDur");
8347 if (val)
8348 nominal_min_wake_dur = atoi(val);
8349
8350 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8351 NL80211_CMD_VENDOR)) ||
8352 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8353 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8354 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008355 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008356 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008357 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8358 QCA_WLAN_TWT_SET) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008359 !(params = nla_nest_start(
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008360 msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008361 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8362 wake_interval_exp) ||
Kiran Kumar Lokerebd396102020-04-27 12:01:09 -07008363 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, cmd_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008364 (twt_trigger &&
8365 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008366 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8367 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008368 (protection &&
8369 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008370 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8371 target_wake_time) ||
8372 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8373 nominal_min_wake_dur) ||
8374 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8375 wake_interval_mantissa)) {
8376 sigma_dut_print(dut, DUT_MSG_ERROR,
8377 "%s: err in adding vendor_cmd and vendor_data",
8378 __func__);
8379 nlmsg_free(msg);
8380 return -1;
8381 }
Arif Hussain480d5f42019-03-12 14:40:42 -07008382 nla_nest_end(msg, params);
8383 nla_nest_end(msg, attr);
8384
8385 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8386 if (ret) {
8387 sigma_dut_print(dut, DUT_MSG_ERROR,
8388 "%s: err in send_and_recv_msgs, ret=%d",
8389 __func__, ret);
8390 }
8391
8392 return ret;
8393#else /* NL80211_SUPPORT */
8394 sigma_dut_print(dut, DUT_MSG_ERROR,
8395 "TWT request cannot be done without NL80211_SUPPORT defined");
8396 return -1;
8397#endif /* NL80211_SUPPORT */
8398}
8399
8400
8401static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8402 struct sigma_cmd *cmd)
8403{
8404 #ifdef NL80211_SUPPORT
8405 struct nlattr *params;
8406 struct nlattr *attr;
Arif Hussain480d5f42019-03-12 14:40:42 -07008407 int ifindex, ret;
8408 struct nl_msg *msg;
8409 const char *intf = get_param(cmd, "Interface");
8410
8411 ifindex = if_nametoindex(intf);
8412 if (ifindex == 0) {
8413 sigma_dut_print(dut, DUT_MSG_ERROR,
8414 "%s: Index for interface %s failed",
8415 __func__, intf);
8416 return -1;
8417 }
8418
8419 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8420 NL80211_CMD_VENDOR)) ||
8421 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8422 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8423 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008424 QCA_NL80211_VENDOR_SUBCMD_CONFIG_TWT) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008425 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008426 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_OPERATION,
8427 QCA_WLAN_TWT_TERMINATE) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008428 !(params = nla_nest_start(
8429 msg,
Srinivas Girigowda6707f032020-10-26 15:24:46 -07008430 QCA_WLAN_VENDOR_ATTR_CONFIG_TWT_PARAMS)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008431 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8432 sigma_dut_print(dut, DUT_MSG_ERROR,
8433 "%s: err in adding vendor_cmd and vendor_data",
8434 __func__);
8435 nlmsg_free(msg);
8436 return -1;
8437 }
Arif Hussain480d5f42019-03-12 14:40:42 -07008438 nla_nest_end(msg, params);
8439 nla_nest_end(msg, attr);
8440
8441 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8442 if (ret) {
8443 sigma_dut_print(dut, DUT_MSG_ERROR,
8444 "%s: err in send_and_recv_msgs, ret=%d",
8445 __func__, ret);
8446 }
8447
8448 return ret;
8449#else /* NL80211_SUPPORT */
8450 sigma_dut_print(dut, DUT_MSG_ERROR,
8451 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8452 return -1;
8453#endif /* NL80211_SUPPORT */
8454}
8455
8456
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008457static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8458 struct sigma_cmd *cmd)
8459{
8460#ifdef NL80211_SUPPORT
8461 struct nlattr *params;
8462 struct nlattr *attr;
8463 struct nlattr *attr1;
8464 struct nl_msg *msg;
8465 int ifindex, ret;
8466 const char *val;
8467 const char *intf = get_param(cmd, "Interface");
8468 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8469 ulmu_data_dis = 0;
8470
8471 ifindex = if_nametoindex(intf);
8472 if (ifindex == 0) {
8473 sigma_dut_print(dut, DUT_MSG_ERROR,
8474 "%s: Index for interface %s failed",
8475 __func__, intf);
8476 return -1;
8477 }
8478 val = get_param(cmd, "OMCtrl_RxNSS");
8479 if (val)
8480 rx_nss = atoi(val);
8481
8482 val = get_param(cmd, "OMCtrl_ChnlWidth");
8483 if (val)
8484 ch_bw = atoi(val);
8485
8486 val = get_param(cmd, "OMCtrl_ULMUDisable");
8487 if (val)
8488 ulmu_dis = atoi(val);
8489
8490 val = get_param(cmd, "OMCtrl_TxNSTS");
8491 if (val)
8492 tx_nsts = atoi(val);
8493
8494 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8495 if (val)
8496 ulmu_data_dis = atoi(val);
8497
8498 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8499 NL80211_CMD_VENDOR)) ||
8500 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8501 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8502 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8503 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8504 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8505 !(params = nla_nest_start(
8506 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8507 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8508 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8509 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8510 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8511 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8512 ulmu_data_dis) ||
8513 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8514 ulmu_dis)) {
8515 sigma_dut_print(dut, DUT_MSG_ERROR,
8516 "%s: err in adding vendor_cmd and vendor_data",
8517 __func__);
8518 nlmsg_free(msg);
8519 return -1;
8520 }
8521 nla_nest_end(msg, attr1);
8522 nla_nest_end(msg, params);
8523 nla_nest_end(msg, attr);
8524
8525 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8526 if (ret) {
8527 sigma_dut_print(dut, DUT_MSG_ERROR,
8528 "%s: err in send_and_recv_msgs, ret=%d",
8529 __func__, ret);
8530 }
8531
8532 return ret;
8533#else /* NL80211_SUPPORT */
8534 sigma_dut_print(dut, DUT_MSG_ERROR,
8535 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8536 return -1;
8537#endif /* NL80211_SUPPORT */
8538}
8539
8540
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008541static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8542 struct sigma_conn *conn,
8543 struct sigma_cmd *cmd)
8544{
8545 const char *intf = get_param(cmd, "Interface");
8546 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008547 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008548 int tkip = -1;
8549 int wep = -1;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308550 int iwpriv_status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008551
Arif Hussaina37e9552018-06-20 17:05:59 -07008552 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008553 val = get_param(cmd, "SGI80");
8554 if (val) {
8555 int sgi80;
8556
8557 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008558 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008559 }
8560
8561 val = get_param(cmd, "TxBF");
8562 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008563 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008564 case DRIVER_WCN:
8565 if (sta_set_tx_beamformee(dut, intf, 1)) {
8566 send_resp(dut, conn, SIGMA_ERROR,
8567 "ErrorCode,Failed to set TX beamformee enable");
8568 return 0;
8569 }
8570 break;
8571 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008572 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008573 send_resp(dut, conn, SIGMA_ERROR,
8574 "ErrorCode,Setting vhtsubfee failed");
8575 return 0;
8576 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008577 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008578 send_resp(dut, conn, SIGMA_ERROR,
8579 "ErrorCode,Setting vhtsubfer failed");
8580 return 0;
8581 }
8582 break;
8583 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008584 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008585 "Unsupported driver type");
8586 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008587 }
8588 }
8589
8590 val = get_param(cmd, "MU_TxBF");
8591 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008592 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008593 case DRIVER_ATHEROS:
8594 ath_sta_set_txsp_stream(dut, intf, "1SS");
8595 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008596 run_iwpriv(dut, intf, "vhtmubfee 1");
8597 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308598 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008599 case DRIVER_WCN:
8600 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8601 send_resp(dut, conn, SIGMA_ERROR,
8602 "ErrorCode,Failed to set RX/TXSP_STREAM");
8603 return 0;
8604 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308605 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008606 default:
8607 sigma_dut_print(dut, DUT_MSG_ERROR,
8608 "Setting SP_STREAM not supported");
8609 break;
8610 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008611 }
8612
8613 val = get_param(cmd, "LDPC");
8614 if (val) {
8615 int ldpc;
8616
8617 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308618 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", ldpc);
8619 if (iwpriv_status)
8620 sta_config_params(dut, intf, STA_SET_LDPC, ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008621 }
8622
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008623 val = get_param(cmd, "BCC");
8624 if (val) {
8625 int bcc;
8626
8627 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8628 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8629 * is mutually exclusive to bcc */
Mohammad Asaad Akram50848402020-05-28 14:10:24 +05308630 iwpriv_status = run_iwpriv(dut, intf, "ldpc %d", !bcc);
8631 if (iwpriv_status)
8632 sta_config_params(dut, intf, STA_SET_LDPC, !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008633 }
8634
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008635 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8636 if (val && dut->sta_nss == 1)
8637 cmd_set_max_he_mcs(dut, intf, atoi(val));
8638
8639 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8640 if (val && dut->sta_nss == 2)
8641 cmd_set_max_he_mcs(dut, intf, atoi(val));
8642
Arif Hussainac6c5112018-05-25 17:34:00 -07008643 val = get_param(cmd, "MCS_FixedRate");
8644 if (val) {
8645#ifdef NL80211_SUPPORT
8646 int mcs, ratecode = 0;
8647 enum he_mcs_config mcs_config;
8648 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008649 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008650
8651 ratecode = (0x07 & dut->sta_nss) << 5;
8652 mcs = atoi(val);
8653 /* Add the MCS to the ratecode */
8654 if (mcs >= 0 && mcs <= 11) {
8655 ratecode += mcs;
8656 if (dut->device_type == STA_testbed &&
8657 mcs > 7 && mcs <= 11) {
8658 if (mcs <= 9)
8659 mcs_config = HE_80_MCS0_9;
8660 else
8661 mcs_config = HE_80_MCS0_11;
8662 ret = sta_set_he_mcs(dut, intf, mcs_config);
8663 if (ret) {
8664 sigma_dut_print(dut, DUT_MSG_ERROR,
8665 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8666 mcs, mcs_config, ret);
8667 }
8668 }
8669 snprintf(buf, sizeof(buf),
8670 "iwpriv %s set_11ax_rate 0x%03x",
8671 intf, ratecode);
8672 if (system(buf) != 0) {
8673 sigma_dut_print(dut, DUT_MSG_ERROR,
8674 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8675 ratecode);
8676 }
8677 } else {
8678 sigma_dut_print(dut, DUT_MSG_ERROR,
8679 "MCS_FixedRate: HE MCS %d not supported",
8680 mcs);
8681 }
8682#else /* NL80211_SUPPORT */
8683 sigma_dut_print(dut, DUT_MSG_ERROR,
8684 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8685#endif /* NL80211_SUPPORT */
8686 }
8687
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008688 val = get_param(cmd, "opt_md_notif_ie");
8689 if (val) {
8690 char *result = NULL;
8691 char delim[] = ";";
8692 char token[30];
8693 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308694 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008695
Peng Xub8fc5cc2017-05-10 17:27:28 -07008696 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308697 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008698
8699 /* Extract the NSS information */
8700 if (result) {
8701 value = atoi(result);
8702 switch (value) {
8703 case 1:
8704 config_val = 1;
8705 break;
8706 case 2:
8707 config_val = 3;
8708 break;
8709 case 3:
8710 config_val = 7;
8711 break;
8712 case 4:
8713 config_val = 15;
8714 break;
8715 default:
8716 config_val = 3;
8717 break;
8718 }
8719
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008720 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8721 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008722
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008723 }
8724
8725 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308726 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008727 if (result) {
8728 value = atoi(result);
8729 switch (value) {
8730 case 20:
8731 config_val = 0;
8732 break;
8733 case 40:
8734 config_val = 1;
8735 break;
8736 case 80:
8737 config_val = 2;
8738 break;
8739 case 160:
8740 config_val = 3;
8741 break;
8742 default:
8743 config_val = 2;
8744 break;
8745 }
8746
8747 dut->chwidth = config_val;
8748
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008749 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008750 }
8751
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008752 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008753 }
8754
8755 val = get_param(cmd, "nss_mcs_cap");
8756 if (val) {
8757 int nss, mcs;
8758 char token[20];
8759 char *result = NULL;
8760 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308761 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008762
Peng Xub8fc5cc2017-05-10 17:27:28 -07008763 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308764 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308765 if (!result) {
8766 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008767 "NSS not specified");
8768 send_resp(dut, conn, SIGMA_ERROR,
8769 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308770 return 0;
8771 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008772 nss = atoi(result);
8773
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008774 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008775 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008776
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308777 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008778 if (result == NULL) {
8779 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008780 "MCS not specified");
8781 send_resp(dut, conn, SIGMA_ERROR,
8782 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008783 return 0;
8784 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308785 result = strtok_r(result, "-", &saveptr);
8786 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308787 if (!result) {
8788 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008789 "MCS not specified");
8790 send_resp(dut, conn, SIGMA_ERROR,
8791 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308792 return 0;
8793 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008794 mcs = atoi(result);
8795
Arif Hussaina37e9552018-06-20 17:05:59 -07008796 if (program && strcasecmp(program, "HE") == 0) {
8797#ifdef NL80211_SUPPORT
8798 enum he_mcs_config mcs_config;
8799 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008800
Arif Hussaina37e9552018-06-20 17:05:59 -07008801 if (mcs >= 0 && mcs <= 7) {
8802 mcs_config = HE_80_MCS0_7;
8803 } else if (mcs > 7 && mcs <= 9) {
8804 mcs_config = HE_80_MCS0_9;
8805 } else if (mcs > 9 && mcs <= 11) {
8806 mcs_config = HE_80_MCS0_11;
8807 } else {
8808 sigma_dut_print(dut, DUT_MSG_ERROR,
8809 "nss_mcs_cap: HE: Invalid mcs: %d",
8810 mcs);
8811 send_resp(dut, conn, SIGMA_ERROR,
8812 "errorCode,Invalid MCS");
8813 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008814 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008815
8816 ret = sta_set_he_mcs(dut, intf, mcs_config);
8817 if (ret) {
8818 sigma_dut_print(dut, DUT_MSG_ERROR,
8819 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8820 mcs_config, ret);
8821 send_resp(dut, conn, SIGMA_ERROR,
8822 "errorCode,Failed to set MCS");
8823 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008824 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008825#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008826 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008827 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8828#endif /* NL80211_SUPPORT */
8829 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008830 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008831
8832 switch (nss) {
8833 case 1:
8834 switch (mcs) {
8835 case 7:
8836 vht_mcsmap = 0xfffc;
8837 break;
8838 case 8:
8839 vht_mcsmap = 0xfffd;
8840 break;
8841 case 9:
8842 vht_mcsmap = 0xfffe;
8843 break;
8844 default:
8845 vht_mcsmap = 0xfffe;
8846 break;
8847 }
8848 break;
8849 case 2:
8850 switch (mcs) {
8851 case 7:
8852 vht_mcsmap = 0xfff0;
8853 break;
8854 case 8:
8855 vht_mcsmap = 0xfff5;
8856 break;
8857 case 9:
8858 vht_mcsmap = 0xfffa;
8859 break;
8860 default:
8861 vht_mcsmap = 0xfffa;
8862 break;
8863 }
8864 break;
8865 case 3:
8866 switch (mcs) {
8867 case 7:
8868 vht_mcsmap = 0xffc0;
8869 break;
8870 case 8:
8871 vht_mcsmap = 0xffd5;
8872 break;
8873 case 9:
8874 vht_mcsmap = 0xffea;
8875 break;
8876 default:
8877 vht_mcsmap = 0xffea;
8878 break;
8879 }
8880 break;
8881 default:
8882 vht_mcsmap = 0xffea;
8883 break;
8884 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008885 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008886 }
8887 }
8888
8889 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8890
8891 val = get_param(cmd, "Vht_tkip");
8892 if (val)
8893 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8894
8895 val = get_param(cmd, "Vht_wep");
8896 if (val)
8897 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8898
8899 if (tkip != -1 || wep != -1) {
8900 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008901 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008902 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008903 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008904 } else {
8905 sigma_dut_print(dut, DUT_MSG_ERROR,
8906 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8907 return 0;
8908 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008909 }
8910
Arif Hussain55f00da2018-07-03 08:28:26 -07008911 val = get_param(cmd, "txBandwidth");
8912 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008913 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008914 case DRIVER_WCN:
8915 if (wcn_sta_set_width(dut, intf, val) < 0) {
8916 send_resp(dut, conn, SIGMA_ERROR,
8917 "ErrorCode,Failed to set txBandwidth");
8918 return 0;
8919 }
8920 break;
8921 case DRIVER_ATHEROS:
8922 if (ath_set_width(dut, conn, intf, val) < 0) {
8923 send_resp(dut, conn, SIGMA_ERROR,
8924 "ErrorCode,Failed to set txBandwidth");
8925 return 0;
8926 }
8927 break;
8928 default:
8929 sigma_dut_print(dut, DUT_MSG_ERROR,
8930 "Setting txBandwidth not supported");
8931 break;
8932 }
8933 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008934
Arif Hussain9765f7d2018-07-03 08:28:26 -07008935 val = get_param(cmd, "BeamformeeSTS");
8936 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008937 if (sta_set_tx_beamformee(dut, intf, 1)) {
8938 send_resp(dut, conn, SIGMA_ERROR,
8939 "ErrorCode,Failed to set TX beamformee enable");
8940 return 0;
8941 }
8942
Arif Hussain9765f7d2018-07-03 08:28:26 -07008943 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8944 send_resp(dut, conn, SIGMA_ERROR,
8945 "ErrorCode,Failed to set BeamformeeSTS");
8946 return 0;
8947 }
8948 }
8949
Arif Hussain68d23f52018-07-11 13:39:08 -07008950 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8951 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008952#ifdef NL80211_SUPPORT
8953 enum qca_wlan_he_mac_padding_dur set_val;
8954
8955 switch (atoi(val)) {
8956 case 16:
8957 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8958 break;
8959 case 8:
8960 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8961 break;
8962 default:
8963 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8964 break;
8965 }
8966 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008967 send_resp(dut, conn, SIGMA_ERROR,
8968 "ErrorCode,Failed to set MAC padding duration");
8969 return 0;
8970 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008971#else /* NL80211_SUPPORT */
8972 sigma_dut_print(dut, DUT_MSG_ERROR,
8973 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8974#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008975 }
8976
Arif Hussain480d5f42019-03-12 14:40:42 -07008977 val = get_param(cmd, "TWT_ReqSupport");
8978 if (val) {
8979 int set_val;
8980
8981 if (strcasecmp(val, "Enable") == 0) {
8982 set_val = 1;
8983 } else if (strcasecmp(val, "Disable") == 0) {
8984 set_val = 0;
8985 } else {
8986 send_resp(dut, conn, SIGMA_ERROR,
8987 "ErrorCode,Invalid TWT_ReqSupport");
8988 return STATUS_SENT;
8989 }
8990
8991 if (sta_set_twt_req_support(dut, intf, set_val)) {
8992 sigma_dut_print(dut, DUT_MSG_ERROR,
8993 "Failed to set TWT req support %d",
8994 set_val);
8995 send_resp(dut, conn, SIGMA_ERROR,
8996 "ErrorCode,Failed to set TWT_ReqSupport");
8997 return STATUS_SENT;
8998 }
8999 }
9000
Srinivas Girigowda0525e292020-11-12 13:28:21 -08009001 val = get_param(cmd, "FullBW_ULMUMIMO");
9002 if (val) {
9003 int set_val;
9004
9005 if (strcasecmp(val, "Enable") == 0) {
9006 set_val = 1;
9007 } else if (strcasecmp(val, "Disable") == 0) {
9008 set_val = 0;
9009 } else {
9010 send_resp(dut, conn, SIGMA_ERROR,
9011 "ErrorCode,Invalid FullBW_ULMUMIMO");
9012 return STATUS_SENT_ERROR;
9013 }
9014
9015 if (sta_set_fullbw_ulmumimo(dut, intf, set_val)) {
9016 sigma_dut_print(dut, DUT_MSG_ERROR,
9017 "Failed to set FullBW_ULMUMIMO %d",
9018 set_val);
9019 send_resp(dut, conn, SIGMA_ERROR,
9020 "ErrorCode,Failed to set FullBW_ULMUMIMO");
9021 return STATUS_SENT_ERROR;
9022 }
9023 }
9024
Srinivas Girigowda6707f032020-10-26 15:24:46 -07009025 val = get_param(cmd, "TWTInfoFrameTx");
9026 if (val) {
9027 if (strcasecmp(val, "Enable") == 0) {
9028 /* No-op */
9029 } else if (strcasecmp(val, "Disable") == 0) {
9030 /* No-op */
9031 } else {
9032 send_resp(dut, conn, SIGMA_ERROR,
9033 "ErrorCode,Invalid TWTInfoFrameTx");
9034 return STATUS_SENT_ERROR;
9035 }
9036 }
9037
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07009038 val = get_param(cmd, "MU_EDCA");
9039 if (val && (strcasecmp(val, "Override") == 0)) {
9040 if (sta_set_mu_edca_override(dut, intf, 1)) {
9041 send_resp(dut, conn, SIGMA_ERROR,
9042 "ErrorCode,Failed to set MU EDCA override");
9043 return 0;
9044 }
9045 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009046
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07009047 val = get_param(cmd, "OMControl");
9048 if (val) {
9049 int set_val = 1;
9050
9051 if (strcasecmp(val, "Enable") == 0)
9052 set_val = 1;
9053 else if (strcasecmp(val, "Disable") == 0)
9054 set_val = 0;
9055
9056 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
9057 send_resp(dut, conn, SIGMA_ERROR,
9058 "ErrorCode,Failed to set OM ctrl supp");
9059 return 0;
9060 }
9061 }
9062
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009063 val = get_param(cmd, "ADDBAResp_BufSize");
9064 if (val) {
9065 int buf_size;
9066
9067 if (strcasecmp(val, "gt64") == 0)
9068 buf_size = 256;
9069 else
9070 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009071 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009072 sta_set_addba_buf_size(dut, intf, buf_size)) {
9073 send_resp(dut, conn, SIGMA_ERROR,
9074 "ErrorCode,set addbaresp_buff_size failed");
9075 return 0;
9076 }
9077 }
9078
9079 val = get_param(cmd, "ADDBAReq_BufSize");
9080 if (val) {
9081 int buf_size;
9082
9083 if (strcasecmp(val, "gt64") == 0)
9084 buf_size = 256;
9085 else
9086 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009087 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07009088 sta_set_addba_buf_size(dut, intf, buf_size)) {
9089 send_resp(dut, conn, SIGMA_ERROR,
9090 "ErrorCode,set addbareq_buff_size failed");
9091 return 0;
9092 }
9093 }
9094
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009095 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9096}
9097
9098
9099static int sta_set_wireless_60g(struct sigma_dut *dut,
9100 struct sigma_conn *conn,
9101 struct sigma_cmd *cmd)
9102{
9103 const char *dev_role = get_param(cmd, "DevRole");
9104
9105 if (!dev_role) {
9106 send_resp(dut, conn, SIGMA_INVALID,
9107 "ErrorCode,DevRole not specified");
9108 return 0;
9109 }
9110
9111 if (strcasecmp(dev_role, "PCP") == 0)
9112 return sta_set_60g_pcp(dut, conn, cmd);
9113 if (strcasecmp(dev_role, "STA") == 0)
9114 return sta_set_60g_sta(dut, conn, cmd);
9115 send_resp(dut, conn, SIGMA_INVALID,
9116 "ErrorCode,DevRole not supported");
9117 return 0;
9118}
9119
9120
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309121static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
9122 struct sigma_cmd *cmd)
9123{
9124 int status;
9125 const char *intf = get_param(cmd, "Interface");
9126 const char *val = get_param(cmd, "DevRole");
9127
9128 if (val && strcasecmp(val, "STA-CFON") == 0) {
9129 status = sta_cfon_set_wireless(dut, conn, cmd);
9130 if (status)
9131 return status;
9132 }
9133 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9134}
9135
9136
Jouni Malinen67433fc2020-06-26 22:50:33 +03009137static enum sigma_cmd_result
9138sta_set_wireless_wpa3(struct sigma_dut *dut, struct sigma_conn *conn,
9139 struct sigma_cmd *cmd)
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309140{
9141 const char *intf = get_param(cmd, "Interface");
9142 const char *val;
9143
9144 val = get_param(cmd, "ocvc");
9145 if (val)
9146 dut->ocvc = atoi(val);
9147
Jouni Malinen67433fc2020-06-26 22:50:33 +03009148 val = get_param(cmd, "ClientPrivacy");
9149 if (val) {
9150 dut->client_privacy = atoi(val);
9151 if (dut->client_privacy &&
9152 (wpa_command(intf, "SET mac_addr 1") < 0 ||
9153 wpa_command(intf, "SET rand_addr_lifetime 1") < 0 ||
9154 wpa_command(intf, "SET preassoc_mac_addr 1") < 0 ||
9155 wpa_command(intf, "SET gas_rand_mac_addr 1") < 0 ||
9156 wpa_command(intf, "SET gas_rand_addr_lifetime 1") < 0)) {
9157 send_resp(dut, conn, SIGMA_ERROR,
9158 "errorCode,Failed to enable random MAC address use");
9159 return STATUS_SENT_ERROR;
9160 }
9161 }
9162
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309163 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9164}
9165
9166
Jouni Malinenf7222712019-06-13 01:50:21 +03009167static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9168 struct sigma_conn *conn,
9169 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009170{
9171 const char *val;
9172
9173 val = get_param(cmd, "Program");
9174 if (val) {
9175 if (strcasecmp(val, "11n") == 0)
9176 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009177 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009178 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9179 if (strcasecmp(val, "60ghz") == 0)
9180 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309181 if (strcasecmp(val, "OCE") == 0)
9182 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009183 /* sta_set_wireless in WPS program is only used for 60G */
9184 if (is_60g_sigma_dut(dut))
9185 return sta_set_wireless_60g(dut, conn, cmd);
Vamsi Krishnac1633d22020-05-06 18:31:21 +05309186 if (strcasecmp(val, "WPA3") == 0)
9187 return sta_set_wireless_wpa3(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009188 send_resp(dut, conn, SIGMA_ERROR,
9189 "ErrorCode,Program value not supported");
9190 } else {
9191 send_resp(dut, conn, SIGMA_ERROR,
9192 "ErrorCode,Program argument not available");
9193 }
9194
9195 return 0;
9196}
9197
9198
9199static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9200 int tid)
9201{
9202 char buf[100];
9203 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9204
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309205 if (tid < 0 ||
9206 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9207 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9208 return;
9209 }
9210
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009211 /*
9212 * Two ways to ensure that addba request with a
9213 * non zero TID could be sent out. EV 117296
9214 */
9215 snprintf(buf, sizeof(buf),
9216 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9217 tid);
9218 if (system(buf) != 0) {
9219 sigma_dut_print(dut, DUT_MSG_ERROR,
9220 "Ping did not send out");
9221 }
9222
9223 snprintf(buf, sizeof(buf),
9224 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9225 intf, VI_QOS_TMP_FILE);
9226 if (system(buf) != 0)
9227 return;
9228
9229 snprintf(buf, sizeof(buf),
9230 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9231 intf, VI_QOS_TMP_FILE);
9232 if (system(buf) != 0)
9233 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9234
9235 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9236 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9237 if (system(buf) != 0) {
9238 sigma_dut_print(dut, DUT_MSG_ERROR,
9239 "VI_QOS_TEMP_FILE generation error failed");
9240 }
9241 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9242 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9243 if (system(buf) != 0) {
9244 sigma_dut_print(dut, DUT_MSG_ERROR,
9245 "VI_QOS_FILE generation failed");
9246 }
9247
9248 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9249 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9250 if (system(buf) != 0) {
9251 sigma_dut_print(dut, DUT_MSG_ERROR,
9252 "VI_QOS_FILE generation failed");
9253 }
9254
9255 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9256 if (system(buf) != 0) {
9257 }
9258}
9259
9260
9261static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9262 struct sigma_cmd *cmd)
9263{
9264 const char *intf = get_param(cmd, "Interface");
9265 const char *val;
9266 int tid = 0;
9267 char buf[100];
9268
9269 val = get_param(cmd, "TID");
9270 if (val) {
9271 tid = atoi(val);
9272 if (tid)
9273 ath_sta_inject_frame(dut, intf, tid);
9274 }
9275
9276 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009277 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009278
9279 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9280 if (system(buf) != 0) {
9281 sigma_dut_print(dut, DUT_MSG_ERROR,
9282 "wifitool senddelba failed");
9283 }
9284
9285 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9286 if (system(buf) != 0) {
9287 sigma_dut_print(dut, DUT_MSG_ERROR,
9288 "wifitool sendaddba failed");
9289 }
9290
9291 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9292
9293 return 1;
9294}
9295
9296
Lior David9981b512017-01-20 13:16:40 +02009297#ifdef __linux__
9298
9299static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9300 int agg_size)
9301{
9302 char dir[128], buf[128];
9303 FILE *f;
9304 regex_t re;
9305 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009306 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009307
9308 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9309 sigma_dut_print(dut, DUT_MSG_ERROR,
9310 "failed to get wil6210 debugfs dir");
9311 return -1;
9312 }
9313
Jouni Malinen3aa72862019-05-29 23:14:51 +03009314 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9315 if (res < 0 || res >= sizeof(buf))
9316 return -1;
Lior David9981b512017-01-20 13:16:40 +02009317 f = fopen(buf, "r");
9318 if (!f) {
9319 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009320 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009321 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9322 if (res < 0 || res >= sizeof(buf))
9323 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009324 f = fopen(buf, "r");
9325 if (!f) {
9326 sigma_dut_print(dut, DUT_MSG_ERROR,
9327 "failed to open: %s", buf);
9328 return -1;
9329 }
Lior David9981b512017-01-20 13:16:40 +02009330 }
9331
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009332 /* can be either VRING tx... or RING... */
9333 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009334 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9335 goto out;
9336 }
9337
9338 /* find TX VRING for the mac address */
9339 found = 0;
9340 while (fgets(buf, sizeof(buf), f)) {
9341 if (strcasestr(buf, dest_mac)) {
9342 found = 1;
9343 break;
9344 }
9345 }
9346
9347 if (!found) {
9348 sigma_dut_print(dut, DUT_MSG_ERROR,
9349 "no TX VRING for %s", dest_mac);
9350 goto out;
9351 }
9352
9353 /* extract VRING ID, "VRING tx_<id> = {" */
9354 if (!fgets(buf, sizeof(buf), f)) {
9355 sigma_dut_print(dut, DUT_MSG_ERROR,
9356 "no VRING start line for %s", dest_mac);
9357 goto out;
9358 }
9359
9360 rc = regexec(&re, buf, 2, m, 0);
9361 regfree(&re);
9362 if (rc || m[1].rm_so < 0) {
9363 sigma_dut_print(dut, DUT_MSG_ERROR,
9364 "no VRING TX ID for %s", dest_mac);
9365 goto out;
9366 }
9367 buf[m[1].rm_eo] = 0;
9368 vring_id = atoi(&buf[m[1].rm_so]);
9369
9370 /* send the addba command */
9371 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009372 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9373 if (res < 0 || res >= sizeof(buf))
9374 return -1;
Lior David9981b512017-01-20 13:16:40 +02009375 f = fopen(buf, "w");
9376 if (!f) {
9377 sigma_dut_print(dut, DUT_MSG_ERROR,
9378 "failed to open: %s", buf);
9379 return -1;
9380 }
9381
9382 fprintf(f, "add %d %d\n", vring_id, agg_size);
9383
9384 ret = 0;
9385
9386out:
9387 fclose(f);
9388
9389 return ret;
9390}
9391
9392
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009393int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9394 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009395{
9396 const char *val;
9397 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009398
9399 val = get_param(cmd, "TID");
9400 if (val) {
9401 tid = atoi(val);
9402 if (tid != 0) {
9403 sigma_dut_print(dut, DUT_MSG_ERROR,
9404 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9405 tid);
9406 }
9407 }
9408
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009409 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009410 if (!val) {
9411 sigma_dut_print(dut, DUT_MSG_ERROR,
9412 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009413 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009414 }
9415
Lior David9981b512017-01-20 13:16:40 +02009416 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009417 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009418
9419 return 1;
9420}
9421
Lior David9981b512017-01-20 13:16:40 +02009422#endif /* __linux__ */
9423
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009424
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009425static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9426 struct sigma_cmd *cmd)
9427{
9428#ifdef NL80211_SUPPORT
9429 const char *intf = get_param(cmd, "Interface");
9430 const char *val;
9431 int tid = -1;
9432 int bufsize = 64;
9433 struct nl_msg *msg;
9434 int ret = 0;
9435 struct nlattr *params;
9436 int ifindex;
9437
9438 val = get_param(cmd, "TID");
9439 if (val)
9440 tid = atoi(val);
9441
9442 if (tid == -1) {
9443 send_resp(dut, conn, SIGMA_ERROR,
9444 "ErrorCode,sta_send_addba tid invalid");
9445 return 0;
9446 }
9447
9448 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9449
9450 ifindex = if_nametoindex(intf);
9451 if (ifindex == 0) {
9452 sigma_dut_print(dut, DUT_MSG_ERROR,
9453 "%s: Index for interface %s failed",
9454 __func__, intf);
9455 send_resp(dut, conn, SIGMA_ERROR,
9456 "ErrorCode,sta_send_addba interface invalid");
9457 return 0;
9458 }
9459
9460 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9461 NL80211_CMD_VENDOR)) ||
9462 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9463 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9464 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9465 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9466 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9467 nla_put_u8(msg,
9468 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9469 QCA_WLAN_ADD_BA) ||
9470 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9471 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009472 nla_put_u16(msg,
9473 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9474 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009475 sigma_dut_print(dut, DUT_MSG_ERROR,
9476 "%s: err in adding vendor_cmd and vendor_data",
9477 __func__);
9478 nlmsg_free(msg);
9479 send_resp(dut, conn, SIGMA_ERROR,
9480 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9481 return 0;
9482 }
9483 nla_nest_end(msg, params);
9484
9485 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9486 if (ret) {
9487 sigma_dut_print(dut, DUT_MSG_ERROR,
9488 "%s: err in send_and_recv_msgs, ret=%d",
9489 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309490 if (ret == -EOPNOTSUPP)
9491 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009492 send_resp(dut, conn, SIGMA_ERROR,
9493 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9494 return 0;
9495 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009496#else /* NL80211_SUPPORT */
9497 sigma_dut_print(dut, DUT_MSG_ERROR,
9498 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009499#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309500
9501 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009502}
9503
9504
Jouni Malinenf7222712019-06-13 01:50:21 +03009505static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9506 struct sigma_conn *conn,
9507 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009508{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009509 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009510 case DRIVER_ATHEROS:
9511 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009512 case DRIVER_WCN:
9513 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009514#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009515 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009516 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009517#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009518 default:
9519 /*
9520 * There is no driver specific implementation for other drivers.
9521 * Ignore the command and report COMPLETE since the following
9522 * throughput test operation will end up sending ADDBA anyway.
9523 */
9524 return 1;
9525 }
9526}
9527
9528
9529int inject_eth_frame(int s, const void *data, size_t len,
9530 unsigned short ethtype, char *dst, char *src)
9531{
9532 struct iovec iov[4] = {
9533 {
9534 .iov_base = dst,
9535 .iov_len = ETH_ALEN,
9536 },
9537 {
9538 .iov_base = src,
9539 .iov_len = ETH_ALEN,
9540 },
9541 {
9542 .iov_base = &ethtype,
9543 .iov_len = sizeof(unsigned short),
9544 },
9545 {
9546 .iov_base = (void *) data,
9547 .iov_len = len,
9548 }
9549 };
9550 struct msghdr msg = {
9551 .msg_name = NULL,
9552 .msg_namelen = 0,
9553 .msg_iov = iov,
9554 .msg_iovlen = 4,
9555 .msg_control = NULL,
9556 .msg_controllen = 0,
9557 .msg_flags = 0,
9558 };
9559
9560 return sendmsg(s, &msg, 0);
9561}
9562
9563#if defined(__linux__) || defined(__QNXNTO__)
9564
9565int inject_frame(int s, const void *data, size_t len, int encrypt)
9566{
9567#define IEEE80211_RADIOTAP_F_WEP 0x04
9568#define IEEE80211_RADIOTAP_F_FRAG 0x08
9569 unsigned char rtap_hdr[] = {
9570 0x00, 0x00, /* radiotap version */
9571 0x0e, 0x00, /* radiotap length */
9572 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9573 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9574 0x00, /* padding */
9575 0x00, 0x00, /* RX and TX flags to indicate that */
9576 0x00, 0x00, /* this is the injected frame directly */
9577 };
9578 struct iovec iov[2] = {
9579 {
9580 .iov_base = &rtap_hdr,
9581 .iov_len = sizeof(rtap_hdr),
9582 },
9583 {
9584 .iov_base = (void *) data,
9585 .iov_len = len,
9586 }
9587 };
9588 struct msghdr msg = {
9589 .msg_name = NULL,
9590 .msg_namelen = 0,
9591 .msg_iov = iov,
9592 .msg_iovlen = 2,
9593 .msg_control = NULL,
9594 .msg_controllen = 0,
9595 .msg_flags = 0,
9596 };
9597
9598 if (encrypt)
9599 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9600
9601 return sendmsg(s, &msg, 0);
9602}
9603
9604
9605int open_monitor(const char *ifname)
9606{
9607#ifdef __QNXNTO__
9608 struct sockaddr_dl ll;
9609 int s;
9610
9611 memset(&ll, 0, sizeof(ll));
9612 ll.sdl_family = AF_LINK;
9613 ll.sdl_index = if_nametoindex(ifname);
9614 if (ll.sdl_index == 0) {
9615 perror("if_nametoindex");
9616 return -1;
9617 }
9618 s = socket(PF_INET, SOCK_RAW, 0);
9619#else /* __QNXNTO__ */
9620 struct sockaddr_ll ll;
9621 int s;
9622
9623 memset(&ll, 0, sizeof(ll));
9624 ll.sll_family = AF_PACKET;
9625 ll.sll_ifindex = if_nametoindex(ifname);
9626 if (ll.sll_ifindex == 0) {
9627 perror("if_nametoindex");
9628 return -1;
9629 }
9630 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9631#endif /* __QNXNTO__ */
9632 if (s < 0) {
9633 perror("socket[PF_PACKET,SOCK_RAW]");
9634 return -1;
9635 }
9636
9637 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9638 perror("monitor socket bind");
9639 close(s);
9640 return -1;
9641 }
9642
9643 return s;
9644}
9645
9646
9647static int hex2num(char c)
9648{
9649 if (c >= '0' && c <= '9')
9650 return c - '0';
9651 if (c >= 'a' && c <= 'f')
9652 return c - 'a' + 10;
9653 if (c >= 'A' && c <= 'F')
9654 return c - 'A' + 10;
9655 return -1;
9656}
9657
9658
9659int hwaddr_aton(const char *txt, unsigned char *addr)
9660{
9661 int i;
9662
9663 for (i = 0; i < 6; i++) {
9664 int a, b;
9665
9666 a = hex2num(*txt++);
9667 if (a < 0)
9668 return -1;
9669 b = hex2num(*txt++);
9670 if (b < 0)
9671 return -1;
9672 *addr++ = (a << 4) | b;
9673 if (i < 5 && *txt++ != ':')
9674 return -1;
9675 }
9676
9677 return 0;
9678}
9679
9680#endif /* defined(__linux__) || defined(__QNXNTO__) */
9681
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309682
9683#ifdef NL80211_SUPPORT
9684static int nl80211_send_frame_cmd(struct sigma_dut *dut, const char *intf,
9685 const u8 *data, size_t data_len, int freq)
9686{
9687 struct nl_msg *msg;
9688 int ret = 0;
9689 int ifindex;
9690
9691 ifindex = if_nametoindex(intf);
9692 if (ifindex == 0) {
9693 sigma_dut_print(dut, DUT_MSG_ERROR,
9694 "%s: Index for interface %s failed",
9695 __func__, intf);
9696 return -1;
9697 }
9698
9699 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9700 NL80211_CMD_FRAME)) ||
9701 (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
9702 nla_put(msg, NL80211_ATTR_FRAME, data_len, data)) {
9703 sigma_dut_print(dut, DUT_MSG_ERROR,
9704 "%s: Error in adding NL80211_CMD_FRAME",
9705 __func__);
9706 nlmsg_free(msg);
9707 return -1;
9708 }
9709
9710 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9711 if (ret) {
9712 sigma_dut_print(dut, DUT_MSG_ERROR,
9713 "nl80211: Frame command failed: ret=%d (%s) req=%u",
9714 ret, strerror(-ret), freq);
9715 return -1;
9716 }
9717
9718 return 0;
9719}
9720#endif /* NL80211_SUPPORT */
9721
9722
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009723enum send_frame_type {
9724 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9725};
9726enum send_frame_protection {
9727 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9728};
9729
9730
9731static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309732 const char *intf, enum send_frame_type frame,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009733 enum send_frame_protection protected,
Veerendranath Jakkam49774122020-07-05 09:52:18 +05309734 const char *dest, int use_monitor)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009735{
9736#ifdef __linux__
9737 unsigned char buf[1000], *pos;
9738 int s, res;
9739 char bssid[20], addr[20];
9740 char result[32], ssid[100];
9741 size_t ssid_len;
9742
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009743 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009744 sizeof(result)) < 0 ||
9745 strncmp(result, "COMPLETED", 9) != 0) {
9746 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9747 return 0;
9748 }
9749
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009750 if (get_wpa_status(get_station_ifname(dut), "bssid",
9751 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009752 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9753 "current BSSID");
9754 return 0;
9755 }
9756
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009757 if (get_wpa_status(get_station_ifname(dut), "address",
9758 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009759 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9760 "own MAC address");
9761 return 0;
9762 }
9763
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009764 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009765 < 0) {
9766 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9767 "current SSID");
9768 return 0;
9769 }
9770 ssid_len = strlen(ssid);
9771
9772 pos = buf;
9773
9774 /* Frame Control */
9775 switch (frame) {
9776 case DISASSOC:
9777 *pos++ = 0xa0;
9778 break;
9779 case DEAUTH:
9780 *pos++ = 0xc0;
9781 break;
9782 case SAQUERY:
9783 *pos++ = 0xd0;
9784 break;
9785 case AUTH:
9786 *pos++ = 0xb0;
9787 break;
9788 case ASSOCREQ:
9789 *pos++ = 0x00;
9790 break;
9791 case REASSOCREQ:
9792 *pos++ = 0x20;
9793 break;
9794 case DLS_REQ:
9795 *pos++ = 0xd0;
9796 break;
9797 }
9798
9799 if (protected == INCORRECT_KEY)
9800 *pos++ = 0x40; /* Set Protected field to 1 */
9801 else
9802 *pos++ = 0x00;
9803
9804 /* Duration */
9805 *pos++ = 0x00;
9806 *pos++ = 0x00;
9807
9808 /* addr1 = DA (current AP) */
9809 hwaddr_aton(bssid, pos);
9810 pos += 6;
9811 /* addr2 = SA (own address) */
9812 hwaddr_aton(addr, pos);
9813 pos += 6;
9814 /* addr3 = BSSID (current AP) */
9815 hwaddr_aton(bssid, pos);
9816 pos += 6;
9817
9818 /* Seq# (to be filled by driver/mac80211) */
9819 *pos++ = 0x00;
9820 *pos++ = 0x00;
9821
9822 if (protected == INCORRECT_KEY) {
9823 /* CCMP parameters */
9824 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9825 pos += 8;
9826 }
9827
9828 if (protected == INCORRECT_KEY) {
9829 switch (frame) {
9830 case DEAUTH:
9831 /* Reason code (encrypted) */
9832 memcpy(pos, "\xa7\x39", 2);
9833 pos += 2;
9834 break;
9835 case DISASSOC:
9836 /* Reason code (encrypted) */
9837 memcpy(pos, "\xa7\x39", 2);
9838 pos += 2;
9839 break;
9840 case SAQUERY:
9841 /* Category|Action|TransID (encrypted) */
9842 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9843 pos += 4;
9844 break;
9845 default:
9846 return -1;
9847 }
9848
9849 /* CCMP MIC */
9850 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9851 pos += 8;
9852 } else {
9853 switch (frame) {
9854 case DEAUTH:
9855 /* reason code = 8 */
9856 *pos++ = 0x08;
9857 *pos++ = 0x00;
9858 break;
9859 case DISASSOC:
9860 /* reason code = 8 */
9861 *pos++ = 0x08;
9862 *pos++ = 0x00;
9863 break;
9864 case SAQUERY:
9865 /* Category - SA Query */
9866 *pos++ = 0x08;
9867 /* SA query Action - Request */
9868 *pos++ = 0x00;
9869 /* Transaction ID */
9870 *pos++ = 0x12;
9871 *pos++ = 0x34;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309872 if (dut->saquery_oci_freq) {
9873 /* OCI IE - Extended ID */
9874 *pos++ = 0xFF;
9875 *pos++ = 0x04;
9876 *pos++ = 0x36;
9877 /* Operating Class */
9878 *pos++ = 0x74;
9879 /* Primary Channel */
9880 *pos++ = freq_to_channel(dut->saquery_oci_freq);
9881 /* Frequency Segment 1 Channel Number */
9882 *pos++ = 0x00;
9883 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009884 break;
9885 case AUTH:
9886 /* Auth Alg (Open) */
9887 *pos++ = 0x00;
9888 *pos++ = 0x00;
9889 /* Seq# */
9890 *pos++ = 0x01;
9891 *pos++ = 0x00;
9892 /* Status code */
9893 *pos++ = 0x00;
9894 *pos++ = 0x00;
9895 break;
9896 case ASSOCREQ:
9897 /* Capability Information */
9898 *pos++ = 0x31;
9899 *pos++ = 0x04;
9900 /* Listen Interval */
9901 *pos++ = 0x0a;
9902 *pos++ = 0x00;
9903 /* SSID */
9904 *pos++ = 0x00;
9905 *pos++ = ssid_len;
9906 memcpy(pos, ssid, ssid_len);
9907 pos += ssid_len;
9908 /* Supported Rates */
9909 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9910 10);
9911 pos += 10;
9912 /* Extended Supported Rates */
9913 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9914 pos += 6;
9915 /* RSN */
9916 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9917 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9918 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9919 pos += 28;
9920 break;
9921 case REASSOCREQ:
9922 /* Capability Information */
9923 *pos++ = 0x31;
9924 *pos++ = 0x04;
9925 /* Listen Interval */
9926 *pos++ = 0x0a;
9927 *pos++ = 0x00;
9928 /* Current AP */
9929 hwaddr_aton(bssid, pos);
9930 pos += 6;
9931 /* SSID */
9932 *pos++ = 0x00;
9933 *pos++ = ssid_len;
9934 memcpy(pos, ssid, ssid_len);
9935 pos += ssid_len;
9936 /* Supported Rates */
9937 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9938 10);
9939 pos += 10;
9940 /* Extended Supported Rates */
9941 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9942 pos += 6;
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +05309943 /* RSNE - Group and Pairwise ciphers */
9944 memcpy(pos,
9945 "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04",
9946 14);
9947 pos += 14;
9948 /* RSNE - AKM Suite count */
9949 *pos++ = 0x01;
9950 *pos++ = 0x00;
9951 /* RSNE - AKM Suites */
9952 if (dut->program == PROGRAM_WPA3)
9953 memcpy(pos, "\x00\x0f\xac\x08", 4);
9954 else
9955 memcpy(pos, "\x00\x0f\xac\x02", 4);
9956 pos += 4;
9957 /* RSNE - Capabilities */
9958 *pos++ = 0xc0;
9959 if (dut->ocvc)
9960 *pos++ = 0x40;
9961 else
9962 *pos++ = 0x00;
9963 /* RSNE - PMKID list and Group Management Ciphers */
9964 memcpy(pos, "\x00\x00\x00\x0f\xac\x06", 6);
9965 pos += 6;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009966 break;
9967 case DLS_REQ:
9968 /* Category - DLS */
9969 *pos++ = 0x02;
9970 /* DLS Action - Request */
9971 *pos++ = 0x00;
9972 /* Destination MACAddress */
9973 if (dest)
9974 hwaddr_aton(dest, pos);
9975 else
9976 memset(pos, 0, 6);
9977 pos += 6;
9978 /* Source MACAddress */
9979 hwaddr_aton(addr, pos);
9980 pos += 6;
9981 /* Capability Information */
9982 *pos++ = 0x10; /* Privacy */
9983 *pos++ = 0x06; /* QoS */
9984 /* DLS Timeout Value */
9985 *pos++ = 0x00;
9986 *pos++ = 0x01;
9987 /* Supported rates */
9988 *pos++ = 0x01;
9989 *pos++ = 0x08;
9990 *pos++ = 0x0c; /* 6 Mbps */
9991 *pos++ = 0x12; /* 9 Mbps */
9992 *pos++ = 0x18; /* 12 Mbps */
9993 *pos++ = 0x24; /* 18 Mbps */
9994 *pos++ = 0x30; /* 24 Mbps */
9995 *pos++ = 0x48; /* 36 Mbps */
9996 *pos++ = 0x60; /* 48 Mbps */
9997 *pos++ = 0x6c; /* 54 Mbps */
9998 /* TODO: Extended Supported Rates */
9999 /* TODO: HT Capabilities */
10000 break;
10001 }
10002 }
10003
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010004 if (use_monitor) {
10005 s = open_monitor("sigmadut");
10006 if (s < 0) {
10007 send_resp(dut, conn, SIGMA_ERROR,
10008 "errorCode,Failed to open monitor socket");
10009 return 0;
10010 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010011
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010012 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
10013 if (res < 0) {
10014 send_resp(dut, conn, SIGMA_ERROR,
10015 "errorCode,Failed to inject frame");
10016 close(s);
10017 return 0;
10018 }
10019 if (res < pos - buf) {
10020 send_resp(dut, conn, SIGMA_ERROR,
10021 "errorCode,Only partial frame sent");
10022 close(s);
10023 return 0;
10024 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010025
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010026 close(s);
10027 } else {
10028#ifdef NL80211_SUPPORT
10029 int freq;
10030 char freq_str[10];
10031
10032 if (get_wpa_status(get_station_ifname(dut), "freq",
10033 freq_str, sizeof(freq_str)) < 0) {
10034 send_resp(dut, conn, SIGMA_ERROR,
10035 "errorCode,Could not get current operating frequency");
10036 return 0;
10037 }
10038 freq = atoi(freq_str);
10039
10040 if (nl80211_send_frame_cmd(dut, intf, buf, pos - buf, freq)) {
10041 send_resp(dut, conn, SIGMA_ERROR,
10042 "errorCode,Failed to inject frame");
10043 return 0;
10044 }
10045#else /* NL80211_SUPPORT */
10046 send_resp(dut, conn, SIGMA_ERROR,
10047 "errorCode,Failed to inject frame (no NL80211_SUPPORT)");
10048 return 0;
10049#endif /* NL80211_SUPPORT */
10050 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010051
10052 return 1;
10053#else /* __linux__ */
10054 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
10055 "yet supported");
10056 return 0;
10057#endif /* __linux__ */
10058}
10059
10060
10061static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
10062 struct sigma_conn *conn,
10063 struct sigma_cmd *cmd)
10064{
10065 const char *intf = get_param(cmd, "Interface");
10066 const char *sta, *val;
10067 unsigned char addr[ETH_ALEN];
10068 char buf[100];
10069
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010070 if (!intf)
10071 return -1;
10072
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010073 sta = get_param(cmd, "peer");
10074 if (sta == NULL)
10075 sta = get_param(cmd, "station");
10076 if (sta == NULL) {
10077 send_resp(dut, conn, SIGMA_ERROR,
10078 "ErrorCode,Missing peer address");
10079 return 0;
10080 }
10081 if (hwaddr_aton(sta, addr) < 0) {
10082 send_resp(dut, conn, SIGMA_ERROR,
10083 "ErrorCode,Invalid peer address");
10084 return 0;
10085 }
10086
10087 val = get_param(cmd, "type");
10088 if (val == NULL)
10089 return -1;
10090
10091 if (strcasecmp(val, "DISCOVERY") == 0) {
10092 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
10093 if (wpa_command(intf, buf) < 0) {
10094 send_resp(dut, conn, SIGMA_ERROR,
10095 "ErrorCode,Failed to send TDLS discovery");
10096 return 0;
10097 }
10098 return 1;
10099 }
10100
10101 if (strcasecmp(val, "SETUP") == 0) {
10102 int status = 0, timeout = 0;
10103
10104 val = get_param(cmd, "Status");
10105 if (val)
10106 status = atoi(val);
10107
10108 val = get_param(cmd, "Timeout");
10109 if (val)
10110 timeout = atoi(val);
10111
10112 if (status != 0 && status != 37) {
10113 send_resp(dut, conn, SIGMA_ERROR,
10114 "ErrorCode,Unsupported status value");
10115 return 0;
10116 }
10117
10118 if (timeout != 0 && timeout != 301) {
10119 send_resp(dut, conn, SIGMA_ERROR,
10120 "ErrorCode,Unsupported timeout value");
10121 return 0;
10122 }
10123
10124 if (status && timeout) {
10125 send_resp(dut, conn, SIGMA_ERROR,
10126 "ErrorCode,Unsupported timeout+status "
10127 "combination");
10128 return 0;
10129 }
10130
10131 if (status == 37 &&
10132 wpa_command(intf, "SET tdls_testing 0x200")) {
10133 send_resp(dut, conn, SIGMA_ERROR,
10134 "ErrorCode,Failed to enable "
10135 "decline setup response test mode");
10136 return 0;
10137 }
10138
10139 if (timeout == 301) {
10140 int res;
10141 if (dut->no_tpk_expiration)
10142 res = wpa_command(intf,
10143 "SET tdls_testing 0x108");
10144 else
10145 res = wpa_command(intf,
10146 "SET tdls_testing 0x8");
10147 if (res) {
10148 send_resp(dut, conn, SIGMA_ERROR,
10149 "ErrorCode,Failed to set short TPK "
10150 "lifetime");
10151 return 0;
10152 }
10153 }
10154
10155 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
10156 if (wpa_command(intf, buf) < 0) {
10157 send_resp(dut, conn, SIGMA_ERROR,
10158 "ErrorCode,Failed to send TDLS setup");
10159 return 0;
10160 }
10161 return 1;
10162 }
10163
10164 if (strcasecmp(val, "TEARDOWN") == 0) {
10165 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
10166 if (wpa_command(intf, buf) < 0) {
10167 send_resp(dut, conn, SIGMA_ERROR,
10168 "ErrorCode,Failed to send TDLS teardown");
10169 return 0;
10170 }
10171 return 1;
10172 }
10173
10174 send_resp(dut, conn, SIGMA_ERROR,
10175 "ErrorCode,Unsupported TDLS frame");
10176 return 0;
10177}
10178
10179
10180static int sta_ap_known(const char *ifname, const char *bssid)
10181{
10182 char buf[4096];
10183
Jouni Malinendd32f192018-09-15 02:55:19 +030010184 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010185 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
10186 return 0;
10187 if (strncmp(buf, "id=", 3) != 0)
10188 return 0;
10189 return 1;
10190}
10191
10192
10193static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
10194 const char *bssid)
10195{
10196 int res;
10197 struct wpa_ctrl *ctrl;
10198 char buf[256];
10199
10200 if (sta_ap_known(ifname, bssid))
10201 return 0;
10202 sigma_dut_print(dut, DUT_MSG_DEBUG,
10203 "AP not in BSS table - start scan");
10204
10205 ctrl = open_wpa_mon(ifname);
10206 if (ctrl == NULL) {
10207 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10208 "wpa_supplicant monitor connection");
10209 return -1;
10210 }
10211
10212 if (wpa_command(ifname, "SCAN") < 0) {
10213 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
10214 wpa_ctrl_detach(ctrl);
10215 wpa_ctrl_close(ctrl);
10216 return -1;
10217 }
10218
10219 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10220 buf, sizeof(buf));
10221
10222 wpa_ctrl_detach(ctrl);
10223 wpa_ctrl_close(ctrl);
10224
10225 if (res < 0) {
10226 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
10227 return -1;
10228 }
10229
10230 if (sta_ap_known(ifname, bssid))
10231 return 0;
10232 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
10233 return -1;
10234}
10235
10236
10237static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
10238 struct sigma_conn *conn,
10239 struct sigma_cmd *cmd,
10240 const char *intf)
10241{
10242 char buf[200];
10243
10244 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
10245 if (system(buf) != 0) {
10246 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
10247 "ndsend");
10248 return 0;
10249 }
10250
10251 return 1;
10252}
10253
10254
10255static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10256 struct sigma_conn *conn,
10257 struct sigma_cmd *cmd,
10258 const char *intf)
10259{
10260 char buf[200];
10261 const char *ip = get_param(cmd, "SenderIP");
10262
Peng Xu26b356d2017-10-04 17:58:16 -070010263 if (!ip)
10264 return 0;
10265
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010266 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10267 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10268 if (system(buf) == 0) {
10269 sigma_dut_print(dut, DUT_MSG_INFO,
10270 "Neighbor Solicitation got a response "
10271 "for %s@%s", ip, intf);
10272 }
10273
10274 return 1;
10275}
10276
10277
10278static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10279 struct sigma_conn *conn,
10280 struct sigma_cmd *cmd,
10281 const char *ifname)
10282{
10283 char buf[200];
10284 const char *ip = get_param(cmd, "SenderIP");
10285
10286 if (ip == NULL) {
10287 send_resp(dut, conn, SIGMA_ERROR,
10288 "ErrorCode,Missing SenderIP parameter");
10289 return 0;
10290 }
10291 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10292 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10293 if (system(buf) != 0) {
10294 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10295 "for %s@%s", ip, ifname);
10296 }
10297
10298 return 1;
10299}
10300
10301
10302static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10303 struct sigma_conn *conn,
10304 struct sigma_cmd *cmd,
10305 const char *ifname)
10306{
10307 char buf[200];
10308 char ip[16];
10309 int s;
Peng Xub3756882017-10-04 14:39:09 -070010310 struct ifreq ifr;
10311 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010312
10313 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010314 if (s < 0) {
10315 perror("socket");
10316 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010317 }
10318
Peng Xub3756882017-10-04 14:39:09 -070010319 memset(&ifr, 0, sizeof(ifr));
10320 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10321 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10322 sigma_dut_print(dut, DUT_MSG_INFO,
10323 "Failed to get %s IP address: %s",
10324 ifname, strerror(errno));
10325 close(s);
10326 return -1;
10327 }
10328 close(s);
10329
10330 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10331 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10332
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010333 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10334 ip);
10335 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10336 if (system(buf) != 0) {
10337 }
10338
10339 return 1;
10340}
10341
10342
10343static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10344 struct sigma_conn *conn,
10345 struct sigma_cmd *cmd,
10346 const char *ifname)
10347{
10348 char buf[200], addr[20];
10349 char dst[ETH_ALEN], src[ETH_ALEN];
10350 short ethtype = htons(ETH_P_ARP);
10351 char *pos;
10352 int s, res;
10353 const char *val;
10354 struct sockaddr_in taddr;
10355
10356 val = get_param(cmd, "dest");
10357 if (val)
10358 hwaddr_aton(val, (unsigned char *) dst);
10359
10360 val = get_param(cmd, "DestIP");
10361 if (val)
10362 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010363 else
10364 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010365
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010366 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010367 sizeof(addr)) < 0)
10368 return -2;
10369 hwaddr_aton(addr, (unsigned char *) src);
10370
10371 pos = buf;
10372 *pos++ = 0x00;
10373 *pos++ = 0x01;
10374 *pos++ = 0x08;
10375 *pos++ = 0x00;
10376 *pos++ = 0x06;
10377 *pos++ = 0x04;
10378 *pos++ = 0x00;
10379 *pos++ = 0x02;
10380 memcpy(pos, src, ETH_ALEN);
10381 pos += ETH_ALEN;
10382 memcpy(pos, &taddr.sin_addr, 4);
10383 pos += 4;
10384 memcpy(pos, dst, ETH_ALEN);
10385 pos += ETH_ALEN;
10386 memcpy(pos, &taddr.sin_addr, 4);
10387 pos += 4;
10388
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010389 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010390 if (s < 0) {
10391 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10392 "monitor socket");
10393 return 0;
10394 }
10395
10396 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10397 if (res < 0) {
10398 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10399 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010400 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010401 return 0;
10402 }
10403
10404 close(s);
10405
10406 return 1;
10407}
10408
10409
10410static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10411 struct sigma_conn *conn,
10412 struct sigma_cmd *cmd,
10413 const char *intf, const char *dest)
10414{
10415 char buf[100];
10416
10417 if (if_nametoindex("sigmadut") == 0) {
10418 snprintf(buf, sizeof(buf),
10419 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010420 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010421 if (system(buf) != 0 ||
10422 if_nametoindex("sigmadut") == 0) {
10423 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10424 "monitor interface with '%s'", buf);
10425 return -2;
10426 }
10427 }
10428
10429 if (system("ifconfig sigmadut up") != 0) {
10430 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10431 "monitor interface up");
10432 return -2;
10433 }
10434
Veerendranath Jakkam49774122020-07-05 09:52:18 +053010435 return sta_inject_frame(dut, conn, intf, DLS_REQ, UNPROTECTED, dest, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010436}
10437
10438
10439static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10440 struct sigma_conn *conn,
10441 struct sigma_cmd *cmd)
10442{
10443 const char *intf = get_param(cmd, "Interface");
10444 const char *dest = get_param(cmd, "Dest");
10445 const char *type = get_param(cmd, "FrameName");
10446 const char *val;
10447 char buf[200], *pos, *end;
10448 int count, count2;
10449
10450 if (type == NULL)
10451 type = get_param(cmd, "Type");
10452
10453 if (intf == NULL || dest == NULL || type == NULL)
10454 return -1;
10455
10456 if (strcasecmp(type, "NeighAdv") == 0)
10457 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10458
10459 if (strcasecmp(type, "NeighSolicitReq") == 0)
10460 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10461
10462 if (strcasecmp(type, "ARPProbe") == 0)
10463 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10464
10465 if (strcasecmp(type, "ARPAnnounce") == 0)
10466 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10467
10468 if (strcasecmp(type, "ARPReply") == 0)
10469 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10470
10471 if (strcasecmp(type, "DLS-request") == 0 ||
10472 strcasecmp(type, "DLSrequest") == 0)
10473 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10474 dest);
10475
10476 if (strcasecmp(type, "ANQPQuery") != 0 &&
10477 strcasecmp(type, "Query") != 0) {
10478 send_resp(dut, conn, SIGMA_ERROR,
10479 "ErrorCode,Unsupported HS 2.0 send frame type");
10480 return 0;
10481 }
10482
10483 if (sta_scan_ap(dut, intf, dest) < 0) {
10484 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10485 "the requested AP");
10486 return 0;
10487 }
10488
10489 pos = buf;
10490 end = buf + sizeof(buf);
10491 count = 0;
10492 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10493
10494 val = get_param(cmd, "ANQP_CAP_LIST");
10495 if (val && atoi(val)) {
10496 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10497 count++;
10498 }
10499
10500 val = get_param(cmd, "VENUE_NAME");
10501 if (val && atoi(val)) {
10502 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10503 count++;
10504 }
10505
10506 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10507 if (val && atoi(val)) {
10508 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10509 count++;
10510 }
10511
10512 val = get_param(cmd, "ROAMING_CONS");
10513 if (val && atoi(val)) {
10514 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10515 count++;
10516 }
10517
10518 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10519 if (val && atoi(val)) {
10520 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10521 count++;
10522 }
10523
10524 val = get_param(cmd, "NAI_REALM_LIST");
10525 if (val && atoi(val)) {
10526 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10527 count++;
10528 }
10529
10530 val = get_param(cmd, "3GPP_INFO");
10531 if (val && atoi(val)) {
10532 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10533 count++;
10534 }
10535
10536 val = get_param(cmd, "DOMAIN_LIST");
10537 if (val && atoi(val)) {
10538 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10539 count++;
10540 }
10541
Jouni Malinen34cf9532018-04-29 19:26:33 +030010542 val = get_param(cmd, "Venue_URL");
10543 if (val && atoi(val)) {
10544 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10545 count++;
10546 }
10547
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010548 val = get_param(cmd, "Advice_Of_Charge");
10549 if (val && atoi(val)) {
10550 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10551 count++;
10552 }
10553
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010554 if (count && wpa_command(intf, buf)) {
10555 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10556 return 0;
10557 }
10558
10559 pos = buf;
10560 end = buf + sizeof(buf);
10561 count2 = 0;
10562 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10563
10564 val = get_param(cmd, "HS_CAP_LIST");
10565 if (val && atoi(val)) {
10566 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10567 count2++;
10568 }
10569
10570 val = get_param(cmd, "OPER_NAME");
10571 if (val && atoi(val)) {
10572 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10573 count2++;
10574 }
10575
10576 val = get_param(cmd, "WAN_METRICS");
10577 if (!val)
10578 val = get_param(cmd, "WAN_MAT");
10579 if (!val)
10580 val = get_param(cmd, "WAN_MET");
10581 if (val && atoi(val)) {
10582 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10583 count2++;
10584 }
10585
10586 val = get_param(cmd, "CONNECTION_CAPABILITY");
10587 if (val && atoi(val)) {
10588 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10589 count2++;
10590 }
10591
10592 val = get_param(cmd, "OP_CLASS");
10593 if (val && atoi(val)) {
10594 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10595 count2++;
10596 }
10597
10598 val = get_param(cmd, "OSU_PROVIDER_LIST");
10599 if (val && atoi(val)) {
10600 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10601 count2++;
10602 }
10603
Jouni Malinenf67afec2018-04-29 19:24:58 +030010604 val = get_param(cmd, "OPER_ICON_METADATA");
10605 if (!val)
10606 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10607 if (val && atoi(val)) {
10608 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10609 count2++;
10610 }
10611
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010612 if (count && count2) {
10613 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10614 "second query");
10615 sleep(1);
10616 }
10617
10618 if (count2 && wpa_command(intf, buf)) {
10619 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10620 "failed");
10621 return 0;
10622 }
10623
10624 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10625 if (val) {
10626 if (count || count2) {
10627 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10628 "sending out second query");
10629 sleep(1);
10630 }
10631
10632 if (strcmp(val, "1") == 0)
10633 val = "mail.example.com";
10634 snprintf(buf, end - pos,
10635 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10636 dest, val);
10637 if (wpa_command(intf, buf)) {
10638 send_resp(dut, conn, SIGMA_ERROR,
10639 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10640 "failed");
10641 return 0;
10642 }
10643 }
10644
10645 val = get_param(cmd, "ICON_REQUEST");
10646 if (val) {
10647 if (count || count2) {
10648 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10649 "sending out second query");
10650 sleep(1);
10651 }
10652
10653 snprintf(buf, end - pos,
10654 "HS20_ICON_REQUEST %s %s", dest, val);
10655 if (wpa_command(intf, buf)) {
10656 send_resp(dut, conn, SIGMA_ERROR,
10657 "ErrorCode,HS20_ICON_REQUEST failed");
10658 return 0;
10659 }
10660 }
10661
10662 return 1;
10663}
10664
10665
10666static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10667 struct sigma_conn *conn,
10668 struct sigma_cmd *cmd)
10669{
10670 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010671 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010672 int chwidth, nss;
10673
10674 val = get_param(cmd, "framename");
10675 if (!val)
10676 return -1;
10677 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10678
10679 /* Command sequence to generate Op mode notification */
10680 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010681 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010682
10683 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010684 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010685
10686 /* Extract Channel width */
10687 val = get_param(cmd, "Channel_width");
10688 if (val) {
10689 switch (atoi(val)) {
10690 case 20:
10691 chwidth = 0;
10692 break;
10693 case 40:
10694 chwidth = 1;
10695 break;
10696 case 80:
10697 chwidth = 2;
10698 break;
10699 case 160:
10700 chwidth = 3;
10701 break;
10702 default:
10703 chwidth = 2;
10704 break;
10705 }
10706
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010707 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010708 }
10709
10710 /* Extract NSS */
10711 val = get_param(cmd, "NSS");
10712 if (val) {
10713 switch (atoi(val)) {
10714 case 1:
10715 nss = 1;
10716 break;
10717 case 2:
10718 nss = 3;
10719 break;
10720 case 3:
10721 nss = 7;
10722 break;
10723 default:
10724 /* We do not support NSS > 3 */
10725 nss = 3;
10726 break;
10727 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010728 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010729 }
10730
10731 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010732 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010733 }
10734
10735 return 1;
10736}
10737
10738
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010739static int wcn_sta_set_pmf_config(struct sigma_dut *dut, const char *intf,
10740 enum send_frame_protection protected)
10741{
10742#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010743 return wcn_wifi_test_config_set_u8(
10744 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_PMF_PROTECTION,
10745 protected);
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010746#else /* NL80211_SUPPORT */
10747 sigma_dut_print(dut, DUT_MSG_ERROR,
10748 "PMF config cannot be set without NL80211_SUPPORT defined");
10749 return -1;
10750#endif /* NL80211_SUPPORT */
10751}
10752
10753
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010754static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10755 struct sigma_conn *conn,
10756 struct sigma_cmd *cmd)
10757{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010758 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010759 case DRIVER_ATHEROS:
10760 return ath_sta_send_frame_vht(dut, conn, cmd);
10761 default:
10762 send_resp(dut, conn, SIGMA_ERROR,
10763 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10764 return 0;
10765 }
10766}
10767
10768
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010769static int wcn_sta_send_disassoc(struct sigma_dut *dut, const char *intf)
10770{
10771#ifdef NL80211_SUPPORT
Veerendranath Jakkam050b85a2020-07-04 04:00:32 +053010772 return wcn_wifi_test_config_set_flag(
10773 dut, intf, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_DISASSOC_TX);
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010774#else /* NL80211_SUPPORT */
10775 sigma_dut_print(dut, DUT_MSG_ERROR,
10776 "Disassoc Tx cannot be done without NL80211_SUPPORT defined");
10777 return -1;
10778#endif /* NL80211_SUPPORT */
10779}
10780
10781
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010782static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10783 struct sigma_cmd *cmd)
10784{
10785 const char *val;
10786 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010787 enum send_frame_protection protected;
10788 const char *pmf;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010789
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010790 if (!intf)
10791 return -1;
10792
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010793 val = get_param(cmd, "framename");
10794 if (!val)
10795 return -1;
10796 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10797
Kiran Kumar Lokere00d74412020-07-23 13:26:51 -070010798 pmf = get_param(cmd, "PMFProtected");
10799 if (!pmf)
10800 pmf = get_param(cmd, "Protected");
10801 if (pmf) {
10802 if (strcasecmp(pmf, "Correct-key") == 0 ||
10803 strcasecmp(pmf, "CorrectKey") == 0) {
10804 protected = CORRECT_KEY;
10805 } else if (strcasecmp(pmf, "IncorrectKey") == 0) {
10806 protected = INCORRECT_KEY;
10807 } else if (strcasecmp(pmf, "Unprotected") == 0) {
10808 protected = UNPROTECTED;
10809 } else {
10810 send_resp(dut, conn, SIGMA_ERROR,
10811 "errorCode,Unsupported PMFProtected");
10812 return STATUS_SENT_ERROR;
10813 }
10814 sigma_dut_print(dut, DUT_MSG_DEBUG, "Config PMF protection %d",
10815 protected);
10816 wcn_sta_set_pmf_config(dut, intf, protected);
10817 }
10818
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010819 /* Command sequence to generate Op mode notification */
10820 if (val && strcasecmp(val, "action") == 0) {
10821 val = get_param(cmd, "PPDUTxType");
10822 if (val && strcasecmp(val, "TB") == 0) {
10823 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10824 sigma_dut_print(dut, DUT_MSG_ERROR,
10825 "failed to send TB PPDU Tx cfg");
10826 send_resp(dut, conn, SIGMA_ERROR,
10827 "ErrorCode,set TB PPDU Tx cfg failed");
10828 return 0;
10829 }
10830 return 1;
10831 }
10832
10833 sigma_dut_print(dut, DUT_MSG_ERROR,
10834 "Action Tx type is not defined");
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010835
10836 return SUCCESS_SEND_STATUS;
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010837 }
10838
Kiran Kumar Lokerec2c3b412020-07-23 13:51:27 -070010839 if (strcasecmp(val, "disassoc") == 0)
10840 wcn_sta_send_disassoc(dut, intf);
10841
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010842 return 1;
10843}
10844
10845
10846static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10847 struct sigma_conn *conn,
10848 struct sigma_cmd *cmd)
10849{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010850 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010851 case DRIVER_WCN:
10852 return wcn_sta_send_frame_he(dut, conn, cmd);
10853 default:
10854 send_resp(dut, conn, SIGMA_ERROR,
10855 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10856 return 0;
10857 }
10858}
10859
10860
Lior David0fe101e2017-03-09 16:09:50 +020010861#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010862
10863static int
10864wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10865 const char *frame_name, const char *dest_mac)
10866{
10867 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10868 const char *ssid = get_param(cmd, "ssid");
10869 const char *countstr = get_param(cmd, "count");
10870 const char *channelstr = get_param(cmd, "channel");
10871 const char *group_id = get_param(cmd, "groupid");
10872 const char *client_id = get_param(cmd, "clientmac");
10873 int count, channel, freq, i;
10874 const char *fname;
10875 char frame[1024], src_mac[20], group_id_attr[25],
10876 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10877 const char *group_ssid;
10878 const int group_ssid_prefix_len = 9;
10879 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10880 size_t framelen = sizeof(frame);
10881 struct template_frame_tag tags[2];
10882 size_t tags_total = ARRAY_SIZE(tags);
10883 int tag_index, len, dst_len;
10884
10885 if (!countstr || !channelstr) {
10886 sigma_dut_print(dut, DUT_MSG_ERROR,
10887 "Missing argument: count, channel");
10888 return -1;
10889 }
10890 if (isprobereq && !ssid) {
10891 sigma_dut_print(dut, DUT_MSG_ERROR,
10892 "Missing argument: ssid");
10893 return -1;
10894 }
10895 if (!isprobereq && (!group_id || !client_id)) {
10896 sigma_dut_print(dut, DUT_MSG_ERROR,
10897 "Missing argument: group_id, client_id");
10898 return -1;
10899 }
10900
10901 count = atoi(countstr);
10902 channel = atoi(channelstr);
10903 freq = channel_to_freq(dut, channel);
10904
10905 if (!freq) {
10906 sigma_dut_print(dut, DUT_MSG_ERROR,
10907 "invalid channel: %s", channelstr);
10908 return -1;
10909 }
10910
10911 if (isprobereq) {
10912 if (strcasecmp(ssid, "wildcard") == 0) {
10913 fname = "probe_req_wildcard.txt";
10914 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10915 fname = "probe_req_P2P_Wildcard.txt";
10916 } else {
10917 sigma_dut_print(dut, DUT_MSG_ERROR,
10918 "invalid probe request type");
10919 return -1;
10920 }
10921 } else {
10922 fname = "P2P_device_discovery_req.txt";
10923 }
10924
10925 if (parse_template_frame_file(dut, fname, frame, &framelen,
10926 tags, &tags_total)) {
10927 sigma_dut_print(dut, DUT_MSG_ERROR,
10928 "invalid frame template: %s", fname);
10929 return -1;
10930 }
10931
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010932 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010933 src_mac, sizeof(src_mac)) < 0 ||
10934 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10935 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10936 return -1;
10937 /* Use wildcard BSSID, since we are in PBSS */
10938 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10939
10940 if (!isprobereq) {
10941 tag_index = find_template_frame_tag(tags, tags_total, 1);
10942 if (tag_index < 0) {
10943 sigma_dut_print(dut, DUT_MSG_ERROR,
10944 "can't find device id attribute");
10945 return -1;
10946 }
10947 if (parse_mac_address(dut, client_id,
10948 (unsigned char *) client_mac)) {
10949 sigma_dut_print(dut, DUT_MSG_ERROR,
10950 "invalid client_id: %s", client_id);
10951 return -1;
10952 }
10953 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10954 framelen - tags[tag_index].offset,
10955 IEEE80211_P2P_ATTR_DEVICE_ID,
10956 client_mac, ETH_ALEN)) {
10957 sigma_dut_print(dut, DUT_MSG_ERROR,
10958 "fail to replace device id attribute");
10959 return -1;
10960 }
10961
10962 /*
10963 * group_id arg contains device MAC address followed by
10964 * space and SSID (DIRECT-somessid).
10965 * group id attribute contains device address (6 bytes)
10966 * followed by SSID prefix DIRECT-XX (9 bytes)
10967 */
10968 if (strlen(group_id) < sizeof(device_macstr)) {
10969 sigma_dut_print(dut, DUT_MSG_ERROR,
10970 "group_id arg too short");
10971 return -1;
10972 }
10973 memcpy(device_macstr, group_id, sizeof(device_macstr));
10974 device_macstr[sizeof(device_macstr) - 1] = '\0';
10975 if (parse_mac_address(dut, device_macstr,
10976 (unsigned char *) group_id_attr)) {
10977 sigma_dut_print(dut, DUT_MSG_ERROR,
10978 "fail to parse device address from group_id");
10979 return -1;
10980 }
10981 group_ssid = strchr(group_id, ' ');
10982 if (!group_ssid) {
10983 sigma_dut_print(dut, DUT_MSG_ERROR,
10984 "invalid group_id arg, no ssid");
10985 return -1;
10986 }
10987 group_ssid++;
10988 len = strlen(group_ssid);
10989 if (len < group_ssid_prefix_len) {
10990 sigma_dut_print(dut, DUT_MSG_ERROR,
10991 "group_id SSID too short");
10992 return -1;
10993 }
10994 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10995 if (len > dst_len) {
10996 sigma_dut_print(dut, DUT_MSG_ERROR,
10997 "group_id SSID (%s) too long",
10998 group_ssid);
10999 return -1;
11000 }
11001
11002 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
11003 tag_index = find_template_frame_tag(tags, tags_total, 2);
11004 if (tag_index < 0) {
11005 sigma_dut_print(dut, DUT_MSG_ERROR,
11006 "can't find group id attribute");
11007 return -1;
11008 }
11009 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
11010 framelen - tags[tag_index].offset,
11011 IEEE80211_P2P_ATTR_GROUP_ID,
11012 group_id_attr,
11013 sizeof(group_id_attr))) {
11014 sigma_dut_print(dut, DUT_MSG_ERROR,
11015 "fail to replace group id attribute");
11016 return -1;
11017 }
11018 }
11019
11020 for (i = 0; i < count; i++) {
11021 if (wil6210_transmit_frame(dut, freq,
11022 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
11023 frame, framelen)) {
11024 sigma_dut_print(dut, DUT_MSG_ERROR,
11025 "fail to transmit probe request frame");
11026 return -1;
11027 }
11028 }
11029
11030 return 0;
11031}
11032
11033
Lior David0fe101e2017-03-09 16:09:50 +020011034int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
11035 struct sigma_cmd *cmd)
11036{
11037 const char *frame_name = get_param(cmd, "framename");
11038 const char *mac = get_param(cmd, "dest_mac");
11039
11040 if (!frame_name || !mac) {
11041 sigma_dut_print(dut, DUT_MSG_ERROR,
11042 "framename and dest_mac must be provided");
11043 return -1;
11044 }
11045
11046 if (strcasecmp(frame_name, "brp") == 0) {
11047 const char *l_rx = get_param(cmd, "L-RX");
11048 int l_rx_i;
11049
11050 if (!l_rx) {
11051 sigma_dut_print(dut, DUT_MSG_ERROR,
11052 "L-RX must be provided");
11053 return -1;
11054 }
11055 l_rx_i = atoi(l_rx);
11056
11057 sigma_dut_print(dut, DUT_MSG_INFO,
11058 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
11059 mac, l_rx);
11060 if (l_rx_i != 16) {
11061 sigma_dut_print(dut, DUT_MSG_ERROR,
11062 "unsupported L-RX: %s", l_rx);
11063 return -1;
11064 }
11065
11066 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
11067 return -1;
11068 } else if (strcasecmp(frame_name, "ssw") == 0) {
11069 sigma_dut_print(dut, DUT_MSG_INFO,
11070 "dev_send_frame: SLS, dest_mac %s", mac);
11071 if (wil6210_send_sls(dut, mac))
11072 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011073 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
11074 (strcasecmp(frame_name, "devdiscreq") == 0)) {
11075 sigma_dut_print(dut, DUT_MSG_INFO,
11076 "dev_send_frame: %s, dest_mac %s", frame_name,
11077 mac);
11078 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
11079 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020011080 } else {
11081 sigma_dut_print(dut, DUT_MSG_ERROR,
11082 "unsupported frame type: %s", frame_name);
11083 return -1;
11084 }
11085
11086 return 1;
11087}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030011088
Lior David0fe101e2017-03-09 16:09:50 +020011089#endif /* __linux__ */
11090
11091
11092static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
11093 struct sigma_conn *conn,
11094 struct sigma_cmd *cmd)
11095{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011096 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020011097#ifdef __linux__
11098 case DRIVER_WIL6210:
11099 return wil6210_send_frame_60g(dut, conn, cmd);
11100#endif /* __linux__ */
11101 default:
11102 send_resp(dut, conn, SIGMA_ERROR,
11103 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
11104 return 0;
11105 }
11106}
11107
11108
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011109static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
11110 const char *intf, struct sigma_cmd *cmd)
11111{
11112 const char *val, *addr;
11113 char buf[100];
11114
11115 addr = get_param(cmd, "DestMac");
11116 if (!addr) {
11117 send_resp(dut, conn, SIGMA_INVALID,
11118 "ErrorCode,AP MAC address is missing");
11119 return 0;
11120 }
11121
11122 val = get_param(cmd, "ANQPQuery_ID");
11123 if (!val) {
11124 send_resp(dut, conn, SIGMA_INVALID,
11125 "ErrorCode,Missing ANQPQuery_ID");
11126 return 0;
11127 }
11128
11129 if (strcasecmp(val, "NeighborReportReq") == 0) {
11130 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
11131 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
11132 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
11133 } else {
11134 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
11135 val);
11136 send_resp(dut, conn, SIGMA_INVALID,
11137 "ErrorCode,Invalid ANQPQuery_ID");
11138 return 0;
11139 }
11140
Ashwini Patild174f2c2017-04-13 16:49:46 +053011141 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
11142 * (Address3 = Wildcard BSSID when sent to not-associated AP;
11143 * if associated, AP BSSID).
11144 */
11145 if (wpa_command(intf, "SET gas_address3 1") < 0) {
11146 send_resp(dut, conn, SIGMA_ERROR,
11147 "ErrorCode,Failed to set gas_address3");
11148 return 0;
11149 }
11150
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011151 if (wpa_command(intf, buf) < 0) {
11152 send_resp(dut, conn, SIGMA_ERROR,
11153 "ErrorCode,Failed to send ANQP query");
11154 return 0;
11155 }
11156
11157 return 1;
11158}
11159
11160
11161static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
11162 struct sigma_conn *conn,
11163 const char *intf,
11164 struct sigma_cmd *cmd)
11165{
11166 const char *val = get_param(cmd, "FrameName");
11167
11168 if (val && strcasecmp(val, "ANQPQuery") == 0)
11169 return mbo_send_anqp_query(dut, conn, intf, cmd);
11170
11171 return 2;
11172}
11173
11174
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011175static enum sigma_cmd_result cmd_sta_send_frame_wpa3(struct sigma_dut *dut,
11176 struct sigma_conn *conn,
11177 const char *intf,
11178 struct sigma_cmd *cmd)
11179{
11180 const char *val = get_param(cmd, "framename");
11181
11182 if (!val)
11183 return INVALID_SEND_STATUS;
11184
11185 if (strcasecmp(val, "SAQueryReq") == 0) {
11186 val = get_param(cmd, "OCIChannel");
11187
11188 if (!val) {
11189 send_resp(dut, conn, SIGMA_ERROR,
11190 "errorCode,OCIChannel not present");
11191 return STATUS_SENT_ERROR;
11192 }
11193
11194 dut->saquery_oci_freq = channel_to_freq(dut, atoi(val));
11195 if (!dut->saquery_oci_freq) {
11196 send_resp(dut, conn, SIGMA_ERROR,
11197 "errorCode,Invalid OCIChannel number");
11198 return STATUS_SENT_ERROR;
11199 }
11200
11201 return sta_inject_frame(dut, conn, intf, SAQUERY, CORRECT_KEY,
11202 NULL, 0);
11203 }
11204
11205 if (strcasecmp(val, "reassocreq") == 0)
11206 return sta_inject_frame(dut, conn, intf, REASSOCREQ,
11207 CORRECT_KEY, NULL, 0);
11208
Veerendranath9f81dfb2020-08-10 01:21:29 -070011209 if (strcasecmp(val, "ANQPQuery") == 0) {
11210 char buf[50];
11211 const char *dest = get_param(cmd, "DestMac");
11212 const char *chan = get_param(cmd, "channel");
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011213 const char *freq_str = get_param(cmd, "ChnlFreq");
Veerendranath9f81dfb2020-08-10 01:21:29 -070011214 int len, freq;
11215
Veerendranath Jakkam78862fc2020-11-19 21:23:27 +053011216 if (freq_str)
11217 freq = atoi(freq_str);
11218 else
11219 freq = chan ? channel_to_freq(dut, atoi(chan)) : 0;
11220
Veerendranath9f81dfb2020-08-10 01:21:29 -070011221 if (!dest || !freq)
11222 return INVALID_SEND_STATUS;
11223
11224 len = snprintf(buf, sizeof(buf), "ANQP_GET %s freq=%d 257",
11225 dest, freq);
11226 if (len < 0 || len >= sizeof(buf)) {
11227 sigma_dut_print(dut, DUT_MSG_ERROR,
11228 "Failed to allocate buf");
11229 return ERROR_SEND_STATUS;
11230 }
11231
11232 if (wpa_command(intf, buf) != 0) {
11233 send_resp(dut, conn, SIGMA_ERROR,
11234 "ErrorCode,Failed to send ANQP Query frame");
11235 return STATUS_SENT_ERROR;
11236 }
11237
11238 sigma_dut_print(dut, DUT_MSG_DEBUG,
11239 "ANQP Query sent: %s", buf);
11240
11241 return SUCCESS_SEND_STATUS;
11242 }
11243
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011244 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported framename");
11245 return STATUS_SENT_ERROR;
11246}
11247
11248
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011249static enum sigma_cmd_result
11250cmd_sta_send_frame_mscs(struct sigma_dut *dut, struct sigma_conn *conn,
11251 const char *intf, struct sigma_cmd *cmd)
11252{
11253 char buf[128], *pos;
11254 const char *val, *classifier_type = "04", *type;
11255 int len, rem_len;
11256 u8 up_bitmap;
11257
11258 val = get_param(cmd, "FrameName");
11259 type = get_param(cmd, "Request_Type");
11260 if (!val || !type || strcasecmp(val, "MSCSReq") != 0) {
11261 sigma_dut_print(dut, DUT_MSG_ERROR,
11262 "%s: frame name or type not valid", __func__);
11263 return INVALID_SEND_STATUS;
11264 }
11265
11266 rem_len = sizeof(buf);
11267 pos = buf;
11268 if (strcasecmp(type, "add") == 0) {
11269 len = snprintf(pos, rem_len, "MSCS add");
11270 } else if (strcasecmp(type, "update") == 0) {
11271 len = snprintf(pos, rem_len, "MSCS change");
11272 } else if (strcasecmp(type, "remove") == 0) {
11273 if (wpa_command(intf, "MSCS remove") != 0) {
11274 send_resp(dut, conn, SIGMA_ERROR,
11275 "ErrorCode,Failed to send MSCS frame req");
11276 return STATUS_SENT_ERROR;
11277 }
11278 return SUCCESS_SEND_STATUS;
11279 } else {
11280 sigma_dut_print(dut, DUT_MSG_ERROR,
11281 "%s: request type invalid", __func__);
11282 return INVALID_SEND_STATUS;
11283 }
11284
11285 if (len < 0 || len >= rem_len)
11286 goto fail;
11287
11288 pos += len;
11289 rem_len -= len;
11290
11291 val = get_param(cmd, "User_Priority_Bitmap");
11292 if (!val) {
11293 sigma_dut_print(dut, DUT_MSG_ERROR,
11294 "%s: user priority bitmap empty", __func__);
11295 return INVALID_SEND_STATUS;
11296 }
11297
11298 switch (atoi(val)) {
11299 case 0:
11300 up_bitmap = 0x00;
11301 break;
11302 case 1:
11303 up_bitmap = 0xF0;
11304 break;
11305 case 2:
11306 up_bitmap = 0xF6;
11307 break;
11308 default:
11309 sigma_dut_print(dut, DUT_MSG_ERROR,
11310 "%s: Unknown User_Priority_Bitmap value %d",
11311 __func__, atoi(val));
11312 return INVALID_SEND_STATUS;
11313 }
11314
11315 len = snprintf(pos, rem_len, " up_bitmap=%02x", up_bitmap);
11316 if (len < 0 || len >= rem_len)
11317 goto fail;
11318
11319 pos += len;
11320 rem_len -= len;
11321
11322 val = get_param(cmd, "User_Priority_Limit");
11323 if (!val) {
11324 sigma_dut_print(dut, DUT_MSG_ERROR,
11325 "%s: invalid user priority limit", __func__);
11326 return INVALID_SEND_STATUS;
11327 }
11328
11329 len = snprintf(pos, rem_len, " up_limit=%s", val);
11330 if (len < 0 || len >= rem_len)
11331 goto fail;
11332
11333 pos += len;
11334 rem_len -= len;
11335
11336 val = get_param(cmd, "Stream_Timeout");
11337 if (!val)
11338 val = get_param(cmd, "Stream_Timtout");
11339 if (!val) {
11340 sigma_dut_print(dut, DUT_MSG_ERROR,
11341 "%s: invalid stream timeout", __func__);
11342 return INVALID_SEND_STATUS;
11343 }
11344
11345 len = snprintf(pos, rem_len, " stream_timeout=%s", val);
11346 if (len < 0 || len >= rem_len)
11347 goto fail;
11348
11349 pos += len;
11350 rem_len -= len;
11351
11352 val = get_param(cmd, "TCLAS_Mask");
11353 if (!val) {
11354 sigma_dut_print(dut, DUT_MSG_ERROR,
11355 "%s: invalid tclas mask", __func__);
11356 return INVALID_SEND_STATUS;
11357 }
11358
11359 len = snprintf(pos, rem_len, " frame_classifier=%s%lx%032x",
11360 classifier_type, strtol(val, NULL, 2), 0);
11361 if (len < 0 || len >= rem_len)
11362 goto fail;
11363
11364 if (wpa_command(intf, buf) != 0) {
11365 send_resp(dut, conn, SIGMA_ERROR,
11366 "ErrorCode,Failed to send MSCS frame req");
11367 return STATUS_SENT_ERROR;
11368 }
11369
11370 sigma_dut_print(dut, DUT_MSG_DEBUG,
11371 "MSCS frame request sent: %s", buf);
11372
11373 return SUCCESS_SEND_STATUS;
11374fail:
11375 sigma_dut_print(dut, DUT_MSG_ERROR,
11376 "Failed to create MSCS frame req");
11377 return ERROR_SEND_STATUS;
11378}
11379
11380
Jouni Malinenf7222712019-06-13 01:50:21 +030011381enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
11382 struct sigma_conn *conn,
11383 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011384{
11385 const char *intf = get_param(cmd, "Interface");
11386 const char *val;
11387 enum send_frame_type frame;
11388 enum send_frame_protection protected;
11389 char buf[100];
11390 unsigned char addr[ETH_ALEN];
11391 int res;
11392
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030011393 if (!intf)
11394 return -1;
11395
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011396 val = get_param(cmd, "program");
11397 if (val == NULL)
11398 val = get_param(cmd, "frame");
11399 if (val && strcasecmp(val, "TDLS") == 0)
11400 return cmd_sta_send_frame_tdls(dut, conn, cmd);
11401 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011402 strcasecmp(val, "HS2-R2") == 0 ||
11403 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011404 return cmd_sta_send_frame_hs2(dut, conn, cmd);
11405 if (val && strcasecmp(val, "VHT") == 0)
11406 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070011407 if (val && strcasecmp(val, "HE") == 0)
11408 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070011409 if (val && strcasecmp(val, "LOC") == 0)
11410 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020011411 if (val && strcasecmp(val, "60GHz") == 0)
11412 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053011413 if (val && strcasecmp(val, "MBO") == 0) {
11414 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
11415 if (res != 2)
11416 return res;
11417 }
Veerendranath Jakkam54ddc352020-07-05 15:47:54 +053011418 if (val && strcasecmp(val, "WPA3") == 0)
11419 return cmd_sta_send_frame_wpa3(dut, conn, intf, cmd);
Vinita S. Malooee9e7e92020-04-28 16:26:50 +053011420 if (val && strcasecmp(val, "QM") == 0)
11421 return cmd_sta_send_frame_mscs(dut, conn, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011422
11423 val = get_param(cmd, "TD_DISC");
11424 if (val) {
11425 if (hwaddr_aton(val, addr) < 0)
11426 return -1;
11427 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
11428 if (wpa_command(intf, buf) < 0) {
11429 send_resp(dut, conn, SIGMA_ERROR,
11430 "ErrorCode,Failed to send TDLS discovery");
11431 return 0;
11432 }
11433 return 1;
11434 }
11435
11436 val = get_param(cmd, "TD_Setup");
11437 if (val) {
11438 if (hwaddr_aton(val, addr) < 0)
11439 return -1;
11440 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
11441 if (wpa_command(intf, buf) < 0) {
11442 send_resp(dut, conn, SIGMA_ERROR,
11443 "ErrorCode,Failed to start TDLS setup");
11444 return 0;
11445 }
11446 return 1;
11447 }
11448
11449 val = get_param(cmd, "TD_TearDown");
11450 if (val) {
11451 if (hwaddr_aton(val, addr) < 0)
11452 return -1;
11453 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
11454 if (wpa_command(intf, buf) < 0) {
11455 send_resp(dut, conn, SIGMA_ERROR,
11456 "ErrorCode,Failed to tear down TDLS link");
11457 return 0;
11458 }
11459 return 1;
11460 }
11461
11462 val = get_param(cmd, "TD_ChannelSwitch");
11463 if (val) {
11464 /* TODO */
11465 send_resp(dut, conn, SIGMA_ERROR,
11466 "ErrorCode,TD_ChannelSwitch not yet supported");
11467 return 0;
11468 }
11469
11470 val = get_param(cmd, "TD_NF");
11471 if (val) {
11472 /* TODO */
11473 send_resp(dut, conn, SIGMA_ERROR,
11474 "ErrorCode,TD_NF not yet supported");
11475 return 0;
11476 }
11477
11478 val = get_param(cmd, "PMFFrameType");
11479 if (val == NULL)
11480 val = get_param(cmd, "FrameName");
11481 if (val == NULL)
11482 val = get_param(cmd, "Type");
11483 if (val == NULL)
11484 return -1;
11485 if (strcasecmp(val, "disassoc") == 0)
11486 frame = DISASSOC;
11487 else if (strcasecmp(val, "deauth") == 0)
11488 frame = DEAUTH;
11489 else if (strcasecmp(val, "saquery") == 0)
11490 frame = SAQUERY;
11491 else if (strcasecmp(val, "auth") == 0)
11492 frame = AUTH;
11493 else if (strcasecmp(val, "assocreq") == 0)
11494 frame = ASSOCREQ;
11495 else if (strcasecmp(val, "reassocreq") == 0)
11496 frame = REASSOCREQ;
11497 else if (strcasecmp(val, "neigreq") == 0) {
11498 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
11499
11500 val = get_param(cmd, "ssid");
11501 if (val == NULL)
11502 return -1;
11503
11504 res = send_neighbor_request(dut, intf, val);
11505 if (res) {
11506 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11507 "Failed to send neighbor report request");
11508 return 0;
11509 }
11510
11511 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053011512 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
11513 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011514 sigma_dut_print(dut, DUT_MSG_DEBUG,
11515 "Got Transition Management Query");
11516
Ashwini Patil5acd7382017-04-13 15:55:04 +053011517 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011518 if (res) {
11519 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11520 "Failed to send Transition Management Query");
11521 return 0;
11522 }
11523
11524 return 1;
11525 } else {
11526 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11527 "PMFFrameType");
11528 return 0;
11529 }
11530
11531 val = get_param(cmd, "PMFProtected");
11532 if (val == NULL)
11533 val = get_param(cmd, "Protected");
11534 if (val == NULL)
11535 return -1;
11536 if (strcasecmp(val, "Correct-key") == 0 ||
11537 strcasecmp(val, "CorrectKey") == 0)
11538 protected = CORRECT_KEY;
11539 else if (strcasecmp(val, "IncorrectKey") == 0)
11540 protected = INCORRECT_KEY;
11541 else if (strcasecmp(val, "Unprotected") == 0)
11542 protected = UNPROTECTED;
11543 else {
11544 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11545 "PMFProtected");
11546 return 0;
11547 }
11548
11549 if (protected != UNPROTECTED &&
11550 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11551 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11552 "PMFProtected for auth/assocreq/reassocreq");
11553 return 0;
11554 }
11555
11556 if (if_nametoindex("sigmadut") == 0) {
11557 snprintf(buf, sizeof(buf),
11558 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011559 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011560 if (system(buf) != 0 ||
11561 if_nametoindex("sigmadut") == 0) {
11562 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11563 "monitor interface with '%s'", buf);
11564 return -2;
11565 }
11566 }
11567
11568 if (system("ifconfig sigmadut up") != 0) {
11569 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11570 "monitor interface up");
11571 return -2;
11572 }
11573
Veerendranath Jakkam49774122020-07-05 09:52:18 +053011574 return sta_inject_frame(dut, conn, intf, frame, protected, NULL, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011575}
11576
11577
11578static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11579 struct sigma_conn *conn,
11580 struct sigma_cmd *cmd,
11581 const char *ifname)
11582{
11583 char buf[200];
11584 const char *val;
11585
11586 val = get_param(cmd, "ClearARP");
11587 if (val && atoi(val) == 1) {
11588 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11589 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11590 if (system(buf) != 0) {
11591 send_resp(dut, conn, SIGMA_ERROR,
11592 "errorCode,Failed to clear ARP cache");
11593 return 0;
11594 }
11595 }
11596
11597 return 1;
11598}
11599
11600
11601int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11602 struct sigma_cmd *cmd)
11603{
11604 const char *intf = get_param(cmd, "Interface");
11605 const char *val;
11606
11607 if (intf == NULL)
11608 return -1;
11609
11610 val = get_param(cmd, "program");
11611 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011612 strcasecmp(val, "HS2-R2") == 0 ||
11613 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011614 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11615
11616 return -1;
11617}
11618
11619
Jouni Malinenf7222712019-06-13 01:50:21 +030011620static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11621 struct sigma_conn *conn,
11622 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011623{
11624 const char *intf = get_param(cmd, "Interface");
11625 const char *mac = get_param(cmd, "MAC");
11626
11627 if (intf == NULL || mac == NULL)
11628 return -1;
11629
11630 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11631 "interface %s to %s", intf, mac);
11632
11633 if (dut->set_macaddr) {
11634 char buf[128];
11635 int res;
11636 if (strcasecmp(mac, "default") == 0) {
11637 res = snprintf(buf, sizeof(buf), "%s",
11638 dut->set_macaddr);
11639 dut->tmp_mac_addr = 0;
11640 } else {
11641 res = snprintf(buf, sizeof(buf), "%s %s",
11642 dut->set_macaddr, mac);
11643 dut->tmp_mac_addr = 1;
11644 }
11645 if (res < 0 || res >= (int) sizeof(buf))
11646 return -1;
11647 if (system(buf) != 0) {
11648 send_resp(dut, conn, SIGMA_ERROR,
11649 "errorCode,Failed to set MAC "
11650 "address");
11651 return 0;
11652 }
11653 return 1;
11654 }
11655
11656 if (strcasecmp(mac, "default") == 0)
11657 return 1;
11658
11659 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11660 "command");
11661 return 0;
11662}
11663
11664
11665static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11666 struct sigma_conn *conn, const char *intf,
11667 int val)
11668{
11669 char buf[200];
11670 int res;
11671
11672 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11673 intf, val);
11674 if (res < 0 || res >= (int) sizeof(buf))
11675 return -1;
11676 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11677 if (system(buf) != 0) {
11678 send_resp(dut, conn, SIGMA_ERROR,
11679 "errorCode,Failed to configure offchannel mode");
11680 return 0;
11681 }
11682
11683 return 1;
11684}
11685
11686
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011687static int off_chan_val(enum sec_ch_offset off)
11688{
11689 switch (off) {
11690 case SEC_CH_NO:
11691 return 0;
11692 case SEC_CH_40ABOVE:
11693 return 40;
11694 case SEC_CH_40BELOW:
11695 return -40;
11696 }
11697
11698 return 0;
11699}
11700
11701
11702static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11703 const char *intf, int off_ch_num,
11704 enum sec_ch_offset sec)
11705{
11706 char buf[200];
11707 int res;
11708
11709 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11710 intf, off_ch_num);
11711 if (res < 0 || res >= (int) sizeof(buf))
11712 return -1;
11713 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11714 if (system(buf) != 0) {
11715 send_resp(dut, conn, SIGMA_ERROR,
11716 "errorCode,Failed to set offchan");
11717 return 0;
11718 }
11719
11720 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11721 intf, off_chan_val(sec));
11722 if (res < 0 || res >= (int) sizeof(buf))
11723 return -1;
11724 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11725 if (system(buf) != 0) {
11726 send_resp(dut, conn, SIGMA_ERROR,
11727 "errorCode,Failed to set sec chan offset");
11728 return 0;
11729 }
11730
11731 return 1;
11732}
11733
11734
11735static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11736 struct sigma_conn *conn,
11737 const char *intf, int off_ch_num,
11738 enum sec_ch_offset sec)
11739{
11740 char buf[200];
11741 int res;
11742
11743 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11744 off_ch_num);
11745 if (res < 0 || res >= (int) sizeof(buf))
11746 return -1;
11747 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11748
11749 if (wpa_command(intf, buf) < 0) {
11750 send_resp(dut, conn, SIGMA_ERROR,
11751 "ErrorCode,Failed to set offchan");
11752 return 0;
11753 }
11754 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11755 off_chan_val(sec));
11756 if (res < 0 || res >= (int) sizeof(buf))
11757 return -1;
11758
11759 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11760
11761 if (wpa_command(intf, buf) < 0) {
11762 send_resp(dut, conn, SIGMA_ERROR,
11763 "ErrorCode,Failed to set sec chan offset");
11764 return 0;
11765 }
11766
11767 return 1;
11768}
11769
11770
11771static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11772 struct sigma_conn *conn,
11773 const char *intf, int val)
11774{
11775 char buf[200];
11776 int res;
11777
11778 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11779 val);
11780 if (res < 0 || res >= (int) sizeof(buf))
11781 return -1;
11782 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11783
11784 if (wpa_command(intf, buf) < 0) {
11785 send_resp(dut, conn, SIGMA_ERROR,
11786 "ErrorCode,Failed to configure offchannel mode");
11787 return 0;
11788 }
11789
11790 return 1;
11791}
11792
11793
11794static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11795 struct sigma_conn *conn,
11796 struct sigma_cmd *cmd)
11797{
11798 const char *val;
11799 enum {
11800 CHSM_NOT_SET,
11801 CHSM_ENABLE,
11802 CHSM_DISABLE,
11803 CHSM_REJREQ,
11804 CHSM_UNSOLRESP
11805 } chsm = CHSM_NOT_SET;
11806 int off_ch_num = -1;
11807 enum sec_ch_offset sec_ch = SEC_CH_NO;
11808 int res;
11809
11810 val = get_param(cmd, "Uapsd");
11811 if (val) {
11812 char buf[100];
11813 if (strcasecmp(val, "Enable") == 0)
11814 snprintf(buf, sizeof(buf), "SET ps 99");
11815 else if (strcasecmp(val, "Disable") == 0)
11816 snprintf(buf, sizeof(buf), "SET ps 98");
11817 else {
11818 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11819 "Unsupported uapsd parameter value");
11820 return 0;
11821 }
11822 if (wpa_command(intf, buf)) {
11823 send_resp(dut, conn, SIGMA_ERROR,
11824 "ErrorCode,Failed to change U-APSD "
11825 "powersave mode");
11826 return 0;
11827 }
11828 }
11829
11830 val = get_param(cmd, "TPKTIMER");
11831 if (val && strcasecmp(val, "DISABLE") == 0) {
11832 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11833 send_resp(dut, conn, SIGMA_ERROR,
11834 "ErrorCode,Failed to enable no TPK "
11835 "expiration test mode");
11836 return 0;
11837 }
11838 dut->no_tpk_expiration = 1;
11839 }
11840
11841 val = get_param(cmd, "ChSwitchMode");
11842 if (val) {
11843 if (strcasecmp(val, "Enable") == 0 ||
11844 strcasecmp(val, "Initiate") == 0)
11845 chsm = CHSM_ENABLE;
11846 else if (strcasecmp(val, "Disable") == 0 ||
11847 strcasecmp(val, "passive") == 0)
11848 chsm = CHSM_DISABLE;
11849 else if (strcasecmp(val, "RejReq") == 0)
11850 chsm = CHSM_REJREQ;
11851 else if (strcasecmp(val, "UnSolResp") == 0)
11852 chsm = CHSM_UNSOLRESP;
11853 else {
11854 send_resp(dut, conn, SIGMA_ERROR,
11855 "ErrorCode,Unknown ChSwitchMode value");
11856 return 0;
11857 }
11858 }
11859
11860 val = get_param(cmd, "OffChNum");
11861 if (val) {
11862 off_ch_num = atoi(val);
11863 if (off_ch_num == 0) {
11864 send_resp(dut, conn, SIGMA_ERROR,
11865 "ErrorCode,Invalid OffChNum");
11866 return 0;
11867 }
11868 }
11869
11870 val = get_param(cmd, "SecChOffset");
11871 if (val) {
11872 if (strcmp(val, "20") == 0)
11873 sec_ch = SEC_CH_NO;
11874 else if (strcasecmp(val, "40above") == 0)
11875 sec_ch = SEC_CH_40ABOVE;
11876 else if (strcasecmp(val, "40below") == 0)
11877 sec_ch = SEC_CH_40BELOW;
11878 else {
11879 send_resp(dut, conn, SIGMA_ERROR,
11880 "ErrorCode,Unknown SecChOffset value");
11881 return 0;
11882 }
11883 }
11884
11885 if (chsm == CHSM_NOT_SET) {
11886 /* no offchannel changes requested */
11887 return 1;
11888 }
11889
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011890 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11891 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011892 send_resp(dut, conn, SIGMA_ERROR,
11893 "ErrorCode,Unknown interface");
11894 return 0;
11895 }
11896
11897 switch (chsm) {
11898 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011899 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011900 break;
11901 case CHSM_ENABLE:
11902 if (off_ch_num < 0) {
11903 send_resp(dut, conn, SIGMA_ERROR,
11904 "ErrorCode,Missing OffChNum argument");
11905 return 0;
11906 }
11907 if (wifi_chip_type == DRIVER_WCN) {
11908 res = tdls_set_offchannel_offset(dut, conn, intf,
11909 off_ch_num, sec_ch);
11910 } else {
11911 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11912 sec_ch);
11913 }
11914 if (res != 1)
11915 return res;
11916 if (wifi_chip_type == DRIVER_WCN)
11917 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11918 else
11919 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11920 break;
11921 case CHSM_DISABLE:
11922 if (wifi_chip_type == DRIVER_WCN)
11923 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11924 else
11925 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11926 break;
11927 case CHSM_REJREQ:
11928 if (wifi_chip_type == DRIVER_WCN)
11929 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11930 else
11931 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11932 break;
11933 case CHSM_UNSOLRESP:
11934 if (off_ch_num < 0) {
11935 send_resp(dut, conn, SIGMA_ERROR,
11936 "ErrorCode,Missing OffChNum argument");
11937 return 0;
11938 }
11939 if (wifi_chip_type == DRIVER_WCN) {
11940 res = tdls_set_offchannel_offset(dut, conn, intf,
11941 off_ch_num, sec_ch);
11942 } else {
11943 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11944 sec_ch);
11945 }
11946 if (res != 1)
11947 return res;
11948 if (wifi_chip_type == DRIVER_WCN)
11949 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11950 else
11951 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11952 break;
11953 }
11954
11955 return res;
11956}
11957
11958
11959static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11960 struct sigma_conn *conn,
11961 struct sigma_cmd *cmd)
11962{
11963 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011964 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011965
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011966 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011967
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011968 val = get_param(cmd, "nss_mcs_opt");
11969 if (val) {
11970 /* String (nss_operating_mode; mcs_operating_mode) */
11971 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011972 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011973
11974 token = strdup(val);
11975 if (!token)
11976 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011977 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011978 if (!result) {
11979 sigma_dut_print(dut, DUT_MSG_ERROR,
11980 "VHT NSS not specified");
11981 goto failed;
11982 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011983 if (strcasecmp(result, "def") != 0) {
11984 nss = atoi(result);
11985 if (nss == 4)
11986 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011987 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011988 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011989
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011990 }
11991
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011992 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011993 if (!result) {
11994 sigma_dut_print(dut, DUT_MSG_ERROR,
11995 "VHT MCS not specified");
11996 goto failed;
11997 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011998 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011999 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012000 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012001 } else {
12002 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012003 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012004 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012005 }
12006 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070012007 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012008 }
12009
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053012010 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012011 return 1;
12012failed:
12013 free(token);
12014 return 0;
12015}
12016
12017
12018static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
12019 struct sigma_conn *conn,
12020 struct sigma_cmd *cmd)
12021{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012022 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012023 case DRIVER_ATHEROS:
12024 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
12025 default:
12026 send_resp(dut, conn, SIGMA_ERROR,
12027 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
12028 return 0;
12029 }
12030}
12031
12032
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012033static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12034 struct sigma_conn *conn,
12035 struct sigma_cmd *cmd)
12036{
12037 const char *val;
12038 char *token = NULL, *result;
12039 char buf[60];
12040
12041 val = get_param(cmd, "nss_mcs_opt");
12042 if (val) {
12043 /* String (nss_operating_mode; mcs_operating_mode) */
12044 int nss, mcs, ratecode;
12045 char *saveptr;
12046
12047 token = strdup(val);
12048 if (!token)
12049 return -2;
12050
12051 result = strtok_r(token, ";", &saveptr);
12052 if (!result) {
12053 sigma_dut_print(dut, DUT_MSG_ERROR,
12054 "HE NSS not specified");
12055 goto failed;
12056 }
12057 nss = 1;
12058 if (strcasecmp(result, "def") != 0)
12059 nss = atoi(result);
12060
12061 result = strtok_r(NULL, ";", &saveptr);
12062 if (!result) {
12063 sigma_dut_print(dut, DUT_MSG_ERROR,
12064 "HE MCS not specified");
12065 goto failed;
12066 }
12067 mcs = 7;
12068 if (strcasecmp(result, "def") != 0)
12069 mcs = atoi(result);
12070
Arif Hussain557bf412018-05-25 17:29:36 -070012071 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012072 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070012073 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012074 } else if (nss > 2) {
12075 sigma_dut_print(dut, DUT_MSG_ERROR,
12076 "HE NSS %d not supported", nss);
12077 goto failed;
12078 }
12079
Arif Hussain557bf412018-05-25 17:29:36 -070012080 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
12081 if (system(buf) != 0) {
12082 sigma_dut_print(dut, DUT_MSG_ERROR,
12083 "nss_mcs_opt: iwpriv %s nss %d failed",
12084 intf, nss);
12085 goto failed;
12086 }
Arif Hussainac6c5112018-05-25 17:34:00 -070012087 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070012088
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012089 /* Add the MCS to the ratecode */
12090 if (mcs >= 0 && mcs <= 11) {
12091 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070012092#ifdef NL80211_SUPPORT
12093 if (dut->device_type == STA_testbed) {
12094 enum he_mcs_config mcs_config;
12095 int ret;
12096
12097 if (mcs <= 7)
12098 mcs_config = HE_80_MCS0_7;
12099 else if (mcs <= 9)
12100 mcs_config = HE_80_MCS0_9;
12101 else
12102 mcs_config = HE_80_MCS0_11;
12103 ret = sta_set_he_mcs(dut, intf, mcs_config);
12104 if (ret) {
12105 sigma_dut_print(dut, DUT_MSG_ERROR,
12106 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
12107 mcs, mcs_config, ret);
12108 goto failed;
12109 }
12110 }
12111#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012112 } else {
12113 sigma_dut_print(dut, DUT_MSG_ERROR,
12114 "HE MCS %d not supported", mcs);
12115 goto failed;
12116 }
12117 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
12118 intf, ratecode);
12119 if (system(buf) != 0) {
12120 sigma_dut_print(dut, DUT_MSG_ERROR,
12121 "iwpriv setting of 11ax rates failed");
12122 goto failed;
12123 }
12124 free(token);
12125 }
12126
12127 val = get_param(cmd, "GI");
12128 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012129 int fix_rate_sgi;
12130
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012131 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012132 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012133 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012134 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012135 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
12136 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012137 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012138 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070012139 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
12140 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012141 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012142 } else {
12143 send_resp(dut, conn, SIGMA_ERROR,
12144 "errorCode,GI value not supported");
12145 return 0;
12146 }
12147 if (system(buf) != 0) {
12148 send_resp(dut, conn, SIGMA_ERROR,
12149 "errorCode,Failed to set shortgi");
12150 return 0;
12151 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080012152 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
12153 intf, fix_rate_sgi);
12154 if (system(buf) != 0) {
12155 send_resp(dut, conn, SIGMA_ERROR,
12156 "errorCode,Failed to set fix rate shortgi");
12157 return STATUS_SENT;
12158 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012159 }
12160
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012161 val = get_param(cmd, "LTF");
12162 if (val) {
12163#ifdef NL80211_SUPPORT
12164 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012165 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012166 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012167 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012168 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080012169 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070012170 } else {
12171 send_resp(dut, conn, SIGMA_ERROR,
12172 "errorCode, LTF value not supported");
12173 return 0;
12174 }
12175#else /* NL80211_SUPPORT */
12176 sigma_dut_print(dut, DUT_MSG_ERROR,
12177 "LTF cannot be set without NL80211_SUPPORT defined");
12178 return -2;
12179#endif /* NL80211_SUPPORT */
12180 }
12181
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070012182 val = get_param(cmd, "TxSUPPDU");
12183 if (val) {
12184 int set_val = 1;
12185
12186 if (strcasecmp(val, "Enable") == 0)
12187 set_val = 1;
12188 else if (strcasecmp(val, "Disable") == 0)
12189 set_val = 0;
12190
12191 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
12192 send_resp(dut, conn, SIGMA_ERROR,
12193 "ErrorCode,Failed to set Tx SU PPDU config");
12194 return 0;
12195 }
12196 }
12197
Arif Hussain480d5f42019-03-12 14:40:42 -070012198 val = get_param(cmd, "TWT_Setup");
12199 if (val) {
12200 if (strcasecmp(val, "Request") == 0) {
12201 if (sta_twt_request(dut, conn, cmd)) {
12202 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070012203 "ErrorCode,TWT setup failed");
Arif Hussain480d5f42019-03-12 14:40:42 -070012204 return STATUS_SENT;
12205 }
12206 } else if (strcasecmp(val, "Teardown") == 0) {
12207 if (sta_twt_teardown(dut, conn, cmd)) {
12208 send_resp(dut, conn, SIGMA_ERROR,
Srinivas Girigowda6707f032020-10-26 15:24:46 -070012209 "ErrorCode,TWT teardown failed");
Arif Hussain480d5f42019-03-12 14:40:42 -070012210 return STATUS_SENT;
12211 }
12212 }
12213 }
12214
Srinivas Girigowda6707f032020-10-26 15:24:46 -070012215 val = get_param(cmd, "TWT_Operation");
12216 if (val) {
12217 if (strcasecmp(val, "Suspend") == 0) {
12218 if (sta_twt_suspend_or_nudge(dut, conn, cmd)) {
12219 send_resp(dut, conn, SIGMA_ERROR,
12220 "ErrorCode,TWT suspend failed");
12221 return STATUS_SENT_ERROR;
12222 }
12223 } else if (strcasecmp(val, "Resume") == 0) {
12224 if (sta_twt_resume(dut, conn, cmd)) {
12225 send_resp(dut, conn, SIGMA_ERROR,
12226 "ErrorCode,TWT resume failed");
12227 return STATUS_SENT_ERROR;
12228 }
12229 }
12230 }
12231
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080012232 val = get_param(cmd, "transmitOMI");
12233 if (val && sta_transmit_omi(dut, conn, cmd)) {
12234 send_resp(dut, conn, SIGMA_ERROR,
12235 "ErrorCode,sta_transmit_omi failed");
12236 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070012237 }
12238
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012239 val = get_param(cmd, "Powersave");
12240 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012241 int ps;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012242
12243 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012244 ps = 2;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012245 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012246 ps = 1;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012247 } else {
12248 sigma_dut_print(dut, DUT_MSG_ERROR,
12249 "Unsupported Powersave value '%s'",
12250 val);
12251 return -1;
12252 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012253 if (set_power_save_wcn(dut, intf, ps) < 0)
12254 return 0;
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080012255 }
12256
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080012257 val = get_param(cmd, "MU_EDCA");
12258 if (val) {
12259 if (strcasecmp(val, "Override") == 0) {
12260 if (sta_set_mu_edca_override(dut, intf, 1)) {
12261 send_resp(dut, conn, SIGMA_ERROR,
12262 "errorCode,MU EDCA override set failed");
12263 return STATUS_SENT;
12264 }
12265 } else if (strcasecmp(val, "Disable") == 0) {
12266 if (sta_set_mu_edca_override(dut, intf, 0)) {
12267 send_resp(dut, conn, SIGMA_ERROR,
12268 "errorCode,MU EDCA override disable failed");
12269 return STATUS_SENT;
12270 }
12271 }
12272 }
12273
Kiran Kumar Lokeredd086642020-06-04 00:29:26 -070012274 val = get_param(cmd, "Ch_Pref");
12275 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12276 return STATUS_SENT;
12277
12278 val = get_param(cmd, "Cellular_Data_Cap");
12279 if (val && mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12280 return STATUS_SENT;
12281
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012282 return 1;
12283
12284failed:
12285 free(token);
12286 return -2;
12287}
12288
12289
12290static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
12291 struct sigma_conn *conn,
12292 struct sigma_cmd *cmd)
12293{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012294 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012295 case DRIVER_WCN:
12296 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
12297 default:
12298 send_resp(dut, conn, SIGMA_ERROR,
12299 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
12300 return 0;
12301 }
12302}
12303
12304
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012305static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
12306 struct sigma_conn *conn,
12307 struct sigma_cmd *cmd)
12308{
12309 const char *val;
12310
12311 val = get_param(cmd, "powersave");
12312 if (val) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012313 int ps;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012314
12315 if (strcasecmp(val, "off") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012316 ps = 2;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012317 } else if (strcasecmp(val, "on") == 0) {
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012318 ps = 1;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012319 } else {
12320 sigma_dut_print(dut, DUT_MSG_ERROR,
12321 "Unsupported power save config");
12322 return -1;
12323 }
Vinita S. Malooa8b62722020-04-23 01:45:41 +053012324 if (set_power_save_wcn(dut, intf, ps) < 0)
12325 return 0;
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012326 return 1;
12327 }
12328
12329 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
12330
12331 return 0;
12332}
12333
12334
Ashwini Patil5acd7382017-04-13 15:55:04 +053012335static int btm_query_candidate_list(struct sigma_dut *dut,
12336 struct sigma_conn *conn,
12337 struct sigma_cmd *cmd)
12338{
12339 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
12340 int len, ret;
12341 char buf[10];
12342
12343 /*
12344 * Neighbor Report elements format:
12345 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
12346 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
12347 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
12348 */
12349
12350 bssid = get_param(cmd, "Nebor_BSSID");
12351 if (!bssid) {
12352 send_resp(dut, conn, SIGMA_INVALID,
12353 "errorCode,Nebor_BSSID is missing");
12354 return 0;
12355 }
12356
12357 info = get_param(cmd, "Nebor_Bssid_Info");
12358 if (!info) {
12359 sigma_dut_print(dut, DUT_MSG_INFO,
12360 "Using default value for Nebor_Bssid_Info: %s",
12361 DEFAULT_NEIGHBOR_BSSID_INFO);
12362 info = DEFAULT_NEIGHBOR_BSSID_INFO;
12363 }
12364
12365 op_class = get_param(cmd, "Nebor_Op_Class");
12366 if (!op_class) {
12367 send_resp(dut, conn, SIGMA_INVALID,
12368 "errorCode,Nebor_Op_Class is missing");
12369 return 0;
12370 }
12371
12372 ch = get_param(cmd, "Nebor_Op_Ch");
12373 if (!ch) {
12374 send_resp(dut, conn, SIGMA_INVALID,
12375 "errorCode,Nebor_Op_Ch is missing");
12376 return 0;
12377 }
12378
12379 phy_type = get_param(cmd, "Nebor_Phy_Type");
12380 if (!phy_type) {
12381 sigma_dut_print(dut, DUT_MSG_INFO,
12382 "Using default value for Nebor_Phy_Type: %s",
12383 DEFAULT_NEIGHBOR_PHY_TYPE);
12384 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
12385 }
12386
12387 /* Parse optional subelements */
12388 buf[0] = '\0';
12389 pref = get_param(cmd, "Nebor_Pref");
12390 if (pref) {
12391 /* hexdump for preferrence subelement */
12392 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
12393 if (ret < 0 || ret >= (int) sizeof(buf)) {
12394 sigma_dut_print(dut, DUT_MSG_ERROR,
12395 "snprintf failed for optional subelement ret: %d",
12396 ret);
12397 send_resp(dut, conn, SIGMA_ERROR,
12398 "errorCode,snprintf failed for subelement");
12399 return 0;
12400 }
12401 }
12402
12403 if (!dut->btm_query_cand_list) {
12404 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
12405 if (!dut->btm_query_cand_list) {
12406 send_resp(dut, conn, SIGMA_ERROR,
12407 "errorCode,Failed to allocate memory for btm_query_cand_list");
12408 return 0;
12409 }
12410 }
12411
12412 len = strlen(dut->btm_query_cand_list);
12413 ret = snprintf(dut->btm_query_cand_list + len,
12414 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
12415 bssid, info, op_class, ch, phy_type, buf);
12416 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
12417 sigma_dut_print(dut, DUT_MSG_ERROR,
12418 "snprintf failed for neighbor report list ret: %d",
12419 ret);
12420 send_resp(dut, conn, SIGMA_ERROR,
12421 "errorCode,snprintf failed for neighbor report");
12422 free(dut->btm_query_cand_list);
12423 dut->btm_query_cand_list = NULL;
12424 return 0;
12425 }
12426
12427 return 1;
12428}
12429
12430
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012431int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
12432 struct sigma_ese_alloc *allocs, int *allocs_size)
12433{
12434 int max_count = *allocs_size;
12435 int count = 0, i;
12436 const char *val;
12437
12438 do {
12439 val = get_param_indexed(cmd, "AllocID", count);
12440 if (val)
12441 count++;
12442 } while (val);
12443
12444 if (count == 0 || count > max_count) {
12445 sigma_dut_print(dut, DUT_MSG_ERROR,
12446 "Invalid number of allocations(%d)", count);
12447 return -1;
12448 }
12449
12450 for (i = 0; i < count; i++) {
12451 val = get_param_indexed(cmd, "PercentBI", i);
12452 if (!val) {
12453 sigma_dut_print(dut, DUT_MSG_ERROR,
12454 "Missing PercentBI parameter at index %d",
12455 i);
12456 return -1;
12457 }
12458 allocs[i].percent_bi = atoi(val);
12459
12460 val = get_param_indexed(cmd, "SrcAID", i);
12461 if (val)
12462 allocs[i].src_aid = strtol(val, NULL, 0);
12463 else
12464 allocs[i].src_aid = ESE_BCAST_AID;
12465
12466 val = get_param_indexed(cmd, "DestAID", i);
12467 if (val)
12468 allocs[i].dst_aid = strtol(val, NULL, 0);
12469 else
12470 allocs[i].dst_aid = ESE_BCAST_AID;
12471
12472 allocs[i].type = ESE_CBAP;
12473 sigma_dut_print(dut, DUT_MSG_INFO,
12474 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
12475 i, allocs[i].percent_bi, allocs[i].src_aid,
12476 allocs[i].dst_aid);
12477 }
12478
12479 *allocs_size = count;
12480 return 0;
12481}
12482
12483
12484static int sta_set_60g_ese(struct sigma_dut *dut, int count,
12485 struct sigma_ese_alloc *allocs)
12486{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012487 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012488#ifdef __linux__
12489 case DRIVER_WIL6210:
12490 if (wil6210_set_ese(dut, count, allocs))
12491 return -1;
12492 return 1;
12493#endif /* __linux__ */
12494 default:
12495 sigma_dut_print(dut, DUT_MSG_ERROR,
12496 "Unsupported sta_set_60g_ese with the current driver");
12497 return -1;
12498 }
12499}
12500
12501
12502static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
12503 struct sigma_conn *conn,
12504 struct sigma_cmd *cmd)
12505{
12506 const char *val;
12507
12508 val = get_param(cmd, "ExtSchIE");
12509 if (val && !strcasecmp(val, "Enable")) {
12510 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
12511 int count = MAX_ESE_ALLOCS;
12512
12513 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
12514 return -1;
12515 return sta_set_60g_ese(dut, count, allocs);
12516 }
12517
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012518 val = get_param(cmd, "MCS_FixedRate");
12519 if (val) {
12520 int sta_mcs = atoi(val);
12521
12522 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12523 sta_mcs);
12524 wil6210_set_force_mcs(dut, 1, sta_mcs);
12525
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012526 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012527 }
12528
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012529 send_resp(dut, conn, SIGMA_ERROR,
12530 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012531 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012532}
12533
12534
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012535static int wcn_sta_override_oci(struct sigma_dut *dut, const char *intf,
12536 const char *oci_frametype, uint32_t oci_freq)
12537{
12538#ifdef NL80211_SUPPORT
12539 struct nl_msg *msg;
12540 int ret = 0;
12541 struct nlattr *params;
12542 struct nlattr *attr;
12543 int ifindex;
12544 u8 frame_type;
12545
12546 ifindex = if_nametoindex(intf);
12547 if (ifindex == 0) {
12548 sigma_dut_print(dut, DUT_MSG_ERROR,
12549 "%s: Index for interface %s failed",
12550 __func__, intf);
12551 return -1;
12552 }
12553
12554 if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12555 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_REQ;
12556 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12557 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_SA_QUERY_RESP;
12558 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12559 frame_type = QCA_WLAN_VENDOR_OCI_OVERRIDE_FRAME_FT_REASSOC_REQ;
12560 } else {
12561 sigma_dut_print(dut, DUT_MSG_ERROR, "%s: Unknown frametype %s",
12562 __func__, oci_frametype);
12563 return -1;
12564 }
12565
12566
12567 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
12568 NL80211_CMD_VENDOR)) ||
12569 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
12570 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
12571 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
12572 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
12573 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
12574 !(params = nla_nest_start(
12575 msg,
12576 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OCI_OVERRIDE)) ||
12577 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FRAME_TYPE,
12578 frame_type) ||
12579 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_OCI_OVERRIDE_FREQUENCY,
12580 oci_freq)) {
12581 sigma_dut_print(dut, DUT_MSG_ERROR,
12582 "%s: err in adding vendor_cmd and vendor_data",
12583 __func__);
12584 nlmsg_free(msg);
12585 return -1;
12586 }
12587 nla_nest_end(msg, params);
12588 nla_nest_end(msg, attr);
12589
12590 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
12591 if (ret) {
12592 sigma_dut_print(dut, DUT_MSG_ERROR,
12593 "%s: err in send_and_recv_msgs, ret=%d",
12594 __func__, ret);
12595 }
12596 return ret;
12597#else /* NL80211_SUPPORT */
12598 sigma_dut_print(dut, DUT_MSG_ERROR,
12599 "OCI override not possible without NL80211_SUPPORT defined");
12600 return -1;
12601#endif /* NL80211_SUPPORT */
12602}
12603
12604
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012605static int wcn_sta_ignore_csa(struct sigma_dut *dut, const char *intf,
12606 uint8_t ignore_csa)
12607{
12608#ifdef NL80211_SUPPORT
12609 return wcn_wifi_test_config_set_u8(
12610 dut, intf,
12611 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_CSA, ignore_csa);
12612#else /* NL80211_SUPPORT */
12613 sigma_dut_print(dut, DUT_MSG_ERROR,
12614 "IgnoreCSA can't be set without NL80211_SUPPORT defined");
12615 return -1;
12616#endif /* NL80211_SUPPORT */
12617}
12618
12619
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012620static int wcn_sta_set_rsnxe_used(struct sigma_dut *dut, const char *intf,
12621 uint8_t rsnxe_used)
12622{
12623#ifdef NL80211_SUPPORT
12624 return wcn_wifi_test_config_set_u8(
12625 dut, intf,
12626 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_FT_REASSOCREQ_RSNXE_USED,
12627 rsnxe_used);
12628#else /* NL80211_SUPPORT */
12629 sigma_dut_print(dut, DUT_MSG_ERROR,
12630 "RSNXE_Used can't be set without NL80211_SUPPORT defined");
12631 return -1;
12632#endif /* NL80211_SUPPORT */
12633}
12634
12635
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012636static int wcn_sta_ignore_sa_query_timeout(struct sigma_dut *dut,
12637 const char *intf,
12638 uint8_t ignore_sa_query_timeout)
12639{
12640#ifdef NL80211_SUPPORT
12641 return wcn_wifi_test_config_set_u8(
12642 dut, intf,
12643 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_IGNORE_SA_QUERY_TIMEOUT,
12644 ignore_sa_query_timeout);
12645#else /* NL80211_SUPPORT */
12646 sigma_dut_print(dut, DUT_MSG_ERROR,
12647 "Ignore SA Query timeout can't be set without NL80211_SUPPORT defined");
12648 return -1;
12649#endif /* NL80211_SUPPORT */
12650}
12651
12652
Jouni Malinen6250cb02020-04-15 13:54:45 +030012653static enum sigma_cmd_result
12654cmd_sta_set_rfeature_wpa3(const char *intf, struct sigma_dut *dut,
12655 struct sigma_conn *conn,
12656 struct sigma_cmd *cmd)
12657{
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012658 const char *val, *oci_chan, *oci_frametype;
Jouni Malinen6250cb02020-04-15 13:54:45 +030012659
Veerendranath Jakkam30bf9072020-04-16 14:37:57 +053012660 val = get_param(cmd, "ReassocReq_RSNXE_Used");
Jouni Malinen6250cb02020-04-15 13:54:45 +030012661 if (val && atoi(val) == 1) {
Veerendranath Jakkamc771fac2020-07-22 01:32:56 +053012662 if (wifi_chip_type == DRIVER_WCN) {
12663 if (wcn_sta_set_rsnxe_used(dut, intf, 1)) {
12664 send_resp(dut, conn, SIGMA_ERROR,
12665 "errorCode,Failed to set ft_rsnxe_used");
12666 return STATUS_SENT_ERROR;
12667 }
12668 return SUCCESS_SEND_STATUS;
12669 } else if (wpa_command(intf, "SET ft_rsnxe_used 1") < 0) {
Jouni Malinen6250cb02020-04-15 13:54:45 +030012670 send_resp(dut, conn, SIGMA_ERROR,
12671 "errorCode,Failed to set ft_rsnxe_used");
12672 return STATUS_SENT_ERROR;
12673 }
12674 return SUCCESS_SEND_STATUS;
12675 }
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012676
12677 oci_chan = get_param(cmd, "OCIChannel");
12678 oci_frametype = get_param(cmd, "OCIFrameType");
12679 if (oci_chan && oci_frametype) {
12680 unsigned int oci_freq = channel_to_freq(dut, atoi(oci_chan));
12681 char buf[100];
12682
12683 if (!oci_freq) {
12684 send_resp(dut, conn, SIGMA_ERROR,
12685 "errorCode,Invalid OCIChannel number");
12686 return STATUS_SENT_ERROR;
12687 }
12688
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012689 if (wifi_chip_type == DRIVER_WCN &&
12690 (strcasecmp(oci_frametype, "SAQueryReq") == 0 ||
12691 strcasecmp(oci_frametype, "SAQueryResp") == 0 ||
12692 strcasecmp(oci_frametype, "Reassocreq") == 0)) {
12693 if (wcn_sta_override_oci(dut, intf, oci_frametype,
12694 oci_freq)) {
12695 send_resp(dut, conn, SIGMA_ERROR,
12696 "errorCode,Failed to override OCI");
12697 return STATUS_SENT_ERROR;
12698 }
12699 return SUCCESS_SEND_STATUS;
12700 }
12701
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012702 if (strcasecmp(oci_frametype, "eapolM2") == 0) {
12703 snprintf(buf, sizeof(buf),
12704 "SET oci_freq_override_eapol %d", oci_freq);
12705 } else if (strcasecmp(oci_frametype, "SAQueryReq") == 0) {
12706 snprintf(buf, sizeof(buf),
12707 "SET oci_freq_override_saquery_req %d",
12708 oci_freq);
12709 } else if (strcasecmp(oci_frametype, "SAQueryResp") == 0) {
12710 snprintf(buf, sizeof(buf),
12711 "SET oci_freq_override_saquery_resp %d",
12712 oci_freq);
Veerendranath Jakkam76a845c2020-07-14 13:19:40 +053012713 } else if (strcasecmp(oci_frametype, "GrpKeyM2") == 0) {
12714 snprintf(buf, sizeof(buf),
12715 "SET oci_freq_override_eapol_g2 %d",
12716 oci_freq);
12717 } else if (strcasecmp(oci_frametype, "Reassocreq") == 0) {
12718 snprintf(buf, sizeof(buf),
12719 "SET oci_freq_override_ft_assoc %d",
12720 oci_freq);
Vamsi Krishnad29bc762020-05-08 23:23:30 +053012721 } else {
12722 send_resp(dut, conn, SIGMA_ERROR,
12723 "errorCode,Unsupported OCIFrameType");
12724 return STATUS_SENT_ERROR;
12725 }
12726 if (wpa_command(intf, buf) < 0) {
12727 send_resp(dut, conn, SIGMA_ERROR,
12728 "errorCode,Failed to set oci_freq_override");
12729 return STATUS_SENT_ERROR;
12730 }
12731 return SUCCESS_SEND_STATUS;
12732 }
12733
Veerendranath Jakkam50d5c782020-07-22 01:59:01 +053012734 val = get_param(cmd, "IgnoreCSA");
12735 if (val && atoi(val) == 1) {
12736 if (wifi_chip_type == DRIVER_WCN) {
12737 if (wcn_sta_ignore_csa(dut, intf, 1)) {
12738 send_resp(dut, conn, SIGMA_ERROR,
12739 "errorCode,Failed to set ignore CSA");
12740 return STATUS_SENT_ERROR;
12741 }
12742 return SUCCESS_SEND_STATUS;
12743 }
12744 }
12745
Veerendranath Jakkam1e1e5fd2020-09-10 07:12:37 +053012746 val = get_param(cmd, "Deauth_Per_SAQueryResp");
12747 if (val && atoi(val) == 0) {
12748 if (wifi_chip_type == DRIVER_WCN) {
12749 if (wcn_sta_ignore_sa_query_timeout(dut, intf, 1)) {
12750 send_resp(dut, conn, SIGMA_ERROR,
12751 "errorCode,Failed to set ignore SA Query timeout");
12752 return STATUS_SENT_ERROR;
12753 }
12754 return SUCCESS_SEND_STATUS;
12755 }
12756 }
12757
Jouni Malinen6250cb02020-04-15 13:54:45 +030012758 send_resp(dut, conn, SIGMA_ERROR,
12759 "errorCode,Unsupported WPA3 rfeature");
12760 return STATUS_SENT_ERROR;
12761}
12762
12763
Jouni Malinenf7222712019-06-13 01:50:21 +030012764static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12765 struct sigma_conn *conn,
12766 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012767{
12768 const char *intf = get_param(cmd, "Interface");
12769 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012770 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012771
12772 if (intf == NULL || prog == NULL)
12773 return -1;
12774
Ashwini Patil5acd7382017-04-13 15:55:04 +053012775 /* BSS Transition candidate list for BTM query */
12776 val = get_param(cmd, "Nebor_BSSID");
12777 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12778 return 0;
12779
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012780 if (strcasecmp(prog, "TDLS") == 0)
12781 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12782
12783 if (strcasecmp(prog, "VHT") == 0)
12784 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12785
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012786 if (strcasecmp(prog, "HE") == 0)
12787 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12788
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012789 if (strcasecmp(prog, "MBO") == 0) {
12790 val = get_param(cmd, "Cellular_Data_Cap");
12791 if (val &&
12792 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12793 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012794
12795 val = get_param(cmd, "Ch_Pref");
12796 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12797 return 0;
12798
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012799 return 1;
12800 }
12801
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012802 if (strcasecmp(prog, "60GHz") == 0)
12803 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12804
Jouni Malinen6250cb02020-04-15 13:54:45 +030012805 if (strcasecmp(prog, "WPA3") == 0)
12806 return cmd_sta_set_rfeature_wpa3(intf, dut, conn, cmd);
12807
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012808 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12809 return 0;
12810}
12811
12812
Jouni Malinenf7222712019-06-13 01:50:21 +030012813static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12814 struct sigma_conn *conn,
12815 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012816{
12817 const char *intf = get_param(cmd, "Interface");
12818 const char *mode = get_param(cmd, "Mode");
12819 int res;
12820
12821 if (intf == NULL || mode == NULL)
12822 return -1;
12823
12824 if (strcasecmp(mode, "On") == 0)
12825 res = wpa_command(intf, "SET radio_disabled 0");
12826 else if (strcasecmp(mode, "Off") == 0)
12827 res = wpa_command(intf, "SET radio_disabled 1");
12828 else
12829 return -1;
12830
12831 if (res) {
12832 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12833 "radio mode");
12834 return 0;
12835 }
12836
12837 return 1;
12838}
12839
12840
Jouni Malinenf7222712019-06-13 01:50:21 +030012841static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12842 struct sigma_conn *conn,
12843 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012844{
12845 const char *intf = get_param(cmd, "Interface");
12846 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012847 const char *prog = get_param(cmd, "program");
12848 const char *powersave = get_param(cmd, "powersave");
12849 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012850
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012851 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012852 return -1;
12853
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012854 if (prog && strcasecmp(prog, "60GHz") == 0) {
12855 /*
12856 * The CAPI mode parameter does not exist in 60G
12857 * unscheduled PS.
12858 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012859 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012860 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012861 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012862 strcasecmp(prog, "HE") == 0) {
12863 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012864 } else {
12865 if (mode == NULL)
12866 return -1;
12867
12868 if (strcasecmp(mode, "On") == 0)
12869 res = set_ps(intf, dut, 1);
12870 else if (strcasecmp(mode, "Off") == 0)
12871 res = set_ps(intf, dut, 0);
12872 else
12873 return -1;
12874 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012875
12876 if (res) {
12877 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12878 "power save mode");
12879 return 0;
12880 }
12881
12882 return 1;
12883}
12884
12885
Jouni Malinenf7222712019-06-13 01:50:21 +030012886static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12887 struct sigma_conn *conn,
12888 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012889{
12890 const char *intf = get_param(cmd, "Interface");
12891 const char *val, *bssid;
12892 int res;
12893 char *buf;
12894 size_t buf_len;
12895
12896 val = get_param(cmd, "BSSID_FILTER");
12897 if (val == NULL)
12898 return -1;
12899
12900 bssid = get_param(cmd, "BSSID_List");
12901 if (atoi(val) == 0 || bssid == NULL) {
12902 /* Disable BSSID filter */
12903 if (wpa_command(intf, "SET bssid_filter ")) {
12904 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12905 "to disable BSSID filter");
12906 return 0;
12907 }
12908
12909 return 1;
12910 }
12911
12912 buf_len = 100 + strlen(bssid);
12913 buf = malloc(buf_len);
12914 if (buf == NULL)
12915 return -1;
12916
12917 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12918 res = wpa_command(intf, buf);
12919 free(buf);
12920 if (res) {
12921 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12922 "BSSID filter");
12923 return 0;
12924 }
12925
12926 return 1;
12927}
12928
12929
Jouni Malinenf7222712019-06-13 01:50:21 +030012930static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12931 struct sigma_conn *conn,
12932 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012933{
12934 const char *intf = get_param(cmd, "Interface");
12935 const char *val;
12936
12937 /* TODO: ARP */
12938
12939 val = get_param(cmd, "HS2_CACHE_PROFILE");
12940 if (val && strcasecmp(val, "All") == 0)
12941 hs2_clear_credentials(intf);
12942
12943 return 1;
12944}
12945
12946
Jouni Malinenf7222712019-06-13 01:50:21 +030012947static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12948 struct sigma_conn *conn,
12949 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012950{
12951 const char *intf = get_param(cmd, "Interface");
12952 const char *key_type = get_param(cmd, "KeyType");
12953 char buf[100], resp[200];
12954
12955 if (key_type == NULL)
12956 return -1;
12957
12958 if (strcasecmp(key_type, "GTK") == 0) {
12959 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12960 strncmp(buf, "FAIL", 4) == 0) {
12961 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12962 "not fetch current GTK");
12963 return 0;
12964 }
12965 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12966 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12967 return 0;
12968 } else {
12969 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12970 "KeyType");
12971 return 0;
12972 }
12973
12974 return 1;
12975}
12976
12977
12978static int hs2_set_policy(struct sigma_dut *dut)
12979{
12980#ifdef ANDROID
12981 system("ip rule del prio 23000");
12982 if (system("ip rule add from all lookup main prio 23000") != 0) {
12983 sigma_dut_print(dut, DUT_MSG_ERROR,
12984 "Failed to run:ip rule add from all lookup main prio");
12985 return -1;
12986 }
12987 if (system("ip route flush cache") != 0) {
12988 sigma_dut_print(dut, DUT_MSG_ERROR,
12989 "Failed to run ip route flush cache");
12990 return -1;
12991 }
12992 return 1;
12993#else /* ANDROID */
12994 return 0;
12995#endif /* ANDROID */
12996}
12997
12998
Jouni Malinenf7222712019-06-13 01:50:21 +030012999static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
13000 struct sigma_conn *conn,
13001 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013002{
13003 const char *intf = get_param(cmd, "Interface");
13004 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030013005 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013006 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030013007 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013008 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
13009 int tries = 0;
13010 int ignore_blacklist = 0;
13011 const char *events[] = {
13012 "CTRL-EVENT-CONNECTED",
13013 "INTERWORKING-BLACKLISTED",
13014 "INTERWORKING-NO-MATCH",
13015 NULL
13016 };
13017
13018 start_sta_mode(dut);
13019
Jouni Malinen439352d2018-09-13 03:42:23 +030013020 if (band) {
13021 if (strcmp(band, "2.4") == 0) {
13022 wpa_command(intf, "SET setband 2G");
13023 } else if (strcmp(band, "5") == 0) {
13024 wpa_command(intf, "SET setband 5G");
13025 } else {
13026 send_resp(dut, conn, SIGMA_ERROR,
13027 "errorCode,Unsupported band");
13028 return 0;
13029 }
13030 }
13031
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013032 blacklisted[0] = '\0';
13033 if (val && atoi(val))
13034 ignore_blacklist = 1;
13035
13036try_again:
13037 ctrl = open_wpa_mon(intf);
13038 if (ctrl == NULL) {
13039 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13040 "wpa_supplicant monitor connection");
13041 return -2;
13042 }
13043
13044 tries++;
13045 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
13046 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
13047 "Interworking connection");
13048 wpa_ctrl_detach(ctrl);
13049 wpa_ctrl_close(ctrl);
13050 return 0;
13051 }
13052
13053 buf[0] = '\0';
13054 while (1) {
13055 char *pos;
13056 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13057 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
13058 if (!pos)
13059 break;
13060 pos += 25;
13061 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
13062 pos);
13063 if (!blacklisted[0])
13064 memcpy(blacklisted, pos, strlen(pos) + 1);
13065 }
13066
13067 if (ignore_blacklist && blacklisted[0]) {
13068 char *end;
13069 end = strchr(blacklisted, ' ');
13070 if (end)
13071 *end = '\0';
13072 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
13073 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030013074 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
13075 blacklisted);
13076 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013077 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
13078 wpa_ctrl_detach(ctrl);
13079 wpa_ctrl_close(ctrl);
13080 return 0;
13081 }
13082 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13083 buf, sizeof(buf));
13084 }
13085
13086 wpa_ctrl_detach(ctrl);
13087 wpa_ctrl_close(ctrl);
13088
13089 if (res < 0) {
13090 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13091 "connect");
13092 return 0;
13093 }
13094
13095 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
13096 strstr(buf, "INTERWORKING-BLACKLISTED")) {
13097 if (tries < 2) {
13098 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
13099 goto try_again;
13100 }
13101 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
13102 "matching credentials found");
13103 return 0;
13104 }
13105
13106 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13107 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13108 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
13109 "get current BSSID/SSID");
13110 return 0;
13111 }
13112
13113 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
13114 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13115 hs2_set_policy(dut);
13116 return 0;
13117}
13118
13119
Jouni Malinenf7222712019-06-13 01:50:21 +030013120static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
13121 struct sigma_conn *conn,
13122 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013123{
13124 const char *intf = get_param(cmd, "Interface");
13125 const char *display = get_param(cmd, "Display");
13126 struct wpa_ctrl *ctrl;
13127 char buf[300], params[400], *pos;
13128 char bssid[20];
13129 int info_avail = 0;
13130 unsigned int old_timeout;
13131 int res;
13132
13133 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
13134 send_resp(dut, conn, SIGMA_ERROR,
13135 "ErrorCode,Could not get current BSSID");
13136 return 0;
13137 }
13138 ctrl = open_wpa_mon(intf);
13139 if (!ctrl) {
13140 sigma_dut_print(dut, DUT_MSG_ERROR,
13141 "Failed to open wpa_supplicant monitor connection");
13142 return -2;
13143 }
13144
13145 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
13146 wpa_command(intf, buf);
13147
13148 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
13149 if (res < 0) {
13150 send_resp(dut, conn, SIGMA_ERROR,
13151 "ErrorCode,Could not complete GAS query");
13152 goto fail;
13153 }
13154
13155 old_timeout = dut->default_timeout;
13156 dut->default_timeout = 2;
13157 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
13158 dut->default_timeout = old_timeout;
13159 if (res < 0)
13160 goto done;
13161 pos = strchr(buf, ' ');
13162 if (!pos)
13163 goto done;
13164 pos++;
13165 pos = strchr(pos, ' ');
13166 if (!pos)
13167 goto done;
13168 pos++;
13169 info_avail = 1;
13170 snprintf(params, sizeof(params), "browser %s", pos);
13171
13172 if (display && strcasecmp(display, "Yes") == 0) {
13173 pid_t pid;
13174
13175 pid = fork();
13176 if (pid < 0) {
13177 perror("fork");
13178 return -1;
13179 }
13180
13181 if (pid == 0) {
13182 run_hs20_osu(dut, params);
13183 exit(0);
13184 }
13185 }
13186
13187done:
13188 snprintf(buf, sizeof(buf), "Info_available,%s",
13189 info_avail ? "Yes" : "No");
13190 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13191fail:
13192 wpa_ctrl_detach(ctrl);
13193 wpa_ctrl_close(ctrl);
13194 return 0;
13195}
13196
13197
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013198static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
13199 struct sigma_conn *conn,
13200 const char *ifname,
13201 struct sigma_cmd *cmd)
13202{
13203 const char *val;
13204 int id;
13205
13206 id = add_cred(ifname);
13207 if (id < 0)
13208 return -2;
13209 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13210
13211 val = get_param(cmd, "prefer");
13212 if (val && atoi(val) > 0)
13213 set_cred(ifname, id, "priority", "1");
13214
13215 val = get_param(cmd, "REALM");
13216 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13217 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13218 "realm");
13219 return 0;
13220 }
13221
13222 val = get_param(cmd, "HOME_FQDN");
13223 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13224 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13225 "home_fqdn");
13226 return 0;
13227 }
13228
13229 val = get_param(cmd, "Username");
13230 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13231 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13232 "username");
13233 return 0;
13234 }
13235
13236 val = get_param(cmd, "Password");
13237 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
13238 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13239 "password");
13240 return 0;
13241 }
13242
13243 val = get_param(cmd, "ROOT_CA");
13244 if (val) {
13245 char fname[200];
13246 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13247#ifdef __linux__
13248 if (!file_exists(fname)) {
13249 char msg[300];
13250 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13251 "file (%s) not found", fname);
13252 send_resp(dut, conn, SIGMA_ERROR, msg);
13253 return 0;
13254 }
13255#endif /* __linux__ */
13256 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13257 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13258 "not set root CA");
13259 return 0;
13260 }
13261 }
13262
13263 return 1;
13264}
13265
13266
13267static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
13268{
13269 FILE *in, *out;
13270 char buf[500];
13271 int found = 0;
13272
13273 in = fopen("devdetail.xml", "r");
13274 if (in == NULL)
13275 return -1;
13276 out = fopen("devdetail.xml.tmp", "w");
13277 if (out == NULL) {
13278 fclose(in);
13279 return -1;
13280 }
13281
13282 while (fgets(buf, sizeof(buf), in)) {
13283 char *pos = strstr(buf, "<IMSI>");
13284 if (pos) {
13285 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
13286 imsi);
13287 pos += 6;
13288 *pos = '\0';
13289 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
13290 found++;
13291 } else {
13292 fprintf(out, "%s", buf);
13293 }
13294 }
13295
13296 fclose(out);
13297 fclose(in);
13298 if (found)
13299 rename("devdetail.xml.tmp", "devdetail.xml");
13300 else
13301 unlink("devdetail.xml.tmp");
13302
13303 return 0;
13304}
13305
13306
13307static int sta_add_credential_sim(struct sigma_dut *dut,
13308 struct sigma_conn *conn,
13309 const char *ifname, struct sigma_cmd *cmd)
13310{
13311 const char *val, *imsi = NULL;
13312 int id;
13313 char buf[200];
13314 int res;
13315 const char *pos;
13316 size_t mnc_len;
13317 char plmn_mcc[4];
13318 char plmn_mnc[4];
13319
13320 id = add_cred(ifname);
13321 if (id < 0)
13322 return -2;
13323 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13324
13325 val = get_param(cmd, "prefer");
13326 if (val && atoi(val) > 0)
13327 set_cred(ifname, id, "priority", "1");
13328
13329 val = get_param(cmd, "PLMN_MCC");
13330 if (val == NULL) {
13331 send_resp(dut, conn, SIGMA_ERROR,
13332 "errorCode,Missing PLMN_MCC");
13333 return 0;
13334 }
13335 if (strlen(val) != 3) {
13336 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
13337 return 0;
13338 }
13339 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
13340
13341 val = get_param(cmd, "PLMN_MNC");
13342 if (val == NULL) {
13343 send_resp(dut, conn, SIGMA_ERROR,
13344 "errorCode,Missing PLMN_MNC");
13345 return 0;
13346 }
13347 if (strlen(val) != 2 && strlen(val) != 3) {
13348 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
13349 return 0;
13350 }
13351 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
13352
13353 val = get_param(cmd, "IMSI");
13354 if (val == NULL) {
13355 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
13356 "IMSI");
13357 return 0;
13358 }
13359
13360 imsi = pos = val;
13361
13362 if (strncmp(plmn_mcc, pos, 3) != 0) {
13363 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
13364 return 0;
13365 }
13366 pos += 3;
13367
13368 mnc_len = strlen(plmn_mnc);
13369 if (mnc_len < 2) {
13370 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
13371 return 0;
13372 }
13373
13374 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
13375 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
13376 return 0;
13377 }
13378 pos += mnc_len;
13379
13380 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
13381 if (res < 0 || res >= (int) sizeof(buf))
13382 return -1;
13383 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
13384 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13385 "not set IMSI");
13386 return 0;
13387 }
13388
13389 val = get_param(cmd, "Password");
13390 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
13391 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13392 "not set password");
13393 return 0;
13394 }
13395
Jouni Malinenba630452018-06-22 11:49:59 +030013396 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013397 /*
13398 * Set provisioning_sp for the test cases where SIM/USIM
13399 * provisioning is used.
13400 */
13401 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
13402 "wi-fi.org") < 0) {
13403 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13404 "not set provisioning_sp");
13405 return 0;
13406 }
13407
13408 update_devdetail_imsi(dut, imsi);
13409 }
13410
13411 return 1;
13412}
13413
13414
13415static int sta_add_credential_cert(struct sigma_dut *dut,
13416 struct sigma_conn *conn,
13417 const char *ifname,
13418 struct sigma_cmd *cmd)
13419{
13420 const char *val;
13421 int id;
13422
13423 id = add_cred(ifname);
13424 if (id < 0)
13425 return -2;
13426 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
13427
13428 val = get_param(cmd, "prefer");
13429 if (val && atoi(val) > 0)
13430 set_cred(ifname, id, "priority", "1");
13431
13432 val = get_param(cmd, "REALM");
13433 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
13434 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13435 "realm");
13436 return 0;
13437 }
13438
13439 val = get_param(cmd, "HOME_FQDN");
13440 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
13441 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13442 "home_fqdn");
13443 return 0;
13444 }
13445
13446 val = get_param(cmd, "Username");
13447 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
13448 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
13449 "username");
13450 return 0;
13451 }
13452
13453 val = get_param(cmd, "clientCertificate");
13454 if (val) {
13455 char fname[200];
13456 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13457#ifdef __linux__
13458 if (!file_exists(fname)) {
13459 char msg[300];
13460 snprintf(msg, sizeof(msg),
13461 "ErrorCode,clientCertificate "
13462 "file (%s) not found", fname);
13463 send_resp(dut, conn, SIGMA_ERROR, msg);
13464 return 0;
13465 }
13466#endif /* __linux__ */
13467 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
13468 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13469 "not set client_cert");
13470 return 0;
13471 }
13472 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
13473 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13474 "not set private_key");
13475 return 0;
13476 }
13477 }
13478
13479 val = get_param(cmd, "ROOT_CA");
13480 if (val) {
13481 char fname[200];
13482 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
13483#ifdef __linux__
13484 if (!file_exists(fname)) {
13485 char msg[300];
13486 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
13487 "file (%s) not found", fname);
13488 send_resp(dut, conn, SIGMA_ERROR, msg);
13489 return 0;
13490 }
13491#endif /* __linux__ */
13492 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
13493 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
13494 "not set root CA");
13495 return 0;
13496 }
13497 }
13498
13499 return 1;
13500}
13501
13502
Jouni Malinenf7222712019-06-13 01:50:21 +030013503static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
13504 struct sigma_conn *conn,
13505 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013506{
13507 const char *intf = get_param(cmd, "Interface");
13508 const char *type;
13509
13510 start_sta_mode(dut);
13511
13512 type = get_param(cmd, "Type");
13513 if (!type)
13514 return -1;
13515
13516 if (strcasecmp(type, "uname_pwd") == 0)
13517 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
13518
13519 if (strcasecmp(type, "sim") == 0)
13520 return sta_add_credential_sim(dut, conn, intf, cmd);
13521
13522 if (strcasecmp(type, "cert") == 0)
13523 return sta_add_credential_cert(dut, conn, intf, cmd);
13524
13525 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
13526 "type");
13527 return 0;
13528}
13529
13530
Jouni Malinenf7222712019-06-13 01:50:21 +030013531static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
13532 struct sigma_conn *conn,
13533 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013534{
13535 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013536 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Veerendranathdc581b52020-08-10 03:29:08 -070013537 char buf[4096], scan_res[20];
vamsi krishna89ad8c62017-09-19 12:51:18 +053013538 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013539 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013540 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013541 enum sigma_cmd_result status;
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013542 struct wpa_ctrl *ctrl = NULL;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013543
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020013544 start_sta_mode(dut);
13545
Arif Hussain66a4af02019-02-07 15:04:51 -080013546 val = get_param(cmd, "GetParameter");
13547 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013548 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080013549 buf, sizeof(buf)) < 0) {
13550 sigma_dut_print(dut, DUT_MSG_ERROR,
13551 "Could not get ssid bssid");
13552 return ERROR_SEND_STATUS;
13553 }
13554
13555 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
13556 send_resp(dut, conn, SIGMA_COMPLETE, buf);
13557 return STATUS_SENT;
13558 }
13559
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013560 val = get_param(cmd, "HESSID");
13561 if (val) {
13562 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
13563 if (res < 0 || res >= (int) sizeof(buf))
13564 return -1;
13565 wpa_command(intf, buf);
13566 }
13567
13568 val = get_param(cmd, "ACCS_NET_TYPE");
13569 if (val) {
13570 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
13571 val);
13572 if (res < 0 || res >= (int) sizeof(buf))
13573 return -1;
13574 wpa_command(intf, buf);
13575 }
13576
vamsi krishna89ad8c62017-09-19 12:51:18 +053013577 bssid = get_param(cmd, "Bssid");
13578 ssid = get_param(cmd, "Ssid");
13579
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013580 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
13581 dut->device_type == STA_testbed) {
13582 ssid = NULL;
13583 wildcard_ssid = 1;
13584 }
13585
vamsi krishna89ad8c62017-09-19 12:51:18 +053013586 if (ssid) {
13587 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
13588 send_resp(dut, conn, SIGMA_ERROR,
13589 "ErrorCode,Too long SSID");
13590 return 0;
13591 }
13592 ascii2hexstr(ssid, ssid_hex);
13593 }
13594
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013595 short_ssid = get_param(cmd, "ShortSSID");
13596 if (short_ssid) {
13597 uint32_t short_ssid_hex;
13598
13599 short_ssid_hex = strtoul(short_ssid, NULL, 16);
13600 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
13601 (((short_ssid_hex >> 8) & 0xFF) << 16) |
13602 (((short_ssid_hex >> 16) & 0xFF) << 8) |
13603 ((short_ssid_hex >> 24) & 0xFF);
13604
13605 res = snprintf(buf, sizeof(buf),
13606 "VENDOR_ELEM_ADD 14 ff053a%08x",
13607 short_ssid_hex);
13608 if (res < 0 || res >= (int) sizeof(buf) ||
13609 wpa_command(intf, buf)) {
13610 send_resp(dut, conn, SIGMA_ERROR,
13611 "errorCode,Failed to add short SSID");
13612 return STATUS_SENT_ERROR;
13613 }
13614 }
13615
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013616 scan_freq = get_param(cmd, "ChnlFreq");
Veerendranath Jakkam132c4b42020-08-10 00:29:03 +053013617 if (scan_freq) {
13618 if (strcasecmp(scan_freq, "2G") == 0)
13619 scan_freq = "2412-2462";
13620 else if (strcasecmp(scan_freq, "5G") == 0)
13621 scan_freq = "5180-5925";
13622 }
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013623
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013624 val = get_param(cmd, "WaitCompletion");
13625 if (val && atoi(val) == 1) {
13626 ctrl = open_wpa_mon(intf);
13627 if (!ctrl) {
13628 send_resp(dut, conn, SIGMA_ERROR,
13629 "errorCode,Failed to open monitor socket");
13630 return STATUS_SENT_ERROR;
13631 }
13632 }
13633
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013634 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053013635 bssid ? " bssid=": "",
13636 bssid ? bssid : "",
13637 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080013638 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080013639 wildcard_ssid ? " wildcard_ssid=1" : "",
13640 scan_freq ? " freq=" : "",
13641 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013642 if (res < 0 || res >= (int) sizeof(buf)) {
13643 send_resp(dut, conn, SIGMA_ERROR,
13644 "errorCode,Could not build scan command");
13645 status = STATUS_SENT_ERROR;
13646 goto remove_s_ssid;
13647 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053013648
Veerendranathdc581b52020-08-10 03:29:08 -070013649 res = wpa_command_resp(intf, buf, scan_res, sizeof(scan_res));
13650 if (strncmp(scan_res, "FAIL-BUSY", 9) == 0) {
13651 sigma_dut_print(dut, DUT_MSG_DEBUG,
13652 "Scan request rejected with busy status, abort ongoing scan and try again");
13653 wpa_command(intf, "ABORT_SCAN");
13654 res = wpa_command(intf, buf);
13655 }
13656
13657 if (res < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013658 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
13659 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013660 status = STATUS_SENT_ERROR;
13661 } else {
13662 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013663 }
13664
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013665remove_s_ssid:
13666 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
13667 sigma_dut_print(dut, DUT_MSG_ERROR,
13668 "Failed to delete vendor element");
13669
Jouni Malinen228a2fc2020-06-22 23:37:45 +030013670 if (ctrl) {
13671 if (status == SUCCESS_SEND_STATUS) {
13672 res = get_wpa_cli_event(dut, ctrl,
13673 "CTRL-EVENT-SCAN-RESULTS",
13674 buf, sizeof(buf));
13675 if (res < 0) {
13676 send_resp(dut, conn, SIGMA_ERROR,
13677 "ErrorCode,scan did not complete");
13678 status = STATUS_SENT_ERROR;
13679 }
13680 }
13681
13682 wpa_ctrl_detach(ctrl);
13683 wpa_ctrl_close(ctrl);
13684 }
13685
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080013686 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013687}
13688
13689
Jouni Malinenf7222712019-06-13 01:50:21 +030013690static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
13691 struct sigma_conn *conn,
13692 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013693{
13694 const char *intf = get_param(cmd, "Interface");
13695 const char *bssid;
13696 char buf[4096], *pos;
13697 int freq, chan;
13698 char *ssid;
13699 char resp[100];
13700 int res;
13701 struct wpa_ctrl *ctrl;
13702
13703 bssid = get_param(cmd, "BSSID");
13704 if (!bssid) {
13705 send_resp(dut, conn, SIGMA_INVALID,
13706 "errorCode,BSSID argument is missing");
13707 return 0;
13708 }
13709
13710 ctrl = open_wpa_mon(intf);
13711 if (!ctrl) {
13712 sigma_dut_print(dut, DUT_MSG_ERROR,
13713 "Failed to open wpa_supplicant monitor connection");
13714 return -1;
13715 }
13716
13717 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
13718 send_resp(dut, conn, SIGMA_ERROR,
13719 "errorCode,Could not start scan");
13720 wpa_ctrl_detach(ctrl);
13721 wpa_ctrl_close(ctrl);
13722 return 0;
13723 }
13724
13725 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
13726 buf, sizeof(buf));
13727
13728 wpa_ctrl_detach(ctrl);
13729 wpa_ctrl_close(ctrl);
13730
13731 if (res < 0) {
13732 send_resp(dut, conn, SIGMA_ERROR,
13733 "errorCode,Scan did not complete");
13734 return 0;
13735 }
13736
13737 snprintf(buf, sizeof(buf), "BSS %s", bssid);
13738 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
13739 strncmp(buf, "id=", 3) != 0) {
13740 send_resp(dut, conn, SIGMA_ERROR,
13741 "errorCode,Specified BSSID not found");
13742 return 0;
13743 }
13744
13745 pos = strstr(buf, "\nfreq=");
13746 if (!pos) {
13747 send_resp(dut, conn, SIGMA_ERROR,
13748 "errorCode,Channel not found");
13749 return 0;
13750 }
13751 freq = atoi(pos + 6);
13752 chan = freq_to_channel(freq);
13753
13754 pos = strstr(buf, "\nssid=");
13755 if (!pos) {
13756 send_resp(dut, conn, SIGMA_ERROR,
13757 "errorCode,SSID not found");
13758 return 0;
13759 }
13760 ssid = pos + 6;
13761 pos = strchr(ssid, '\n');
13762 if (pos)
13763 *pos = '\0';
13764 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
13765 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13766 return 0;
13767}
13768
13769
Jouni Malinenf7222712019-06-13 01:50:21 +030013770static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
13771 struct sigma_conn *conn,
13772 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013773{
13774#ifdef __linux__
13775 struct timeval tv;
13776 struct tm tm;
13777 time_t t;
13778 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013779 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013780
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013781 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013782
13783 memset(&tm, 0, sizeof(tm));
13784 val = get_param(cmd, "seconds");
13785 if (val)
13786 tm.tm_sec = atoi(val);
13787 val = get_param(cmd, "minutes");
13788 if (val)
13789 tm.tm_min = atoi(val);
13790 val = get_param(cmd, "hours");
13791 if (val)
13792 tm.tm_hour = atoi(val);
13793 val = get_param(cmd, "date");
13794 if (val)
13795 tm.tm_mday = atoi(val);
13796 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013797 if (val) {
13798 v = atoi(val);
13799 if (v < 1 || v > 12) {
13800 send_resp(dut, conn, SIGMA_INVALID,
13801 "errorCode,Invalid month");
13802 return 0;
13803 }
13804 tm.tm_mon = v - 1;
13805 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013806 val = get_param(cmd, "year");
13807 if (val) {
13808 int year = atoi(val);
13809#ifdef ANDROID
13810 if (year > 2035)
13811 year = 2035; /* years beyond 2035 not supported */
13812#endif /* ANDROID */
13813 tm.tm_year = year - 1900;
13814 }
13815 t = mktime(&tm);
13816 if (t == (time_t) -1) {
13817 send_resp(dut, conn, SIGMA_ERROR,
13818 "errorCode,Invalid date or time");
13819 return 0;
13820 }
13821
13822 memset(&tv, 0, sizeof(tv));
13823 tv.tv_sec = t;
13824
13825 if (settimeofday(&tv, NULL) < 0) {
13826 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13827 strerror(errno));
13828 send_resp(dut, conn, SIGMA_ERROR,
13829 "errorCode,Failed to set time");
13830 return 0;
13831 }
13832
13833 return 1;
13834#endif /* __linux__ */
13835
13836 return -1;
13837}
13838
13839
Jouni Malinenf7222712019-06-13 01:50:21 +030013840static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13841 struct sigma_conn *conn,
13842 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013843{
13844 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013845 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013846 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013847 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013848 int res;
13849 struct wpa_ctrl *ctrl;
13850
13851 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013852 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013853
13854 val = get_param(cmd, "ProdESSAssoc");
13855 if (val)
13856 prod_ess_assoc = atoi(val);
13857
13858 kill_dhcp_client(dut, intf);
13859 if (start_dhcp_client(dut, intf) < 0)
13860 return -2;
13861
13862 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13863 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13864 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013865 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013866 prod_ess_assoc ? "" : "-N",
13867 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013868 name ? "'" : "",
13869 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13870 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013871
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013872 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013873 if (run_hs20_osu(dut, buf) < 0) {
13874 FILE *f;
13875
13876 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13877
13878 f = fopen("hs20-osu-client.res", "r");
13879 if (f) {
13880 char resp[400], res[300], *pos;
13881 if (!fgets(res, sizeof(res), f))
13882 res[0] = '\0';
13883 pos = strchr(res, '\n');
13884 if (pos)
13885 *pos = '\0';
13886 fclose(f);
13887 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13888 res);
13889 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13890 if (system(resp) != 0) {
13891 }
13892 snprintf(resp, sizeof(resp),
13893 "SSID,,BSSID,,failureReason,%s", res);
13894 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13895 return 0;
13896 }
13897
13898 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13899 return 0;
13900 }
13901
13902 if (!prod_ess_assoc)
13903 goto report;
13904
13905 ctrl = open_wpa_mon(intf);
13906 if (ctrl == NULL) {
13907 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13908 "wpa_supplicant monitor connection");
13909 return -1;
13910 }
13911
13912 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13913 buf, sizeof(buf));
13914
13915 wpa_ctrl_detach(ctrl);
13916 wpa_ctrl_close(ctrl);
13917
13918 if (res < 0) {
13919 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13920 "network after OSU");
13921 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13922 return 0;
13923 }
13924
13925report:
13926 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13927 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13928 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13929 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13930 return 0;
13931 }
13932
13933 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13934 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013935 return 0;
13936}
13937
13938
Jouni Malinenf7222712019-06-13 01:50:21 +030013939static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13940 struct sigma_conn *conn,
13941 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013942{
13943 const char *val;
13944 int timeout = 120;
13945
13946 val = get_param(cmd, "PolicyUpdate");
13947 if (val == NULL || atoi(val) == 0)
13948 return 1; /* No operation requested */
13949
13950 val = get_param(cmd, "Timeout");
13951 if (val)
13952 timeout = atoi(val);
13953
13954 if (timeout) {
13955 /* TODO: time out the command and return
13956 * PolicyUpdateStatus,TIMEOUT if needed. */
13957 }
13958
13959 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13960 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13961 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13962 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13963 return 0;
13964 }
13965
13966 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13967 return 0;
13968}
13969
13970
Jouni Malinenf7222712019-06-13 01:50:21 +030013971static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13972 struct sigma_conn *conn,
13973 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013974{
13975 struct wpa_ctrl *ctrl;
13976 const char *intf = get_param(cmd, "Interface");
13977 const char *bssid = get_param(cmd, "Bssid");
13978 const char *ssid = get_param(cmd, "SSID");
13979 const char *security = get_param(cmd, "Security");
13980 const char *passphrase = get_param(cmd, "Passphrase");
13981 const char *pin = get_param(cmd, "PIN");
13982 char buf[1000];
13983 char ssid_hex[200], passphrase_hex[200];
13984 const char *keymgmt, *cipher;
13985
13986 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013987 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013988
13989 if (!bssid) {
13990 send_resp(dut, conn, SIGMA_ERROR,
13991 "ErrorCode,Missing Bssid argument");
13992 return 0;
13993 }
13994
13995 if (!ssid) {
13996 send_resp(dut, conn, SIGMA_ERROR,
13997 "ErrorCode,Missing SSID argument");
13998 return 0;
13999 }
14000
14001 if (!security) {
14002 send_resp(dut, conn, SIGMA_ERROR,
14003 "ErrorCode,Missing Security argument");
14004 return 0;
14005 }
14006
14007 if (!passphrase) {
14008 send_resp(dut, conn, SIGMA_ERROR,
14009 "ErrorCode,Missing Passphrase argument");
14010 return 0;
14011 }
14012
14013 if (!pin) {
14014 send_resp(dut, conn, SIGMA_ERROR,
14015 "ErrorCode,Missing PIN argument");
14016 return 0;
14017 }
14018
vamsi krishna8c9c1562017-05-12 15:51:46 +053014019 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
14020 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014021 send_resp(dut, conn, SIGMA_ERROR,
14022 "ErrorCode,Too long SSID/passphrase");
14023 return 0;
14024 }
14025
14026 ctrl = open_wpa_mon(intf);
14027 if (ctrl == NULL) {
14028 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14029 "wpa_supplicant monitor connection");
14030 return -2;
14031 }
14032
14033 if (strcasecmp(security, "wpa2-psk") == 0) {
14034 keymgmt = "WPA2PSK";
14035 cipher = "CCMP";
14036 } else {
14037 wpa_ctrl_detach(ctrl);
14038 wpa_ctrl_close(ctrl);
14039 send_resp(dut, conn, SIGMA_ERROR,
14040 "ErrorCode,Unsupported Security value");
14041 return 0;
14042 }
14043
14044 ascii2hexstr(ssid, ssid_hex);
14045 ascii2hexstr(passphrase, passphrase_hex);
14046 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
14047 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
14048
14049 if (wpa_command(intf, buf) < 0) {
14050 wpa_ctrl_detach(ctrl);
14051 wpa_ctrl_close(ctrl);
14052 send_resp(dut, conn, SIGMA_ERROR,
14053 "ErrorCode,Failed to start registrar");
14054 return 0;
14055 }
14056
14057 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
14058 dut->er_oper_performed = 1;
14059
14060 return wps_connection_event(dut, conn, ctrl, intf, 0);
14061}
14062
14063
Jouni Malinenf7222712019-06-13 01:50:21 +030014064static enum sigma_cmd_result
14065cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
14066 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014067{
14068 struct wpa_ctrl *ctrl;
14069 const char *intf = get_param(cmd, "Interface");
14070 const char *bssid = get_param(cmd, "Bssid");
14071 char buf[100];
14072
14073 if (!bssid) {
14074 send_resp(dut, conn, SIGMA_ERROR,
14075 "ErrorCode,Missing Bssid argument");
14076 return 0;
14077 }
14078
14079 ctrl = open_wpa_mon(intf);
14080 if (ctrl == NULL) {
14081 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
14082 "wpa_supplicant monitor connection");
14083 return -2;
14084 }
14085
14086 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
14087
14088 if (wpa_command(intf, buf) < 0) {
14089 wpa_ctrl_detach(ctrl);
14090 wpa_ctrl_close(ctrl);
14091 send_resp(dut, conn, SIGMA_ERROR,
14092 "ErrorCode,Failed to start registrar");
14093 return 0;
14094 }
14095
14096 return wps_connection_event(dut, conn, ctrl, intf, 0);
14097}
14098
14099
Jouni Malinenf7222712019-06-13 01:50:21 +030014100static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
14101 struct sigma_conn *conn,
14102 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053014103{
14104 struct wpa_ctrl *ctrl;
14105 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014106 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014107 const char *config_method = get_param(cmd, "WPSConfigMethod");
14108 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053014109 int res;
14110 char buf[256];
14111 const char *events[] = {
14112 "CTRL-EVENT-CONNECTED",
14113 "WPS-OVERLAP-DETECTED",
14114 "WPS-TIMEOUT",
14115 "WPS-FAIL",
14116 NULL
14117 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014118 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053014119
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014120 /* 60G WPS tests do not pass Interface parameter */
14121 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014122 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014123
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014124 if (dut->mode == SIGMA_MODE_AP)
14125 return ap_wps_registration(dut, conn, cmd);
14126
14127 if (config_method) {
14128 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
14129 * sta_wps_enter_pin before calling start_wps_registration. */
14130 if (strcasecmp(config_method, "PBC") == 0)
14131 dut->wps_method = WFA_CS_WPS_PBC;
14132 }
14133 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
14134 send_resp(dut, conn, SIGMA_ERROR,
14135 "ErrorCode,WPS parameters not yet set");
14136 return STATUS_SENT;
14137 }
14138
14139 /* Make sure WPS is enabled (also for STA mode) */
14140 dut->wps_disable = 0;
14141
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014142 if (dut->band == WPS_BAND_60G && network_mode &&
14143 strcasecmp(network_mode, "PBSS") == 0) {
14144 sigma_dut_print(dut, DUT_MSG_DEBUG,
14145 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020014146 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020014147 return -2;
14148 }
14149
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014150 if (dut->force_rsn_ie) {
14151 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
14152 dut->force_rsn_ie);
14153 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
14154 sigma_dut_print(dut, DUT_MSG_INFO,
14155 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020014156 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020014157 }
14158 }
14159
vamsi krishna9b144002017-09-20 13:28:13 +053014160 ctrl = open_wpa_mon(intf);
14161 if (!ctrl) {
14162 sigma_dut_print(dut, DUT_MSG_ERROR,
14163 "Failed to open wpa_supplicant monitor connection");
14164 return -2;
14165 }
14166
14167 role = get_param(cmd, "WpsRole");
14168 if (!role) {
14169 send_resp(dut, conn, SIGMA_INVALID,
14170 "ErrorCode,WpsRole not provided");
14171 goto fail;
14172 }
14173
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014174 if (strcasecmp(role, "Enrollee") != 0) {
14175 /* Registrar role for STA not supported */
14176 send_resp(dut, conn, SIGMA_ERROR,
14177 "ErrorCode,Unsupported WpsRole value");
14178 goto fail;
14179 }
14180
14181 if (is_60g_sigma_dut(dut)) {
14182 if (dut->wps_method == WFA_CS_WPS_PBC)
14183 snprintf(buf, sizeof(buf), "WPS_PBC");
14184 else /* WFA_CS_WPS_PIN_KEYPAD */
14185 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
14186 dut->wps_pin);
14187 if (wpa_command(intf, buf) < 0) {
14188 send_resp(dut, conn, SIGMA_ERROR,
14189 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053014190 goto fail;
14191 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020014192 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14193 if (res < 0) {
14194 send_resp(dut, conn, SIGMA_ERROR,
14195 "ErrorCode,WPS connection did not complete");
14196 goto fail;
14197 }
14198 if (strstr(buf, "WPS-TIMEOUT")) {
14199 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
14200 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14201 send_resp(dut, conn, SIGMA_COMPLETE,
14202 "WpsState,OverlapSession");
14203 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14204 send_resp(dut, conn, SIGMA_COMPLETE,
14205 "WpsState,Successful");
14206 } else {
14207 send_resp(dut, conn, SIGMA_COMPLETE,
14208 "WpsState,Failure");
14209 }
14210 } else {
14211 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053014212 if (wpa_command(intf, "WPS_PBC") < 0) {
14213 send_resp(dut, conn, SIGMA_ERROR,
14214 "ErrorCode,Failed to enable PBC");
14215 goto fail;
14216 }
14217 } else {
14218 /* TODO: PIN method */
14219 send_resp(dut, conn, SIGMA_ERROR,
14220 "ErrorCode,Unsupported WpsConfigMethod value");
14221 goto fail;
14222 }
14223 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
14224 if (res < 0) {
14225 send_resp(dut, conn, SIGMA_ERROR,
14226 "ErrorCode,WPS connection did not complete");
14227 goto fail;
14228 }
14229 if (strstr(buf, "WPS-TIMEOUT")) {
14230 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
14231 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
14232 send_resp(dut, conn, SIGMA_ERROR,
14233 "ErrorCode,OverlapSession");
14234 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
14235 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
14236 } else {
14237 send_resp(dut, conn, SIGMA_ERROR,
14238 "ErrorCode,WPS operation failed");
14239 }
vamsi krishna9b144002017-09-20 13:28:13 +053014240 }
14241
14242fail:
14243 wpa_ctrl_detach(ctrl);
14244 wpa_ctrl_close(ctrl);
14245 return 0;
14246}
14247
14248
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014249static int req_intf(struct sigma_cmd *cmd)
14250{
14251 return get_param(cmd, "interface") == NULL ? -1 : 0;
14252}
14253
14254
14255void sta_register_cmds(void)
14256{
14257 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
14258 cmd_sta_get_ip_config);
14259 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
14260 cmd_sta_set_ip_config);
14261 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
14262 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
14263 cmd_sta_get_mac_address);
14264 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
14265 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
14266 cmd_sta_verify_ip_connection);
14267 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
14268 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
14269 cmd_sta_set_encryption);
14270 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
14271 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
14272 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
14273 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
14274 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
14275 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
14276 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
14277 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
14278 cmd_sta_set_eapakaprime);
14279 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
14280 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
14281 /* TODO: sta_set_ibss */
14282 /* TODO: sta_set_mode */
14283 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
14284 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
14285 /* TODO: sta_up_load */
14286 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
14287 cmd_sta_preset_testparameters);
14288 /* TODO: sta_set_system */
14289 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
14290 /* TODO: sta_set_rifs_test */
14291 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
14292 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
14293 /* TODO: sta_send_coexist_mgmt */
14294 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
14295 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
14296 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
14297 sigma_dut_reg_cmd("sta_reset_default", req_intf,
14298 cmd_sta_reset_default);
14299 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
14300 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
14301 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
14302 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
14303 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020014304 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014305 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
14306 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
14307 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
14308 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
14309 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030014310 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
14311 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014312 sigma_dut_reg_cmd("sta_add_credential", req_intf,
14313 cmd_sta_add_credential);
14314 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020014315 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014316 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
14317 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
14318 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
14319 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
14320 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
14321 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030014322 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014323 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
14324 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020014325 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053014326 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014327}