blob: 69b67661740de8214a3c27bff91477a16d75d826 [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
234int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
235{
236#ifdef __linux__
237 char buf[100];
238
239 if (wifi_chip_type == DRIVER_WCN) {
240 if (enabled) {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530241 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
242 intf);
243 if (system(buf) != 0) {
244 snprintf(buf, sizeof(buf),
245 "iwpriv wlan0 dump 906");
246 if (system(buf) != 0)
247 goto set_power_save;
248 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200249 } else {
Purushottam Kushwaha304561d2019-12-23 16:57:18 +0530250 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
251 intf);
252 if (system(buf) != 0) {
253 snprintf(buf, sizeof(buf),
254 "iwpriv wlan0 dump 905");
255 if (system(buf) != 0)
256 goto set_power_save;
257 snprintf(buf, sizeof(buf),
258 "iwpriv wlan0 dump 912");
259 if (system(buf) != 0)
260 goto set_power_save;
261 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200262 }
263
264 return 0;
265 }
266
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530267set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200268 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
269 intf, enabled ? "on" : "off");
270 if (system(buf) != 0) {
271 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
272 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530273 if (system(buf) != 0) {
274 sigma_dut_print(dut, DUT_MSG_ERROR,
275 "Failed to set power save %s",
276 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200277 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530278 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200279 }
280
281 return 0;
282#else /* __linux__ */
283 return -1;
284#endif /* __linux__ */
285}
286
287
Lior Davidcc88b562017-01-03 18:52:09 +0200288#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200289
Lior Davidcc88b562017-01-03 18:52:09 +0200290static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
291 size_t len)
292{
293 DIR *dir, *wil_dir;
294 struct dirent *entry;
295 int ret = -1;
296 const char *root_path = "/sys/kernel/debug/ieee80211";
297
298 dir = opendir(root_path);
299 if (!dir)
300 return -2;
301
302 while ((entry = readdir(dir))) {
303 if (strcmp(entry->d_name, ".") == 0 ||
304 strcmp(entry->d_name, "..") == 0)
305 continue;
306
307 if (snprintf(path, len, "%s/%s/wil6210",
308 root_path, entry->d_name) >= (int) len) {
309 ret = -3;
310 break;
311 }
312
313 wil_dir = opendir(path);
314 if (wil_dir) {
315 closedir(wil_dir);
316 ret = 0;
317 break;
318 }
319 }
320
321 closedir(dir);
322 return ret;
323}
Lior David0fe101e2017-03-09 16:09:50 +0200324
325
326static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
327 void *payload, uint16_t length)
328{
329 struct {
330 struct wil_wmi_header hdr;
331 char payload[WIL_WMI_MAX_PAYLOAD];
332 } __attribute__((packed)) cmd;
333 char buf[128], fname[128];
334 size_t towrite, written;
335 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300336 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200337
338 if (length > WIL_WMI_MAX_PAYLOAD) {
339 sigma_dut_print(dut, DUT_MSG_ERROR,
340 "payload too large(%u, max %u)",
341 length, WIL_WMI_MAX_PAYLOAD);
342 return -1;
343 }
344
345 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
346 cmd.hdr.cmd = command;
347 memcpy(cmd.payload, payload, length);
348
349 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
350 sigma_dut_print(dut, DUT_MSG_ERROR,
351 "failed to get wil6210 debugfs dir");
352 return -1;
353 }
354
Jouni Malinen3aa72862019-05-29 23:14:51 +0300355 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
356 if (res < 0 || res >= sizeof(fname))
357 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200358 f = fopen(fname, "wb");
359 if (!f) {
360 sigma_dut_print(dut, DUT_MSG_ERROR,
361 "failed to open: %s", fname);
362 return -1;
363 }
364
365 towrite = sizeof(cmd.hdr) + length;
366 written = fwrite(&cmd, 1, towrite, f);
367 fclose(f);
368 if (written != towrite) {
369 sigma_dut_print(dut, DUT_MSG_ERROR,
370 "failed to send wmi %u", command);
371 return -1;
372 }
373
374 return 0;
375}
376
377
378static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
379 const char *pattern, unsigned int *field)
380{
381 char buf[128], fname[128];
382 FILE *f;
383 regex_t re;
384 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300385 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200386
387 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
388 sigma_dut_print(dut, DUT_MSG_ERROR,
389 "failed to get wil6210 debugfs dir");
390 return -1;
391 }
392
Jouni Malinen3aa72862019-05-29 23:14:51 +0300393 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
394 if (res < 0 || res >= sizeof(fname))
395 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200396 f = fopen(fname, "r");
397 if (!f) {
398 sigma_dut_print(dut, DUT_MSG_ERROR,
399 "failed to open: %s", fname);
400 return -1;
401 }
402
403 if (regcomp(&re, pattern, REG_EXTENDED)) {
404 sigma_dut_print(dut, DUT_MSG_ERROR,
405 "regcomp failed: %s", pattern);
406 goto out;
407 }
408
409 /*
410 * find the entry for the mac address
411 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
412 */
413 while (fgets(buf, sizeof(buf), f)) {
414 if (strcasestr(buf, bssid)) {
415 /* extract the field (CID/AID/state) */
416 rc = regexec(&re, buf, 2, m, 0);
417 if (!rc && (m[1].rm_so >= 0)) {
418 buf[m[1].rm_eo] = 0;
419 *field = atoi(&buf[m[1].rm_so]);
420 ret = 0;
421 break;
422 }
423 }
424 }
425
426 regfree(&re);
427 if (ret)
428 sigma_dut_print(dut, DUT_MSG_ERROR,
429 "could not extract field");
430
431out:
432 fclose(f);
433
434 return ret;
435}
436
437
438static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
439 unsigned int *cid)
440{
441 const char *pattern = "\\[([0-9]+)\\]";
442
443 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
444}
445
446
447static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
448 int l_rx)
449{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700450 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200451 unsigned int cid;
452
Rakesh Sunki556237d2017-03-30 14:49:31 -0700453 memset(&cmd, 0, sizeof(cmd));
454
Lior David0fe101e2017-03-09 16:09:50 +0200455 if (wil6210_get_cid(dut, mac, &cid))
456 return -1;
457
458 cmd.bf_type = WIL_WMI_BRP_RX;
459 cmd.sta_id = cid;
460 /* training length (l_rx) is ignored, FW always uses length 16 */
461 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
462 &cmd, sizeof(cmd));
463}
464
465
466static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
467{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700468 struct wil_wmi_bf_trig_cmd cmd;
469
470 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200471
472 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
473 return -1;
474
475 cmd.bf_type = WIL_WMI_SLS;
476 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
477 &cmd, sizeof(cmd));
478}
479
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200480
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200481int wil6210_set_ese(struct sigma_dut *dut, int count,
482 struct sigma_ese_alloc *allocs)
483{
484 struct wil_wmi_ese_cfg cmd = { };
485 int i;
486
487 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
488 return -1;
489
490 if (dut->ap_bcnint <= 0) {
491 sigma_dut_print(dut, DUT_MSG_ERROR,
492 "invalid beacon interval(%d), check test",
493 dut->ap_bcnint);
494 return -1;
495 }
496
497 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
498 cmd.flags = 0x1d;
499 cmd.num_allocs = count;
500 for (i = 0; i < count; i++) {
501 /*
502 * Convert percent from BI (BI specified in milliseconds)
503 * to absolute duration in microseconds.
504 */
505 cmd.slots[i].duration =
506 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
507 switch (allocs[i].type) {
508 case ESE_CBAP:
509 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
510 break;
511 case ESE_SP:
512 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
513 break;
514 default:
515 sigma_dut_print(dut, DUT_MSG_ERROR,
516 "invalid slot type(%d) at index %d",
517 allocs[i].type, i);
518 return -1;
519 }
520 cmd.slots[i].src_aid = allocs[i].src_aid;
521 cmd.slots[i].dst_aid = allocs[i].dst_aid;
522 sigma_dut_print(dut, DUT_MSG_INFO,
523 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
524 i, cmd.slots[i].duration,
525 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
526 cmd.slots[i].dst_aid);
527 }
528
529 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
530}
531
532
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200533int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
534{
535 struct wil_wmi_force_mcs cmd = { };
536
537 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
538 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
539 cmd.force_enable = (uint32_t) force;
540 cmd.mcs = (uint32_t) mcs;
541
542 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
543 &cmd, sizeof(cmd));
544}
545
546
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200547static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
548{
549 struct wil_wmi_force_rsn_ie cmd = { };
550
551 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
552 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
553 cmd.state = (uint32_t) state;
554
555 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
556 &cmd, sizeof(cmd));
557}
558
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300559
560/*
561 * this function is also used to configure generic remain-on-channel
562 */
563static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
564{
565 struct wil_wmi_p2p_cfg_cmd cmd = { };
566 int channel = freq_to_channel(freq);
567
568 if (channel < 0)
569 return -1;
570 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
571 cmd.channel = channel - 1;
572 cmd.bcon_interval = WIL_DEFAULT_BI;
573 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
574
575 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
576 &cmd, sizeof(cmd));
577}
578
579
580static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
581{
582 int ret = wil6210_p2p_cfg(dut, freq);
583
584 if (ret)
585 return ret;
586
587 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
588 if (!ret) {
589 /*
590 * wait a bit to allow FW to setup the radio
591 * especially important if we switch channels
592 */
593 usleep(500000);
594 }
595
596 return ret;
597}
598
599
600static int wil6210_stop_discovery(struct sigma_dut *dut)
601{
602 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
603}
604
605
606static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
607 int wait_duration,
608 const char *frame, size_t frame_len)
609{
610 char buf[128], fname[128];
611 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300612 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300613 size_t written;
614
615 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
616 sigma_dut_print(dut, DUT_MSG_ERROR,
617 "failed to get wil6210 debugfs dir");
618 return -1;
619 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300620 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
621 if (r < 0 || r >= sizeof(fname))
622 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300623
624 if (wil6210_remain_on_channel(dut, freq)) {
625 sigma_dut_print(dut, DUT_MSG_ERROR,
626 "failed to listen on channel");
627 return -1;
628 }
629
630 f = fopen(fname, "wb");
631 if (!f) {
632 sigma_dut_print(dut, DUT_MSG_ERROR,
633 "failed to open: %s", fname);
634 res = -1;
635 goto out_stop;
636 }
637 written = fwrite(frame, 1, frame_len, f);
638 fclose(f);
639
640 if (written != frame_len) {
641 sigma_dut_print(dut, DUT_MSG_ERROR,
642 "failed to transmit frame (got %zd, expected %zd)",
643 written, frame_len);
644 res = -1;
645 goto out_stop;
646 }
647
648 usleep(wait_duration * 1000);
649
650out_stop:
651 wil6210_stop_discovery(dut);
652 return res;
653}
654
655
656static int find_template_frame_tag(struct template_frame_tag *tags,
657 int total_tags, int tag_num)
658{
659 int i;
660
661 for (i = 0; i < total_tags; i++) {
662 if (tag_num == tags[i].num)
663 return i;
664 }
665
666 return -1;
667}
668
669
670static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
671 int id, const char *value, size_t val_len)
672{
673 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
674
675 if (len < 3 + val_len) {
676 sigma_dut_print(dut, DUT_MSG_ERROR,
677 "not enough space to replace P2P attribute");
678 return -1;
679 }
680
681 if (attr->len != val_len) {
682 sigma_dut_print(dut, DUT_MSG_ERROR,
683 "attribute length mismatch (need %zu have %hu)",
684 val_len, attr->len);
685 return -1;
686 }
687
688 if (attr->id != id) {
689 sigma_dut_print(dut, DUT_MSG_ERROR,
690 "incorrect attribute id (expected %d actual %d)",
691 id, attr->id);
692 return -1;
693 }
694
695 memcpy(attr->variable, value, val_len);
696
697 return 0;
698}
699
700
701static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
702 char *buf, size_t *length,
703 struct template_frame_tag *tags,
704 size_t *num_tags)
705{
706 char line[512];
707 FILE *f;
708 size_t offset = 0, tag_index = 0;
709 int num, index;
710 int in_tag = 0, tag_num = 0, tag_offset = 0;
711
712 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
713 sigma_dut_print(dut, DUT_MSG_ERROR,
714 "supplied buffer is too small");
715 return -1;
716 }
717
718 f = fopen(fname, "r");
719 if (!f) {
720 sigma_dut_print(dut, DUT_MSG_ERROR,
721 "failed to open template file %s", fname);
722 return -1;
723 }
724
725 /*
726 * template file format: lines beginning with # are comments and
727 * ignored.
728 * It is possible to tag bytes in the frame to make it easy
729 * to replace fields in the template, espcially if they appear
730 * in variable-sized sections (such as IEs)
731 * This is done by a line beginning with $NUM where NUM is an integer
732 * tag number. It can be followed by space(s) and comment.
733 * The next line is considered the tagged bytes. The parser will fill
734 * the tag number, offset and length of the tagged bytes.
735 * rest of the lines contain frame bytes as sequence of hex digits,
736 * 2 digits for each byte. Spaces are allowed between bytes.
737 * On bytes lines only hex digits and spaces are allowed
738 */
739 while (!feof(f)) {
740 if (!fgets(line, sizeof(line), f))
741 break;
742 index = 0;
743 while (isspace((unsigned char) line[index]))
744 index++;
745 if (!line[index] || line[index] == '#')
746 continue;
747 if (line[index] == '$') {
748 if (tags) {
749 index++;
750 tag_num = strtol(&line[index], NULL, 0);
751 tag_offset = offset;
752 in_tag = 1;
753 }
754 continue;
755 }
756 while (line[index]) {
757 if (isspace((unsigned char) line[index])) {
758 index++;
759 continue;
760 }
761 num = hex_byte(&line[index]);
762 if (num < 0)
763 break;
764 buf[offset++] = num;
765 if (offset == *length)
766 goto out;
767 index += 2;
768 }
769
770 if (in_tag) {
771 if (tag_index < *num_tags) {
772 tags[tag_index].num = tag_num;
773 tags[tag_index].offset = tag_offset;
774 tags[tag_index].len = offset - tag_offset;
775 tag_index++;
776 } else {
777 sigma_dut_print(dut, DUT_MSG_INFO,
778 "too many tags, tag ignored");
779 }
780 in_tag = 0;
781 }
782 }
783
784 if (num_tags)
785 *num_tags = tag_index;
786out:
787 fclose(f);
788 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
789 sigma_dut_print(dut, DUT_MSG_ERROR,
790 "template frame is too small");
791 return -1;
792 }
793
794 *length = offset;
795 return 0;
796}
797
Lior Davidcc88b562017-01-03 18:52:09 +0200798#endif /* __linux__ */
799
800
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200801static void static_ip_file(int proto, const char *addr, const char *mask,
802 const char *gw)
803{
804 if (proto) {
805 FILE *f = fopen("static-ip", "w");
806 if (f) {
807 fprintf(f, "%d %s %s %s\n", proto, addr,
808 mask ? mask : "N/A",
809 gw ? gw : "N/A");
810 fclose(f);
811 }
812 } else {
813 unlink("static-ip");
814 }
815}
816
817
818static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
819 const char *ssid)
820{
821#ifdef __linux__
822 char buf[100];
823
824 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
825 intf, ssid);
826 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
827
828 if (system(buf) != 0) {
829 sigma_dut_print(dut, DUT_MSG_ERROR,
830 "iwpriv neighbor request failed");
831 return -1;
832 }
833
834 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
835
836 return 0;
837#else /* __linux__ */
838 return -1;
839#endif /* __linux__ */
840}
841
842
843static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530844 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200845{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530846 const char *val;
847 int reason_code = 0;
848 char buf[1024];
849
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200850 /*
851 * In the earlier builds we used WNM_QUERY and in later
852 * builds used WNM_BSS_QUERY.
853 */
854
Ashwini Patil5acd7382017-04-13 15:55:04 +0530855 val = get_param(cmd, "BTMQuery_Reason_Code");
856 if (val)
857 reason_code = atoi(val);
858
859 val = get_param(cmd, "Cand_List");
860 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
861 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
862 dut->btm_query_cand_list);
863 free(dut->btm_query_cand_list);
864 dut->btm_query_cand_list = NULL;
865 } else {
866 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
867 }
868
869 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200870 sigma_dut_print(dut, DUT_MSG_ERROR,
871 "transition management query failed");
872 return -1;
873 }
874
875 sigma_dut_print(dut, DUT_MSG_DEBUG,
876 "transition management query sent");
877
878 return 0;
879}
880
881
882int is_ip_addr(const char *str)
883{
884 const char *pos = str;
885 struct in_addr addr;
886
887 while (*pos) {
888 if (*pos != '.' && (*pos < '0' || *pos > '9'))
889 return 0;
890 pos++;
891 }
892
893 return inet_aton(str, &addr);
894}
895
896
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200897int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
898 size_t buf_len)
899{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530900 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200901 char ip[16], mask[15], dns[16], sec_dns[16];
902 int is_dhcp = 0;
903 int s;
904#ifdef ANDROID
905 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530906#else /* ANDROID */
907 FILE *f;
908#ifdef __linux__
909 const char *str_ps;
910#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200911#endif /* ANDROID */
912
913 ip[0] = '\0';
914 mask[0] = '\0';
915 dns[0] = '\0';
916 sec_dns[0] = '\0';
917
918 s = socket(PF_INET, SOCK_DGRAM, 0);
919 if (s >= 0) {
920 struct ifreq ifr;
921 struct sockaddr_in saddr;
922
923 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700924 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200925 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
926 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
927 "%s IP address: %s",
928 ifname, strerror(errno));
929 } else {
930 memcpy(&saddr, &ifr.ifr_addr,
931 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700932 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200933 }
934
935 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
936 memcpy(&saddr, &ifr.ifr_addr,
937 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700938 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200939 }
940 close(s);
941 }
942
943#ifdef ANDROID
944 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
945 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
946 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
947 if (property_get(tmp, prop, NULL) != 0 &&
948 strcmp(prop, "ok") == 0) {
949 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
950 ifname);
951 if (property_get(tmp, prop, NULL) != 0 &&
952 strcmp(ip, prop) == 0)
953 is_dhcp = 1;
954 }
955 }
956
957 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700958 if (property_get(tmp, prop, NULL) != 0)
959 strlcpy(dns, prop, sizeof(dns));
960 else if (property_get("net.dns1", prop, NULL) != 0)
961 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962
963 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700964 if (property_get(tmp, prop, NULL) != 0)
965 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200966#else /* ANDROID */
967#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200968 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530969 str_ps = "ps -w";
970 else
971 str_ps = "ps ax";
972 snprintf(tmp, sizeof(tmp),
973 "%s | grep dhclient | grep -v grep | grep -q %s",
974 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200975 if (system(tmp) == 0)
976 is_dhcp = 1;
977 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530978 snprintf(tmp, sizeof(tmp),
979 "%s | grep udhcpc | grep -v grep | grep -q %s",
980 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200981 if (system(tmp) == 0)
982 is_dhcp = 1;
983 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530984 snprintf(tmp, sizeof(tmp),
985 "%s | grep dhcpcd | grep -v grep | grep -q %s",
986 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200987 if (system(tmp) == 0)
988 is_dhcp = 1;
989 }
990 }
991#endif /* __linux__ */
992
993 f = fopen("/etc/resolv.conf", "r");
994 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530995 char *pos, *pos2;
996
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200997 while (fgets(tmp, sizeof(tmp), f)) {
998 if (strncmp(tmp, "nameserver", 10) != 0)
999 continue;
1000 pos = tmp + 10;
1001 while (*pos == ' ' || *pos == '\t')
1002 pos++;
1003 pos2 = pos;
1004 while (*pos2) {
1005 if (*pos2 == '\n' || *pos2 == '\r') {
1006 *pos2 = '\0';
1007 break;
1008 }
1009 pos2++;
1010 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001011 if (!dns[0])
1012 strlcpy(dns, pos, sizeof(dns));
1013 else if (!sec_dns[0])
1014 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001015 }
1016 fclose(f);
1017 }
1018#endif /* ANDROID */
1019
1020 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1021 is_dhcp, ip, mask, dns);
1022 buf[buf_len - 1] = '\0';
1023
1024 return 0;
1025}
1026
1027
1028
1029
1030int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1031 size_t buf_len)
1032{
1033#ifdef __linux__
1034#ifdef ANDROID
1035 char cmd[200], result[1000], *pos, *end;
1036 FILE *f;
1037 size_t len;
1038
1039 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1040 f = popen(cmd, "r");
1041 if (f == NULL)
1042 return -1;
1043 len = fread(result, 1, sizeof(result) - 1, f);
1044 pclose(f);
1045 if (len == 0)
1046 return -1;
1047 result[len] = '\0';
1048 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1049
1050 pos = strstr(result, "inet6 ");
1051 if (pos == NULL)
1052 return -1;
1053 pos += 6;
1054 end = strchr(pos, ' ');
1055 if (end)
1056 *end = '\0';
1057 end = strchr(pos, '/');
1058 if (end)
1059 *end = '\0';
1060 snprintf(buf, buf_len, "ip,%s", pos);
1061 buf[buf_len - 1] = '\0';
1062 return 0;
1063#else /* ANDROID */
1064 struct ifaddrs *ifaddr, *ifa;
1065 int res, found = 0;
1066 char host[NI_MAXHOST];
1067
1068 if (getifaddrs(&ifaddr) < 0) {
1069 perror("getifaddrs");
1070 return -1;
1071 }
1072
1073 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1074 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1075 continue;
1076 if (ifa->ifa_addr == NULL ||
1077 ifa->ifa_addr->sa_family != AF_INET6)
1078 continue;
1079
1080 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1081 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1082 if (res != 0) {
1083 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1084 gai_strerror(res));
1085 continue;
1086 }
1087 if (strncmp(host, "fe80::", 6) == 0)
1088 continue; /* skip link-local */
1089
1090 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1091 found = 1;
1092 break;
1093 }
1094
1095 freeifaddrs(ifaddr);
1096
1097 if (found) {
1098 char *pos;
1099 pos = strchr(host, '%');
1100 if (pos)
1101 *pos = '\0';
1102 snprintf(buf, buf_len, "ip,%s", host);
1103 buf[buf_len - 1] = '\0';
1104 return 0;
1105 }
1106
1107#endif /* ANDROID */
1108#endif /* __linux__ */
1109 return -1;
1110}
1111
1112
Jouni Malinenf7222712019-06-13 01:50:21 +03001113static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1114 struct sigma_conn *conn,
1115 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001116{
1117 const char *intf = get_param(cmd, "Interface");
1118 const char *ifname;
1119 char buf[200];
1120 const char *val;
1121 int type = 1;
1122
1123 if (intf == NULL)
1124 return -1;
1125
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001126 if (strcmp(intf, get_main_ifname(dut)) == 0)
1127 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001128 else
1129 ifname = intf;
1130
1131 /*
1132 * UCC may assume the IP address to be available immediately after
1133 * association without trying to run sta_get_ip_config multiple times.
1134 * Sigma CAPI does not specify this command as a block command that
1135 * would wait for the address to become available, but to pass tests
1136 * more reliably, it looks like such a wait may be needed here.
1137 */
1138 if (wait_ip_addr(dut, ifname, 15) < 0) {
1139 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1140 "for sta_get_ip_config");
1141 /*
1142 * Try to continue anyway since many UCC tests do not really
1143 * care about the return value from here..
1144 */
1145 }
1146
1147 val = get_param(cmd, "Type");
1148 if (val)
1149 type = atoi(val);
1150 if (type == 2 || dut->last_set_ip_config_ipv6) {
1151 int i;
1152
1153 /*
1154 * Since we do not have proper wait for IPv6 addresses, use a
1155 * fixed two second delay here as a workaround for UCC script
1156 * assuming IPv6 address is available when this command returns.
1157 * Some scripts did not use Type,2 properly for IPv6, so include
1158 * also the cases where the previous sta_set_ip_config indicated
1159 * use of IPv6.
1160 */
1161 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1162 for (i = 0; i < 10; i++) {
1163 sleep(1);
1164 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1165 {
1166 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1167 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1168#ifdef ANDROID
1169 sigma_dut_print(dut, DUT_MSG_INFO,
1170 "Adding IPv6 rule on Android");
1171 add_ipv6_rule(dut, intf);
1172#endif /* ANDROID */
1173
1174 return 0;
1175 }
1176 }
1177 }
1178 if (type == 1) {
1179 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1180 return -2;
1181 } else if (type == 2) {
1182 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1183 return -2;
1184 } else {
1185 send_resp(dut, conn, SIGMA_ERROR,
1186 "errorCode,Unsupported address type");
1187 return 0;
1188 }
1189
1190 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1191 return 0;
1192}
1193
1194
1195static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1196{
1197#ifdef __linux__
1198 char buf[200];
1199 char path[128];
1200 struct stat s;
1201
1202#ifdef ANDROID
1203 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1204#else /* ANDROID */
1205 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1206#endif /* ANDROID */
1207 if (stat(path, &s) == 0) {
1208 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1209 sigma_dut_print(dut, DUT_MSG_INFO,
1210 "Kill previous DHCP client: %s", buf);
1211 if (system(buf) != 0)
1212 sigma_dut_print(dut, DUT_MSG_INFO,
1213 "Failed to kill DHCP client");
1214 unlink(path);
1215 sleep(1);
1216 } else {
1217 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1218
1219 if (stat(path, &s) == 0) {
1220 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1221 sigma_dut_print(dut, DUT_MSG_INFO,
1222 "Kill previous DHCP client: %s", buf);
1223 if (system(buf) != 0)
1224 sigma_dut_print(dut, DUT_MSG_INFO,
1225 "Failed to kill DHCP client");
1226 unlink(path);
1227 sleep(1);
1228 }
1229 }
1230#endif /* __linux__ */
1231}
1232
1233
1234static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1235{
1236#ifdef __linux__
1237 char buf[200];
1238
1239#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301240 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1241 snprintf(buf, sizeof(buf),
1242 "/system/bin/dhcpcd -b %s", ifname);
1243 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1244 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301245 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1246 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1247 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1248 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301249 } else {
1250 sigma_dut_print(dut, DUT_MSG_ERROR,
1251 "DHCP client program missing");
1252 return 0;
1253 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001254#else /* ANDROID */
1255 snprintf(buf, sizeof(buf),
1256 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1257 ifname, ifname);
1258#endif /* ANDROID */
1259 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1260 if (system(buf) != 0) {
1261 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1262 if (system(buf) != 0) {
1263 sigma_dut_print(dut, DUT_MSG_INFO,
1264 "Failed to start DHCP client");
1265#ifndef ANDROID
1266 return -1;
1267#endif /* ANDROID */
1268 }
1269 }
1270#endif /* __linux__ */
1271
1272 return 0;
1273}
1274
1275
1276static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1277{
1278#ifdef __linux__
1279 char buf[200];
1280
1281 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1282 if (system(buf) != 0) {
1283 sigma_dut_print(dut, DUT_MSG_INFO,
1284 "Failed to clear IP addresses");
1285 return -1;
1286 }
1287#endif /* __linux__ */
1288
1289 return 0;
1290}
1291
1292
1293#ifdef ANDROID
1294static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1295{
1296 char cmd[200], *result, *pos;
1297 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301298 int tableid;
1299 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001300
1301 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1302 ifname);
1303 fp = popen(cmd, "r");
1304 if (fp == NULL)
1305 return -1;
1306
1307 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301308 if (result == NULL) {
1309 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001310 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001312
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301313 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001314 fclose(fp);
1315
1316 if (len == 0) {
1317 free(result);
1318 return -1;
1319 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301320 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001321
1322 pos = strstr(result, "table ");
1323 if (pos == NULL) {
1324 free(result);
1325 return -1;
1326 }
1327
1328 pos += strlen("table ");
1329 tableid = atoi(pos);
1330 if (tableid != 0) {
1331 if (system("ip -6 rule del prio 22000") != 0) {
1332 /* ignore any error */
1333 }
1334 snprintf(cmd, sizeof(cmd),
1335 "ip -6 rule add from all lookup %d prio 22000",
1336 tableid);
1337 if (system(cmd) != 0) {
1338 sigma_dut_print(dut, DUT_MSG_INFO,
1339 "Failed to run %s", cmd);
1340 free(result);
1341 return -1;
1342 }
1343 } else {
1344 sigma_dut_print(dut, DUT_MSG_INFO,
1345 "No Valid Table Id found %s", pos);
1346 free(result);
1347 return -1;
1348 }
1349 free(result);
1350
1351 return 0;
1352}
1353#endif /* ANDROID */
1354
1355
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301356int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1357 const char *ip, const char *mask)
1358{
1359 char buf[200];
1360
1361 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1362 ifname, ip, mask);
1363 return system(buf) == 0;
1364}
1365
1366
1367int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1368{
1369 char buf[200];
1370
1371 if (!is_ip_addr(gw)) {
1372 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1373 return -1;
1374 }
1375
1376 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1377 if (!dut->no_ip_addr_set && system(buf) != 0) {
1378 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1379 gw);
1380 if (system(buf) != 0)
1381 return 0;
1382 }
1383
1384 return 1;
1385}
1386
1387
Jouni Malinenf7222712019-06-13 01:50:21 +03001388static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1389 struct sigma_conn *conn,
1390 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001391{
1392 const char *intf = get_param(cmd, "Interface");
1393 const char *ifname;
1394 char buf[200];
1395 const char *val, *ip, *mask, *gw;
1396 int type = 1;
1397
1398 if (intf == NULL)
1399 return -1;
1400
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001401 if (strcmp(intf, get_main_ifname(dut)) == 0)
1402 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001403 else
1404 ifname = intf;
1405
1406 if (if_nametoindex(ifname) == 0) {
1407 send_resp(dut, conn, SIGMA_ERROR,
1408 "ErrorCode,Unknown interface");
1409 return 0;
1410 }
1411
1412 val = get_param(cmd, "Type");
1413 if (val) {
1414 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301415 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001416 send_resp(dut, conn, SIGMA_ERROR,
1417 "ErrorCode,Unsupported address type");
1418 return 0;
1419 }
1420 }
1421
1422 dut->last_set_ip_config_ipv6 = 0;
1423
1424 val = get_param(cmd, "dhcp");
1425 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1426 static_ip_file(0, NULL, NULL, NULL);
1427#ifdef __linux__
1428 if (type == 2) {
1429 dut->last_set_ip_config_ipv6 = 1;
1430 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1431 "stateless address autoconfiguration");
1432#ifdef ANDROID
1433 /*
1434 * This sleep is required as the assignment in case of
1435 * Android is taking time and is done by the kernel.
1436 * The subsequent ping for IPv6 is impacting HS20 test
1437 * case.
1438 */
1439 sleep(2);
1440 add_ipv6_rule(dut, intf);
1441#endif /* ANDROID */
1442 /* Assume this happens by default */
1443 return 1;
1444 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301445 if (type != 3) {
1446 kill_dhcp_client(dut, ifname);
1447 if (start_dhcp_client(dut, ifname) < 0)
1448 return -2;
1449 } else {
1450 sigma_dut_print(dut, DUT_MSG_DEBUG,
1451 "Using FILS HLP DHCPv4 Rapid Commit");
1452 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001453
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001454 return 1;
1455#endif /* __linux__ */
1456 return -2;
1457 }
1458
1459 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301460 if (!ip) {
1461 send_resp(dut, conn, SIGMA_INVALID,
1462 "ErrorCode,Missing IP address");
1463 return 0;
1464 }
1465
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001466 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301467 if (!mask) {
1468 send_resp(dut, conn, SIGMA_INVALID,
1469 "ErrorCode,Missing subnet mask");
1470 return 0;
1471 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001472
1473 if (type == 2) {
1474 int net = atoi(mask);
1475
1476 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1477 return -1;
1478
1479 if (dut->no_ip_addr_set) {
1480 snprintf(buf, sizeof(buf),
1481 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1482 ifname);
1483 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1484 if (system(buf) != 0) {
1485 sigma_dut_print(dut, DUT_MSG_DEBUG,
1486 "Failed to disable IPv6 address before association");
1487 }
1488 } else {
1489 snprintf(buf, sizeof(buf),
1490 "ip -6 addr del %s/%s dev %s",
1491 ip, mask, ifname);
1492 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1493 if (system(buf) != 0) {
1494 /*
1495 * This command may fail if the address being
1496 * deleted does not exist. Inaction here is
1497 * intentional.
1498 */
1499 }
1500
1501 snprintf(buf, sizeof(buf),
1502 "ip -6 addr add %s/%s dev %s",
1503 ip, mask, ifname);
1504 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1505 if (system(buf) != 0) {
1506 send_resp(dut, conn, SIGMA_ERROR,
1507 "ErrorCode,Failed to set IPv6 address");
1508 return 0;
1509 }
1510 }
1511
1512 dut->last_set_ip_config_ipv6 = 1;
1513 static_ip_file(6, ip, mask, NULL);
1514 return 1;
1515 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301516 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001517 return -1;
1518 }
1519
1520 kill_dhcp_client(dut, ifname);
1521
1522 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301523 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001524 send_resp(dut, conn, SIGMA_ERROR,
1525 "ErrorCode,Failed to set IP address");
1526 return 0;
1527 }
1528 }
1529
1530 gw = get_param(cmd, "defaultGateway");
1531 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301532 if (set_ipv4_gw(dut, gw) < 1) {
1533 send_resp(dut, conn, SIGMA_ERROR,
1534 "ErrorCode,Failed to set default gateway");
1535 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001536 }
1537 }
1538
1539 val = get_param(cmd, "primary-dns");
1540 if (val) {
1541 /* TODO */
1542 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1543 "setting", val);
1544 }
1545
1546 val = get_param(cmd, "secondary-dns");
1547 if (val) {
1548 /* TODO */
1549 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1550 "setting", val);
1551 }
1552
1553 static_ip_file(4, ip, mask, gw);
1554
1555 return 1;
1556}
1557
1558
Jouni Malinenf7222712019-06-13 01:50:21 +03001559static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1560 struct sigma_conn *conn,
1561 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562{
1563 /* const char *intf = get_param(cmd, "Interface"); */
1564 /* TODO: could report more details here */
1565 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1566 return 0;
1567}
1568
1569
Jouni Malinenf7222712019-06-13 01:50:21 +03001570static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1571 struct sigma_conn *conn,
1572 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001573{
1574 /* const char *intf = get_param(cmd, "Interface"); */
1575 char addr[20], resp[50];
1576
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301577 if (dut->dev_role == DEVROLE_STA_CFON)
1578 return sta_cfon_get_mac_address(dut, conn, cmd);
1579
Jouni Malinen9540e012019-11-05 17:08:42 +02001580 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001581 if (get_wpa_status(get_station_ifname(dut), "address",
1582 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001583 return -2;
1584
1585 snprintf(resp, sizeof(resp), "mac,%s", addr);
1586 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1587 return 0;
1588}
1589
1590
Jouni Malinenf7222712019-06-13 01:50:21 +03001591static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1592 struct sigma_conn *conn,
1593 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001594{
1595 /* const char *intf = get_param(cmd, "Interface"); */
1596 int connected = 0;
1597 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001598 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001599 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001600 sigma_dut_print(dut, DUT_MSG_INFO,
1601 "Could not get interface %s status",
1602 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001603 return -2;
1604 }
1605
1606 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1607 if (strncmp(result, "COMPLETED", 9) == 0)
1608 connected = 1;
1609
1610 if (connected)
1611 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1612 else
1613 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1614
1615 return 0;
1616}
1617
1618
Jouni Malinenf7222712019-06-13 01:50:21 +03001619static enum sigma_cmd_result
1620cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1621 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001622{
1623 /* const char *intf = get_param(cmd, "Interface"); */
1624 const char *dst, *timeout;
1625 int wait_time = 90;
1626 char buf[100];
1627 int res;
1628
1629 dst = get_param(cmd, "destination");
1630 if (dst == NULL || !is_ip_addr(dst))
1631 return -1;
1632
1633 timeout = get_param(cmd, "timeout");
1634 if (timeout) {
1635 wait_time = atoi(timeout);
1636 if (wait_time < 1)
1637 wait_time = 1;
1638 }
1639
1640 /* TODO: force renewal of IP lease if DHCP is enabled */
1641
1642 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1643 res = system(buf);
1644 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1645 if (res == 0)
1646 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1647 else if (res == 256)
1648 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1649 else
1650 return -2;
1651
1652 return 0;
1653}
1654
1655
Jouni Malinenf7222712019-06-13 01:50:21 +03001656static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1657 struct sigma_conn *conn,
1658 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001659{
1660 /* const char *intf = get_param(cmd, "Interface"); */
1661 char bssid[20], resp[50];
1662
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001663 if (get_wpa_status(get_station_ifname(dut), "bssid",
1664 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001665 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001666
1667 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1668 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1669 return 0;
1670}
1671
1672
1673#ifdef __SAMSUNG__
1674static int add_use_network(const char *ifname)
1675{
1676 char buf[100];
1677
1678 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1679 wpa_command(ifname, buf);
1680 return 0;
1681}
1682#endif /* __SAMSUNG__ */
1683
1684
1685static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1686 const char *ifname, struct sigma_cmd *cmd)
1687{
1688 const char *ssid = get_param(cmd, "ssid");
1689 int id;
1690 const char *val;
1691
1692 if (ssid == NULL)
1693 return -1;
1694
1695 start_sta_mode(dut);
1696
1697#ifdef __SAMSUNG__
1698 add_use_network(ifname);
1699#endif /* __SAMSUNG__ */
1700
1701 id = add_network(ifname);
1702 if (id < 0)
1703 return -2;
1704 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1705
1706 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1707 return -2;
1708
1709 dut->infra_network_id = id;
1710 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1711
1712 val = get_param(cmd, "program");
1713 if (!val)
1714 val = get_param(cmd, "prog");
1715 if (val && strcasecmp(val, "hs2") == 0) {
1716 char buf[100];
1717 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1718 wpa_command(ifname, buf);
1719
1720 val = get_param(cmd, "prefer");
1721 if (val && atoi(val) > 0)
1722 set_network(ifname, id, "priority", "1");
1723 }
1724
1725 return id;
1726}
1727
1728
Jouni Malinenf7222712019-06-13 01:50:21 +03001729static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1730 struct sigma_conn *conn,
1731 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001732{
1733 const char *intf = get_param(cmd, "Interface");
1734 const char *ssid = get_param(cmd, "ssid");
1735 const char *type = get_param(cmd, "encpType");
1736 const char *ifname;
1737 char buf[200];
1738 int id;
1739
1740 if (intf == NULL || ssid == NULL)
1741 return -1;
1742
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001743 if (strcmp(intf, get_main_ifname(dut)) == 0)
1744 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001745 else
1746 ifname = intf;
1747
1748 id = add_network_common(dut, conn, ifname, cmd);
1749 if (id < 0)
1750 return id;
1751
1752 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1753 return -2;
1754
1755 if (type && strcasecmp(type, "wep") == 0) {
1756 const char *val;
1757 int i;
1758
1759 val = get_param(cmd, "activeKey");
1760 if (val) {
1761 int keyid;
1762 keyid = atoi(val);
1763 if (keyid < 1 || keyid > 4)
1764 return -1;
1765 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1766 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1767 return -2;
1768 }
1769
1770 for (i = 0; i < 4; i++) {
1771 snprintf(buf, sizeof(buf), "key%d", i + 1);
1772 val = get_param(cmd, buf);
1773 if (val == NULL)
1774 continue;
1775 snprintf(buf, sizeof(buf), "wep_key%d", i);
1776 if (set_network(ifname, id, buf, val) < 0)
1777 return -2;
1778 }
1779 }
1780
1781 return 1;
1782}
1783
1784
Jouni Malinene4fde732019-03-25 22:29:37 +02001785static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1786 int id, const char *val)
1787{
1788 char key_mgmt[200], *end, *pos;
1789 const char *in_pos = val;
1790
Jouni Malinen8179fee2019-03-28 03:19:47 +02001791 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001792 pos = key_mgmt;
1793 end = pos + sizeof(key_mgmt);
1794 while (*in_pos) {
1795 int res, akm = atoi(in_pos);
1796 const char *str;
1797
Jouni Malinen8179fee2019-03-28 03:19:47 +02001798 if (akm >= 0 && akm < 32)
1799 dut->akm_values |= 1 << akm;
1800
Jouni Malinene4fde732019-03-25 22:29:37 +02001801 switch (akm) {
1802 case AKM_WPA_EAP:
1803 str = "WPA-EAP";
1804 break;
1805 case AKM_WPA_PSK:
1806 str = "WPA-PSK";
1807 break;
1808 case AKM_FT_EAP:
1809 str = "FT-EAP";
1810 break;
1811 case AKM_FT_PSK:
1812 str = "FT-PSK";
1813 break;
1814 case AKM_EAP_SHA256:
1815 str = "WPA-EAP-SHA256";
1816 break;
1817 case AKM_PSK_SHA256:
1818 str = "WPA-PSK-SHA256";
1819 break;
1820 case AKM_SAE:
1821 str = "SAE";
1822 break;
1823 case AKM_FT_SAE:
1824 str = "FT-SAE";
1825 break;
1826 case AKM_SUITE_B:
1827 str = "WPA-EAP-SUITE-B-192";
1828 break;
1829 case AKM_FT_SUITE_B:
1830 str = "FT-EAP-SHA384";
1831 break;
1832 case AKM_FILS_SHA256:
1833 str = "FILS-SHA256";
1834 break;
1835 case AKM_FILS_SHA384:
1836 str = "FILS-SHA384";
1837 break;
1838 case AKM_FT_FILS_SHA256:
1839 str = "FT-FILS-SHA256";
1840 break;
1841 case AKM_FT_FILS_SHA384:
1842 str = "FT-FILS-SHA384";
1843 break;
1844 default:
1845 sigma_dut_print(dut, DUT_MSG_ERROR,
1846 "Unsupported AKMSuitetype %d", akm);
1847 return -1;
1848 }
1849
1850 res = snprintf(pos, end - pos, "%s%s",
1851 pos == key_mgmt ? "" : " ", str);
1852 if (res < 0 || res >= end - pos)
1853 return -1;
1854 pos += res;
1855
1856 in_pos = strchr(in_pos, ';');
1857 if (!in_pos)
1858 break;
1859 while (*in_pos == ';')
1860 in_pos++;
1861 }
1862 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1863 val, key_mgmt);
1864 return set_network(ifname, id, "key_mgmt", key_mgmt);
1865}
1866
1867
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001868static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1869 const char *ifname, struct sigma_cmd *cmd)
1870{
1871 const char *val;
1872 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001873 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001874 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301875 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001876
1877 id = add_network_common(dut, conn, ifname, cmd);
1878 if (id < 0)
1879 return id;
1880
Jouni Malinen47dcc952017-10-09 16:43:24 +03001881 val = get_param(cmd, "Type");
1882 owe = val && strcasecmp(val, "OWE") == 0;
1883
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001884 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001885 if (!val && owe)
1886 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001887 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001888 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1889 * this missing parameter and assume proto=WPA2. */
1890 if (set_network(ifname, id, "proto", "WPA2") < 0)
1891 return ERROR_SEND_STATUS;
1892 } else if (strcasecmp(val, "wpa") == 0 ||
1893 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001894 if (set_network(ifname, id, "proto", "WPA") < 0)
1895 return -2;
1896 } else if (strcasecmp(val, "wpa2") == 0 ||
1897 strcasecmp(val, "wpa2-psk") == 0 ||
1898 strcasecmp(val, "wpa2-ft") == 0 ||
1899 strcasecmp(val, "wpa2-sha256") == 0) {
1900 if (set_network(ifname, id, "proto", "WPA2") < 0)
1901 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301902 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1903 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001904 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1905 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001906 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301907 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001908 if (set_network(ifname, id, "proto", "WPA2") < 0)
1909 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001910 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001911 } else {
1912 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1913 return 0;
1914 }
1915
1916 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001917 if (val) {
1918 cipher_set = 1;
1919 if (strcasecmp(val, "tkip") == 0) {
1920 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1921 return -2;
1922 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1923 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1924 return -2;
1925 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1926 if (set_network(ifname, id, "pairwise",
1927 "CCMP TKIP") < 0)
1928 return -2;
1929 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1930 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1931 return -2;
1932 if (set_network(ifname, id, "group", "GCMP") < 0)
1933 return -2;
1934 } else {
1935 send_resp(dut, conn, SIGMA_ERROR,
1936 "errorCode,Unrecognized encpType value");
1937 return 0;
1938 }
1939 }
1940
1941 val = get_param(cmd, "PairwiseCipher");
1942 if (val) {
1943 cipher_set = 1;
1944 /* TODO: Support space separated list */
1945 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1946 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1947 return -2;
1948 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1949 if (set_network(ifname, id, "pairwise",
1950 "CCMP-256") < 0)
1951 return -2;
1952 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1953 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1954 return -2;
1955 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1956 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1957 return -2;
1958 } else {
1959 send_resp(dut, conn, SIGMA_ERROR,
1960 "errorCode,Unrecognized PairwiseCipher value");
1961 return 0;
1962 }
1963 }
1964
Jouni Malinen47dcc952017-10-09 16:43:24 +03001965 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001966 send_resp(dut, conn, SIGMA_ERROR,
1967 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001968 return 0;
1969 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001970
1971 val = get_param(cmd, "GroupCipher");
1972 if (val) {
1973 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1974 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1975 return -2;
1976 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1977 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1978 return -2;
1979 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1980 if (set_network(ifname, id, "group", "GCMP") < 0)
1981 return -2;
1982 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1983 if (set_network(ifname, id, "group", "CCMP") < 0)
1984 return -2;
1985 } else {
1986 send_resp(dut, conn, SIGMA_ERROR,
1987 "errorCode,Unrecognized GroupCipher value");
1988 return 0;
1989 }
1990 }
1991
Jouni Malinen7b239522017-09-14 21:37:18 +03001992 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001993 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001994 const char *cipher;
1995
1996 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1997 cipher = "BIP-GMAC-256";
1998 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1999 cipher = "BIP-CMAC-256";
2000 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
2001 cipher = "BIP-GMAC-128";
2002 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
2003 cipher = "AES-128-CMAC";
2004 } else {
2005 send_resp(dut, conn, SIGMA_INVALID,
2006 "errorCode,Unsupported GroupMgntCipher");
2007 return 0;
2008 }
2009 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
2010 send_resp(dut, conn, SIGMA_INVALID,
2011 "errorCode,Failed to set GroupMgntCipher");
2012 return 0;
2013 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002014 }
2015
Jouni Malinene4fde732019-03-25 22:29:37 +02002016 val = get_param(cmd, "AKMSuiteType");
2017 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2018 return ERROR_SEND_STATUS;
2019
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002020 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302021
2022 if (dut->program == PROGRAM_OCE) {
2023 dut->sta_pmf = STA_PMF_OPTIONAL;
2024 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2025 return -2;
2026 }
2027
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002028 val = get_param(cmd, "PMF");
2029 if (val) {
2030 if (strcasecmp(val, "Required") == 0 ||
2031 strcasecmp(val, "Forced_Required") == 0) {
2032 dut->sta_pmf = STA_PMF_REQUIRED;
2033 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2034 return -2;
2035 } else if (strcasecmp(val, "Optional") == 0) {
2036 dut->sta_pmf = STA_PMF_OPTIONAL;
2037 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2038 return -2;
2039 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002040 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002041 strcasecmp(val, "Forced_Disabled") == 0) {
2042 dut->sta_pmf = STA_PMF_DISABLED;
2043 } else {
2044 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2045 return 0;
2046 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302047 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002048 dut->sta_pmf = STA_PMF_REQUIRED;
2049 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2050 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002051 }
2052
Jouni Malinen0165c7f2020-03-26 11:51:58 +02002053 val = get_param(cmd, "BeaconProtection");
2054 if (val && atoi(val) == 1 &&
2055 set_network(ifname, id, "beacon_prot", "1") < 0)
2056 return ERROR_SEND_STATUS;
2057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002058 return id;
2059}
2060
2061
Jouni Malinenf7222712019-06-13 01:50:21 +03002062static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2063 struct sigma_conn *conn,
2064 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002065{
2066 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002067 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002068 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002069 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002070 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002071 const char *ifname, *val, *alg;
2072 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002073 char buf[50];
Jouni Malinen11e55212019-11-22 21:46:59 +02002074 int sae_pwe = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002075
2076 if (intf == NULL)
2077 return -1;
2078
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002079 if (strcmp(intf, get_main_ifname(dut)) == 0)
2080 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002081 else
2082 ifname = intf;
2083
2084 id = set_wpa_common(dut, conn, ifname, cmd);
2085 if (id < 0)
2086 return id;
2087
2088 val = get_param(cmd, "keyMgmtType");
2089 alg = get_param(cmd, "micAlg");
2090
Jouni Malinen992a81e2017-08-22 13:57:47 +03002091 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002092 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002093 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2094 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002095 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002096 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2097 return -2;
2098 }
2099 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2100 sigma_dut_print(dut, DUT_MSG_ERROR,
2101 "Failed to clear sae_groups to default");
2102 return -2;
2103 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002104 if (!pmf) {
2105 dut->sta_pmf = STA_PMF_REQUIRED;
2106 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2107 return -2;
2108 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002109 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2110 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2111 if (set_network(ifname, id, "key_mgmt",
2112 "FT-SAE FT-PSK") < 0)
2113 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002114 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002115 if (set_network(ifname, id, "key_mgmt",
2116 "SAE WPA-PSK") < 0)
2117 return -2;
2118 }
2119 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2120 sigma_dut_print(dut, DUT_MSG_ERROR,
2121 "Failed to clear sae_groups to default");
2122 return -2;
2123 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002124 if (!pmf) {
2125 dut->sta_pmf = STA_PMF_OPTIONAL;
2126 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2127 return -2;
2128 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002129 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002130 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2131 return -2;
2132 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2133 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2134 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302135 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2136 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2137 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002138 } else if (!akm &&
2139 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2140 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002141 if (set_network(ifname, id, "key_mgmt",
2142 "WPA-PSK WPA-PSK-SHA256") < 0)
2143 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002144 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002145 if (set_network(ifname, id, "key_mgmt",
2146 "WPA-PSK WPA-PSK-SHA256") < 0)
2147 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002148 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002149 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2150 return -2;
2151 }
2152
2153 val = get_param(cmd, "passPhrase");
2154 if (val == NULL)
2155 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002156 if (type && strcasecmp(type, "SAE") == 0) {
2157 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2158 return -2;
2159 } else {
2160 if (set_network_quoted(ifname, id, "psk", val) < 0)
2161 return -2;
2162 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002163
Jouni Malinen78d10c42019-03-25 22:34:32 +02002164 val = get_param(cmd, "PasswordId");
2165 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2166 return ERROR_SEND_STATUS;
2167
Jouni Malinen992a81e2017-08-22 13:57:47 +03002168 val = get_param(cmd, "ECGroupID");
2169 if (val) {
Jouni Malinenb54f0df2019-12-12 01:57:29 +02002170 snprintf(buf, sizeof(buf), "SET sae_groups %s", val);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002171 if (wpa_command(ifname, buf) != 0) {
2172 sigma_dut_print(dut, DUT_MSG_ERROR,
2173 "Failed to clear sae_groups");
2174 return -2;
2175 }
2176 }
2177
Jouni Malinen68143132017-09-02 02:34:08 +03002178 val = get_param(cmd, "InvalidSAEElement");
2179 if (val) {
2180 free(dut->sae_commit_override);
2181 dut->sae_commit_override = strdup(val);
2182 }
2183
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002184 val = get_param(cmd, "PMKID_Include");
2185 if (val) {
2186 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2187 get_enable_disable(val));
2188 wpa_command(intf, buf);
2189 }
2190
Jouni Malineneeb43d32019-12-06 17:40:07 +02002191 val = get_param(cmd, "IgnoreH2E_RSNXE_BSSMemSel");
2192 if (val) {
2193 snprintf(buf, sizeof(buf), "SET ignore_sae_h2e_only %d",
2194 get_enable_disable(val));
2195 wpa_command(intf, buf);
2196 }
2197
Jouni Malinenf2348d22019-12-07 11:52:55 +02002198 val = get_param(cmd, "ECGroupID_RGE");
2199 if (val) {
2200 snprintf(buf, sizeof(buf), "SET extra_sae_rejected_groups %s",
2201 val);
2202 wpa_command(intf, buf);
2203 }
2204
Jouni Malinen99e55022019-12-07 13:59:41 +02002205 val = get_param(cmd, "RSNXE_Content");
2206 if (val) {
2207 const char *param;
2208
2209 if (strncasecmp(val, "AssocReq:", 9) == 0) {
2210 val += 9;
2211 param = "rsnxe_override_assoc";
2212 } else if (strncasecmp(val, "EapolM2:", 8) == 0) {
2213 val += 8;
2214 param = "rsnxe_override_eapol";
2215 } else {
2216 send_resp(dut, conn, SIGMA_ERROR,
2217 "errorCode,Unsupported RSNXE_Content value");
2218 return STATUS_SENT_ERROR;
2219 }
2220 snprintf(buf, sizeof(buf), "SET %s %s", param, val);
2221 wpa_command(intf, buf);
2222 }
2223
Jouni Malinen11e55212019-11-22 21:46:59 +02002224 val = get_param(cmd, "sae_pwe");
2225 if (val) {
2226 if (strcasecmp(val, "h2e") == 0) {
2227 dut->sae_pwe = SAE_PWE_H2E;
Jouni Malinen7244a412019-12-07 11:54:10 +02002228 } else if (strcasecmp(val, "loop") == 0 ||
2229 strcasecmp(val, "looping") == 0) {
Jouni Malinen11e55212019-11-22 21:46:59 +02002230 dut->sae_pwe = SAE_PWE_LOOP;
2231 } else {
2232 send_resp(dut, conn, SIGMA_ERROR,
2233 "errorCode,Unsupported sae_pwe value");
2234 return STATUS_SENT_ERROR;
2235 }
2236 }
Jouni Malinenc0078772020-03-04 21:23:16 +02002237 if (dut->sae_pwe == SAE_PWE_LOOP && get_param(cmd, "PasswordId"))
2238 sae_pwe = 3;
2239 else if (dut->sae_pwe == SAE_PWE_LOOP)
Jouni Malinen11e55212019-11-22 21:46:59 +02002240 sae_pwe = 0;
2241 else if (dut->sae_pwe == SAE_PWE_H2E)
2242 sae_pwe = 1;
2243 else if (dut->sae_h2e_default)
2244 sae_pwe = 2;
2245 snprintf(buf, sizeof(buf), "SET sae_pwe %d", sae_pwe);
2246 if (sae_pwe >= 0 && wpa_command(ifname, buf) != 0)
2247 return ERROR_SEND_STATUS;
2248
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002249 if (dut->program == PROGRAM_60GHZ && network_mode &&
2250 strcasecmp(network_mode, "PBSS") == 0 &&
2251 set_network(ifname, id, "pbss", "1") < 0)
2252 return -2;
2253
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002254 return 1;
2255}
2256
2257
Jouni Malinen8ac93452019-08-14 15:19:13 +03002258static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2259 struct sigma_conn *conn,
2260 const char *ifname, int id)
2261{
2262 char buf[200];
2263
2264 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2265 if (!file_exists(buf))
2266 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2267 if (!file_exists(buf))
2268 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2269 if (!file_exists(buf)) {
2270 char msg[300];
2271
2272 snprintf(msg, sizeof(msg),
2273 "ErrorCode,trustedRootCA system store (%s) not found",
2274 buf);
2275 send_resp(dut, conn, SIGMA_ERROR, msg);
2276 return STATUS_SENT_ERROR;
2277 }
2278
2279 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2280 return ERROR_SEND_STATUS;
2281
2282 return SUCCESS_SEND_STATUS;
2283}
2284
2285
2286static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2287 struct sigma_conn *conn,
2288 const char *ifname, int id,
2289 const char *val)
2290{
2291 char buf[200];
2292#ifdef ANDROID
2293 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2294 int length;
2295#endif /* ANDROID */
2296
2297 if (strcmp(val, "DEFAULT") == 0)
2298 return set_trust_root_system(dut, conn, ifname, id);
2299
2300#ifdef ANDROID
2301 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2302 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2303 if (length > 0) {
2304 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2305 buf);
2306 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2307 goto ca_cert_selected;
2308 }
2309#endif /* ANDROID */
2310
2311 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2312#ifdef __linux__
2313 if (!file_exists(buf)) {
2314 char msg[300];
2315
2316 snprintf(msg, sizeof(msg),
2317 "ErrorCode,trustedRootCA file (%s) not found", buf);
2318 send_resp(dut, conn, SIGMA_ERROR, msg);
2319 return STATUS_SENT_ERROR;
2320 }
2321#endif /* __linux__ */
2322#ifdef ANDROID
2323ca_cert_selected:
2324#endif /* ANDROID */
2325 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2326 return ERROR_SEND_STATUS;
2327
2328 return SUCCESS_SEND_STATUS;
2329}
2330
2331
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002332static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302333 const char *ifname, int username_identity,
2334 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002335{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002336 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002337 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002338 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002339 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002340 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002341
2342 id = set_wpa_common(dut, conn, ifname, cmd);
2343 if (id < 0)
2344 return id;
2345
2346 val = get_param(cmd, "keyMgmtType");
2347 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302348 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002349 trust_root = get_param(cmd, "trustedRootCA");
2350 domain = get_param(cmd, "Domain");
2351 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002352
Jouni Malinenad395a22017-09-01 21:13:46 +03002353 if (val && strcasecmp(val, "SuiteB") == 0) {
2354 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2355 0)
2356 return -2;
2357 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002358 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2359 return -2;
2360 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2361 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2362 return -2;
2363 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2364 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2365 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002366 } else if (!akm &&
2367 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2368 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002369 if (set_network(ifname, id, "key_mgmt",
2370 "WPA-EAP WPA-EAP-SHA256") < 0)
2371 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302372 } else if (akm && atoi(akm) == 14) {
2373 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2374 dut->sta_pmf == STA_PMF_REQUIRED) {
2375 if (set_network(ifname, id, "key_mgmt",
2376 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2377 return -2;
2378 } else {
2379 if (set_network(ifname, id, "key_mgmt",
2380 "WPA-EAP FILS-SHA256") < 0)
2381 return -2;
2382 }
2383
Jouni Malinen8179fee2019-03-28 03:19:47 +02002384 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302385 } else if (akm && atoi(akm) == 15) {
2386 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2387 dut->sta_pmf == STA_PMF_REQUIRED) {
2388 if (set_network(ifname, id, "key_mgmt",
2389 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2390 return -2;
2391 } else {
2392 if (set_network(ifname, id, "key_mgmt",
2393 "WPA-EAP FILS-SHA384") < 0)
2394 return -2;
2395 }
2396
Jouni Malinen8179fee2019-03-28 03:19:47 +02002397 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002398 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002399 if (set_network(ifname, id, "key_mgmt",
2400 "WPA-EAP WPA-EAP-SHA256") < 0)
2401 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002402 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002403 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2404 return -2;
2405 }
2406
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002407 if (trust_root) {
2408 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2409 !domain_suffix) {
2410 send_resp(dut, conn, SIGMA_ERROR,
2411 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2412 return STATUS_SENT_ERROR;
2413 }
2414 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002415 if (res != SUCCESS_SEND_STATUS)
2416 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002417 }
2418
Jouni Malinen53264f62019-05-03 13:04:40 +03002419 val = get_param(cmd, "ServerCert");
2420 if (val) {
2421 FILE *f;
2422 char *result = NULL, *pos;
2423
2424 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2425 val);
2426 f = fopen(buf, "r");
2427 if (f) {
2428 result = fgets(buf, sizeof(buf), f);
2429 fclose(f);
2430 }
2431 if (!result) {
2432 snprintf(buf2, sizeof(buf2),
2433 "ErrorCode,ServerCert hash could not be read from %s",
2434 buf);
2435 send_resp(dut, conn, SIGMA_ERROR, buf2);
2436 return STATUS_SENT_ERROR;
2437 }
2438 pos = strchr(buf, '\n');
2439 if (pos)
2440 *pos = '\0';
2441 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2442 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2443 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002444
2445 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2446 if (file_exists(buf)) {
2447 sigma_dut_print(dut, DUT_MSG_DEBUG,
2448 "TOD policy enabled for the configured ServerCert hash");
2449 dut->sta_tod_policy = 1;
2450 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002451 }
2452
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002453 if (domain &&
2454 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002455 return ERROR_SEND_STATUS;
2456
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002457 if (domain_suffix &&
2458 set_network_quoted(ifname, id, "domain_suffix_match",
2459 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002460 return ERROR_SEND_STATUS;
2461
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302462 if (username_identity) {
2463 val = get_param(cmd, "username");
2464 if (val) {
2465 if (set_network_quoted(ifname, id, "identity", val) < 0)
2466 return -2;
2467 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002468
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302469 val = get_param(cmd, "password");
2470 if (val) {
2471 if (set_network_quoted(ifname, id, "password", val) < 0)
2472 return -2;
2473 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002474 }
2475
Jouni Malinen8179fee2019-03-28 03:19:47 +02002476 if (dut->akm_values &
2477 ((1 << AKM_FILS_SHA256) |
2478 (1 << AKM_FILS_SHA384) |
2479 (1 << AKM_FT_FILS_SHA256) |
2480 (1 << AKM_FT_FILS_SHA384)))
2481 erp = 1;
2482 if (erp && set_network(ifname, id, "erp", "1") < 0)
2483 return ERROR_SEND_STATUS;
2484
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002485 dut->sta_associate_wait_connect = 1;
2486
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002487 return id;
2488}
2489
2490
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002491static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2492{
2493 const char *val;
2494
2495 if (!cipher)
2496 return 0;
2497
2498 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2499 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2500 else if (strcasecmp(cipher,
2501 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2502 val = "ECDHE-RSA-AES256-GCM-SHA384";
2503 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2504 val = "DHE-RSA-AES256-GCM-SHA384";
2505 else if (strcasecmp(cipher,
2506 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2507 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2508 else
2509 return -1;
2510
2511 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2512 set_network_quoted(ifname, id, "phase1", "");
2513
2514 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2515}
2516
2517
Jouni Malinenf7222712019-06-13 01:50:21 +03002518static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2519 struct sigma_conn *conn,
2520 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002521{
2522 const char *intf = get_param(cmd, "Interface");
2523 const char *ifname, *val;
2524 int id;
2525 char buf[200];
2526#ifdef ANDROID
2527 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2528 int length;
2529 int jb_or_newer = 0;
2530 char prop[PROPERTY_VALUE_MAX];
2531#endif /* ANDROID */
2532
2533 if (intf == NULL)
2534 return -1;
2535
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002536 if (strcmp(intf, get_main_ifname(dut)) == 0)
2537 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002538 else
2539 ifname = intf;
2540
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302541 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002542 if (id < 0)
2543 return id;
2544
2545 if (set_network(ifname, id, "eap", "TLS") < 0)
2546 return -2;
2547
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302548 if (!get_param(cmd, "username") &&
2549 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002550 "wifi-user@wifilabs.local") < 0)
2551 return -2;
2552
2553 val = get_param(cmd, "clientCertificate");
2554 if (val == NULL)
2555 return -1;
2556#ifdef ANDROID
2557 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2558 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2559 if (length < 0) {
2560 /*
2561 * JB started reporting keystore type mismatches, so retry with
2562 * the GET_PUBKEY command if the generic GET fails.
2563 */
2564 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2565 buf, kvalue);
2566 }
2567
2568 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2569 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2570 if (strncmp(prop, "4.0", 3) != 0)
2571 jb_or_newer = 1;
2572 } else
2573 jb_or_newer = 1; /* assume newer */
2574
2575 if (jb_or_newer && length > 0) {
2576 sigma_dut_print(dut, DUT_MSG_INFO,
2577 "Use Android keystore [%s]", buf);
2578 if (set_network(ifname, id, "engine", "1") < 0)
2579 return -2;
2580 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2581 return -2;
2582 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2583 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2584 return -2;
2585 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2586 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2587 return -2;
2588 return 1;
2589 } else if (length > 0) {
2590 sigma_dut_print(dut, DUT_MSG_INFO,
2591 "Use Android keystore [%s]", buf);
2592 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2593 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2594 return -2;
2595 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2596 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2597 return -2;
2598 return 1;
2599 }
2600#endif /* ANDROID */
2601
2602 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2603#ifdef __linux__
2604 if (!file_exists(buf)) {
2605 char msg[300];
2606 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2607 "(%s) not found", buf);
2608 send_resp(dut, conn, SIGMA_ERROR, msg);
2609 return -3;
2610 }
2611#endif /* __linux__ */
2612 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2613 return -2;
2614 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2615 return -2;
2616
2617 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2618 return -2;
2619
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002620 val = get_param(cmd, "keyMgmtType");
2621 if (val && strcasecmp(val, "SuiteB") == 0) {
2622 val = get_param(cmd, "CertType");
2623 if (val && strcasecmp(val, "RSA") == 0) {
2624 if (set_network_quoted(ifname, id, "phase1",
2625 "tls_suiteb=1") < 0)
2626 return -2;
2627 } else {
2628 if (set_network_quoted(ifname, id, "openssl_ciphers",
2629 "SUITEB192") < 0)
2630 return -2;
2631 }
2632
2633 val = get_param(cmd, "TLSCipher");
2634 if (set_tls_cipher(ifname, id, val) < 0) {
2635 send_resp(dut, conn, SIGMA_ERROR,
2636 "ErrorCode,Unsupported TLSCipher value");
2637 return -3;
2638 }
2639 }
2640
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002641 return 1;
2642}
2643
2644
Jouni Malinenf7222712019-06-13 01:50:21 +03002645static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2646 struct sigma_conn *conn,
2647 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002648{
2649 const char *intf = get_param(cmd, "Interface");
2650 const char *ifname;
2651 int id;
2652
2653 if (intf == NULL)
2654 return -1;
2655
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002656 if (strcmp(intf, get_main_ifname(dut)) == 0)
2657 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002658 else
2659 ifname = intf;
2660
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302661 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002662 if (id < 0)
2663 return id;
2664
2665 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2666 send_resp(dut, conn, SIGMA_ERROR,
2667 "errorCode,Failed to set TTLS method");
2668 return 0;
2669 }
2670
2671 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2672 send_resp(dut, conn, SIGMA_ERROR,
2673 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2674 return 0;
2675 }
2676
2677 return 1;
2678}
2679
2680
Jouni Malinenf7222712019-06-13 01:50:21 +03002681static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2682 struct sigma_conn *conn,
2683 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002684{
2685 const char *intf = get_param(cmd, "Interface");
2686 const char *ifname;
2687 int id;
2688
2689 if (intf == NULL)
2690 return -1;
2691
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002692 if (strcmp(intf, get_main_ifname(dut)) == 0)
2693 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002694 else
2695 ifname = intf;
2696
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302697 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002698 if (id < 0)
2699 return id;
2700
2701 if (set_network(ifname, id, "eap", "SIM") < 0)
2702 return -2;
2703
2704 return 1;
2705}
2706
2707
Jouni Malinenf7222712019-06-13 01:50:21 +03002708static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2709 struct sigma_conn *conn,
2710 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002711{
2712 const char *intf = get_param(cmd, "Interface");
2713 const char *ifname, *val;
2714 int id;
2715 char buf[100];
2716
2717 if (intf == NULL)
2718 return -1;
2719
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002720 if (strcmp(intf, get_main_ifname(dut)) == 0)
2721 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002722 else
2723 ifname = intf;
2724
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302725 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002726 if (id < 0)
2727 return id;
2728
2729 if (set_network(ifname, id, "eap", "PEAP") < 0)
2730 return -2;
2731
2732 val = get_param(cmd, "innerEAP");
2733 if (val) {
2734 if (strcasecmp(val, "MSCHAPv2") == 0) {
2735 if (set_network_quoted(ifname, id, "phase2",
2736 "auth=MSCHAPV2") < 0)
2737 return -2;
2738 } else if (strcasecmp(val, "GTC") == 0) {
2739 if (set_network_quoted(ifname, id, "phase2",
2740 "auth=GTC") < 0)
2741 return -2;
2742 } else
2743 return -1;
2744 }
2745
2746 val = get_param(cmd, "peapVersion");
2747 if (val) {
2748 int ver = atoi(val);
2749 if (ver < 0 || ver > 1)
2750 return -1;
2751 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2752 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2753 return -2;
2754 }
2755
2756 return 1;
2757}
2758
2759
Jouni Malinenf7222712019-06-13 01:50:21 +03002760static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2761 struct sigma_conn *conn,
2762 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002763{
2764 const char *intf = get_param(cmd, "Interface");
2765 const char *ifname, *val;
2766 int id;
2767 char buf[100];
2768
2769 if (intf == NULL)
2770 return -1;
2771
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002772 if (strcmp(intf, get_main_ifname(dut)) == 0)
2773 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002774 else
2775 ifname = intf;
2776
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302777 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002778 if (id < 0)
2779 return id;
2780
2781 if (set_network(ifname, id, "eap", "FAST") < 0)
2782 return -2;
2783
2784 val = get_param(cmd, "innerEAP");
2785 if (val) {
2786 if (strcasecmp(val, "MSCHAPV2") == 0) {
2787 if (set_network_quoted(ifname, id, "phase2",
2788 "auth=MSCHAPV2") < 0)
2789 return -2;
2790 } else if (strcasecmp(val, "GTC") == 0) {
2791 if (set_network_quoted(ifname, id, "phase2",
2792 "auth=GTC") < 0)
2793 return -2;
2794 } else
2795 return -1;
2796 }
2797
2798 val = get_param(cmd, "validateServer");
2799 if (val) {
2800 /* TODO */
2801 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2802 "validateServer=%s", val);
2803 }
2804
2805 val = get_param(cmd, "pacFile");
2806 if (val) {
2807 snprintf(buf, sizeof(buf), "blob://%s", val);
2808 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2809 return -2;
2810 }
2811
2812 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2813 0)
2814 return -2;
2815
2816 return 1;
2817}
2818
2819
Jouni Malinenf7222712019-06-13 01:50:21 +03002820static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2821 struct sigma_conn *conn,
2822 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002823{
2824 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302825 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002826 const char *ifname;
2827 int id;
2828
2829 if (intf == NULL)
2830 return -1;
2831
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002832 if (strcmp(intf, get_main_ifname(dut)) == 0)
2833 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834 else
2835 ifname = intf;
2836
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302837 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002838 if (id < 0)
2839 return id;
2840
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302841 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2842 * hexadecimal).
2843 */
2844 if (username && username[0] == '6') {
2845 if (set_network(ifname, id, "eap", "AKA'") < 0)
2846 return -2;
2847 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002848 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302849 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002850
2851 return 1;
2852}
2853
2854
Jouni Malinenf7222712019-06-13 01:50:21 +03002855static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2856 struct sigma_conn *conn,
2857 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002858{
2859 const char *intf = get_param(cmd, "Interface");
2860 const char *ifname;
2861 int id;
2862
2863 if (intf == NULL)
2864 return -1;
2865
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002866 if (strcmp(intf, get_main_ifname(dut)) == 0)
2867 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002868 else
2869 ifname = intf;
2870
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302871 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002872 if (id < 0)
2873 return id;
2874
2875 if (set_network(ifname, id, "eap", "AKA'") < 0)
2876 return -2;
2877
2878 return 1;
2879}
2880
2881
2882static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2883 struct sigma_cmd *cmd)
2884{
2885 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002886 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002887 const char *ifname;
2888 int id;
2889
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002890 if (strcmp(intf, get_main_ifname(dut)) == 0)
2891 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002892 else
2893 ifname = intf;
2894
2895 id = add_network_common(dut, conn, ifname, cmd);
2896 if (id < 0)
2897 return id;
2898
2899 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2900 return -2;
2901
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002902 if (dut->program == PROGRAM_60GHZ && network_mode &&
2903 strcasecmp(network_mode, "PBSS") == 0 &&
2904 set_network(ifname, id, "pbss", "1") < 0)
2905 return -2;
2906
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002907 return 1;
2908}
2909
2910
Jouni Malinen47dcc952017-10-09 16:43:24 +03002911static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2912 struct sigma_cmd *cmd)
2913{
2914 const char *intf = get_param(cmd, "Interface");
2915 const char *ifname, *val;
2916 int id;
2917
2918 if (intf == NULL)
2919 return -1;
2920
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002921 if (strcmp(intf, get_main_ifname(dut)) == 0)
2922 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002923 else
2924 ifname = intf;
2925
2926 id = set_wpa_common(dut, conn, ifname, cmd);
2927 if (id < 0)
2928 return id;
2929
2930 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2931 return -2;
2932
2933 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002934 if (val && strcmp(val, "0") == 0) {
2935 if (wpa_command(ifname,
2936 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2937 sigma_dut_print(dut, DUT_MSG_ERROR,
2938 "Failed to set OWE DH Param element override");
2939 return -2;
2940 }
Hu Wang6010ce72020-03-05 19:33:53 +08002941 } else if (val &&
2942 (set_network(ifname, id, "owe_group", val) < 0 ||
2943 (dut->owe_ptk_workaround &&
2944 set_network(ifname, id, "owe_ptk_workaround", "1") < 0))) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002945 sigma_dut_print(dut, DUT_MSG_ERROR,
Hu Wang6010ce72020-03-05 19:33:53 +08002946 "Failed to set owe_group");
Jouni Malinen47dcc952017-10-09 16:43:24 +03002947 return -2;
2948 }
2949
2950 return 1;
2951}
2952
2953
Jouni Malinenf7222712019-06-13 01:50:21 +03002954static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
2955 struct sigma_conn *conn,
2956 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002957{
2958 const char *type = get_param(cmd, "Type");
2959
2960 if (type == NULL) {
2961 send_resp(dut, conn, SIGMA_ERROR,
2962 "ErrorCode,Missing Type argument");
2963 return 0;
2964 }
2965
2966 if (strcasecmp(type, "OPEN") == 0)
2967 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002968 if (strcasecmp(type, "OWE") == 0)
2969 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002970 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002971 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002972 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002973 return cmd_sta_set_psk(dut, conn, cmd);
2974 if (strcasecmp(type, "EAPTLS") == 0)
2975 return cmd_sta_set_eaptls(dut, conn, cmd);
2976 if (strcasecmp(type, "EAPTTLS") == 0)
2977 return cmd_sta_set_eapttls(dut, conn, cmd);
2978 if (strcasecmp(type, "EAPPEAP") == 0)
2979 return cmd_sta_set_peap(dut, conn, cmd);
2980 if (strcasecmp(type, "EAPSIM") == 0)
2981 return cmd_sta_set_eapsim(dut, conn, cmd);
2982 if (strcasecmp(type, "EAPFAST") == 0)
2983 return cmd_sta_set_eapfast(dut, conn, cmd);
2984 if (strcasecmp(type, "EAPAKA") == 0)
2985 return cmd_sta_set_eapaka(dut, conn, cmd);
2986 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2987 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002988 if (strcasecmp(type, "wep") == 0)
2989 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002990
2991 send_resp(dut, conn, SIGMA_ERROR,
2992 "ErrorCode,Unsupported Type value");
2993 return 0;
2994}
2995
2996
2997int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2998{
2999#ifdef __linux__
3000 /* special handling for ath6kl */
3001 char path[128], fname[128], *pos;
3002 ssize_t res;
3003 FILE *f;
3004
Jouni Malinene39cd562019-05-29 23:39:56 +03003005 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
3006 intf);
3007 if (res < 0 || res >= sizeof(fname))
3008 return 0;
3009 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003010 if (res < 0)
3011 return 0; /* not ath6kl */
3012
3013 if (res >= (int) sizeof(path))
3014 res = sizeof(path) - 1;
3015 path[res] = '\0';
3016 pos = strrchr(path, '/');
3017 if (pos == NULL)
3018 pos = path;
3019 else
3020 pos++;
Jouni Malinen77dda642020-01-07 11:21:55 +02003021 res = snprintf(fname, sizeof(fname),
3022 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3023 "create_qos", pos);
3024 if (res < 0 || res >= sizeof(fname) || !file_exists(fname))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003025 return 0; /* not ath6kl */
3026
3027 if (uapsd) {
3028 f = fopen(fname, "w");
3029 if (f == NULL)
3030 return -1;
3031
3032 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
3033 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
3034 "45000 200 56789000 56789000 5678900 0 0 9999999 "
3035 "20000 0\n");
3036 fclose(f);
3037 } else {
Jouni Malinen77dda642020-01-07 11:21:55 +02003038 res = snprintf(fname, sizeof(fname),
3039 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
3040 "delete_qos", pos);
3041 if (res < 0 || res >= sizeof(fname))
3042 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003043
3044 f = fopen(fname, "w");
3045 if (f == NULL)
3046 return -1;
3047
3048 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
3049 fprintf(f, "2 4\n");
3050 fclose(f);
3051 }
3052#endif /* __linux__ */
3053
3054 return 0;
3055}
3056
3057
Jouni Malinenf7222712019-06-13 01:50:21 +03003058static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
3059 struct sigma_conn *conn,
3060 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003061{
3062 const char *intf = get_param(cmd, "Interface");
3063 /* const char *ssid = get_param(cmd, "ssid"); */
3064 const char *val;
3065 int max_sp_len = 4;
3066 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
3067 char buf[100];
3068 int ret1, ret2;
3069
3070 val = get_param(cmd, "maxSPLength");
3071 if (val) {
3072 max_sp_len = atoi(val);
3073 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
3074 max_sp_len != 4)
3075 return -1;
3076 }
3077
3078 val = get_param(cmd, "acBE");
3079 if (val)
3080 ac_be = atoi(val);
3081
3082 val = get_param(cmd, "acBK");
3083 if (val)
3084 ac_bk = atoi(val);
3085
3086 val = get_param(cmd, "acVI");
3087 if (val)
3088 ac_vi = atoi(val);
3089
3090 val = get_param(cmd, "acVO");
3091 if (val)
3092 ac_vo = atoi(val);
3093
3094 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3095
3096 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3097 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3098 ret1 = wpa_command(intf, buf);
3099
3100 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3101 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3102 ret2 = wpa_command(intf, buf);
3103
3104 if (ret1 && ret2) {
3105 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3106 "UAPSD parameters.");
3107 return -2;
3108 }
3109
3110 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3111 send_resp(dut, conn, SIGMA_ERROR,
3112 "ErrorCode,Failed to set ath6kl QoS parameters");
3113 return 0;
3114 }
3115
3116 return 1;
3117}
3118
3119
Jouni Malinenf7222712019-06-13 01:50:21 +03003120static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3121 struct sigma_conn *conn,
3122 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003123{
3124 char buf[1000];
3125 const char *intf = get_param(cmd, "Interface");
3126 const char *grp = get_param(cmd, "Group");
3127 const char *act = get_param(cmd, "Action");
3128 const char *tid = get_param(cmd, "Tid");
3129 const char *dir = get_param(cmd, "Direction");
3130 const char *psb = get_param(cmd, "Psb");
3131 const char *up = get_param(cmd, "Up");
3132 const char *fixed = get_param(cmd, "Fixed");
3133 const char *size = get_param(cmd, "Size");
3134 const char *msize = get_param(cmd, "Maxsize");
3135 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3136 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3137 const char *inact = get_param(cmd, "Inactivity");
3138 const char *sus = get_param(cmd, "Suspension");
3139 const char *mindr = get_param(cmd, "Mindatarate");
3140 const char *meandr = get_param(cmd, "Meandatarate");
3141 const char *peakdr = get_param(cmd, "Peakdatarate");
3142 const char *phyrate = get_param(cmd, "Phyrate");
3143 const char *burstsize = get_param(cmd, "Burstsize");
3144 const char *sba = get_param(cmd, "Sba");
3145 int direction;
3146 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003147 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003148 int fixed_int;
3149 int psb_ts;
3150
3151 if (intf == NULL || grp == NULL || act == NULL )
3152 return -1;
3153
3154 if (strcasecmp(act, "addts") == 0) {
3155 if (tid == NULL || dir == NULL || psb == NULL ||
3156 up == NULL || fixed == NULL || size == NULL)
3157 return -1;
3158
3159 /*
3160 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3161 * possible values, but WMM-AC and V-E test scripts use "UP,
3162 * "DOWN", and "BIDI".
3163 */
3164 if (strcasecmp(dir, "uplink") == 0 ||
3165 strcasecmp(dir, "up") == 0) {
3166 direction = 0;
3167 } else if (strcasecmp(dir, "downlink") == 0 ||
3168 strcasecmp(dir, "down") == 0) {
3169 direction = 1;
3170 } else if (strcasecmp(dir, "bidi") == 0) {
3171 direction = 2;
3172 } else {
3173 sigma_dut_print(dut, DUT_MSG_ERROR,
3174 "Direction %s not supported", dir);
3175 return -1;
3176 }
3177
3178 if (strcasecmp(psb, "legacy") == 0) {
3179 psb_ts = 0;
3180 } else if (strcasecmp(psb, "uapsd") == 0) {
3181 psb_ts = 1;
3182 } else {
3183 sigma_dut_print(dut, DUT_MSG_ERROR,
3184 "PSB %s not supported", psb);
3185 return -1;
3186 }
3187
3188 if (atoi(tid) < 0 || atoi(tid) > 7) {
3189 sigma_dut_print(dut, DUT_MSG_ERROR,
3190 "TID %s not supported", tid);
3191 return -1;
3192 }
3193
3194 if (strcasecmp(fixed, "true") == 0) {
3195 fixed_int = 1;
3196 } else {
3197 fixed_int = 0;
3198 }
3199
Peng Xu93319622017-10-04 17:58:16 -07003200 if (sba)
3201 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003202
3203 dut->dialog_token++;
3204 handle = 7000 + dut->dialog_token;
3205
3206 /*
3207 * size: convert to hex
3208 * maxsi: convert to hex
3209 * mindr: convert to hex
3210 * meandr: convert to hex
3211 * peakdr: convert to hex
3212 * burstsize: convert to hex
3213 * phyrate: convert to hex
3214 * sba: convert to hex with modification
3215 * minsi: convert to integer
3216 * sus: convert to integer
3217 * inact: convert to integer
3218 * maxsi: convert to integer
3219 */
3220
3221 /*
3222 * The Nominal MSDU Size field is 2 octets long and contains an
3223 * unsigned integer that specifies the nominal size, in octets,
3224 * of MSDUs belonging to the traffic under this traffic
3225 * specification and is defined in Figure 16. If the Fixed
3226 * subfield is set to 1, then the size of the MSDU is fixed and
3227 * is indicated by the Size Subfield. If the Fixed subfield is
3228 * set to 0, then the size of the MSDU might not be fixed and
3229 * the Size indicates the nominal MSDU size.
3230 *
3231 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3232 * and specifies the excess allocation of time (and bandwidth)
3233 * over and above the stated rates required to transport an MSDU
3234 * belonging to the traffic in this TSPEC. This field is
3235 * represented as an unsigned binary number with an implicit
3236 * binary point after the leftmost 3 bits. For example, an SBA
3237 * of 1.75 is represented as 0x3800. This field is included to
3238 * account for retransmissions. As such, the value of this field
3239 * must be greater than unity.
3240 */
3241
3242 snprintf(buf, sizeof(buf),
3243 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3244 " 0x%X 0x%X 0x%X"
3245 " 0x%X 0x%X 0x%X"
3246 " 0x%X %d %d %d %d"
3247 " %d %d",
3248 intf, handle, tid, direction, psb_ts, up,
3249 (unsigned int) ((fixed_int << 15) | atoi(size)),
3250 msize ? atoi(msize) : 0,
3251 mindr ? atoi(mindr) : 0,
3252 meandr ? atoi(meandr) : 0,
3253 peakdr ? atoi(peakdr) : 0,
3254 burstsize ? atoi(burstsize) : 0,
3255 phyrate ? atoi(phyrate) : 0,
3256 sba ? ((unsigned int) (((int) sba_fv << 13) |
3257 (int)((sba_fv - (int) sba_fv) *
3258 8192))) : 0,
3259 minsi ? atoi(minsi) : 0,
3260 sus ? atoi(sus) : 0,
3261 0, 0,
3262 inact ? atoi(inact) : 0,
3263 maxsi ? atoi(maxsi) : 0);
3264
3265 if (system(buf) != 0) {
3266 sigma_dut_print(dut, DUT_MSG_ERROR,
3267 "iwpriv addtspec request failed");
3268 send_resp(dut, conn, SIGMA_ERROR,
3269 "errorCode,Failed to execute addTspec command");
3270 return 0;
3271 }
3272
3273 sigma_dut_print(dut, DUT_MSG_INFO,
3274 "iwpriv addtspec request send");
3275
3276 /* Mapping handle to a TID */
3277 dut->tid_to_handle[atoi(tid)] = handle;
3278 } else if (strcasecmp(act, "delts") == 0) {
3279 if (tid == NULL)
3280 return -1;
3281
3282 if (atoi(tid) < 0 || atoi(tid) > 7) {
3283 sigma_dut_print(dut, DUT_MSG_ERROR,
3284 "TID %s not supported", tid);
3285 send_resp(dut, conn, SIGMA_ERROR,
3286 "errorCode,Unsupported TID");
3287 return 0;
3288 }
3289
3290 handle = dut->tid_to_handle[atoi(tid)];
3291
3292 if (handle < 7000 || handle > 7255) {
3293 /* Invalid handle ie no mapping for that TID */
3294 sigma_dut_print(dut, DUT_MSG_ERROR,
3295 "handle-> %d not found", handle);
3296 }
3297
3298 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3299 intf, handle);
3300
3301 if (system(buf) != 0) {
3302 sigma_dut_print(dut, DUT_MSG_ERROR,
3303 "iwpriv deltspec request failed");
3304 send_resp(dut, conn, SIGMA_ERROR,
3305 "errorCode,Failed to execute delTspec command");
3306 return 0;
3307 }
3308
3309 sigma_dut_print(dut, DUT_MSG_INFO,
3310 "iwpriv deltspec request send");
3311
3312 dut->tid_to_handle[atoi(tid)] = 0;
3313 } else {
3314 sigma_dut_print(dut, DUT_MSG_ERROR,
3315 "Action type %s not supported", act);
3316 send_resp(dut, conn, SIGMA_ERROR,
3317 "errorCode,Unsupported Action");
3318 return 0;
3319 }
3320
3321 return 1;
3322}
3323
3324
vamsi krishna52e16f92017-08-29 12:37:34 +05303325static int find_network(struct sigma_dut *dut, const char *ssid)
3326{
3327 char list[4096];
3328 char *pos;
3329
3330 sigma_dut_print(dut, DUT_MSG_DEBUG,
3331 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003332 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303333 list, sizeof(list)) < 0)
3334 return -1;
3335 pos = strstr(list, ssid);
3336 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3337 return -1;
3338
3339 while (pos > list && pos[-1] != '\n')
3340 pos--;
3341 dut->infra_network_id = atoi(pos);
3342 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3343 return 0;
3344}
3345
3346
Sunil Dutt44595082018-02-12 19:41:45 +05303347#ifdef NL80211_SUPPORT
3348static int sta_config_rsnie(struct sigma_dut *dut, int val)
3349{
3350 struct nl_msg *msg;
3351 int ret;
3352 struct nlattr *params;
3353 int ifindex;
3354
3355 ifindex = if_nametoindex("wlan0");
3356 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3357 NL80211_CMD_VENDOR)) ||
3358 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3359 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3360 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3361 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3362 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3363 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3364 sigma_dut_print(dut, DUT_MSG_ERROR,
3365 "%s: err in adding vendor_cmd and vendor_data",
3366 __func__);
3367 nlmsg_free(msg);
3368 return -1;
3369 }
3370 nla_nest_end(msg, params);
3371
3372 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3373 if (ret) {
3374 sigma_dut_print(dut, DUT_MSG_ERROR,
3375 "%s: err in send_and_recv_msgs, ret=%d",
3376 __func__, ret);
3377 return ret;
3378 }
3379
3380 return 0;
3381}
3382#endif /* NL80211_SUPPORT */
3383
3384
Jouni Malinenf7222712019-06-13 01:50:21 +03003385static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3386 struct sigma_conn *conn,
3387 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003388{
3389 /* const char *intf = get_param(cmd, "Interface"); */
3390 const char *ssid = get_param(cmd, "ssid");
3391 const char *wps_param = get_param(cmd, "WPS");
3392 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003393 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003394 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003395 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003396 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003397 int e;
3398 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3399 struct wpa_ctrl *ctrl = NULL;
3400 int num_network_not_found = 0;
3401 int num_disconnected = 0;
3402 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003403
3404 if (ssid == NULL)
3405 return -1;
3406
Jouni Malinen37d5c692019-08-19 16:56:55 +03003407 dut->server_cert_tod = 0;
3408
Jouni Malinen3c367e82017-06-23 17:01:47 +03003409 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303410#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003411 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303412 sta_config_rsnie(dut, 1);
3413 dut->config_rsnie = 1;
3414 }
3415#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003416 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3417 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003418 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003419 send_resp(dut, conn, SIGMA_ERROR,
3420 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3421 return 0;
3422 }
3423 }
3424
Jouni Malinen68143132017-09-02 02:34:08 +03003425 if (dut->sae_commit_override) {
3426 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3427 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003428 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003429 send_resp(dut, conn, SIGMA_ERROR,
3430 "ErrorCode,Failed to set SAE commit override");
3431 return 0;
3432 }
3433 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303434#ifdef ANDROID
3435 if (dut->fils_hlp)
3436 process_fils_hlp(dut);
3437#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003438
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003439 if (wps_param &&
3440 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3441 wps = 1;
3442
3443 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003444 if (dut->program == PROGRAM_60GHZ && network_mode &&
3445 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003446 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003447 "pbss", "1") < 0)
3448 return -2;
3449
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003450 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3451 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3452 "parameters not yet set");
3453 return 0;
3454 }
3455 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003456 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003457 return -2;
3458 } else {
3459 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3460 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003461 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003462 return -2;
3463 }
3464 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303465 if (strcmp(ssid, dut->infra_ssid) == 0) {
3466 sigma_dut_print(dut, DUT_MSG_DEBUG,
3467 "sta_associate for the most recently added network");
3468 } else if (find_network(dut, ssid) < 0) {
3469 sigma_dut_print(dut, DUT_MSG_DEBUG,
3470 "sta_associate for a previously stored network profile");
3471 send_resp(dut, conn, SIGMA_ERROR,
3472 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003473 return 0;
3474 }
3475
3476 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003477 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003478 "bssid", bssid) < 0) {
3479 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3480 "Invalid bssid argument");
3481 return 0;
3482 }
3483
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003484 if (dut->program == PROGRAM_WPA3 &&
3485 dut->sta_associate_wait_connect) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003486 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003487 if (!ctrl)
3488 return ERROR_SEND_STATUS;
3489 }
3490
Jouni Malinen46a19b62017-06-23 14:31:27 +03003491 extra[0] = '\0';
3492 if (chan)
3493 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003494 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003495 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3496 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003497 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003498 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3499 "network id %d on %s",
3500 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003501 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003502 ret = ERROR_SEND_STATUS;
3503 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003504 }
3505 }
3506
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003507 if (!ctrl)
3508 return SUCCESS_SEND_STATUS;
3509
3510 /* Wait for connection result to be able to store server certificate
3511 * hash for trust root override testing
3512 * (dev_exec_action,ServerCertTrust). */
3513
3514 for (e = 0; e < 20; e++) {
3515 const char *events[] = {
3516 "CTRL-EVENT-EAP-PEER-CERT",
3517 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3518 "CTRL-EVENT-DISCONNECTED",
3519 "CTRL-EVENT-CONNECTED",
3520 "CTRL-EVENT-NETWORK-NOT-FOUND",
3521 NULL
3522 };
3523 char buf[1024];
3524 int res;
3525
3526 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3527 if (res < 0) {
Jouni Malinenf1f16642019-11-15 21:19:04 +02003528 send_resp(dut, conn, SIGMA_COMPLETE,
3529 "Result,Association did not complete");
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003530 ret = STATUS_SENT_ERROR;
3531 break;
3532 }
3533 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3534 buf);
3535
3536 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3537 strstr(buf, " depth=0")) {
3538 char *pos = strstr(buf, " hash=");
3539
3540 if (pos) {
3541 char *end;
3542
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003543 if (strstr(buf, " tod=1"))
3544 tod = 1;
3545 else if (strstr(buf, " tod=2"))
3546 tod = 2;
3547 else
3548 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003549 sigma_dut_print(dut, DUT_MSG_DEBUG,
3550 "Server certificate TOD policy: %d",
3551 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003552 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003553
3554 pos += 6;
3555 end = strchr(pos, ' ');
3556 if (end)
3557 *end = '\0';
3558 strlcpy(dut->server_cert_hash, pos,
3559 sizeof(dut->server_cert_hash));
3560 sigma_dut_print(dut, DUT_MSG_DEBUG,
3561 "Server certificate hash: %s",
3562 dut->server_cert_hash);
3563 }
3564 }
3565
3566 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3567 send_resp(dut, conn, SIGMA_COMPLETE,
3568 "Result,TLS server certificate validation failed");
3569 ret = STATUS_SENT_ERROR;
3570 break;
3571 }
3572
3573 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3574 num_network_not_found++;
3575
3576 if (num_network_not_found > 2) {
3577 send_resp(dut, conn, SIGMA_COMPLETE,
3578 "Result,Network not found");
3579 ret = STATUS_SENT_ERROR;
3580 break;
3581 }
3582 }
3583
3584 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3585 num_disconnected++;
3586
3587 if (num_disconnected > 2) {
3588 send_resp(dut, conn, SIGMA_COMPLETE,
3589 "Result,Connection failed");
3590 ret = STATUS_SENT_ERROR;
3591 break;
3592 }
3593 }
3594
3595 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3596 if (tod >= 0) {
3597 sigma_dut_print(dut, DUT_MSG_DEBUG,
3598 "Network profile TOD policy update: %d -> %d",
3599 dut->sta_tod_policy, tod);
3600 dut->sta_tod_policy = tod;
3601 }
3602 break;
3603 }
3604 }
3605done:
3606 if (ctrl) {
3607 wpa_ctrl_detach(ctrl);
3608 wpa_ctrl_close(ctrl);
3609 }
3610 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003611}
3612
3613
3614static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3615{
3616 char buf[500], cmd[200];
3617 int res;
3618
3619 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3620 * default path */
3621 res = snprintf(cmd, sizeof(cmd),
3622 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3623 file_exists("./hs20-osu-client") ?
3624 "./hs20-osu-client" : "hs20-osu-client",
3625 sigma_wpas_ctrl,
3626 dut->summary_log ? "-s " : "",
3627 dut->summary_log ? dut->summary_log : "");
3628 if (res < 0 || res >= (int) sizeof(cmd))
3629 return -1;
3630
3631 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3632 if (res < 0 || res >= (int) sizeof(buf))
3633 return -1;
3634 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3635
3636 if (system(buf) != 0) {
3637 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3638 return -1;
3639 }
3640 sigma_dut_print(dut, DUT_MSG_DEBUG,
3641 "Completed hs20-osu-client operation");
3642
3643 return 0;
3644}
3645
3646
3647static int download_ppsmo(struct sigma_dut *dut,
3648 struct sigma_conn *conn,
3649 const char *intf,
3650 struct sigma_cmd *cmd)
3651{
3652 const char *name, *path, *val;
3653 char url[500], buf[600], fbuf[100];
3654 char *fqdn = NULL;
3655
3656 name = get_param(cmd, "FileName");
3657 path = get_param(cmd, "FilePath");
3658 if (name == NULL || path == NULL)
3659 return -1;
3660
3661 if (strcasecmp(path, "VendorSpecific") == 0) {
3662 snprintf(url, sizeof(url), "PPS/%s", name);
3663 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3664 "from the device (%s)", url);
3665 if (!file_exists(url)) {
3666 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3667 "PPS MO file does not exist");
3668 return 0;
3669 }
3670 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3671 if (system(buf) != 0) {
3672 send_resp(dut, conn, SIGMA_ERROR,
3673 "errorCode,Failed to copy PPS MO");
3674 return 0;
3675 }
3676 } else if (strncasecmp(path, "http:", 5) != 0 &&
3677 strncasecmp(path, "https:", 6) != 0) {
3678 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3679 "Unsupported FilePath value");
3680 return 0;
3681 } else {
3682 snprintf(url, sizeof(url), "%s/%s", path, name);
3683 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3684 url);
3685 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3686 remove("pps-tnds.xml");
3687 if (system(buf) != 0) {
3688 send_resp(dut, conn, SIGMA_ERROR,
3689 "errorCode,Failed to download PPS MO");
3690 return 0;
3691 }
3692 }
3693
3694 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3695 send_resp(dut, conn, SIGMA_ERROR,
3696 "errorCode,Failed to parse downloaded PPSMO");
3697 return 0;
3698 }
3699 unlink("pps-tnds.xml");
3700
3701 val = get_param(cmd, "managementTreeURI");
3702 if (val) {
3703 const char *pos, *end;
3704 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3705 val);
3706 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3707 send_resp(dut, conn, SIGMA_ERROR,
3708 "errorCode,Invalid managementTreeURI prefix");
3709 return 0;
3710 }
3711 pos = val + 8;
3712 end = strchr(pos, '/');
3713 if (end == NULL ||
3714 strcmp(end, "/PerProviderSubscription") != 0) {
3715 send_resp(dut, conn, SIGMA_ERROR,
3716 "errorCode,Invalid managementTreeURI postfix");
3717 return 0;
3718 }
3719 if (end - pos >= (int) sizeof(fbuf)) {
3720 send_resp(dut, conn, SIGMA_ERROR,
3721 "errorCode,Too long FQDN in managementTreeURI");
3722 return 0;
3723 }
3724 memcpy(fbuf, pos, end - pos);
3725 fbuf[end - pos] = '\0';
3726 fqdn = fbuf;
3727 sigma_dut_print(dut, DUT_MSG_INFO,
3728 "FQDN from managementTreeURI: %s", fqdn);
3729 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3730 FILE *f = fopen("pps-fqdn", "r");
3731 if (f) {
3732 if (fgets(fbuf, sizeof(fbuf), f)) {
3733 fbuf[sizeof(fbuf) - 1] = '\0';
3734 fqdn = fbuf;
3735 sigma_dut_print(dut, DUT_MSG_DEBUG,
3736 "Use FQDN %s", fqdn);
3737 }
3738 fclose(f);
3739 }
3740 }
3741
3742 if (fqdn == NULL) {
3743 send_resp(dut, conn, SIGMA_ERROR,
3744 "errorCode,No FQDN specified");
3745 return 0;
3746 }
3747
3748 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3749 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3750 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3751
3752 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3753 if (rename("pps.xml", buf) < 0) {
3754 send_resp(dut, conn, SIGMA_ERROR,
3755 "errorCode,Could not move PPS MO");
3756 return 0;
3757 }
3758
3759 if (strcasecmp(path, "VendorSpecific") == 0) {
3760 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3761 fqdn);
3762 if (system(buf)) {
3763 send_resp(dut, conn, SIGMA_ERROR,
3764 "errorCode,Failed to copy OSU CA cert");
3765 return 0;
3766 }
3767
3768 snprintf(buf, sizeof(buf),
3769 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3770 fqdn);
3771 if (system(buf)) {
3772 send_resp(dut, conn, SIGMA_ERROR,
3773 "errorCode,Failed to copy AAA CA cert");
3774 return 0;
3775 }
3776 } else {
3777 snprintf(buf, sizeof(buf),
3778 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3779 fqdn, fqdn);
3780 if (run_hs20_osu(dut, buf) < 0) {
3781 send_resp(dut, conn, SIGMA_ERROR,
3782 "errorCode,Failed to download OSU CA cert");
3783 return 0;
3784 }
3785
3786 snprintf(buf, sizeof(buf),
3787 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3788 fqdn, fqdn);
3789 if (run_hs20_osu(dut, buf) < 0) {
3790 sigma_dut_print(dut, DUT_MSG_INFO,
3791 "Failed to download AAA CA cert");
3792 }
3793 }
3794
3795 if (file_exists("next-client-cert.pem")) {
3796 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3797 if (rename("next-client-cert.pem", buf) < 0) {
3798 send_resp(dut, conn, SIGMA_ERROR,
3799 "errorCode,Could not move client certificate");
3800 return 0;
3801 }
3802 }
3803
3804 if (file_exists("next-client-key.pem")) {
3805 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3806 if (rename("next-client-key.pem", buf) < 0) {
3807 send_resp(dut, conn, SIGMA_ERROR,
3808 "errorCode,Could not move client key");
3809 return 0;
3810 }
3811 }
3812
3813 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3814 if (run_hs20_osu(dut, buf) < 0) {
3815 send_resp(dut, conn, SIGMA_ERROR,
3816 "errorCode,Failed to configure credential from "
3817 "PPSMO");
3818 return 0;
3819 }
3820
3821 return 1;
3822}
3823
3824
3825static int download_cert(struct sigma_dut *dut,
3826 struct sigma_conn *conn,
3827 const char *intf,
3828 struct sigma_cmd *cmd)
3829{
3830 const char *name, *path;
3831 char url[500], buf[600];
3832
3833 name = get_param(cmd, "FileName");
3834 path = get_param(cmd, "FilePath");
3835 if (name == NULL || path == NULL)
3836 return -1;
3837
3838 if (strcasecmp(path, "VendorSpecific") == 0) {
3839 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3840 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3841 "certificate from the device (%s)", url);
3842 if (!file_exists(url)) {
3843 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3844 "certificate file does not exist");
3845 return 0;
3846 }
3847 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3848 if (system(buf) != 0) {
3849 send_resp(dut, conn, SIGMA_ERROR,
3850 "errorCode,Failed to copy client "
3851 "certificate");
3852 return 0;
3853 }
3854
3855 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3856 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3857 "private key from the device (%s)", url);
3858 if (!file_exists(url)) {
3859 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3860 "private key file does not exist");
3861 return 0;
3862 }
3863 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3864 if (system(buf) != 0) {
3865 send_resp(dut, conn, SIGMA_ERROR,
3866 "errorCode,Failed to copy client key");
3867 return 0;
3868 }
3869 } else if (strncasecmp(path, "http:", 5) != 0 &&
3870 strncasecmp(path, "https:", 6) != 0) {
3871 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3872 "Unsupported FilePath value");
3873 return 0;
3874 } else {
3875 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3876 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3877 "certificate/key from %s", url);
3878 snprintf(buf, sizeof(buf),
3879 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3880 if (system(buf) != 0) {
3881 send_resp(dut, conn, SIGMA_ERROR,
3882 "errorCode,Failed to download client "
3883 "certificate");
3884 return 0;
3885 }
3886
3887 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3888 {
3889 send_resp(dut, conn, SIGMA_ERROR,
3890 "errorCode,Failed to copy client key");
3891 return 0;
3892 }
3893 }
3894
3895 return 1;
3896}
3897
3898
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003899static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3900 struct sigma_conn *conn,
3901 struct sigma_cmd *cmd)
3902{
3903 const char *val;
3904 const char *intf = get_param(cmd, "interface");
3905
3906 if (!intf)
3907 return -1;
3908
3909 val = get_param(cmd, "WscIEFragment");
3910 if (val && strcasecmp(val, "enable") == 0) {
3911 sigma_dut_print(dut, DUT_MSG_DEBUG,
3912 "Enable WSC IE fragmentation");
3913
3914 dut->wsc_fragment = 1;
3915 /* set long attributes to force fragmentation */
3916 if (wpa_command(intf, "SET device_name "
3917 WPS_LONG_DEVICE_NAME) < 0)
3918 return -2;
3919 if (wpa_command(intf, "SET manufacturer "
3920 WPS_LONG_MANUFACTURER) < 0)
3921 return -2;
3922 if (wpa_command(intf, "SET model_name "
3923 WPS_LONG_MODEL_NAME) < 0)
3924 return -2;
3925 if (wpa_command(intf, "SET model_number "
3926 WPS_LONG_MODEL_NUMBER) < 0)
3927 return -2;
3928 if (wpa_command(intf, "SET serial_number "
3929 WPS_LONG_SERIAL_NUMBER) < 0)
3930 return -2;
3931 }
3932
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003933 val = get_param(cmd, "RSN_IE");
3934 if (val) {
3935 if (strcasecmp(val, "disable") == 0)
3936 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3937 else if (strcasecmp(val, "enable") == 0)
3938 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3939 }
3940
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003941 val = get_param(cmd, "WpsVersion");
3942 if (val)
3943 dut->wps_forced_version = get_wps_forced_version(dut, val);
3944
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003945 val = get_param(cmd, "WscEAPFragment");
3946 if (val && strcasecmp(val, "enable") == 0)
3947 dut->eap_fragment = 1;
3948
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003949 return 1;
3950}
3951
3952
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003953static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3954 struct sigma_conn *conn,
3955 const char *intf,
3956 struct sigma_cmd *cmd)
3957{
3958 const char *val;
3959
3960 val = get_param(cmd, "FileType");
3961 if (val && strcasecmp(val, "PPSMO") == 0)
3962 return download_ppsmo(dut, conn, intf, cmd);
3963 if (val && strcasecmp(val, "CERT") == 0)
3964 return download_cert(dut, conn, intf, cmd);
3965 if (val) {
3966 send_resp(dut, conn, SIGMA_ERROR,
3967 "ErrorCode,Unsupported FileType");
3968 return 0;
3969 }
3970
3971 return 1;
3972}
3973
3974
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303975static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3976 struct sigma_conn *conn,
3977 const char *intf,
3978 struct sigma_cmd *cmd)
3979{
3980 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303981 char buf[1000];
3982 char text[20];
3983 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303984
3985 val = get_param(cmd, "OCESupport");
3986 if (val && strcasecmp(val, "Disable") == 0) {
3987 if (wpa_command(intf, "SET oce 0") < 0) {
3988 send_resp(dut, conn, SIGMA_ERROR,
3989 "ErrorCode,Failed to disable OCE");
3990 return 0;
3991 }
3992 } else if (val && strcasecmp(val, "Enable") == 0) {
3993 if (wpa_command(intf, "SET oce 1") < 0) {
3994 send_resp(dut, conn, SIGMA_ERROR,
3995 "ErrorCode,Failed to enable OCE");
3996 return 0;
3997 }
3998 }
3999
vamsi krishnaa2799492017-12-05 14:28:01 +05304000 val = get_param(cmd, "FILScap");
4001 if (val && (atoi(val) == 1)) {
4002 if (wpa_command(intf, "SET disable_fils 0") < 0) {
4003 send_resp(dut, conn, SIGMA_ERROR,
4004 "ErrorCode,Failed to enable FILS");
4005 return 0;
4006 }
4007 } else if (val && (atoi(val) == 0)) {
4008 if (wpa_command(intf, "SET disable_fils 1") < 0) {
4009 send_resp(dut, conn, SIGMA_ERROR,
4010 "ErrorCode,Failed to disable FILS");
4011 return 0;
4012 }
4013 }
4014
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304015 val = get_param(cmd, "FILSHLP");
4016 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004017 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05304018 sizeof(text)) < 0)
4019 return -2;
4020 hwaddr_aton(text, addr);
4021 snprintf(buf, sizeof(buf),
4022 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
4023 "080045100140000040004011399e00000000ffffffff00440043"
4024 "012cb30001010600fd4f46410000000000000000000000000000"
4025 "000000000000"
4026 "%02x%02x%02x%02x%02x%02x"
4027 "0000000000000000000000000000000000000000000000000000"
4028 "0000000000000000000000000000000000000000000000000000"
4029 "0000000000000000000000000000000000000000000000000000"
4030 "0000000000000000000000000000000000000000000000000000"
4031 "0000000000000000000000000000000000000000000000000000"
4032 "0000000000000000000000000000000000000000000000000000"
4033 "0000000000000000000000000000000000000000000000000000"
4034 "0000000000000000000000000000000000000000638253633501"
4035 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
4036 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
4037 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
4038 if (wpa_command(intf, buf)) {
4039 send_resp(dut, conn, SIGMA_ERROR,
4040 "ErrorCode,Failed to add HLP");
4041 return 0;
4042 }
4043 dut->fils_hlp = 1;
4044 }
4045
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304046 return 1;
4047}
4048
4049
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004050static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
4051 const char *val)
4052{
4053 int counter = 0;
4054 char token[50];
4055 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304056 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004057
Peng Xub8fc5cc2017-05-10 17:27:28 -07004058 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004059 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304060 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004061 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004062 if (strcmp(result, "disable") == 0)
4063 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
4064 else
4065 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304066 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004067 counter++;
4068 }
4069}
4070
4071
4072static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
4073 const char *val)
4074{
4075 char buf[100];
4076
4077 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
4078 if (system(buf) != 0) {
4079 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4080 }
4081}
4082
4083
4084static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4085 const char *val)
4086{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004087 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004088 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004089 }
4090}
4091
4092
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004093static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4094 const char *val)
4095{
4096#ifdef NL80211_SUPPORT
4097 struct nl_msg *msg;
4098 int ret = 0;
4099 struct nlattr *params;
4100 int ifindex;
4101 int wmmenable = 1;
4102
4103 if (val &&
4104 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4105 wmmenable = 0;
4106
4107 ifindex = if_nametoindex(intf);
4108 if (ifindex == 0) {
4109 sigma_dut_print(dut, DUT_MSG_ERROR,
4110 "%s: Index for interface %s failed",
4111 __func__, intf);
4112 return -1;
4113 }
4114
4115 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4116 NL80211_CMD_VENDOR)) ||
4117 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4118 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4119 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4120 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4121 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4122 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4123 wmmenable)) {
4124 sigma_dut_print(dut, DUT_MSG_ERROR,
4125 "%s: err in adding vendor_cmd and vendor_data",
4126 __func__);
4127 nlmsg_free(msg);
4128 return -1;
4129 }
4130 nla_nest_end(msg, params);
4131
4132 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4133 if (ret) {
4134 sigma_dut_print(dut, DUT_MSG_ERROR,
4135 "%s: err in send_and_recv_msgs, ret=%d",
4136 __func__, ret);
4137 }
4138 return ret;
4139#else /* NL80211_SUPPORT */
4140 sigma_dut_print(dut, DUT_MSG_ERROR,
4141 "WMM cannot be changed without NL80211_SUPPORT defined");
4142 return -1;
4143#endif /* NL80211_SUPPORT */
4144}
4145
4146
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004147static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4148 const char *val)
4149{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004150 int sgi20;
4151
4152 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4153
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004154 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004155}
4156
4157
4158static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4159 const char *val)
4160{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304161 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004162
4163 /* Disable Tx Beam forming when using a fixed rate */
4164 ath_disable_txbf(dut, intf);
4165
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304166 v = atoi(val);
4167 if (v < 0 || v > 32) {
4168 sigma_dut_print(dut, DUT_MSG_ERROR,
4169 "Invalid Fixed MCS rate: %d", v);
4170 return;
4171 }
4172 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004173
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004174 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004175
4176 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004177 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004178}
4179
4180
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004181static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4182 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004183{
4184 char buf[60];
4185
4186 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4187 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4188 else
4189 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4190
4191 if (system(buf) != 0)
4192 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4193}
4194
4195
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004196static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4197 int ampdu)
4198{
4199 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004200 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004201
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004202 if (ampdu)
4203 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004204 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4205 if (system(buf) != 0) {
4206 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4207 return -1;
4208 }
4209
4210 return 0;
4211}
4212
4213
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004214static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4215 const char *val)
4216{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004217 run_iwpriv(dut, intf, "tx_stbc %s", val);
4218 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004219}
4220
4221
4222static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4223 const char *val)
4224{
4225 char buf[60];
4226
Peng Xucc317ed2017-05-18 16:44:37 -07004227 if (strcmp(val, "160") == 0) {
4228 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4229 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004230 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4231 } else if (strcmp(val, "40") == 0) {
4232 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4233 } else if (strcmp(val, "20") == 0) {
4234 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4235 } else if (strcasecmp(val, "Auto") == 0) {
4236 buf[0] = '\0';
4237 } else {
4238 sigma_dut_print(dut, DUT_MSG_ERROR,
4239 "WIDTH/CTS_WIDTH value not supported");
4240 return -1;
4241 }
4242
4243 if (buf[0] != '\0' && system(buf) != 0) {
4244 sigma_dut_print(dut, DUT_MSG_ERROR,
4245 "Failed to set WIDTH/CTS_WIDTH");
4246 return -1;
4247 }
4248
4249 return 0;
4250}
4251
4252
4253int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4254 const char *intf, const char *val)
4255{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004256 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004257 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004258 dut->chwidth = 0;
4259 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004260 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004261 dut->chwidth = 0;
4262 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004263 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004264 dut->chwidth = 1;
4265 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004266 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004267 dut->chwidth = 2;
4268 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004269 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004270 dut->chwidth = 3;
4271 } else {
4272 send_resp(dut, conn, SIGMA_ERROR,
4273 "ErrorCode,WIDTH not supported");
4274 return -1;
4275 }
4276
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004277 return 0;
4278}
4279
4280
4281static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4282 const char *val)
4283{
4284 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004285 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004286
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004287 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004288 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004289 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004290 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004291 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004292 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004293 } else {
4294 sigma_dut_print(dut, DUT_MSG_ERROR,
4295 "SP_STREAM value not supported");
4296 return -1;
4297 }
4298
4299 if (system(buf) != 0) {
4300 sigma_dut_print(dut, DUT_MSG_ERROR,
4301 "Failed to set SP_STREAM");
4302 return -1;
4303 }
4304
Arif Hussainac6c5112018-05-25 17:34:00 -07004305 dut->sta_nss = sta_nss;
4306
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004307 return 0;
4308}
4309
4310
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304311static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4312 const char *val)
4313{
4314 char buf[60];
4315
4316 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4317 if (system(buf) != 0)
4318 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4319
4320 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4321 if (system(buf) != 0)
4322 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4323}
4324
4325
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304326static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4327 struct sigma_conn *conn,
4328 const char *intf, int capa)
4329{
4330 char buf[32];
4331
4332 if (capa > 0 && capa < 4) {
4333 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4334 if (wpa_command(intf, buf) < 0) {
4335 send_resp(dut, conn, SIGMA_ERROR,
4336 "ErrorCode, Failed to set cellular data capability");
4337 return 0;
4338 }
4339 return 1;
4340 }
4341
4342 sigma_dut_print(dut, DUT_MSG_ERROR,
4343 "Invalid Cellular data capability: %d", capa);
4344 send_resp(dut, conn, SIGMA_INVALID,
4345 "ErrorCode,Invalid cellular data capability");
4346 return 0;
4347}
4348
4349
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304350static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4351 const char *intf, const char *val)
4352{
4353 if (strcasecmp(val, "Disable") == 0) {
4354 if (wpa_command(intf, "SET roaming 0") < 0) {
4355 send_resp(dut, conn, SIGMA_ERROR,
4356 "ErrorCode,Failed to disable roaming");
4357 return 0;
4358 }
4359 return 1;
4360 }
4361
4362 if (strcasecmp(val, "Enable") == 0) {
4363 if (wpa_command(intf, "SET roaming 1") < 0) {
4364 send_resp(dut, conn, SIGMA_ERROR,
4365 "ErrorCode,Failed to enable roaming");
4366 return 0;
4367 }
4368 return 1;
4369 }
4370
4371 sigma_dut_print(dut, DUT_MSG_ERROR,
4372 "Invalid value provided for roaming: %s", val);
4373 send_resp(dut, conn, SIGMA_INVALID,
4374 "ErrorCode,Unknown value provided for Roaming");
4375 return 0;
4376}
4377
4378
Ashwini Patila75de5a2017-04-13 16:35:05 +05304379static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4380 struct sigma_conn *conn,
4381 const char *intf, const char *val)
4382{
4383 if (strcasecmp(val, "Disable") == 0) {
4384 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4385 send_resp(dut, conn, SIGMA_ERROR,
4386 "ErrorCode,Failed to disable Assoc_disallow");
4387 return 0;
4388 }
4389 return 1;
4390 }
4391
4392 if (strcasecmp(val, "Enable") == 0) {
4393 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4394 send_resp(dut, conn, SIGMA_ERROR,
4395 "ErrorCode,Failed to enable Assoc_disallow");
4396 return 0;
4397 }
4398 return 1;
4399 }
4400
4401 sigma_dut_print(dut, DUT_MSG_ERROR,
4402 "Invalid value provided for Assoc_disallow: %s", val);
4403 send_resp(dut, conn, SIGMA_INVALID,
4404 "ErrorCode,Unknown value provided for Assoc_disallow");
4405 return 0;
4406}
4407
4408
Ashwini Patilc63161e2017-04-13 16:30:23 +05304409static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4410 const char *intf, const char *val)
4411{
4412 if (strcasecmp(val, "Reject") == 0) {
4413 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4414 send_resp(dut, conn, SIGMA_ERROR,
4415 "ErrorCode,Failed to Reject BTM Request");
4416 return 0;
4417 }
4418 return 1;
4419 }
4420
4421 if (strcasecmp(val, "Accept") == 0) {
4422 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4423 send_resp(dut, conn, SIGMA_ERROR,
4424 "ErrorCode,Failed to Accept BTM Request");
4425 return 0;
4426 }
4427 return 1;
4428 }
4429
4430 sigma_dut_print(dut, DUT_MSG_ERROR,
4431 "Invalid value provided for BSS_Transition: %s", val);
4432 send_resp(dut, conn, SIGMA_INVALID,
4433 "ErrorCode,Unknown value provided for BSS_Transition");
4434 return 0;
4435}
4436
4437
Ashwini Patil00402582017-04-13 12:29:39 +05304438static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4439 struct sigma_conn *conn,
4440 const char *intf,
4441 struct sigma_cmd *cmd)
4442{
4443 const char *ch, *pref, *op_class, *reason;
4444 char buf[120];
4445 int len, ret;
4446
4447 pref = get_param(cmd, "Ch_Pref");
4448 if (!pref)
4449 return 1;
4450
4451 if (strcasecmp(pref, "clear") == 0) {
4452 free(dut->non_pref_ch_list);
4453 dut->non_pref_ch_list = NULL;
4454 } else {
4455 op_class = get_param(cmd, "Ch_Op_Class");
4456 if (!op_class) {
4457 send_resp(dut, conn, SIGMA_INVALID,
4458 "ErrorCode,Ch_Op_Class not provided");
4459 return 0;
4460 }
4461
4462 ch = get_param(cmd, "Ch_Pref_Num");
4463 if (!ch) {
4464 send_resp(dut, conn, SIGMA_INVALID,
4465 "ErrorCode,Ch_Pref_Num not provided");
4466 return 0;
4467 }
4468
4469 reason = get_param(cmd, "Ch_Reason_Code");
4470 if (!reason) {
4471 send_resp(dut, conn, SIGMA_INVALID,
4472 "ErrorCode,Ch_Reason_Code not provided");
4473 return 0;
4474 }
4475
4476 if (!dut->non_pref_ch_list) {
4477 dut->non_pref_ch_list =
4478 calloc(1, NON_PREF_CH_LIST_SIZE);
4479 if (!dut->non_pref_ch_list) {
4480 send_resp(dut, conn, SIGMA_ERROR,
4481 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4482 return 0;
4483 }
4484 }
4485 len = strlen(dut->non_pref_ch_list);
4486 ret = snprintf(dut->non_pref_ch_list + len,
4487 NON_PREF_CH_LIST_SIZE - len,
4488 " %s:%s:%s:%s", op_class, ch, pref, reason);
4489 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4490 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4491 dut->non_pref_ch_list);
4492 } else {
4493 sigma_dut_print(dut, DUT_MSG_ERROR,
4494 "snprintf failed for non_pref_list, ret = %d",
4495 ret);
4496 send_resp(dut, conn, SIGMA_ERROR,
4497 "ErrorCode,snprintf failed");
4498 free(dut->non_pref_ch_list);
4499 dut->non_pref_ch_list = NULL;
4500 return 0;
4501 }
4502 }
4503
4504 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4505 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4506 if (ret < 0 || ret >= (int) sizeof(buf)) {
4507 sigma_dut_print(dut, DUT_MSG_DEBUG,
4508 "snprintf failed for set non_pref_chan, ret: %d",
4509 ret);
4510 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4511 return 0;
4512 }
4513
4514 if (wpa_command(intf, buf) < 0) {
4515 send_resp(dut, conn, SIGMA_ERROR,
4516 "ErrorCode,Failed to set non-preferred channel list");
4517 return 0;
4518 }
4519
4520 return 1;
4521}
4522
4523
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004524#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004525
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004526static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4527 uint8_t cfg)
4528{
4529 struct nl_msg *msg;
4530 int ret = 0;
4531 struct nlattr *params;
4532 int ifindex;
4533
4534 ifindex = if_nametoindex(intf);
4535 if (ifindex == 0) {
4536 sigma_dut_print(dut, DUT_MSG_ERROR,
4537 "%s: Index for interface %s failed",
4538 __func__, intf);
4539 return -1;
4540 }
4541
4542 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4543 NL80211_CMD_VENDOR)) ||
4544 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4545 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4546 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4547 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4548 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4549 nla_put_u8(msg,
4550 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4551 cfg)) {
4552 sigma_dut_print(dut, DUT_MSG_ERROR,
4553 "%s: err in adding vendor_cmd and vendor_data",
4554 __func__);
4555 nlmsg_free(msg);
4556 return -1;
4557 }
4558 nla_nest_end(msg, params);
4559
4560 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4561 if (ret) {
4562 sigma_dut_print(dut, DUT_MSG_ERROR,
4563 "%s: err in send_and_recv_msgs, ret=%d",
4564 __func__, ret);
4565 }
4566 return ret;
4567}
4568
4569
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004570static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4571 enum he_fragmentation_val frag)
4572{
4573 struct nl_msg *msg;
4574 int ret = 0;
4575 struct nlattr *params;
4576 int ifindex;
4577
4578 ifindex = if_nametoindex(intf);
4579 if (ifindex == 0) {
4580 sigma_dut_print(dut, DUT_MSG_ERROR,
4581 "%s: Index for interface %s failed",
4582 __func__, intf);
4583 return -1;
4584 }
4585
4586 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4587 NL80211_CMD_VENDOR)) ||
4588 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4589 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4590 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4591 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4592 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4593 nla_put_u8(msg,
4594 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4595 frag)) {
4596 sigma_dut_print(dut, DUT_MSG_ERROR,
4597 "%s: err in adding vendor_cmd and vendor_data",
4598 __func__);
4599 nlmsg_free(msg);
4600 return -1;
4601 }
4602 nla_nest_end(msg, params);
4603
4604 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4605 if (ret) {
4606 sigma_dut_print(dut, DUT_MSG_ERROR,
4607 "%s: err in send_and_recv_msgs, ret=%d",
4608 __func__, ret);
4609 }
4610 return ret;
4611}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004612
4613
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08004614int wcn_set_he_ltf(struct sigma_dut *dut, const char *intf,
4615 enum qca_wlan_he_ltf_cfg ltf)
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004616{
4617 struct nl_msg *msg;
4618 int ret = 0;
4619 struct nlattr *params;
4620 int ifindex;
4621
4622 ifindex = if_nametoindex(intf);
4623 if (ifindex == 0) {
4624 sigma_dut_print(dut, DUT_MSG_ERROR,
4625 "%s: Index for interface %s failed",
4626 __func__, intf);
4627 return -1;
4628 }
4629
4630 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4631 NL80211_CMD_VENDOR)) ||
4632 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4633 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4634 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4635 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4636 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4637 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4638 ltf)) {
4639 sigma_dut_print(dut, DUT_MSG_ERROR,
4640 "%s: err in adding vendor_cmd and vendor_data",
4641 __func__);
4642 nlmsg_free(msg);
4643 return -1;
4644 }
4645 nla_nest_end(msg, params);
4646
4647 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4648 if (ret) {
4649 sigma_dut_print(dut, DUT_MSG_ERROR,
4650 "%s: err in send_and_recv_msgs, ret=%d",
4651 __func__, ret);
4652 }
4653 return ret;
4654}
4655
4656
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004657static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4658 int noack, enum qca_wlan_ac_type ac)
4659{
4660 struct nl_msg *msg;
4661 int ret = 0;
4662 struct nlattr *params;
4663 int ifindex;
4664
4665 ifindex = if_nametoindex(intf);
4666 if (ifindex == 0) {
4667 sigma_dut_print(dut, DUT_MSG_ERROR,
4668 "%s: Index for interface %s failed",
4669 __func__, intf);
4670 return -1;
4671 }
4672
4673 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4674 NL80211_CMD_VENDOR)) ||
4675 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4676 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4677 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4678 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4679 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4680 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4681 noack) ||
4682 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4683 ac)) {
4684 sigma_dut_print(dut, DUT_MSG_ERROR,
4685 "%s: err in adding vendor_cmd and vendor_data",
4686 __func__);
4687 nlmsg_free(msg);
4688 return -1;
4689 }
4690 nla_nest_end(msg, params);
4691
4692 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4693 if (ret) {
4694 sigma_dut_print(dut, DUT_MSG_ERROR,
4695 "%s: err in send_and_recv_msgs, ret=%d",
4696 __func__, ret);
4697 }
4698 return ret;
4699}
4700
4701
4702static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4703 const char *val)
4704{
4705 int noack, ret;
4706 char token[100];
4707 char *result;
4708 char *saveptr;
4709 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4710
4711 strlcpy(token, val, sizeof(token));
4712 token[sizeof(token) - 1] = '\0';
4713 result = strtok_r(token, ":", &saveptr);
4714 while (result) {
4715 noack = strcasecmp(result, "Disable") != 0;
4716 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4717 if (ret) {
4718 sigma_dut_print(dut, DUT_MSG_ERROR,
4719 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4720 ac, ret);
4721 }
4722 result = strtok_r(NULL, ":", &saveptr);
4723 ac++;
4724 }
4725}
4726
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004727#endif /* NL80211_SUPPORT */
4728
4729
Jouni Malinenf7222712019-06-13 01:50:21 +03004730static enum sigma_cmd_result
4731cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4732 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004733{
4734 const char *intf = get_param(cmd, "Interface");
4735 const char *val;
4736
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004737 val = get_param(cmd, "FT_DS");
4738 if (val) {
4739 if (strcasecmp(val, "Enable") == 0) {
4740 dut->sta_ft_ds = 1;
4741 } else if (strcasecmp(val, "Disable") == 0) {
4742 dut->sta_ft_ds = 0;
4743 } else {
4744 send_resp(dut, conn, SIGMA_ERROR,
4745 "errorCode,Unsupported value for FT_DS");
4746 return STATUS_SENT_ERROR;
4747 }
4748 }
4749
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004750 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004751 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4752 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004753 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4754 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004755
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004756 if (val && strcasecmp(val, "LOC") == 0)
4757 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004758 if (val && strcasecmp(val, "60GHZ") == 0) {
4759 val = get_param(cmd, "WPS");
4760 if (val && strcasecmp(val, "disable") == 0) {
4761 dut->wps_disable = 1;
4762 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4763 } else {
4764 /* wps_disable can have other value from the previous
4765 * test, so make sure it has the correct value.
4766 */
4767 dut->wps_disable = 0;
4768 }
4769
4770 val = get_param(cmd, "P2P");
4771 if (val && strcasecmp(val, "disable") == 0)
4772 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4773 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004774
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004775 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4776 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4777
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004778#ifdef ANDROID_NAN
4779 if (val && strcasecmp(val, "NAN") == 0)
4780 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4781#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004782#ifdef MIRACAST
4783 if (val && (strcasecmp(val, "WFD") == 0 ||
4784 strcasecmp(val, "DisplayR2") == 0))
4785 return miracast_preset_testparameters(dut, conn, cmd);
4786#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004787
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304788 if (val && strcasecmp(val, "MBO") == 0) {
4789 val = get_param(cmd, "Cellular_Data_Cap");
4790 if (val &&
4791 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4792 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304793
4794 val = get_param(cmd, "Ch_Pref");
4795 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4796 return 0;
4797
Ashwini Patilc63161e2017-04-13 16:30:23 +05304798 val = get_param(cmd, "BSS_Transition");
4799 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4800 return 0;
4801
Ashwini Patila75de5a2017-04-13 16:35:05 +05304802 val = get_param(cmd, "Assoc_Disallow");
4803 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4804 return 0;
4805
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304806 val = get_param(cmd, "Roaming");
4807 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4808 return 0;
4809
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304810 return 1;
4811 }
4812
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304813 if (val && strcasecmp(val, "OCE") == 0)
4814 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4815
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004816#if 0
4817 val = get_param(cmd, "Supplicant");
4818 if (val && strcasecmp(val, "Default") != 0) {
4819 send_resp(dut, conn, SIGMA_ERROR,
4820 "ErrorCode,Only default(Vendor) supplicant "
4821 "supported");
4822 return 0;
4823 }
4824#endif
4825
4826 val = get_param(cmd, "RTS");
4827 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004828 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004829 case DRIVER_ATHEROS:
4830 ath_sta_set_rts(dut, intf, val);
4831 break;
4832 default:
4833#if 0
4834 send_resp(dut, conn, SIGMA_ERROR,
4835 "ErrorCode,Setting RTS not supported");
4836 return 0;
4837#else
4838 sigma_dut_print(dut, DUT_MSG_DEBUG,
4839 "Setting RTS not supported");
4840 break;
4841#endif
4842 }
4843 }
4844
4845#if 0
4846 val = get_param(cmd, "FRGMNT");
4847 if (val) {
4848 /* TODO */
4849 send_resp(dut, conn, SIGMA_ERROR,
4850 "ErrorCode,Setting FRGMNT not supported");
4851 return 0;
4852 }
4853#endif
4854
4855#if 0
4856 val = get_param(cmd, "Preamble");
4857 if (val) {
4858 /* TODO: Long/Short */
4859 send_resp(dut, conn, SIGMA_ERROR,
4860 "ErrorCode,Setting Preamble not supported");
4861 return 0;
4862 }
4863#endif
4864
4865 val = get_param(cmd, "Mode");
4866 if (val) {
4867 if (strcmp(val, "11b") == 0 ||
4868 strcmp(val, "11g") == 0 ||
4869 strcmp(val, "11a") == 0 ||
4870 strcmp(val, "11n") == 0 ||
4871 strcmp(val, "11ng") == 0 ||
4872 strcmp(val, "11nl") == 0 ||
4873 strcmp(val, "11nl(nabg)") == 0 ||
4874 strcmp(val, "AC") == 0 ||
4875 strcmp(val, "11AC") == 0 ||
4876 strcmp(val, "11ac") == 0 ||
4877 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004878 strcmp(val, "11an") == 0 ||
4879 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004880 /* STA supports all modes by default */
4881 } else {
4882 send_resp(dut, conn, SIGMA_ERROR,
4883 "ErrorCode,Setting Mode not supported");
4884 return 0;
4885 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004886
4887 /* Change the mode only in case of testbed for HE program
4888 * and for 11a and 11g modes only. */
4889 if (dut->program == PROGRAM_HE &&
4890 dut->device_type == STA_testbed) {
4891 int phymode;
4892 char buf[60];
4893
4894 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004895 phymode = 1; /* IEEE80211_MODE_11A */
4896 } else if (strcmp(val, "11g") == 0) {
4897 phymode = 3; /* IEEE80211_MODE_11G */
4898 } else if (strcmp(val, "11b") == 0) {
4899 phymode = 2; /* IEEE80211_MODE_11B */
4900 } else if (strcmp(val, "11n") == 0 ||
4901 strcmp(val, "11nl") == 0 ||
4902 strcmp(val, "11nl(nabg)") == 0) {
4903 phymode = 22; /* IEEE80211_MODE_11AGN */
4904 } else if (strcmp(val, "11ng") == 0) {
4905 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4906 } else if (strcmp(val, "AC") == 0 ||
4907 strcasecmp(val, "11AC") == 0) {
4908 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4909 } else if (strcmp(val, "11na") == 0 ||
4910 strcasecmp(val, "11an") == 0) {
4911 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4912 } else if (strcmp(val, "11ax") == 0) {
4913 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004914 } else {
4915 sigma_dut_print(dut, DUT_MSG_DEBUG,
4916 "Ignoring mode change for mode: %s",
4917 val);
4918 phymode = -1;
4919 }
4920 if (phymode != -1) {
4921 snprintf(buf, sizeof(buf),
4922 "iwpriv %s setphymode %d",
4923 intf, phymode);
4924 if (system(buf) != 0) {
4925 sigma_dut_print(dut, DUT_MSG_ERROR,
4926 "iwpriv setting of phymode failed");
4927 }
4928 }
4929 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004930 }
4931
4932 val = get_param(cmd, "wmm");
4933 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004934 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004935 case DRIVER_ATHEROS:
4936 ath_sta_set_wmm(dut, intf, val);
4937 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004938 case DRIVER_WCN:
4939 wcn_sta_set_wmm(dut, intf, val);
4940 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004941 default:
4942 sigma_dut_print(dut, DUT_MSG_DEBUG,
4943 "Setting wmm not supported");
4944 break;
4945 }
4946 }
4947
4948 val = get_param(cmd, "Powersave");
4949 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004950 char buf[60];
4951
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004952 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004953 if (get_driver_type(dut) == DRIVER_WCN) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004954 snprintf(buf, sizeof(buf),
4955 "iwpriv %s setPower 2", intf);
4956 if (system(buf) != 0) {
4957 sigma_dut_print(dut, DUT_MSG_ERROR,
4958 "iwpriv setPower 2 failed");
4959 return 0;
4960 }
4961 }
4962
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004963 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004964 "P2P_SET ps 0") < 0)
4965 return -2;
4966 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004967 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
4968 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004969 } else if (strcmp(val, "1") == 0 ||
4970 strcasecmp(val, "PSPoll") == 0 ||
4971 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004972 if (get_driver_type(dut) == DRIVER_WCN) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004973 snprintf(buf, sizeof(buf),
4974 "iwpriv %s setPower 1", intf);
4975 if (system(buf) != 0) {
4976 sigma_dut_print(dut, DUT_MSG_ERROR,
4977 "iwpriv setPower 1 failed");
4978 return 0;
4979 }
4980 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004981 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004982 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004983 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004984 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004985 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004986 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004987 "P2P_SET ps 99") < 0)
4988 return -2;
4989 } else if (strcmp(val, "2") == 0 ||
4990 strcasecmp(val, "Fast") == 0) {
4991 /* TODO */
4992 send_resp(dut, conn, SIGMA_ERROR,
4993 "ErrorCode,Powersave=Fast not supported");
4994 return 0;
4995 } else if (strcmp(val, "3") == 0 ||
4996 strcasecmp(val, "PSNonPoll") == 0) {
4997 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004998 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
4999 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005000
5001 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005002 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005003 "P2P_SET ps 1") < 0)
5004 return -2;
5005 } else
5006 return -1;
5007 }
5008
5009 val = get_param(cmd, "NoAck");
5010 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005011 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005012 case DRIVER_ATHEROS:
5013 ath_sta_set_noack(dut, intf, val);
5014 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08005015#ifdef NL80211_SUPPORT
5016 case DRIVER_WCN:
5017 wcn_sta_set_noack(dut, intf, val);
5018 break;
5019#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005020 default:
5021 send_resp(dut, conn, SIGMA_ERROR,
5022 "ErrorCode,Setting NoAck not supported");
5023 return 0;
5024 }
5025 }
5026
5027 val = get_param(cmd, "IgnoreChswitchProhibit");
5028 if (val) {
5029 /* TODO: Enabled/disabled */
5030 if (strcasecmp(val, "Enabled") == 0) {
5031 send_resp(dut, conn, SIGMA_ERROR,
5032 "ErrorCode,Enabling IgnoreChswitchProhibit "
5033 "not supported");
5034 return 0;
5035 }
5036 }
5037
5038 val = get_param(cmd, "TDLS");
5039 if (val) {
5040 if (strcasecmp(val, "Disabled") == 0) {
5041 if (wpa_command(intf, "SET tdls_disabled 1")) {
5042 send_resp(dut, conn, SIGMA_ERROR,
5043 "ErrorCode,Failed to disable TDLS");
5044 return 0;
5045 }
5046 } else if (strcasecmp(val, "Enabled") == 0) {
5047 if (wpa_command(intf, "SET tdls_disabled 0")) {
5048 send_resp(dut, conn, SIGMA_ERROR,
5049 "ErrorCode,Failed to enable TDLS");
5050 return 0;
5051 }
5052 } else {
5053 send_resp(dut, conn, SIGMA_ERROR,
5054 "ErrorCode,Unsupported TDLS value");
5055 return 0;
5056 }
5057 }
5058
5059 val = get_param(cmd, "TDLSmode");
5060 if (val) {
5061 if (strcasecmp(val, "Default") == 0) {
5062 wpa_command(intf, "SET tdls_testing 0");
5063 } else if (strcasecmp(val, "APProhibit") == 0) {
5064 if (wpa_command(intf, "SET tdls_testing 0x400")) {
5065 send_resp(dut, conn, SIGMA_ERROR,
5066 "ErrorCode,Failed to enable ignore "
5067 "APProhibit TDLS mode");
5068 return 0;
5069 }
5070 } else if (strcasecmp(val, "HiLoMac") == 0) {
5071 /* STA should respond with TDLS setup req for a TDLS
5072 * setup req */
5073 if (wpa_command(intf, "SET tdls_testing 0x80")) {
5074 send_resp(dut, conn, SIGMA_ERROR,
5075 "ErrorCode,Failed to enable HiLoMac "
5076 "TDLS mode");
5077 return 0;
5078 }
5079 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5080 /*
5081 * Since all security modes are enabled by default when
5082 * Sigma control is used, there is no need to do
5083 * anything here.
5084 */
5085 } else if (strcasecmp(val, "ExistLink") == 0) {
5086 /*
5087 * Since we allow new TDLS Setup Request even if there
5088 * is an existing link, nothing needs to be done for
5089 * this.
5090 */
5091 } else {
5092 /* TODO:
5093 * ExistLink: STA should send TDLS setup req even if
5094 * direct link already exists
5095 */
5096 send_resp(dut, conn, SIGMA_ERROR,
5097 "ErrorCode,Unsupported TDLSmode value");
5098 return 0;
5099 }
5100 }
5101
5102 val = get_param(cmd, "FakePubKey");
5103 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5104 send_resp(dut, conn, SIGMA_ERROR,
5105 "ErrorCode,Failed to enable FakePubKey");
5106 return 0;
5107 }
5108
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005109#ifdef NL80211_SUPPORT
5110 val = get_param(cmd, "FrgmntSupport");
5111 if (val) {
5112 if (strcasecmp(val, "Enable") == 0) {
5113 if (sta_set_he_fragmentation(dut, intf,
5114 HE_FRAG_LEVEL1)) {
5115 send_resp(dut, conn, SIGMA_ERROR,
5116 "ErrorCode,Failed to enable HE Fragmentation");
5117 return 0;
5118 }
5119 } else if (strcasecmp(val, "Disable") == 0) {
5120 if (sta_set_he_fragmentation(dut, intf,
5121 HE_FRAG_DISABLE)) {
5122 send_resp(dut, conn, SIGMA_ERROR,
5123 "ErrorCode,Failed to disable HE Fragmentation");
5124 return 0;
5125 }
5126 }
5127 }
5128#endif /* NL80211_SUPPORT */
5129
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005130 return 1;
5131}
5132
5133
5134static const char * ath_get_radio_name(const char *radio_name)
5135{
5136 if (radio_name == NULL)
5137 return "wifi0";
5138 if (strcmp(radio_name, "wifi1") == 0)
5139 return "wifi1";
5140 if (strcmp(radio_name, "wifi2") == 0)
5141 return "wifi2";
5142 return "wifi0";
5143}
5144
5145
5146static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5147 const char *val)
5148{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005149 unsigned int vht_mcsmap = 0;
5150 int txchainmask = 0;
5151 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5152
5153 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5154 if (dut->testbed_flag_txsp == 1) {
5155 vht_mcsmap = 0xfffc;
5156 dut->testbed_flag_txsp = 0;
5157 } else {
5158 vht_mcsmap = 0xfffe;
5159 }
5160 txchainmask = 1;
5161 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5162 if (dut->testbed_flag_txsp == 1) {
5163 vht_mcsmap = 0xfff0;
5164 dut->testbed_flag_txsp = 0;
5165 } else {
5166 vht_mcsmap = 0xfffa;
5167 }
5168 txchainmask = 3;
5169 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5170 if (dut->testbed_flag_txsp == 1) {
5171 vht_mcsmap = 0xffc0;
5172 dut->testbed_flag_txsp = 0;
5173 } else {
5174 vht_mcsmap = 0xffea;
5175 }
5176 txchainmask = 7;
5177 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5178 if (dut->testbed_flag_txsp == 1) {
5179 vht_mcsmap = 0xff00;
5180 dut->testbed_flag_txsp = 0;
5181 } else {
5182 vht_mcsmap = 0xffaa;
5183 }
5184 txchainmask = 15;
5185 } else {
5186 if (dut->testbed_flag_txsp == 1) {
5187 vht_mcsmap = 0xffc0;
5188 dut->testbed_flag_txsp = 0;
5189 } else {
5190 vht_mcsmap = 0xffea;
5191 }
5192 }
5193
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005194 if (txchainmask)
5195 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005196
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005197 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005198}
5199
5200
5201static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5202 const char *val)
5203{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005204 unsigned int vht_mcsmap = 0;
5205 int rxchainmask = 0;
5206 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5207
5208 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5209 if (dut->testbed_flag_rxsp == 1) {
5210 vht_mcsmap = 0xfffc;
5211 dut->testbed_flag_rxsp = 0;
5212 } else {
5213 vht_mcsmap = 0xfffe;
5214 }
5215 rxchainmask = 1;
5216 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5217 if (dut->testbed_flag_rxsp == 1) {
5218 vht_mcsmap = 0xfff0;
5219 dut->testbed_flag_rxsp = 0;
5220 } else {
5221 vht_mcsmap = 0xfffa;
5222 }
5223 rxchainmask = 3;
5224 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5225 if (dut->testbed_flag_rxsp == 1) {
5226 vht_mcsmap = 0xffc0;
5227 dut->testbed_flag_rxsp = 0;
5228 } else {
5229 vht_mcsmap = 0xffea;
5230 }
5231 rxchainmask = 7;
5232 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5233 if (dut->testbed_flag_rxsp == 1) {
5234 vht_mcsmap = 0xff00;
5235 dut->testbed_flag_rxsp = 0;
5236 } else {
5237 vht_mcsmap = 0xffaa;
5238 }
5239 rxchainmask = 15;
5240 } else {
5241 if (dut->testbed_flag_rxsp == 1) {
5242 vht_mcsmap = 0xffc0;
5243 dut->testbed_flag_rxsp = 0;
5244 } else {
5245 vht_mcsmap = 0xffea;
5246 }
5247 }
5248
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005249 if (rxchainmask)
5250 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005251
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005252 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005253}
5254
5255
5256void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5257{
5258 if (strcasecmp(val, "enable") == 0) {
5259 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5260 != 0) {
5261 sigma_dut_print(dut, DUT_MSG_ERROR,
5262 "Disable BB_VHTSIGB_CRC_CALC failed");
5263 }
5264
5265 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5266 != 0) {
5267 sigma_dut_print(dut, DUT_MSG_ERROR,
5268 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5269 }
5270 } else {
5271 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5272 != 0) {
5273 sigma_dut_print(dut, DUT_MSG_ERROR,
5274 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5275 }
5276
5277 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5278 != 0) {
5279 sigma_dut_print(dut, DUT_MSG_ERROR,
5280 "Enable BB_VHTSIGB_CRC_CALC failed");
5281 }
5282 }
5283}
5284
5285
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005286static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5287 const char *val)
5288{
5289 char buf[60];
5290
5291 if (strcmp(val, "20") == 0) {
5292 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5293 dut->chwidth = 0;
5294 } else if (strcmp(val, "40") == 0) {
5295 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5296 dut->chwidth = 1;
5297 } else if (strcmp(val, "80") == 0) {
5298 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5299 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305300 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005301 buf[0] = '\0';
5302 } else {
5303 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5304 val);
5305 return -1;
5306 }
5307
5308 if (buf[0] != '\0' && system(buf) != 0) {
5309 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5310 return -1;
5311 }
5312
5313 return 0;
5314}
5315
5316
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005317static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5318 const char *intf, int addbareject)
5319{
5320#ifdef NL80211_SUPPORT
5321 struct nl_msg *msg;
5322 int ret = 0;
5323 struct nlattr *params;
5324 int ifindex;
5325
5326 ifindex = if_nametoindex(intf);
5327 if (ifindex == 0) {
5328 sigma_dut_print(dut, DUT_MSG_ERROR,
5329 "%s: Index for interface %s failed",
5330 __func__, intf);
5331 return -1;
5332 }
5333
5334 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5335 NL80211_CMD_VENDOR)) ||
5336 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5337 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5338 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5339 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5340 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5341 nla_put_u8(msg,
5342 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5343 !addbareject)) {
5344 sigma_dut_print(dut, DUT_MSG_ERROR,
5345 "%s: err in adding vendor_cmd and vendor_data",
5346 __func__);
5347 nlmsg_free(msg);
5348 return -1;
5349 }
5350 nla_nest_end(msg, params);
5351
5352 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5353 if (ret) {
5354 sigma_dut_print(dut, DUT_MSG_ERROR,
5355 "%s: err in send_and_recv_msgs, ret=%d",
5356 __func__, ret);
5357 }
5358 return ret;
5359#else /* NL80211_SUPPORT */
5360 sigma_dut_print(dut, DUT_MSG_ERROR,
5361 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5362 return -1;
5363#endif /* NL80211_SUPPORT */
5364}
5365
5366
5367static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5368 int addbareject)
5369{
5370 int ret;
5371
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005372 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005373 case DRIVER_WCN:
5374 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5375 if (ret) {
5376 sigma_dut_print(dut, DUT_MSG_ERROR,
5377 "nlvendor_sta_set_addba_reject failed, ret:%d",
5378 ret);
5379 return ret;
5380 }
5381 break;
5382 default:
5383 sigma_dut_print(dut, DUT_MSG_ERROR,
5384 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5385 ret = -1;
5386 break;
5387 }
5388
5389 return ret;
5390}
5391
5392
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005393static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5394 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005395{
5396#ifdef NL80211_SUPPORT
5397 struct nl_msg *msg;
5398 int ret = 0;
5399 struct nlattr *params;
5400 int ifindex;
5401
5402 ifindex = if_nametoindex(intf);
5403 if (ifindex == 0) {
5404 sigma_dut_print(dut, DUT_MSG_ERROR,
5405 "%s: Index for interface %s failed",
5406 __func__, intf);
5407 return -1;
5408 }
5409
5410 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5411 NL80211_CMD_VENDOR)) ||
5412 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5413 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5414 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5415 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5416 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5417 nla_put_u8(msg,
5418 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005419 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005420 sigma_dut_print(dut, DUT_MSG_ERROR,
5421 "%s: err in adding vendor_cmd and vendor_data",
5422 __func__);
5423 nlmsg_free(msg);
5424 return -1;
5425 }
5426 nla_nest_end(msg, params);
5427
5428 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5429 if (ret) {
5430 sigma_dut_print(dut, DUT_MSG_ERROR,
5431 "%s: err in send_and_recv_msgs, ret=%d",
5432 __func__, ret);
5433 }
5434 return ret;
5435#else /* NL80211_SUPPORT */
5436 sigma_dut_print(dut, DUT_MSG_ERROR,
5437 "Disable addba not possible without NL80211_SUPPORT defined");
5438 return -1;
5439#endif /* NL80211_SUPPORT */
5440}
5441
5442
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305443#ifdef NL80211_SUPPORT
5444static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5445{
5446 struct nl_msg *msg;
5447 int ret = 0;
5448 int ifindex;
5449
5450 ifindex = if_nametoindex(intf);
5451 if (ifindex == 0) {
5452 sigma_dut_print(dut, DUT_MSG_ERROR,
5453 "%s: Index for interface %s failed",
5454 __func__, intf);
5455 return -1;
5456 }
5457
5458 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5459 NL80211_CMD_SET_WIPHY)) ||
5460 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5461 sigma_dut_print(dut, DUT_MSG_ERROR,
5462 "%s: err in adding RTS threshold",
5463 __func__);
5464 nlmsg_free(msg);
5465 return -1;
5466 }
5467
5468 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5469 if (ret) {
5470 sigma_dut_print(dut, DUT_MSG_ERROR,
5471 "%s: err in send_and_recv_msgs, ret=%d",
5472 __func__, ret);
5473 }
5474 return ret;
5475}
5476#endif /* NL80211_SUPPORT */
5477
5478
5479static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5480{
5481 char buf[100];
5482
5483#ifdef NL80211_SUPPORT
5484 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5485 return 0;
5486 sigma_dut_print(dut, DUT_MSG_DEBUG,
5487 "Fall back to using iwconfig for setting RTS threshold");
5488#endif /* NL80211_SUPPORT */
5489
5490 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5491 if (system(buf) != 0) {
5492 sigma_dut_print(dut, DUT_MSG_ERROR,
5493 "Failed to set RTS threshold %d", val);
5494 return -1;
5495 }
5496 return 0;
5497}
5498
5499
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005500static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5501 struct sigma_conn *conn,
5502 struct sigma_cmd *cmd)
5503{
5504 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005505 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005506 char buf[128];
5507 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005508
5509 val = get_param(cmd, "40_INTOLERANT");
5510 if (val) {
5511 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5512 /* TODO: iwpriv ht40intol through wpa_supplicant */
5513 send_resp(dut, conn, SIGMA_ERROR,
5514 "ErrorCode,40_INTOLERANT not supported");
5515 return 0;
5516 }
5517 }
5518
5519 val = get_param(cmd, "ADDBA_REJECT");
5520 if (val) {
5521 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5522 /* reject any ADDBA with status "decline" */
5523 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005524 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005525 } else {
5526 /* accept ADDBA */
5527 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005528 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005529 }
5530 }
5531
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005532 if (addbareject >= 0 &&
5533 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5534 send_resp(dut, conn, SIGMA_ERROR,
5535 "ErrorCode,set addba_reject failed");
5536 return 0;
5537 }
5538
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005539 val = get_param(cmd, "AMPDU");
5540 if (val) {
5541 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5542 /* enable AMPDU Aggregation */
5543 if (ampdu == 0) {
5544 send_resp(dut, conn, SIGMA_ERROR,
5545 "ErrorCode,Mismatch in "
5546 "addba_reject/ampdu - "
5547 "not supported");
5548 return 0;
5549 }
5550 ampdu = 1;
5551 } else {
5552 /* disable AMPDU Aggregation */
5553 if (ampdu == 1) {
5554 send_resp(dut, conn, SIGMA_ERROR,
5555 "ErrorCode,Mismatch in "
5556 "addba_reject/ampdu - "
5557 "not supported");
5558 return 0;
5559 }
5560 ampdu = 0;
5561 }
5562 }
5563
5564 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005565 int ret;
5566
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005567 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5568 ampdu ? "Enabling" : "Disabling");
5569 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005570 if (wpa_command(intf, buf) < 0 &&
5571 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005572 send_resp(dut, conn, SIGMA_ERROR,
5573 "ErrorCode,set aggr failed");
5574 return 0;
5575 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005576
5577 if (ampdu == 0) {
5578 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005579 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005580 if (ret) {
5581 sigma_dut_print(dut, DUT_MSG_ERROR,
5582 "Failed to disable addba, ret:%d",
5583 ret);
5584 }
5585 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005586 }
5587
5588 val = get_param(cmd, "AMSDU");
5589 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005590 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005591 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005592 case DRIVER_WCN:
5593 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005594 break;
5595 default:
5596 if (strcmp(val, "1") == 0 ||
5597 strcasecmp(val, "Enable") == 0) {
5598 /* Enable AMSDU Aggregation */
5599 send_resp(dut, conn, SIGMA_ERROR,
5600 "ErrorCode,AMSDU aggregation not supported");
5601 return 0;
5602 }
5603 break;
5604 }
5605 }
5606
5607 val = get_param(cmd, "STBC_RX");
5608 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005609 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005610 case DRIVER_ATHEROS:
5611 ath_sta_set_stbc(dut, intf, val);
5612 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305613 case DRIVER_WCN:
5614 wcn_sta_set_stbc(dut, intf, val);
5615 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005616 default:
5617 send_resp(dut, conn, SIGMA_ERROR,
5618 "ErrorCode,STBC_RX not supported");
5619 return 0;
5620 }
5621 }
5622
5623 val = get_param(cmd, "WIDTH");
5624 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005625 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005626 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005627 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005628 send_resp(dut, conn, SIGMA_ERROR,
5629 "ErrorCode,Failed to set WIDTH");
5630 return 0;
5631 }
5632 break;
5633 case DRIVER_ATHEROS:
5634 if (ath_set_width(dut, conn, intf, val) < 0)
5635 return 0;
5636 break;
5637 default:
5638 sigma_dut_print(dut, DUT_MSG_ERROR,
5639 "Setting WIDTH not supported");
5640 break;
5641 }
5642 }
5643
5644 val = get_param(cmd, "SMPS");
5645 if (val) {
5646 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5647 send_resp(dut, conn, SIGMA_ERROR,
5648 "ErrorCode,SMPS not supported");
5649 return 0;
5650 }
5651
5652 val = get_param(cmd, "TXSP_STREAM");
5653 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005654 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005655 case DRIVER_WCN:
5656 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5657 send_resp(dut, conn, SIGMA_ERROR,
5658 "ErrorCode,Failed to set TXSP_STREAM");
5659 return 0;
5660 }
5661 break;
5662 case DRIVER_ATHEROS:
5663 ath_sta_set_txsp_stream(dut, intf, val);
5664 break;
5665 default:
5666 sigma_dut_print(dut, DUT_MSG_ERROR,
5667 "Setting TXSP_STREAM not supported");
5668 break;
5669 }
5670 }
5671
5672 val = get_param(cmd, "RXSP_STREAM");
5673 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005674 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005675 case DRIVER_WCN:
5676 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5677 send_resp(dut, conn, SIGMA_ERROR,
5678 "ErrorCode,Failed to set RXSP_STREAM");
5679 return 0;
5680 }
5681 break;
5682 case DRIVER_ATHEROS:
5683 ath_sta_set_rxsp_stream(dut, intf, val);
5684 break;
5685 default:
5686 sigma_dut_print(dut, DUT_MSG_ERROR,
5687 "Setting RXSP_STREAM not supported");
5688 break;
5689 }
5690 }
5691
5692 val = get_param(cmd, "DYN_BW_SGNL");
5693 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005694 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005695 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005696 if (strcasecmp(val, "enable") == 0) {
5697 snprintf(buf, sizeof(buf),
5698 "iwpriv %s cwmenable 1", intf);
5699 if (system(buf) != 0) {
5700 sigma_dut_print(dut, DUT_MSG_ERROR,
5701 "iwpriv cwmenable 1 failed");
5702 return 0;
5703 }
5704 } else if (strcasecmp(val, "disable") == 0) {
5705 snprintf(buf, sizeof(buf),
5706 "iwpriv %s cwmenable 0", intf);
5707 if (system(buf) != 0) {
5708 sigma_dut_print(dut, DUT_MSG_ERROR,
5709 "iwpriv cwmenable 0 failed");
5710 return 0;
5711 }
5712 } else {
5713 sigma_dut_print(dut, DUT_MSG_ERROR,
5714 "Unsupported DYN_BW_SGL");
5715 }
5716
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005717 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5718 if (system(buf) != 0) {
5719 sigma_dut_print(dut, DUT_MSG_ERROR,
5720 "Failed to set cts_cbw in DYN_BW_SGNL");
5721 return 0;
5722 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005723 break;
5724 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005725 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005726 ath_config_dyn_bw_sig(dut, intf, val);
5727 break;
5728 default:
5729 sigma_dut_print(dut, DUT_MSG_ERROR,
5730 "Failed to set DYN_BW_SGNL");
5731 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005732 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005733 }
5734
5735 val = get_param(cmd, "RTS_FORCE");
5736 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005737 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005738 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305739 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005740 sigma_dut_print(dut, DUT_MSG_ERROR,
5741 "Failed to set RTS_FORCE 64");
5742 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005743 res = snprintf(buf, sizeof(buf),
5744 "wifitool %s beeliner_fw_test 100 1",
5745 intf);
5746 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005747 sigma_dut_print(dut, DUT_MSG_ERROR,
5748 "wifitool beeliner_fw_test 100 1 failed");
5749 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005750 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305751 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005752 sigma_dut_print(dut, DUT_MSG_ERROR,
5753 "Failed to set RTS_FORCE 2347");
5754 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005755 } else {
5756 send_resp(dut, conn, SIGMA_ERROR,
5757 "ErrorCode,RTS_FORCE value not supported");
5758 return 0;
5759 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005760 }
5761
5762 val = get_param(cmd, "CTS_WIDTH");
5763 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005764 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005765 case DRIVER_WCN:
5766 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5767 send_resp(dut, conn, SIGMA_ERROR,
5768 "ErrorCode,Failed to set CTS_WIDTH");
5769 return 0;
5770 }
5771 break;
5772 case DRIVER_ATHEROS:
5773 ath_set_cts_width(dut, intf, val);
5774 break;
5775 default:
5776 sigma_dut_print(dut, DUT_MSG_ERROR,
5777 "Setting CTS_WIDTH not supported");
5778 break;
5779 }
5780 }
5781
5782 val = get_param(cmd, "BW_SGNL");
5783 if (val) {
5784 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005785 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005786 } else if (strcasecmp(val, "Disable") == 0) {
5787 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005788 } else {
5789 send_resp(dut, conn, SIGMA_ERROR,
5790 "ErrorCode,BW_SGNL value not supported");
5791 return 0;
5792 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005793 }
5794
5795 val = get_param(cmd, "Band");
5796 if (val) {
5797 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5798 /* STA supports all bands by default */
5799 } else {
5800 send_resp(dut, conn, SIGMA_ERROR,
5801 "ErrorCode,Unsupported Band");
5802 return 0;
5803 }
5804 }
5805
5806 val = get_param(cmd, "zero_crc");
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_ATHEROS:
5810 ath_set_zero_crc(dut, val);
5811 break;
5812 default:
5813 break;
5814 }
5815 }
5816
5817 return 1;
5818}
5819
5820
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005821static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5822{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005823 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005824#ifdef __linux__
5825 case DRIVER_WIL6210:
5826 return wil6210_set_force_mcs(dut, force, mcs);
5827#endif /* __linux__ */
5828 default:
5829 sigma_dut_print(dut, DUT_MSG_ERROR,
5830 "Unsupported sta_set_force_mcs with the current driver");
5831 return -1;
5832 }
5833}
5834
5835
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005836static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5837{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005838 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005839#ifdef __linux__
5840 case DRIVER_WIL6210:
5841 return wil6210_force_rsn_ie(dut, state);
5842#endif /* __linux__ */
5843 default:
5844 sigma_dut_print(dut, DUT_MSG_ERROR,
5845 "Unsupported sta_60g_force_rsn_ie with the current driver");
5846 return -1;
5847 }
5848}
5849
5850
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005851static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5852 struct sigma_cmd *cmd)
5853{
5854 const char *val;
5855 char buf[100];
5856
5857 val = get_param(cmd, "MSDUSize");
5858 if (val) {
5859 int mtu;
5860
5861 dut->amsdu_size = atoi(val);
5862 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5863 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5864 sigma_dut_print(dut, DUT_MSG_ERROR,
5865 "MSDUSize %d is above max %d or below min %d",
5866 dut->amsdu_size,
5867 IEEE80211_MAX_DATA_LEN_DMG,
5868 IEEE80211_SNAP_LEN_DMG);
5869 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005870 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005871 }
5872
5873 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5874 sigma_dut_print(dut, DUT_MSG_DEBUG,
5875 "Setting amsdu_size to %d", mtu);
5876 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005877 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005878
5879 if (system(buf) != 0) {
5880 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5881 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005882 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005883 }
5884 }
5885
5886 val = get_param(cmd, "BAckRcvBuf");
5887 if (val) {
5888 dut->back_rcv_buf = atoi(val);
5889 if (dut->back_rcv_buf == 0) {
5890 sigma_dut_print(dut, DUT_MSG_ERROR,
5891 "Failed to convert %s or value is 0",
5892 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005893 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005894 }
5895
5896 sigma_dut_print(dut, DUT_MSG_DEBUG,
5897 "Setting BAckRcvBuf to %s", val);
5898 }
5899
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005900 val = get_param(cmd, "MCS_FixedRate");
5901 if (val) {
5902 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5903 sigma_dut_print(dut, DUT_MSG_ERROR,
5904 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005905 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005906 }
5907 }
5908
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005909 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910}
5911
5912
5913static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5914 struct sigma_cmd *cmd)
5915{
5916 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005917 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005918 const char *val;
5919 char buf[100];
5920
5921 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005922 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005923 if (wpa_command(ifname, "PING") != 0) {
5924 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005925 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005926 }
5927
5928 wpa_command(ifname, "FLUSH");
5929 net_id = add_network_common(dut, conn, ifname, cmd);
5930 if (net_id < 0) {
5931 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5932 return net_id;
5933 }
5934
5935 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5936 if (set_network(ifname, net_id, "mode", "2") < 0) {
5937 sigma_dut_print(dut, DUT_MSG_ERROR,
5938 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005939 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005940 }
5941
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005942 if (set_network(ifname, net_id, "pbss", "1") < 0)
5943 return -2;
5944
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005945 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005946 "Supplicant set network with mode 2. network_id %d",
5947 net_id);
5948
5949 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5950 sigma_dut_print(dut, DUT_MSG_INFO,
5951 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005952 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005953 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005954
5955 val = get_param(cmd, "Security");
5956 if (val && strcasecmp(val, "OPEN") == 0) {
5957 dut->ap_key_mgmt = AP_OPEN;
5958 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5959 sigma_dut_print(dut, DUT_MSG_ERROR,
5960 "Failed to set supplicant to %s security",
5961 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005962 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005963 }
5964 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5965 dut->ap_key_mgmt = AP_WPA2_PSK;
5966 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5967 sigma_dut_print(dut, DUT_MSG_ERROR,
5968 "Failed to set supplicant to %s security",
5969 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005970 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005971 }
5972
5973 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5974 sigma_dut_print(dut, DUT_MSG_ERROR,
5975 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005976 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005977 }
5978 } else if (val) {
5979 sigma_dut_print(dut, DUT_MSG_ERROR,
5980 "Requested Security %s is not supported on 60GHz",
5981 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005982 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005983 }
5984
5985 val = get_param(cmd, "Encrypt");
5986 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5987 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5988 sigma_dut_print(dut, DUT_MSG_ERROR,
5989 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005990 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005991 }
5992 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5993 sigma_dut_print(dut, DUT_MSG_ERROR,
5994 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005995 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005996 }
5997 } else if (val) {
5998 sigma_dut_print(dut, DUT_MSG_ERROR,
5999 "Requested Encrypt %s is not supported on 60 GHz",
6000 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006001 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006002 }
6003
6004 val = get_param(cmd, "PSK");
6005 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
6006 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
6007 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006008 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006009 }
6010
6011 /* Convert 60G channel to freq */
6012 switch (dut->ap_channel) {
6013 case 1:
6014 val = "58320";
6015 break;
6016 case 2:
6017 val = "60480";
6018 break;
6019 case 3:
6020 val = "62640";
6021 break;
6022 default:
6023 sigma_dut_print(dut, DUT_MSG_ERROR,
6024 "Failed to configure channel %d. Not supported",
6025 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006026 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006027 }
6028
6029 if (set_network(ifname, net_id, "frequency", val) < 0) {
6030 sigma_dut_print(dut, DUT_MSG_ERROR,
6031 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006032 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006033 }
6034
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02006035 if (dut->eap_fragment) {
6036 sigma_dut_print(dut, DUT_MSG_DEBUG,
6037 "Set EAP fragment size to 128 bytes.");
6038 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
6039 return ERROR_SEND_STATUS;
6040 }
6041
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006042 sigma_dut_print(dut, DUT_MSG_DEBUG,
6043 "Supplicant set network with frequency");
6044
6045 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
6046 if (wpa_command(ifname, buf) < 0) {
6047 sigma_dut_print(dut, DUT_MSG_INFO,
6048 "Failed to select network id %d on %s",
6049 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006050 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006051 }
6052
6053 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
6054
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006055 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006056}
6057
6058
Lior David67543f52017-01-03 19:04:22 +02006059static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
6060{
6061 char buf[128], fname[128];
6062 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03006063 int res;
Lior David67543f52017-01-03 19:04:22 +02006064
6065 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
6066 sigma_dut_print(dut, DUT_MSG_ERROR,
6067 "failed to get wil6210 debugfs dir");
6068 return -1;
6069 }
6070
Jouni Malinen3aa72862019-05-29 23:14:51 +03006071 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
6072 if (res < 0 || res >= sizeof(fname))
6073 return -1;
Lior David67543f52017-01-03 19:04:22 +02006074 f = fopen(fname, "w");
6075 if (!f) {
6076 sigma_dut_print(dut, DUT_MSG_ERROR,
6077 "failed to open: %s", fname);
6078 return -1;
6079 }
6080
6081 fprintf(f, "%d\n", abft_len);
6082 fclose(f);
6083
6084 return 0;
6085}
6086
6087
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006088int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6089 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006090{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006091 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006092 case DRIVER_WIL6210:
6093 return wil6210_set_abft_len(dut, abft_len);
6094 default:
6095 sigma_dut_print(dut, DUT_MSG_ERROR,
6096 "set abft_len not supported");
6097 return -1;
6098 }
6099}
6100
6101
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006102static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6103 struct sigma_cmd *cmd)
6104{
6105 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006106 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006107
6108 if (dut->dev_role != DEVROLE_PCP) {
6109 send_resp(dut, conn, SIGMA_INVALID,
6110 "ErrorCode,Invalid DevRole");
6111 return 0;
6112 }
6113
6114 val = get_param(cmd, "SSID");
6115 if (val) {
6116 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6117 send_resp(dut, conn, SIGMA_INVALID,
6118 "ErrorCode,Invalid SSID");
6119 return -1;
6120 }
6121
Peng Xub8fc5cc2017-05-10 17:27:28 -07006122 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006123 }
6124
6125 val = get_param(cmd, "CHANNEL");
6126 if (val) {
6127 const char *pos;
6128
6129 dut->ap_channel = atoi(val);
6130 pos = strchr(val, ';');
6131 if (pos) {
6132 pos++;
6133 dut->ap_channel_1 = atoi(pos);
6134 }
6135 }
6136
6137 switch (dut->ap_channel) {
6138 case 1:
6139 case 2:
6140 case 3:
6141 break;
6142 default:
6143 sigma_dut_print(dut, DUT_MSG_ERROR,
6144 "Channel %d is not supported", dut->ap_channel);
6145 send_resp(dut, conn, SIGMA_ERROR,
6146 "Requested channel is not supported");
6147 return -1;
6148 }
6149
6150 val = get_param(cmd, "BCNINT");
6151 if (val)
6152 dut->ap_bcnint = atoi(val);
6153
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006154 val = get_param(cmd, "AllocType");
6155 if (val) {
6156 send_resp(dut, conn, SIGMA_ERROR,
6157 "ErrorCode,AllocType is not supported yet");
6158 return -1;
6159 }
6160
6161 val = get_param(cmd, "PercentBI");
6162 if (val) {
6163 send_resp(dut, conn, SIGMA_ERROR,
6164 "ErrorCode,PercentBI is not supported yet");
6165 return -1;
6166 }
6167
6168 val = get_param(cmd, "CBAPOnly");
6169 if (val) {
6170 send_resp(dut, conn, SIGMA_ERROR,
6171 "ErrorCode,CBAPOnly is not supported yet");
6172 return -1;
6173 }
6174
6175 val = get_param(cmd, "AMPDU");
6176 if (val) {
6177 if (strcasecmp(val, "Enable") == 0)
6178 dut->ap_ampdu = 1;
6179 else if (strcasecmp(val, "Disable") == 0)
6180 dut->ap_ampdu = 2;
6181 else {
6182 send_resp(dut, conn, SIGMA_ERROR,
6183 "ErrorCode,AMPDU value is not Enable nor Disabled");
6184 return -1;
6185 }
6186 }
6187
6188 val = get_param(cmd, "AMSDU");
6189 if (val) {
6190 if (strcasecmp(val, "Enable") == 0)
6191 dut->ap_amsdu = 1;
6192 else if (strcasecmp(val, "Disable") == 0)
6193 dut->ap_amsdu = 2;
6194 }
6195
6196 val = get_param(cmd, "NumMSDU");
6197 if (val) {
6198 send_resp(dut, conn, SIGMA_ERROR,
6199 "ErrorCode, NumMSDU is not supported yet");
6200 return -1;
6201 }
6202
6203 val = get_param(cmd, "ABFTLRang");
6204 if (val) {
6205 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006206 "ABFTLRang parameter %s", val);
6207 if (strcmp(val, "Gt1") == 0)
6208 abft_len = 2; /* 2 slots in this case */
6209 }
6210
6211 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6212 send_resp(dut, conn, SIGMA_ERROR,
6213 "ErrorCode, Can't set ABFT length");
6214 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006215 }
6216
6217 if (sta_pcp_start(dut, conn, cmd) < 0) {
6218 send_resp(dut, conn, SIGMA_ERROR,
6219 "ErrorCode, Can't start PCP role");
6220 return -1;
6221 }
6222
6223 return sta_set_60g_common(dut, conn, cmd);
6224}
6225
6226
6227static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6228 struct sigma_cmd *cmd)
6229{
6230 const char *val = get_param(cmd, "DiscoveryMode");
6231
6232 if (dut->dev_role != DEVROLE_STA) {
6233 send_resp(dut, conn, SIGMA_INVALID,
6234 "ErrorCode,Invalid DevRole");
6235 return 0;
6236 }
6237
6238 if (val) {
6239 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6240 /* Ignore Discovery mode till Driver expose API. */
6241#if 0
6242 if (strcasecmp(val, "1") == 0) {
6243 send_resp(dut, conn, SIGMA_INVALID,
6244 "ErrorCode,DiscoveryMode 1 not supported");
6245 return 0;
6246 }
6247
6248 if (strcasecmp(val, "0") == 0) {
6249 /* OK */
6250 } else {
6251 send_resp(dut, conn, SIGMA_INVALID,
6252 "ErrorCode,DiscoveryMode not supported");
6253 return 0;
6254 }
6255#endif
6256 }
6257
6258 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006259 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006260 return sta_set_60g_common(dut, conn, cmd);
6261}
6262
6263
Jouni Malinenf7222712019-06-13 01:50:21 +03006264static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6265 struct sigma_conn *conn,
6266 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006267{
6268 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006269 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306270
Jouni Malinened77e672018-01-10 16:45:13 +02006271 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006272 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006273 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306274 wpa_command(intf, "DISCONNECT");
6275 return 1;
6276 }
6277
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006278 disconnect_station(dut);
6279 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6280 * due to cached results. */
6281 wpa_command(intf, "SET ignore_old_scan_res 1");
6282 wpa_command(intf, "BSS_FLUSH");
6283 return 1;
6284}
6285
6286
Jouni Malinenf7222712019-06-13 01:50:21 +03006287static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6288 struct sigma_conn *conn,
6289 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006290{
6291 const char *intf = get_param(cmd, "Interface");
6292 const char *bssid = get_param(cmd, "bssid");
6293 const char *val = get_param(cmd, "CHANNEL");
6294 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306295 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306296 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006297 int res;
6298 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006299 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306300 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006301 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006302
6303 if (bssid == NULL) {
6304 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6305 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006306 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006307 }
6308
6309 if (val)
6310 chan = atoi(val);
6311
6312 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6313 /* The current network may be from sta_associate or
6314 * sta_hs2_associate
6315 */
6316 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6317 0 ||
6318 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006319 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006320 }
6321
6322 ctrl = open_wpa_mon(intf);
6323 if (ctrl == NULL) {
6324 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6325 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006326 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006327 }
6328
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006329 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306330 sizeof(result)) < 0 ||
6331 strncmp(result, "COMPLETED", 9) != 0) {
6332 sigma_dut_print(dut, DUT_MSG_DEBUG,
6333 "sta_reassoc: Not connected");
6334 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006335 } else if (dut->sta_ft_ds) {
6336 sigma_dut_print(dut, DUT_MSG_DEBUG,
6337 "sta_reassoc: Use FT-over-DS");
6338 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306339 }
6340
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306341 if (dut->rsne_override) {
6342#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006343 if (get_driver_type(dut) == DRIVER_WCN &&
6344 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306345 sta_config_rsnie(dut, 1);
6346 dut->config_rsnie = 1;
6347 }
6348#endif /* NL80211_SUPPORT */
6349 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6350 dut->rsne_override);
6351 if (wpa_command(intf, buf) < 0) {
6352 send_resp(dut, conn, SIGMA_ERROR,
6353 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6354 return 0;
6355 }
6356 }
6357
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006358 if (ft_ds) {
6359 if (chan) {
6360 unsigned int freq;
6361
6362 freq = channel_to_freq(dut, chan);
6363 if (!freq) {
6364 sigma_dut_print(dut, DUT_MSG_ERROR,
6365 "Invalid channel number provided: %d",
6366 chan);
6367 send_resp(dut, conn, SIGMA_INVALID,
6368 "ErrorCode,Invalid channel number");
6369 goto close_mon_conn;
6370 }
6371 res = snprintf(buf, sizeof(buf),
6372 "SCAN TYPE=ONLY freq=%d", freq);
6373 } else {
6374 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6375 }
6376 if (res < 0 || res >= (int) sizeof(buf)) {
6377 send_resp(dut, conn, SIGMA_ERROR,
6378 "ErrorCode,snprintf failed");
6379 goto close_mon_conn;
6380 }
6381 if (wpa_command(intf, buf) < 0) {
6382 sigma_dut_print(dut, DUT_MSG_INFO,
6383 "Failed to start scan");
6384 send_resp(dut, conn, SIGMA_ERROR,
6385 "ErrorCode,scan failed");
6386 goto close_mon_conn;
6387 }
6388
6389 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6390 buf, sizeof(buf));
6391 if (res < 0) {
6392 sigma_dut_print(dut, DUT_MSG_INFO,
6393 "Scan did not complete");
6394 send_resp(dut, conn, SIGMA_ERROR,
6395 "ErrorCode,scan did not complete");
6396 goto close_mon_conn;
6397 }
6398
6399 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6400 if (res > 0 && res < (int) sizeof(buf))
6401 res = wpa_command(intf, buf);
6402
6403 if (res < 0 || res >= (int) sizeof(buf)) {
6404 send_resp(dut, conn, SIGMA_ERROR,
6405 "errorCode,FT_DS command failed");
6406 status = STATUS_SENT_ERROR;
6407 goto close_mon_conn;
6408 }
6409 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306410 if (chan) {
6411 unsigned int freq;
6412
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006413 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306414 if (!freq) {
6415 sigma_dut_print(dut, DUT_MSG_ERROR,
6416 "Invalid channel number provided: %d",
6417 chan);
6418 send_resp(dut, conn, SIGMA_INVALID,
6419 "ErrorCode,Invalid channel number");
6420 goto close_mon_conn;
6421 }
6422 res = snprintf(buf, sizeof(buf),
6423 "SCAN TYPE=ONLY freq=%d", freq);
6424 } else {
6425 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6426 }
6427 if (res < 0 || res >= (int) sizeof(buf)) {
6428 send_resp(dut, conn, SIGMA_ERROR,
6429 "ErrorCode,snprintf failed");
6430 goto close_mon_conn;
6431 }
6432 if (wpa_command(intf, buf) < 0) {
6433 sigma_dut_print(dut, DUT_MSG_INFO,
6434 "Failed to start scan");
6435 send_resp(dut, conn, SIGMA_ERROR,
6436 "ErrorCode,scan failed");
6437 goto close_mon_conn;
6438 }
6439
6440 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6441 buf, sizeof(buf));
6442 if (res < 0) {
6443 sigma_dut_print(dut, DUT_MSG_INFO,
6444 "Scan did not complete");
6445 send_resp(dut, conn, SIGMA_ERROR,
6446 "ErrorCode,scan did not complete");
6447 goto close_mon_conn;
6448 }
6449
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006450 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6451 < 0) {
6452 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6453 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006454 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306455 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006456 }
6457 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6458 bssid, chan);
6459 if (res > 0 && res < (int) sizeof(buf))
6460 res = wpa_command(intf, buf);
6461
6462 if (res < 0 || res >= (int) sizeof(buf)) {
6463 send_resp(dut, conn, SIGMA_ERROR,
6464 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306465 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006466 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006467 sigma_dut_print(dut, DUT_MSG_INFO,
6468 "sta_reassoc: Run %s successful", buf);
6469 } else if (wpa_command(intf, "REASSOCIATE")) {
6470 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6471 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306472 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006473 }
6474
6475 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6476 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306477 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006478 send_resp(dut, conn, SIGMA_ERROR,
6479 "errorCode,Connection did not complete");
6480 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306481 goto close_mon_conn;
6482 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006483 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006484
Ashwini Patil467efef2017-05-25 12:18:27 +05306485close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006486 wpa_ctrl_detach(ctrl);
6487 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306488 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006489}
6490
6491
6492static void hs2_clear_credentials(const char *intf)
6493{
6494 wpa_command(intf, "REMOVE_CRED all");
6495}
6496
6497
Lior Davidcc88b562017-01-03 18:52:09 +02006498#ifdef __linux__
6499static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6500 unsigned int *aid)
6501{
Lior David0fe101e2017-03-09 16:09:50 +02006502 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006503
Lior David0fe101e2017-03-09 16:09:50 +02006504 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006505}
6506#endif /* __linux__ */
6507
6508
6509static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6510 unsigned int *aid)
6511{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006512 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006513#ifdef __linux__
6514 case DRIVER_WIL6210:
6515 return wil6210_get_aid(dut, bssid, aid);
6516#endif /* __linux__ */
6517 default:
6518 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6519 return -1;
6520 }
6521}
6522
6523
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006524static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6525 struct sigma_cmd *cmd)
6526{
6527 char buf[MAX_CMD_LEN];
6528 char bss_list[MAX_CMD_LEN];
6529 const char *parameter = get_param(cmd, "Parameter");
6530
6531 if (parameter == NULL)
6532 return -1;
6533
Lior Davidcc88b562017-01-03 18:52:09 +02006534 if (strcasecmp(parameter, "AID") == 0) {
6535 unsigned int aid = 0;
6536 char bssid[20];
6537
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006538 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006539 bssid, sizeof(bssid)) < 0) {
6540 sigma_dut_print(dut, DUT_MSG_ERROR,
6541 "could not get bssid");
6542 return -2;
6543 }
6544
6545 if (sta_get_aid_60g(dut, bssid, &aid))
6546 return -2;
6547
6548 snprintf(buf, sizeof(buf), "aid,%d", aid);
6549 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6550 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6551 return 0;
6552 }
6553
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006554 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6555 char *bss_line;
6556 char *bss_id = NULL;
6557 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306558 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006559
6560 if (ifname == NULL) {
6561 sigma_dut_print(dut, DUT_MSG_INFO,
6562 "For get DiscoveredDevList need Interface name.");
6563 return -1;
6564 }
6565
6566 /*
6567 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6568 * of BSSIDs in "bssid=<BSSID>\n"
6569 */
6570 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6571 bss_list,
6572 sizeof(bss_list)) < 0) {
6573 sigma_dut_print(dut, DUT_MSG_ERROR,
6574 "Failed to get bss list");
6575 return -1;
6576 }
6577
6578 sigma_dut_print(dut, DUT_MSG_DEBUG,
6579 "bss list for ifname:%s is:%s",
6580 ifname, bss_list);
6581
6582 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306583 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006584 while (bss_line) {
6585 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6586 bss_id) {
6587 int len;
6588
6589 len = snprintf(buf + strlen(buf),
6590 sizeof(buf) - strlen(buf),
6591 ",%s", bss_id);
6592 free(bss_id);
6593 bss_id = NULL;
6594 if (len < 0) {
6595 sigma_dut_print(dut,
6596 DUT_MSG_ERROR,
6597 "Failed to read BSSID");
6598 send_resp(dut, conn, SIGMA_ERROR,
6599 "ErrorCode,Failed to read BSS ID");
6600 return 0;
6601 }
6602
6603 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6604 sigma_dut_print(dut,
6605 DUT_MSG_ERROR,
6606 "Response buf too small for list");
6607 send_resp(dut, conn,
6608 SIGMA_ERROR,
6609 "ErrorCode,Response buf too small for list");
6610 return 0;
6611 }
6612 }
6613
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306614 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006615 }
6616
6617 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6618 buf);
6619 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6620 return 0;
6621 }
6622
6623 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6624 return 0;
6625}
6626
6627
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006628static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6629 struct sigma_cmd *cmd)
6630{
6631 char buf[MAX_CMD_LEN];
6632 const char *parameter = get_param(cmd, "Parameter");
6633
6634 if (!parameter)
6635 return -1;
6636
6637 if (strcasecmp(parameter, "RSSI") == 0) {
6638 char rssi[10];
6639
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006640 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006641 rssi, sizeof(rssi)) < 0) {
6642 sigma_dut_print(dut, DUT_MSG_ERROR,
6643 "Could not get RSSI");
6644 return -2;
6645 }
6646
6647 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6648 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6649 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6650 return 0;
6651 }
6652
6653 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6654 return 0;
6655}
6656
6657
Jouni Malinenca0abd32020-02-09 20:18:10 +02006658static enum sigma_cmd_result sta_get_pmk(struct sigma_dut *dut,
6659 struct sigma_conn *conn,
6660 struct sigma_cmd *cmd)
6661{
6662 const char *intf = get_param(cmd, "Interface");
6663 char buf[4096], bssid[20], resp[200], *pos, *tmp;
6664
6665 snprintf(buf, sizeof(buf), "PMKSA_GET %d", dut->infra_network_id);
6666 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
6667 strncmp(buf, "UNKNOWN COMMAND", 15) == 0) {
6668 send_resp(dut, conn, SIGMA_ERROR,
6669 "ErrorCode,PMKSA_GET not supported");
6670 return STATUS_SENT_ERROR;
6671 }
6672
6673 if (strncmp(buf, "FAIL", 4) == 0 ||
6674 get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
6675 send_resp(dut, conn, SIGMA_ERROR,
6676 "ErrorCode,Could not find current network");
6677 return STATUS_SENT_ERROR;
6678 }
6679
6680 pos = buf;
6681 while (pos) {
6682 if (strncmp(pos, bssid, 17) == 0) {
6683 pos = strchr(pos, ' ');
6684 if (!pos)
6685 goto fail;
6686 pos++;
6687 pos = strchr(pos, ' ');
6688 if (!pos)
6689 goto fail;
6690 pos++;
6691 tmp = strchr(pos, ' ');
6692 if (!tmp)
6693 goto fail;
6694 *tmp = '\0';
6695 break;
6696 }
6697
6698 fail:
6699 pos = strchr(pos, '\n');
6700 if (pos)
6701 pos++;
6702 }
6703
6704 if (!pos) {
6705 send_resp(dut, conn, SIGMA_ERROR,
6706 "ErrorCode,PMK not available");
6707 return STATUS_SENT_ERROR;
6708 }
6709
6710 snprintf(resp, sizeof(resp), "PMK,%s", pos);
6711 send_resp(dut, conn, SIGMA_COMPLETE, resp);
6712 return STATUS_SENT;
6713}
6714
6715
Jouni Malinenf7222712019-06-13 01:50:21 +03006716static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6717 struct sigma_conn *conn,
6718 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006719{
6720 const char *program = get_param(cmd, "Program");
Jouni Malinenca0abd32020-02-09 20:18:10 +02006721 const char *parameter = get_param(cmd, "Parameter");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006722
Jouni Malinenca0abd32020-02-09 20:18:10 +02006723 if (!parameter)
6724 return INVALID_SEND_STATUS;
6725
6726 if (strcasecmp(parameter, "PMK") == 0)
6727 return sta_get_pmk(dut, conn, cmd);
6728
6729 if (!program)
6730 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006731
6732 if (strcasecmp(program, "P2PNFC") == 0)
6733 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6734
6735 if (strcasecmp(program, "60ghz") == 0)
6736 return sta_get_parameter_60g(dut, conn, cmd);
6737
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006738 if (strcasecmp(program, "he") == 0)
6739 return sta_get_parameter_he(dut, conn, cmd);
6740
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006741#ifdef ANDROID_NAN
6742 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006743 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006744#endif /* ANDROID_NAN */
6745
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006746#ifdef MIRACAST
6747 if (strcasecmp(program, "WFD") == 0 ||
6748 strcasecmp(program, "DisplayR2") == 0)
6749 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6750#endif /* MIRACAST */
6751
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006752 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6753 return 0;
6754}
6755
6756
6757static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6758 const char *type)
6759{
6760 char buf[100];
6761
6762 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006763 run_iwpriv(dut, intf, "chwidth 2");
6764 run_iwpriv(dut, intf, "mode 11ACVHT80");
6765 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006766 }
6767
6768 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006769 run_iwpriv(dut, intf, "chwidth 0");
6770 run_iwpriv(dut, intf, "mode 11naht40");
6771 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006772 }
6773
6774 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006775 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006776
6777 /* Reset CTS width */
6778 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6779 intf);
6780 if (system(buf) != 0) {
6781 sigma_dut_print(dut, DUT_MSG_ERROR,
6782 "wifitool %s beeliner_fw_test 54 0 failed",
6783 intf);
6784 }
6785
6786 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006787 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006788
6789 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6790 if (system(buf) != 0) {
6791 sigma_dut_print(dut, DUT_MSG_ERROR,
6792 "iwpriv rts failed");
6793 }
6794 }
6795
6796 if (type && strcasecmp(type, "Testbed") == 0) {
6797 dut->testbed_flag_txsp = 1;
6798 dut->testbed_flag_rxsp = 1;
6799 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006800 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006801
6802 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006803 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006804
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006805 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006806
6807 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006808 run_iwpriv(dut, intf, "tx_stbc 0");
6809 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006810
6811 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006812 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006813 }
6814
6815 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006816 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006817 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006818
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006819 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006820 }
6821}
6822
6823
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006824#ifdef NL80211_SUPPORT
6825static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6826 enum he_mcs_config mcs)
6827{
6828 struct nl_msg *msg;
6829 int ret = 0;
6830 struct nlattr *params;
6831 int ifindex;
6832
6833 ifindex = if_nametoindex(intf);
6834 if (ifindex == 0) {
6835 sigma_dut_print(dut, DUT_MSG_ERROR,
6836 "%s: Index for interface %s failed",
6837 __func__, intf);
6838 return -1;
6839 }
6840
6841 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6842 NL80211_CMD_VENDOR)) ||
6843 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6844 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6845 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6846 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6847 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6848 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6849 mcs)) {
6850 sigma_dut_print(dut, DUT_MSG_ERROR,
6851 "%s: err in adding vendor_cmd and vendor_data",
6852 __func__);
6853 nlmsg_free(msg);
6854 return -1;
6855 }
6856 nla_nest_end(msg, params);
6857
6858 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6859 if (ret) {
6860 sigma_dut_print(dut, DUT_MSG_ERROR,
6861 "%s: err in send_and_recv_msgs, ret=%d",
6862 __func__, ret);
6863 }
6864 return ret;
6865}
6866#endif /* NL80211_SUPPORT */
6867
6868
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006869static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6870 const char *intf, int enable)
6871{
6872#ifdef NL80211_SUPPORT
6873 struct nl_msg *msg;
6874 int ret = 0;
6875 struct nlattr *params;
6876 int ifindex;
6877
6878 ifindex = if_nametoindex(intf);
6879 if (ifindex == 0) {
6880 sigma_dut_print(dut, DUT_MSG_ERROR,
6881 "%s: Index for interface %s failed",
6882 __func__, intf);
6883 return -1;
6884 }
6885
6886 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6887 NL80211_CMD_VENDOR)) ||
6888 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6889 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6890 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6891 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6892 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6893 nla_put_u8(msg,
6894 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6895 enable)) {
6896 sigma_dut_print(dut, DUT_MSG_ERROR,
6897 "%s: err in adding vendor_cmd and vendor_data",
6898 __func__);
6899 nlmsg_free(msg);
6900 return -1;
6901 }
6902 nla_nest_end(msg, params);
6903
6904 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6905 if (ret) {
6906 sigma_dut_print(dut, DUT_MSG_ERROR,
6907 "%s: err in send_and_recv_msgs, ret=%d",
6908 __func__, ret);
6909 }
6910 return ret;
6911#else /* NL80211_SUPPORT */
6912 sigma_dut_print(dut, DUT_MSG_ERROR,
6913 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6914 return -1;
6915#endif /* NL80211_SUPPORT */
6916}
6917
6918
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006919static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6920 const char *intf, int enable)
6921{
6922#ifdef NL80211_SUPPORT
6923 struct nl_msg *msg;
6924 int ret = 0;
6925 struct nlattr *params;
6926 int ifindex;
6927
6928 ifindex = if_nametoindex(intf);
6929 if (ifindex == 0) {
6930 sigma_dut_print(dut, DUT_MSG_ERROR,
6931 "%s: Index for interface %s failed",
6932 __func__, intf);
6933 return -1;
6934 }
6935
6936 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6937 NL80211_CMD_VENDOR)) ||
6938 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6939 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6940 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6941 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6942 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6943 nla_put_u8(msg,
6944 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6945 enable)) {
6946 sigma_dut_print(dut, DUT_MSG_ERROR,
6947 "%s: err in adding vendor_cmd and vendor_data",
6948 __func__);
6949 nlmsg_free(msg);
6950 return -1;
6951 }
6952 nla_nest_end(msg, params);
6953
6954 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6955 if (ret) {
6956 sigma_dut_print(dut, DUT_MSG_ERROR,
6957 "%s: err in send_and_recv_msgs, ret=%d",
6958 __func__, ret);
6959 }
6960 return ret;
6961#else /* NL80211_SUPPORT */
6962 sigma_dut_print(dut, DUT_MSG_ERROR,
6963 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6964 return -1;
6965#endif /* NL80211_SUPPORT */
6966}
6967
6968
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006969#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006970
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006971static int sta_set_he_testbed_def(struct sigma_dut *dut,
6972 const char *intf, int cfg)
6973{
6974 struct nl_msg *msg;
6975 int ret = 0;
6976 struct nlattr *params;
6977 int ifindex;
6978
6979 ifindex = if_nametoindex(intf);
6980 if (ifindex == 0) {
6981 sigma_dut_print(dut, DUT_MSG_ERROR,
6982 "%s: Index for interface %s failed",
6983 __func__, intf);
6984 return -1;
6985 }
6986
6987 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6988 NL80211_CMD_VENDOR)) ||
6989 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6990 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6991 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6992 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6993 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6994 nla_put_u8(msg,
6995 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6996 cfg)) {
6997 sigma_dut_print(dut, DUT_MSG_ERROR,
6998 "%s: err in adding vendor_cmd and vendor_data",
6999 __func__);
7000 nlmsg_free(msg);
7001 return -1;
7002 }
7003 nla_nest_end(msg, params);
7004
7005 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7006 if (ret) {
7007 sigma_dut_print(dut, DUT_MSG_ERROR,
7008 "%s: err in send_and_recv_msgs, ret=%d",
7009 __func__, ret);
7010 }
7011 return ret;
7012}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007013
7014
7015static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
7016{
7017 struct nl_msg *msg;
7018 int ret = 0;
7019 struct nlattr *params;
7020 int ifindex;
7021
7022 ifindex = if_nametoindex(intf);
7023 if (ifindex == 0) {
7024 sigma_dut_print(dut, DUT_MSG_ERROR,
7025 "%s: Index for interface %s failed",
7026 __func__, intf);
7027 return -1;
7028 }
7029
7030 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7031 NL80211_CMD_VENDOR)) ||
7032 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7033 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7034 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7035 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7036 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7037 nla_put_u8(msg,
7038 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
7039 cfg)) {
7040 sigma_dut_print(dut, DUT_MSG_ERROR,
7041 "%s: err in adding vendor_cmd and vendor_data",
7042 __func__);
7043 nlmsg_free(msg);
7044 return -1;
7045 }
7046 nla_nest_end(msg, params);
7047
7048 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7049 if (ret) {
7050 sigma_dut_print(dut, DUT_MSG_ERROR,
7051 "%s: err in send_and_recv_msgs, ret=%d",
7052 __func__, ret);
7053 }
7054 return ret;
7055}
7056
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007057#endif /* NL80211_SUPPORT */
7058
7059
Qiwei Caib6806972020-01-15 13:52:11 +08007060int sta_set_addba_buf_size(struct sigma_dut *dut,
7061 const char *intf, int bufsize)
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007062{
7063#ifdef NL80211_SUPPORT
7064 struct nl_msg *msg;
7065 int ret = 0;
7066 struct nlattr *params;
7067 int ifindex;
7068
7069 ifindex = if_nametoindex(intf);
7070 if (ifindex == 0) {
7071 sigma_dut_print(dut, DUT_MSG_ERROR,
7072 "%s: Index for interface %s failed",
7073 __func__, intf);
7074 return -1;
7075 }
7076
7077 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7078 NL80211_CMD_VENDOR)) ||
7079 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7080 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7081 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7082 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7083 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007084 nla_put_u16(msg,
7085 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7086 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007087 sigma_dut_print(dut, DUT_MSG_ERROR,
7088 "%s: err in adding vendor_cmd and vendor_data",
7089 __func__);
7090 nlmsg_free(msg);
7091 return -1;
7092 }
7093 nla_nest_end(msg, params);
7094
7095 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7096 if (ret) {
7097 sigma_dut_print(dut, DUT_MSG_ERROR,
7098 "%s: err in send_and_recv_msgs, ret=%d",
7099 __func__, ret);
7100 }
7101 return ret;
7102#else /* NL80211_SUPPORT */
7103 sigma_dut_print(dut, DUT_MSG_ERROR,
7104 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
7105 return -1;
7106#endif /* NL80211_SUPPORT */
7107}
7108
7109
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007110static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
7111 int enable)
7112{
7113#ifdef NL80211_SUPPORT
7114 struct nl_msg *msg;
7115 int ret = 0;
7116 struct nlattr *params;
7117 int ifindex;
7118
7119 ifindex = if_nametoindex(intf);
7120 if (ifindex == 0) {
7121 sigma_dut_print(dut, DUT_MSG_ERROR,
7122 "%s: Index for interface %s failed",
7123 __func__, intf);
7124 return -1;
7125 }
7126
7127 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7128 NL80211_CMD_VENDOR)) ||
7129 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7130 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7131 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7132 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7133 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7134 nla_put_u8(msg,
7135 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7136 enable)) {
7137 sigma_dut_print(dut, DUT_MSG_ERROR,
7138 "%s: err in adding vendor_cmd and vendor_data",
7139 __func__);
7140 nlmsg_free(msg);
7141 return -1;
7142 }
7143 nla_nest_end(msg, params);
7144
7145 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7146 if (ret) {
7147 sigma_dut_print(dut, DUT_MSG_ERROR,
7148 "%s: err in send_and_recv_msgs, ret=%d",
7149 __func__, ret);
7150 }
7151 return ret;
7152#else /* NL80211_SUPPORT */
7153 sigma_dut_print(dut, DUT_MSG_ERROR,
7154 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7155 return -1;
7156#endif /* NL80211_SUPPORT */
7157}
7158
7159
Arif Hussain9765f7d2018-07-03 08:28:26 -07007160static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7161 int val)
7162{
7163#ifdef NL80211_SUPPORT
7164 struct nl_msg *msg;
7165 int ret = 0;
7166 struct nlattr *params;
7167 int ifindex;
7168
7169 ifindex = if_nametoindex(intf);
7170 if (ifindex == 0) {
7171 sigma_dut_print(dut, DUT_MSG_ERROR,
7172 "%s: Index for interface %s failed, val:%d",
7173 __func__, intf, val);
7174 return -1;
7175 }
7176
7177 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7178 NL80211_CMD_VENDOR)) ||
7179 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7180 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7181 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7182 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7183 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7184 nla_put_u8(msg,
7185 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7186 val)) {
7187 sigma_dut_print(dut, DUT_MSG_ERROR,
7188 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7189 __func__, val);
7190 nlmsg_free(msg);
7191 return -1;
7192 }
7193 nla_nest_end(msg, params);
7194
7195 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7196 if (ret) {
7197 sigma_dut_print(dut, DUT_MSG_ERROR,
7198 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7199 __func__, ret, val);
7200 }
7201 return ret;
7202#else /* NL80211_SUPPORT */
7203 sigma_dut_print(dut, DUT_MSG_ERROR,
7204 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7205 return -1;
7206#endif /* NL80211_SUPPORT */
7207}
7208
7209
Arif Hussain68d23f52018-07-11 13:39:08 -07007210#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007211static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7212 enum qca_wlan_he_mac_padding_dur val)
7213{
Arif Hussain68d23f52018-07-11 13:39:08 -07007214 struct nl_msg *msg;
7215 int ret = 0;
7216 struct nlattr *params;
7217 int ifindex;
7218
7219 ifindex = if_nametoindex(intf);
7220 if (ifindex == 0) {
7221 sigma_dut_print(dut, DUT_MSG_ERROR,
7222 "%s: Index for interface %s failed, val:%d",
7223 __func__, intf, val);
7224 return -1;
7225 }
7226
7227 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7228 NL80211_CMD_VENDOR)) ||
7229 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7230 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7231 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7232 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7233 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7234 nla_put_u8(msg,
7235 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7236 val)) {
7237 sigma_dut_print(dut, DUT_MSG_ERROR,
7238 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7239 __func__, val);
7240 nlmsg_free(msg);
7241 return -1;
7242 }
7243 nla_nest_end(msg, params);
7244
7245 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7246 if (ret) {
7247 sigma_dut_print(dut, DUT_MSG_ERROR,
7248 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7249 __func__, ret, val);
7250 }
7251 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007252}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007253#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007254
7255
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007256static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7257 int val)
7258{
7259#ifdef NL80211_SUPPORT
7260 struct nl_msg *msg;
7261 int ret = 0;
7262 struct nlattr *params;
7263 int ifindex;
7264
7265 ifindex = if_nametoindex(intf);
7266 if (ifindex == 0) {
7267 sigma_dut_print(dut, DUT_MSG_ERROR,
7268 "%s: Index for interface %s failed, val:%d",
7269 __func__, intf, val);
7270 return -1;
7271 }
7272
7273 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7274 NL80211_CMD_VENDOR)) ||
7275 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7276 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7277 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7278 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7279 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7280 nla_put_u8(msg,
7281 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7282 val)) {
7283 sigma_dut_print(dut, DUT_MSG_ERROR,
7284 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7285 __func__, val);
7286 nlmsg_free(msg);
7287 return -1;
7288 }
7289 nla_nest_end(msg, params);
7290
7291 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7292 if (ret) {
7293 sigma_dut_print(dut, DUT_MSG_ERROR,
7294 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7295 __func__, ret, val);
7296 }
7297 return ret;
7298#else /* NL80211_SUPPORT */
7299 sigma_dut_print(dut, DUT_MSG_ERROR,
7300 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7301 return -1;
7302#endif /* NL80211_SUPPORT */
7303}
7304
7305
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007306#ifdef NL80211_SUPPORT
7307static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7308{
7309 struct nl_msg *msg;
7310 int ret = 0;
7311 struct nlattr *params;
7312 int ifindex;
7313
7314 ifindex = if_nametoindex(intf);
7315 if (ifindex == 0) {
7316 sigma_dut_print(dut, DUT_MSG_ERROR,
7317 "%s: Index for interface %s failed",
7318 __func__, intf);
7319 return -1;
7320 }
7321
7322 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7323 NL80211_CMD_VENDOR)) ||
7324 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7325 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7326 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7327 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7328 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7329 nla_put_flag(msg,
7330 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7331 sigma_dut_print(dut, DUT_MSG_ERROR,
7332 "%s: err in adding vendor_cmd and vendor_data",
7333 __func__);
7334 nlmsg_free(msg);
7335 return -1;
7336 }
7337 nla_nest_end(msg, params);
7338
7339 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7340 if (ret) {
7341 sigma_dut_print(dut, DUT_MSG_ERROR,
7342 "%s: err in send_and_recv_msgs, ret=%d",
7343 __func__, ret);
7344 }
7345 return ret;
7346}
7347#endif /* NL80211_SUPPORT */
7348
7349
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007350static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7351 int val)
7352{
7353#ifdef NL80211_SUPPORT
7354 struct nl_msg *msg;
7355 int ret = 0;
7356 struct nlattr *params;
7357 int ifindex;
7358
7359 ifindex = if_nametoindex(intf);
7360 if (ifindex == 0) {
7361 sigma_dut_print(dut, DUT_MSG_ERROR,
7362 "%s: Index for interface %s failed, val:%d",
7363 __func__, intf, val);
7364 return -1;
7365 }
7366
7367 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7368 NL80211_CMD_VENDOR)) ||
7369 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7370 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7371 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7372 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7373 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7374 nla_put_u8(msg,
7375 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7376 val)) {
7377 sigma_dut_print(dut, DUT_MSG_ERROR,
7378 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7379 __func__, val);
7380 nlmsg_free(msg);
7381 return -1;
7382 }
7383 nla_nest_end(msg, params);
7384
7385 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7386 if (ret) {
7387 sigma_dut_print(dut, DUT_MSG_ERROR,
7388 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7389 __func__, ret, val);
7390 }
7391 return ret;
7392#else /* NL80211_SUPPORT */
7393 sigma_dut_print(dut, DUT_MSG_ERROR,
7394 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7395 return -1;
7396#endif /* NL80211_SUPPORT */
7397}
7398
7399
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007400static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7401 int val)
7402{
7403#ifdef NL80211_SUPPORT
7404 struct nl_msg *msg;
7405 int ret = 0;
7406 struct nlattr *params;
7407 int ifindex;
7408
7409 ifindex = if_nametoindex(intf);
7410 if (ifindex == 0) {
7411 sigma_dut_print(dut, DUT_MSG_ERROR,
7412 "%s: Index for interface %s failed, val:%d",
7413 __func__, intf, val);
7414 return -1;
7415 }
7416
7417 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7418 NL80211_CMD_VENDOR)) ||
7419 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7420 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7421 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7422 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7423 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7424 nla_put_u8(msg,
7425 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7426 val)) {
7427 sigma_dut_print(dut, DUT_MSG_ERROR,
7428 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7429 __func__, val);
7430 nlmsg_free(msg);
7431 return -1;
7432 }
7433 nla_nest_end(msg, params);
7434
7435 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7436 if (ret) {
7437 sigma_dut_print(dut, DUT_MSG_ERROR,
7438 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7439 __func__, ret, val);
7440 }
7441 return ret;
7442#else /* NL80211_SUPPORT */
7443 sigma_dut_print(dut, DUT_MSG_ERROR,
7444 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7445 return -1;
7446#endif /* NL80211_SUPPORT */
7447}
7448
7449
Arif Hussain480d5f42019-03-12 14:40:42 -07007450static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7451 int val)
7452{
7453#ifdef NL80211_SUPPORT
7454 struct nl_msg *msg;
7455 int ret;
7456 struct nlattr *params;
7457 int ifindex;
7458
7459 ifindex = if_nametoindex(intf);
7460 if (ifindex == 0) {
7461 sigma_dut_print(dut, DUT_MSG_ERROR,
7462 "%s: Index for interface %s failed, val:%d",
7463 __func__, intf, val);
7464 return -1;
7465 }
7466
7467 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7468 NL80211_CMD_VENDOR)) ||
7469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7470 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7471 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7472 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7473 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7474 nla_put_u8(msg,
7475 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7476 val)) {
7477 sigma_dut_print(dut, DUT_MSG_ERROR,
7478 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7479 __func__, val);
7480 nlmsg_free(msg);
7481 return -1;
7482 }
7483 nla_nest_end(msg, params);
7484
7485 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7486 if (ret) {
7487 sigma_dut_print(dut, DUT_MSG_ERROR,
7488 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7489 __func__, ret, val);
7490 }
7491 return ret;
7492#else /* NL80211_SUPPORT */
7493 sigma_dut_print(dut, DUT_MSG_ERROR,
7494 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7495 return -1;
7496#endif /* NL80211_SUPPORT */
7497}
7498
7499
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007500static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7501 const char *type)
7502{
7503 char buf[60];
7504
7505 if (dut->program == PROGRAM_HE) {
7506 /* resetting phymode to auto in case of HE program */
7507 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7508 if (system(buf) != 0) {
7509 sigma_dut_print(dut, DUT_MSG_ERROR,
7510 "iwpriv %s setphymode failed", intf);
7511 }
7512
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007513 /* reset the rate to Auto rate */
7514 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7515 intf);
7516 if (system(buf) != 0) {
7517 sigma_dut_print(dut, DUT_MSG_ERROR,
7518 "iwpriv %s set_11ax_rate 0xff failed",
7519 intf);
7520 }
7521
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007522 /* reset the LDPC setting */
7523 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7524 if (system(buf) != 0) {
7525 sigma_dut_print(dut, DUT_MSG_ERROR,
7526 "iwpriv %s ldpc 1 failed", intf);
7527 }
7528
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007529 /* reset the power save setting */
7530 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7531 if (system(buf) != 0) {
7532 sigma_dut_print(dut, DUT_MSG_ERROR,
7533 "iwpriv %s setPower 2 failed", intf);
7534 }
7535
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007536 /* remove all network profiles */
7537 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007538
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007539 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7540 sta_set_addba_buf_size(dut, intf, 64);
7541
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007542#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007543 /* Reset the device HE capabilities to its default supported
7544 * configuration. */
7545 sta_set_he_testbed_def(dut, intf, 0);
7546
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007547 /* Disable noackpolicy for all AC */
7548 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7549 sigma_dut_print(dut, DUT_MSG_ERROR,
7550 "Disable of noackpolicy for all AC failed");
7551 }
7552#endif /* NL80211_SUPPORT */
7553
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007554 /* Enable WMM by default */
7555 if (wcn_sta_set_wmm(dut, intf, "on")) {
7556 sigma_dut_print(dut, DUT_MSG_ERROR,
7557 "Enable of WMM in sta_reset_default_wcn failed");
7558 }
7559
7560 /* Disable ADDBA_REJECT by default */
7561 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7562 sigma_dut_print(dut, DUT_MSG_ERROR,
7563 "Disable of addba_reject in sta_reset_default_wcn failed");
7564 }
7565
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007566 /* Enable sending of ADDBA by default */
7567 if (nlvendor_config_send_addba(dut, intf, 1)) {
7568 sigma_dut_print(dut, DUT_MSG_ERROR,
7569 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7570 }
7571
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007572 /* Enable AMPDU by default */
7573 iwpriv_sta_set_ampdu(dut, intf, 1);
7574
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007575#ifdef NL80211_SUPPORT
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -08007576 if (wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007577 sigma_dut_print(dut, DUT_MSG_ERROR,
7578 "Set LTF config to default in sta_reset_default_wcn failed");
7579 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007580
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007581 /* set the beamformee NSTS(maximum number of
7582 * space-time streams) to default DUT config
7583 */
7584 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007585 sigma_dut_print(dut, DUT_MSG_ERROR,
7586 "Failed to set BeamformeeSTS");
7587 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007588
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007589 if (sta_set_mac_padding_duration(
7590 dut, intf,
7591 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007592 sigma_dut_print(dut, DUT_MSG_ERROR,
7593 "Failed to set MAC padding duration");
7594 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007595
7596 if (sta_set_mu_edca_override(dut, intf, 0)) {
7597 sigma_dut_print(dut, DUT_MSG_ERROR,
7598 "ErrorCode,Failed to set MU EDCA override disable");
7599 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007600
7601 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7602 sigma_dut_print(dut, DUT_MSG_ERROR,
7603 "Failed to set OM ctrl supp");
7604 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007605
7606 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7607 sigma_dut_print(dut, DUT_MSG_ERROR,
7608 "Failed to set Tx SU PPDU enable");
7609 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007610
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007611 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7612 sigma_dut_print(dut, DUT_MSG_ERROR,
7613 "failed to send TB PPDU Tx cfg");
7614 }
7615
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007616 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7617 sigma_dut_print(dut, DUT_MSG_ERROR,
7618 "Failed to set OM ctrl reset");
7619 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007620
7621 /* +HTC-HE support default on */
7622 if (sta_set_he_htc_supp(dut, intf, 1)) {
7623 sigma_dut_print(dut, DUT_MSG_ERROR,
7624 "Setting of +HTC-HE support failed");
7625 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007626#endif /* NL80211_SUPPORT */
7627
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007628 if (sta_set_tx_beamformee(dut, intf, 1)) {
7629 sigma_dut_print(dut, DUT_MSG_ERROR,
7630 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7631 }
7632
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007633 /* Set nss to 1 and MCS 0-7 in case of testbed */
7634 if (type && strcasecmp(type, "Testbed") == 0) {
7635#ifdef NL80211_SUPPORT
7636 int ret;
7637#endif /* NL80211_SUPPORT */
7638
7639 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7640 if (system(buf) != 0) {
7641 sigma_dut_print(dut, DUT_MSG_ERROR,
7642 "iwpriv %s nss failed", intf);
7643 }
7644
7645#ifdef NL80211_SUPPORT
7646 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7647 if (ret) {
7648 sigma_dut_print(dut, DUT_MSG_ERROR,
7649 "Setting of MCS failed, ret:%d",
7650 ret);
7651 }
7652#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007653
7654 /* Disable STBC as default */
7655 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007656
7657 /* Disable AMSDU as default */
7658 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007659
7660#ifdef NL80211_SUPPORT
7661 /* HE fragmentation default off */
7662 if (sta_set_he_fragmentation(dut, intf,
7663 HE_FRAG_DISABLE)) {
7664 sigma_dut_print(dut, DUT_MSG_ERROR,
7665 "Setting of HE fragmentation failed");
7666 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007667
7668 /* set the beamformee NSTS(maximum number of
7669 * space-time streams) to default testbed config
7670 */
7671 if (sta_set_beamformee_sts(dut, intf, 3)) {
7672 sigma_dut_print(dut, DUT_MSG_ERROR,
7673 "Failed to set BeamformeeSTS");
7674 }
7675
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007676 /* +HTC-HE support default off */
7677 if (sta_set_he_htc_supp(dut, intf, 0)) {
7678 sigma_dut_print(dut, DUT_MSG_ERROR,
7679 "Setting of +HTC-HE support failed");
7680 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007681
7682 /* Set device HE capabilities to testbed default
7683 * configuration. */
7684 if (sta_set_he_testbed_def(dut, intf, 1)) {
7685 sigma_dut_print(dut, DUT_MSG_DEBUG,
7686 "Failed to set HE defaults");
7687 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007688
7689 /* Disable VHT support in 2.4 GHz for testbed */
7690 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007691#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007692
7693 /* Enable WEP/TKIP with HE capability in testbed */
7694 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7695 sigma_dut_print(dut, DUT_MSG_ERROR,
7696 "Enabling HE config with WEP/TKIP failed");
7697 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007698 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007699
7700 /* Defaults in case of DUT */
7701 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007702 /* Enable STBC by default */
7703 wcn_sta_set_stbc(dut, intf, "1");
7704
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007705 /* set nss to 2 */
7706 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7707 if (system(buf) != 0) {
7708 sigma_dut_print(dut, DUT_MSG_ERROR,
7709 "iwpriv %s nss 2 failed", intf);
7710 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007711 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007712
7713#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007714 /* Set HE_MCS to 0-11 */
7715 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007716 sigma_dut_print(dut, DUT_MSG_ERROR,
7717 "Setting of MCS failed");
7718 }
7719#endif /* NL80211_SUPPORT */
7720
7721 /* Disable WEP/TKIP with HE capability in DUT */
7722 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7723 sigma_dut_print(dut, DUT_MSG_ERROR,
7724 "Enabling HE config with WEP/TKIP failed");
7725 }
7726 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007727 }
7728}
7729
7730
Jouni Malinenf7222712019-06-13 01:50:21 +03007731static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7732 struct sigma_conn *conn,
7733 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007734{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007735 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007736 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007737 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007738 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307739 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007740
Jouni Malinenb21f0542019-11-04 17:53:38 +02007741 if (dut->station_ifname_2g &&
7742 strcmp(dut->station_ifname_2g, intf) == 0)
7743 dut->use_5g = 0;
7744 else if (dut->station_ifname_5g &&
7745 strcmp(dut->station_ifname_5g, intf) == 0)
7746 dut->use_5g = 1;
7747
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007748 if (!program)
7749 program = get_param(cmd, "prog");
7750 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007751 dut->device_type = STA_unknown;
7752 type = get_param(cmd, "type");
7753 if (type && strcasecmp(type, "Testbed") == 0)
7754 dut->device_type = STA_testbed;
7755 if (type && strcasecmp(type, "DUT") == 0)
7756 dut->device_type = STA_dut;
7757
7758 if (dut->program == PROGRAM_TDLS) {
7759 /* Clear TDLS testing mode */
7760 wpa_command(intf, "SET tdls_disabled 0");
7761 wpa_command(intf, "SET tdls_testing 0");
7762 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007763 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307764 /* Enable the WCN driver in TDLS Explicit trigger mode
7765 */
7766 wpa_command(intf, "SET tdls_external_control 0");
7767 wpa_command(intf, "SET tdls_trigger_control 0");
7768 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007769 }
7770
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007771#ifdef MIRACAST
7772 if (dut->program == PROGRAM_WFD ||
7773 dut->program == PROGRAM_DISPLAYR2)
7774 miracast_sta_reset_default(dut, conn, cmd);
7775#endif /* MIRACAST */
7776
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007777 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007778 case DRIVER_ATHEROS:
7779 sta_reset_default_ath(dut, intf, type);
7780 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007781 case DRIVER_WCN:
7782 sta_reset_default_wcn(dut, intf, type);
7783 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007784 default:
7785 break;
7786 }
7787
7788#ifdef ANDROID_NAN
7789 if (dut->program == PROGRAM_NAN)
7790 nan_cmd_sta_reset_default(dut, conn, cmd);
7791#endif /* ANDROID_NAN */
7792
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307793 if (dut->program == PROGRAM_LOC &&
7794 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7795 return ERROR_SEND_STATUS;
7796
Jouni Malinenba630452018-06-22 11:49:59 +03007797 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007798 unlink("SP/wi-fi.org/pps.xml");
7799 if (system("rm -r SP/*") != 0) {
7800 }
7801 unlink("next-client-cert.pem");
7802 unlink("next-client-key.pem");
7803 }
7804
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007805 /* For WPS program of the 60 GHz band the band type needs to be saved */
7806 if (dut->program == PROGRAM_WPS) {
7807 if (band && strcasecmp(band, "60GHz") == 0) {
7808 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007809 /* For 60 GHz enable WPS for WPS TCs */
7810 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007811 } else {
7812 dut->band = WPS_BAND_NON_60G;
7813 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007814 } else if (dut->program == PROGRAM_60GHZ) {
7815 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7816 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007817 }
7818
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007819 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007820 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007821 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007822
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007823 sigma_dut_print(dut, DUT_MSG_INFO,
7824 "WPS 60 GHz program, wps_disable = %d",
7825 dut->wps_disable);
7826
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007827 if (!dev_role) {
7828 send_resp(dut, conn, SIGMA_ERROR,
7829 "errorCode,Missing DevRole argument");
7830 return 0;
7831 }
7832
7833 if (strcasecmp(dev_role, "STA") == 0)
7834 dut->dev_role = DEVROLE_STA;
7835 else if (strcasecmp(dev_role, "PCP") == 0)
7836 dut->dev_role = DEVROLE_PCP;
7837 else {
7838 send_resp(dut, conn, SIGMA_ERROR,
7839 "errorCode,Unknown DevRole");
7840 return 0;
7841 }
7842
7843 if (dut->device_type == STA_unknown) {
7844 sigma_dut_print(dut, DUT_MSG_ERROR,
7845 "Device type is not STA testbed or DUT");
7846 send_resp(dut, conn, SIGMA_ERROR,
7847 "errorCode,Unknown device type");
7848 return 0;
7849 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007850
7851 sigma_dut_print(dut, DUT_MSG_DEBUG,
7852 "Setting msdu_size to MAX: 7912");
7853 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007854 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007855
7856 if (system(buf) != 0) {
7857 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7858 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007859 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007860 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007861
7862 if (sta_set_force_mcs(dut, 0, 1)) {
7863 sigma_dut_print(dut, DUT_MSG_ERROR,
7864 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007865 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007866 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007867 }
7868
7869 wpa_command(intf, "WPS_ER_STOP");
7870 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307871 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007872 wpa_command(intf, "SET radio_disabled 0");
7873
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007874 dut->wps_forced_version = 0;
7875
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007876 if (dut->wsc_fragment) {
7877 dut->wsc_fragment = 0;
7878 wpa_command(intf, "SET device_name Test client");
7879 wpa_command(intf, "SET manufacturer ");
7880 wpa_command(intf, "SET model_name ");
7881 wpa_command(intf, "SET model_number ");
7882 wpa_command(intf, "SET serial_number ");
7883 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007884 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7885 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7886 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7887 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007888
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007889 if (dut->tmp_mac_addr && dut->set_macaddr) {
7890 dut->tmp_mac_addr = 0;
7891 if (system(dut->set_macaddr) != 0) {
7892 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7893 "temporary MAC address");
7894 }
7895 }
7896
7897 set_ps(intf, dut, 0);
7898
Jouni Malinenba630452018-06-22 11:49:59 +03007899 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7900 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007901 wpa_command(intf, "SET interworking 1");
7902 wpa_command(intf, "SET hs20 1");
7903 }
7904
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007905 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007906 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007907 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007908 wpa_command(intf, "SET pmf 1");
7909 } else {
7910 wpa_command(intf, "SET pmf 0");
7911 }
7912
7913 hs2_clear_credentials(intf);
7914 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7915 wpa_command(intf, "SET access_network_type 15");
7916
7917 static_ip_file(0, NULL, NULL, NULL);
7918 kill_dhcp_client(dut, intf);
7919 clear_ip_addr(dut, intf);
7920
7921 dut->er_oper_performed = 0;
7922 dut->er_oper_bssid[0] = '\0';
7923
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007924 if (dut->program == PROGRAM_LOC) {
7925 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007926 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007927 }
7928
Ashwini Patil00402582017-04-13 12:29:39 +05307929 if (dut->program == PROGRAM_MBO) {
7930 free(dut->non_pref_ch_list);
7931 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307932 free(dut->btm_query_cand_list);
7933 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307934 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307935 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307936 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307937 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307938 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307939 }
7940
Jouni Malinen3c367e82017-06-23 17:01:47 +03007941 free(dut->rsne_override);
7942 dut->rsne_override = NULL;
7943
Jouni Malinen68143132017-09-02 02:34:08 +03007944 free(dut->sae_commit_override);
7945 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007946 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen11e55212019-11-22 21:46:59 +02007947 dut->sae_pwe = SAE_PWE_DEFAULT;
Jouni Malinen68143132017-09-02 02:34:08 +03007948
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007949 dut->sta_associate_wait_connect = 0;
7950 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007951 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007952 dut->sta_tod_policy = 0;
7953
Jouni Malinend86e5822017-08-29 03:55:32 +03007954 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007955 free(dut->dpp_peer_uri);
7956 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007957 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007958 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007959
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007960 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7961
vamsi krishnaa2799492017-12-05 14:28:01 +05307962 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307963 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307964 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307965 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7966 dut->fils_hlp = 0;
7967#ifdef ANDROID
7968 hlp_thread_cleanup(dut);
7969#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307970 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307971
Vamsi Krishnaf642d6a2020-03-27 12:33:14 +05307972 if (dut->program == PROGRAM_QM)
7973 wpa_command(intf, "SET interworking 1");
7974
Jouni Malinen8179fee2019-03-28 03:19:47 +02007975 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007976 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007977
Sunil Dutt076081f2018-02-05 19:45:50 +05307978#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007979 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307980 dut->config_rsnie == 1) {
7981 dut->config_rsnie = 0;
7982 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307983 }
7984#endif /* NL80211_SUPPORT */
7985
Sunil Duttfebf8a82018-02-09 18:50:13 +05307986 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7987 dut->dev_role = DEVROLE_STA_CFON;
7988 return sta_cfon_reset_default(dut, conn, cmd);
7989 }
7990
Jouni Malinen439352d2018-09-13 03:42:23 +03007991 wpa_command(intf, "SET setband AUTO");
7992
Sunil Duttfebf8a82018-02-09 18:50:13 +05307993 if (dut->program != PROGRAM_VHT)
7994 return cmd_sta_p2p_reset(dut, conn, cmd);
7995
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007996 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007997}
7998
7999
Jouni Malinenf7222712019-06-13 01:50:21 +03008000static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
8001 struct sigma_conn *conn,
8002 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008003{
8004 const char *program = get_param(cmd, "Program");
8005
8006 if (program == NULL)
8007 return -1;
8008#ifdef ANDROID_NAN
8009 if (strcasecmp(program, "NAN") == 0)
8010 return nan_cmd_sta_get_events(dut, conn, cmd);
8011#endif /* ANDROID_NAN */
8012 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8013 return 0;
8014}
8015
8016
Jouni Malinen82905202018-04-29 17:20:10 +03008017static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
8018 struct sigma_cmd *cmd)
8019{
8020 const char *url = get_param(cmd, "url");
8021 const char *method = get_param(cmd, "method");
8022 pid_t pid;
8023 int status;
8024
8025 if (!url || !method)
8026 return -1;
8027
8028 /* TODO: Add support for method,post */
8029 if (strcasecmp(method, "get") != 0) {
8030 send_resp(dut, conn, SIGMA_ERROR,
8031 "ErrorCode,Unsupported method");
8032 return 0;
8033 }
8034
8035 pid = fork();
8036 if (pid < 0) {
8037 perror("fork");
8038 return -1;
8039 }
8040
8041 if (pid == 0) {
8042 char * argv[5] = { "wget", "-O", "/dev/null",
8043 (char *) url, NULL };
8044
8045 execv("/usr/bin/wget", argv);
8046 perror("execv");
8047 exit(0);
8048 return -1;
8049 }
8050
8051 if (waitpid(pid, &status, 0) < 0) {
8052 perror("waitpid");
8053 return -1;
8054 }
8055
8056 if (WIFEXITED(status)) {
8057 const char *errmsg;
8058
8059 if (WEXITSTATUS(status) == 0)
8060 return 1;
8061 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
8062 WEXITSTATUS(status));
8063 switch (WEXITSTATUS(status)) {
8064 case 4:
8065 errmsg = "errmsg,Network failure";
8066 break;
8067 case 8:
8068 errmsg = "errmsg,Server issued an error response";
8069 break;
8070 default:
8071 errmsg = "errmsg,Unknown failure from wget";
8072 break;
8073 }
8074 send_resp(dut, conn, SIGMA_ERROR, errmsg);
8075 return 0;
8076 }
8077
8078 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
8079 return 0;
8080}
8081
8082
Jouni Malinenf7222712019-06-13 01:50:21 +03008083static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
8084 struct sigma_conn *conn,
8085 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008086{
8087 const char *program = get_param(cmd, "Prog");
8088
Jouni Malinen82905202018-04-29 17:20:10 +03008089 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008090 return -1;
8091#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03008092 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008093 return nan_cmd_sta_exec_action(dut, conn, cmd);
8094#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03008095
8096 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07008097 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03008098
8099 if (get_param(cmd, "url"))
8100 return sta_exec_action_url(dut, conn, cmd);
8101
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008102 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
8103 return 0;
8104}
8105
8106
Jouni Malinenf7222712019-06-13 01:50:21 +03008107static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
8108 struct sigma_conn *conn,
8109 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008110{
8111 const char *intf = get_param(cmd, "Interface");
8112 const char *val, *mcs32, *rate;
8113
8114 val = get_param(cmd, "GREENFIELD");
8115 if (val) {
8116 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
8117 /* Enable GD */
8118 send_resp(dut, conn, SIGMA_ERROR,
8119 "ErrorCode,GF not supported");
8120 return 0;
8121 }
8122 }
8123
8124 val = get_param(cmd, "SGI20");
8125 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008126 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008127 case DRIVER_ATHEROS:
8128 ath_sta_set_sgi(dut, intf, val);
8129 break;
8130 default:
8131 send_resp(dut, conn, SIGMA_ERROR,
8132 "ErrorCode,SGI20 not supported");
8133 return 0;
8134 }
8135 }
8136
8137 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8138 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8139 if (mcs32 && rate) {
8140 /* TODO */
8141 send_resp(dut, conn, SIGMA_ERROR,
8142 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8143 return 0;
8144 } else if (mcs32 && !rate) {
8145 /* TODO */
8146 send_resp(dut, conn, SIGMA_ERROR,
8147 "ErrorCode,MCS32 not supported");
8148 return 0;
8149 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008150 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008151 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008152 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008153 ath_sta_set_11nrates(dut, intf, rate);
8154 break;
8155 default:
8156 send_resp(dut, conn, SIGMA_ERROR,
8157 "ErrorCode,MCS32_FIXEDRATE not supported");
8158 return 0;
8159 }
8160 }
8161
8162 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8163}
8164
8165
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008166static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8167 int mcs_config)
8168{
8169#ifdef NL80211_SUPPORT
8170 int ret;
8171
8172 switch (mcs_config) {
8173 case HE_80_MCS0_7:
8174 case HE_80_MCS0_9:
8175 case HE_80_MCS0_11:
8176 ret = sta_set_he_mcs(dut, intf, mcs_config);
8177 if (ret) {
8178 sigma_dut_print(dut, DUT_MSG_ERROR,
8179 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8180 mcs_config, ret);
8181 }
8182 break;
8183 default:
8184 sigma_dut_print(dut, DUT_MSG_ERROR,
8185 "cmd_set_max_he_mcs: Invalid mcs %d",
8186 mcs_config);
8187 break;
8188 }
8189#else /* NL80211_SUPPORT */
8190 sigma_dut_print(dut, DUT_MSG_ERROR,
8191 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8192#endif /* NL80211_SUPPORT */
8193}
8194
8195
Arif Hussain480d5f42019-03-12 14:40:42 -07008196static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8197 struct sigma_cmd *cmd)
8198{
8199#ifdef NL80211_SUPPORT
8200 struct nlattr *params;
8201 struct nlattr *attr;
8202 struct nlattr *attr1;
8203 struct nl_msg *msg;
8204 int ifindex, ret;
8205 const char *val;
8206 const char *intf = get_param(cmd, "Interface");
8207 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8208 wake_interval_mantissa = 512;
8209 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8210 protection = 0;
8211
8212 ifindex = if_nametoindex(intf);
8213 if (ifindex == 0) {
8214 sigma_dut_print(dut, DUT_MSG_ERROR,
8215 "%s: Index for interface %s failed",
8216 __func__, intf);
8217 return -1;
8218 }
8219
8220 val = get_param(cmd, "FlowType");
8221 if (val) {
8222 flow_type = atoi(val);
8223 if (flow_type != 0 && flow_type != 1) {
8224 sigma_dut_print(dut, DUT_MSG_ERROR,
8225 "TWT: Invalid FlowType %d", flow_type);
8226 return -1;
8227 }
8228 }
8229
8230 val = get_param(cmd, "TWT_Trigger");
8231 if (val) {
8232 twt_trigger = atoi(val);
8233 if (twt_trigger != 0 && twt_trigger != 1) {
8234 sigma_dut_print(dut, DUT_MSG_ERROR,
8235 "TWT: Invalid TWT_Trigger %d",
8236 twt_trigger);
8237 return -1;
8238 }
8239 }
8240
8241 val = get_param(cmd, "Protection");
8242 if (val) {
8243 protection = atoi(val);
8244 if (protection != 0 && protection != 1) {
8245 sigma_dut_print(dut, DUT_MSG_ERROR,
8246 "TWT: Invalid Protection %d",
8247 protection);
8248 return -1;
8249 }
8250 }
8251
8252 val = get_param(cmd, "TargetWakeTime");
8253 if (val)
8254 target_wake_time = atoi(val);
8255
8256 val = get_param(cmd, "WakeIntervalMantissa");
8257 if (val)
8258 wake_interval_mantissa = atoi(val);
8259
8260 val = get_param(cmd, "WakeIntervalExp");
8261 if (val)
8262 wake_interval_exp = atoi(val);
8263
8264 val = get_param(cmd, "NominalMinWakeDur");
8265 if (val)
8266 nominal_min_wake_dur = atoi(val);
8267
8268 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8269 NL80211_CMD_VENDOR)) ||
8270 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8271 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8272 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8273 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8274 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8275 !(params = nla_nest_start(
8276 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8277 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8278 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8279 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008280 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008281 (twt_trigger &&
8282 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008283 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8284 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008285 (protection &&
8286 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008287 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8288 target_wake_time) ||
8289 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8290 nominal_min_wake_dur) ||
8291 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8292 wake_interval_mantissa)) {
8293 sigma_dut_print(dut, DUT_MSG_ERROR,
8294 "%s: err in adding vendor_cmd and vendor_data",
8295 __func__);
8296 nlmsg_free(msg);
8297 return -1;
8298 }
8299 nla_nest_end(msg, attr1);
8300 nla_nest_end(msg, params);
8301 nla_nest_end(msg, attr);
8302
8303 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8304 if (ret) {
8305 sigma_dut_print(dut, DUT_MSG_ERROR,
8306 "%s: err in send_and_recv_msgs, ret=%d",
8307 __func__, ret);
8308 }
8309
8310 return ret;
8311#else /* NL80211_SUPPORT */
8312 sigma_dut_print(dut, DUT_MSG_ERROR,
8313 "TWT request cannot be done without NL80211_SUPPORT defined");
8314 return -1;
8315#endif /* NL80211_SUPPORT */
8316}
8317
8318
8319static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8320 struct sigma_cmd *cmd)
8321{
8322 #ifdef NL80211_SUPPORT
8323 struct nlattr *params;
8324 struct nlattr *attr;
8325 struct nlattr *attr1;
8326 int ifindex, ret;
8327 struct nl_msg *msg;
8328 const char *intf = get_param(cmd, "Interface");
8329
8330 ifindex = if_nametoindex(intf);
8331 if (ifindex == 0) {
8332 sigma_dut_print(dut, DUT_MSG_ERROR,
8333 "%s: Index for interface %s failed",
8334 __func__, intf);
8335 return -1;
8336 }
8337
8338 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8339 NL80211_CMD_VENDOR)) ||
8340 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8341 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8342 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8343 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8344 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8345 !(params = nla_nest_start(
8346 msg,
8347 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8348 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8349 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8350 sigma_dut_print(dut, DUT_MSG_ERROR,
8351 "%s: err in adding vendor_cmd and vendor_data",
8352 __func__);
8353 nlmsg_free(msg);
8354 return -1;
8355 }
8356 nla_nest_end(msg, attr1);
8357 nla_nest_end(msg, params);
8358 nla_nest_end(msg, attr);
8359
8360 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8361 if (ret) {
8362 sigma_dut_print(dut, DUT_MSG_ERROR,
8363 "%s: err in send_and_recv_msgs, ret=%d",
8364 __func__, ret);
8365 }
8366
8367 return ret;
8368#else /* NL80211_SUPPORT */
8369 sigma_dut_print(dut, DUT_MSG_ERROR,
8370 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8371 return -1;
8372#endif /* NL80211_SUPPORT */
8373}
8374
8375
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008376static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8377 struct sigma_cmd *cmd)
8378{
8379#ifdef NL80211_SUPPORT
8380 struct nlattr *params;
8381 struct nlattr *attr;
8382 struct nlattr *attr1;
8383 struct nl_msg *msg;
8384 int ifindex, ret;
8385 const char *val;
8386 const char *intf = get_param(cmd, "Interface");
8387 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8388 ulmu_data_dis = 0;
8389
8390 ifindex = if_nametoindex(intf);
8391 if (ifindex == 0) {
8392 sigma_dut_print(dut, DUT_MSG_ERROR,
8393 "%s: Index for interface %s failed",
8394 __func__, intf);
8395 return -1;
8396 }
8397 val = get_param(cmd, "OMCtrl_RxNSS");
8398 if (val)
8399 rx_nss = atoi(val);
8400
8401 val = get_param(cmd, "OMCtrl_ChnlWidth");
8402 if (val)
8403 ch_bw = atoi(val);
8404
8405 val = get_param(cmd, "OMCtrl_ULMUDisable");
8406 if (val)
8407 ulmu_dis = atoi(val);
8408
8409 val = get_param(cmd, "OMCtrl_TxNSTS");
8410 if (val)
8411 tx_nsts = atoi(val);
8412
8413 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8414 if (val)
8415 ulmu_data_dis = atoi(val);
8416
8417 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8418 NL80211_CMD_VENDOR)) ||
8419 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8420 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8421 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8422 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8423 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8424 !(params = nla_nest_start(
8425 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8426 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8427 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8428 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8429 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8430 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8431 ulmu_data_dis) ||
8432 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8433 ulmu_dis)) {
8434 sigma_dut_print(dut, DUT_MSG_ERROR,
8435 "%s: err in adding vendor_cmd and vendor_data",
8436 __func__);
8437 nlmsg_free(msg);
8438 return -1;
8439 }
8440 nla_nest_end(msg, attr1);
8441 nla_nest_end(msg, params);
8442 nla_nest_end(msg, attr);
8443
8444 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8445 if (ret) {
8446 sigma_dut_print(dut, DUT_MSG_ERROR,
8447 "%s: err in send_and_recv_msgs, ret=%d",
8448 __func__, ret);
8449 }
8450
8451 return ret;
8452#else /* NL80211_SUPPORT */
8453 sigma_dut_print(dut, DUT_MSG_ERROR,
8454 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8455 return -1;
8456#endif /* NL80211_SUPPORT */
8457}
8458
8459
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008460static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8461 struct sigma_conn *conn,
8462 struct sigma_cmd *cmd)
8463{
8464 const char *intf = get_param(cmd, "Interface");
8465 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008466 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008467 int tkip = -1;
8468 int wep = -1;
8469
Arif Hussaina37e9552018-06-20 17:05:59 -07008470 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008471 val = get_param(cmd, "SGI80");
8472 if (val) {
8473 int sgi80;
8474
8475 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008476 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008477 }
8478
8479 val = get_param(cmd, "TxBF");
8480 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008481 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008482 case DRIVER_WCN:
8483 if (sta_set_tx_beamformee(dut, intf, 1)) {
8484 send_resp(dut, conn, SIGMA_ERROR,
8485 "ErrorCode,Failed to set TX beamformee enable");
8486 return 0;
8487 }
8488 break;
8489 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008490 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008491 send_resp(dut, conn, SIGMA_ERROR,
8492 "ErrorCode,Setting vhtsubfee failed");
8493 return 0;
8494 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008495 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008496 send_resp(dut, conn, SIGMA_ERROR,
8497 "ErrorCode,Setting vhtsubfer failed");
8498 return 0;
8499 }
8500 break;
8501 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008502 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008503 "Unsupported driver type");
8504 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008505 }
8506 }
8507
8508 val = get_param(cmd, "MU_TxBF");
8509 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008510 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008511 case DRIVER_ATHEROS:
8512 ath_sta_set_txsp_stream(dut, intf, "1SS");
8513 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008514 run_iwpriv(dut, intf, "vhtmubfee 1");
8515 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308516 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008517 case DRIVER_WCN:
8518 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8519 send_resp(dut, conn, SIGMA_ERROR,
8520 "ErrorCode,Failed to set RX/TXSP_STREAM");
8521 return 0;
8522 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308523 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008524 default:
8525 sigma_dut_print(dut, DUT_MSG_ERROR,
8526 "Setting SP_STREAM not supported");
8527 break;
8528 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008529 }
8530
8531 val = get_param(cmd, "LDPC");
8532 if (val) {
8533 int ldpc;
8534
8535 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008536 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008537 }
8538
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008539 val = get_param(cmd, "BCC");
8540 if (val) {
8541 int bcc;
8542
8543 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8544 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8545 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008546 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008547 }
8548
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008549 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8550 if (val && dut->sta_nss == 1)
8551 cmd_set_max_he_mcs(dut, intf, atoi(val));
8552
8553 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8554 if (val && dut->sta_nss == 2)
8555 cmd_set_max_he_mcs(dut, intf, atoi(val));
8556
Arif Hussainac6c5112018-05-25 17:34:00 -07008557 val = get_param(cmd, "MCS_FixedRate");
8558 if (val) {
8559#ifdef NL80211_SUPPORT
8560 int mcs, ratecode = 0;
8561 enum he_mcs_config mcs_config;
8562 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008563 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008564
8565 ratecode = (0x07 & dut->sta_nss) << 5;
8566 mcs = atoi(val);
8567 /* Add the MCS to the ratecode */
8568 if (mcs >= 0 && mcs <= 11) {
8569 ratecode += mcs;
8570 if (dut->device_type == STA_testbed &&
8571 mcs > 7 && mcs <= 11) {
8572 if (mcs <= 9)
8573 mcs_config = HE_80_MCS0_9;
8574 else
8575 mcs_config = HE_80_MCS0_11;
8576 ret = sta_set_he_mcs(dut, intf, mcs_config);
8577 if (ret) {
8578 sigma_dut_print(dut, DUT_MSG_ERROR,
8579 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8580 mcs, mcs_config, ret);
8581 }
8582 }
8583 snprintf(buf, sizeof(buf),
8584 "iwpriv %s set_11ax_rate 0x%03x",
8585 intf, ratecode);
8586 if (system(buf) != 0) {
8587 sigma_dut_print(dut, DUT_MSG_ERROR,
8588 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8589 ratecode);
8590 }
8591 } else {
8592 sigma_dut_print(dut, DUT_MSG_ERROR,
8593 "MCS_FixedRate: HE MCS %d not supported",
8594 mcs);
8595 }
8596#else /* NL80211_SUPPORT */
8597 sigma_dut_print(dut, DUT_MSG_ERROR,
8598 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8599#endif /* NL80211_SUPPORT */
8600 }
8601
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008602 val = get_param(cmd, "opt_md_notif_ie");
8603 if (val) {
8604 char *result = NULL;
8605 char delim[] = ";";
8606 char token[30];
8607 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308608 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008609
Peng Xub8fc5cc2017-05-10 17:27:28 -07008610 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308611 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008612
8613 /* Extract the NSS information */
8614 if (result) {
8615 value = atoi(result);
8616 switch (value) {
8617 case 1:
8618 config_val = 1;
8619 break;
8620 case 2:
8621 config_val = 3;
8622 break;
8623 case 3:
8624 config_val = 7;
8625 break;
8626 case 4:
8627 config_val = 15;
8628 break;
8629 default:
8630 config_val = 3;
8631 break;
8632 }
8633
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008634 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8635 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008636
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008637 }
8638
8639 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308640 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008641 if (result) {
8642 value = atoi(result);
8643 switch (value) {
8644 case 20:
8645 config_val = 0;
8646 break;
8647 case 40:
8648 config_val = 1;
8649 break;
8650 case 80:
8651 config_val = 2;
8652 break;
8653 case 160:
8654 config_val = 3;
8655 break;
8656 default:
8657 config_val = 2;
8658 break;
8659 }
8660
8661 dut->chwidth = config_val;
8662
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008663 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008664 }
8665
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008666 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008667 }
8668
8669 val = get_param(cmd, "nss_mcs_cap");
8670 if (val) {
8671 int nss, mcs;
8672 char token[20];
8673 char *result = NULL;
8674 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308675 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008676
Peng Xub8fc5cc2017-05-10 17:27:28 -07008677 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308678 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308679 if (!result) {
8680 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008681 "NSS not specified");
8682 send_resp(dut, conn, SIGMA_ERROR,
8683 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308684 return 0;
8685 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008686 nss = atoi(result);
8687
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008688 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008689 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008690
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308691 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008692 if (result == NULL) {
8693 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008694 "MCS not specified");
8695 send_resp(dut, conn, SIGMA_ERROR,
8696 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008697 return 0;
8698 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308699 result = strtok_r(result, "-", &saveptr);
8700 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308701 if (!result) {
8702 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008703 "MCS not specified");
8704 send_resp(dut, conn, SIGMA_ERROR,
8705 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308706 return 0;
8707 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008708 mcs = atoi(result);
8709
Arif Hussaina37e9552018-06-20 17:05:59 -07008710 if (program && strcasecmp(program, "HE") == 0) {
8711#ifdef NL80211_SUPPORT
8712 enum he_mcs_config mcs_config;
8713 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008714
Arif Hussaina37e9552018-06-20 17:05:59 -07008715 if (mcs >= 0 && mcs <= 7) {
8716 mcs_config = HE_80_MCS0_7;
8717 } else if (mcs > 7 && mcs <= 9) {
8718 mcs_config = HE_80_MCS0_9;
8719 } else if (mcs > 9 && mcs <= 11) {
8720 mcs_config = HE_80_MCS0_11;
8721 } else {
8722 sigma_dut_print(dut, DUT_MSG_ERROR,
8723 "nss_mcs_cap: HE: Invalid mcs: %d",
8724 mcs);
8725 send_resp(dut, conn, SIGMA_ERROR,
8726 "errorCode,Invalid MCS");
8727 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008728 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008729
8730 ret = sta_set_he_mcs(dut, intf, mcs_config);
8731 if (ret) {
8732 sigma_dut_print(dut, DUT_MSG_ERROR,
8733 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8734 mcs_config, ret);
8735 send_resp(dut, conn, SIGMA_ERROR,
8736 "errorCode,Failed to set MCS");
8737 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008738 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008739#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008740 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008741 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8742#endif /* NL80211_SUPPORT */
8743 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008744 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008745
8746 switch (nss) {
8747 case 1:
8748 switch (mcs) {
8749 case 7:
8750 vht_mcsmap = 0xfffc;
8751 break;
8752 case 8:
8753 vht_mcsmap = 0xfffd;
8754 break;
8755 case 9:
8756 vht_mcsmap = 0xfffe;
8757 break;
8758 default:
8759 vht_mcsmap = 0xfffe;
8760 break;
8761 }
8762 break;
8763 case 2:
8764 switch (mcs) {
8765 case 7:
8766 vht_mcsmap = 0xfff0;
8767 break;
8768 case 8:
8769 vht_mcsmap = 0xfff5;
8770 break;
8771 case 9:
8772 vht_mcsmap = 0xfffa;
8773 break;
8774 default:
8775 vht_mcsmap = 0xfffa;
8776 break;
8777 }
8778 break;
8779 case 3:
8780 switch (mcs) {
8781 case 7:
8782 vht_mcsmap = 0xffc0;
8783 break;
8784 case 8:
8785 vht_mcsmap = 0xffd5;
8786 break;
8787 case 9:
8788 vht_mcsmap = 0xffea;
8789 break;
8790 default:
8791 vht_mcsmap = 0xffea;
8792 break;
8793 }
8794 break;
8795 default:
8796 vht_mcsmap = 0xffea;
8797 break;
8798 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008799 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008800 }
8801 }
8802
8803 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8804
8805 val = get_param(cmd, "Vht_tkip");
8806 if (val)
8807 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8808
8809 val = get_param(cmd, "Vht_wep");
8810 if (val)
8811 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8812
8813 if (tkip != -1 || wep != -1) {
8814 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008815 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008816 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008817 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008818 } else {
8819 sigma_dut_print(dut, DUT_MSG_ERROR,
8820 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8821 return 0;
8822 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008823 }
8824
Arif Hussain55f00da2018-07-03 08:28:26 -07008825 val = get_param(cmd, "txBandwidth");
8826 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008827 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008828 case DRIVER_WCN:
8829 if (wcn_sta_set_width(dut, intf, val) < 0) {
8830 send_resp(dut, conn, SIGMA_ERROR,
8831 "ErrorCode,Failed to set txBandwidth");
8832 return 0;
8833 }
8834 break;
8835 case DRIVER_ATHEROS:
8836 if (ath_set_width(dut, conn, intf, val) < 0) {
8837 send_resp(dut, conn, SIGMA_ERROR,
8838 "ErrorCode,Failed to set txBandwidth");
8839 return 0;
8840 }
8841 break;
8842 default:
8843 sigma_dut_print(dut, DUT_MSG_ERROR,
8844 "Setting txBandwidth not supported");
8845 break;
8846 }
8847 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008848
Arif Hussain9765f7d2018-07-03 08:28:26 -07008849 val = get_param(cmd, "BeamformeeSTS");
8850 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008851 if (sta_set_tx_beamformee(dut, intf, 1)) {
8852 send_resp(dut, conn, SIGMA_ERROR,
8853 "ErrorCode,Failed to set TX beamformee enable");
8854 return 0;
8855 }
8856
Arif Hussain9765f7d2018-07-03 08:28:26 -07008857 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8858 send_resp(dut, conn, SIGMA_ERROR,
8859 "ErrorCode,Failed to set BeamformeeSTS");
8860 return 0;
8861 }
8862 }
8863
Arif Hussain68d23f52018-07-11 13:39:08 -07008864 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8865 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008866#ifdef NL80211_SUPPORT
8867 enum qca_wlan_he_mac_padding_dur set_val;
8868
8869 switch (atoi(val)) {
8870 case 16:
8871 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8872 break;
8873 case 8:
8874 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8875 break;
8876 default:
8877 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8878 break;
8879 }
8880 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008881 send_resp(dut, conn, SIGMA_ERROR,
8882 "ErrorCode,Failed to set MAC padding duration");
8883 return 0;
8884 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008885#else /* NL80211_SUPPORT */
8886 sigma_dut_print(dut, DUT_MSG_ERROR,
8887 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8888#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008889 }
8890
Arif Hussain480d5f42019-03-12 14:40:42 -07008891 val = get_param(cmd, "TWT_ReqSupport");
8892 if (val) {
8893 int set_val;
8894
8895 if (strcasecmp(val, "Enable") == 0) {
8896 set_val = 1;
8897 } else if (strcasecmp(val, "Disable") == 0) {
8898 set_val = 0;
8899 } else {
8900 send_resp(dut, conn, SIGMA_ERROR,
8901 "ErrorCode,Invalid TWT_ReqSupport");
8902 return STATUS_SENT;
8903 }
8904
8905 if (sta_set_twt_req_support(dut, intf, set_val)) {
8906 sigma_dut_print(dut, DUT_MSG_ERROR,
8907 "Failed to set TWT req support %d",
8908 set_val);
8909 send_resp(dut, conn, SIGMA_ERROR,
8910 "ErrorCode,Failed to set TWT_ReqSupport");
8911 return STATUS_SENT;
8912 }
8913 }
8914
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008915 val = get_param(cmd, "MU_EDCA");
8916 if (val && (strcasecmp(val, "Override") == 0)) {
8917 if (sta_set_mu_edca_override(dut, intf, 1)) {
8918 send_resp(dut, conn, SIGMA_ERROR,
8919 "ErrorCode,Failed to set MU EDCA override");
8920 return 0;
8921 }
8922 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008923
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008924 val = get_param(cmd, "OMControl");
8925 if (val) {
8926 int set_val = 1;
8927
8928 if (strcasecmp(val, "Enable") == 0)
8929 set_val = 1;
8930 else if (strcasecmp(val, "Disable") == 0)
8931 set_val = 0;
8932
8933 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8934 send_resp(dut, conn, SIGMA_ERROR,
8935 "ErrorCode,Failed to set OM ctrl supp");
8936 return 0;
8937 }
8938 }
8939
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008940 val = get_param(cmd, "ADDBAResp_BufSize");
8941 if (val) {
8942 int buf_size;
8943
8944 if (strcasecmp(val, "gt64") == 0)
8945 buf_size = 256;
8946 else
8947 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008948 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008949 sta_set_addba_buf_size(dut, intf, buf_size)) {
8950 send_resp(dut, conn, SIGMA_ERROR,
8951 "ErrorCode,set addbaresp_buff_size failed");
8952 return 0;
8953 }
8954 }
8955
8956 val = get_param(cmd, "ADDBAReq_BufSize");
8957 if (val) {
8958 int buf_size;
8959
8960 if (strcasecmp(val, "gt64") == 0)
8961 buf_size = 256;
8962 else
8963 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008964 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008965 sta_set_addba_buf_size(dut, intf, buf_size)) {
8966 send_resp(dut, conn, SIGMA_ERROR,
8967 "ErrorCode,set addbareq_buff_size failed");
8968 return 0;
8969 }
8970 }
8971
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008972 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8973}
8974
8975
8976static int sta_set_wireless_60g(struct sigma_dut *dut,
8977 struct sigma_conn *conn,
8978 struct sigma_cmd *cmd)
8979{
8980 const char *dev_role = get_param(cmd, "DevRole");
8981
8982 if (!dev_role) {
8983 send_resp(dut, conn, SIGMA_INVALID,
8984 "ErrorCode,DevRole not specified");
8985 return 0;
8986 }
8987
8988 if (strcasecmp(dev_role, "PCP") == 0)
8989 return sta_set_60g_pcp(dut, conn, cmd);
8990 if (strcasecmp(dev_role, "STA") == 0)
8991 return sta_set_60g_sta(dut, conn, cmd);
8992 send_resp(dut, conn, SIGMA_INVALID,
8993 "ErrorCode,DevRole not supported");
8994 return 0;
8995}
8996
8997
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308998static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8999 struct sigma_cmd *cmd)
9000{
9001 int status;
9002 const char *intf = get_param(cmd, "Interface");
9003 const char *val = get_param(cmd, "DevRole");
9004
9005 if (val && strcasecmp(val, "STA-CFON") == 0) {
9006 status = sta_cfon_set_wireless(dut, conn, cmd);
9007 if (status)
9008 return status;
9009 }
9010 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
9011}
9012
9013
Jouni Malinenf7222712019-06-13 01:50:21 +03009014static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
9015 struct sigma_conn *conn,
9016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009017{
9018 const char *val;
9019
9020 val = get_param(cmd, "Program");
9021 if (val) {
9022 if (strcasecmp(val, "11n") == 0)
9023 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08009024 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009025 return cmd_sta_set_wireless_vht(dut, conn, cmd);
9026 if (strcasecmp(val, "60ghz") == 0)
9027 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05309028 if (strcasecmp(val, "OCE") == 0)
9029 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02009030 /* sta_set_wireless in WPS program is only used for 60G */
9031 if (is_60g_sigma_dut(dut))
9032 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009033 send_resp(dut, conn, SIGMA_ERROR,
9034 "ErrorCode,Program value not supported");
9035 } else {
9036 send_resp(dut, conn, SIGMA_ERROR,
9037 "ErrorCode,Program argument not available");
9038 }
9039
9040 return 0;
9041}
9042
9043
9044static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
9045 int tid)
9046{
9047 char buf[100];
9048 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
9049
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05309050 if (tid < 0 ||
9051 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
9052 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
9053 return;
9054 }
9055
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009056 /*
9057 * Two ways to ensure that addba request with a
9058 * non zero TID could be sent out. EV 117296
9059 */
9060 snprintf(buf, sizeof(buf),
9061 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
9062 tid);
9063 if (system(buf) != 0) {
9064 sigma_dut_print(dut, DUT_MSG_ERROR,
9065 "Ping did not send out");
9066 }
9067
9068 snprintf(buf, sizeof(buf),
9069 "iwconfig %s | grep Access | awk '{print $6}' > %s",
9070 intf, VI_QOS_TMP_FILE);
9071 if (system(buf) != 0)
9072 return;
9073
9074 snprintf(buf, sizeof(buf),
9075 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
9076 intf, VI_QOS_TMP_FILE);
9077 if (system(buf) != 0)
9078 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
9079
9080 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
9081 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
9082 if (system(buf) != 0) {
9083 sigma_dut_print(dut, DUT_MSG_ERROR,
9084 "VI_QOS_TEMP_FILE generation error failed");
9085 }
9086 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9087 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9088 if (system(buf) != 0) {
9089 sigma_dut_print(dut, DUT_MSG_ERROR,
9090 "VI_QOS_FILE generation failed");
9091 }
9092
9093 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
9094 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
9095 if (system(buf) != 0) {
9096 sigma_dut_print(dut, DUT_MSG_ERROR,
9097 "VI_QOS_FILE generation failed");
9098 }
9099
9100 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
9101 if (system(buf) != 0) {
9102 }
9103}
9104
9105
9106static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9107 struct sigma_cmd *cmd)
9108{
9109 const char *intf = get_param(cmd, "Interface");
9110 const char *val;
9111 int tid = 0;
9112 char buf[100];
9113
9114 val = get_param(cmd, "TID");
9115 if (val) {
9116 tid = atoi(val);
9117 if (tid)
9118 ath_sta_inject_frame(dut, intf, tid);
9119 }
9120
9121 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009122 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009123
9124 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
9125 if (system(buf) != 0) {
9126 sigma_dut_print(dut, DUT_MSG_ERROR,
9127 "wifitool senddelba failed");
9128 }
9129
9130 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
9131 if (system(buf) != 0) {
9132 sigma_dut_print(dut, DUT_MSG_ERROR,
9133 "wifitool sendaddba failed");
9134 }
9135
9136 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9137
9138 return 1;
9139}
9140
9141
Lior David9981b512017-01-20 13:16:40 +02009142#ifdef __linux__
9143
9144static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9145 int agg_size)
9146{
9147 char dir[128], buf[128];
9148 FILE *f;
9149 regex_t re;
9150 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009151 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009152
9153 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9154 sigma_dut_print(dut, DUT_MSG_ERROR,
9155 "failed to get wil6210 debugfs dir");
9156 return -1;
9157 }
9158
Jouni Malinen3aa72862019-05-29 23:14:51 +03009159 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9160 if (res < 0 || res >= sizeof(buf))
9161 return -1;
Lior David9981b512017-01-20 13:16:40 +02009162 f = fopen(buf, "r");
9163 if (!f) {
9164 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009165 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009166 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9167 if (res < 0 || res >= sizeof(buf))
9168 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009169 f = fopen(buf, "r");
9170 if (!f) {
9171 sigma_dut_print(dut, DUT_MSG_ERROR,
9172 "failed to open: %s", buf);
9173 return -1;
9174 }
Lior David9981b512017-01-20 13:16:40 +02009175 }
9176
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009177 /* can be either VRING tx... or RING... */
9178 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009179 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9180 goto out;
9181 }
9182
9183 /* find TX VRING for the mac address */
9184 found = 0;
9185 while (fgets(buf, sizeof(buf), f)) {
9186 if (strcasestr(buf, dest_mac)) {
9187 found = 1;
9188 break;
9189 }
9190 }
9191
9192 if (!found) {
9193 sigma_dut_print(dut, DUT_MSG_ERROR,
9194 "no TX VRING for %s", dest_mac);
9195 goto out;
9196 }
9197
9198 /* extract VRING ID, "VRING tx_<id> = {" */
9199 if (!fgets(buf, sizeof(buf), f)) {
9200 sigma_dut_print(dut, DUT_MSG_ERROR,
9201 "no VRING start line for %s", dest_mac);
9202 goto out;
9203 }
9204
9205 rc = regexec(&re, buf, 2, m, 0);
9206 regfree(&re);
9207 if (rc || m[1].rm_so < 0) {
9208 sigma_dut_print(dut, DUT_MSG_ERROR,
9209 "no VRING TX ID for %s", dest_mac);
9210 goto out;
9211 }
9212 buf[m[1].rm_eo] = 0;
9213 vring_id = atoi(&buf[m[1].rm_so]);
9214
9215 /* send the addba command */
9216 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009217 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9218 if (res < 0 || res >= sizeof(buf))
9219 return -1;
Lior David9981b512017-01-20 13:16:40 +02009220 f = fopen(buf, "w");
9221 if (!f) {
9222 sigma_dut_print(dut, DUT_MSG_ERROR,
9223 "failed to open: %s", buf);
9224 return -1;
9225 }
9226
9227 fprintf(f, "add %d %d\n", vring_id, agg_size);
9228
9229 ret = 0;
9230
9231out:
9232 fclose(f);
9233
9234 return ret;
9235}
9236
9237
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009238int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9239 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009240{
9241 const char *val;
9242 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009243
9244 val = get_param(cmd, "TID");
9245 if (val) {
9246 tid = atoi(val);
9247 if (tid != 0) {
9248 sigma_dut_print(dut, DUT_MSG_ERROR,
9249 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9250 tid);
9251 }
9252 }
9253
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009254 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009255 if (!val) {
9256 sigma_dut_print(dut, DUT_MSG_ERROR,
9257 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009258 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009259 }
9260
Lior David9981b512017-01-20 13:16:40 +02009261 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009262 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009263
9264 return 1;
9265}
9266
Lior David9981b512017-01-20 13:16:40 +02009267#endif /* __linux__ */
9268
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009269
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009270static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9271 struct sigma_cmd *cmd)
9272{
9273#ifdef NL80211_SUPPORT
9274 const char *intf = get_param(cmd, "Interface");
9275 const char *val;
9276 int tid = -1;
9277 int bufsize = 64;
9278 struct nl_msg *msg;
9279 int ret = 0;
9280 struct nlattr *params;
9281 int ifindex;
9282
9283 val = get_param(cmd, "TID");
9284 if (val)
9285 tid = atoi(val);
9286
9287 if (tid == -1) {
9288 send_resp(dut, conn, SIGMA_ERROR,
9289 "ErrorCode,sta_send_addba tid invalid");
9290 return 0;
9291 }
9292
9293 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9294
9295 ifindex = if_nametoindex(intf);
9296 if (ifindex == 0) {
9297 sigma_dut_print(dut, DUT_MSG_ERROR,
9298 "%s: Index for interface %s failed",
9299 __func__, intf);
9300 send_resp(dut, conn, SIGMA_ERROR,
9301 "ErrorCode,sta_send_addba interface invalid");
9302 return 0;
9303 }
9304
9305 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9306 NL80211_CMD_VENDOR)) ||
9307 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9308 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9309 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9310 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9311 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9312 nla_put_u8(msg,
9313 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9314 QCA_WLAN_ADD_BA) ||
9315 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9316 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009317 nla_put_u16(msg,
9318 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9319 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009320 sigma_dut_print(dut, DUT_MSG_ERROR,
9321 "%s: err in adding vendor_cmd and vendor_data",
9322 __func__);
9323 nlmsg_free(msg);
9324 send_resp(dut, conn, SIGMA_ERROR,
9325 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9326 return 0;
9327 }
9328 nla_nest_end(msg, params);
9329
9330 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9331 if (ret) {
9332 sigma_dut_print(dut, DUT_MSG_ERROR,
9333 "%s: err in send_and_recv_msgs, ret=%d",
9334 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309335 if (ret == -EOPNOTSUPP)
9336 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009337 send_resp(dut, conn, SIGMA_ERROR,
9338 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9339 return 0;
9340 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009341#else /* NL80211_SUPPORT */
9342 sigma_dut_print(dut, DUT_MSG_ERROR,
9343 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009344#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309345
9346 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009347}
9348
9349
Jouni Malinenf7222712019-06-13 01:50:21 +03009350static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9351 struct sigma_conn *conn,
9352 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009353{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009354 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009355 case DRIVER_ATHEROS:
9356 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009357 case DRIVER_WCN:
9358 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009359#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009360 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009361 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009362#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009363 default:
9364 /*
9365 * There is no driver specific implementation for other drivers.
9366 * Ignore the command and report COMPLETE since the following
9367 * throughput test operation will end up sending ADDBA anyway.
9368 */
9369 return 1;
9370 }
9371}
9372
9373
9374int inject_eth_frame(int s, const void *data, size_t len,
9375 unsigned short ethtype, char *dst, char *src)
9376{
9377 struct iovec iov[4] = {
9378 {
9379 .iov_base = dst,
9380 .iov_len = ETH_ALEN,
9381 },
9382 {
9383 .iov_base = src,
9384 .iov_len = ETH_ALEN,
9385 },
9386 {
9387 .iov_base = &ethtype,
9388 .iov_len = sizeof(unsigned short),
9389 },
9390 {
9391 .iov_base = (void *) data,
9392 .iov_len = len,
9393 }
9394 };
9395 struct msghdr msg = {
9396 .msg_name = NULL,
9397 .msg_namelen = 0,
9398 .msg_iov = iov,
9399 .msg_iovlen = 4,
9400 .msg_control = NULL,
9401 .msg_controllen = 0,
9402 .msg_flags = 0,
9403 };
9404
9405 return sendmsg(s, &msg, 0);
9406}
9407
9408#if defined(__linux__) || defined(__QNXNTO__)
9409
9410int inject_frame(int s, const void *data, size_t len, int encrypt)
9411{
9412#define IEEE80211_RADIOTAP_F_WEP 0x04
9413#define IEEE80211_RADIOTAP_F_FRAG 0x08
9414 unsigned char rtap_hdr[] = {
9415 0x00, 0x00, /* radiotap version */
9416 0x0e, 0x00, /* radiotap length */
9417 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9418 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9419 0x00, /* padding */
9420 0x00, 0x00, /* RX and TX flags to indicate that */
9421 0x00, 0x00, /* this is the injected frame directly */
9422 };
9423 struct iovec iov[2] = {
9424 {
9425 .iov_base = &rtap_hdr,
9426 .iov_len = sizeof(rtap_hdr),
9427 },
9428 {
9429 .iov_base = (void *) data,
9430 .iov_len = len,
9431 }
9432 };
9433 struct msghdr msg = {
9434 .msg_name = NULL,
9435 .msg_namelen = 0,
9436 .msg_iov = iov,
9437 .msg_iovlen = 2,
9438 .msg_control = NULL,
9439 .msg_controllen = 0,
9440 .msg_flags = 0,
9441 };
9442
9443 if (encrypt)
9444 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9445
9446 return sendmsg(s, &msg, 0);
9447}
9448
9449
9450int open_monitor(const char *ifname)
9451{
9452#ifdef __QNXNTO__
9453 struct sockaddr_dl ll;
9454 int s;
9455
9456 memset(&ll, 0, sizeof(ll));
9457 ll.sdl_family = AF_LINK;
9458 ll.sdl_index = if_nametoindex(ifname);
9459 if (ll.sdl_index == 0) {
9460 perror("if_nametoindex");
9461 return -1;
9462 }
9463 s = socket(PF_INET, SOCK_RAW, 0);
9464#else /* __QNXNTO__ */
9465 struct sockaddr_ll ll;
9466 int s;
9467
9468 memset(&ll, 0, sizeof(ll));
9469 ll.sll_family = AF_PACKET;
9470 ll.sll_ifindex = if_nametoindex(ifname);
9471 if (ll.sll_ifindex == 0) {
9472 perror("if_nametoindex");
9473 return -1;
9474 }
9475 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9476#endif /* __QNXNTO__ */
9477 if (s < 0) {
9478 perror("socket[PF_PACKET,SOCK_RAW]");
9479 return -1;
9480 }
9481
9482 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9483 perror("monitor socket bind");
9484 close(s);
9485 return -1;
9486 }
9487
9488 return s;
9489}
9490
9491
9492static int hex2num(char c)
9493{
9494 if (c >= '0' && c <= '9')
9495 return c - '0';
9496 if (c >= 'a' && c <= 'f')
9497 return c - 'a' + 10;
9498 if (c >= 'A' && c <= 'F')
9499 return c - 'A' + 10;
9500 return -1;
9501}
9502
9503
9504int hwaddr_aton(const char *txt, unsigned char *addr)
9505{
9506 int i;
9507
9508 for (i = 0; i < 6; i++) {
9509 int a, b;
9510
9511 a = hex2num(*txt++);
9512 if (a < 0)
9513 return -1;
9514 b = hex2num(*txt++);
9515 if (b < 0)
9516 return -1;
9517 *addr++ = (a << 4) | b;
9518 if (i < 5 && *txt++ != ':')
9519 return -1;
9520 }
9521
9522 return 0;
9523}
9524
9525#endif /* defined(__linux__) || defined(__QNXNTO__) */
9526
9527enum send_frame_type {
9528 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9529};
9530enum send_frame_protection {
9531 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9532};
9533
9534
9535static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9536 enum send_frame_type frame,
9537 enum send_frame_protection protected,
9538 const char *dest)
9539{
9540#ifdef __linux__
9541 unsigned char buf[1000], *pos;
9542 int s, res;
9543 char bssid[20], addr[20];
9544 char result[32], ssid[100];
9545 size_t ssid_len;
9546
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009547 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009548 sizeof(result)) < 0 ||
9549 strncmp(result, "COMPLETED", 9) != 0) {
9550 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9551 return 0;
9552 }
9553
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009554 if (get_wpa_status(get_station_ifname(dut), "bssid",
9555 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009556 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9557 "current BSSID");
9558 return 0;
9559 }
9560
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009561 if (get_wpa_status(get_station_ifname(dut), "address",
9562 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009563 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9564 "own MAC address");
9565 return 0;
9566 }
9567
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009568 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009569 < 0) {
9570 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9571 "current SSID");
9572 return 0;
9573 }
9574 ssid_len = strlen(ssid);
9575
9576 pos = buf;
9577
9578 /* Frame Control */
9579 switch (frame) {
9580 case DISASSOC:
9581 *pos++ = 0xa0;
9582 break;
9583 case DEAUTH:
9584 *pos++ = 0xc0;
9585 break;
9586 case SAQUERY:
9587 *pos++ = 0xd0;
9588 break;
9589 case AUTH:
9590 *pos++ = 0xb0;
9591 break;
9592 case ASSOCREQ:
9593 *pos++ = 0x00;
9594 break;
9595 case REASSOCREQ:
9596 *pos++ = 0x20;
9597 break;
9598 case DLS_REQ:
9599 *pos++ = 0xd0;
9600 break;
9601 }
9602
9603 if (protected == INCORRECT_KEY)
9604 *pos++ = 0x40; /* Set Protected field to 1 */
9605 else
9606 *pos++ = 0x00;
9607
9608 /* Duration */
9609 *pos++ = 0x00;
9610 *pos++ = 0x00;
9611
9612 /* addr1 = DA (current AP) */
9613 hwaddr_aton(bssid, pos);
9614 pos += 6;
9615 /* addr2 = SA (own address) */
9616 hwaddr_aton(addr, pos);
9617 pos += 6;
9618 /* addr3 = BSSID (current AP) */
9619 hwaddr_aton(bssid, pos);
9620 pos += 6;
9621
9622 /* Seq# (to be filled by driver/mac80211) */
9623 *pos++ = 0x00;
9624 *pos++ = 0x00;
9625
9626 if (protected == INCORRECT_KEY) {
9627 /* CCMP parameters */
9628 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9629 pos += 8;
9630 }
9631
9632 if (protected == INCORRECT_KEY) {
9633 switch (frame) {
9634 case DEAUTH:
9635 /* Reason code (encrypted) */
9636 memcpy(pos, "\xa7\x39", 2);
9637 pos += 2;
9638 break;
9639 case DISASSOC:
9640 /* Reason code (encrypted) */
9641 memcpy(pos, "\xa7\x39", 2);
9642 pos += 2;
9643 break;
9644 case SAQUERY:
9645 /* Category|Action|TransID (encrypted) */
9646 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9647 pos += 4;
9648 break;
9649 default:
9650 return -1;
9651 }
9652
9653 /* CCMP MIC */
9654 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9655 pos += 8;
9656 } else {
9657 switch (frame) {
9658 case DEAUTH:
9659 /* reason code = 8 */
9660 *pos++ = 0x08;
9661 *pos++ = 0x00;
9662 break;
9663 case DISASSOC:
9664 /* reason code = 8 */
9665 *pos++ = 0x08;
9666 *pos++ = 0x00;
9667 break;
9668 case SAQUERY:
9669 /* Category - SA Query */
9670 *pos++ = 0x08;
9671 /* SA query Action - Request */
9672 *pos++ = 0x00;
9673 /* Transaction ID */
9674 *pos++ = 0x12;
9675 *pos++ = 0x34;
9676 break;
9677 case AUTH:
9678 /* Auth Alg (Open) */
9679 *pos++ = 0x00;
9680 *pos++ = 0x00;
9681 /* Seq# */
9682 *pos++ = 0x01;
9683 *pos++ = 0x00;
9684 /* Status code */
9685 *pos++ = 0x00;
9686 *pos++ = 0x00;
9687 break;
9688 case ASSOCREQ:
9689 /* Capability Information */
9690 *pos++ = 0x31;
9691 *pos++ = 0x04;
9692 /* Listen Interval */
9693 *pos++ = 0x0a;
9694 *pos++ = 0x00;
9695 /* SSID */
9696 *pos++ = 0x00;
9697 *pos++ = ssid_len;
9698 memcpy(pos, ssid, ssid_len);
9699 pos += ssid_len;
9700 /* Supported Rates */
9701 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9702 10);
9703 pos += 10;
9704 /* Extended Supported Rates */
9705 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9706 pos += 6;
9707 /* RSN */
9708 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9709 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9710 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9711 pos += 28;
9712 break;
9713 case REASSOCREQ:
9714 /* Capability Information */
9715 *pos++ = 0x31;
9716 *pos++ = 0x04;
9717 /* Listen Interval */
9718 *pos++ = 0x0a;
9719 *pos++ = 0x00;
9720 /* Current AP */
9721 hwaddr_aton(bssid, pos);
9722 pos += 6;
9723 /* SSID */
9724 *pos++ = 0x00;
9725 *pos++ = ssid_len;
9726 memcpy(pos, ssid, ssid_len);
9727 pos += ssid_len;
9728 /* Supported Rates */
9729 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9730 10);
9731 pos += 10;
9732 /* Extended Supported Rates */
9733 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9734 pos += 6;
9735 /* RSN */
9736 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9737 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9738 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9739 pos += 28;
9740 break;
9741 case DLS_REQ:
9742 /* Category - DLS */
9743 *pos++ = 0x02;
9744 /* DLS Action - Request */
9745 *pos++ = 0x00;
9746 /* Destination MACAddress */
9747 if (dest)
9748 hwaddr_aton(dest, pos);
9749 else
9750 memset(pos, 0, 6);
9751 pos += 6;
9752 /* Source MACAddress */
9753 hwaddr_aton(addr, pos);
9754 pos += 6;
9755 /* Capability Information */
9756 *pos++ = 0x10; /* Privacy */
9757 *pos++ = 0x06; /* QoS */
9758 /* DLS Timeout Value */
9759 *pos++ = 0x00;
9760 *pos++ = 0x01;
9761 /* Supported rates */
9762 *pos++ = 0x01;
9763 *pos++ = 0x08;
9764 *pos++ = 0x0c; /* 6 Mbps */
9765 *pos++ = 0x12; /* 9 Mbps */
9766 *pos++ = 0x18; /* 12 Mbps */
9767 *pos++ = 0x24; /* 18 Mbps */
9768 *pos++ = 0x30; /* 24 Mbps */
9769 *pos++ = 0x48; /* 36 Mbps */
9770 *pos++ = 0x60; /* 48 Mbps */
9771 *pos++ = 0x6c; /* 54 Mbps */
9772 /* TODO: Extended Supported Rates */
9773 /* TODO: HT Capabilities */
9774 break;
9775 }
9776 }
9777
9778 s = open_monitor("sigmadut");
9779 if (s < 0) {
9780 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9781 "monitor socket");
9782 return 0;
9783 }
9784
9785 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9786 if (res < 0) {
9787 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9788 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309789 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009790 return 0;
9791 }
9792 if (res < pos - buf) {
9793 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9794 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309795 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009796 return 0;
9797 }
9798
9799 close(s);
9800
9801 return 1;
9802#else /* __linux__ */
9803 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9804 "yet supported");
9805 return 0;
9806#endif /* __linux__ */
9807}
9808
9809
9810static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9811 struct sigma_conn *conn,
9812 struct sigma_cmd *cmd)
9813{
9814 const char *intf = get_param(cmd, "Interface");
9815 const char *sta, *val;
9816 unsigned char addr[ETH_ALEN];
9817 char buf[100];
9818
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009819 if (!intf)
9820 return -1;
9821
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009822 sta = get_param(cmd, "peer");
9823 if (sta == NULL)
9824 sta = get_param(cmd, "station");
9825 if (sta == NULL) {
9826 send_resp(dut, conn, SIGMA_ERROR,
9827 "ErrorCode,Missing peer address");
9828 return 0;
9829 }
9830 if (hwaddr_aton(sta, addr) < 0) {
9831 send_resp(dut, conn, SIGMA_ERROR,
9832 "ErrorCode,Invalid peer address");
9833 return 0;
9834 }
9835
9836 val = get_param(cmd, "type");
9837 if (val == NULL)
9838 return -1;
9839
9840 if (strcasecmp(val, "DISCOVERY") == 0) {
9841 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9842 if (wpa_command(intf, buf) < 0) {
9843 send_resp(dut, conn, SIGMA_ERROR,
9844 "ErrorCode,Failed to send TDLS discovery");
9845 return 0;
9846 }
9847 return 1;
9848 }
9849
9850 if (strcasecmp(val, "SETUP") == 0) {
9851 int status = 0, timeout = 0;
9852
9853 val = get_param(cmd, "Status");
9854 if (val)
9855 status = atoi(val);
9856
9857 val = get_param(cmd, "Timeout");
9858 if (val)
9859 timeout = atoi(val);
9860
9861 if (status != 0 && status != 37) {
9862 send_resp(dut, conn, SIGMA_ERROR,
9863 "ErrorCode,Unsupported status value");
9864 return 0;
9865 }
9866
9867 if (timeout != 0 && timeout != 301) {
9868 send_resp(dut, conn, SIGMA_ERROR,
9869 "ErrorCode,Unsupported timeout value");
9870 return 0;
9871 }
9872
9873 if (status && timeout) {
9874 send_resp(dut, conn, SIGMA_ERROR,
9875 "ErrorCode,Unsupported timeout+status "
9876 "combination");
9877 return 0;
9878 }
9879
9880 if (status == 37 &&
9881 wpa_command(intf, "SET tdls_testing 0x200")) {
9882 send_resp(dut, conn, SIGMA_ERROR,
9883 "ErrorCode,Failed to enable "
9884 "decline setup response test mode");
9885 return 0;
9886 }
9887
9888 if (timeout == 301) {
9889 int res;
9890 if (dut->no_tpk_expiration)
9891 res = wpa_command(intf,
9892 "SET tdls_testing 0x108");
9893 else
9894 res = wpa_command(intf,
9895 "SET tdls_testing 0x8");
9896 if (res) {
9897 send_resp(dut, conn, SIGMA_ERROR,
9898 "ErrorCode,Failed to set short TPK "
9899 "lifetime");
9900 return 0;
9901 }
9902 }
9903
9904 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9905 if (wpa_command(intf, buf) < 0) {
9906 send_resp(dut, conn, SIGMA_ERROR,
9907 "ErrorCode,Failed to send TDLS setup");
9908 return 0;
9909 }
9910 return 1;
9911 }
9912
9913 if (strcasecmp(val, "TEARDOWN") == 0) {
9914 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9915 if (wpa_command(intf, buf) < 0) {
9916 send_resp(dut, conn, SIGMA_ERROR,
9917 "ErrorCode,Failed to send TDLS teardown");
9918 return 0;
9919 }
9920 return 1;
9921 }
9922
9923 send_resp(dut, conn, SIGMA_ERROR,
9924 "ErrorCode,Unsupported TDLS frame");
9925 return 0;
9926}
9927
9928
9929static int sta_ap_known(const char *ifname, const char *bssid)
9930{
9931 char buf[4096];
9932
Jouni Malinendd32f192018-09-15 02:55:19 +03009933 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009934 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9935 return 0;
9936 if (strncmp(buf, "id=", 3) != 0)
9937 return 0;
9938 return 1;
9939}
9940
9941
9942static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9943 const char *bssid)
9944{
9945 int res;
9946 struct wpa_ctrl *ctrl;
9947 char buf[256];
9948
9949 if (sta_ap_known(ifname, bssid))
9950 return 0;
9951 sigma_dut_print(dut, DUT_MSG_DEBUG,
9952 "AP not in BSS table - start scan");
9953
9954 ctrl = open_wpa_mon(ifname);
9955 if (ctrl == NULL) {
9956 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9957 "wpa_supplicant monitor connection");
9958 return -1;
9959 }
9960
9961 if (wpa_command(ifname, "SCAN") < 0) {
9962 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9963 wpa_ctrl_detach(ctrl);
9964 wpa_ctrl_close(ctrl);
9965 return -1;
9966 }
9967
9968 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9969 buf, sizeof(buf));
9970
9971 wpa_ctrl_detach(ctrl);
9972 wpa_ctrl_close(ctrl);
9973
9974 if (res < 0) {
9975 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9976 return -1;
9977 }
9978
9979 if (sta_ap_known(ifname, bssid))
9980 return 0;
9981 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9982 return -1;
9983}
9984
9985
9986static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9987 struct sigma_conn *conn,
9988 struct sigma_cmd *cmd,
9989 const char *intf)
9990{
9991 char buf[200];
9992
9993 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9994 if (system(buf) != 0) {
9995 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9996 "ndsend");
9997 return 0;
9998 }
9999
10000 return 1;
10001}
10002
10003
10004static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
10005 struct sigma_conn *conn,
10006 struct sigma_cmd *cmd,
10007 const char *intf)
10008{
10009 char buf[200];
10010 const char *ip = get_param(cmd, "SenderIP");
10011
Peng Xu26b356d2017-10-04 17:58:16 -070010012 if (!ip)
10013 return 0;
10014
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010015 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
10016 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10017 if (system(buf) == 0) {
10018 sigma_dut_print(dut, DUT_MSG_INFO,
10019 "Neighbor Solicitation got a response "
10020 "for %s@%s", ip, intf);
10021 }
10022
10023 return 1;
10024}
10025
10026
10027static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
10028 struct sigma_conn *conn,
10029 struct sigma_cmd *cmd,
10030 const char *ifname)
10031{
10032 char buf[200];
10033 const char *ip = get_param(cmd, "SenderIP");
10034
10035 if (ip == NULL) {
10036 send_resp(dut, conn, SIGMA_ERROR,
10037 "ErrorCode,Missing SenderIP parameter");
10038 return 0;
10039 }
10040 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
10041 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10042 if (system(buf) != 0) {
10043 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
10044 "for %s@%s", ip, ifname);
10045 }
10046
10047 return 1;
10048}
10049
10050
10051static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
10052 struct sigma_conn *conn,
10053 struct sigma_cmd *cmd,
10054 const char *ifname)
10055{
10056 char buf[200];
10057 char ip[16];
10058 int s;
Peng Xub3756882017-10-04 14:39:09 -070010059 struct ifreq ifr;
10060 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010061
10062 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -070010063 if (s < 0) {
10064 perror("socket");
10065 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010066 }
10067
Peng Xub3756882017-10-04 14:39:09 -070010068 memset(&ifr, 0, sizeof(ifr));
10069 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
10070 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
10071 sigma_dut_print(dut, DUT_MSG_INFO,
10072 "Failed to get %s IP address: %s",
10073 ifname, strerror(errno));
10074 close(s);
10075 return -1;
10076 }
10077 close(s);
10078
10079 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
10080 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
10081
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010082 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
10083 ip);
10084 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10085 if (system(buf) != 0) {
10086 }
10087
10088 return 1;
10089}
10090
10091
10092static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
10093 struct sigma_conn *conn,
10094 struct sigma_cmd *cmd,
10095 const char *ifname)
10096{
10097 char buf[200], addr[20];
10098 char dst[ETH_ALEN], src[ETH_ALEN];
10099 short ethtype = htons(ETH_P_ARP);
10100 char *pos;
10101 int s, res;
10102 const char *val;
10103 struct sockaddr_in taddr;
10104
10105 val = get_param(cmd, "dest");
10106 if (val)
10107 hwaddr_aton(val, (unsigned char *) dst);
10108
10109 val = get_param(cmd, "DestIP");
10110 if (val)
10111 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -070010112 else
10113 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010114
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010115 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010116 sizeof(addr)) < 0)
10117 return -2;
10118 hwaddr_aton(addr, (unsigned char *) src);
10119
10120 pos = buf;
10121 *pos++ = 0x00;
10122 *pos++ = 0x01;
10123 *pos++ = 0x08;
10124 *pos++ = 0x00;
10125 *pos++ = 0x06;
10126 *pos++ = 0x04;
10127 *pos++ = 0x00;
10128 *pos++ = 0x02;
10129 memcpy(pos, src, ETH_ALEN);
10130 pos += ETH_ALEN;
10131 memcpy(pos, &taddr.sin_addr, 4);
10132 pos += 4;
10133 memcpy(pos, dst, ETH_ALEN);
10134 pos += ETH_ALEN;
10135 memcpy(pos, &taddr.sin_addr, 4);
10136 pos += 4;
10137
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010138 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010139 if (s < 0) {
10140 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10141 "monitor socket");
10142 return 0;
10143 }
10144
10145 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10146 if (res < 0) {
10147 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10148 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010149 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010150 return 0;
10151 }
10152
10153 close(s);
10154
10155 return 1;
10156}
10157
10158
10159static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10160 struct sigma_conn *conn,
10161 struct sigma_cmd *cmd,
10162 const char *intf, const char *dest)
10163{
10164 char buf[100];
10165
10166 if (if_nametoindex("sigmadut") == 0) {
10167 snprintf(buf, sizeof(buf),
10168 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010169 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010170 if (system(buf) != 0 ||
10171 if_nametoindex("sigmadut") == 0) {
10172 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10173 "monitor interface with '%s'", buf);
10174 return -2;
10175 }
10176 }
10177
10178 if (system("ifconfig sigmadut up") != 0) {
10179 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10180 "monitor interface up");
10181 return -2;
10182 }
10183
10184 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10185}
10186
10187
10188static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10189 struct sigma_conn *conn,
10190 struct sigma_cmd *cmd)
10191{
10192 const char *intf = get_param(cmd, "Interface");
10193 const char *dest = get_param(cmd, "Dest");
10194 const char *type = get_param(cmd, "FrameName");
10195 const char *val;
10196 char buf[200], *pos, *end;
10197 int count, count2;
10198
10199 if (type == NULL)
10200 type = get_param(cmd, "Type");
10201
10202 if (intf == NULL || dest == NULL || type == NULL)
10203 return -1;
10204
10205 if (strcasecmp(type, "NeighAdv") == 0)
10206 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10207
10208 if (strcasecmp(type, "NeighSolicitReq") == 0)
10209 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10210
10211 if (strcasecmp(type, "ARPProbe") == 0)
10212 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10213
10214 if (strcasecmp(type, "ARPAnnounce") == 0)
10215 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10216
10217 if (strcasecmp(type, "ARPReply") == 0)
10218 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10219
10220 if (strcasecmp(type, "DLS-request") == 0 ||
10221 strcasecmp(type, "DLSrequest") == 0)
10222 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10223 dest);
10224
10225 if (strcasecmp(type, "ANQPQuery") != 0 &&
10226 strcasecmp(type, "Query") != 0) {
10227 send_resp(dut, conn, SIGMA_ERROR,
10228 "ErrorCode,Unsupported HS 2.0 send frame type");
10229 return 0;
10230 }
10231
10232 if (sta_scan_ap(dut, intf, dest) < 0) {
10233 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10234 "the requested AP");
10235 return 0;
10236 }
10237
10238 pos = buf;
10239 end = buf + sizeof(buf);
10240 count = 0;
10241 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10242
10243 val = get_param(cmd, "ANQP_CAP_LIST");
10244 if (val && atoi(val)) {
10245 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10246 count++;
10247 }
10248
10249 val = get_param(cmd, "VENUE_NAME");
10250 if (val && atoi(val)) {
10251 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10252 count++;
10253 }
10254
10255 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10256 if (val && atoi(val)) {
10257 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10258 count++;
10259 }
10260
10261 val = get_param(cmd, "ROAMING_CONS");
10262 if (val && atoi(val)) {
10263 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10264 count++;
10265 }
10266
10267 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10268 if (val && atoi(val)) {
10269 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10270 count++;
10271 }
10272
10273 val = get_param(cmd, "NAI_REALM_LIST");
10274 if (val && atoi(val)) {
10275 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10276 count++;
10277 }
10278
10279 val = get_param(cmd, "3GPP_INFO");
10280 if (val && atoi(val)) {
10281 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10282 count++;
10283 }
10284
10285 val = get_param(cmd, "DOMAIN_LIST");
10286 if (val && atoi(val)) {
10287 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10288 count++;
10289 }
10290
Jouni Malinen34cf9532018-04-29 19:26:33 +030010291 val = get_param(cmd, "Venue_URL");
10292 if (val && atoi(val)) {
10293 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10294 count++;
10295 }
10296
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010297 val = get_param(cmd, "Advice_Of_Charge");
10298 if (val && atoi(val)) {
10299 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10300 count++;
10301 }
10302
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010303 if (count && wpa_command(intf, buf)) {
10304 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10305 return 0;
10306 }
10307
10308 pos = buf;
10309 end = buf + sizeof(buf);
10310 count2 = 0;
10311 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10312
10313 val = get_param(cmd, "HS_CAP_LIST");
10314 if (val && atoi(val)) {
10315 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10316 count2++;
10317 }
10318
10319 val = get_param(cmd, "OPER_NAME");
10320 if (val && atoi(val)) {
10321 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10322 count2++;
10323 }
10324
10325 val = get_param(cmd, "WAN_METRICS");
10326 if (!val)
10327 val = get_param(cmd, "WAN_MAT");
10328 if (!val)
10329 val = get_param(cmd, "WAN_MET");
10330 if (val && atoi(val)) {
10331 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10332 count2++;
10333 }
10334
10335 val = get_param(cmd, "CONNECTION_CAPABILITY");
10336 if (val && atoi(val)) {
10337 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10338 count2++;
10339 }
10340
10341 val = get_param(cmd, "OP_CLASS");
10342 if (val && atoi(val)) {
10343 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10344 count2++;
10345 }
10346
10347 val = get_param(cmd, "OSU_PROVIDER_LIST");
10348 if (val && atoi(val)) {
10349 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10350 count2++;
10351 }
10352
Jouni Malinenf67afec2018-04-29 19:24:58 +030010353 val = get_param(cmd, "OPER_ICON_METADATA");
10354 if (!val)
10355 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10356 if (val && atoi(val)) {
10357 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10358 count2++;
10359 }
10360
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010361 if (count && count2) {
10362 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10363 "second query");
10364 sleep(1);
10365 }
10366
10367 if (count2 && wpa_command(intf, buf)) {
10368 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10369 "failed");
10370 return 0;
10371 }
10372
10373 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10374 if (val) {
10375 if (count || count2) {
10376 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10377 "sending out second query");
10378 sleep(1);
10379 }
10380
10381 if (strcmp(val, "1") == 0)
10382 val = "mail.example.com";
10383 snprintf(buf, end - pos,
10384 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10385 dest, val);
10386 if (wpa_command(intf, buf)) {
10387 send_resp(dut, conn, SIGMA_ERROR,
10388 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10389 "failed");
10390 return 0;
10391 }
10392 }
10393
10394 val = get_param(cmd, "ICON_REQUEST");
10395 if (val) {
10396 if (count || count2) {
10397 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10398 "sending out second query");
10399 sleep(1);
10400 }
10401
10402 snprintf(buf, end - pos,
10403 "HS20_ICON_REQUEST %s %s", dest, val);
10404 if (wpa_command(intf, buf)) {
10405 send_resp(dut, conn, SIGMA_ERROR,
10406 "ErrorCode,HS20_ICON_REQUEST failed");
10407 return 0;
10408 }
10409 }
10410
10411 return 1;
10412}
10413
10414
10415static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10416 struct sigma_conn *conn,
10417 struct sigma_cmd *cmd)
10418{
10419 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010420 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010421 int chwidth, nss;
10422
10423 val = get_param(cmd, "framename");
10424 if (!val)
10425 return -1;
10426 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10427
10428 /* Command sequence to generate Op mode notification */
10429 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010430 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010431
10432 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010433 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010434
10435 /* Extract Channel width */
10436 val = get_param(cmd, "Channel_width");
10437 if (val) {
10438 switch (atoi(val)) {
10439 case 20:
10440 chwidth = 0;
10441 break;
10442 case 40:
10443 chwidth = 1;
10444 break;
10445 case 80:
10446 chwidth = 2;
10447 break;
10448 case 160:
10449 chwidth = 3;
10450 break;
10451 default:
10452 chwidth = 2;
10453 break;
10454 }
10455
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010456 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010457 }
10458
10459 /* Extract NSS */
10460 val = get_param(cmd, "NSS");
10461 if (val) {
10462 switch (atoi(val)) {
10463 case 1:
10464 nss = 1;
10465 break;
10466 case 2:
10467 nss = 3;
10468 break;
10469 case 3:
10470 nss = 7;
10471 break;
10472 default:
10473 /* We do not support NSS > 3 */
10474 nss = 3;
10475 break;
10476 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010477 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010478 }
10479
10480 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010481 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010482 }
10483
10484 return 1;
10485}
10486
10487
10488static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10489 struct sigma_conn *conn,
10490 struct sigma_cmd *cmd)
10491{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010492 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010493 case DRIVER_ATHEROS:
10494 return ath_sta_send_frame_vht(dut, conn, cmd);
10495 default:
10496 send_resp(dut, conn, SIGMA_ERROR,
10497 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10498 return 0;
10499 }
10500}
10501
10502
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010503static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10504 struct sigma_cmd *cmd)
10505{
10506 const char *val;
10507 const char *intf = get_param(cmd, "Interface");
10508
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010509 if (!intf)
10510 return -1;
10511
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010512 val = get_param(cmd, "framename");
10513 if (!val)
10514 return -1;
10515 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10516
10517 /* Command sequence to generate Op mode notification */
10518 if (val && strcasecmp(val, "action") == 0) {
10519 val = get_param(cmd, "PPDUTxType");
10520 if (val && strcasecmp(val, "TB") == 0) {
10521 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10522 sigma_dut_print(dut, DUT_MSG_ERROR,
10523 "failed to send TB PPDU Tx cfg");
10524 send_resp(dut, conn, SIGMA_ERROR,
10525 "ErrorCode,set TB PPDU Tx cfg failed");
10526 return 0;
10527 }
10528 return 1;
10529 }
10530
10531 sigma_dut_print(dut, DUT_MSG_ERROR,
10532 "Action Tx type is not defined");
10533 }
10534
10535 return 1;
10536}
10537
10538
10539static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10540 struct sigma_conn *conn,
10541 struct sigma_cmd *cmd)
10542{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010543 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010544 case DRIVER_WCN:
10545 return wcn_sta_send_frame_he(dut, conn, cmd);
10546 default:
10547 send_resp(dut, conn, SIGMA_ERROR,
10548 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10549 return 0;
10550 }
10551}
10552
10553
Lior David0fe101e2017-03-09 16:09:50 +020010554#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010555
10556static int
10557wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10558 const char *frame_name, const char *dest_mac)
10559{
10560 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10561 const char *ssid = get_param(cmd, "ssid");
10562 const char *countstr = get_param(cmd, "count");
10563 const char *channelstr = get_param(cmd, "channel");
10564 const char *group_id = get_param(cmd, "groupid");
10565 const char *client_id = get_param(cmd, "clientmac");
10566 int count, channel, freq, i;
10567 const char *fname;
10568 char frame[1024], src_mac[20], group_id_attr[25],
10569 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10570 const char *group_ssid;
10571 const int group_ssid_prefix_len = 9;
10572 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10573 size_t framelen = sizeof(frame);
10574 struct template_frame_tag tags[2];
10575 size_t tags_total = ARRAY_SIZE(tags);
10576 int tag_index, len, dst_len;
10577
10578 if (!countstr || !channelstr) {
10579 sigma_dut_print(dut, DUT_MSG_ERROR,
10580 "Missing argument: count, channel");
10581 return -1;
10582 }
10583 if (isprobereq && !ssid) {
10584 sigma_dut_print(dut, DUT_MSG_ERROR,
10585 "Missing argument: ssid");
10586 return -1;
10587 }
10588 if (!isprobereq && (!group_id || !client_id)) {
10589 sigma_dut_print(dut, DUT_MSG_ERROR,
10590 "Missing argument: group_id, client_id");
10591 return -1;
10592 }
10593
10594 count = atoi(countstr);
10595 channel = atoi(channelstr);
10596 freq = channel_to_freq(dut, channel);
10597
10598 if (!freq) {
10599 sigma_dut_print(dut, DUT_MSG_ERROR,
10600 "invalid channel: %s", channelstr);
10601 return -1;
10602 }
10603
10604 if (isprobereq) {
10605 if (strcasecmp(ssid, "wildcard") == 0) {
10606 fname = "probe_req_wildcard.txt";
10607 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10608 fname = "probe_req_P2P_Wildcard.txt";
10609 } else {
10610 sigma_dut_print(dut, DUT_MSG_ERROR,
10611 "invalid probe request type");
10612 return -1;
10613 }
10614 } else {
10615 fname = "P2P_device_discovery_req.txt";
10616 }
10617
10618 if (parse_template_frame_file(dut, fname, frame, &framelen,
10619 tags, &tags_total)) {
10620 sigma_dut_print(dut, DUT_MSG_ERROR,
10621 "invalid frame template: %s", fname);
10622 return -1;
10623 }
10624
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010625 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010626 src_mac, sizeof(src_mac)) < 0 ||
10627 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10628 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10629 return -1;
10630 /* Use wildcard BSSID, since we are in PBSS */
10631 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10632
10633 if (!isprobereq) {
10634 tag_index = find_template_frame_tag(tags, tags_total, 1);
10635 if (tag_index < 0) {
10636 sigma_dut_print(dut, DUT_MSG_ERROR,
10637 "can't find device id attribute");
10638 return -1;
10639 }
10640 if (parse_mac_address(dut, client_id,
10641 (unsigned char *) client_mac)) {
10642 sigma_dut_print(dut, DUT_MSG_ERROR,
10643 "invalid client_id: %s", client_id);
10644 return -1;
10645 }
10646 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10647 framelen - tags[tag_index].offset,
10648 IEEE80211_P2P_ATTR_DEVICE_ID,
10649 client_mac, ETH_ALEN)) {
10650 sigma_dut_print(dut, DUT_MSG_ERROR,
10651 "fail to replace device id attribute");
10652 return -1;
10653 }
10654
10655 /*
10656 * group_id arg contains device MAC address followed by
10657 * space and SSID (DIRECT-somessid).
10658 * group id attribute contains device address (6 bytes)
10659 * followed by SSID prefix DIRECT-XX (9 bytes)
10660 */
10661 if (strlen(group_id) < sizeof(device_macstr)) {
10662 sigma_dut_print(dut, DUT_MSG_ERROR,
10663 "group_id arg too short");
10664 return -1;
10665 }
10666 memcpy(device_macstr, group_id, sizeof(device_macstr));
10667 device_macstr[sizeof(device_macstr) - 1] = '\0';
10668 if (parse_mac_address(dut, device_macstr,
10669 (unsigned char *) group_id_attr)) {
10670 sigma_dut_print(dut, DUT_MSG_ERROR,
10671 "fail to parse device address from group_id");
10672 return -1;
10673 }
10674 group_ssid = strchr(group_id, ' ');
10675 if (!group_ssid) {
10676 sigma_dut_print(dut, DUT_MSG_ERROR,
10677 "invalid group_id arg, no ssid");
10678 return -1;
10679 }
10680 group_ssid++;
10681 len = strlen(group_ssid);
10682 if (len < group_ssid_prefix_len) {
10683 sigma_dut_print(dut, DUT_MSG_ERROR,
10684 "group_id SSID too short");
10685 return -1;
10686 }
10687 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10688 if (len > dst_len) {
10689 sigma_dut_print(dut, DUT_MSG_ERROR,
10690 "group_id SSID (%s) too long",
10691 group_ssid);
10692 return -1;
10693 }
10694
10695 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10696 tag_index = find_template_frame_tag(tags, tags_total, 2);
10697 if (tag_index < 0) {
10698 sigma_dut_print(dut, DUT_MSG_ERROR,
10699 "can't find group id attribute");
10700 return -1;
10701 }
10702 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10703 framelen - tags[tag_index].offset,
10704 IEEE80211_P2P_ATTR_GROUP_ID,
10705 group_id_attr,
10706 sizeof(group_id_attr))) {
10707 sigma_dut_print(dut, DUT_MSG_ERROR,
10708 "fail to replace group id attribute");
10709 return -1;
10710 }
10711 }
10712
10713 for (i = 0; i < count; i++) {
10714 if (wil6210_transmit_frame(dut, freq,
10715 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10716 frame, framelen)) {
10717 sigma_dut_print(dut, DUT_MSG_ERROR,
10718 "fail to transmit probe request frame");
10719 return -1;
10720 }
10721 }
10722
10723 return 0;
10724}
10725
10726
Lior David0fe101e2017-03-09 16:09:50 +020010727int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10728 struct sigma_cmd *cmd)
10729{
10730 const char *frame_name = get_param(cmd, "framename");
10731 const char *mac = get_param(cmd, "dest_mac");
10732
10733 if (!frame_name || !mac) {
10734 sigma_dut_print(dut, DUT_MSG_ERROR,
10735 "framename and dest_mac must be provided");
10736 return -1;
10737 }
10738
10739 if (strcasecmp(frame_name, "brp") == 0) {
10740 const char *l_rx = get_param(cmd, "L-RX");
10741 int l_rx_i;
10742
10743 if (!l_rx) {
10744 sigma_dut_print(dut, DUT_MSG_ERROR,
10745 "L-RX must be provided");
10746 return -1;
10747 }
10748 l_rx_i = atoi(l_rx);
10749
10750 sigma_dut_print(dut, DUT_MSG_INFO,
10751 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10752 mac, l_rx);
10753 if (l_rx_i != 16) {
10754 sigma_dut_print(dut, DUT_MSG_ERROR,
10755 "unsupported L-RX: %s", l_rx);
10756 return -1;
10757 }
10758
10759 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10760 return -1;
10761 } else if (strcasecmp(frame_name, "ssw") == 0) {
10762 sigma_dut_print(dut, DUT_MSG_INFO,
10763 "dev_send_frame: SLS, dest_mac %s", mac);
10764 if (wil6210_send_sls(dut, mac))
10765 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010766 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10767 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10768 sigma_dut_print(dut, DUT_MSG_INFO,
10769 "dev_send_frame: %s, dest_mac %s", frame_name,
10770 mac);
10771 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10772 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010773 } else {
10774 sigma_dut_print(dut, DUT_MSG_ERROR,
10775 "unsupported frame type: %s", frame_name);
10776 return -1;
10777 }
10778
10779 return 1;
10780}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010781
Lior David0fe101e2017-03-09 16:09:50 +020010782#endif /* __linux__ */
10783
10784
10785static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10786 struct sigma_conn *conn,
10787 struct sigma_cmd *cmd)
10788{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010789 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010790#ifdef __linux__
10791 case DRIVER_WIL6210:
10792 return wil6210_send_frame_60g(dut, conn, cmd);
10793#endif /* __linux__ */
10794 default:
10795 send_resp(dut, conn, SIGMA_ERROR,
10796 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10797 return 0;
10798 }
10799}
10800
10801
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010802static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10803 const char *intf, struct sigma_cmd *cmd)
10804{
10805 const char *val, *addr;
10806 char buf[100];
10807
10808 addr = get_param(cmd, "DestMac");
10809 if (!addr) {
10810 send_resp(dut, conn, SIGMA_INVALID,
10811 "ErrorCode,AP MAC address is missing");
10812 return 0;
10813 }
10814
10815 val = get_param(cmd, "ANQPQuery_ID");
10816 if (!val) {
10817 send_resp(dut, conn, SIGMA_INVALID,
10818 "ErrorCode,Missing ANQPQuery_ID");
10819 return 0;
10820 }
10821
10822 if (strcasecmp(val, "NeighborReportReq") == 0) {
10823 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10824 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10825 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10826 } else {
10827 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10828 val);
10829 send_resp(dut, conn, SIGMA_INVALID,
10830 "ErrorCode,Invalid ANQPQuery_ID");
10831 return 0;
10832 }
10833
Ashwini Patild174f2c2017-04-13 16:49:46 +053010834 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10835 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10836 * if associated, AP BSSID).
10837 */
10838 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10839 send_resp(dut, conn, SIGMA_ERROR,
10840 "ErrorCode,Failed to set gas_address3");
10841 return 0;
10842 }
10843
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010844 if (wpa_command(intf, buf) < 0) {
10845 send_resp(dut, conn, SIGMA_ERROR,
10846 "ErrorCode,Failed to send ANQP query");
10847 return 0;
10848 }
10849
10850 return 1;
10851}
10852
10853
10854static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10855 struct sigma_conn *conn,
10856 const char *intf,
10857 struct sigma_cmd *cmd)
10858{
10859 const char *val = get_param(cmd, "FrameName");
10860
10861 if (val && strcasecmp(val, "ANQPQuery") == 0)
10862 return mbo_send_anqp_query(dut, conn, intf, cmd);
10863
10864 return 2;
10865}
10866
10867
Jouni Malinenf7222712019-06-13 01:50:21 +030010868enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10869 struct sigma_conn *conn,
10870 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010871{
10872 const char *intf = get_param(cmd, "Interface");
10873 const char *val;
10874 enum send_frame_type frame;
10875 enum send_frame_protection protected;
10876 char buf[100];
10877 unsigned char addr[ETH_ALEN];
10878 int res;
10879
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010880 if (!intf)
10881 return -1;
10882
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010883 val = get_param(cmd, "program");
10884 if (val == NULL)
10885 val = get_param(cmd, "frame");
10886 if (val && strcasecmp(val, "TDLS") == 0)
10887 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10888 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010889 strcasecmp(val, "HS2-R2") == 0 ||
10890 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010891 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10892 if (val && strcasecmp(val, "VHT") == 0)
10893 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010894 if (val && strcasecmp(val, "HE") == 0)
10895 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010896 if (val && strcasecmp(val, "LOC") == 0)
10897 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010898 if (val && strcasecmp(val, "60GHz") == 0)
10899 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010900 if (val && strcasecmp(val, "MBO") == 0) {
10901 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10902 if (res != 2)
10903 return res;
10904 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010905
10906 val = get_param(cmd, "TD_DISC");
10907 if (val) {
10908 if (hwaddr_aton(val, addr) < 0)
10909 return -1;
10910 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10911 if (wpa_command(intf, buf) < 0) {
10912 send_resp(dut, conn, SIGMA_ERROR,
10913 "ErrorCode,Failed to send TDLS discovery");
10914 return 0;
10915 }
10916 return 1;
10917 }
10918
10919 val = get_param(cmd, "TD_Setup");
10920 if (val) {
10921 if (hwaddr_aton(val, addr) < 0)
10922 return -1;
10923 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10924 if (wpa_command(intf, buf) < 0) {
10925 send_resp(dut, conn, SIGMA_ERROR,
10926 "ErrorCode,Failed to start TDLS setup");
10927 return 0;
10928 }
10929 return 1;
10930 }
10931
10932 val = get_param(cmd, "TD_TearDown");
10933 if (val) {
10934 if (hwaddr_aton(val, addr) < 0)
10935 return -1;
10936 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10937 if (wpa_command(intf, buf) < 0) {
10938 send_resp(dut, conn, SIGMA_ERROR,
10939 "ErrorCode,Failed to tear down TDLS link");
10940 return 0;
10941 }
10942 return 1;
10943 }
10944
10945 val = get_param(cmd, "TD_ChannelSwitch");
10946 if (val) {
10947 /* TODO */
10948 send_resp(dut, conn, SIGMA_ERROR,
10949 "ErrorCode,TD_ChannelSwitch not yet supported");
10950 return 0;
10951 }
10952
10953 val = get_param(cmd, "TD_NF");
10954 if (val) {
10955 /* TODO */
10956 send_resp(dut, conn, SIGMA_ERROR,
10957 "ErrorCode,TD_NF not yet supported");
10958 return 0;
10959 }
10960
10961 val = get_param(cmd, "PMFFrameType");
10962 if (val == NULL)
10963 val = get_param(cmd, "FrameName");
10964 if (val == NULL)
10965 val = get_param(cmd, "Type");
10966 if (val == NULL)
10967 return -1;
10968 if (strcasecmp(val, "disassoc") == 0)
10969 frame = DISASSOC;
10970 else if (strcasecmp(val, "deauth") == 0)
10971 frame = DEAUTH;
10972 else if (strcasecmp(val, "saquery") == 0)
10973 frame = SAQUERY;
10974 else if (strcasecmp(val, "auth") == 0)
10975 frame = AUTH;
10976 else if (strcasecmp(val, "assocreq") == 0)
10977 frame = ASSOCREQ;
10978 else if (strcasecmp(val, "reassocreq") == 0)
10979 frame = REASSOCREQ;
10980 else if (strcasecmp(val, "neigreq") == 0) {
10981 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10982
10983 val = get_param(cmd, "ssid");
10984 if (val == NULL)
10985 return -1;
10986
10987 res = send_neighbor_request(dut, intf, val);
10988 if (res) {
10989 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10990 "Failed to send neighbor report request");
10991 return 0;
10992 }
10993
10994 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010995 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10996 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010997 sigma_dut_print(dut, DUT_MSG_DEBUG,
10998 "Got Transition Management Query");
10999
Ashwini Patil5acd7382017-04-13 15:55:04 +053011000 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011001 if (res) {
11002 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11003 "Failed to send Transition Management Query");
11004 return 0;
11005 }
11006
11007 return 1;
11008 } else {
11009 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11010 "PMFFrameType");
11011 return 0;
11012 }
11013
11014 val = get_param(cmd, "PMFProtected");
11015 if (val == NULL)
11016 val = get_param(cmd, "Protected");
11017 if (val == NULL)
11018 return -1;
11019 if (strcasecmp(val, "Correct-key") == 0 ||
11020 strcasecmp(val, "CorrectKey") == 0)
11021 protected = CORRECT_KEY;
11022 else if (strcasecmp(val, "IncorrectKey") == 0)
11023 protected = INCORRECT_KEY;
11024 else if (strcasecmp(val, "Unprotected") == 0)
11025 protected = UNPROTECTED;
11026 else {
11027 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11028 "PMFProtected");
11029 return 0;
11030 }
11031
11032 if (protected != UNPROTECTED &&
11033 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
11034 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
11035 "PMFProtected for auth/assocreq/reassocreq");
11036 return 0;
11037 }
11038
11039 if (if_nametoindex("sigmadut") == 0) {
11040 snprintf(buf, sizeof(buf),
11041 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011042 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011043 if (system(buf) != 0 ||
11044 if_nametoindex("sigmadut") == 0) {
11045 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
11046 "monitor interface with '%s'", buf);
11047 return -2;
11048 }
11049 }
11050
11051 if (system("ifconfig sigmadut up") != 0) {
11052 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
11053 "monitor interface up");
11054 return -2;
11055 }
11056
11057 return sta_inject_frame(dut, conn, frame, protected, NULL);
11058}
11059
11060
11061static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
11062 struct sigma_conn *conn,
11063 struct sigma_cmd *cmd,
11064 const char *ifname)
11065{
11066 char buf[200];
11067 const char *val;
11068
11069 val = get_param(cmd, "ClearARP");
11070 if (val && atoi(val) == 1) {
11071 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
11072 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11073 if (system(buf) != 0) {
11074 send_resp(dut, conn, SIGMA_ERROR,
11075 "errorCode,Failed to clear ARP cache");
11076 return 0;
11077 }
11078 }
11079
11080 return 1;
11081}
11082
11083
11084int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
11085 struct sigma_cmd *cmd)
11086{
11087 const char *intf = get_param(cmd, "Interface");
11088 const char *val;
11089
11090 if (intf == NULL)
11091 return -1;
11092
11093 val = get_param(cmd, "program");
11094 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030011095 strcasecmp(val, "HS2-R2") == 0 ||
11096 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011097 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
11098
11099 return -1;
11100}
11101
11102
Jouni Malinenf7222712019-06-13 01:50:21 +030011103static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
11104 struct sigma_conn *conn,
11105 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011106{
11107 const char *intf = get_param(cmd, "Interface");
11108 const char *mac = get_param(cmd, "MAC");
11109
11110 if (intf == NULL || mac == NULL)
11111 return -1;
11112
11113 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
11114 "interface %s to %s", intf, mac);
11115
11116 if (dut->set_macaddr) {
11117 char buf[128];
11118 int res;
11119 if (strcasecmp(mac, "default") == 0) {
11120 res = snprintf(buf, sizeof(buf), "%s",
11121 dut->set_macaddr);
11122 dut->tmp_mac_addr = 0;
11123 } else {
11124 res = snprintf(buf, sizeof(buf), "%s %s",
11125 dut->set_macaddr, mac);
11126 dut->tmp_mac_addr = 1;
11127 }
11128 if (res < 0 || res >= (int) sizeof(buf))
11129 return -1;
11130 if (system(buf) != 0) {
11131 send_resp(dut, conn, SIGMA_ERROR,
11132 "errorCode,Failed to set MAC "
11133 "address");
11134 return 0;
11135 }
11136 return 1;
11137 }
11138
11139 if (strcasecmp(mac, "default") == 0)
11140 return 1;
11141
11142 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11143 "command");
11144 return 0;
11145}
11146
11147
11148static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11149 struct sigma_conn *conn, const char *intf,
11150 int val)
11151{
11152 char buf[200];
11153 int res;
11154
11155 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11156 intf, val);
11157 if (res < 0 || res >= (int) sizeof(buf))
11158 return -1;
11159 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11160 if (system(buf) != 0) {
11161 send_resp(dut, conn, SIGMA_ERROR,
11162 "errorCode,Failed to configure offchannel mode");
11163 return 0;
11164 }
11165
11166 return 1;
11167}
11168
11169
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011170static int off_chan_val(enum sec_ch_offset off)
11171{
11172 switch (off) {
11173 case SEC_CH_NO:
11174 return 0;
11175 case SEC_CH_40ABOVE:
11176 return 40;
11177 case SEC_CH_40BELOW:
11178 return -40;
11179 }
11180
11181 return 0;
11182}
11183
11184
11185static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11186 const char *intf, int off_ch_num,
11187 enum sec_ch_offset sec)
11188{
11189 char buf[200];
11190 int res;
11191
11192 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11193 intf, off_ch_num);
11194 if (res < 0 || res >= (int) sizeof(buf))
11195 return -1;
11196 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11197 if (system(buf) != 0) {
11198 send_resp(dut, conn, SIGMA_ERROR,
11199 "errorCode,Failed to set offchan");
11200 return 0;
11201 }
11202
11203 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11204 intf, off_chan_val(sec));
11205 if (res < 0 || res >= (int) sizeof(buf))
11206 return -1;
11207 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11208 if (system(buf) != 0) {
11209 send_resp(dut, conn, SIGMA_ERROR,
11210 "errorCode,Failed to set sec chan offset");
11211 return 0;
11212 }
11213
11214 return 1;
11215}
11216
11217
11218static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11219 struct sigma_conn *conn,
11220 const char *intf, int off_ch_num,
11221 enum sec_ch_offset sec)
11222{
11223 char buf[200];
11224 int res;
11225
11226 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11227 off_ch_num);
11228 if (res < 0 || res >= (int) sizeof(buf))
11229 return -1;
11230 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11231
11232 if (wpa_command(intf, buf) < 0) {
11233 send_resp(dut, conn, SIGMA_ERROR,
11234 "ErrorCode,Failed to set offchan");
11235 return 0;
11236 }
11237 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11238 off_chan_val(sec));
11239 if (res < 0 || res >= (int) sizeof(buf))
11240 return -1;
11241
11242 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11243
11244 if (wpa_command(intf, buf) < 0) {
11245 send_resp(dut, conn, SIGMA_ERROR,
11246 "ErrorCode,Failed to set sec chan offset");
11247 return 0;
11248 }
11249
11250 return 1;
11251}
11252
11253
11254static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11255 struct sigma_conn *conn,
11256 const char *intf, int val)
11257{
11258 char buf[200];
11259 int res;
11260
11261 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11262 val);
11263 if (res < 0 || res >= (int) sizeof(buf))
11264 return -1;
11265 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11266
11267 if (wpa_command(intf, buf) < 0) {
11268 send_resp(dut, conn, SIGMA_ERROR,
11269 "ErrorCode,Failed to configure offchannel mode");
11270 return 0;
11271 }
11272
11273 return 1;
11274}
11275
11276
11277static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11278 struct sigma_conn *conn,
11279 struct sigma_cmd *cmd)
11280{
11281 const char *val;
11282 enum {
11283 CHSM_NOT_SET,
11284 CHSM_ENABLE,
11285 CHSM_DISABLE,
11286 CHSM_REJREQ,
11287 CHSM_UNSOLRESP
11288 } chsm = CHSM_NOT_SET;
11289 int off_ch_num = -1;
11290 enum sec_ch_offset sec_ch = SEC_CH_NO;
11291 int res;
11292
11293 val = get_param(cmd, "Uapsd");
11294 if (val) {
11295 char buf[100];
11296 if (strcasecmp(val, "Enable") == 0)
11297 snprintf(buf, sizeof(buf), "SET ps 99");
11298 else if (strcasecmp(val, "Disable") == 0)
11299 snprintf(buf, sizeof(buf), "SET ps 98");
11300 else {
11301 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11302 "Unsupported uapsd parameter value");
11303 return 0;
11304 }
11305 if (wpa_command(intf, buf)) {
11306 send_resp(dut, conn, SIGMA_ERROR,
11307 "ErrorCode,Failed to change U-APSD "
11308 "powersave mode");
11309 return 0;
11310 }
11311 }
11312
11313 val = get_param(cmd, "TPKTIMER");
11314 if (val && strcasecmp(val, "DISABLE") == 0) {
11315 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11316 send_resp(dut, conn, SIGMA_ERROR,
11317 "ErrorCode,Failed to enable no TPK "
11318 "expiration test mode");
11319 return 0;
11320 }
11321 dut->no_tpk_expiration = 1;
11322 }
11323
11324 val = get_param(cmd, "ChSwitchMode");
11325 if (val) {
11326 if (strcasecmp(val, "Enable") == 0 ||
11327 strcasecmp(val, "Initiate") == 0)
11328 chsm = CHSM_ENABLE;
11329 else if (strcasecmp(val, "Disable") == 0 ||
11330 strcasecmp(val, "passive") == 0)
11331 chsm = CHSM_DISABLE;
11332 else if (strcasecmp(val, "RejReq") == 0)
11333 chsm = CHSM_REJREQ;
11334 else if (strcasecmp(val, "UnSolResp") == 0)
11335 chsm = CHSM_UNSOLRESP;
11336 else {
11337 send_resp(dut, conn, SIGMA_ERROR,
11338 "ErrorCode,Unknown ChSwitchMode value");
11339 return 0;
11340 }
11341 }
11342
11343 val = get_param(cmd, "OffChNum");
11344 if (val) {
11345 off_ch_num = atoi(val);
11346 if (off_ch_num == 0) {
11347 send_resp(dut, conn, SIGMA_ERROR,
11348 "ErrorCode,Invalid OffChNum");
11349 return 0;
11350 }
11351 }
11352
11353 val = get_param(cmd, "SecChOffset");
11354 if (val) {
11355 if (strcmp(val, "20") == 0)
11356 sec_ch = SEC_CH_NO;
11357 else if (strcasecmp(val, "40above") == 0)
11358 sec_ch = SEC_CH_40ABOVE;
11359 else if (strcasecmp(val, "40below") == 0)
11360 sec_ch = SEC_CH_40BELOW;
11361 else {
11362 send_resp(dut, conn, SIGMA_ERROR,
11363 "ErrorCode,Unknown SecChOffset value");
11364 return 0;
11365 }
11366 }
11367
11368 if (chsm == CHSM_NOT_SET) {
11369 /* no offchannel changes requested */
11370 return 1;
11371 }
11372
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011373 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11374 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011375 send_resp(dut, conn, SIGMA_ERROR,
11376 "ErrorCode,Unknown interface");
11377 return 0;
11378 }
11379
11380 switch (chsm) {
11381 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011382 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011383 break;
11384 case CHSM_ENABLE:
11385 if (off_ch_num < 0) {
11386 send_resp(dut, conn, SIGMA_ERROR,
11387 "ErrorCode,Missing OffChNum argument");
11388 return 0;
11389 }
11390 if (wifi_chip_type == DRIVER_WCN) {
11391 res = tdls_set_offchannel_offset(dut, conn, intf,
11392 off_ch_num, sec_ch);
11393 } else {
11394 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11395 sec_ch);
11396 }
11397 if (res != 1)
11398 return res;
11399 if (wifi_chip_type == DRIVER_WCN)
11400 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11401 else
11402 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11403 break;
11404 case CHSM_DISABLE:
11405 if (wifi_chip_type == DRIVER_WCN)
11406 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11407 else
11408 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11409 break;
11410 case CHSM_REJREQ:
11411 if (wifi_chip_type == DRIVER_WCN)
11412 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11413 else
11414 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11415 break;
11416 case CHSM_UNSOLRESP:
11417 if (off_ch_num < 0) {
11418 send_resp(dut, conn, SIGMA_ERROR,
11419 "ErrorCode,Missing OffChNum argument");
11420 return 0;
11421 }
11422 if (wifi_chip_type == DRIVER_WCN) {
11423 res = tdls_set_offchannel_offset(dut, conn, intf,
11424 off_ch_num, sec_ch);
11425 } else {
11426 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11427 sec_ch);
11428 }
11429 if (res != 1)
11430 return res;
11431 if (wifi_chip_type == DRIVER_WCN)
11432 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11433 else
11434 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11435 break;
11436 }
11437
11438 return res;
11439}
11440
11441
11442static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11443 struct sigma_conn *conn,
11444 struct sigma_cmd *cmd)
11445{
11446 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011447 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011448
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011449 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011450
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011451 val = get_param(cmd, "nss_mcs_opt");
11452 if (val) {
11453 /* String (nss_operating_mode; mcs_operating_mode) */
11454 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011455 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011456
11457 token = strdup(val);
11458 if (!token)
11459 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011460 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011461 if (!result) {
11462 sigma_dut_print(dut, DUT_MSG_ERROR,
11463 "VHT NSS not specified");
11464 goto failed;
11465 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011466 if (strcasecmp(result, "def") != 0) {
11467 nss = atoi(result);
11468 if (nss == 4)
11469 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011470 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011471 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011472
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011473 }
11474
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011475 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011476 if (!result) {
11477 sigma_dut_print(dut, DUT_MSG_ERROR,
11478 "VHT MCS not specified");
11479 goto failed;
11480 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011481 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011482 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011483 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011484 } else {
11485 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011486 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011487 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011488 }
11489 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011490 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011491 }
11492
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011493 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011494 return 1;
11495failed:
11496 free(token);
11497 return 0;
11498}
11499
11500
11501static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11502 struct sigma_conn *conn,
11503 struct sigma_cmd *cmd)
11504{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011505 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011506 case DRIVER_ATHEROS:
11507 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11508 default:
11509 send_resp(dut, conn, SIGMA_ERROR,
11510 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11511 return 0;
11512 }
11513}
11514
11515
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011516static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11517 struct sigma_conn *conn,
11518 struct sigma_cmd *cmd)
11519{
11520 const char *val;
11521 char *token = NULL, *result;
11522 char buf[60];
11523
11524 val = get_param(cmd, "nss_mcs_opt");
11525 if (val) {
11526 /* String (nss_operating_mode; mcs_operating_mode) */
11527 int nss, mcs, ratecode;
11528 char *saveptr;
11529
11530 token = strdup(val);
11531 if (!token)
11532 return -2;
11533
11534 result = strtok_r(token, ";", &saveptr);
11535 if (!result) {
11536 sigma_dut_print(dut, DUT_MSG_ERROR,
11537 "HE NSS not specified");
11538 goto failed;
11539 }
11540 nss = 1;
11541 if (strcasecmp(result, "def") != 0)
11542 nss = atoi(result);
11543
11544 result = strtok_r(NULL, ";", &saveptr);
11545 if (!result) {
11546 sigma_dut_print(dut, DUT_MSG_ERROR,
11547 "HE MCS not specified");
11548 goto failed;
11549 }
11550 mcs = 7;
11551 if (strcasecmp(result, "def") != 0)
11552 mcs = atoi(result);
11553
Arif Hussain557bf412018-05-25 17:29:36 -070011554 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011555 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011556 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011557 } else if (nss > 2) {
11558 sigma_dut_print(dut, DUT_MSG_ERROR,
11559 "HE NSS %d not supported", nss);
11560 goto failed;
11561 }
11562
Arif Hussain557bf412018-05-25 17:29:36 -070011563 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11564 if (system(buf) != 0) {
11565 sigma_dut_print(dut, DUT_MSG_ERROR,
11566 "nss_mcs_opt: iwpriv %s nss %d failed",
11567 intf, nss);
11568 goto failed;
11569 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011570 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011571
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011572 /* Add the MCS to the ratecode */
11573 if (mcs >= 0 && mcs <= 11) {
11574 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011575#ifdef NL80211_SUPPORT
11576 if (dut->device_type == STA_testbed) {
11577 enum he_mcs_config mcs_config;
11578 int ret;
11579
11580 if (mcs <= 7)
11581 mcs_config = HE_80_MCS0_7;
11582 else if (mcs <= 9)
11583 mcs_config = HE_80_MCS0_9;
11584 else
11585 mcs_config = HE_80_MCS0_11;
11586 ret = sta_set_he_mcs(dut, intf, mcs_config);
11587 if (ret) {
11588 sigma_dut_print(dut, DUT_MSG_ERROR,
11589 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11590 mcs, mcs_config, ret);
11591 goto failed;
11592 }
11593 }
11594#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011595 } else {
11596 sigma_dut_print(dut, DUT_MSG_ERROR,
11597 "HE MCS %d not supported", mcs);
11598 goto failed;
11599 }
11600 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11601 intf, ratecode);
11602 if (system(buf) != 0) {
11603 sigma_dut_print(dut, DUT_MSG_ERROR,
11604 "iwpriv setting of 11ax rates failed");
11605 goto failed;
11606 }
11607 free(token);
11608 }
11609
11610 val = get_param(cmd, "GI");
11611 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011612 int fix_rate_sgi;
11613
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011614 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011615 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011616 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011617 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011618 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11619 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011620 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011621 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011622 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11623 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011624 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011625 } else {
11626 send_resp(dut, conn, SIGMA_ERROR,
11627 "errorCode,GI value not supported");
11628 return 0;
11629 }
11630 if (system(buf) != 0) {
11631 send_resp(dut, conn, SIGMA_ERROR,
11632 "errorCode,Failed to set shortgi");
11633 return 0;
11634 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011635 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11636 intf, fix_rate_sgi);
11637 if (system(buf) != 0) {
11638 send_resp(dut, conn, SIGMA_ERROR,
11639 "errorCode,Failed to set fix rate shortgi");
11640 return STATUS_SENT;
11641 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011642 }
11643
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011644 val = get_param(cmd, "LTF");
11645 if (val) {
11646#ifdef NL80211_SUPPORT
11647 if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011648 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011649 } if (strcmp(val, "6.4") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011650 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011651 } else if (strcmp(val, "12.8") == 0) {
Kiran Kumar Lokere26c0f862020-01-22 11:15:59 -080011652 wcn_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011653 } else {
11654 send_resp(dut, conn, SIGMA_ERROR,
11655 "errorCode, LTF value not supported");
11656 return 0;
11657 }
11658#else /* NL80211_SUPPORT */
11659 sigma_dut_print(dut, DUT_MSG_ERROR,
11660 "LTF cannot be set without NL80211_SUPPORT defined");
11661 return -2;
11662#endif /* NL80211_SUPPORT */
11663 }
11664
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011665 val = get_param(cmd, "TxSUPPDU");
11666 if (val) {
11667 int set_val = 1;
11668
11669 if (strcasecmp(val, "Enable") == 0)
11670 set_val = 1;
11671 else if (strcasecmp(val, "Disable") == 0)
11672 set_val = 0;
11673
11674 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11675 send_resp(dut, conn, SIGMA_ERROR,
11676 "ErrorCode,Failed to set Tx SU PPDU config");
11677 return 0;
11678 }
11679 }
11680
Arif Hussain480d5f42019-03-12 14:40:42 -070011681 val = get_param(cmd, "TWT_Setup");
11682 if (val) {
11683 if (strcasecmp(val, "Request") == 0) {
11684 if (sta_twt_request(dut, conn, cmd)) {
11685 send_resp(dut, conn, SIGMA_ERROR,
11686 "ErrorCode,sta_twt_request failed");
11687 return STATUS_SENT;
11688 }
11689 } else if (strcasecmp(val, "Teardown") == 0) {
11690 if (sta_twt_teardown(dut, conn, cmd)) {
11691 send_resp(dut, conn, SIGMA_ERROR,
11692 "ErrorCode,sta_twt_teardown failed");
11693 return STATUS_SENT;
11694 }
11695 }
11696 }
11697
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011698 val = get_param(cmd, "transmitOMI");
11699 if (val && sta_transmit_omi(dut, conn, cmd)) {
11700 send_resp(dut, conn, SIGMA_ERROR,
11701 "ErrorCode,sta_transmit_omi failed");
11702 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011703 }
11704
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011705 val = get_param(cmd, "Powersave");
11706 if (val) {
11707 char buf[60];
11708
11709 if (strcasecmp(val, "off") == 0) {
11710 snprintf(buf, sizeof(buf),
11711 "iwpriv %s setPower 2", intf);
11712 if (system(buf) != 0) {
11713 sigma_dut_print(dut, DUT_MSG_ERROR,
11714 "iwpriv setPower 2 failed");
11715 return 0;
11716 }
11717 } else if (strcasecmp(val, "on") == 0) {
11718 snprintf(buf, sizeof(buf),
11719 "iwpriv %s setPower 1", intf);
11720 if (system(buf) != 0) {
11721 sigma_dut_print(dut, DUT_MSG_ERROR,
11722 "iwpriv setPower 1 failed");
11723 return 0;
11724 }
11725 } else {
11726 sigma_dut_print(dut, DUT_MSG_ERROR,
11727 "Unsupported Powersave value '%s'",
11728 val);
11729 return -1;
11730 }
11731 }
11732
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011733 val = get_param(cmd, "MU_EDCA");
11734 if (val) {
11735 if (strcasecmp(val, "Override") == 0) {
11736 if (sta_set_mu_edca_override(dut, intf, 1)) {
11737 send_resp(dut, conn, SIGMA_ERROR,
11738 "errorCode,MU EDCA override set failed");
11739 return STATUS_SENT;
11740 }
11741 } else if (strcasecmp(val, "Disable") == 0) {
11742 if (sta_set_mu_edca_override(dut, intf, 0)) {
11743 send_resp(dut, conn, SIGMA_ERROR,
11744 "errorCode,MU EDCA override disable failed");
11745 return STATUS_SENT;
11746 }
11747 }
11748 }
11749
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011750 return 1;
11751
11752failed:
11753 free(token);
11754 return -2;
11755}
11756
11757
11758static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11759 struct sigma_conn *conn,
11760 struct sigma_cmd *cmd)
11761{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011762 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011763 case DRIVER_WCN:
11764 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11765 default:
11766 send_resp(dut, conn, SIGMA_ERROR,
11767 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11768 return 0;
11769 }
11770}
11771
11772
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011773static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11774 struct sigma_conn *conn,
11775 struct sigma_cmd *cmd)
11776{
11777 const char *val;
11778
11779 val = get_param(cmd, "powersave");
11780 if (val) {
11781 char buf[60];
11782
11783 if (strcasecmp(val, "off") == 0) {
11784 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11785 intf);
11786 if (system(buf) != 0) {
11787 sigma_dut_print(dut, DUT_MSG_ERROR,
11788 "iwpriv setPower 2 failed");
11789 return 0;
11790 }
11791 } else if (strcasecmp(val, "on") == 0) {
11792 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11793 intf);
11794 if (system(buf) != 0) {
11795 sigma_dut_print(dut, DUT_MSG_ERROR,
11796 "iwpriv setPower 1 failed");
11797 return 0;
11798 }
11799 } else {
11800 sigma_dut_print(dut, DUT_MSG_ERROR,
11801 "Unsupported power save config");
11802 return -1;
11803 }
11804 return 1;
11805 }
11806
11807 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11808
11809 return 0;
11810}
11811
11812
Ashwini Patil5acd7382017-04-13 15:55:04 +053011813static int btm_query_candidate_list(struct sigma_dut *dut,
11814 struct sigma_conn *conn,
11815 struct sigma_cmd *cmd)
11816{
11817 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11818 int len, ret;
11819 char buf[10];
11820
11821 /*
11822 * Neighbor Report elements format:
11823 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11824 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11825 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11826 */
11827
11828 bssid = get_param(cmd, "Nebor_BSSID");
11829 if (!bssid) {
11830 send_resp(dut, conn, SIGMA_INVALID,
11831 "errorCode,Nebor_BSSID is missing");
11832 return 0;
11833 }
11834
11835 info = get_param(cmd, "Nebor_Bssid_Info");
11836 if (!info) {
11837 sigma_dut_print(dut, DUT_MSG_INFO,
11838 "Using default value for Nebor_Bssid_Info: %s",
11839 DEFAULT_NEIGHBOR_BSSID_INFO);
11840 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11841 }
11842
11843 op_class = get_param(cmd, "Nebor_Op_Class");
11844 if (!op_class) {
11845 send_resp(dut, conn, SIGMA_INVALID,
11846 "errorCode,Nebor_Op_Class is missing");
11847 return 0;
11848 }
11849
11850 ch = get_param(cmd, "Nebor_Op_Ch");
11851 if (!ch) {
11852 send_resp(dut, conn, SIGMA_INVALID,
11853 "errorCode,Nebor_Op_Ch is missing");
11854 return 0;
11855 }
11856
11857 phy_type = get_param(cmd, "Nebor_Phy_Type");
11858 if (!phy_type) {
11859 sigma_dut_print(dut, DUT_MSG_INFO,
11860 "Using default value for Nebor_Phy_Type: %s",
11861 DEFAULT_NEIGHBOR_PHY_TYPE);
11862 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11863 }
11864
11865 /* Parse optional subelements */
11866 buf[0] = '\0';
11867 pref = get_param(cmd, "Nebor_Pref");
11868 if (pref) {
11869 /* hexdump for preferrence subelement */
11870 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11871 if (ret < 0 || ret >= (int) sizeof(buf)) {
11872 sigma_dut_print(dut, DUT_MSG_ERROR,
11873 "snprintf failed for optional subelement ret: %d",
11874 ret);
11875 send_resp(dut, conn, SIGMA_ERROR,
11876 "errorCode,snprintf failed for subelement");
11877 return 0;
11878 }
11879 }
11880
11881 if (!dut->btm_query_cand_list) {
11882 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11883 if (!dut->btm_query_cand_list) {
11884 send_resp(dut, conn, SIGMA_ERROR,
11885 "errorCode,Failed to allocate memory for btm_query_cand_list");
11886 return 0;
11887 }
11888 }
11889
11890 len = strlen(dut->btm_query_cand_list);
11891 ret = snprintf(dut->btm_query_cand_list + len,
11892 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11893 bssid, info, op_class, ch, phy_type, buf);
11894 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11895 sigma_dut_print(dut, DUT_MSG_ERROR,
11896 "snprintf failed for neighbor report list ret: %d",
11897 ret);
11898 send_resp(dut, conn, SIGMA_ERROR,
11899 "errorCode,snprintf failed for neighbor report");
11900 free(dut->btm_query_cand_list);
11901 dut->btm_query_cand_list = NULL;
11902 return 0;
11903 }
11904
11905 return 1;
11906}
11907
11908
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011909int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11910 struct sigma_ese_alloc *allocs, int *allocs_size)
11911{
11912 int max_count = *allocs_size;
11913 int count = 0, i;
11914 const char *val;
11915
11916 do {
11917 val = get_param_indexed(cmd, "AllocID", count);
11918 if (val)
11919 count++;
11920 } while (val);
11921
11922 if (count == 0 || count > max_count) {
11923 sigma_dut_print(dut, DUT_MSG_ERROR,
11924 "Invalid number of allocations(%d)", count);
11925 return -1;
11926 }
11927
11928 for (i = 0; i < count; i++) {
11929 val = get_param_indexed(cmd, "PercentBI", i);
11930 if (!val) {
11931 sigma_dut_print(dut, DUT_MSG_ERROR,
11932 "Missing PercentBI parameter at index %d",
11933 i);
11934 return -1;
11935 }
11936 allocs[i].percent_bi = atoi(val);
11937
11938 val = get_param_indexed(cmd, "SrcAID", i);
11939 if (val)
11940 allocs[i].src_aid = strtol(val, NULL, 0);
11941 else
11942 allocs[i].src_aid = ESE_BCAST_AID;
11943
11944 val = get_param_indexed(cmd, "DestAID", i);
11945 if (val)
11946 allocs[i].dst_aid = strtol(val, NULL, 0);
11947 else
11948 allocs[i].dst_aid = ESE_BCAST_AID;
11949
11950 allocs[i].type = ESE_CBAP;
11951 sigma_dut_print(dut, DUT_MSG_INFO,
11952 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11953 i, allocs[i].percent_bi, allocs[i].src_aid,
11954 allocs[i].dst_aid);
11955 }
11956
11957 *allocs_size = count;
11958 return 0;
11959}
11960
11961
11962static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11963 struct sigma_ese_alloc *allocs)
11964{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011965 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011966#ifdef __linux__
11967 case DRIVER_WIL6210:
11968 if (wil6210_set_ese(dut, count, allocs))
11969 return -1;
11970 return 1;
11971#endif /* __linux__ */
11972 default:
11973 sigma_dut_print(dut, DUT_MSG_ERROR,
11974 "Unsupported sta_set_60g_ese with the current driver");
11975 return -1;
11976 }
11977}
11978
11979
11980static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11981 struct sigma_conn *conn,
11982 struct sigma_cmd *cmd)
11983{
11984 const char *val;
11985
11986 val = get_param(cmd, "ExtSchIE");
11987 if (val && !strcasecmp(val, "Enable")) {
11988 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11989 int count = MAX_ESE_ALLOCS;
11990
11991 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11992 return -1;
11993 return sta_set_60g_ese(dut, count, allocs);
11994 }
11995
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011996 val = get_param(cmd, "MCS_FixedRate");
11997 if (val) {
11998 int sta_mcs = atoi(val);
11999
12000 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
12001 sta_mcs);
12002 wil6210_set_force_mcs(dut, 1, sta_mcs);
12003
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012004 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020012005 }
12006
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012007 send_resp(dut, conn, SIGMA_ERROR,
12008 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012009 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012010}
12011
12012
Jouni Malinenf7222712019-06-13 01:50:21 +030012013static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
12014 struct sigma_conn *conn,
12015 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012016{
12017 const char *intf = get_param(cmd, "Interface");
12018 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012019 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012020
12021 if (intf == NULL || prog == NULL)
12022 return -1;
12023
Ashwini Patil5acd7382017-04-13 15:55:04 +053012024 /* BSS Transition candidate list for BTM query */
12025 val = get_param(cmd, "Nebor_BSSID");
12026 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
12027 return 0;
12028
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012029 if (strcasecmp(prog, "TDLS") == 0)
12030 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
12031
12032 if (strcasecmp(prog, "VHT") == 0)
12033 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
12034
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080012035 if (strcasecmp(prog, "HE") == 0)
12036 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
12037
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012038 if (strcasecmp(prog, "MBO") == 0) {
12039 val = get_param(cmd, "Cellular_Data_Cap");
12040 if (val &&
12041 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
12042 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053012043
12044 val = get_param(cmd, "Ch_Pref");
12045 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
12046 return 0;
12047
Ashwini Patil68d02cd2017-01-10 15:39:16 +053012048 return 1;
12049 }
12050
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020012051 if (strcasecmp(prog, "60GHz") == 0)
12052 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
12053
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012054 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
12055 return 0;
12056}
12057
12058
Jouni Malinenf7222712019-06-13 01:50:21 +030012059static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
12060 struct sigma_conn *conn,
12061 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012062{
12063 const char *intf = get_param(cmd, "Interface");
12064 const char *mode = get_param(cmd, "Mode");
12065 int res;
12066
12067 if (intf == NULL || mode == NULL)
12068 return -1;
12069
12070 if (strcasecmp(mode, "On") == 0)
12071 res = wpa_command(intf, "SET radio_disabled 0");
12072 else if (strcasecmp(mode, "Off") == 0)
12073 res = wpa_command(intf, "SET radio_disabled 1");
12074 else
12075 return -1;
12076
12077 if (res) {
12078 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12079 "radio mode");
12080 return 0;
12081 }
12082
12083 return 1;
12084}
12085
12086
Jouni Malinenf7222712019-06-13 01:50:21 +030012087static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
12088 struct sigma_conn *conn,
12089 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012090{
12091 const char *intf = get_param(cmd, "Interface");
12092 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012093 const char *prog = get_param(cmd, "program");
12094 const char *powersave = get_param(cmd, "powersave");
12095 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012096
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012097 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012098 return -1;
12099
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012100 if (prog && strcasecmp(prog, "60GHz") == 0) {
12101 /*
12102 * The CAPI mode parameter does not exist in 60G
12103 * unscheduled PS.
12104 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080012105 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012106 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012107 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020012108 strcasecmp(prog, "HE") == 0) {
12109 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012110 } else {
12111 if (mode == NULL)
12112 return -1;
12113
12114 if (strcasecmp(mode, "On") == 0)
12115 res = set_ps(intf, dut, 1);
12116 else if (strcasecmp(mode, "Off") == 0)
12117 res = set_ps(intf, dut, 0);
12118 else
12119 return -1;
12120 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012121
12122 if (res) {
12123 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
12124 "power save mode");
12125 return 0;
12126 }
12127
12128 return 1;
12129}
12130
12131
Jouni Malinenf7222712019-06-13 01:50:21 +030012132static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
12133 struct sigma_conn *conn,
12134 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012135{
12136 const char *intf = get_param(cmd, "Interface");
12137 const char *val, *bssid;
12138 int res;
12139 char *buf;
12140 size_t buf_len;
12141
12142 val = get_param(cmd, "BSSID_FILTER");
12143 if (val == NULL)
12144 return -1;
12145
12146 bssid = get_param(cmd, "BSSID_List");
12147 if (atoi(val) == 0 || bssid == NULL) {
12148 /* Disable BSSID filter */
12149 if (wpa_command(intf, "SET bssid_filter ")) {
12150 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12151 "to disable BSSID filter");
12152 return 0;
12153 }
12154
12155 return 1;
12156 }
12157
12158 buf_len = 100 + strlen(bssid);
12159 buf = malloc(buf_len);
12160 if (buf == NULL)
12161 return -1;
12162
12163 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12164 res = wpa_command(intf, buf);
12165 free(buf);
12166 if (res) {
12167 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12168 "BSSID filter");
12169 return 0;
12170 }
12171
12172 return 1;
12173}
12174
12175
Jouni Malinenf7222712019-06-13 01:50:21 +030012176static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12177 struct sigma_conn *conn,
12178 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012179{
12180 const char *intf = get_param(cmd, "Interface");
12181 const char *val;
12182
12183 /* TODO: ARP */
12184
12185 val = get_param(cmd, "HS2_CACHE_PROFILE");
12186 if (val && strcasecmp(val, "All") == 0)
12187 hs2_clear_credentials(intf);
12188
12189 return 1;
12190}
12191
12192
Jouni Malinenf7222712019-06-13 01:50:21 +030012193static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12194 struct sigma_conn *conn,
12195 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012196{
12197 const char *intf = get_param(cmd, "Interface");
12198 const char *key_type = get_param(cmd, "KeyType");
12199 char buf[100], resp[200];
12200
12201 if (key_type == NULL)
12202 return -1;
12203
12204 if (strcasecmp(key_type, "GTK") == 0) {
12205 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12206 strncmp(buf, "FAIL", 4) == 0) {
12207 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12208 "not fetch current GTK");
12209 return 0;
12210 }
12211 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12212 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12213 return 0;
12214 } else {
12215 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12216 "KeyType");
12217 return 0;
12218 }
12219
12220 return 1;
12221}
12222
12223
12224static int hs2_set_policy(struct sigma_dut *dut)
12225{
12226#ifdef ANDROID
12227 system("ip rule del prio 23000");
12228 if (system("ip rule add from all lookup main prio 23000") != 0) {
12229 sigma_dut_print(dut, DUT_MSG_ERROR,
12230 "Failed to run:ip rule add from all lookup main prio");
12231 return -1;
12232 }
12233 if (system("ip route flush cache") != 0) {
12234 sigma_dut_print(dut, DUT_MSG_ERROR,
12235 "Failed to run ip route flush cache");
12236 return -1;
12237 }
12238 return 1;
12239#else /* ANDROID */
12240 return 0;
12241#endif /* ANDROID */
12242}
12243
12244
Jouni Malinenf7222712019-06-13 01:50:21 +030012245static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12246 struct sigma_conn *conn,
12247 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012248{
12249 const char *intf = get_param(cmd, "Interface");
12250 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012251 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012252 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012253 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012254 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12255 int tries = 0;
12256 int ignore_blacklist = 0;
12257 const char *events[] = {
12258 "CTRL-EVENT-CONNECTED",
12259 "INTERWORKING-BLACKLISTED",
12260 "INTERWORKING-NO-MATCH",
12261 NULL
12262 };
12263
12264 start_sta_mode(dut);
12265
Jouni Malinen439352d2018-09-13 03:42:23 +030012266 if (band) {
12267 if (strcmp(band, "2.4") == 0) {
12268 wpa_command(intf, "SET setband 2G");
12269 } else if (strcmp(band, "5") == 0) {
12270 wpa_command(intf, "SET setband 5G");
12271 } else {
12272 send_resp(dut, conn, SIGMA_ERROR,
12273 "errorCode,Unsupported band");
12274 return 0;
12275 }
12276 }
12277
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012278 blacklisted[0] = '\0';
12279 if (val && atoi(val))
12280 ignore_blacklist = 1;
12281
12282try_again:
12283 ctrl = open_wpa_mon(intf);
12284 if (ctrl == NULL) {
12285 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12286 "wpa_supplicant monitor connection");
12287 return -2;
12288 }
12289
12290 tries++;
12291 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12292 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12293 "Interworking connection");
12294 wpa_ctrl_detach(ctrl);
12295 wpa_ctrl_close(ctrl);
12296 return 0;
12297 }
12298
12299 buf[0] = '\0';
12300 while (1) {
12301 char *pos;
12302 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12303 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12304 if (!pos)
12305 break;
12306 pos += 25;
12307 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12308 pos);
12309 if (!blacklisted[0])
12310 memcpy(blacklisted, pos, strlen(pos) + 1);
12311 }
12312
12313 if (ignore_blacklist && blacklisted[0]) {
12314 char *end;
12315 end = strchr(blacklisted, ' ');
12316 if (end)
12317 *end = '\0';
12318 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12319 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012320 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12321 blacklisted);
12322 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012323 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12324 wpa_ctrl_detach(ctrl);
12325 wpa_ctrl_close(ctrl);
12326 return 0;
12327 }
12328 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12329 buf, sizeof(buf));
12330 }
12331
12332 wpa_ctrl_detach(ctrl);
12333 wpa_ctrl_close(ctrl);
12334
12335 if (res < 0) {
12336 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12337 "connect");
12338 return 0;
12339 }
12340
12341 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12342 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12343 if (tries < 2) {
12344 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12345 goto try_again;
12346 }
12347 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12348 "matching credentials found");
12349 return 0;
12350 }
12351
12352 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12353 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12354 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12355 "get current BSSID/SSID");
12356 return 0;
12357 }
12358
12359 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12360 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12361 hs2_set_policy(dut);
12362 return 0;
12363}
12364
12365
Jouni Malinenf7222712019-06-13 01:50:21 +030012366static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12367 struct sigma_conn *conn,
12368 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012369{
12370 const char *intf = get_param(cmd, "Interface");
12371 const char *display = get_param(cmd, "Display");
12372 struct wpa_ctrl *ctrl;
12373 char buf[300], params[400], *pos;
12374 char bssid[20];
12375 int info_avail = 0;
12376 unsigned int old_timeout;
12377 int res;
12378
12379 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12380 send_resp(dut, conn, SIGMA_ERROR,
12381 "ErrorCode,Could not get current BSSID");
12382 return 0;
12383 }
12384 ctrl = open_wpa_mon(intf);
12385 if (!ctrl) {
12386 sigma_dut_print(dut, DUT_MSG_ERROR,
12387 "Failed to open wpa_supplicant monitor connection");
12388 return -2;
12389 }
12390
12391 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12392 wpa_command(intf, buf);
12393
12394 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12395 if (res < 0) {
12396 send_resp(dut, conn, SIGMA_ERROR,
12397 "ErrorCode,Could not complete GAS query");
12398 goto fail;
12399 }
12400
12401 old_timeout = dut->default_timeout;
12402 dut->default_timeout = 2;
12403 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12404 dut->default_timeout = old_timeout;
12405 if (res < 0)
12406 goto done;
12407 pos = strchr(buf, ' ');
12408 if (!pos)
12409 goto done;
12410 pos++;
12411 pos = strchr(pos, ' ');
12412 if (!pos)
12413 goto done;
12414 pos++;
12415 info_avail = 1;
12416 snprintf(params, sizeof(params), "browser %s", pos);
12417
12418 if (display && strcasecmp(display, "Yes") == 0) {
12419 pid_t pid;
12420
12421 pid = fork();
12422 if (pid < 0) {
12423 perror("fork");
12424 return -1;
12425 }
12426
12427 if (pid == 0) {
12428 run_hs20_osu(dut, params);
12429 exit(0);
12430 }
12431 }
12432
12433done:
12434 snprintf(buf, sizeof(buf), "Info_available,%s",
12435 info_avail ? "Yes" : "No");
12436 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12437fail:
12438 wpa_ctrl_detach(ctrl);
12439 wpa_ctrl_close(ctrl);
12440 return 0;
12441}
12442
12443
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012444static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12445 struct sigma_conn *conn,
12446 const char *ifname,
12447 struct sigma_cmd *cmd)
12448{
12449 const char *val;
12450 int id;
12451
12452 id = add_cred(ifname);
12453 if (id < 0)
12454 return -2;
12455 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12456
12457 val = get_param(cmd, "prefer");
12458 if (val && atoi(val) > 0)
12459 set_cred(ifname, id, "priority", "1");
12460
12461 val = get_param(cmd, "REALM");
12462 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12464 "realm");
12465 return 0;
12466 }
12467
12468 val = get_param(cmd, "HOME_FQDN");
12469 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12470 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12471 "home_fqdn");
12472 return 0;
12473 }
12474
12475 val = get_param(cmd, "Username");
12476 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12477 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12478 "username");
12479 return 0;
12480 }
12481
12482 val = get_param(cmd, "Password");
12483 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12485 "password");
12486 return 0;
12487 }
12488
12489 val = get_param(cmd, "ROOT_CA");
12490 if (val) {
12491 char fname[200];
12492 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12493#ifdef __linux__
12494 if (!file_exists(fname)) {
12495 char msg[300];
12496 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12497 "file (%s) not found", fname);
12498 send_resp(dut, conn, SIGMA_ERROR, msg);
12499 return 0;
12500 }
12501#endif /* __linux__ */
12502 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12503 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12504 "not set root CA");
12505 return 0;
12506 }
12507 }
12508
12509 return 1;
12510}
12511
12512
12513static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12514{
12515 FILE *in, *out;
12516 char buf[500];
12517 int found = 0;
12518
12519 in = fopen("devdetail.xml", "r");
12520 if (in == NULL)
12521 return -1;
12522 out = fopen("devdetail.xml.tmp", "w");
12523 if (out == NULL) {
12524 fclose(in);
12525 return -1;
12526 }
12527
12528 while (fgets(buf, sizeof(buf), in)) {
12529 char *pos = strstr(buf, "<IMSI>");
12530 if (pos) {
12531 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12532 imsi);
12533 pos += 6;
12534 *pos = '\0';
12535 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12536 found++;
12537 } else {
12538 fprintf(out, "%s", buf);
12539 }
12540 }
12541
12542 fclose(out);
12543 fclose(in);
12544 if (found)
12545 rename("devdetail.xml.tmp", "devdetail.xml");
12546 else
12547 unlink("devdetail.xml.tmp");
12548
12549 return 0;
12550}
12551
12552
12553static int sta_add_credential_sim(struct sigma_dut *dut,
12554 struct sigma_conn *conn,
12555 const char *ifname, struct sigma_cmd *cmd)
12556{
12557 const char *val, *imsi = NULL;
12558 int id;
12559 char buf[200];
12560 int res;
12561 const char *pos;
12562 size_t mnc_len;
12563 char plmn_mcc[4];
12564 char plmn_mnc[4];
12565
12566 id = add_cred(ifname);
12567 if (id < 0)
12568 return -2;
12569 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12570
12571 val = get_param(cmd, "prefer");
12572 if (val && atoi(val) > 0)
12573 set_cred(ifname, id, "priority", "1");
12574
12575 val = get_param(cmd, "PLMN_MCC");
12576 if (val == NULL) {
12577 send_resp(dut, conn, SIGMA_ERROR,
12578 "errorCode,Missing PLMN_MCC");
12579 return 0;
12580 }
12581 if (strlen(val) != 3) {
12582 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12583 return 0;
12584 }
12585 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12586
12587 val = get_param(cmd, "PLMN_MNC");
12588 if (val == NULL) {
12589 send_resp(dut, conn, SIGMA_ERROR,
12590 "errorCode,Missing PLMN_MNC");
12591 return 0;
12592 }
12593 if (strlen(val) != 2 && strlen(val) != 3) {
12594 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12595 return 0;
12596 }
12597 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12598
12599 val = get_param(cmd, "IMSI");
12600 if (val == NULL) {
12601 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12602 "IMSI");
12603 return 0;
12604 }
12605
12606 imsi = pos = val;
12607
12608 if (strncmp(plmn_mcc, pos, 3) != 0) {
12609 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12610 return 0;
12611 }
12612 pos += 3;
12613
12614 mnc_len = strlen(plmn_mnc);
12615 if (mnc_len < 2) {
12616 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12617 return 0;
12618 }
12619
12620 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12621 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12622 return 0;
12623 }
12624 pos += mnc_len;
12625
12626 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12627 if (res < 0 || res >= (int) sizeof(buf))
12628 return -1;
12629 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12630 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12631 "not set IMSI");
12632 return 0;
12633 }
12634
12635 val = get_param(cmd, "Password");
12636 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12638 "not set password");
12639 return 0;
12640 }
12641
Jouni Malinenba630452018-06-22 11:49:59 +030012642 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012643 /*
12644 * Set provisioning_sp for the test cases where SIM/USIM
12645 * provisioning is used.
12646 */
12647 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12648 "wi-fi.org") < 0) {
12649 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12650 "not set provisioning_sp");
12651 return 0;
12652 }
12653
12654 update_devdetail_imsi(dut, imsi);
12655 }
12656
12657 return 1;
12658}
12659
12660
12661static int sta_add_credential_cert(struct sigma_dut *dut,
12662 struct sigma_conn *conn,
12663 const char *ifname,
12664 struct sigma_cmd *cmd)
12665{
12666 const char *val;
12667 int id;
12668
12669 id = add_cred(ifname);
12670 if (id < 0)
12671 return -2;
12672 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12673
12674 val = get_param(cmd, "prefer");
12675 if (val && atoi(val) > 0)
12676 set_cred(ifname, id, "priority", "1");
12677
12678 val = get_param(cmd, "REALM");
12679 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12680 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12681 "realm");
12682 return 0;
12683 }
12684
12685 val = get_param(cmd, "HOME_FQDN");
12686 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12687 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12688 "home_fqdn");
12689 return 0;
12690 }
12691
12692 val = get_param(cmd, "Username");
12693 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12694 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12695 "username");
12696 return 0;
12697 }
12698
12699 val = get_param(cmd, "clientCertificate");
12700 if (val) {
12701 char fname[200];
12702 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12703#ifdef __linux__
12704 if (!file_exists(fname)) {
12705 char msg[300];
12706 snprintf(msg, sizeof(msg),
12707 "ErrorCode,clientCertificate "
12708 "file (%s) not found", fname);
12709 send_resp(dut, conn, SIGMA_ERROR, msg);
12710 return 0;
12711 }
12712#endif /* __linux__ */
12713 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12714 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12715 "not set client_cert");
12716 return 0;
12717 }
12718 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12719 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12720 "not set private_key");
12721 return 0;
12722 }
12723 }
12724
12725 val = get_param(cmd, "ROOT_CA");
12726 if (val) {
12727 char fname[200];
12728 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12729#ifdef __linux__
12730 if (!file_exists(fname)) {
12731 char msg[300];
12732 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12733 "file (%s) not found", fname);
12734 send_resp(dut, conn, SIGMA_ERROR, msg);
12735 return 0;
12736 }
12737#endif /* __linux__ */
12738 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12739 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12740 "not set root CA");
12741 return 0;
12742 }
12743 }
12744
12745 return 1;
12746}
12747
12748
Jouni Malinenf7222712019-06-13 01:50:21 +030012749static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12750 struct sigma_conn *conn,
12751 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012752{
12753 const char *intf = get_param(cmd, "Interface");
12754 const char *type;
12755
12756 start_sta_mode(dut);
12757
12758 type = get_param(cmd, "Type");
12759 if (!type)
12760 return -1;
12761
12762 if (strcasecmp(type, "uname_pwd") == 0)
12763 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12764
12765 if (strcasecmp(type, "sim") == 0)
12766 return sta_add_credential_sim(dut, conn, intf, cmd);
12767
12768 if (strcasecmp(type, "cert") == 0)
12769 return sta_add_credential_cert(dut, conn, intf, cmd);
12770
12771 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12772 "type");
12773 return 0;
12774}
12775
12776
Jouni Malinenf7222712019-06-13 01:50:21 +030012777static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12778 struct sigma_conn *conn,
12779 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012780{
12781 const char *intf = get_param(cmd, "Interface");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012782 const char *val, *bssid, *ssid, *scan_freq, *short_ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012783 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012784 char ssid_hex[65];
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012785 int wildcard_ssid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012786 int res;
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012787 enum sigma_cmd_result status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012788
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020012789 start_sta_mode(dut);
12790
Arif Hussain66a4af02019-02-07 15:04:51 -080012791 val = get_param(cmd, "GetParameter");
12792 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012793 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012794 buf, sizeof(buf)) < 0) {
12795 sigma_dut_print(dut, DUT_MSG_ERROR,
12796 "Could not get ssid bssid");
12797 return ERROR_SEND_STATUS;
12798 }
12799
12800 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12801 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12802 return STATUS_SENT;
12803 }
12804
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012805 val = get_param(cmd, "HESSID");
12806 if (val) {
12807 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12808 if (res < 0 || res >= (int) sizeof(buf))
12809 return -1;
12810 wpa_command(intf, buf);
12811 }
12812
12813 val = get_param(cmd, "ACCS_NET_TYPE");
12814 if (val) {
12815 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12816 val);
12817 if (res < 0 || res >= (int) sizeof(buf))
12818 return -1;
12819 wpa_command(intf, buf);
12820 }
12821
vamsi krishna89ad8c62017-09-19 12:51:18 +053012822 bssid = get_param(cmd, "Bssid");
12823 ssid = get_param(cmd, "Ssid");
12824
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012825 if (ssid && strcasecmp(ssid, "ZeroLength") == 0 &&
12826 dut->device_type == STA_testbed) {
12827 ssid = NULL;
12828 wildcard_ssid = 1;
12829 }
12830
vamsi krishna89ad8c62017-09-19 12:51:18 +053012831 if (ssid) {
12832 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12833 send_resp(dut, conn, SIGMA_ERROR,
12834 "ErrorCode,Too long SSID");
12835 return 0;
12836 }
12837 ascii2hexstr(ssid, ssid_hex);
12838 }
12839
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012840 short_ssid = get_param(cmd, "ShortSSID");
12841 if (short_ssid) {
12842 uint32_t short_ssid_hex;
12843
12844 short_ssid_hex = strtoul(short_ssid, NULL, 16);
12845 short_ssid_hex = ((short_ssid_hex & 0xFF) << 24) |
12846 (((short_ssid_hex >> 8) & 0xFF) << 16) |
12847 (((short_ssid_hex >> 16) & 0xFF) << 8) |
12848 ((short_ssid_hex >> 24) & 0xFF);
12849
12850 res = snprintf(buf, sizeof(buf),
12851 "VENDOR_ELEM_ADD 14 ff053a%08x",
12852 short_ssid_hex);
12853 if (res < 0 || res >= (int) sizeof(buf) ||
12854 wpa_command(intf, buf)) {
12855 send_resp(dut, conn, SIGMA_ERROR,
12856 "errorCode,Failed to add short SSID");
12857 return STATUS_SENT_ERROR;
12858 }
12859 }
12860
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012861 scan_freq = get_param(cmd, "ChnlFreq");
12862
12863 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s%s%s%s",
vamsi krishna89ad8c62017-09-19 12:51:18 +053012864 bssid ? " bssid=": "",
12865 bssid ? bssid : "",
12866 ssid ? " ssid " : "",
Kiran Kumar Lokere3399af22020-03-04 16:31:56 -080012867 ssid ? ssid_hex : "",
Kiran Kumar Lokerec0deb482020-03-04 16:35:06 -080012868 wildcard_ssid ? " wildcard_ssid=1" : "",
12869 scan_freq ? " freq=" : "",
12870 scan_freq ? scan_freq : "");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012871 if (res < 0 || res >= (int) sizeof(buf)) {
12872 send_resp(dut, conn, SIGMA_ERROR,
12873 "errorCode,Could not build scan command");
12874 status = STATUS_SENT_ERROR;
12875 goto remove_s_ssid;
12876 }
vamsi krishna89ad8c62017-09-19 12:51:18 +053012877
12878 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012879 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12880 "scan");
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012881 status = STATUS_SENT_ERROR;
12882 } else {
12883 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012884 }
12885
Kiran Kumar Lokere0044a872020-03-04 16:38:06 -080012886remove_s_ssid:
12887 if (short_ssid && wpa_command(intf, "VENDOR_ELEM_REMOVE 14 *"))
12888 sigma_dut_print(dut, DUT_MSG_ERROR,
12889 "Failed to delete vendor element");
12890
12891 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012892}
12893
12894
Jouni Malinenf7222712019-06-13 01:50:21 +030012895static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12896 struct sigma_conn *conn,
12897 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012898{
12899 const char *intf = get_param(cmd, "Interface");
12900 const char *bssid;
12901 char buf[4096], *pos;
12902 int freq, chan;
12903 char *ssid;
12904 char resp[100];
12905 int res;
12906 struct wpa_ctrl *ctrl;
12907
12908 bssid = get_param(cmd, "BSSID");
12909 if (!bssid) {
12910 send_resp(dut, conn, SIGMA_INVALID,
12911 "errorCode,BSSID argument is missing");
12912 return 0;
12913 }
12914
12915 ctrl = open_wpa_mon(intf);
12916 if (!ctrl) {
12917 sigma_dut_print(dut, DUT_MSG_ERROR,
12918 "Failed to open wpa_supplicant monitor connection");
12919 return -1;
12920 }
12921
12922 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12923 send_resp(dut, conn, SIGMA_ERROR,
12924 "errorCode,Could not start scan");
12925 wpa_ctrl_detach(ctrl);
12926 wpa_ctrl_close(ctrl);
12927 return 0;
12928 }
12929
12930 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12931 buf, sizeof(buf));
12932
12933 wpa_ctrl_detach(ctrl);
12934 wpa_ctrl_close(ctrl);
12935
12936 if (res < 0) {
12937 send_resp(dut, conn, SIGMA_ERROR,
12938 "errorCode,Scan did not complete");
12939 return 0;
12940 }
12941
12942 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12943 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12944 strncmp(buf, "id=", 3) != 0) {
12945 send_resp(dut, conn, SIGMA_ERROR,
12946 "errorCode,Specified BSSID not found");
12947 return 0;
12948 }
12949
12950 pos = strstr(buf, "\nfreq=");
12951 if (!pos) {
12952 send_resp(dut, conn, SIGMA_ERROR,
12953 "errorCode,Channel not found");
12954 return 0;
12955 }
12956 freq = atoi(pos + 6);
12957 chan = freq_to_channel(freq);
12958
12959 pos = strstr(buf, "\nssid=");
12960 if (!pos) {
12961 send_resp(dut, conn, SIGMA_ERROR,
12962 "errorCode,SSID not found");
12963 return 0;
12964 }
12965 ssid = pos + 6;
12966 pos = strchr(ssid, '\n');
12967 if (pos)
12968 *pos = '\0';
12969 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12970 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12971 return 0;
12972}
12973
12974
Jouni Malinenf7222712019-06-13 01:50:21 +030012975static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
12976 struct sigma_conn *conn,
12977 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012978{
12979#ifdef __linux__
12980 struct timeval tv;
12981 struct tm tm;
12982 time_t t;
12983 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012984 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012985
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012986 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012987
12988 memset(&tm, 0, sizeof(tm));
12989 val = get_param(cmd, "seconds");
12990 if (val)
12991 tm.tm_sec = atoi(val);
12992 val = get_param(cmd, "minutes");
12993 if (val)
12994 tm.tm_min = atoi(val);
12995 val = get_param(cmd, "hours");
12996 if (val)
12997 tm.tm_hour = atoi(val);
12998 val = get_param(cmd, "date");
12999 if (val)
13000 tm.tm_mday = atoi(val);
13001 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053013002 if (val) {
13003 v = atoi(val);
13004 if (v < 1 || v > 12) {
13005 send_resp(dut, conn, SIGMA_INVALID,
13006 "errorCode,Invalid month");
13007 return 0;
13008 }
13009 tm.tm_mon = v - 1;
13010 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013011 val = get_param(cmd, "year");
13012 if (val) {
13013 int year = atoi(val);
13014#ifdef ANDROID
13015 if (year > 2035)
13016 year = 2035; /* years beyond 2035 not supported */
13017#endif /* ANDROID */
13018 tm.tm_year = year - 1900;
13019 }
13020 t = mktime(&tm);
13021 if (t == (time_t) -1) {
13022 send_resp(dut, conn, SIGMA_ERROR,
13023 "errorCode,Invalid date or time");
13024 return 0;
13025 }
13026
13027 memset(&tv, 0, sizeof(tv));
13028 tv.tv_sec = t;
13029
13030 if (settimeofday(&tv, NULL) < 0) {
13031 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
13032 strerror(errno));
13033 send_resp(dut, conn, SIGMA_ERROR,
13034 "errorCode,Failed to set time");
13035 return 0;
13036 }
13037
13038 return 1;
13039#endif /* __linux__ */
13040
13041 return -1;
13042}
13043
13044
Jouni Malinenf7222712019-06-13 01:50:21 +030013045static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
13046 struct sigma_conn *conn,
13047 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013048{
13049 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013050 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013051 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013052 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013053 int res;
13054 struct wpa_ctrl *ctrl;
13055
13056 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013057 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013058
13059 val = get_param(cmd, "ProdESSAssoc");
13060 if (val)
13061 prod_ess_assoc = atoi(val);
13062
13063 kill_dhcp_client(dut, intf);
13064 if (start_dhcp_client(dut, intf) < 0)
13065 return -2;
13066
13067 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
13068 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13069 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013070 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013071 prod_ess_assoc ? "" : "-N",
13072 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030013073 name ? "'" : "",
13074 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
13075 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013076
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053013077 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013078 if (run_hs20_osu(dut, buf) < 0) {
13079 FILE *f;
13080
13081 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
13082
13083 f = fopen("hs20-osu-client.res", "r");
13084 if (f) {
13085 char resp[400], res[300], *pos;
13086 if (!fgets(res, sizeof(res), f))
13087 res[0] = '\0';
13088 pos = strchr(res, '\n');
13089 if (pos)
13090 *pos = '\0';
13091 fclose(f);
13092 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
13093 res);
13094 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
13095 if (system(resp) != 0) {
13096 }
13097 snprintf(resp, sizeof(resp),
13098 "SSID,,BSSID,,failureReason,%s", res);
13099 send_resp(dut, conn, SIGMA_COMPLETE, resp);
13100 return 0;
13101 }
13102
13103 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13104 return 0;
13105 }
13106
13107 if (!prod_ess_assoc)
13108 goto report;
13109
13110 ctrl = open_wpa_mon(intf);
13111 if (ctrl == NULL) {
13112 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13113 "wpa_supplicant monitor connection");
13114 return -1;
13115 }
13116
13117 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
13118 buf, sizeof(buf));
13119
13120 wpa_ctrl_detach(ctrl);
13121 wpa_ctrl_close(ctrl);
13122
13123 if (res < 0) {
13124 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
13125 "network after OSU");
13126 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13127 return 0;
13128 }
13129
13130report:
13131 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
13132 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
13133 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
13134 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
13135 return 0;
13136 }
13137
13138 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
13139 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013140 return 0;
13141}
13142
13143
Jouni Malinenf7222712019-06-13 01:50:21 +030013144static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
13145 struct sigma_conn *conn,
13146 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013147{
13148 const char *val;
13149 int timeout = 120;
13150
13151 val = get_param(cmd, "PolicyUpdate");
13152 if (val == NULL || atoi(val) == 0)
13153 return 1; /* No operation requested */
13154
13155 val = get_param(cmd, "Timeout");
13156 if (val)
13157 timeout = atoi(val);
13158
13159 if (timeout) {
13160 /* TODO: time out the command and return
13161 * PolicyUpdateStatus,TIMEOUT if needed. */
13162 }
13163
13164 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
13165 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
13166 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
13167 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
13168 return 0;
13169 }
13170
13171 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
13172 return 0;
13173}
13174
13175
Jouni Malinenf7222712019-06-13 01:50:21 +030013176static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
13177 struct sigma_conn *conn,
13178 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013179{
13180 struct wpa_ctrl *ctrl;
13181 const char *intf = get_param(cmd, "Interface");
13182 const char *bssid = get_param(cmd, "Bssid");
13183 const char *ssid = get_param(cmd, "SSID");
13184 const char *security = get_param(cmd, "Security");
13185 const char *passphrase = get_param(cmd, "Passphrase");
13186 const char *pin = get_param(cmd, "PIN");
13187 char buf[1000];
13188 char ssid_hex[200], passphrase_hex[200];
13189 const char *keymgmt, *cipher;
13190
13191 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013192 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013193
13194 if (!bssid) {
13195 send_resp(dut, conn, SIGMA_ERROR,
13196 "ErrorCode,Missing Bssid argument");
13197 return 0;
13198 }
13199
13200 if (!ssid) {
13201 send_resp(dut, conn, SIGMA_ERROR,
13202 "ErrorCode,Missing SSID argument");
13203 return 0;
13204 }
13205
13206 if (!security) {
13207 send_resp(dut, conn, SIGMA_ERROR,
13208 "ErrorCode,Missing Security argument");
13209 return 0;
13210 }
13211
13212 if (!passphrase) {
13213 send_resp(dut, conn, SIGMA_ERROR,
13214 "ErrorCode,Missing Passphrase argument");
13215 return 0;
13216 }
13217
13218 if (!pin) {
13219 send_resp(dut, conn, SIGMA_ERROR,
13220 "ErrorCode,Missing PIN argument");
13221 return 0;
13222 }
13223
vamsi krishna8c9c1562017-05-12 15:51:46 +053013224 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13225 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013226 send_resp(dut, conn, SIGMA_ERROR,
13227 "ErrorCode,Too long SSID/passphrase");
13228 return 0;
13229 }
13230
13231 ctrl = open_wpa_mon(intf);
13232 if (ctrl == NULL) {
13233 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13234 "wpa_supplicant monitor connection");
13235 return -2;
13236 }
13237
13238 if (strcasecmp(security, "wpa2-psk") == 0) {
13239 keymgmt = "WPA2PSK";
13240 cipher = "CCMP";
13241 } else {
13242 wpa_ctrl_detach(ctrl);
13243 wpa_ctrl_close(ctrl);
13244 send_resp(dut, conn, SIGMA_ERROR,
13245 "ErrorCode,Unsupported Security value");
13246 return 0;
13247 }
13248
13249 ascii2hexstr(ssid, ssid_hex);
13250 ascii2hexstr(passphrase, passphrase_hex);
13251 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13252 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13253
13254 if (wpa_command(intf, buf) < 0) {
13255 wpa_ctrl_detach(ctrl);
13256 wpa_ctrl_close(ctrl);
13257 send_resp(dut, conn, SIGMA_ERROR,
13258 "ErrorCode,Failed to start registrar");
13259 return 0;
13260 }
13261
13262 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13263 dut->er_oper_performed = 1;
13264
13265 return wps_connection_event(dut, conn, ctrl, intf, 0);
13266}
13267
13268
Jouni Malinenf7222712019-06-13 01:50:21 +030013269static enum sigma_cmd_result
13270cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13271 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013272{
13273 struct wpa_ctrl *ctrl;
13274 const char *intf = get_param(cmd, "Interface");
13275 const char *bssid = get_param(cmd, "Bssid");
13276 char buf[100];
13277
13278 if (!bssid) {
13279 send_resp(dut, conn, SIGMA_ERROR,
13280 "ErrorCode,Missing Bssid argument");
13281 return 0;
13282 }
13283
13284 ctrl = open_wpa_mon(intf);
13285 if (ctrl == NULL) {
13286 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13287 "wpa_supplicant monitor connection");
13288 return -2;
13289 }
13290
13291 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13292
13293 if (wpa_command(intf, buf) < 0) {
13294 wpa_ctrl_detach(ctrl);
13295 wpa_ctrl_close(ctrl);
13296 send_resp(dut, conn, SIGMA_ERROR,
13297 "ErrorCode,Failed to start registrar");
13298 return 0;
13299 }
13300
13301 return wps_connection_event(dut, conn, ctrl, intf, 0);
13302}
13303
13304
Jouni Malinenf7222712019-06-13 01:50:21 +030013305static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13306 struct sigma_conn *conn,
13307 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013308{
13309 struct wpa_ctrl *ctrl;
13310 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013311 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013312 const char *config_method = get_param(cmd, "WPSConfigMethod");
13313 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013314 int res;
13315 char buf[256];
13316 const char *events[] = {
13317 "CTRL-EVENT-CONNECTED",
13318 "WPS-OVERLAP-DETECTED",
13319 "WPS-TIMEOUT",
13320 "WPS-FAIL",
13321 NULL
13322 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013323 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013324
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013325 /* 60G WPS tests do not pass Interface parameter */
13326 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013327 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013328
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013329 if (dut->mode == SIGMA_MODE_AP)
13330 return ap_wps_registration(dut, conn, cmd);
13331
13332 if (config_method) {
13333 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13334 * sta_wps_enter_pin before calling start_wps_registration. */
13335 if (strcasecmp(config_method, "PBC") == 0)
13336 dut->wps_method = WFA_CS_WPS_PBC;
13337 }
13338 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13339 send_resp(dut, conn, SIGMA_ERROR,
13340 "ErrorCode,WPS parameters not yet set");
13341 return STATUS_SENT;
13342 }
13343
13344 /* Make sure WPS is enabled (also for STA mode) */
13345 dut->wps_disable = 0;
13346
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013347 if (dut->band == WPS_BAND_60G && network_mode &&
13348 strcasecmp(network_mode, "PBSS") == 0) {
13349 sigma_dut_print(dut, DUT_MSG_DEBUG,
13350 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013351 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013352 return -2;
13353 }
13354
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013355 if (dut->force_rsn_ie) {
13356 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13357 dut->force_rsn_ie);
13358 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13359 sigma_dut_print(dut, DUT_MSG_INFO,
13360 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013361 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013362 }
13363 }
13364
vamsi krishna9b144002017-09-20 13:28:13 +053013365 ctrl = open_wpa_mon(intf);
13366 if (!ctrl) {
13367 sigma_dut_print(dut, DUT_MSG_ERROR,
13368 "Failed to open wpa_supplicant monitor connection");
13369 return -2;
13370 }
13371
13372 role = get_param(cmd, "WpsRole");
13373 if (!role) {
13374 send_resp(dut, conn, SIGMA_INVALID,
13375 "ErrorCode,WpsRole not provided");
13376 goto fail;
13377 }
13378
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013379 if (strcasecmp(role, "Enrollee") != 0) {
13380 /* Registrar role for STA not supported */
13381 send_resp(dut, conn, SIGMA_ERROR,
13382 "ErrorCode,Unsupported WpsRole value");
13383 goto fail;
13384 }
13385
13386 if (is_60g_sigma_dut(dut)) {
13387 if (dut->wps_method == WFA_CS_WPS_PBC)
13388 snprintf(buf, sizeof(buf), "WPS_PBC");
13389 else /* WFA_CS_WPS_PIN_KEYPAD */
13390 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13391 dut->wps_pin);
13392 if (wpa_command(intf, buf) < 0) {
13393 send_resp(dut, conn, SIGMA_ERROR,
13394 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013395 goto fail;
13396 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013397 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13398 if (res < 0) {
13399 send_resp(dut, conn, SIGMA_ERROR,
13400 "ErrorCode,WPS connection did not complete");
13401 goto fail;
13402 }
13403 if (strstr(buf, "WPS-TIMEOUT")) {
13404 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13405 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13406 send_resp(dut, conn, SIGMA_COMPLETE,
13407 "WpsState,OverlapSession");
13408 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13409 send_resp(dut, conn, SIGMA_COMPLETE,
13410 "WpsState,Successful");
13411 } else {
13412 send_resp(dut, conn, SIGMA_COMPLETE,
13413 "WpsState,Failure");
13414 }
13415 } else {
13416 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013417 if (wpa_command(intf, "WPS_PBC") < 0) {
13418 send_resp(dut, conn, SIGMA_ERROR,
13419 "ErrorCode,Failed to enable PBC");
13420 goto fail;
13421 }
13422 } else {
13423 /* TODO: PIN method */
13424 send_resp(dut, conn, SIGMA_ERROR,
13425 "ErrorCode,Unsupported WpsConfigMethod value");
13426 goto fail;
13427 }
13428 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13429 if (res < 0) {
13430 send_resp(dut, conn, SIGMA_ERROR,
13431 "ErrorCode,WPS connection did not complete");
13432 goto fail;
13433 }
13434 if (strstr(buf, "WPS-TIMEOUT")) {
13435 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13436 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13437 send_resp(dut, conn, SIGMA_ERROR,
13438 "ErrorCode,OverlapSession");
13439 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13440 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13441 } else {
13442 send_resp(dut, conn, SIGMA_ERROR,
13443 "ErrorCode,WPS operation failed");
13444 }
vamsi krishna9b144002017-09-20 13:28:13 +053013445 }
13446
13447fail:
13448 wpa_ctrl_detach(ctrl);
13449 wpa_ctrl_close(ctrl);
13450 return 0;
13451}
13452
13453
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013454static int req_intf(struct sigma_cmd *cmd)
13455{
13456 return get_param(cmd, "interface") == NULL ? -1 : 0;
13457}
13458
13459
13460void sta_register_cmds(void)
13461{
13462 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13463 cmd_sta_get_ip_config);
13464 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13465 cmd_sta_set_ip_config);
13466 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13467 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13468 cmd_sta_get_mac_address);
13469 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13470 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13471 cmd_sta_verify_ip_connection);
13472 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13473 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13474 cmd_sta_set_encryption);
13475 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13476 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13477 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13478 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13479 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13480 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13481 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13482 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13483 cmd_sta_set_eapakaprime);
13484 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13485 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13486 /* TODO: sta_set_ibss */
13487 /* TODO: sta_set_mode */
13488 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13489 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13490 /* TODO: sta_up_load */
13491 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13492 cmd_sta_preset_testparameters);
13493 /* TODO: sta_set_system */
13494 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13495 /* TODO: sta_set_rifs_test */
13496 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13497 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13498 /* TODO: sta_send_coexist_mgmt */
13499 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13500 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13501 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13502 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13503 cmd_sta_reset_default);
13504 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13505 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13506 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13507 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13508 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013509 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013510 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13511 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13512 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13513 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13514 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013515 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13516 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013517 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13518 cmd_sta_add_credential);
13519 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013520 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013521 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13522 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13523 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13524 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13525 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13526 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013527 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013528 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13529 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013530 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013531 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013532}