blob: 5370907c679f7239e6e1d4a12075550593275535 [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) {
241 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530242 if (system(buf) != 0)
243 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200244 } else {
245 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530246 if (system(buf) != 0)
247 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200248 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530249 if (system(buf) != 0)
250 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200251 }
252
253 return 0;
254 }
255
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530256set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200257 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
258 intf, enabled ? "on" : "off");
259 if (system(buf) != 0) {
260 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
261 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530262 if (system(buf) != 0) {
263 sigma_dut_print(dut, DUT_MSG_ERROR,
264 "Failed to set power save %s",
265 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200266 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530267 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200268 }
269
270 return 0;
271#else /* __linux__ */
272 return -1;
273#endif /* __linux__ */
274}
275
276
Lior Davidcc88b562017-01-03 18:52:09 +0200277#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200278
Lior Davidcc88b562017-01-03 18:52:09 +0200279static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
280 size_t len)
281{
282 DIR *dir, *wil_dir;
283 struct dirent *entry;
284 int ret = -1;
285 const char *root_path = "/sys/kernel/debug/ieee80211";
286
287 dir = opendir(root_path);
288 if (!dir)
289 return -2;
290
291 while ((entry = readdir(dir))) {
292 if (strcmp(entry->d_name, ".") == 0 ||
293 strcmp(entry->d_name, "..") == 0)
294 continue;
295
296 if (snprintf(path, len, "%s/%s/wil6210",
297 root_path, entry->d_name) >= (int) len) {
298 ret = -3;
299 break;
300 }
301
302 wil_dir = opendir(path);
303 if (wil_dir) {
304 closedir(wil_dir);
305 ret = 0;
306 break;
307 }
308 }
309
310 closedir(dir);
311 return ret;
312}
Lior David0fe101e2017-03-09 16:09:50 +0200313
314
315static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
316 void *payload, uint16_t length)
317{
318 struct {
319 struct wil_wmi_header hdr;
320 char payload[WIL_WMI_MAX_PAYLOAD];
321 } __attribute__((packed)) cmd;
322 char buf[128], fname[128];
323 size_t towrite, written;
324 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300325 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200326
327 if (length > WIL_WMI_MAX_PAYLOAD) {
328 sigma_dut_print(dut, DUT_MSG_ERROR,
329 "payload too large(%u, max %u)",
330 length, WIL_WMI_MAX_PAYLOAD);
331 return -1;
332 }
333
334 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
335 cmd.hdr.cmd = command;
336 memcpy(cmd.payload, payload, length);
337
338 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
339 sigma_dut_print(dut, DUT_MSG_ERROR,
340 "failed to get wil6210 debugfs dir");
341 return -1;
342 }
343
Jouni Malinen3aa72862019-05-29 23:14:51 +0300344 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
345 if (res < 0 || res >= sizeof(fname))
346 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200347 f = fopen(fname, "wb");
348 if (!f) {
349 sigma_dut_print(dut, DUT_MSG_ERROR,
350 "failed to open: %s", fname);
351 return -1;
352 }
353
354 towrite = sizeof(cmd.hdr) + length;
355 written = fwrite(&cmd, 1, towrite, f);
356 fclose(f);
357 if (written != towrite) {
358 sigma_dut_print(dut, DUT_MSG_ERROR,
359 "failed to send wmi %u", command);
360 return -1;
361 }
362
363 return 0;
364}
365
366
367static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
368 const char *pattern, unsigned int *field)
369{
370 char buf[128], fname[128];
371 FILE *f;
372 regex_t re;
373 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300374 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200375
376 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
377 sigma_dut_print(dut, DUT_MSG_ERROR,
378 "failed to get wil6210 debugfs dir");
379 return -1;
380 }
381
Jouni Malinen3aa72862019-05-29 23:14:51 +0300382 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
383 if (res < 0 || res >= sizeof(fname))
384 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200385 f = fopen(fname, "r");
386 if (!f) {
387 sigma_dut_print(dut, DUT_MSG_ERROR,
388 "failed to open: %s", fname);
389 return -1;
390 }
391
392 if (regcomp(&re, pattern, REG_EXTENDED)) {
393 sigma_dut_print(dut, DUT_MSG_ERROR,
394 "regcomp failed: %s", pattern);
395 goto out;
396 }
397
398 /*
399 * find the entry for the mac address
400 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
401 */
402 while (fgets(buf, sizeof(buf), f)) {
403 if (strcasestr(buf, bssid)) {
404 /* extract the field (CID/AID/state) */
405 rc = regexec(&re, buf, 2, m, 0);
406 if (!rc && (m[1].rm_so >= 0)) {
407 buf[m[1].rm_eo] = 0;
408 *field = atoi(&buf[m[1].rm_so]);
409 ret = 0;
410 break;
411 }
412 }
413 }
414
415 regfree(&re);
416 if (ret)
417 sigma_dut_print(dut, DUT_MSG_ERROR,
418 "could not extract field");
419
420out:
421 fclose(f);
422
423 return ret;
424}
425
426
427static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
428 unsigned int *cid)
429{
430 const char *pattern = "\\[([0-9]+)\\]";
431
432 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
433}
434
435
436static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
437 int l_rx)
438{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700439 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200440 unsigned int cid;
441
Rakesh Sunki556237d2017-03-30 14:49:31 -0700442 memset(&cmd, 0, sizeof(cmd));
443
Lior David0fe101e2017-03-09 16:09:50 +0200444 if (wil6210_get_cid(dut, mac, &cid))
445 return -1;
446
447 cmd.bf_type = WIL_WMI_BRP_RX;
448 cmd.sta_id = cid;
449 /* training length (l_rx) is ignored, FW always uses length 16 */
450 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
451 &cmd, sizeof(cmd));
452}
453
454
455static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
456{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700457 struct wil_wmi_bf_trig_cmd cmd;
458
459 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200460
461 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
462 return -1;
463
464 cmd.bf_type = WIL_WMI_SLS;
465 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
466 &cmd, sizeof(cmd));
467}
468
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200469
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200470int wil6210_set_ese(struct sigma_dut *dut, int count,
471 struct sigma_ese_alloc *allocs)
472{
473 struct wil_wmi_ese_cfg cmd = { };
474 int i;
475
476 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
477 return -1;
478
479 if (dut->ap_bcnint <= 0) {
480 sigma_dut_print(dut, DUT_MSG_ERROR,
481 "invalid beacon interval(%d), check test",
482 dut->ap_bcnint);
483 return -1;
484 }
485
486 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
487 cmd.flags = 0x1d;
488 cmd.num_allocs = count;
489 for (i = 0; i < count; i++) {
490 /*
491 * Convert percent from BI (BI specified in milliseconds)
492 * to absolute duration in microseconds.
493 */
494 cmd.slots[i].duration =
495 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
496 switch (allocs[i].type) {
497 case ESE_CBAP:
498 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
499 break;
500 case ESE_SP:
501 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
502 break;
503 default:
504 sigma_dut_print(dut, DUT_MSG_ERROR,
505 "invalid slot type(%d) at index %d",
506 allocs[i].type, i);
507 return -1;
508 }
509 cmd.slots[i].src_aid = allocs[i].src_aid;
510 cmd.slots[i].dst_aid = allocs[i].dst_aid;
511 sigma_dut_print(dut, DUT_MSG_INFO,
512 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
513 i, cmd.slots[i].duration,
514 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
515 cmd.slots[i].dst_aid);
516 }
517
518 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
519}
520
521
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200522int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
523{
524 struct wil_wmi_force_mcs cmd = { };
525
526 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
527 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
528 cmd.force_enable = (uint32_t) force;
529 cmd.mcs = (uint32_t) mcs;
530
531 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
532 &cmd, sizeof(cmd));
533}
534
535
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200536static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
537{
538 struct wil_wmi_force_rsn_ie cmd = { };
539
540 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
541 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
542 cmd.state = (uint32_t) state;
543
544 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
545 &cmd, sizeof(cmd));
546}
547
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300548
549/*
550 * this function is also used to configure generic remain-on-channel
551 */
552static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
553{
554 struct wil_wmi_p2p_cfg_cmd cmd = { };
555 int channel = freq_to_channel(freq);
556
557 if (channel < 0)
558 return -1;
559 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
560 cmd.channel = channel - 1;
561 cmd.bcon_interval = WIL_DEFAULT_BI;
562 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
563
564 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
565 &cmd, sizeof(cmd));
566}
567
568
569static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
570{
571 int ret = wil6210_p2p_cfg(dut, freq);
572
573 if (ret)
574 return ret;
575
576 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
577 if (!ret) {
578 /*
579 * wait a bit to allow FW to setup the radio
580 * especially important if we switch channels
581 */
582 usleep(500000);
583 }
584
585 return ret;
586}
587
588
589static int wil6210_stop_discovery(struct sigma_dut *dut)
590{
591 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
592}
593
594
595static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
596 int wait_duration,
597 const char *frame, size_t frame_len)
598{
599 char buf[128], fname[128];
600 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300601 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300602 size_t written;
603
604 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
605 sigma_dut_print(dut, DUT_MSG_ERROR,
606 "failed to get wil6210 debugfs dir");
607 return -1;
608 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300609 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
610 if (r < 0 || r >= sizeof(fname))
611 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300612
613 if (wil6210_remain_on_channel(dut, freq)) {
614 sigma_dut_print(dut, DUT_MSG_ERROR,
615 "failed to listen on channel");
616 return -1;
617 }
618
619 f = fopen(fname, "wb");
620 if (!f) {
621 sigma_dut_print(dut, DUT_MSG_ERROR,
622 "failed to open: %s", fname);
623 res = -1;
624 goto out_stop;
625 }
626 written = fwrite(frame, 1, frame_len, f);
627 fclose(f);
628
629 if (written != frame_len) {
630 sigma_dut_print(dut, DUT_MSG_ERROR,
631 "failed to transmit frame (got %zd, expected %zd)",
632 written, frame_len);
633 res = -1;
634 goto out_stop;
635 }
636
637 usleep(wait_duration * 1000);
638
639out_stop:
640 wil6210_stop_discovery(dut);
641 return res;
642}
643
644
645static int find_template_frame_tag(struct template_frame_tag *tags,
646 int total_tags, int tag_num)
647{
648 int i;
649
650 for (i = 0; i < total_tags; i++) {
651 if (tag_num == tags[i].num)
652 return i;
653 }
654
655 return -1;
656}
657
658
659static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
660 int id, const char *value, size_t val_len)
661{
662 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
663
664 if (len < 3 + val_len) {
665 sigma_dut_print(dut, DUT_MSG_ERROR,
666 "not enough space to replace P2P attribute");
667 return -1;
668 }
669
670 if (attr->len != val_len) {
671 sigma_dut_print(dut, DUT_MSG_ERROR,
672 "attribute length mismatch (need %zu have %hu)",
673 val_len, attr->len);
674 return -1;
675 }
676
677 if (attr->id != id) {
678 sigma_dut_print(dut, DUT_MSG_ERROR,
679 "incorrect attribute id (expected %d actual %d)",
680 id, attr->id);
681 return -1;
682 }
683
684 memcpy(attr->variable, value, val_len);
685
686 return 0;
687}
688
689
690static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
691 char *buf, size_t *length,
692 struct template_frame_tag *tags,
693 size_t *num_tags)
694{
695 char line[512];
696 FILE *f;
697 size_t offset = 0, tag_index = 0;
698 int num, index;
699 int in_tag = 0, tag_num = 0, tag_offset = 0;
700
701 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "supplied buffer is too small");
704 return -1;
705 }
706
707 f = fopen(fname, "r");
708 if (!f) {
709 sigma_dut_print(dut, DUT_MSG_ERROR,
710 "failed to open template file %s", fname);
711 return -1;
712 }
713
714 /*
715 * template file format: lines beginning with # are comments and
716 * ignored.
717 * It is possible to tag bytes in the frame to make it easy
718 * to replace fields in the template, espcially if they appear
719 * in variable-sized sections (such as IEs)
720 * This is done by a line beginning with $NUM where NUM is an integer
721 * tag number. It can be followed by space(s) and comment.
722 * The next line is considered the tagged bytes. The parser will fill
723 * the tag number, offset and length of the tagged bytes.
724 * rest of the lines contain frame bytes as sequence of hex digits,
725 * 2 digits for each byte. Spaces are allowed between bytes.
726 * On bytes lines only hex digits and spaces are allowed
727 */
728 while (!feof(f)) {
729 if (!fgets(line, sizeof(line), f))
730 break;
731 index = 0;
732 while (isspace((unsigned char) line[index]))
733 index++;
734 if (!line[index] || line[index] == '#')
735 continue;
736 if (line[index] == '$') {
737 if (tags) {
738 index++;
739 tag_num = strtol(&line[index], NULL, 0);
740 tag_offset = offset;
741 in_tag = 1;
742 }
743 continue;
744 }
745 while (line[index]) {
746 if (isspace((unsigned char) line[index])) {
747 index++;
748 continue;
749 }
750 num = hex_byte(&line[index]);
751 if (num < 0)
752 break;
753 buf[offset++] = num;
754 if (offset == *length)
755 goto out;
756 index += 2;
757 }
758
759 if (in_tag) {
760 if (tag_index < *num_tags) {
761 tags[tag_index].num = tag_num;
762 tags[tag_index].offset = tag_offset;
763 tags[tag_index].len = offset - tag_offset;
764 tag_index++;
765 } else {
766 sigma_dut_print(dut, DUT_MSG_INFO,
767 "too many tags, tag ignored");
768 }
769 in_tag = 0;
770 }
771 }
772
773 if (num_tags)
774 *num_tags = tag_index;
775out:
776 fclose(f);
777 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
778 sigma_dut_print(dut, DUT_MSG_ERROR,
779 "template frame is too small");
780 return -1;
781 }
782
783 *length = offset;
784 return 0;
785}
786
Lior Davidcc88b562017-01-03 18:52:09 +0200787#endif /* __linux__ */
788
789
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200790static void static_ip_file(int proto, const char *addr, const char *mask,
791 const char *gw)
792{
793 if (proto) {
794 FILE *f = fopen("static-ip", "w");
795 if (f) {
796 fprintf(f, "%d %s %s %s\n", proto, addr,
797 mask ? mask : "N/A",
798 gw ? gw : "N/A");
799 fclose(f);
800 }
801 } else {
802 unlink("static-ip");
803 }
804}
805
806
807static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
808 const char *ssid)
809{
810#ifdef __linux__
811 char buf[100];
812
813 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
814 intf, ssid);
815 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
816
817 if (system(buf) != 0) {
818 sigma_dut_print(dut, DUT_MSG_ERROR,
819 "iwpriv neighbor request failed");
820 return -1;
821 }
822
823 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
824
825 return 0;
826#else /* __linux__ */
827 return -1;
828#endif /* __linux__ */
829}
830
831
832static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530833 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200834{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530835 const char *val;
836 int reason_code = 0;
837 char buf[1024];
838
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200839 /*
840 * In the earlier builds we used WNM_QUERY and in later
841 * builds used WNM_BSS_QUERY.
842 */
843
Ashwini Patil5acd7382017-04-13 15:55:04 +0530844 val = get_param(cmd, "BTMQuery_Reason_Code");
845 if (val)
846 reason_code = atoi(val);
847
848 val = get_param(cmd, "Cand_List");
849 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
850 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
851 dut->btm_query_cand_list);
852 free(dut->btm_query_cand_list);
853 dut->btm_query_cand_list = NULL;
854 } else {
855 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
856 }
857
858 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200859 sigma_dut_print(dut, DUT_MSG_ERROR,
860 "transition management query failed");
861 return -1;
862 }
863
864 sigma_dut_print(dut, DUT_MSG_DEBUG,
865 "transition management query sent");
866
867 return 0;
868}
869
870
871int is_ip_addr(const char *str)
872{
873 const char *pos = str;
874 struct in_addr addr;
875
876 while (*pos) {
877 if (*pos != '.' && (*pos < '0' || *pos > '9'))
878 return 0;
879 pos++;
880 }
881
882 return inet_aton(str, &addr);
883}
884
885
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200886int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
887 size_t buf_len)
888{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530889 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200890 char ip[16], mask[15], dns[16], sec_dns[16];
891 int is_dhcp = 0;
892 int s;
893#ifdef ANDROID
894 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530895#else /* ANDROID */
896 FILE *f;
897#ifdef __linux__
898 const char *str_ps;
899#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200900#endif /* ANDROID */
901
902 ip[0] = '\0';
903 mask[0] = '\0';
904 dns[0] = '\0';
905 sec_dns[0] = '\0';
906
907 s = socket(PF_INET, SOCK_DGRAM, 0);
908 if (s >= 0) {
909 struct ifreq ifr;
910 struct sockaddr_in saddr;
911
912 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700913 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200914 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
915 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
916 "%s IP address: %s",
917 ifname, strerror(errno));
918 } else {
919 memcpy(&saddr, &ifr.ifr_addr,
920 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700921 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200922 }
923
924 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
925 memcpy(&saddr, &ifr.ifr_addr,
926 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700927 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200928 }
929 close(s);
930 }
931
932#ifdef ANDROID
933 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
934 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
935 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
936 if (property_get(tmp, prop, NULL) != 0 &&
937 strcmp(prop, "ok") == 0) {
938 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
939 ifname);
940 if (property_get(tmp, prop, NULL) != 0 &&
941 strcmp(ip, prop) == 0)
942 is_dhcp = 1;
943 }
944 }
945
946 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700947 if (property_get(tmp, prop, NULL) != 0)
948 strlcpy(dns, prop, sizeof(dns));
949 else if (property_get("net.dns1", prop, NULL) != 0)
950 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200951
952 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700953 if (property_get(tmp, prop, NULL) != 0)
954 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200955#else /* ANDROID */
956#ifdef __linux__
Jouni Malinen016ae6c2019-11-04 17:00:01 +0200957 if (get_driver_type(dut) == DRIVER_OPENWRT)
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530958 str_ps = "ps -w";
959 else
960 str_ps = "ps ax";
961 snprintf(tmp, sizeof(tmp),
962 "%s | grep dhclient | grep -v grep | grep -q %s",
963 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200964 if (system(tmp) == 0)
965 is_dhcp = 1;
966 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530967 snprintf(tmp, sizeof(tmp),
968 "%s | grep udhcpc | grep -v grep | grep -q %s",
969 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200970 if (system(tmp) == 0)
971 is_dhcp = 1;
972 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530973 snprintf(tmp, sizeof(tmp),
974 "%s | grep dhcpcd | grep -v grep | grep -q %s",
975 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200976 if (system(tmp) == 0)
977 is_dhcp = 1;
978 }
979 }
980#endif /* __linux__ */
981
982 f = fopen("/etc/resolv.conf", "r");
983 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530984 char *pos, *pos2;
985
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 while (fgets(tmp, sizeof(tmp), f)) {
987 if (strncmp(tmp, "nameserver", 10) != 0)
988 continue;
989 pos = tmp + 10;
990 while (*pos == ' ' || *pos == '\t')
991 pos++;
992 pos2 = pos;
993 while (*pos2) {
994 if (*pos2 == '\n' || *pos2 == '\r') {
995 *pos2 = '\0';
996 break;
997 }
998 pos2++;
999 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001000 if (!dns[0])
1001 strlcpy(dns, pos, sizeof(dns));
1002 else if (!sec_dns[0])
1003 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001004 }
1005 fclose(f);
1006 }
1007#endif /* ANDROID */
1008
1009 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1010 is_dhcp, ip, mask, dns);
1011 buf[buf_len - 1] = '\0';
1012
1013 return 0;
1014}
1015
1016
1017
1018
1019int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1020 size_t buf_len)
1021{
1022#ifdef __linux__
1023#ifdef ANDROID
1024 char cmd[200], result[1000], *pos, *end;
1025 FILE *f;
1026 size_t len;
1027
1028 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1029 f = popen(cmd, "r");
1030 if (f == NULL)
1031 return -1;
1032 len = fread(result, 1, sizeof(result) - 1, f);
1033 pclose(f);
1034 if (len == 0)
1035 return -1;
1036 result[len] = '\0';
1037 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1038
1039 pos = strstr(result, "inet6 ");
1040 if (pos == NULL)
1041 return -1;
1042 pos += 6;
1043 end = strchr(pos, ' ');
1044 if (end)
1045 *end = '\0';
1046 end = strchr(pos, '/');
1047 if (end)
1048 *end = '\0';
1049 snprintf(buf, buf_len, "ip,%s", pos);
1050 buf[buf_len - 1] = '\0';
1051 return 0;
1052#else /* ANDROID */
1053 struct ifaddrs *ifaddr, *ifa;
1054 int res, found = 0;
1055 char host[NI_MAXHOST];
1056
1057 if (getifaddrs(&ifaddr) < 0) {
1058 perror("getifaddrs");
1059 return -1;
1060 }
1061
1062 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1063 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1064 continue;
1065 if (ifa->ifa_addr == NULL ||
1066 ifa->ifa_addr->sa_family != AF_INET6)
1067 continue;
1068
1069 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1070 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1071 if (res != 0) {
1072 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1073 gai_strerror(res));
1074 continue;
1075 }
1076 if (strncmp(host, "fe80::", 6) == 0)
1077 continue; /* skip link-local */
1078
1079 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1080 found = 1;
1081 break;
1082 }
1083
1084 freeifaddrs(ifaddr);
1085
1086 if (found) {
1087 char *pos;
1088 pos = strchr(host, '%');
1089 if (pos)
1090 *pos = '\0';
1091 snprintf(buf, buf_len, "ip,%s", host);
1092 buf[buf_len - 1] = '\0';
1093 return 0;
1094 }
1095
1096#endif /* ANDROID */
1097#endif /* __linux__ */
1098 return -1;
1099}
1100
1101
Jouni Malinenf7222712019-06-13 01:50:21 +03001102static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1103 struct sigma_conn *conn,
1104 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001105{
1106 const char *intf = get_param(cmd, "Interface");
1107 const char *ifname;
1108 char buf[200];
1109 const char *val;
1110 int type = 1;
1111
1112 if (intf == NULL)
1113 return -1;
1114
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001115 if (strcmp(intf, get_main_ifname(dut)) == 0)
1116 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001117 else
1118 ifname = intf;
1119
1120 /*
1121 * UCC may assume the IP address to be available immediately after
1122 * association without trying to run sta_get_ip_config multiple times.
1123 * Sigma CAPI does not specify this command as a block command that
1124 * would wait for the address to become available, but to pass tests
1125 * more reliably, it looks like such a wait may be needed here.
1126 */
1127 if (wait_ip_addr(dut, ifname, 15) < 0) {
1128 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1129 "for sta_get_ip_config");
1130 /*
1131 * Try to continue anyway since many UCC tests do not really
1132 * care about the return value from here..
1133 */
1134 }
1135
1136 val = get_param(cmd, "Type");
1137 if (val)
1138 type = atoi(val);
1139 if (type == 2 || dut->last_set_ip_config_ipv6) {
1140 int i;
1141
1142 /*
1143 * Since we do not have proper wait for IPv6 addresses, use a
1144 * fixed two second delay here as a workaround for UCC script
1145 * assuming IPv6 address is available when this command returns.
1146 * Some scripts did not use Type,2 properly for IPv6, so include
1147 * also the cases where the previous sta_set_ip_config indicated
1148 * use of IPv6.
1149 */
1150 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1151 for (i = 0; i < 10; i++) {
1152 sleep(1);
1153 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1154 {
1155 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1156 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1157#ifdef ANDROID
1158 sigma_dut_print(dut, DUT_MSG_INFO,
1159 "Adding IPv6 rule on Android");
1160 add_ipv6_rule(dut, intf);
1161#endif /* ANDROID */
1162
1163 return 0;
1164 }
1165 }
1166 }
1167 if (type == 1) {
1168 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1169 return -2;
1170 } else if (type == 2) {
1171 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1172 return -2;
1173 } else {
1174 send_resp(dut, conn, SIGMA_ERROR,
1175 "errorCode,Unsupported address type");
1176 return 0;
1177 }
1178
1179 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1180 return 0;
1181}
1182
1183
1184static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1185{
1186#ifdef __linux__
1187 char buf[200];
1188 char path[128];
1189 struct stat s;
1190
1191#ifdef ANDROID
1192 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1193#else /* ANDROID */
1194 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1195#endif /* ANDROID */
1196 if (stat(path, &s) == 0) {
1197 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1198 sigma_dut_print(dut, DUT_MSG_INFO,
1199 "Kill previous DHCP client: %s", buf);
1200 if (system(buf) != 0)
1201 sigma_dut_print(dut, DUT_MSG_INFO,
1202 "Failed to kill DHCP client");
1203 unlink(path);
1204 sleep(1);
1205 } else {
1206 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1207
1208 if (stat(path, &s) == 0) {
1209 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1210 sigma_dut_print(dut, DUT_MSG_INFO,
1211 "Kill previous DHCP client: %s", buf);
1212 if (system(buf) != 0)
1213 sigma_dut_print(dut, DUT_MSG_INFO,
1214 "Failed to kill DHCP client");
1215 unlink(path);
1216 sleep(1);
1217 }
1218 }
1219#endif /* __linux__ */
1220}
1221
1222
1223static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1224{
1225#ifdef __linux__
1226 char buf[200];
1227
1228#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301229 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1230 snprintf(buf, sizeof(buf),
1231 "/system/bin/dhcpcd -b %s", ifname);
1232 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1233 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301234 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1235 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1236 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1237 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301238 } else {
1239 sigma_dut_print(dut, DUT_MSG_ERROR,
1240 "DHCP client program missing");
1241 return 0;
1242 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001243#else /* ANDROID */
1244 snprintf(buf, sizeof(buf),
1245 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1246 ifname, ifname);
1247#endif /* ANDROID */
1248 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1249 if (system(buf) != 0) {
1250 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1251 if (system(buf) != 0) {
1252 sigma_dut_print(dut, DUT_MSG_INFO,
1253 "Failed to start DHCP client");
1254#ifndef ANDROID
1255 return -1;
1256#endif /* ANDROID */
1257 }
1258 }
1259#endif /* __linux__ */
1260
1261 return 0;
1262}
1263
1264
1265static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1266{
1267#ifdef __linux__
1268 char buf[200];
1269
1270 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1271 if (system(buf) != 0) {
1272 sigma_dut_print(dut, DUT_MSG_INFO,
1273 "Failed to clear IP addresses");
1274 return -1;
1275 }
1276#endif /* __linux__ */
1277
1278 return 0;
1279}
1280
1281
1282#ifdef ANDROID
1283static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1284{
1285 char cmd[200], *result, *pos;
1286 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301287 int tableid;
1288 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001289
1290 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1291 ifname);
1292 fp = popen(cmd, "r");
1293 if (fp == NULL)
1294 return -1;
1295
1296 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301297 if (result == NULL) {
1298 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001299 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301300 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001301
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301302 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001303 fclose(fp);
1304
1305 if (len == 0) {
1306 free(result);
1307 return -1;
1308 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301309 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001310
1311 pos = strstr(result, "table ");
1312 if (pos == NULL) {
1313 free(result);
1314 return -1;
1315 }
1316
1317 pos += strlen("table ");
1318 tableid = atoi(pos);
1319 if (tableid != 0) {
1320 if (system("ip -6 rule del prio 22000") != 0) {
1321 /* ignore any error */
1322 }
1323 snprintf(cmd, sizeof(cmd),
1324 "ip -6 rule add from all lookup %d prio 22000",
1325 tableid);
1326 if (system(cmd) != 0) {
1327 sigma_dut_print(dut, DUT_MSG_INFO,
1328 "Failed to run %s", cmd);
1329 free(result);
1330 return -1;
1331 }
1332 } else {
1333 sigma_dut_print(dut, DUT_MSG_INFO,
1334 "No Valid Table Id found %s", pos);
1335 free(result);
1336 return -1;
1337 }
1338 free(result);
1339
1340 return 0;
1341}
1342#endif /* ANDROID */
1343
1344
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301345int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1346 const char *ip, const char *mask)
1347{
1348 char buf[200];
1349
1350 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1351 ifname, ip, mask);
1352 return system(buf) == 0;
1353}
1354
1355
1356int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1357{
1358 char buf[200];
1359
1360 if (!is_ip_addr(gw)) {
1361 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1362 return -1;
1363 }
1364
1365 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1366 if (!dut->no_ip_addr_set && system(buf) != 0) {
1367 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1368 gw);
1369 if (system(buf) != 0)
1370 return 0;
1371 }
1372
1373 return 1;
1374}
1375
1376
Jouni Malinenf7222712019-06-13 01:50:21 +03001377static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1378 struct sigma_conn *conn,
1379 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001380{
1381 const char *intf = get_param(cmd, "Interface");
1382 const char *ifname;
1383 char buf[200];
1384 const char *val, *ip, *mask, *gw;
1385 int type = 1;
1386
1387 if (intf == NULL)
1388 return -1;
1389
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001390 if (strcmp(intf, get_main_ifname(dut)) == 0)
1391 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001392 else
1393 ifname = intf;
1394
1395 if (if_nametoindex(ifname) == 0) {
1396 send_resp(dut, conn, SIGMA_ERROR,
1397 "ErrorCode,Unknown interface");
1398 return 0;
1399 }
1400
1401 val = get_param(cmd, "Type");
1402 if (val) {
1403 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301404 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001405 send_resp(dut, conn, SIGMA_ERROR,
1406 "ErrorCode,Unsupported address type");
1407 return 0;
1408 }
1409 }
1410
1411 dut->last_set_ip_config_ipv6 = 0;
1412
1413 val = get_param(cmd, "dhcp");
1414 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1415 static_ip_file(0, NULL, NULL, NULL);
1416#ifdef __linux__
1417 if (type == 2) {
1418 dut->last_set_ip_config_ipv6 = 1;
1419 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1420 "stateless address autoconfiguration");
1421#ifdef ANDROID
1422 /*
1423 * This sleep is required as the assignment in case of
1424 * Android is taking time and is done by the kernel.
1425 * The subsequent ping for IPv6 is impacting HS20 test
1426 * case.
1427 */
1428 sleep(2);
1429 add_ipv6_rule(dut, intf);
1430#endif /* ANDROID */
1431 /* Assume this happens by default */
1432 return 1;
1433 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301434 if (type != 3) {
1435 kill_dhcp_client(dut, ifname);
1436 if (start_dhcp_client(dut, ifname) < 0)
1437 return -2;
1438 } else {
1439 sigma_dut_print(dut, DUT_MSG_DEBUG,
1440 "Using FILS HLP DHCPv4 Rapid Commit");
1441 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001442
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001443 return 1;
1444#endif /* __linux__ */
1445 return -2;
1446 }
1447
1448 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301449 if (!ip) {
1450 send_resp(dut, conn, SIGMA_INVALID,
1451 "ErrorCode,Missing IP address");
1452 return 0;
1453 }
1454
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001455 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301456 if (!mask) {
1457 send_resp(dut, conn, SIGMA_INVALID,
1458 "ErrorCode,Missing subnet mask");
1459 return 0;
1460 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001461
1462 if (type == 2) {
1463 int net = atoi(mask);
1464
1465 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1466 return -1;
1467
1468 if (dut->no_ip_addr_set) {
1469 snprintf(buf, sizeof(buf),
1470 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1471 ifname);
1472 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1473 if (system(buf) != 0) {
1474 sigma_dut_print(dut, DUT_MSG_DEBUG,
1475 "Failed to disable IPv6 address before association");
1476 }
1477 } else {
1478 snprintf(buf, sizeof(buf),
1479 "ip -6 addr del %s/%s dev %s",
1480 ip, mask, ifname);
1481 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1482 if (system(buf) != 0) {
1483 /*
1484 * This command may fail if the address being
1485 * deleted does not exist. Inaction here is
1486 * intentional.
1487 */
1488 }
1489
1490 snprintf(buf, sizeof(buf),
1491 "ip -6 addr add %s/%s dev %s",
1492 ip, mask, ifname);
1493 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1494 if (system(buf) != 0) {
1495 send_resp(dut, conn, SIGMA_ERROR,
1496 "ErrorCode,Failed to set IPv6 address");
1497 return 0;
1498 }
1499 }
1500
1501 dut->last_set_ip_config_ipv6 = 1;
1502 static_ip_file(6, ip, mask, NULL);
1503 return 1;
1504 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301505 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001506 return -1;
1507 }
1508
1509 kill_dhcp_client(dut, ifname);
1510
1511 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301512 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001513 send_resp(dut, conn, SIGMA_ERROR,
1514 "ErrorCode,Failed to set IP address");
1515 return 0;
1516 }
1517 }
1518
1519 gw = get_param(cmd, "defaultGateway");
1520 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301521 if (set_ipv4_gw(dut, gw) < 1) {
1522 send_resp(dut, conn, SIGMA_ERROR,
1523 "ErrorCode,Failed to set default gateway");
1524 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001525 }
1526 }
1527
1528 val = get_param(cmd, "primary-dns");
1529 if (val) {
1530 /* TODO */
1531 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1532 "setting", val);
1533 }
1534
1535 val = get_param(cmd, "secondary-dns");
1536 if (val) {
1537 /* TODO */
1538 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1539 "setting", val);
1540 }
1541
1542 static_ip_file(4, ip, mask, gw);
1543
1544 return 1;
1545}
1546
1547
Jouni Malinenf7222712019-06-13 01:50:21 +03001548static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1549 struct sigma_conn *conn,
1550 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551{
1552 /* const char *intf = get_param(cmd, "Interface"); */
1553 /* TODO: could report more details here */
1554 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1555 return 0;
1556}
1557
1558
Jouni Malinenf7222712019-06-13 01:50:21 +03001559static enum sigma_cmd_result cmd_sta_get_mac_address(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 char addr[20], resp[50];
1565
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301566 if (dut->dev_role == DEVROLE_STA_CFON)
1567 return sta_cfon_get_mac_address(dut, conn, cmd);
1568
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001569 if (get_wpa_status(get_station_ifname(dut), "address",
1570 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001571 return -2;
1572
1573 snprintf(resp, sizeof(resp), "mac,%s", addr);
1574 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1575 return 0;
1576}
1577
1578
Jouni Malinenf7222712019-06-13 01:50:21 +03001579static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1580 struct sigma_conn *conn,
1581 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001582{
1583 /* const char *intf = get_param(cmd, "Interface"); */
1584 int connected = 0;
1585 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001586 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001588 sigma_dut_print(dut, DUT_MSG_INFO,
1589 "Could not get interface %s status",
1590 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001591 return -2;
1592 }
1593
1594 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1595 if (strncmp(result, "COMPLETED", 9) == 0)
1596 connected = 1;
1597
1598 if (connected)
1599 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1600 else
1601 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1602
1603 return 0;
1604}
1605
1606
Jouni Malinenf7222712019-06-13 01:50:21 +03001607static enum sigma_cmd_result
1608cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1609 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001610{
1611 /* const char *intf = get_param(cmd, "Interface"); */
1612 const char *dst, *timeout;
1613 int wait_time = 90;
1614 char buf[100];
1615 int res;
1616
1617 dst = get_param(cmd, "destination");
1618 if (dst == NULL || !is_ip_addr(dst))
1619 return -1;
1620
1621 timeout = get_param(cmd, "timeout");
1622 if (timeout) {
1623 wait_time = atoi(timeout);
1624 if (wait_time < 1)
1625 wait_time = 1;
1626 }
1627
1628 /* TODO: force renewal of IP lease if DHCP is enabled */
1629
1630 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1631 res = system(buf);
1632 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1633 if (res == 0)
1634 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1635 else if (res == 256)
1636 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1637 else
1638 return -2;
1639
1640 return 0;
1641}
1642
1643
Jouni Malinenf7222712019-06-13 01:50:21 +03001644static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1645 struct sigma_conn *conn,
1646 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001647{
1648 /* const char *intf = get_param(cmd, "Interface"); */
1649 char bssid[20], resp[50];
1650
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001651 if (get_wpa_status(get_station_ifname(dut), "bssid",
1652 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001653 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001654
1655 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1656 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1657 return 0;
1658}
1659
1660
1661#ifdef __SAMSUNG__
1662static int add_use_network(const char *ifname)
1663{
1664 char buf[100];
1665
1666 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1667 wpa_command(ifname, buf);
1668 return 0;
1669}
1670#endif /* __SAMSUNG__ */
1671
1672
1673static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1674 const char *ifname, struct sigma_cmd *cmd)
1675{
1676 const char *ssid = get_param(cmd, "ssid");
1677 int id;
1678 const char *val;
1679
1680 if (ssid == NULL)
1681 return -1;
1682
1683 start_sta_mode(dut);
1684
1685#ifdef __SAMSUNG__
1686 add_use_network(ifname);
1687#endif /* __SAMSUNG__ */
1688
1689 id = add_network(ifname);
1690 if (id < 0)
1691 return -2;
1692 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1693
1694 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1695 return -2;
1696
1697 dut->infra_network_id = id;
1698 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1699
1700 val = get_param(cmd, "program");
1701 if (!val)
1702 val = get_param(cmd, "prog");
1703 if (val && strcasecmp(val, "hs2") == 0) {
1704 char buf[100];
1705 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1706 wpa_command(ifname, buf);
1707
1708 val = get_param(cmd, "prefer");
1709 if (val && atoi(val) > 0)
1710 set_network(ifname, id, "priority", "1");
1711 }
1712
1713 return id;
1714}
1715
1716
Jouni Malinenf7222712019-06-13 01:50:21 +03001717static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1718 struct sigma_conn *conn,
1719 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001720{
1721 const char *intf = get_param(cmd, "Interface");
1722 const char *ssid = get_param(cmd, "ssid");
1723 const char *type = get_param(cmd, "encpType");
1724 const char *ifname;
1725 char buf[200];
1726 int id;
1727
1728 if (intf == NULL || ssid == NULL)
1729 return -1;
1730
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001731 if (strcmp(intf, get_main_ifname(dut)) == 0)
1732 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001733 else
1734 ifname = intf;
1735
1736 id = add_network_common(dut, conn, ifname, cmd);
1737 if (id < 0)
1738 return id;
1739
1740 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1741 return -2;
1742
1743 if (type && strcasecmp(type, "wep") == 0) {
1744 const char *val;
1745 int i;
1746
1747 val = get_param(cmd, "activeKey");
1748 if (val) {
1749 int keyid;
1750 keyid = atoi(val);
1751 if (keyid < 1 || keyid > 4)
1752 return -1;
1753 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1754 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1755 return -2;
1756 }
1757
1758 for (i = 0; i < 4; i++) {
1759 snprintf(buf, sizeof(buf), "key%d", i + 1);
1760 val = get_param(cmd, buf);
1761 if (val == NULL)
1762 continue;
1763 snprintf(buf, sizeof(buf), "wep_key%d", i);
1764 if (set_network(ifname, id, buf, val) < 0)
1765 return -2;
1766 }
1767 }
1768
1769 return 1;
1770}
1771
1772
Jouni Malinene4fde732019-03-25 22:29:37 +02001773static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1774 int id, const char *val)
1775{
1776 char key_mgmt[200], *end, *pos;
1777 const char *in_pos = val;
1778
Jouni Malinen8179fee2019-03-28 03:19:47 +02001779 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001780 pos = key_mgmt;
1781 end = pos + sizeof(key_mgmt);
1782 while (*in_pos) {
1783 int res, akm = atoi(in_pos);
1784 const char *str;
1785
Jouni Malinen8179fee2019-03-28 03:19:47 +02001786 if (akm >= 0 && akm < 32)
1787 dut->akm_values |= 1 << akm;
1788
Jouni Malinene4fde732019-03-25 22:29:37 +02001789 switch (akm) {
1790 case AKM_WPA_EAP:
1791 str = "WPA-EAP";
1792 break;
1793 case AKM_WPA_PSK:
1794 str = "WPA-PSK";
1795 break;
1796 case AKM_FT_EAP:
1797 str = "FT-EAP";
1798 break;
1799 case AKM_FT_PSK:
1800 str = "FT-PSK";
1801 break;
1802 case AKM_EAP_SHA256:
1803 str = "WPA-EAP-SHA256";
1804 break;
1805 case AKM_PSK_SHA256:
1806 str = "WPA-PSK-SHA256";
1807 break;
1808 case AKM_SAE:
1809 str = "SAE";
1810 break;
1811 case AKM_FT_SAE:
1812 str = "FT-SAE";
1813 break;
1814 case AKM_SUITE_B:
1815 str = "WPA-EAP-SUITE-B-192";
1816 break;
1817 case AKM_FT_SUITE_B:
1818 str = "FT-EAP-SHA384";
1819 break;
1820 case AKM_FILS_SHA256:
1821 str = "FILS-SHA256";
1822 break;
1823 case AKM_FILS_SHA384:
1824 str = "FILS-SHA384";
1825 break;
1826 case AKM_FT_FILS_SHA256:
1827 str = "FT-FILS-SHA256";
1828 break;
1829 case AKM_FT_FILS_SHA384:
1830 str = "FT-FILS-SHA384";
1831 break;
1832 default:
1833 sigma_dut_print(dut, DUT_MSG_ERROR,
1834 "Unsupported AKMSuitetype %d", akm);
1835 return -1;
1836 }
1837
1838 res = snprintf(pos, end - pos, "%s%s",
1839 pos == key_mgmt ? "" : " ", str);
1840 if (res < 0 || res >= end - pos)
1841 return -1;
1842 pos += res;
1843
1844 in_pos = strchr(in_pos, ';');
1845 if (!in_pos)
1846 break;
1847 while (*in_pos == ';')
1848 in_pos++;
1849 }
1850 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1851 val, key_mgmt);
1852 return set_network(ifname, id, "key_mgmt", key_mgmt);
1853}
1854
1855
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001856static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1857 const char *ifname, struct sigma_cmd *cmd)
1858{
1859 const char *val;
1860 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001861 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001862 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301863 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001864
1865 id = add_network_common(dut, conn, ifname, cmd);
1866 if (id < 0)
1867 return id;
1868
Jouni Malinen47dcc952017-10-09 16:43:24 +03001869 val = get_param(cmd, "Type");
1870 owe = val && strcasecmp(val, "OWE") == 0;
1871
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001872 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001873 if (!val && owe)
1874 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001875 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001876 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1877 * this missing parameter and assume proto=WPA2. */
1878 if (set_network(ifname, id, "proto", "WPA2") < 0)
1879 return ERROR_SEND_STATUS;
1880 } else if (strcasecmp(val, "wpa") == 0 ||
1881 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001882 if (set_network(ifname, id, "proto", "WPA") < 0)
1883 return -2;
1884 } else if (strcasecmp(val, "wpa2") == 0 ||
1885 strcasecmp(val, "wpa2-psk") == 0 ||
1886 strcasecmp(val, "wpa2-ft") == 0 ||
1887 strcasecmp(val, "wpa2-sha256") == 0) {
1888 if (set_network(ifname, id, "proto", "WPA2") < 0)
1889 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301890 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1891 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001892 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1893 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001894 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301895 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001896 if (set_network(ifname, id, "proto", "WPA2") < 0)
1897 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001898 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001899 } else {
1900 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1901 return 0;
1902 }
1903
1904 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001905 if (val) {
1906 cipher_set = 1;
1907 if (strcasecmp(val, "tkip") == 0) {
1908 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1909 return -2;
1910 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1911 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1912 return -2;
1913 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1914 if (set_network(ifname, id, "pairwise",
1915 "CCMP TKIP") < 0)
1916 return -2;
1917 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1918 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1919 return -2;
1920 if (set_network(ifname, id, "group", "GCMP") < 0)
1921 return -2;
1922 } else {
1923 send_resp(dut, conn, SIGMA_ERROR,
1924 "errorCode,Unrecognized encpType value");
1925 return 0;
1926 }
1927 }
1928
1929 val = get_param(cmd, "PairwiseCipher");
1930 if (val) {
1931 cipher_set = 1;
1932 /* TODO: Support space separated list */
1933 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1934 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1935 return -2;
1936 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1937 if (set_network(ifname, id, "pairwise",
1938 "CCMP-256") < 0)
1939 return -2;
1940 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1941 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1942 return -2;
1943 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1944 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1945 return -2;
1946 } else {
1947 send_resp(dut, conn, SIGMA_ERROR,
1948 "errorCode,Unrecognized PairwiseCipher value");
1949 return 0;
1950 }
1951 }
1952
Jouni Malinen47dcc952017-10-09 16:43:24 +03001953 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001954 send_resp(dut, conn, SIGMA_ERROR,
1955 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001956 return 0;
1957 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001958
1959 val = get_param(cmd, "GroupCipher");
1960 if (val) {
1961 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1962 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1963 return -2;
1964 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1965 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1966 return -2;
1967 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1968 if (set_network(ifname, id, "group", "GCMP") < 0)
1969 return -2;
1970 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1971 if (set_network(ifname, id, "group", "CCMP") < 0)
1972 return -2;
1973 } else {
1974 send_resp(dut, conn, SIGMA_ERROR,
1975 "errorCode,Unrecognized GroupCipher value");
1976 return 0;
1977 }
1978 }
1979
Jouni Malinen7b239522017-09-14 21:37:18 +03001980 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001981 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001982 const char *cipher;
1983
1984 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1985 cipher = "BIP-GMAC-256";
1986 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1987 cipher = "BIP-CMAC-256";
1988 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1989 cipher = "BIP-GMAC-128";
1990 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1991 cipher = "AES-128-CMAC";
1992 } else {
1993 send_resp(dut, conn, SIGMA_INVALID,
1994 "errorCode,Unsupported GroupMgntCipher");
1995 return 0;
1996 }
1997 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1998 send_resp(dut, conn, SIGMA_INVALID,
1999 "errorCode,Failed to set GroupMgntCipher");
2000 return 0;
2001 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002002 }
2003
Jouni Malinene4fde732019-03-25 22:29:37 +02002004 val = get_param(cmd, "AKMSuiteType");
2005 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2006 return ERROR_SEND_STATUS;
2007
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002008 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302009
2010 if (dut->program == PROGRAM_OCE) {
2011 dut->sta_pmf = STA_PMF_OPTIONAL;
2012 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2013 return -2;
2014 }
2015
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002016 val = get_param(cmd, "PMF");
2017 if (val) {
2018 if (strcasecmp(val, "Required") == 0 ||
2019 strcasecmp(val, "Forced_Required") == 0) {
2020 dut->sta_pmf = STA_PMF_REQUIRED;
2021 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2022 return -2;
2023 } else if (strcasecmp(val, "Optional") == 0) {
2024 dut->sta_pmf = STA_PMF_OPTIONAL;
2025 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2026 return -2;
2027 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002028 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002029 strcasecmp(val, "Forced_Disabled") == 0) {
2030 dut->sta_pmf = STA_PMF_DISABLED;
2031 } else {
2032 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2033 return 0;
2034 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302035 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002036 dut->sta_pmf = STA_PMF_REQUIRED;
2037 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2038 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002039 }
2040
2041 return id;
2042}
2043
2044
Jouni Malinenf7222712019-06-13 01:50:21 +03002045static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2046 struct sigma_conn *conn,
2047 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002048{
2049 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002050 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002051 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002052 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002053 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002054 const char *ifname, *val, *alg;
2055 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002056 char buf[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002057
2058 if (intf == NULL)
2059 return -1;
2060
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002061 if (strcmp(intf, get_main_ifname(dut)) == 0)
2062 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002063 else
2064 ifname = intf;
2065
2066 id = set_wpa_common(dut, conn, ifname, cmd);
2067 if (id < 0)
2068 return id;
2069
2070 val = get_param(cmd, "keyMgmtType");
2071 alg = get_param(cmd, "micAlg");
2072
Jouni Malinen992a81e2017-08-22 13:57:47 +03002073 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002074 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002075 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2076 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002077 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002078 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2079 return -2;
2080 }
2081 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2082 sigma_dut_print(dut, DUT_MSG_ERROR,
2083 "Failed to clear sae_groups to default");
2084 return -2;
2085 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002086 if (!pmf) {
2087 dut->sta_pmf = STA_PMF_REQUIRED;
2088 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2089 return -2;
2090 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002091 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2092 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2093 if (set_network(ifname, id, "key_mgmt",
2094 "FT-SAE FT-PSK") < 0)
2095 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002096 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002097 if (set_network(ifname, id, "key_mgmt",
2098 "SAE WPA-PSK") < 0)
2099 return -2;
2100 }
2101 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2102 sigma_dut_print(dut, DUT_MSG_ERROR,
2103 "Failed to clear sae_groups to default");
2104 return -2;
2105 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002106 if (!pmf) {
2107 dut->sta_pmf = STA_PMF_OPTIONAL;
2108 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2109 return -2;
2110 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002111 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002112 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2113 return -2;
2114 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2115 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2116 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302117 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2118 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2119 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002120 } else if (!akm &&
2121 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2122 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002123 if (set_network(ifname, id, "key_mgmt",
2124 "WPA-PSK WPA-PSK-SHA256") < 0)
2125 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002126 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002127 if (set_network(ifname, id, "key_mgmt",
2128 "WPA-PSK WPA-PSK-SHA256") < 0)
2129 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002130 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002131 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2132 return -2;
2133 }
2134
2135 val = get_param(cmd, "passPhrase");
2136 if (val == NULL)
2137 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002138 if (type && strcasecmp(type, "SAE") == 0) {
2139 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2140 return -2;
2141 } else {
2142 if (set_network_quoted(ifname, id, "psk", val) < 0)
2143 return -2;
2144 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002145
Jouni Malinen78d10c42019-03-25 22:34:32 +02002146 val = get_param(cmd, "PasswordId");
2147 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2148 return ERROR_SEND_STATUS;
2149
Jouni Malinen992a81e2017-08-22 13:57:47 +03002150 val = get_param(cmd, "ECGroupID");
2151 if (val) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002152 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
2153 if (wpa_command(ifname, buf) != 0) {
2154 sigma_dut_print(dut, DUT_MSG_ERROR,
2155 "Failed to clear sae_groups");
2156 return -2;
2157 }
2158 }
2159
Jouni Malinen68143132017-09-02 02:34:08 +03002160 val = get_param(cmd, "InvalidSAEElement");
2161 if (val) {
2162 free(dut->sae_commit_override);
2163 dut->sae_commit_override = strdup(val);
2164 }
2165
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002166 val = get_param(cmd, "PMKID_Include");
2167 if (val) {
2168 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2169 get_enable_disable(val));
2170 wpa_command(intf, buf);
2171 }
2172
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002173 if (dut->program == PROGRAM_60GHZ && network_mode &&
2174 strcasecmp(network_mode, "PBSS") == 0 &&
2175 set_network(ifname, id, "pbss", "1") < 0)
2176 return -2;
2177
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002178 return 1;
2179}
2180
2181
Jouni Malinen8ac93452019-08-14 15:19:13 +03002182static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2183 struct sigma_conn *conn,
2184 const char *ifname, int id)
2185{
2186 char buf[200];
2187
2188 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2189 if (!file_exists(buf))
2190 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2191 if (!file_exists(buf))
2192 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2193 if (!file_exists(buf)) {
2194 char msg[300];
2195
2196 snprintf(msg, sizeof(msg),
2197 "ErrorCode,trustedRootCA system store (%s) not found",
2198 buf);
2199 send_resp(dut, conn, SIGMA_ERROR, msg);
2200 return STATUS_SENT_ERROR;
2201 }
2202
2203 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2204 return ERROR_SEND_STATUS;
2205
2206 return SUCCESS_SEND_STATUS;
2207}
2208
2209
2210static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2211 struct sigma_conn *conn,
2212 const char *ifname, int id,
2213 const char *val)
2214{
2215 char buf[200];
2216#ifdef ANDROID
2217 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2218 int length;
2219#endif /* ANDROID */
2220
2221 if (strcmp(val, "DEFAULT") == 0)
2222 return set_trust_root_system(dut, conn, ifname, id);
2223
2224#ifdef ANDROID
2225 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2226 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2227 if (length > 0) {
2228 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2229 buf);
2230 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2231 goto ca_cert_selected;
2232 }
2233#endif /* ANDROID */
2234
2235 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2236#ifdef __linux__
2237 if (!file_exists(buf)) {
2238 char msg[300];
2239
2240 snprintf(msg, sizeof(msg),
2241 "ErrorCode,trustedRootCA file (%s) not found", buf);
2242 send_resp(dut, conn, SIGMA_ERROR, msg);
2243 return STATUS_SENT_ERROR;
2244 }
2245#endif /* __linux__ */
2246#ifdef ANDROID
2247ca_cert_selected:
2248#endif /* ANDROID */
2249 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2250 return ERROR_SEND_STATUS;
2251
2252 return SUCCESS_SEND_STATUS;
2253}
2254
2255
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002256static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302257 const char *ifname, int username_identity,
2258 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002259{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002260 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002261 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002262 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002263 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002264 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002265
2266 id = set_wpa_common(dut, conn, ifname, cmd);
2267 if (id < 0)
2268 return id;
2269
2270 val = get_param(cmd, "keyMgmtType");
2271 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302272 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002273 trust_root = get_param(cmd, "trustedRootCA");
2274 domain = get_param(cmd, "Domain");
2275 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002276
Jouni Malinenad395a22017-09-01 21:13:46 +03002277 if (val && strcasecmp(val, "SuiteB") == 0) {
2278 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2279 0)
2280 return -2;
2281 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002282 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2283 return -2;
2284 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2285 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2286 return -2;
2287 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2288 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2289 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002290 } else if (!akm &&
2291 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2292 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002293 if (set_network(ifname, id, "key_mgmt",
2294 "WPA-EAP WPA-EAP-SHA256") < 0)
2295 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302296 } else if (akm && atoi(akm) == 14) {
2297 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2298 dut->sta_pmf == STA_PMF_REQUIRED) {
2299 if (set_network(ifname, id, "key_mgmt",
2300 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2301 return -2;
2302 } else {
2303 if (set_network(ifname, id, "key_mgmt",
2304 "WPA-EAP FILS-SHA256") < 0)
2305 return -2;
2306 }
2307
Jouni Malinen8179fee2019-03-28 03:19:47 +02002308 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302309 } else if (akm && atoi(akm) == 15) {
2310 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2311 dut->sta_pmf == STA_PMF_REQUIRED) {
2312 if (set_network(ifname, id, "key_mgmt",
2313 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2314 return -2;
2315 } else {
2316 if (set_network(ifname, id, "key_mgmt",
2317 "WPA-EAP FILS-SHA384") < 0)
2318 return -2;
2319 }
2320
Jouni Malinen8179fee2019-03-28 03:19:47 +02002321 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002322 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002323 if (set_network(ifname, id, "key_mgmt",
2324 "WPA-EAP WPA-EAP-SHA256") < 0)
2325 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002326 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002327 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2328 return -2;
2329 }
2330
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002331 if (trust_root) {
2332 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2333 !domain_suffix) {
2334 send_resp(dut, conn, SIGMA_ERROR,
2335 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2336 return STATUS_SENT_ERROR;
2337 }
2338 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002339 if (res != SUCCESS_SEND_STATUS)
2340 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002341 }
2342
Jouni Malinen53264f62019-05-03 13:04:40 +03002343 val = get_param(cmd, "ServerCert");
2344 if (val) {
2345 FILE *f;
2346 char *result = NULL, *pos;
2347
2348 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2349 val);
2350 f = fopen(buf, "r");
2351 if (f) {
2352 result = fgets(buf, sizeof(buf), f);
2353 fclose(f);
2354 }
2355 if (!result) {
2356 snprintf(buf2, sizeof(buf2),
2357 "ErrorCode,ServerCert hash could not be read from %s",
2358 buf);
2359 send_resp(dut, conn, SIGMA_ERROR, buf2);
2360 return STATUS_SENT_ERROR;
2361 }
2362 pos = strchr(buf, '\n');
2363 if (pos)
2364 *pos = '\0';
2365 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2366 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2367 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002368
2369 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2370 if (file_exists(buf)) {
2371 sigma_dut_print(dut, DUT_MSG_DEBUG,
2372 "TOD policy enabled for the configured ServerCert hash");
2373 dut->sta_tod_policy = 1;
2374 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002375 }
2376
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002377 if (domain &&
2378 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002379 return ERROR_SEND_STATUS;
2380
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002381 if (domain_suffix &&
2382 set_network_quoted(ifname, id, "domain_suffix_match",
2383 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002384 return ERROR_SEND_STATUS;
2385
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302386 if (username_identity) {
2387 val = get_param(cmd, "username");
2388 if (val) {
2389 if (set_network_quoted(ifname, id, "identity", val) < 0)
2390 return -2;
2391 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002392
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302393 val = get_param(cmd, "password");
2394 if (val) {
2395 if (set_network_quoted(ifname, id, "password", val) < 0)
2396 return -2;
2397 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002398 }
2399
Jouni Malinen8179fee2019-03-28 03:19:47 +02002400 if (dut->akm_values &
2401 ((1 << AKM_FILS_SHA256) |
2402 (1 << AKM_FILS_SHA384) |
2403 (1 << AKM_FT_FILS_SHA256) |
2404 (1 << AKM_FT_FILS_SHA384)))
2405 erp = 1;
2406 if (erp && set_network(ifname, id, "erp", "1") < 0)
2407 return ERROR_SEND_STATUS;
2408
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002409 dut->sta_associate_wait_connect = 1;
2410
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002411 return id;
2412}
2413
2414
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002415static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2416{
2417 const char *val;
2418
2419 if (!cipher)
2420 return 0;
2421
2422 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2423 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2424 else if (strcasecmp(cipher,
2425 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2426 val = "ECDHE-RSA-AES256-GCM-SHA384";
2427 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2428 val = "DHE-RSA-AES256-GCM-SHA384";
2429 else if (strcasecmp(cipher,
2430 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2431 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2432 else
2433 return -1;
2434
2435 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2436 set_network_quoted(ifname, id, "phase1", "");
2437
2438 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2439}
2440
2441
Jouni Malinenf7222712019-06-13 01:50:21 +03002442static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2443 struct sigma_conn *conn,
2444 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002445{
2446 const char *intf = get_param(cmd, "Interface");
2447 const char *ifname, *val;
2448 int id;
2449 char buf[200];
2450#ifdef ANDROID
2451 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2452 int length;
2453 int jb_or_newer = 0;
2454 char prop[PROPERTY_VALUE_MAX];
2455#endif /* ANDROID */
2456
2457 if (intf == NULL)
2458 return -1;
2459
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002460 if (strcmp(intf, get_main_ifname(dut)) == 0)
2461 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002462 else
2463 ifname = intf;
2464
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302465 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002466 if (id < 0)
2467 return id;
2468
2469 if (set_network(ifname, id, "eap", "TLS") < 0)
2470 return -2;
2471
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302472 if (!get_param(cmd, "username") &&
2473 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002474 "wifi-user@wifilabs.local") < 0)
2475 return -2;
2476
2477 val = get_param(cmd, "clientCertificate");
2478 if (val == NULL)
2479 return -1;
2480#ifdef ANDROID
2481 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2482 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2483 if (length < 0) {
2484 /*
2485 * JB started reporting keystore type mismatches, so retry with
2486 * the GET_PUBKEY command if the generic GET fails.
2487 */
2488 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2489 buf, kvalue);
2490 }
2491
2492 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2493 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2494 if (strncmp(prop, "4.0", 3) != 0)
2495 jb_or_newer = 1;
2496 } else
2497 jb_or_newer = 1; /* assume newer */
2498
2499 if (jb_or_newer && length > 0) {
2500 sigma_dut_print(dut, DUT_MSG_INFO,
2501 "Use Android keystore [%s]", buf);
2502 if (set_network(ifname, id, "engine", "1") < 0)
2503 return -2;
2504 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2505 return -2;
2506 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2507 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2508 return -2;
2509 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2510 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2511 return -2;
2512 return 1;
2513 } else if (length > 0) {
2514 sigma_dut_print(dut, DUT_MSG_INFO,
2515 "Use Android keystore [%s]", buf);
2516 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2517 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2518 return -2;
2519 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2520 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2521 return -2;
2522 return 1;
2523 }
2524#endif /* ANDROID */
2525
2526 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2527#ifdef __linux__
2528 if (!file_exists(buf)) {
2529 char msg[300];
2530 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2531 "(%s) not found", buf);
2532 send_resp(dut, conn, SIGMA_ERROR, msg);
2533 return -3;
2534 }
2535#endif /* __linux__ */
2536 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2537 return -2;
2538 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2539 return -2;
2540
2541 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2542 return -2;
2543
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002544 val = get_param(cmd, "keyMgmtType");
2545 if (val && strcasecmp(val, "SuiteB") == 0) {
2546 val = get_param(cmd, "CertType");
2547 if (val && strcasecmp(val, "RSA") == 0) {
2548 if (set_network_quoted(ifname, id, "phase1",
2549 "tls_suiteb=1") < 0)
2550 return -2;
2551 } else {
2552 if (set_network_quoted(ifname, id, "openssl_ciphers",
2553 "SUITEB192") < 0)
2554 return -2;
2555 }
2556
2557 val = get_param(cmd, "TLSCipher");
2558 if (set_tls_cipher(ifname, id, val) < 0) {
2559 send_resp(dut, conn, SIGMA_ERROR,
2560 "ErrorCode,Unsupported TLSCipher value");
2561 return -3;
2562 }
2563 }
2564
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002565 return 1;
2566}
2567
2568
Jouni Malinenf7222712019-06-13 01:50:21 +03002569static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2570 struct sigma_conn *conn,
2571 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002572{
2573 const char *intf = get_param(cmd, "Interface");
2574 const char *ifname;
2575 int id;
2576
2577 if (intf == NULL)
2578 return -1;
2579
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002580 if (strcmp(intf, get_main_ifname(dut)) == 0)
2581 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002582 else
2583 ifname = intf;
2584
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302585 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002586 if (id < 0)
2587 return id;
2588
2589 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2590 send_resp(dut, conn, SIGMA_ERROR,
2591 "errorCode,Failed to set TTLS method");
2592 return 0;
2593 }
2594
2595 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2596 send_resp(dut, conn, SIGMA_ERROR,
2597 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2598 return 0;
2599 }
2600
2601 return 1;
2602}
2603
2604
Jouni Malinenf7222712019-06-13 01:50:21 +03002605static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2606 struct sigma_conn *conn,
2607 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002608{
2609 const char *intf = get_param(cmd, "Interface");
2610 const char *ifname;
2611 int id;
2612
2613 if (intf == NULL)
2614 return -1;
2615
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002616 if (strcmp(intf, get_main_ifname(dut)) == 0)
2617 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002618 else
2619 ifname = intf;
2620
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302621 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002622 if (id < 0)
2623 return id;
2624
2625 if (set_network(ifname, id, "eap", "SIM") < 0)
2626 return -2;
2627
2628 return 1;
2629}
2630
2631
Jouni Malinenf7222712019-06-13 01:50:21 +03002632static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2633 struct sigma_conn *conn,
2634 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002635{
2636 const char *intf = get_param(cmd, "Interface");
2637 const char *ifname, *val;
2638 int id;
2639 char buf[100];
2640
2641 if (intf == NULL)
2642 return -1;
2643
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002644 if (strcmp(intf, get_main_ifname(dut)) == 0)
2645 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002646 else
2647 ifname = intf;
2648
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302649 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002650 if (id < 0)
2651 return id;
2652
2653 if (set_network(ifname, id, "eap", "PEAP") < 0)
2654 return -2;
2655
2656 val = get_param(cmd, "innerEAP");
2657 if (val) {
2658 if (strcasecmp(val, "MSCHAPv2") == 0) {
2659 if (set_network_quoted(ifname, id, "phase2",
2660 "auth=MSCHAPV2") < 0)
2661 return -2;
2662 } else if (strcasecmp(val, "GTC") == 0) {
2663 if (set_network_quoted(ifname, id, "phase2",
2664 "auth=GTC") < 0)
2665 return -2;
2666 } else
2667 return -1;
2668 }
2669
2670 val = get_param(cmd, "peapVersion");
2671 if (val) {
2672 int ver = atoi(val);
2673 if (ver < 0 || ver > 1)
2674 return -1;
2675 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2676 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2677 return -2;
2678 }
2679
2680 return 1;
2681}
2682
2683
Jouni Malinenf7222712019-06-13 01:50:21 +03002684static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2685 struct sigma_conn *conn,
2686 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002687{
2688 const char *intf = get_param(cmd, "Interface");
2689 const char *ifname, *val;
2690 int id;
2691 char buf[100];
2692
2693 if (intf == NULL)
2694 return -1;
2695
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002696 if (strcmp(intf, get_main_ifname(dut)) == 0)
2697 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002698 else
2699 ifname = intf;
2700
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302701 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002702 if (id < 0)
2703 return id;
2704
2705 if (set_network(ifname, id, "eap", "FAST") < 0)
2706 return -2;
2707
2708 val = get_param(cmd, "innerEAP");
2709 if (val) {
2710 if (strcasecmp(val, "MSCHAPV2") == 0) {
2711 if (set_network_quoted(ifname, id, "phase2",
2712 "auth=MSCHAPV2") < 0)
2713 return -2;
2714 } else if (strcasecmp(val, "GTC") == 0) {
2715 if (set_network_quoted(ifname, id, "phase2",
2716 "auth=GTC") < 0)
2717 return -2;
2718 } else
2719 return -1;
2720 }
2721
2722 val = get_param(cmd, "validateServer");
2723 if (val) {
2724 /* TODO */
2725 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2726 "validateServer=%s", val);
2727 }
2728
2729 val = get_param(cmd, "pacFile");
2730 if (val) {
2731 snprintf(buf, sizeof(buf), "blob://%s", val);
2732 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2733 return -2;
2734 }
2735
2736 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2737 0)
2738 return -2;
2739
2740 return 1;
2741}
2742
2743
Jouni Malinenf7222712019-06-13 01:50:21 +03002744static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2745 struct sigma_conn *conn,
2746 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002747{
2748 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302749 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002750 const char *ifname;
2751 int id;
2752
2753 if (intf == NULL)
2754 return -1;
2755
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002756 if (strcmp(intf, get_main_ifname(dut)) == 0)
2757 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002758 else
2759 ifname = intf;
2760
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302761 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002762 if (id < 0)
2763 return id;
2764
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302765 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2766 * hexadecimal).
2767 */
2768 if (username && username[0] == '6') {
2769 if (set_network(ifname, id, "eap", "AKA'") < 0)
2770 return -2;
2771 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002772 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302773 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002774
2775 return 1;
2776}
2777
2778
Jouni Malinenf7222712019-06-13 01:50:21 +03002779static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2780 struct sigma_conn *conn,
2781 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002782{
2783 const char *intf = get_param(cmd, "Interface");
2784 const char *ifname;
2785 int id;
2786
2787 if (intf == NULL)
2788 return -1;
2789
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002790 if (strcmp(intf, get_main_ifname(dut)) == 0)
2791 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002792 else
2793 ifname = intf;
2794
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302795 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002796 if (id < 0)
2797 return id;
2798
2799 if (set_network(ifname, id, "eap", "AKA'") < 0)
2800 return -2;
2801
2802 return 1;
2803}
2804
2805
2806static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2807 struct sigma_cmd *cmd)
2808{
2809 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002810 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002811 const char *ifname;
2812 int id;
2813
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002814 if (strcmp(intf, get_main_ifname(dut)) == 0)
2815 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002816 else
2817 ifname = intf;
2818
2819 id = add_network_common(dut, conn, ifname, cmd);
2820 if (id < 0)
2821 return id;
2822
2823 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2824 return -2;
2825
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002826 if (dut->program == PROGRAM_60GHZ && network_mode &&
2827 strcasecmp(network_mode, "PBSS") == 0 &&
2828 set_network(ifname, id, "pbss", "1") < 0)
2829 return -2;
2830
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002831 return 1;
2832}
2833
2834
Jouni Malinen47dcc952017-10-09 16:43:24 +03002835static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2836 struct sigma_cmd *cmd)
2837{
2838 const char *intf = get_param(cmd, "Interface");
2839 const char *ifname, *val;
2840 int id;
2841
2842 if (intf == NULL)
2843 return -1;
2844
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002845 if (strcmp(intf, get_main_ifname(dut)) == 0)
2846 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002847 else
2848 ifname = intf;
2849
2850 id = set_wpa_common(dut, conn, ifname, cmd);
2851 if (id < 0)
2852 return id;
2853
2854 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2855 return -2;
2856
2857 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002858 if (val && strcmp(val, "0") == 0) {
2859 if (wpa_command(ifname,
2860 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2861 sigma_dut_print(dut, DUT_MSG_ERROR,
2862 "Failed to set OWE DH Param element override");
2863 return -2;
2864 }
2865 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002866 sigma_dut_print(dut, DUT_MSG_ERROR,
2867 "Failed to clear owe_group");
2868 return -2;
2869 }
2870
2871 return 1;
2872}
2873
2874
Jouni Malinenf7222712019-06-13 01:50:21 +03002875static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
2876 struct sigma_conn *conn,
2877 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002878{
2879 const char *type = get_param(cmd, "Type");
2880
2881 if (type == NULL) {
2882 send_resp(dut, conn, SIGMA_ERROR,
2883 "ErrorCode,Missing Type argument");
2884 return 0;
2885 }
2886
2887 if (strcasecmp(type, "OPEN") == 0)
2888 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002889 if (strcasecmp(type, "OWE") == 0)
2890 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002891 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002892 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002893 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002894 return cmd_sta_set_psk(dut, conn, cmd);
2895 if (strcasecmp(type, "EAPTLS") == 0)
2896 return cmd_sta_set_eaptls(dut, conn, cmd);
2897 if (strcasecmp(type, "EAPTTLS") == 0)
2898 return cmd_sta_set_eapttls(dut, conn, cmd);
2899 if (strcasecmp(type, "EAPPEAP") == 0)
2900 return cmd_sta_set_peap(dut, conn, cmd);
2901 if (strcasecmp(type, "EAPSIM") == 0)
2902 return cmd_sta_set_eapsim(dut, conn, cmd);
2903 if (strcasecmp(type, "EAPFAST") == 0)
2904 return cmd_sta_set_eapfast(dut, conn, cmd);
2905 if (strcasecmp(type, "EAPAKA") == 0)
2906 return cmd_sta_set_eapaka(dut, conn, cmd);
2907 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2908 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002909 if (strcasecmp(type, "wep") == 0)
2910 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002911
2912 send_resp(dut, conn, SIGMA_ERROR,
2913 "ErrorCode,Unsupported Type value");
2914 return 0;
2915}
2916
2917
2918int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2919{
2920#ifdef __linux__
2921 /* special handling for ath6kl */
2922 char path[128], fname[128], *pos;
2923 ssize_t res;
2924 FILE *f;
2925
Jouni Malinene39cd562019-05-29 23:39:56 +03002926 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
2927 intf);
2928 if (res < 0 || res >= sizeof(fname))
2929 return 0;
2930 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002931 if (res < 0)
2932 return 0; /* not ath6kl */
2933
2934 if (res >= (int) sizeof(path))
2935 res = sizeof(path) - 1;
2936 path[res] = '\0';
2937 pos = strrchr(path, '/');
2938 if (pos == NULL)
2939 pos = path;
2940 else
2941 pos++;
2942 snprintf(fname, sizeof(fname),
2943 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2944 "create_qos", pos);
2945 if (!file_exists(fname))
2946 return 0; /* not ath6kl */
2947
2948 if (uapsd) {
2949 f = fopen(fname, "w");
2950 if (f == NULL)
2951 return -1;
2952
2953 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2954 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2955 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2956 "20000 0\n");
2957 fclose(f);
2958 } else {
2959 snprintf(fname, sizeof(fname),
2960 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2961 "delete_qos", pos);
2962
2963 f = fopen(fname, "w");
2964 if (f == NULL)
2965 return -1;
2966
2967 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2968 fprintf(f, "2 4\n");
2969 fclose(f);
2970 }
2971#endif /* __linux__ */
2972
2973 return 0;
2974}
2975
2976
Jouni Malinenf7222712019-06-13 01:50:21 +03002977static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
2978 struct sigma_conn *conn,
2979 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002980{
2981 const char *intf = get_param(cmd, "Interface");
2982 /* const char *ssid = get_param(cmd, "ssid"); */
2983 const char *val;
2984 int max_sp_len = 4;
2985 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2986 char buf[100];
2987 int ret1, ret2;
2988
2989 val = get_param(cmd, "maxSPLength");
2990 if (val) {
2991 max_sp_len = atoi(val);
2992 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2993 max_sp_len != 4)
2994 return -1;
2995 }
2996
2997 val = get_param(cmd, "acBE");
2998 if (val)
2999 ac_be = atoi(val);
3000
3001 val = get_param(cmd, "acBK");
3002 if (val)
3003 ac_bk = atoi(val);
3004
3005 val = get_param(cmd, "acVI");
3006 if (val)
3007 ac_vi = atoi(val);
3008
3009 val = get_param(cmd, "acVO");
3010 if (val)
3011 ac_vo = atoi(val);
3012
3013 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3014
3015 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3016 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3017 ret1 = wpa_command(intf, buf);
3018
3019 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3020 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3021 ret2 = wpa_command(intf, buf);
3022
3023 if (ret1 && ret2) {
3024 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3025 "UAPSD parameters.");
3026 return -2;
3027 }
3028
3029 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3030 send_resp(dut, conn, SIGMA_ERROR,
3031 "ErrorCode,Failed to set ath6kl QoS parameters");
3032 return 0;
3033 }
3034
3035 return 1;
3036}
3037
3038
Jouni Malinenf7222712019-06-13 01:50:21 +03003039static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3040 struct sigma_conn *conn,
3041 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003042{
3043 char buf[1000];
3044 const char *intf = get_param(cmd, "Interface");
3045 const char *grp = get_param(cmd, "Group");
3046 const char *act = get_param(cmd, "Action");
3047 const char *tid = get_param(cmd, "Tid");
3048 const char *dir = get_param(cmd, "Direction");
3049 const char *psb = get_param(cmd, "Psb");
3050 const char *up = get_param(cmd, "Up");
3051 const char *fixed = get_param(cmd, "Fixed");
3052 const char *size = get_param(cmd, "Size");
3053 const char *msize = get_param(cmd, "Maxsize");
3054 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3055 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3056 const char *inact = get_param(cmd, "Inactivity");
3057 const char *sus = get_param(cmd, "Suspension");
3058 const char *mindr = get_param(cmd, "Mindatarate");
3059 const char *meandr = get_param(cmd, "Meandatarate");
3060 const char *peakdr = get_param(cmd, "Peakdatarate");
3061 const char *phyrate = get_param(cmd, "Phyrate");
3062 const char *burstsize = get_param(cmd, "Burstsize");
3063 const char *sba = get_param(cmd, "Sba");
3064 int direction;
3065 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003066 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003067 int fixed_int;
3068 int psb_ts;
3069
3070 if (intf == NULL || grp == NULL || act == NULL )
3071 return -1;
3072
3073 if (strcasecmp(act, "addts") == 0) {
3074 if (tid == NULL || dir == NULL || psb == NULL ||
3075 up == NULL || fixed == NULL || size == NULL)
3076 return -1;
3077
3078 /*
3079 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3080 * possible values, but WMM-AC and V-E test scripts use "UP,
3081 * "DOWN", and "BIDI".
3082 */
3083 if (strcasecmp(dir, "uplink") == 0 ||
3084 strcasecmp(dir, "up") == 0) {
3085 direction = 0;
3086 } else if (strcasecmp(dir, "downlink") == 0 ||
3087 strcasecmp(dir, "down") == 0) {
3088 direction = 1;
3089 } else if (strcasecmp(dir, "bidi") == 0) {
3090 direction = 2;
3091 } else {
3092 sigma_dut_print(dut, DUT_MSG_ERROR,
3093 "Direction %s not supported", dir);
3094 return -1;
3095 }
3096
3097 if (strcasecmp(psb, "legacy") == 0) {
3098 psb_ts = 0;
3099 } else if (strcasecmp(psb, "uapsd") == 0) {
3100 psb_ts = 1;
3101 } else {
3102 sigma_dut_print(dut, DUT_MSG_ERROR,
3103 "PSB %s not supported", psb);
3104 return -1;
3105 }
3106
3107 if (atoi(tid) < 0 || atoi(tid) > 7) {
3108 sigma_dut_print(dut, DUT_MSG_ERROR,
3109 "TID %s not supported", tid);
3110 return -1;
3111 }
3112
3113 if (strcasecmp(fixed, "true") == 0) {
3114 fixed_int = 1;
3115 } else {
3116 fixed_int = 0;
3117 }
3118
Peng Xu93319622017-10-04 17:58:16 -07003119 if (sba)
3120 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003121
3122 dut->dialog_token++;
3123 handle = 7000 + dut->dialog_token;
3124
3125 /*
3126 * size: convert to hex
3127 * maxsi: convert to hex
3128 * mindr: convert to hex
3129 * meandr: convert to hex
3130 * peakdr: convert to hex
3131 * burstsize: convert to hex
3132 * phyrate: convert to hex
3133 * sba: convert to hex with modification
3134 * minsi: convert to integer
3135 * sus: convert to integer
3136 * inact: convert to integer
3137 * maxsi: convert to integer
3138 */
3139
3140 /*
3141 * The Nominal MSDU Size field is 2 octets long and contains an
3142 * unsigned integer that specifies the nominal size, in octets,
3143 * of MSDUs belonging to the traffic under this traffic
3144 * specification and is defined in Figure 16. If the Fixed
3145 * subfield is set to 1, then the size of the MSDU is fixed and
3146 * is indicated by the Size Subfield. If the Fixed subfield is
3147 * set to 0, then the size of the MSDU might not be fixed and
3148 * the Size indicates the nominal MSDU size.
3149 *
3150 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3151 * and specifies the excess allocation of time (and bandwidth)
3152 * over and above the stated rates required to transport an MSDU
3153 * belonging to the traffic in this TSPEC. This field is
3154 * represented as an unsigned binary number with an implicit
3155 * binary point after the leftmost 3 bits. For example, an SBA
3156 * of 1.75 is represented as 0x3800. This field is included to
3157 * account for retransmissions. As such, the value of this field
3158 * must be greater than unity.
3159 */
3160
3161 snprintf(buf, sizeof(buf),
3162 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3163 " 0x%X 0x%X 0x%X"
3164 " 0x%X 0x%X 0x%X"
3165 " 0x%X %d %d %d %d"
3166 " %d %d",
3167 intf, handle, tid, direction, psb_ts, up,
3168 (unsigned int) ((fixed_int << 15) | atoi(size)),
3169 msize ? atoi(msize) : 0,
3170 mindr ? atoi(mindr) : 0,
3171 meandr ? atoi(meandr) : 0,
3172 peakdr ? atoi(peakdr) : 0,
3173 burstsize ? atoi(burstsize) : 0,
3174 phyrate ? atoi(phyrate) : 0,
3175 sba ? ((unsigned int) (((int) sba_fv << 13) |
3176 (int)((sba_fv - (int) sba_fv) *
3177 8192))) : 0,
3178 minsi ? atoi(minsi) : 0,
3179 sus ? atoi(sus) : 0,
3180 0, 0,
3181 inact ? atoi(inact) : 0,
3182 maxsi ? atoi(maxsi) : 0);
3183
3184 if (system(buf) != 0) {
3185 sigma_dut_print(dut, DUT_MSG_ERROR,
3186 "iwpriv addtspec request failed");
3187 send_resp(dut, conn, SIGMA_ERROR,
3188 "errorCode,Failed to execute addTspec command");
3189 return 0;
3190 }
3191
3192 sigma_dut_print(dut, DUT_MSG_INFO,
3193 "iwpriv addtspec request send");
3194
3195 /* Mapping handle to a TID */
3196 dut->tid_to_handle[atoi(tid)] = handle;
3197 } else if (strcasecmp(act, "delts") == 0) {
3198 if (tid == NULL)
3199 return -1;
3200
3201 if (atoi(tid) < 0 || atoi(tid) > 7) {
3202 sigma_dut_print(dut, DUT_MSG_ERROR,
3203 "TID %s not supported", tid);
3204 send_resp(dut, conn, SIGMA_ERROR,
3205 "errorCode,Unsupported TID");
3206 return 0;
3207 }
3208
3209 handle = dut->tid_to_handle[atoi(tid)];
3210
3211 if (handle < 7000 || handle > 7255) {
3212 /* Invalid handle ie no mapping for that TID */
3213 sigma_dut_print(dut, DUT_MSG_ERROR,
3214 "handle-> %d not found", handle);
3215 }
3216
3217 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3218 intf, handle);
3219
3220 if (system(buf) != 0) {
3221 sigma_dut_print(dut, DUT_MSG_ERROR,
3222 "iwpriv deltspec request failed");
3223 send_resp(dut, conn, SIGMA_ERROR,
3224 "errorCode,Failed to execute delTspec command");
3225 return 0;
3226 }
3227
3228 sigma_dut_print(dut, DUT_MSG_INFO,
3229 "iwpriv deltspec request send");
3230
3231 dut->tid_to_handle[atoi(tid)] = 0;
3232 } else {
3233 sigma_dut_print(dut, DUT_MSG_ERROR,
3234 "Action type %s not supported", act);
3235 send_resp(dut, conn, SIGMA_ERROR,
3236 "errorCode,Unsupported Action");
3237 return 0;
3238 }
3239
3240 return 1;
3241}
3242
3243
vamsi krishna52e16f92017-08-29 12:37:34 +05303244static int find_network(struct sigma_dut *dut, const char *ssid)
3245{
3246 char list[4096];
3247 char *pos;
3248
3249 sigma_dut_print(dut, DUT_MSG_DEBUG,
3250 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003251 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303252 list, sizeof(list)) < 0)
3253 return -1;
3254 pos = strstr(list, ssid);
3255 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3256 return -1;
3257
3258 while (pos > list && pos[-1] != '\n')
3259 pos--;
3260 dut->infra_network_id = atoi(pos);
3261 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3262 return 0;
3263}
3264
3265
Sunil Dutt44595082018-02-12 19:41:45 +05303266#ifdef NL80211_SUPPORT
3267static int sta_config_rsnie(struct sigma_dut *dut, int val)
3268{
3269 struct nl_msg *msg;
3270 int ret;
3271 struct nlattr *params;
3272 int ifindex;
3273
3274 ifindex = if_nametoindex("wlan0");
3275 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3276 NL80211_CMD_VENDOR)) ||
3277 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3278 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3279 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3280 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3281 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3282 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3283 sigma_dut_print(dut, DUT_MSG_ERROR,
3284 "%s: err in adding vendor_cmd and vendor_data",
3285 __func__);
3286 nlmsg_free(msg);
3287 return -1;
3288 }
3289 nla_nest_end(msg, params);
3290
3291 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3292 if (ret) {
3293 sigma_dut_print(dut, DUT_MSG_ERROR,
3294 "%s: err in send_and_recv_msgs, ret=%d",
3295 __func__, ret);
3296 return ret;
3297 }
3298
3299 return 0;
3300}
3301#endif /* NL80211_SUPPORT */
3302
3303
Jouni Malinenf7222712019-06-13 01:50:21 +03003304static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3305 struct sigma_conn *conn,
3306 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003307{
3308 /* const char *intf = get_param(cmd, "Interface"); */
3309 const char *ssid = get_param(cmd, "ssid");
3310 const char *wps_param = get_param(cmd, "WPS");
3311 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003312 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003313 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003314 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003315 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003316 int e;
3317 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3318 struct wpa_ctrl *ctrl = NULL;
3319 int num_network_not_found = 0;
3320 int num_disconnected = 0;
3321 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003322
3323 if (ssid == NULL)
3324 return -1;
3325
Jouni Malinen37d5c692019-08-19 16:56:55 +03003326 dut->server_cert_tod = 0;
3327
Jouni Malinen3c367e82017-06-23 17:01:47 +03003328 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303329#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003330 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303331 sta_config_rsnie(dut, 1);
3332 dut->config_rsnie = 1;
3333 }
3334#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003335 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3336 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003337 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003338 send_resp(dut, conn, SIGMA_ERROR,
3339 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3340 return 0;
3341 }
3342 }
3343
Jouni Malinen68143132017-09-02 02:34:08 +03003344 if (dut->sae_commit_override) {
3345 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3346 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003347 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003348 send_resp(dut, conn, SIGMA_ERROR,
3349 "ErrorCode,Failed to set SAE commit override");
3350 return 0;
3351 }
3352 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303353#ifdef ANDROID
3354 if (dut->fils_hlp)
3355 process_fils_hlp(dut);
3356#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003357
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003358 if (wps_param &&
3359 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3360 wps = 1;
3361
3362 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003363 if (dut->program == PROGRAM_60GHZ && network_mode &&
3364 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003365 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003366 "pbss", "1") < 0)
3367 return -2;
3368
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003369 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3370 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3371 "parameters not yet set");
3372 return 0;
3373 }
3374 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003375 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003376 return -2;
3377 } else {
3378 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3379 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003380 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003381 return -2;
3382 }
3383 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303384 if (strcmp(ssid, dut->infra_ssid) == 0) {
3385 sigma_dut_print(dut, DUT_MSG_DEBUG,
3386 "sta_associate for the most recently added network");
3387 } else if (find_network(dut, ssid) < 0) {
3388 sigma_dut_print(dut, DUT_MSG_DEBUG,
3389 "sta_associate for a previously stored network profile");
3390 send_resp(dut, conn, SIGMA_ERROR,
3391 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003392 return 0;
3393 }
3394
3395 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003396 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003397 "bssid", bssid) < 0) {
3398 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3399 "Invalid bssid argument");
3400 return 0;
3401 }
3402
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003403 if (dut->program == PROGRAM_WPA3 &&
3404 dut->sta_associate_wait_connect) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003405 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003406 if (!ctrl)
3407 return ERROR_SEND_STATUS;
3408 }
3409
Jouni Malinen46a19b62017-06-23 14:31:27 +03003410 extra[0] = '\0';
3411 if (chan)
3412 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003413 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003414 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3415 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003416 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003417 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3418 "network id %d on %s",
3419 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003420 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003421 ret = ERROR_SEND_STATUS;
3422 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003423 }
3424 }
3425
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003426 if (!ctrl)
3427 return SUCCESS_SEND_STATUS;
3428
3429 /* Wait for connection result to be able to store server certificate
3430 * hash for trust root override testing
3431 * (dev_exec_action,ServerCertTrust). */
3432
3433 for (e = 0; e < 20; e++) {
3434 const char *events[] = {
3435 "CTRL-EVENT-EAP-PEER-CERT",
3436 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3437 "CTRL-EVENT-DISCONNECTED",
3438 "CTRL-EVENT-CONNECTED",
3439 "CTRL-EVENT-NETWORK-NOT-FOUND",
3440 NULL
3441 };
3442 char buf[1024];
3443 int res;
3444
3445 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3446 if (res < 0) {
3447 send_resp(dut, conn, SIGMA_ERROR,
3448 "ErrorCode,Association did not complete");
3449 ret = STATUS_SENT_ERROR;
3450 break;
3451 }
3452 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3453 buf);
3454
3455 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3456 strstr(buf, " depth=0")) {
3457 char *pos = strstr(buf, " hash=");
3458
3459 if (pos) {
3460 char *end;
3461
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003462 if (strstr(buf, " tod=1"))
3463 tod = 1;
3464 else if (strstr(buf, " tod=2"))
3465 tod = 2;
3466 else
3467 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003468 sigma_dut_print(dut, DUT_MSG_DEBUG,
3469 "Server certificate TOD policy: %d",
3470 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003471 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003472
3473 pos += 6;
3474 end = strchr(pos, ' ');
3475 if (end)
3476 *end = '\0';
3477 strlcpy(dut->server_cert_hash, pos,
3478 sizeof(dut->server_cert_hash));
3479 sigma_dut_print(dut, DUT_MSG_DEBUG,
3480 "Server certificate hash: %s",
3481 dut->server_cert_hash);
3482 }
3483 }
3484
3485 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3486 send_resp(dut, conn, SIGMA_COMPLETE,
3487 "Result,TLS server certificate validation failed");
3488 ret = STATUS_SENT_ERROR;
3489 break;
3490 }
3491
3492 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3493 num_network_not_found++;
3494
3495 if (num_network_not_found > 2) {
3496 send_resp(dut, conn, SIGMA_COMPLETE,
3497 "Result,Network not found");
3498 ret = STATUS_SENT_ERROR;
3499 break;
3500 }
3501 }
3502
3503 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3504 num_disconnected++;
3505
3506 if (num_disconnected > 2) {
3507 send_resp(dut, conn, SIGMA_COMPLETE,
3508 "Result,Connection failed");
3509 ret = STATUS_SENT_ERROR;
3510 break;
3511 }
3512 }
3513
3514 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3515 if (tod >= 0) {
3516 sigma_dut_print(dut, DUT_MSG_DEBUG,
3517 "Network profile TOD policy update: %d -> %d",
3518 dut->sta_tod_policy, tod);
3519 dut->sta_tod_policy = tod;
3520 }
3521 break;
3522 }
3523 }
3524done:
3525 if (ctrl) {
3526 wpa_ctrl_detach(ctrl);
3527 wpa_ctrl_close(ctrl);
3528 }
3529 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003530}
3531
3532
3533static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3534{
3535 char buf[500], cmd[200];
3536 int res;
3537
3538 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3539 * default path */
3540 res = snprintf(cmd, sizeof(cmd),
3541 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3542 file_exists("./hs20-osu-client") ?
3543 "./hs20-osu-client" : "hs20-osu-client",
3544 sigma_wpas_ctrl,
3545 dut->summary_log ? "-s " : "",
3546 dut->summary_log ? dut->summary_log : "");
3547 if (res < 0 || res >= (int) sizeof(cmd))
3548 return -1;
3549
3550 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3551 if (res < 0 || res >= (int) sizeof(buf))
3552 return -1;
3553 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3554
3555 if (system(buf) != 0) {
3556 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3557 return -1;
3558 }
3559 sigma_dut_print(dut, DUT_MSG_DEBUG,
3560 "Completed hs20-osu-client operation");
3561
3562 return 0;
3563}
3564
3565
3566static int download_ppsmo(struct sigma_dut *dut,
3567 struct sigma_conn *conn,
3568 const char *intf,
3569 struct sigma_cmd *cmd)
3570{
3571 const char *name, *path, *val;
3572 char url[500], buf[600], fbuf[100];
3573 char *fqdn = NULL;
3574
3575 name = get_param(cmd, "FileName");
3576 path = get_param(cmd, "FilePath");
3577 if (name == NULL || path == NULL)
3578 return -1;
3579
3580 if (strcasecmp(path, "VendorSpecific") == 0) {
3581 snprintf(url, sizeof(url), "PPS/%s", name);
3582 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3583 "from the device (%s)", url);
3584 if (!file_exists(url)) {
3585 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3586 "PPS MO file does not exist");
3587 return 0;
3588 }
3589 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3590 if (system(buf) != 0) {
3591 send_resp(dut, conn, SIGMA_ERROR,
3592 "errorCode,Failed to copy PPS MO");
3593 return 0;
3594 }
3595 } else if (strncasecmp(path, "http:", 5) != 0 &&
3596 strncasecmp(path, "https:", 6) != 0) {
3597 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3598 "Unsupported FilePath value");
3599 return 0;
3600 } else {
3601 snprintf(url, sizeof(url), "%s/%s", path, name);
3602 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3603 url);
3604 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3605 remove("pps-tnds.xml");
3606 if (system(buf) != 0) {
3607 send_resp(dut, conn, SIGMA_ERROR,
3608 "errorCode,Failed to download PPS MO");
3609 return 0;
3610 }
3611 }
3612
3613 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3614 send_resp(dut, conn, SIGMA_ERROR,
3615 "errorCode,Failed to parse downloaded PPSMO");
3616 return 0;
3617 }
3618 unlink("pps-tnds.xml");
3619
3620 val = get_param(cmd, "managementTreeURI");
3621 if (val) {
3622 const char *pos, *end;
3623 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3624 val);
3625 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3626 send_resp(dut, conn, SIGMA_ERROR,
3627 "errorCode,Invalid managementTreeURI prefix");
3628 return 0;
3629 }
3630 pos = val + 8;
3631 end = strchr(pos, '/');
3632 if (end == NULL ||
3633 strcmp(end, "/PerProviderSubscription") != 0) {
3634 send_resp(dut, conn, SIGMA_ERROR,
3635 "errorCode,Invalid managementTreeURI postfix");
3636 return 0;
3637 }
3638 if (end - pos >= (int) sizeof(fbuf)) {
3639 send_resp(dut, conn, SIGMA_ERROR,
3640 "errorCode,Too long FQDN in managementTreeURI");
3641 return 0;
3642 }
3643 memcpy(fbuf, pos, end - pos);
3644 fbuf[end - pos] = '\0';
3645 fqdn = fbuf;
3646 sigma_dut_print(dut, DUT_MSG_INFO,
3647 "FQDN from managementTreeURI: %s", fqdn);
3648 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3649 FILE *f = fopen("pps-fqdn", "r");
3650 if (f) {
3651 if (fgets(fbuf, sizeof(fbuf), f)) {
3652 fbuf[sizeof(fbuf) - 1] = '\0';
3653 fqdn = fbuf;
3654 sigma_dut_print(dut, DUT_MSG_DEBUG,
3655 "Use FQDN %s", fqdn);
3656 }
3657 fclose(f);
3658 }
3659 }
3660
3661 if (fqdn == NULL) {
3662 send_resp(dut, conn, SIGMA_ERROR,
3663 "errorCode,No FQDN specified");
3664 return 0;
3665 }
3666
3667 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3668 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3669 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3670
3671 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3672 if (rename("pps.xml", buf) < 0) {
3673 send_resp(dut, conn, SIGMA_ERROR,
3674 "errorCode,Could not move PPS MO");
3675 return 0;
3676 }
3677
3678 if (strcasecmp(path, "VendorSpecific") == 0) {
3679 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3680 fqdn);
3681 if (system(buf)) {
3682 send_resp(dut, conn, SIGMA_ERROR,
3683 "errorCode,Failed to copy OSU CA cert");
3684 return 0;
3685 }
3686
3687 snprintf(buf, sizeof(buf),
3688 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3689 fqdn);
3690 if (system(buf)) {
3691 send_resp(dut, conn, SIGMA_ERROR,
3692 "errorCode,Failed to copy AAA CA cert");
3693 return 0;
3694 }
3695 } else {
3696 snprintf(buf, sizeof(buf),
3697 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3698 fqdn, fqdn);
3699 if (run_hs20_osu(dut, buf) < 0) {
3700 send_resp(dut, conn, SIGMA_ERROR,
3701 "errorCode,Failed to download OSU CA cert");
3702 return 0;
3703 }
3704
3705 snprintf(buf, sizeof(buf),
3706 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3707 fqdn, fqdn);
3708 if (run_hs20_osu(dut, buf) < 0) {
3709 sigma_dut_print(dut, DUT_MSG_INFO,
3710 "Failed to download AAA CA cert");
3711 }
3712 }
3713
3714 if (file_exists("next-client-cert.pem")) {
3715 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3716 if (rename("next-client-cert.pem", buf) < 0) {
3717 send_resp(dut, conn, SIGMA_ERROR,
3718 "errorCode,Could not move client certificate");
3719 return 0;
3720 }
3721 }
3722
3723 if (file_exists("next-client-key.pem")) {
3724 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3725 if (rename("next-client-key.pem", buf) < 0) {
3726 send_resp(dut, conn, SIGMA_ERROR,
3727 "errorCode,Could not move client key");
3728 return 0;
3729 }
3730 }
3731
3732 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3733 if (run_hs20_osu(dut, buf) < 0) {
3734 send_resp(dut, conn, SIGMA_ERROR,
3735 "errorCode,Failed to configure credential from "
3736 "PPSMO");
3737 return 0;
3738 }
3739
3740 return 1;
3741}
3742
3743
3744static int download_cert(struct sigma_dut *dut,
3745 struct sigma_conn *conn,
3746 const char *intf,
3747 struct sigma_cmd *cmd)
3748{
3749 const char *name, *path;
3750 char url[500], buf[600];
3751
3752 name = get_param(cmd, "FileName");
3753 path = get_param(cmd, "FilePath");
3754 if (name == NULL || path == NULL)
3755 return -1;
3756
3757 if (strcasecmp(path, "VendorSpecific") == 0) {
3758 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3759 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3760 "certificate from the device (%s)", url);
3761 if (!file_exists(url)) {
3762 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3763 "certificate file does not exist");
3764 return 0;
3765 }
3766 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3767 if (system(buf) != 0) {
3768 send_resp(dut, conn, SIGMA_ERROR,
3769 "errorCode,Failed to copy client "
3770 "certificate");
3771 return 0;
3772 }
3773
3774 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3775 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3776 "private key from the device (%s)", url);
3777 if (!file_exists(url)) {
3778 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3779 "private key file does not exist");
3780 return 0;
3781 }
3782 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3783 if (system(buf) != 0) {
3784 send_resp(dut, conn, SIGMA_ERROR,
3785 "errorCode,Failed to copy client key");
3786 return 0;
3787 }
3788 } else if (strncasecmp(path, "http:", 5) != 0 &&
3789 strncasecmp(path, "https:", 6) != 0) {
3790 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3791 "Unsupported FilePath value");
3792 return 0;
3793 } else {
3794 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3795 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3796 "certificate/key from %s", url);
3797 snprintf(buf, sizeof(buf),
3798 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3799 if (system(buf) != 0) {
3800 send_resp(dut, conn, SIGMA_ERROR,
3801 "errorCode,Failed to download client "
3802 "certificate");
3803 return 0;
3804 }
3805
3806 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3807 {
3808 send_resp(dut, conn, SIGMA_ERROR,
3809 "errorCode,Failed to copy client key");
3810 return 0;
3811 }
3812 }
3813
3814 return 1;
3815}
3816
3817
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003818static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3819 struct sigma_conn *conn,
3820 struct sigma_cmd *cmd)
3821{
3822 const char *val;
3823 const char *intf = get_param(cmd, "interface");
3824
3825 if (!intf)
3826 return -1;
3827
3828 val = get_param(cmd, "WscIEFragment");
3829 if (val && strcasecmp(val, "enable") == 0) {
3830 sigma_dut_print(dut, DUT_MSG_DEBUG,
3831 "Enable WSC IE fragmentation");
3832
3833 dut->wsc_fragment = 1;
3834 /* set long attributes to force fragmentation */
3835 if (wpa_command(intf, "SET device_name "
3836 WPS_LONG_DEVICE_NAME) < 0)
3837 return -2;
3838 if (wpa_command(intf, "SET manufacturer "
3839 WPS_LONG_MANUFACTURER) < 0)
3840 return -2;
3841 if (wpa_command(intf, "SET model_name "
3842 WPS_LONG_MODEL_NAME) < 0)
3843 return -2;
3844 if (wpa_command(intf, "SET model_number "
3845 WPS_LONG_MODEL_NUMBER) < 0)
3846 return -2;
3847 if (wpa_command(intf, "SET serial_number "
3848 WPS_LONG_SERIAL_NUMBER) < 0)
3849 return -2;
3850 }
3851
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003852 val = get_param(cmd, "RSN_IE");
3853 if (val) {
3854 if (strcasecmp(val, "disable") == 0)
3855 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3856 else if (strcasecmp(val, "enable") == 0)
3857 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3858 }
3859
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003860 val = get_param(cmd, "WpsVersion");
3861 if (val)
3862 dut->wps_forced_version = get_wps_forced_version(dut, val);
3863
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003864 val = get_param(cmd, "WscEAPFragment");
3865 if (val && strcasecmp(val, "enable") == 0)
3866 dut->eap_fragment = 1;
3867
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003868 return 1;
3869}
3870
3871
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003872static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3873 struct sigma_conn *conn,
3874 const char *intf,
3875 struct sigma_cmd *cmd)
3876{
3877 const char *val;
3878
3879 val = get_param(cmd, "FileType");
3880 if (val && strcasecmp(val, "PPSMO") == 0)
3881 return download_ppsmo(dut, conn, intf, cmd);
3882 if (val && strcasecmp(val, "CERT") == 0)
3883 return download_cert(dut, conn, intf, cmd);
3884 if (val) {
3885 send_resp(dut, conn, SIGMA_ERROR,
3886 "ErrorCode,Unsupported FileType");
3887 return 0;
3888 }
3889
3890 return 1;
3891}
3892
3893
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303894static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3895 struct sigma_conn *conn,
3896 const char *intf,
3897 struct sigma_cmd *cmd)
3898{
3899 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303900 char buf[1000];
3901 char text[20];
3902 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303903
3904 val = get_param(cmd, "OCESupport");
3905 if (val && strcasecmp(val, "Disable") == 0) {
3906 if (wpa_command(intf, "SET oce 0") < 0) {
3907 send_resp(dut, conn, SIGMA_ERROR,
3908 "ErrorCode,Failed to disable OCE");
3909 return 0;
3910 }
3911 } else if (val && strcasecmp(val, "Enable") == 0) {
3912 if (wpa_command(intf, "SET oce 1") < 0) {
3913 send_resp(dut, conn, SIGMA_ERROR,
3914 "ErrorCode,Failed to enable OCE");
3915 return 0;
3916 }
3917 }
3918
vamsi krishnaa2799492017-12-05 14:28:01 +05303919 val = get_param(cmd, "FILScap");
3920 if (val && (atoi(val) == 1)) {
3921 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3922 send_resp(dut, conn, SIGMA_ERROR,
3923 "ErrorCode,Failed to enable FILS");
3924 return 0;
3925 }
3926 } else if (val && (atoi(val) == 0)) {
3927 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3928 send_resp(dut, conn, SIGMA_ERROR,
3929 "ErrorCode,Failed to disable FILS");
3930 return 0;
3931 }
3932 }
3933
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303934 val = get_param(cmd, "FILSHLP");
3935 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003936 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303937 sizeof(text)) < 0)
3938 return -2;
3939 hwaddr_aton(text, addr);
3940 snprintf(buf, sizeof(buf),
3941 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3942 "080045100140000040004011399e00000000ffffffff00440043"
3943 "012cb30001010600fd4f46410000000000000000000000000000"
3944 "000000000000"
3945 "%02x%02x%02x%02x%02x%02x"
3946 "0000000000000000000000000000000000000000000000000000"
3947 "0000000000000000000000000000000000000000000000000000"
3948 "0000000000000000000000000000000000000000000000000000"
3949 "0000000000000000000000000000000000000000000000000000"
3950 "0000000000000000000000000000000000000000000000000000"
3951 "0000000000000000000000000000000000000000000000000000"
3952 "0000000000000000000000000000000000000000000000000000"
3953 "0000000000000000000000000000000000000000638253633501"
3954 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3955 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3956 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3957 if (wpa_command(intf, buf)) {
3958 send_resp(dut, conn, SIGMA_ERROR,
3959 "ErrorCode,Failed to add HLP");
3960 return 0;
3961 }
3962 dut->fils_hlp = 1;
3963 }
3964
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303965 return 1;
3966}
3967
3968
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003969static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3970 const char *val)
3971{
3972 int counter = 0;
3973 char token[50];
3974 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303975 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003976
Peng Xub8fc5cc2017-05-10 17:27:28 -07003977 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003978 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303979 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003980 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003981 if (strcmp(result, "disable") == 0)
3982 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
3983 else
3984 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303985 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003986 counter++;
3987 }
3988}
3989
3990
3991static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3992 const char *val)
3993{
3994 char buf[100];
3995
3996 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3997 if (system(buf) != 0) {
3998 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3999 }
4000}
4001
4002
4003static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4004 const char *val)
4005{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004006 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004007 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004008 }
4009}
4010
4011
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004012static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4013 const char *val)
4014{
4015#ifdef NL80211_SUPPORT
4016 struct nl_msg *msg;
4017 int ret = 0;
4018 struct nlattr *params;
4019 int ifindex;
4020 int wmmenable = 1;
4021
4022 if (val &&
4023 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4024 wmmenable = 0;
4025
4026 ifindex = if_nametoindex(intf);
4027 if (ifindex == 0) {
4028 sigma_dut_print(dut, DUT_MSG_ERROR,
4029 "%s: Index for interface %s failed",
4030 __func__, intf);
4031 return -1;
4032 }
4033
4034 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4035 NL80211_CMD_VENDOR)) ||
4036 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4037 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4038 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4039 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4040 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4041 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4042 wmmenable)) {
4043 sigma_dut_print(dut, DUT_MSG_ERROR,
4044 "%s: err in adding vendor_cmd and vendor_data",
4045 __func__);
4046 nlmsg_free(msg);
4047 return -1;
4048 }
4049 nla_nest_end(msg, params);
4050
4051 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4052 if (ret) {
4053 sigma_dut_print(dut, DUT_MSG_ERROR,
4054 "%s: err in send_and_recv_msgs, ret=%d",
4055 __func__, ret);
4056 }
4057 return ret;
4058#else /* NL80211_SUPPORT */
4059 sigma_dut_print(dut, DUT_MSG_ERROR,
4060 "WMM cannot be changed without NL80211_SUPPORT defined");
4061 return -1;
4062#endif /* NL80211_SUPPORT */
4063}
4064
4065
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004066static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4067 const char *val)
4068{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004069 int sgi20;
4070
4071 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4072
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004073 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004074}
4075
4076
4077static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4078 const char *val)
4079{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304080 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004081
4082 /* Disable Tx Beam forming when using a fixed rate */
4083 ath_disable_txbf(dut, intf);
4084
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304085 v = atoi(val);
4086 if (v < 0 || v > 32) {
4087 sigma_dut_print(dut, DUT_MSG_ERROR,
4088 "Invalid Fixed MCS rate: %d", v);
4089 return;
4090 }
4091 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004092
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004093 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004094
4095 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004096 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004097}
4098
4099
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004100static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4101 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004102{
4103 char buf[60];
4104
4105 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4106 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4107 else
4108 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4109
4110 if (system(buf) != 0)
4111 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4112}
4113
4114
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004115static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4116 int ampdu)
4117{
4118 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004119 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004120
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004121 if (ampdu)
4122 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004123 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4124 if (system(buf) != 0) {
4125 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4126 return -1;
4127 }
4128
4129 return 0;
4130}
4131
4132
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004133static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4134 const char *val)
4135{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004136 run_iwpriv(dut, intf, "tx_stbc %s", val);
4137 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004138}
4139
4140
4141static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4142 const char *val)
4143{
4144 char buf[60];
4145
Peng Xucc317ed2017-05-18 16:44:37 -07004146 if (strcmp(val, "160") == 0) {
4147 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4148 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004149 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4150 } else if (strcmp(val, "40") == 0) {
4151 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4152 } else if (strcmp(val, "20") == 0) {
4153 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4154 } else if (strcasecmp(val, "Auto") == 0) {
4155 buf[0] = '\0';
4156 } else {
4157 sigma_dut_print(dut, DUT_MSG_ERROR,
4158 "WIDTH/CTS_WIDTH value not supported");
4159 return -1;
4160 }
4161
4162 if (buf[0] != '\0' && system(buf) != 0) {
4163 sigma_dut_print(dut, DUT_MSG_ERROR,
4164 "Failed to set WIDTH/CTS_WIDTH");
4165 return -1;
4166 }
4167
4168 return 0;
4169}
4170
4171
4172int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4173 const char *intf, const char *val)
4174{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004175 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004176 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004177 dut->chwidth = 0;
4178 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004179 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004180 dut->chwidth = 0;
4181 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004182 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004183 dut->chwidth = 1;
4184 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004185 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004186 dut->chwidth = 2;
4187 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004188 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004189 dut->chwidth = 3;
4190 } else {
4191 send_resp(dut, conn, SIGMA_ERROR,
4192 "ErrorCode,WIDTH not supported");
4193 return -1;
4194 }
4195
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004196 return 0;
4197}
4198
4199
4200static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4201 const char *val)
4202{
4203 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004204 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004205
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004206 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004207 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004208 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004209 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004210 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004211 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004212 } else {
4213 sigma_dut_print(dut, DUT_MSG_ERROR,
4214 "SP_STREAM value not supported");
4215 return -1;
4216 }
4217
4218 if (system(buf) != 0) {
4219 sigma_dut_print(dut, DUT_MSG_ERROR,
4220 "Failed to set SP_STREAM");
4221 return -1;
4222 }
4223
Arif Hussainac6c5112018-05-25 17:34:00 -07004224 dut->sta_nss = sta_nss;
4225
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004226 return 0;
4227}
4228
4229
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304230static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4231 const char *val)
4232{
4233 char buf[60];
4234
4235 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4236 if (system(buf) != 0)
4237 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4238
4239 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4240 if (system(buf) != 0)
4241 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4242}
4243
4244
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304245static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4246 struct sigma_conn *conn,
4247 const char *intf, int capa)
4248{
4249 char buf[32];
4250
4251 if (capa > 0 && capa < 4) {
4252 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4253 if (wpa_command(intf, buf) < 0) {
4254 send_resp(dut, conn, SIGMA_ERROR,
4255 "ErrorCode, Failed to set cellular data capability");
4256 return 0;
4257 }
4258 return 1;
4259 }
4260
4261 sigma_dut_print(dut, DUT_MSG_ERROR,
4262 "Invalid Cellular data capability: %d", capa);
4263 send_resp(dut, conn, SIGMA_INVALID,
4264 "ErrorCode,Invalid cellular data capability");
4265 return 0;
4266}
4267
4268
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304269static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4270 const char *intf, const char *val)
4271{
4272 if (strcasecmp(val, "Disable") == 0) {
4273 if (wpa_command(intf, "SET roaming 0") < 0) {
4274 send_resp(dut, conn, SIGMA_ERROR,
4275 "ErrorCode,Failed to disable roaming");
4276 return 0;
4277 }
4278 return 1;
4279 }
4280
4281 if (strcasecmp(val, "Enable") == 0) {
4282 if (wpa_command(intf, "SET roaming 1") < 0) {
4283 send_resp(dut, conn, SIGMA_ERROR,
4284 "ErrorCode,Failed to enable roaming");
4285 return 0;
4286 }
4287 return 1;
4288 }
4289
4290 sigma_dut_print(dut, DUT_MSG_ERROR,
4291 "Invalid value provided for roaming: %s", val);
4292 send_resp(dut, conn, SIGMA_INVALID,
4293 "ErrorCode,Unknown value provided for Roaming");
4294 return 0;
4295}
4296
4297
Ashwini Patila75de5a2017-04-13 16:35:05 +05304298static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4299 struct sigma_conn *conn,
4300 const char *intf, const char *val)
4301{
4302 if (strcasecmp(val, "Disable") == 0) {
4303 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4304 send_resp(dut, conn, SIGMA_ERROR,
4305 "ErrorCode,Failed to disable Assoc_disallow");
4306 return 0;
4307 }
4308 return 1;
4309 }
4310
4311 if (strcasecmp(val, "Enable") == 0) {
4312 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4313 send_resp(dut, conn, SIGMA_ERROR,
4314 "ErrorCode,Failed to enable Assoc_disallow");
4315 return 0;
4316 }
4317 return 1;
4318 }
4319
4320 sigma_dut_print(dut, DUT_MSG_ERROR,
4321 "Invalid value provided for Assoc_disallow: %s", val);
4322 send_resp(dut, conn, SIGMA_INVALID,
4323 "ErrorCode,Unknown value provided for Assoc_disallow");
4324 return 0;
4325}
4326
4327
Ashwini Patilc63161e2017-04-13 16:30:23 +05304328static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4329 const char *intf, const char *val)
4330{
4331 if (strcasecmp(val, "Reject") == 0) {
4332 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4333 send_resp(dut, conn, SIGMA_ERROR,
4334 "ErrorCode,Failed to Reject BTM Request");
4335 return 0;
4336 }
4337 return 1;
4338 }
4339
4340 if (strcasecmp(val, "Accept") == 0) {
4341 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4342 send_resp(dut, conn, SIGMA_ERROR,
4343 "ErrorCode,Failed to Accept BTM Request");
4344 return 0;
4345 }
4346 return 1;
4347 }
4348
4349 sigma_dut_print(dut, DUT_MSG_ERROR,
4350 "Invalid value provided for BSS_Transition: %s", val);
4351 send_resp(dut, conn, SIGMA_INVALID,
4352 "ErrorCode,Unknown value provided for BSS_Transition");
4353 return 0;
4354}
4355
4356
Ashwini Patil00402582017-04-13 12:29:39 +05304357static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4358 struct sigma_conn *conn,
4359 const char *intf,
4360 struct sigma_cmd *cmd)
4361{
4362 const char *ch, *pref, *op_class, *reason;
4363 char buf[120];
4364 int len, ret;
4365
4366 pref = get_param(cmd, "Ch_Pref");
4367 if (!pref)
4368 return 1;
4369
4370 if (strcasecmp(pref, "clear") == 0) {
4371 free(dut->non_pref_ch_list);
4372 dut->non_pref_ch_list = NULL;
4373 } else {
4374 op_class = get_param(cmd, "Ch_Op_Class");
4375 if (!op_class) {
4376 send_resp(dut, conn, SIGMA_INVALID,
4377 "ErrorCode,Ch_Op_Class not provided");
4378 return 0;
4379 }
4380
4381 ch = get_param(cmd, "Ch_Pref_Num");
4382 if (!ch) {
4383 send_resp(dut, conn, SIGMA_INVALID,
4384 "ErrorCode,Ch_Pref_Num not provided");
4385 return 0;
4386 }
4387
4388 reason = get_param(cmd, "Ch_Reason_Code");
4389 if (!reason) {
4390 send_resp(dut, conn, SIGMA_INVALID,
4391 "ErrorCode,Ch_Reason_Code not provided");
4392 return 0;
4393 }
4394
4395 if (!dut->non_pref_ch_list) {
4396 dut->non_pref_ch_list =
4397 calloc(1, NON_PREF_CH_LIST_SIZE);
4398 if (!dut->non_pref_ch_list) {
4399 send_resp(dut, conn, SIGMA_ERROR,
4400 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4401 return 0;
4402 }
4403 }
4404 len = strlen(dut->non_pref_ch_list);
4405 ret = snprintf(dut->non_pref_ch_list + len,
4406 NON_PREF_CH_LIST_SIZE - len,
4407 " %s:%s:%s:%s", op_class, ch, pref, reason);
4408 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4409 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4410 dut->non_pref_ch_list);
4411 } else {
4412 sigma_dut_print(dut, DUT_MSG_ERROR,
4413 "snprintf failed for non_pref_list, ret = %d",
4414 ret);
4415 send_resp(dut, conn, SIGMA_ERROR,
4416 "ErrorCode,snprintf failed");
4417 free(dut->non_pref_ch_list);
4418 dut->non_pref_ch_list = NULL;
4419 return 0;
4420 }
4421 }
4422
4423 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4424 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4425 if (ret < 0 || ret >= (int) sizeof(buf)) {
4426 sigma_dut_print(dut, DUT_MSG_DEBUG,
4427 "snprintf failed for set non_pref_chan, ret: %d",
4428 ret);
4429 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4430 return 0;
4431 }
4432
4433 if (wpa_command(intf, buf) < 0) {
4434 send_resp(dut, conn, SIGMA_ERROR,
4435 "ErrorCode,Failed to set non-preferred channel list");
4436 return 0;
4437 }
4438
4439 return 1;
4440}
4441
4442
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004443#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004444
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004445static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4446 uint8_t cfg)
4447{
4448 struct nl_msg *msg;
4449 int ret = 0;
4450 struct nlattr *params;
4451 int ifindex;
4452
4453 ifindex = if_nametoindex(intf);
4454 if (ifindex == 0) {
4455 sigma_dut_print(dut, DUT_MSG_ERROR,
4456 "%s: Index for interface %s failed",
4457 __func__, intf);
4458 return -1;
4459 }
4460
4461 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4462 NL80211_CMD_VENDOR)) ||
4463 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4464 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4465 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4466 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4467 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4468 nla_put_u8(msg,
4469 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4470 cfg)) {
4471 sigma_dut_print(dut, DUT_MSG_ERROR,
4472 "%s: err in adding vendor_cmd and vendor_data",
4473 __func__);
4474 nlmsg_free(msg);
4475 return -1;
4476 }
4477 nla_nest_end(msg, params);
4478
4479 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4480 if (ret) {
4481 sigma_dut_print(dut, DUT_MSG_ERROR,
4482 "%s: err in send_and_recv_msgs, ret=%d",
4483 __func__, ret);
4484 }
4485 return ret;
4486}
4487
4488
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004489static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4490 enum he_fragmentation_val frag)
4491{
4492 struct nl_msg *msg;
4493 int ret = 0;
4494 struct nlattr *params;
4495 int ifindex;
4496
4497 ifindex = if_nametoindex(intf);
4498 if (ifindex == 0) {
4499 sigma_dut_print(dut, DUT_MSG_ERROR,
4500 "%s: Index for interface %s failed",
4501 __func__, intf);
4502 return -1;
4503 }
4504
4505 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4506 NL80211_CMD_VENDOR)) ||
4507 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4508 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4509 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4510 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4511 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4512 nla_put_u8(msg,
4513 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4514 frag)) {
4515 sigma_dut_print(dut, DUT_MSG_ERROR,
4516 "%s: err in adding vendor_cmd and vendor_data",
4517 __func__);
4518 nlmsg_free(msg);
4519 return -1;
4520 }
4521 nla_nest_end(msg, params);
4522
4523 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4524 if (ret) {
4525 sigma_dut_print(dut, DUT_MSG_ERROR,
4526 "%s: err in send_and_recv_msgs, ret=%d",
4527 __func__, ret);
4528 }
4529 return ret;
4530}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004531
4532
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004533static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
4534 enum qca_wlan_he_ltf_cfg ltf)
4535{
4536 struct nl_msg *msg;
4537 int ret = 0;
4538 struct nlattr *params;
4539 int ifindex;
4540
4541 ifindex = if_nametoindex(intf);
4542 if (ifindex == 0) {
4543 sigma_dut_print(dut, DUT_MSG_ERROR,
4544 "%s: Index for interface %s failed",
4545 __func__, intf);
4546 return -1;
4547 }
4548
4549 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4550 NL80211_CMD_VENDOR)) ||
4551 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4552 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4553 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4554 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4555 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4556 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4557 ltf)) {
4558 sigma_dut_print(dut, DUT_MSG_ERROR,
4559 "%s: err in adding vendor_cmd and vendor_data",
4560 __func__);
4561 nlmsg_free(msg);
4562 return -1;
4563 }
4564 nla_nest_end(msg, params);
4565
4566 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4567 if (ret) {
4568 sigma_dut_print(dut, DUT_MSG_ERROR,
4569 "%s: err in send_and_recv_msgs, ret=%d",
4570 __func__, ret);
4571 }
4572 return ret;
4573}
4574
4575
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004576static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4577 int noack, enum qca_wlan_ac_type ac)
4578{
4579 struct nl_msg *msg;
4580 int ret = 0;
4581 struct nlattr *params;
4582 int ifindex;
4583
4584 ifindex = if_nametoindex(intf);
4585 if (ifindex == 0) {
4586 sigma_dut_print(dut, DUT_MSG_ERROR,
4587 "%s: Index for interface %s failed",
4588 __func__, intf);
4589 return -1;
4590 }
4591
4592 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4593 NL80211_CMD_VENDOR)) ||
4594 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4595 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4596 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4597 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4598 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4599 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4600 noack) ||
4601 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4602 ac)) {
4603 sigma_dut_print(dut, DUT_MSG_ERROR,
4604 "%s: err in adding vendor_cmd and vendor_data",
4605 __func__);
4606 nlmsg_free(msg);
4607 return -1;
4608 }
4609 nla_nest_end(msg, params);
4610
4611 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4612 if (ret) {
4613 sigma_dut_print(dut, DUT_MSG_ERROR,
4614 "%s: err in send_and_recv_msgs, ret=%d",
4615 __func__, ret);
4616 }
4617 return ret;
4618}
4619
4620
4621static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4622 const char *val)
4623{
4624 int noack, ret;
4625 char token[100];
4626 char *result;
4627 char *saveptr;
4628 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4629
4630 strlcpy(token, val, sizeof(token));
4631 token[sizeof(token) - 1] = '\0';
4632 result = strtok_r(token, ":", &saveptr);
4633 while (result) {
4634 noack = strcasecmp(result, "Disable") != 0;
4635 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4636 if (ret) {
4637 sigma_dut_print(dut, DUT_MSG_ERROR,
4638 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4639 ac, ret);
4640 }
4641 result = strtok_r(NULL, ":", &saveptr);
4642 ac++;
4643 }
4644}
4645
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004646#endif /* NL80211_SUPPORT */
4647
4648
Jouni Malinenf7222712019-06-13 01:50:21 +03004649static enum sigma_cmd_result
4650cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4651 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004652{
4653 const char *intf = get_param(cmd, "Interface");
4654 const char *val;
4655
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004656 val = get_param(cmd, "FT_DS");
4657 if (val) {
4658 if (strcasecmp(val, "Enable") == 0) {
4659 dut->sta_ft_ds = 1;
4660 } else if (strcasecmp(val, "Disable") == 0) {
4661 dut->sta_ft_ds = 0;
4662 } else {
4663 send_resp(dut, conn, SIGMA_ERROR,
4664 "errorCode,Unsupported value for FT_DS");
4665 return STATUS_SENT_ERROR;
4666 }
4667 }
4668
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004669 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004670 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4671 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004672 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4673 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004674
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004675 if (val && strcasecmp(val, "LOC") == 0)
4676 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004677 if (val && strcasecmp(val, "60GHZ") == 0) {
4678 val = get_param(cmd, "WPS");
4679 if (val && strcasecmp(val, "disable") == 0) {
4680 dut->wps_disable = 1;
4681 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4682 } else {
4683 /* wps_disable can have other value from the previous
4684 * test, so make sure it has the correct value.
4685 */
4686 dut->wps_disable = 0;
4687 }
4688
4689 val = get_param(cmd, "P2P");
4690 if (val && strcasecmp(val, "disable") == 0)
4691 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4692 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004693
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004694 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4695 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4696
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004697#ifdef ANDROID_NAN
4698 if (val && strcasecmp(val, "NAN") == 0)
4699 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4700#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004701#ifdef MIRACAST
4702 if (val && (strcasecmp(val, "WFD") == 0 ||
4703 strcasecmp(val, "DisplayR2") == 0))
4704 return miracast_preset_testparameters(dut, conn, cmd);
4705#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004706
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304707 if (val && strcasecmp(val, "MBO") == 0) {
4708 val = get_param(cmd, "Cellular_Data_Cap");
4709 if (val &&
4710 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4711 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304712
4713 val = get_param(cmd, "Ch_Pref");
4714 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4715 return 0;
4716
Ashwini Patilc63161e2017-04-13 16:30:23 +05304717 val = get_param(cmd, "BSS_Transition");
4718 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4719 return 0;
4720
Ashwini Patila75de5a2017-04-13 16:35:05 +05304721 val = get_param(cmd, "Assoc_Disallow");
4722 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4723 return 0;
4724
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304725 val = get_param(cmd, "Roaming");
4726 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4727 return 0;
4728
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304729 return 1;
4730 }
4731
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304732 if (val && strcasecmp(val, "OCE") == 0)
4733 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4734
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004735#if 0
4736 val = get_param(cmd, "Supplicant");
4737 if (val && strcasecmp(val, "Default") != 0) {
4738 send_resp(dut, conn, SIGMA_ERROR,
4739 "ErrorCode,Only default(Vendor) supplicant "
4740 "supported");
4741 return 0;
4742 }
4743#endif
4744
4745 val = get_param(cmd, "RTS");
4746 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004747 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004748 case DRIVER_ATHEROS:
4749 ath_sta_set_rts(dut, intf, val);
4750 break;
4751 default:
4752#if 0
4753 send_resp(dut, conn, SIGMA_ERROR,
4754 "ErrorCode,Setting RTS not supported");
4755 return 0;
4756#else
4757 sigma_dut_print(dut, DUT_MSG_DEBUG,
4758 "Setting RTS not supported");
4759 break;
4760#endif
4761 }
4762 }
4763
4764#if 0
4765 val = get_param(cmd, "FRGMNT");
4766 if (val) {
4767 /* TODO */
4768 send_resp(dut, conn, SIGMA_ERROR,
4769 "ErrorCode,Setting FRGMNT not supported");
4770 return 0;
4771 }
4772#endif
4773
4774#if 0
4775 val = get_param(cmd, "Preamble");
4776 if (val) {
4777 /* TODO: Long/Short */
4778 send_resp(dut, conn, SIGMA_ERROR,
4779 "ErrorCode,Setting Preamble not supported");
4780 return 0;
4781 }
4782#endif
4783
4784 val = get_param(cmd, "Mode");
4785 if (val) {
4786 if (strcmp(val, "11b") == 0 ||
4787 strcmp(val, "11g") == 0 ||
4788 strcmp(val, "11a") == 0 ||
4789 strcmp(val, "11n") == 0 ||
4790 strcmp(val, "11ng") == 0 ||
4791 strcmp(val, "11nl") == 0 ||
4792 strcmp(val, "11nl(nabg)") == 0 ||
4793 strcmp(val, "AC") == 0 ||
4794 strcmp(val, "11AC") == 0 ||
4795 strcmp(val, "11ac") == 0 ||
4796 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004797 strcmp(val, "11an") == 0 ||
4798 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004799 /* STA supports all modes by default */
4800 } else {
4801 send_resp(dut, conn, SIGMA_ERROR,
4802 "ErrorCode,Setting Mode not supported");
4803 return 0;
4804 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004805
4806 /* Change the mode only in case of testbed for HE program
4807 * and for 11a and 11g modes only. */
4808 if (dut->program == PROGRAM_HE &&
4809 dut->device_type == STA_testbed) {
4810 int phymode;
4811 char buf[60];
4812
4813 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004814 phymode = 1; /* IEEE80211_MODE_11A */
4815 } else if (strcmp(val, "11g") == 0) {
4816 phymode = 3; /* IEEE80211_MODE_11G */
4817 } else if (strcmp(val, "11b") == 0) {
4818 phymode = 2; /* IEEE80211_MODE_11B */
4819 } else if (strcmp(val, "11n") == 0 ||
4820 strcmp(val, "11nl") == 0 ||
4821 strcmp(val, "11nl(nabg)") == 0) {
4822 phymode = 22; /* IEEE80211_MODE_11AGN */
4823 } else if (strcmp(val, "11ng") == 0) {
4824 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4825 } else if (strcmp(val, "AC") == 0 ||
4826 strcasecmp(val, "11AC") == 0) {
4827 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4828 } else if (strcmp(val, "11na") == 0 ||
4829 strcasecmp(val, "11an") == 0) {
4830 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4831 } else if (strcmp(val, "11ax") == 0) {
4832 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004833 } else {
4834 sigma_dut_print(dut, DUT_MSG_DEBUG,
4835 "Ignoring mode change for mode: %s",
4836 val);
4837 phymode = -1;
4838 }
4839 if (phymode != -1) {
4840 snprintf(buf, sizeof(buf),
4841 "iwpriv %s setphymode %d",
4842 intf, phymode);
4843 if (system(buf) != 0) {
4844 sigma_dut_print(dut, DUT_MSG_ERROR,
4845 "iwpriv setting of phymode failed");
4846 }
4847 }
4848 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004849 }
4850
4851 val = get_param(cmd, "wmm");
4852 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004853 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004854 case DRIVER_ATHEROS:
4855 ath_sta_set_wmm(dut, intf, val);
4856 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004857 case DRIVER_WCN:
4858 wcn_sta_set_wmm(dut, intf, val);
4859 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004860 default:
4861 sigma_dut_print(dut, DUT_MSG_DEBUG,
4862 "Setting wmm not supported");
4863 break;
4864 }
4865 }
4866
4867 val = get_param(cmd, "Powersave");
4868 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004869 char buf[60];
4870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004871 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004872 if (get_driver_type(dut) == DRIVER_WCN) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004873 snprintf(buf, sizeof(buf),
4874 "iwpriv %s setPower 2", intf);
4875 if (system(buf) != 0) {
4876 sigma_dut_print(dut, DUT_MSG_ERROR,
4877 "iwpriv setPower 2 failed");
4878 return 0;
4879 }
4880 }
4881
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004882 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004883 "P2P_SET ps 0") < 0)
4884 return -2;
4885 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004886 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
4887 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004888 } else if (strcmp(val, "1") == 0 ||
4889 strcasecmp(val, "PSPoll") == 0 ||
4890 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004891 if (get_driver_type(dut) == DRIVER_WCN) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004892 snprintf(buf, sizeof(buf),
4893 "iwpriv %s setPower 1", intf);
4894 if (system(buf) != 0) {
4895 sigma_dut_print(dut, DUT_MSG_ERROR,
4896 "iwpriv setPower 1 failed");
4897 return 0;
4898 }
4899 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004900 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004901 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004902 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004903 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004904 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004905 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004906 "P2P_SET ps 99") < 0)
4907 return -2;
4908 } else if (strcmp(val, "2") == 0 ||
4909 strcasecmp(val, "Fast") == 0) {
4910 /* TODO */
4911 send_resp(dut, conn, SIGMA_ERROR,
4912 "ErrorCode,Powersave=Fast not supported");
4913 return 0;
4914 } else if (strcmp(val, "3") == 0 ||
4915 strcasecmp(val, "PSNonPoll") == 0) {
4916 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004917 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
4918 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004919
4920 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004921 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004922 "P2P_SET ps 1") < 0)
4923 return -2;
4924 } else
4925 return -1;
4926 }
4927
4928 val = get_param(cmd, "NoAck");
4929 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004930 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004931 case DRIVER_ATHEROS:
4932 ath_sta_set_noack(dut, intf, val);
4933 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004934#ifdef NL80211_SUPPORT
4935 case DRIVER_WCN:
4936 wcn_sta_set_noack(dut, intf, val);
4937 break;
4938#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004939 default:
4940 send_resp(dut, conn, SIGMA_ERROR,
4941 "ErrorCode,Setting NoAck not supported");
4942 return 0;
4943 }
4944 }
4945
4946 val = get_param(cmd, "IgnoreChswitchProhibit");
4947 if (val) {
4948 /* TODO: Enabled/disabled */
4949 if (strcasecmp(val, "Enabled") == 0) {
4950 send_resp(dut, conn, SIGMA_ERROR,
4951 "ErrorCode,Enabling IgnoreChswitchProhibit "
4952 "not supported");
4953 return 0;
4954 }
4955 }
4956
4957 val = get_param(cmd, "TDLS");
4958 if (val) {
4959 if (strcasecmp(val, "Disabled") == 0) {
4960 if (wpa_command(intf, "SET tdls_disabled 1")) {
4961 send_resp(dut, conn, SIGMA_ERROR,
4962 "ErrorCode,Failed to disable TDLS");
4963 return 0;
4964 }
4965 } else if (strcasecmp(val, "Enabled") == 0) {
4966 if (wpa_command(intf, "SET tdls_disabled 0")) {
4967 send_resp(dut, conn, SIGMA_ERROR,
4968 "ErrorCode,Failed to enable TDLS");
4969 return 0;
4970 }
4971 } else {
4972 send_resp(dut, conn, SIGMA_ERROR,
4973 "ErrorCode,Unsupported TDLS value");
4974 return 0;
4975 }
4976 }
4977
4978 val = get_param(cmd, "TDLSmode");
4979 if (val) {
4980 if (strcasecmp(val, "Default") == 0) {
4981 wpa_command(intf, "SET tdls_testing 0");
4982 } else if (strcasecmp(val, "APProhibit") == 0) {
4983 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4984 send_resp(dut, conn, SIGMA_ERROR,
4985 "ErrorCode,Failed to enable ignore "
4986 "APProhibit TDLS mode");
4987 return 0;
4988 }
4989 } else if (strcasecmp(val, "HiLoMac") == 0) {
4990 /* STA should respond with TDLS setup req for a TDLS
4991 * setup req */
4992 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4993 send_resp(dut, conn, SIGMA_ERROR,
4994 "ErrorCode,Failed to enable HiLoMac "
4995 "TDLS mode");
4996 return 0;
4997 }
4998 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4999 /*
5000 * Since all security modes are enabled by default when
5001 * Sigma control is used, there is no need to do
5002 * anything here.
5003 */
5004 } else if (strcasecmp(val, "ExistLink") == 0) {
5005 /*
5006 * Since we allow new TDLS Setup Request even if there
5007 * is an existing link, nothing needs to be done for
5008 * this.
5009 */
5010 } else {
5011 /* TODO:
5012 * ExistLink: STA should send TDLS setup req even if
5013 * direct link already exists
5014 */
5015 send_resp(dut, conn, SIGMA_ERROR,
5016 "ErrorCode,Unsupported TDLSmode value");
5017 return 0;
5018 }
5019 }
5020
5021 val = get_param(cmd, "FakePubKey");
5022 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5023 send_resp(dut, conn, SIGMA_ERROR,
5024 "ErrorCode,Failed to enable FakePubKey");
5025 return 0;
5026 }
5027
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005028#ifdef NL80211_SUPPORT
5029 val = get_param(cmd, "FrgmntSupport");
5030 if (val) {
5031 if (strcasecmp(val, "Enable") == 0) {
5032 if (sta_set_he_fragmentation(dut, intf,
5033 HE_FRAG_LEVEL1)) {
5034 send_resp(dut, conn, SIGMA_ERROR,
5035 "ErrorCode,Failed to enable HE Fragmentation");
5036 return 0;
5037 }
5038 } else if (strcasecmp(val, "Disable") == 0) {
5039 if (sta_set_he_fragmentation(dut, intf,
5040 HE_FRAG_DISABLE)) {
5041 send_resp(dut, conn, SIGMA_ERROR,
5042 "ErrorCode,Failed to disable HE Fragmentation");
5043 return 0;
5044 }
5045 }
5046 }
5047#endif /* NL80211_SUPPORT */
5048
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005049 return 1;
5050}
5051
5052
5053static const char * ath_get_radio_name(const char *radio_name)
5054{
5055 if (radio_name == NULL)
5056 return "wifi0";
5057 if (strcmp(radio_name, "wifi1") == 0)
5058 return "wifi1";
5059 if (strcmp(radio_name, "wifi2") == 0)
5060 return "wifi2";
5061 return "wifi0";
5062}
5063
5064
5065static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5066 const char *val)
5067{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005068 unsigned int vht_mcsmap = 0;
5069 int txchainmask = 0;
5070 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5071
5072 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5073 if (dut->testbed_flag_txsp == 1) {
5074 vht_mcsmap = 0xfffc;
5075 dut->testbed_flag_txsp = 0;
5076 } else {
5077 vht_mcsmap = 0xfffe;
5078 }
5079 txchainmask = 1;
5080 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5081 if (dut->testbed_flag_txsp == 1) {
5082 vht_mcsmap = 0xfff0;
5083 dut->testbed_flag_txsp = 0;
5084 } else {
5085 vht_mcsmap = 0xfffa;
5086 }
5087 txchainmask = 3;
5088 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5089 if (dut->testbed_flag_txsp == 1) {
5090 vht_mcsmap = 0xffc0;
5091 dut->testbed_flag_txsp = 0;
5092 } else {
5093 vht_mcsmap = 0xffea;
5094 }
5095 txchainmask = 7;
5096 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5097 if (dut->testbed_flag_txsp == 1) {
5098 vht_mcsmap = 0xff00;
5099 dut->testbed_flag_txsp = 0;
5100 } else {
5101 vht_mcsmap = 0xffaa;
5102 }
5103 txchainmask = 15;
5104 } else {
5105 if (dut->testbed_flag_txsp == 1) {
5106 vht_mcsmap = 0xffc0;
5107 dut->testbed_flag_txsp = 0;
5108 } else {
5109 vht_mcsmap = 0xffea;
5110 }
5111 }
5112
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005113 if (txchainmask)
5114 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005115
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005116 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005117}
5118
5119
5120static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5121 const char *val)
5122{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005123 unsigned int vht_mcsmap = 0;
5124 int rxchainmask = 0;
5125 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5126
5127 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5128 if (dut->testbed_flag_rxsp == 1) {
5129 vht_mcsmap = 0xfffc;
5130 dut->testbed_flag_rxsp = 0;
5131 } else {
5132 vht_mcsmap = 0xfffe;
5133 }
5134 rxchainmask = 1;
5135 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5136 if (dut->testbed_flag_rxsp == 1) {
5137 vht_mcsmap = 0xfff0;
5138 dut->testbed_flag_rxsp = 0;
5139 } else {
5140 vht_mcsmap = 0xfffa;
5141 }
5142 rxchainmask = 3;
5143 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5144 if (dut->testbed_flag_rxsp == 1) {
5145 vht_mcsmap = 0xffc0;
5146 dut->testbed_flag_rxsp = 0;
5147 } else {
5148 vht_mcsmap = 0xffea;
5149 }
5150 rxchainmask = 7;
5151 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5152 if (dut->testbed_flag_rxsp == 1) {
5153 vht_mcsmap = 0xff00;
5154 dut->testbed_flag_rxsp = 0;
5155 } else {
5156 vht_mcsmap = 0xffaa;
5157 }
5158 rxchainmask = 15;
5159 } else {
5160 if (dut->testbed_flag_rxsp == 1) {
5161 vht_mcsmap = 0xffc0;
5162 dut->testbed_flag_rxsp = 0;
5163 } else {
5164 vht_mcsmap = 0xffea;
5165 }
5166 }
5167
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005168 if (rxchainmask)
5169 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005170
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005171 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005172}
5173
5174
5175void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5176{
5177 if (strcasecmp(val, "enable") == 0) {
5178 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5179 != 0) {
5180 sigma_dut_print(dut, DUT_MSG_ERROR,
5181 "Disable BB_VHTSIGB_CRC_CALC failed");
5182 }
5183
5184 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5185 != 0) {
5186 sigma_dut_print(dut, DUT_MSG_ERROR,
5187 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5188 }
5189 } else {
5190 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5191 != 0) {
5192 sigma_dut_print(dut, DUT_MSG_ERROR,
5193 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5194 }
5195
5196 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5197 != 0) {
5198 sigma_dut_print(dut, DUT_MSG_ERROR,
5199 "Enable BB_VHTSIGB_CRC_CALC failed");
5200 }
5201 }
5202}
5203
5204
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005205static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5206 const char *val)
5207{
5208 char buf[60];
5209
5210 if (strcmp(val, "20") == 0) {
5211 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5212 dut->chwidth = 0;
5213 } else if (strcmp(val, "40") == 0) {
5214 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5215 dut->chwidth = 1;
5216 } else if (strcmp(val, "80") == 0) {
5217 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5218 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305219 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005220 buf[0] = '\0';
5221 } else {
5222 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5223 val);
5224 return -1;
5225 }
5226
5227 if (buf[0] != '\0' && system(buf) != 0) {
5228 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5229 return -1;
5230 }
5231
5232 return 0;
5233}
5234
5235
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005236static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5237 const char *intf, int addbareject)
5238{
5239#ifdef NL80211_SUPPORT
5240 struct nl_msg *msg;
5241 int ret = 0;
5242 struct nlattr *params;
5243 int ifindex;
5244
5245 ifindex = if_nametoindex(intf);
5246 if (ifindex == 0) {
5247 sigma_dut_print(dut, DUT_MSG_ERROR,
5248 "%s: Index for interface %s failed",
5249 __func__, intf);
5250 return -1;
5251 }
5252
5253 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5254 NL80211_CMD_VENDOR)) ||
5255 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5256 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5257 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5258 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5259 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5260 nla_put_u8(msg,
5261 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5262 !addbareject)) {
5263 sigma_dut_print(dut, DUT_MSG_ERROR,
5264 "%s: err in adding vendor_cmd and vendor_data",
5265 __func__);
5266 nlmsg_free(msg);
5267 return -1;
5268 }
5269 nla_nest_end(msg, params);
5270
5271 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5272 if (ret) {
5273 sigma_dut_print(dut, DUT_MSG_ERROR,
5274 "%s: err in send_and_recv_msgs, ret=%d",
5275 __func__, ret);
5276 }
5277 return ret;
5278#else /* NL80211_SUPPORT */
5279 sigma_dut_print(dut, DUT_MSG_ERROR,
5280 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5281 return -1;
5282#endif /* NL80211_SUPPORT */
5283}
5284
5285
5286static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5287 int addbareject)
5288{
5289 int ret;
5290
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005291 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005292 case DRIVER_WCN:
5293 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5294 if (ret) {
5295 sigma_dut_print(dut, DUT_MSG_ERROR,
5296 "nlvendor_sta_set_addba_reject failed, ret:%d",
5297 ret);
5298 return ret;
5299 }
5300 break;
5301 default:
5302 sigma_dut_print(dut, DUT_MSG_ERROR,
5303 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5304 ret = -1;
5305 break;
5306 }
5307
5308 return ret;
5309}
5310
5311
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005312static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5313 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005314{
5315#ifdef NL80211_SUPPORT
5316 struct nl_msg *msg;
5317 int ret = 0;
5318 struct nlattr *params;
5319 int ifindex;
5320
5321 ifindex = if_nametoindex(intf);
5322 if (ifindex == 0) {
5323 sigma_dut_print(dut, DUT_MSG_ERROR,
5324 "%s: Index for interface %s failed",
5325 __func__, intf);
5326 return -1;
5327 }
5328
5329 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5330 NL80211_CMD_VENDOR)) ||
5331 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5332 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5333 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5334 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5335 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5336 nla_put_u8(msg,
5337 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005338 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005339 sigma_dut_print(dut, DUT_MSG_ERROR,
5340 "%s: err in adding vendor_cmd and vendor_data",
5341 __func__);
5342 nlmsg_free(msg);
5343 return -1;
5344 }
5345 nla_nest_end(msg, params);
5346
5347 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5348 if (ret) {
5349 sigma_dut_print(dut, DUT_MSG_ERROR,
5350 "%s: err in send_and_recv_msgs, ret=%d",
5351 __func__, ret);
5352 }
5353 return ret;
5354#else /* NL80211_SUPPORT */
5355 sigma_dut_print(dut, DUT_MSG_ERROR,
5356 "Disable addba not possible without NL80211_SUPPORT defined");
5357 return -1;
5358#endif /* NL80211_SUPPORT */
5359}
5360
5361
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305362#ifdef NL80211_SUPPORT
5363static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5364{
5365 struct nl_msg *msg;
5366 int ret = 0;
5367 int ifindex;
5368
5369 ifindex = if_nametoindex(intf);
5370 if (ifindex == 0) {
5371 sigma_dut_print(dut, DUT_MSG_ERROR,
5372 "%s: Index for interface %s failed",
5373 __func__, intf);
5374 return -1;
5375 }
5376
5377 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5378 NL80211_CMD_SET_WIPHY)) ||
5379 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5380 sigma_dut_print(dut, DUT_MSG_ERROR,
5381 "%s: err in adding RTS threshold",
5382 __func__);
5383 nlmsg_free(msg);
5384 return -1;
5385 }
5386
5387 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5388 if (ret) {
5389 sigma_dut_print(dut, DUT_MSG_ERROR,
5390 "%s: err in send_and_recv_msgs, ret=%d",
5391 __func__, ret);
5392 }
5393 return ret;
5394}
5395#endif /* NL80211_SUPPORT */
5396
5397
5398static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5399{
5400 char buf[100];
5401
5402#ifdef NL80211_SUPPORT
5403 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5404 return 0;
5405 sigma_dut_print(dut, DUT_MSG_DEBUG,
5406 "Fall back to using iwconfig for setting RTS threshold");
5407#endif /* NL80211_SUPPORT */
5408
5409 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5410 if (system(buf) != 0) {
5411 sigma_dut_print(dut, DUT_MSG_ERROR,
5412 "Failed to set RTS threshold %d", val);
5413 return -1;
5414 }
5415 return 0;
5416}
5417
5418
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005419static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5420 struct sigma_conn *conn,
5421 struct sigma_cmd *cmd)
5422{
5423 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005424 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005425 char buf[128];
5426 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005427
5428 val = get_param(cmd, "40_INTOLERANT");
5429 if (val) {
5430 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5431 /* TODO: iwpriv ht40intol through wpa_supplicant */
5432 send_resp(dut, conn, SIGMA_ERROR,
5433 "ErrorCode,40_INTOLERANT not supported");
5434 return 0;
5435 }
5436 }
5437
5438 val = get_param(cmd, "ADDBA_REJECT");
5439 if (val) {
5440 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5441 /* reject any ADDBA with status "decline" */
5442 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005443 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005444 } else {
5445 /* accept ADDBA */
5446 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005447 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005448 }
5449 }
5450
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005451 if (addbareject >= 0 &&
5452 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5453 send_resp(dut, conn, SIGMA_ERROR,
5454 "ErrorCode,set addba_reject failed");
5455 return 0;
5456 }
5457
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005458 val = get_param(cmd, "AMPDU");
5459 if (val) {
5460 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5461 /* enable AMPDU Aggregation */
5462 if (ampdu == 0) {
5463 send_resp(dut, conn, SIGMA_ERROR,
5464 "ErrorCode,Mismatch in "
5465 "addba_reject/ampdu - "
5466 "not supported");
5467 return 0;
5468 }
5469 ampdu = 1;
5470 } else {
5471 /* disable AMPDU Aggregation */
5472 if (ampdu == 1) {
5473 send_resp(dut, conn, SIGMA_ERROR,
5474 "ErrorCode,Mismatch in "
5475 "addba_reject/ampdu - "
5476 "not supported");
5477 return 0;
5478 }
5479 ampdu = 0;
5480 }
5481 }
5482
5483 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005484 int ret;
5485
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005486 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5487 ampdu ? "Enabling" : "Disabling");
5488 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005489 if (wpa_command(intf, buf) < 0 &&
5490 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005491 send_resp(dut, conn, SIGMA_ERROR,
5492 "ErrorCode,set aggr failed");
5493 return 0;
5494 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005495
5496 if (ampdu == 0) {
5497 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005498 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005499 if (ret) {
5500 sigma_dut_print(dut, DUT_MSG_ERROR,
5501 "Failed to disable addba, ret:%d",
5502 ret);
5503 }
5504 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005505 }
5506
5507 val = get_param(cmd, "AMSDU");
5508 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005509 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005510 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005511 case DRIVER_WCN:
5512 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005513 break;
5514 default:
5515 if (strcmp(val, "1") == 0 ||
5516 strcasecmp(val, "Enable") == 0) {
5517 /* Enable AMSDU Aggregation */
5518 send_resp(dut, conn, SIGMA_ERROR,
5519 "ErrorCode,AMSDU aggregation not supported");
5520 return 0;
5521 }
5522 break;
5523 }
5524 }
5525
5526 val = get_param(cmd, "STBC_RX");
5527 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005528 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005529 case DRIVER_ATHEROS:
5530 ath_sta_set_stbc(dut, intf, val);
5531 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305532 case DRIVER_WCN:
5533 wcn_sta_set_stbc(dut, intf, val);
5534 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005535 default:
5536 send_resp(dut, conn, SIGMA_ERROR,
5537 "ErrorCode,STBC_RX not supported");
5538 return 0;
5539 }
5540 }
5541
5542 val = get_param(cmd, "WIDTH");
5543 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005544 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005545 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005546 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005547 send_resp(dut, conn, SIGMA_ERROR,
5548 "ErrorCode,Failed to set WIDTH");
5549 return 0;
5550 }
5551 break;
5552 case DRIVER_ATHEROS:
5553 if (ath_set_width(dut, conn, intf, val) < 0)
5554 return 0;
5555 break;
5556 default:
5557 sigma_dut_print(dut, DUT_MSG_ERROR,
5558 "Setting WIDTH not supported");
5559 break;
5560 }
5561 }
5562
5563 val = get_param(cmd, "SMPS");
5564 if (val) {
5565 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5566 send_resp(dut, conn, SIGMA_ERROR,
5567 "ErrorCode,SMPS not supported");
5568 return 0;
5569 }
5570
5571 val = get_param(cmd, "TXSP_STREAM");
5572 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005573 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005574 case DRIVER_WCN:
5575 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5576 send_resp(dut, conn, SIGMA_ERROR,
5577 "ErrorCode,Failed to set TXSP_STREAM");
5578 return 0;
5579 }
5580 break;
5581 case DRIVER_ATHEROS:
5582 ath_sta_set_txsp_stream(dut, intf, val);
5583 break;
5584 default:
5585 sigma_dut_print(dut, DUT_MSG_ERROR,
5586 "Setting TXSP_STREAM not supported");
5587 break;
5588 }
5589 }
5590
5591 val = get_param(cmd, "RXSP_STREAM");
5592 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005593 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005594 case DRIVER_WCN:
5595 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5596 send_resp(dut, conn, SIGMA_ERROR,
5597 "ErrorCode,Failed to set RXSP_STREAM");
5598 return 0;
5599 }
5600 break;
5601 case DRIVER_ATHEROS:
5602 ath_sta_set_rxsp_stream(dut, intf, val);
5603 break;
5604 default:
5605 sigma_dut_print(dut, DUT_MSG_ERROR,
5606 "Setting RXSP_STREAM not supported");
5607 break;
5608 }
5609 }
5610
5611 val = get_param(cmd, "DYN_BW_SGNL");
5612 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005613 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005614 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005615 if (strcasecmp(val, "enable") == 0) {
5616 snprintf(buf, sizeof(buf),
5617 "iwpriv %s cwmenable 1", intf);
5618 if (system(buf) != 0) {
5619 sigma_dut_print(dut, DUT_MSG_ERROR,
5620 "iwpriv cwmenable 1 failed");
5621 return 0;
5622 }
5623 } else if (strcasecmp(val, "disable") == 0) {
5624 snprintf(buf, sizeof(buf),
5625 "iwpriv %s cwmenable 0", intf);
5626 if (system(buf) != 0) {
5627 sigma_dut_print(dut, DUT_MSG_ERROR,
5628 "iwpriv cwmenable 0 failed");
5629 return 0;
5630 }
5631 } else {
5632 sigma_dut_print(dut, DUT_MSG_ERROR,
5633 "Unsupported DYN_BW_SGL");
5634 }
5635
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5637 if (system(buf) != 0) {
5638 sigma_dut_print(dut, DUT_MSG_ERROR,
5639 "Failed to set cts_cbw in DYN_BW_SGNL");
5640 return 0;
5641 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005642 break;
5643 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005644 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005645 ath_config_dyn_bw_sig(dut, intf, val);
5646 break;
5647 default:
5648 sigma_dut_print(dut, DUT_MSG_ERROR,
5649 "Failed to set DYN_BW_SGNL");
5650 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005651 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005652 }
5653
5654 val = get_param(cmd, "RTS_FORCE");
5655 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005656 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005657 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305658 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005659 sigma_dut_print(dut, DUT_MSG_ERROR,
5660 "Failed to set RTS_FORCE 64");
5661 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005662 res = snprintf(buf, sizeof(buf),
5663 "wifitool %s beeliner_fw_test 100 1",
5664 intf);
5665 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005666 sigma_dut_print(dut, DUT_MSG_ERROR,
5667 "wifitool beeliner_fw_test 100 1 failed");
5668 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005669 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305670 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005671 sigma_dut_print(dut, DUT_MSG_ERROR,
5672 "Failed to set RTS_FORCE 2347");
5673 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005674 } else {
5675 send_resp(dut, conn, SIGMA_ERROR,
5676 "ErrorCode,RTS_FORCE value not supported");
5677 return 0;
5678 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005679 }
5680
5681 val = get_param(cmd, "CTS_WIDTH");
5682 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005683 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005684 case DRIVER_WCN:
5685 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5686 send_resp(dut, conn, SIGMA_ERROR,
5687 "ErrorCode,Failed to set CTS_WIDTH");
5688 return 0;
5689 }
5690 break;
5691 case DRIVER_ATHEROS:
5692 ath_set_cts_width(dut, intf, val);
5693 break;
5694 default:
5695 sigma_dut_print(dut, DUT_MSG_ERROR,
5696 "Setting CTS_WIDTH not supported");
5697 break;
5698 }
5699 }
5700
5701 val = get_param(cmd, "BW_SGNL");
5702 if (val) {
5703 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005704 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005705 } else if (strcasecmp(val, "Disable") == 0) {
5706 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005707 } else {
5708 send_resp(dut, conn, SIGMA_ERROR,
5709 "ErrorCode,BW_SGNL value not supported");
5710 return 0;
5711 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005712 }
5713
5714 val = get_param(cmd, "Band");
5715 if (val) {
5716 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5717 /* STA supports all bands by default */
5718 } else {
5719 send_resp(dut, conn, SIGMA_ERROR,
5720 "ErrorCode,Unsupported Band");
5721 return 0;
5722 }
5723 }
5724
5725 val = get_param(cmd, "zero_crc");
5726 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005727 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005728 case DRIVER_ATHEROS:
5729 ath_set_zero_crc(dut, val);
5730 break;
5731 default:
5732 break;
5733 }
5734 }
5735
5736 return 1;
5737}
5738
5739
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005740static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5741{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005742 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005743#ifdef __linux__
5744 case DRIVER_WIL6210:
5745 return wil6210_set_force_mcs(dut, force, mcs);
5746#endif /* __linux__ */
5747 default:
5748 sigma_dut_print(dut, DUT_MSG_ERROR,
5749 "Unsupported sta_set_force_mcs with the current driver");
5750 return -1;
5751 }
5752}
5753
5754
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005755static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5756{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005757 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005758#ifdef __linux__
5759 case DRIVER_WIL6210:
5760 return wil6210_force_rsn_ie(dut, state);
5761#endif /* __linux__ */
5762 default:
5763 sigma_dut_print(dut, DUT_MSG_ERROR,
5764 "Unsupported sta_60g_force_rsn_ie with the current driver");
5765 return -1;
5766 }
5767}
5768
5769
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005770static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5771 struct sigma_cmd *cmd)
5772{
5773 const char *val;
5774 char buf[100];
5775
5776 val = get_param(cmd, "MSDUSize");
5777 if (val) {
5778 int mtu;
5779
5780 dut->amsdu_size = atoi(val);
5781 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5782 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5783 sigma_dut_print(dut, DUT_MSG_ERROR,
5784 "MSDUSize %d is above max %d or below min %d",
5785 dut->amsdu_size,
5786 IEEE80211_MAX_DATA_LEN_DMG,
5787 IEEE80211_SNAP_LEN_DMG);
5788 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005789 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005790 }
5791
5792 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5793 sigma_dut_print(dut, DUT_MSG_DEBUG,
5794 "Setting amsdu_size to %d", mtu);
5795 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005796 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005797
5798 if (system(buf) != 0) {
5799 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5800 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005801 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005802 }
5803 }
5804
5805 val = get_param(cmd, "BAckRcvBuf");
5806 if (val) {
5807 dut->back_rcv_buf = atoi(val);
5808 if (dut->back_rcv_buf == 0) {
5809 sigma_dut_print(dut, DUT_MSG_ERROR,
5810 "Failed to convert %s or value is 0",
5811 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005812 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005813 }
5814
5815 sigma_dut_print(dut, DUT_MSG_DEBUG,
5816 "Setting BAckRcvBuf to %s", val);
5817 }
5818
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005819 val = get_param(cmd, "MCS_FixedRate");
5820 if (val) {
5821 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5822 sigma_dut_print(dut, DUT_MSG_ERROR,
5823 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005824 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005825 }
5826 }
5827
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005828 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005829}
5830
5831
5832static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5833 struct sigma_cmd *cmd)
5834{
5835 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005836 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005837 const char *val;
5838 char buf[100];
5839
5840 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005841 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005842 if (wpa_command(ifname, "PING") != 0) {
5843 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005844 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005845 }
5846
5847 wpa_command(ifname, "FLUSH");
5848 net_id = add_network_common(dut, conn, ifname, cmd);
5849 if (net_id < 0) {
5850 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5851 return net_id;
5852 }
5853
5854 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5855 if (set_network(ifname, net_id, "mode", "2") < 0) {
5856 sigma_dut_print(dut, DUT_MSG_ERROR,
5857 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005858 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005859 }
5860
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005861 if (set_network(ifname, net_id, "pbss", "1") < 0)
5862 return -2;
5863
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005864 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005865 "Supplicant set network with mode 2. network_id %d",
5866 net_id);
5867
5868 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5869 sigma_dut_print(dut, DUT_MSG_INFO,
5870 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005871 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005872 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005873
5874 val = get_param(cmd, "Security");
5875 if (val && strcasecmp(val, "OPEN") == 0) {
5876 dut->ap_key_mgmt = AP_OPEN;
5877 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5878 sigma_dut_print(dut, DUT_MSG_ERROR,
5879 "Failed to set supplicant to %s security",
5880 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005881 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005882 }
5883 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5884 dut->ap_key_mgmt = AP_WPA2_PSK;
5885 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5886 sigma_dut_print(dut, DUT_MSG_ERROR,
5887 "Failed to set supplicant to %s security",
5888 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005889 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005890 }
5891
5892 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5893 sigma_dut_print(dut, DUT_MSG_ERROR,
5894 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005895 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005896 }
5897 } else if (val) {
5898 sigma_dut_print(dut, DUT_MSG_ERROR,
5899 "Requested Security %s is not supported on 60GHz",
5900 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005901 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005902 }
5903
5904 val = get_param(cmd, "Encrypt");
5905 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5906 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5907 sigma_dut_print(dut, DUT_MSG_ERROR,
5908 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005909 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910 }
5911 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5912 sigma_dut_print(dut, DUT_MSG_ERROR,
5913 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005914 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005915 }
5916 } else if (val) {
5917 sigma_dut_print(dut, DUT_MSG_ERROR,
5918 "Requested Encrypt %s is not supported on 60 GHz",
5919 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005920 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005921 }
5922
5923 val = get_param(cmd, "PSK");
5924 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5925 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5926 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005927 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005928 }
5929
5930 /* Convert 60G channel to freq */
5931 switch (dut->ap_channel) {
5932 case 1:
5933 val = "58320";
5934 break;
5935 case 2:
5936 val = "60480";
5937 break;
5938 case 3:
5939 val = "62640";
5940 break;
5941 default:
5942 sigma_dut_print(dut, DUT_MSG_ERROR,
5943 "Failed to configure channel %d. Not supported",
5944 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005945 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005946 }
5947
5948 if (set_network(ifname, net_id, "frequency", val) < 0) {
5949 sigma_dut_print(dut, DUT_MSG_ERROR,
5950 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005951 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005952 }
5953
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005954 if (dut->eap_fragment) {
5955 sigma_dut_print(dut, DUT_MSG_DEBUG,
5956 "Set EAP fragment size to 128 bytes.");
5957 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
5958 return ERROR_SEND_STATUS;
5959 }
5960
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005961 sigma_dut_print(dut, DUT_MSG_DEBUG,
5962 "Supplicant set network with frequency");
5963
5964 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5965 if (wpa_command(ifname, buf) < 0) {
5966 sigma_dut_print(dut, DUT_MSG_INFO,
5967 "Failed to select network id %d on %s",
5968 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005969 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005970 }
5971
5972 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5973
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005974 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005975}
5976
5977
Lior David67543f52017-01-03 19:04:22 +02005978static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5979{
5980 char buf[128], fname[128];
5981 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005982 int res;
Lior David67543f52017-01-03 19:04:22 +02005983
5984 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5985 sigma_dut_print(dut, DUT_MSG_ERROR,
5986 "failed to get wil6210 debugfs dir");
5987 return -1;
5988 }
5989
Jouni Malinen3aa72862019-05-29 23:14:51 +03005990 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5991 if (res < 0 || res >= sizeof(fname))
5992 return -1;
Lior David67543f52017-01-03 19:04:22 +02005993 f = fopen(fname, "w");
5994 if (!f) {
5995 sigma_dut_print(dut, DUT_MSG_ERROR,
5996 "failed to open: %s", fname);
5997 return -1;
5998 }
5999
6000 fprintf(f, "%d\n", abft_len);
6001 fclose(f);
6002
6003 return 0;
6004}
6005
6006
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006007int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6008 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006009{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006010 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006011 case DRIVER_WIL6210:
6012 return wil6210_set_abft_len(dut, abft_len);
6013 default:
6014 sigma_dut_print(dut, DUT_MSG_ERROR,
6015 "set abft_len not supported");
6016 return -1;
6017 }
6018}
6019
6020
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006021static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6022 struct sigma_cmd *cmd)
6023{
6024 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006025 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006026
6027 if (dut->dev_role != DEVROLE_PCP) {
6028 send_resp(dut, conn, SIGMA_INVALID,
6029 "ErrorCode,Invalid DevRole");
6030 return 0;
6031 }
6032
6033 val = get_param(cmd, "SSID");
6034 if (val) {
6035 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6036 send_resp(dut, conn, SIGMA_INVALID,
6037 "ErrorCode,Invalid SSID");
6038 return -1;
6039 }
6040
Peng Xub8fc5cc2017-05-10 17:27:28 -07006041 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006042 }
6043
6044 val = get_param(cmd, "CHANNEL");
6045 if (val) {
6046 const char *pos;
6047
6048 dut->ap_channel = atoi(val);
6049 pos = strchr(val, ';');
6050 if (pos) {
6051 pos++;
6052 dut->ap_channel_1 = atoi(pos);
6053 }
6054 }
6055
6056 switch (dut->ap_channel) {
6057 case 1:
6058 case 2:
6059 case 3:
6060 break;
6061 default:
6062 sigma_dut_print(dut, DUT_MSG_ERROR,
6063 "Channel %d is not supported", dut->ap_channel);
6064 send_resp(dut, conn, SIGMA_ERROR,
6065 "Requested channel is not supported");
6066 return -1;
6067 }
6068
6069 val = get_param(cmd, "BCNINT");
6070 if (val)
6071 dut->ap_bcnint = atoi(val);
6072
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006073 val = get_param(cmd, "AllocType");
6074 if (val) {
6075 send_resp(dut, conn, SIGMA_ERROR,
6076 "ErrorCode,AllocType is not supported yet");
6077 return -1;
6078 }
6079
6080 val = get_param(cmd, "PercentBI");
6081 if (val) {
6082 send_resp(dut, conn, SIGMA_ERROR,
6083 "ErrorCode,PercentBI is not supported yet");
6084 return -1;
6085 }
6086
6087 val = get_param(cmd, "CBAPOnly");
6088 if (val) {
6089 send_resp(dut, conn, SIGMA_ERROR,
6090 "ErrorCode,CBAPOnly is not supported yet");
6091 return -1;
6092 }
6093
6094 val = get_param(cmd, "AMPDU");
6095 if (val) {
6096 if (strcasecmp(val, "Enable") == 0)
6097 dut->ap_ampdu = 1;
6098 else if (strcasecmp(val, "Disable") == 0)
6099 dut->ap_ampdu = 2;
6100 else {
6101 send_resp(dut, conn, SIGMA_ERROR,
6102 "ErrorCode,AMPDU value is not Enable nor Disabled");
6103 return -1;
6104 }
6105 }
6106
6107 val = get_param(cmd, "AMSDU");
6108 if (val) {
6109 if (strcasecmp(val, "Enable") == 0)
6110 dut->ap_amsdu = 1;
6111 else if (strcasecmp(val, "Disable") == 0)
6112 dut->ap_amsdu = 2;
6113 }
6114
6115 val = get_param(cmd, "NumMSDU");
6116 if (val) {
6117 send_resp(dut, conn, SIGMA_ERROR,
6118 "ErrorCode, NumMSDU is not supported yet");
6119 return -1;
6120 }
6121
6122 val = get_param(cmd, "ABFTLRang");
6123 if (val) {
6124 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006125 "ABFTLRang parameter %s", val);
6126 if (strcmp(val, "Gt1") == 0)
6127 abft_len = 2; /* 2 slots in this case */
6128 }
6129
6130 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6131 send_resp(dut, conn, SIGMA_ERROR,
6132 "ErrorCode, Can't set ABFT length");
6133 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006134 }
6135
6136 if (sta_pcp_start(dut, conn, cmd) < 0) {
6137 send_resp(dut, conn, SIGMA_ERROR,
6138 "ErrorCode, Can't start PCP role");
6139 return -1;
6140 }
6141
6142 return sta_set_60g_common(dut, conn, cmd);
6143}
6144
6145
6146static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6147 struct sigma_cmd *cmd)
6148{
6149 const char *val = get_param(cmd, "DiscoveryMode");
6150
6151 if (dut->dev_role != DEVROLE_STA) {
6152 send_resp(dut, conn, SIGMA_INVALID,
6153 "ErrorCode,Invalid DevRole");
6154 return 0;
6155 }
6156
6157 if (val) {
6158 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6159 /* Ignore Discovery mode till Driver expose API. */
6160#if 0
6161 if (strcasecmp(val, "1") == 0) {
6162 send_resp(dut, conn, SIGMA_INVALID,
6163 "ErrorCode,DiscoveryMode 1 not supported");
6164 return 0;
6165 }
6166
6167 if (strcasecmp(val, "0") == 0) {
6168 /* OK */
6169 } else {
6170 send_resp(dut, conn, SIGMA_INVALID,
6171 "ErrorCode,DiscoveryMode not supported");
6172 return 0;
6173 }
6174#endif
6175 }
6176
6177 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006178 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006179 return sta_set_60g_common(dut, conn, cmd);
6180}
6181
6182
Jouni Malinenf7222712019-06-13 01:50:21 +03006183static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6184 struct sigma_conn *conn,
6185 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006186{
6187 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006188 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306189
Jouni Malinened77e672018-01-10 16:45:13 +02006190 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006191 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006192 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306193 wpa_command(intf, "DISCONNECT");
6194 return 1;
6195 }
6196
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006197 disconnect_station(dut);
6198 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6199 * due to cached results. */
6200 wpa_command(intf, "SET ignore_old_scan_res 1");
6201 wpa_command(intf, "BSS_FLUSH");
6202 return 1;
6203}
6204
6205
Jouni Malinenf7222712019-06-13 01:50:21 +03006206static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6207 struct sigma_conn *conn,
6208 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006209{
6210 const char *intf = get_param(cmd, "Interface");
6211 const char *bssid = get_param(cmd, "bssid");
6212 const char *val = get_param(cmd, "CHANNEL");
6213 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306214 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306215 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006216 int res;
6217 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006218 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306219 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006220 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006221
6222 if (bssid == NULL) {
6223 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6224 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006225 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006226 }
6227
6228 if (val)
6229 chan = atoi(val);
6230
6231 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6232 /* The current network may be from sta_associate or
6233 * sta_hs2_associate
6234 */
6235 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6236 0 ||
6237 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006238 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006239 }
6240
6241 ctrl = open_wpa_mon(intf);
6242 if (ctrl == NULL) {
6243 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6244 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006245 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006246 }
6247
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006248 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306249 sizeof(result)) < 0 ||
6250 strncmp(result, "COMPLETED", 9) != 0) {
6251 sigma_dut_print(dut, DUT_MSG_DEBUG,
6252 "sta_reassoc: Not connected");
6253 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006254 } else if (dut->sta_ft_ds) {
6255 sigma_dut_print(dut, DUT_MSG_DEBUG,
6256 "sta_reassoc: Use FT-over-DS");
6257 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306258 }
6259
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306260 if (dut->rsne_override) {
6261#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006262 if (get_driver_type(dut) == DRIVER_WCN &&
6263 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306264 sta_config_rsnie(dut, 1);
6265 dut->config_rsnie = 1;
6266 }
6267#endif /* NL80211_SUPPORT */
6268 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6269 dut->rsne_override);
6270 if (wpa_command(intf, buf) < 0) {
6271 send_resp(dut, conn, SIGMA_ERROR,
6272 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6273 return 0;
6274 }
6275 }
6276
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006277 if (ft_ds) {
6278 if (chan) {
6279 unsigned int freq;
6280
6281 freq = channel_to_freq(dut, chan);
6282 if (!freq) {
6283 sigma_dut_print(dut, DUT_MSG_ERROR,
6284 "Invalid channel number provided: %d",
6285 chan);
6286 send_resp(dut, conn, SIGMA_INVALID,
6287 "ErrorCode,Invalid channel number");
6288 goto close_mon_conn;
6289 }
6290 res = snprintf(buf, sizeof(buf),
6291 "SCAN TYPE=ONLY freq=%d", freq);
6292 } else {
6293 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6294 }
6295 if (res < 0 || res >= (int) sizeof(buf)) {
6296 send_resp(dut, conn, SIGMA_ERROR,
6297 "ErrorCode,snprintf failed");
6298 goto close_mon_conn;
6299 }
6300 if (wpa_command(intf, buf) < 0) {
6301 sigma_dut_print(dut, DUT_MSG_INFO,
6302 "Failed to start scan");
6303 send_resp(dut, conn, SIGMA_ERROR,
6304 "ErrorCode,scan failed");
6305 goto close_mon_conn;
6306 }
6307
6308 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6309 buf, sizeof(buf));
6310 if (res < 0) {
6311 sigma_dut_print(dut, DUT_MSG_INFO,
6312 "Scan did not complete");
6313 send_resp(dut, conn, SIGMA_ERROR,
6314 "ErrorCode,scan did not complete");
6315 goto close_mon_conn;
6316 }
6317
6318 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6319 if (res > 0 && res < (int) sizeof(buf))
6320 res = wpa_command(intf, buf);
6321
6322 if (res < 0 || res >= (int) sizeof(buf)) {
6323 send_resp(dut, conn, SIGMA_ERROR,
6324 "errorCode,FT_DS command failed");
6325 status = STATUS_SENT_ERROR;
6326 goto close_mon_conn;
6327 }
6328 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006329#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306330 if (chan) {
6331 unsigned int freq;
6332
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006333 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306334 if (!freq) {
6335 sigma_dut_print(dut, DUT_MSG_ERROR,
6336 "Invalid channel number provided: %d",
6337 chan);
6338 send_resp(dut, conn, SIGMA_INVALID,
6339 "ErrorCode,Invalid channel number");
6340 goto close_mon_conn;
6341 }
6342 res = snprintf(buf, sizeof(buf),
6343 "SCAN TYPE=ONLY freq=%d", freq);
6344 } else {
6345 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6346 }
6347 if (res < 0 || res >= (int) sizeof(buf)) {
6348 send_resp(dut, conn, SIGMA_ERROR,
6349 "ErrorCode,snprintf failed");
6350 goto close_mon_conn;
6351 }
6352 if (wpa_command(intf, buf) < 0) {
6353 sigma_dut_print(dut, DUT_MSG_INFO,
6354 "Failed to start scan");
6355 send_resp(dut, conn, SIGMA_ERROR,
6356 "ErrorCode,scan failed");
6357 goto close_mon_conn;
6358 }
6359
6360 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6361 buf, sizeof(buf));
6362 if (res < 0) {
6363 sigma_dut_print(dut, DUT_MSG_INFO,
6364 "Scan did not complete");
6365 send_resp(dut, conn, SIGMA_ERROR,
6366 "ErrorCode,scan did not complete");
6367 goto close_mon_conn;
6368 }
6369
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006370 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6371 < 0) {
6372 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6373 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006374 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306375 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006376 }
6377 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6378 bssid, chan);
6379 if (res > 0 && res < (int) sizeof(buf))
6380 res = wpa_command(intf, buf);
6381
6382 if (res < 0 || res >= (int) sizeof(buf)) {
6383 send_resp(dut, conn, SIGMA_ERROR,
6384 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306385 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006386 }
6387#else /* ANDROID */
6388 sigma_dut_print(dut, DUT_MSG_DEBUG,
6389 "Reassoc using iwpriv - skip chan=%d info",
6390 chan);
6391 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
6392 if (system(buf) != 0) {
6393 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006394 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306395 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006396 }
6397#endif /* ANDROID */
6398 sigma_dut_print(dut, DUT_MSG_INFO,
6399 "sta_reassoc: Run %s successful", buf);
6400 } else if (wpa_command(intf, "REASSOCIATE")) {
6401 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6402 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306403 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006404 }
6405
6406 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6407 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306408 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006409 send_resp(dut, conn, SIGMA_ERROR,
6410 "errorCode,Connection did not complete");
6411 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306412 goto close_mon_conn;
6413 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006414 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006415
Ashwini Patil467efef2017-05-25 12:18:27 +05306416close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006417 wpa_ctrl_detach(ctrl);
6418 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306419 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006420}
6421
6422
6423static void hs2_clear_credentials(const char *intf)
6424{
6425 wpa_command(intf, "REMOVE_CRED all");
6426}
6427
6428
Lior Davidcc88b562017-01-03 18:52:09 +02006429#ifdef __linux__
6430static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6431 unsigned int *aid)
6432{
Lior David0fe101e2017-03-09 16:09:50 +02006433 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006434
Lior David0fe101e2017-03-09 16:09:50 +02006435 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006436}
6437#endif /* __linux__ */
6438
6439
6440static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6441 unsigned int *aid)
6442{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006443 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006444#ifdef __linux__
6445 case DRIVER_WIL6210:
6446 return wil6210_get_aid(dut, bssid, aid);
6447#endif /* __linux__ */
6448 default:
6449 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6450 return -1;
6451 }
6452}
6453
6454
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006455static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6456 struct sigma_cmd *cmd)
6457{
6458 char buf[MAX_CMD_LEN];
6459 char bss_list[MAX_CMD_LEN];
6460 const char *parameter = get_param(cmd, "Parameter");
6461
6462 if (parameter == NULL)
6463 return -1;
6464
Lior Davidcc88b562017-01-03 18:52:09 +02006465 if (strcasecmp(parameter, "AID") == 0) {
6466 unsigned int aid = 0;
6467 char bssid[20];
6468
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006469 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006470 bssid, sizeof(bssid)) < 0) {
6471 sigma_dut_print(dut, DUT_MSG_ERROR,
6472 "could not get bssid");
6473 return -2;
6474 }
6475
6476 if (sta_get_aid_60g(dut, bssid, &aid))
6477 return -2;
6478
6479 snprintf(buf, sizeof(buf), "aid,%d", aid);
6480 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6481 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6482 return 0;
6483 }
6484
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006485 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6486 char *bss_line;
6487 char *bss_id = NULL;
6488 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306489 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006490
6491 if (ifname == NULL) {
6492 sigma_dut_print(dut, DUT_MSG_INFO,
6493 "For get DiscoveredDevList need Interface name.");
6494 return -1;
6495 }
6496
6497 /*
6498 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6499 * of BSSIDs in "bssid=<BSSID>\n"
6500 */
6501 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6502 bss_list,
6503 sizeof(bss_list)) < 0) {
6504 sigma_dut_print(dut, DUT_MSG_ERROR,
6505 "Failed to get bss list");
6506 return -1;
6507 }
6508
6509 sigma_dut_print(dut, DUT_MSG_DEBUG,
6510 "bss list for ifname:%s is:%s",
6511 ifname, bss_list);
6512
6513 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306514 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006515 while (bss_line) {
6516 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6517 bss_id) {
6518 int len;
6519
6520 len = snprintf(buf + strlen(buf),
6521 sizeof(buf) - strlen(buf),
6522 ",%s", bss_id);
6523 free(bss_id);
6524 bss_id = NULL;
6525 if (len < 0) {
6526 sigma_dut_print(dut,
6527 DUT_MSG_ERROR,
6528 "Failed to read BSSID");
6529 send_resp(dut, conn, SIGMA_ERROR,
6530 "ErrorCode,Failed to read BSS ID");
6531 return 0;
6532 }
6533
6534 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6535 sigma_dut_print(dut,
6536 DUT_MSG_ERROR,
6537 "Response buf too small for list");
6538 send_resp(dut, conn,
6539 SIGMA_ERROR,
6540 "ErrorCode,Response buf too small for list");
6541 return 0;
6542 }
6543 }
6544
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306545 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006546 }
6547
6548 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6549 buf);
6550 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6551 return 0;
6552 }
6553
6554 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6555 return 0;
6556}
6557
6558
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006559static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6560 struct sigma_cmd *cmd)
6561{
6562 char buf[MAX_CMD_LEN];
6563 const char *parameter = get_param(cmd, "Parameter");
6564
6565 if (!parameter)
6566 return -1;
6567
6568 if (strcasecmp(parameter, "RSSI") == 0) {
6569 char rssi[10];
6570
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006571 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006572 rssi, sizeof(rssi)) < 0) {
6573 sigma_dut_print(dut, DUT_MSG_ERROR,
6574 "Could not get RSSI");
6575 return -2;
6576 }
6577
6578 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6579 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6580 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6581 return 0;
6582 }
6583
6584 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6585 return 0;
6586}
6587
6588
Jouni Malinenf7222712019-06-13 01:50:21 +03006589static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6590 struct sigma_conn *conn,
6591 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006592{
6593 const char *program = get_param(cmd, "Program");
6594
6595 if (program == NULL)
6596 return -1;
6597
6598 if (strcasecmp(program, "P2PNFC") == 0)
6599 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6600
6601 if (strcasecmp(program, "60ghz") == 0)
6602 return sta_get_parameter_60g(dut, conn, cmd);
6603
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006604 if (strcasecmp(program, "he") == 0)
6605 return sta_get_parameter_he(dut, conn, cmd);
6606
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006607#ifdef ANDROID_NAN
6608 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006609 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006610#endif /* ANDROID_NAN */
6611
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006612#ifdef MIRACAST
6613 if (strcasecmp(program, "WFD") == 0 ||
6614 strcasecmp(program, "DisplayR2") == 0)
6615 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6616#endif /* MIRACAST */
6617
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006618 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6619 return 0;
6620}
6621
6622
6623static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6624 const char *type)
6625{
6626 char buf[100];
6627
6628 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006629 run_iwpriv(dut, intf, "chwidth 2");
6630 run_iwpriv(dut, intf, "mode 11ACVHT80");
6631 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006632 }
6633
6634 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006635 run_iwpriv(dut, intf, "chwidth 0");
6636 run_iwpriv(dut, intf, "mode 11naht40");
6637 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006638 }
6639
6640 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006641 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006642
6643 /* Reset CTS width */
6644 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6645 intf);
6646 if (system(buf) != 0) {
6647 sigma_dut_print(dut, DUT_MSG_ERROR,
6648 "wifitool %s beeliner_fw_test 54 0 failed",
6649 intf);
6650 }
6651
6652 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006653 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006654
6655 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6656 if (system(buf) != 0) {
6657 sigma_dut_print(dut, DUT_MSG_ERROR,
6658 "iwpriv rts failed");
6659 }
6660 }
6661
6662 if (type && strcasecmp(type, "Testbed") == 0) {
6663 dut->testbed_flag_txsp = 1;
6664 dut->testbed_flag_rxsp = 1;
6665 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006666 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006667
6668 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006669 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006670
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006671 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006672
6673 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006674 run_iwpriv(dut, intf, "tx_stbc 0");
6675 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006676
6677 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006678 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006679 }
6680
6681 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006682 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006683 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006684
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006685 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006686 }
6687}
6688
6689
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006690#ifdef NL80211_SUPPORT
6691static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6692 enum he_mcs_config mcs)
6693{
6694 struct nl_msg *msg;
6695 int ret = 0;
6696 struct nlattr *params;
6697 int ifindex;
6698
6699 ifindex = if_nametoindex(intf);
6700 if (ifindex == 0) {
6701 sigma_dut_print(dut, DUT_MSG_ERROR,
6702 "%s: Index for interface %s failed",
6703 __func__, intf);
6704 return -1;
6705 }
6706
6707 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6708 NL80211_CMD_VENDOR)) ||
6709 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6710 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6711 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6712 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6713 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6714 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6715 mcs)) {
6716 sigma_dut_print(dut, DUT_MSG_ERROR,
6717 "%s: err in adding vendor_cmd and vendor_data",
6718 __func__);
6719 nlmsg_free(msg);
6720 return -1;
6721 }
6722 nla_nest_end(msg, params);
6723
6724 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6725 if (ret) {
6726 sigma_dut_print(dut, DUT_MSG_ERROR,
6727 "%s: err in send_and_recv_msgs, ret=%d",
6728 __func__, ret);
6729 }
6730 return ret;
6731}
6732#endif /* NL80211_SUPPORT */
6733
6734
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006735static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6736 const char *intf, int enable)
6737{
6738#ifdef NL80211_SUPPORT
6739 struct nl_msg *msg;
6740 int ret = 0;
6741 struct nlattr *params;
6742 int ifindex;
6743
6744 ifindex = if_nametoindex(intf);
6745 if (ifindex == 0) {
6746 sigma_dut_print(dut, DUT_MSG_ERROR,
6747 "%s: Index for interface %s failed",
6748 __func__, intf);
6749 return -1;
6750 }
6751
6752 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6753 NL80211_CMD_VENDOR)) ||
6754 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6755 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6756 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6757 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6758 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6759 nla_put_u8(msg,
6760 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6761 enable)) {
6762 sigma_dut_print(dut, DUT_MSG_ERROR,
6763 "%s: err in adding vendor_cmd and vendor_data",
6764 __func__);
6765 nlmsg_free(msg);
6766 return -1;
6767 }
6768 nla_nest_end(msg, params);
6769
6770 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6771 if (ret) {
6772 sigma_dut_print(dut, DUT_MSG_ERROR,
6773 "%s: err in send_and_recv_msgs, ret=%d",
6774 __func__, ret);
6775 }
6776 return ret;
6777#else /* NL80211_SUPPORT */
6778 sigma_dut_print(dut, DUT_MSG_ERROR,
6779 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6780 return -1;
6781#endif /* NL80211_SUPPORT */
6782}
6783
6784
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006785static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6786 const char *intf, int enable)
6787{
6788#ifdef NL80211_SUPPORT
6789 struct nl_msg *msg;
6790 int ret = 0;
6791 struct nlattr *params;
6792 int ifindex;
6793
6794 ifindex = if_nametoindex(intf);
6795 if (ifindex == 0) {
6796 sigma_dut_print(dut, DUT_MSG_ERROR,
6797 "%s: Index for interface %s failed",
6798 __func__, intf);
6799 return -1;
6800 }
6801
6802 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6803 NL80211_CMD_VENDOR)) ||
6804 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6805 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6806 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6807 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6808 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6809 nla_put_u8(msg,
6810 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6811 enable)) {
6812 sigma_dut_print(dut, DUT_MSG_ERROR,
6813 "%s: err in adding vendor_cmd and vendor_data",
6814 __func__);
6815 nlmsg_free(msg);
6816 return -1;
6817 }
6818 nla_nest_end(msg, params);
6819
6820 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6821 if (ret) {
6822 sigma_dut_print(dut, DUT_MSG_ERROR,
6823 "%s: err in send_and_recv_msgs, ret=%d",
6824 __func__, ret);
6825 }
6826 return ret;
6827#else /* NL80211_SUPPORT */
6828 sigma_dut_print(dut, DUT_MSG_ERROR,
6829 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6830 return -1;
6831#endif /* NL80211_SUPPORT */
6832}
6833
6834
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006835#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006836
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006837static int sta_set_he_testbed_def(struct sigma_dut *dut,
6838 const char *intf, int cfg)
6839{
6840 struct nl_msg *msg;
6841 int ret = 0;
6842 struct nlattr *params;
6843 int ifindex;
6844
6845 ifindex = if_nametoindex(intf);
6846 if (ifindex == 0) {
6847 sigma_dut_print(dut, DUT_MSG_ERROR,
6848 "%s: Index for interface %s failed",
6849 __func__, intf);
6850 return -1;
6851 }
6852
6853 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6854 NL80211_CMD_VENDOR)) ||
6855 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6856 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6857 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6858 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6859 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6860 nla_put_u8(msg,
6861 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6862 cfg)) {
6863 sigma_dut_print(dut, DUT_MSG_ERROR,
6864 "%s: err in adding vendor_cmd and vendor_data",
6865 __func__);
6866 nlmsg_free(msg);
6867 return -1;
6868 }
6869 nla_nest_end(msg, params);
6870
6871 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6872 if (ret) {
6873 sigma_dut_print(dut, DUT_MSG_ERROR,
6874 "%s: err in send_and_recv_msgs, ret=%d",
6875 __func__, ret);
6876 }
6877 return ret;
6878}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006879
6880
6881static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
6882{
6883 struct nl_msg *msg;
6884 int ret = 0;
6885 struct nlattr *params;
6886 int ifindex;
6887
6888 ifindex = if_nametoindex(intf);
6889 if (ifindex == 0) {
6890 sigma_dut_print(dut, DUT_MSG_ERROR,
6891 "%s: Index for interface %s failed",
6892 __func__, intf);
6893 return -1;
6894 }
6895
6896 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6897 NL80211_CMD_VENDOR)) ||
6898 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6899 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6900 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6901 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6902 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6903 nla_put_u8(msg,
6904 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
6905 cfg)) {
6906 sigma_dut_print(dut, DUT_MSG_ERROR,
6907 "%s: err in adding vendor_cmd and vendor_data",
6908 __func__);
6909 nlmsg_free(msg);
6910 return -1;
6911 }
6912 nla_nest_end(msg, params);
6913
6914 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6915 if (ret) {
6916 sigma_dut_print(dut, DUT_MSG_ERROR,
6917 "%s: err in send_and_recv_msgs, ret=%d",
6918 __func__, ret);
6919 }
6920 return ret;
6921}
6922
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006923#endif /* NL80211_SUPPORT */
6924
6925
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006926static int sta_set_addba_buf_size(struct sigma_dut *dut,
6927 const char *intf, int bufsize)
6928{
6929#ifdef NL80211_SUPPORT
6930 struct nl_msg *msg;
6931 int ret = 0;
6932 struct nlattr *params;
6933 int ifindex;
6934
6935 ifindex = if_nametoindex(intf);
6936 if (ifindex == 0) {
6937 sigma_dut_print(dut, DUT_MSG_ERROR,
6938 "%s: Index for interface %s failed",
6939 __func__, intf);
6940 return -1;
6941 }
6942
6943 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6944 NL80211_CMD_VENDOR)) ||
6945 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6946 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6947 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6948 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6949 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006950 nla_put_u16(msg,
6951 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6952 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006953 sigma_dut_print(dut, DUT_MSG_ERROR,
6954 "%s: err in adding vendor_cmd and vendor_data",
6955 __func__);
6956 nlmsg_free(msg);
6957 return -1;
6958 }
6959 nla_nest_end(msg, params);
6960
6961 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6962 if (ret) {
6963 sigma_dut_print(dut, DUT_MSG_ERROR,
6964 "%s: err in send_and_recv_msgs, ret=%d",
6965 __func__, ret);
6966 }
6967 return ret;
6968#else /* NL80211_SUPPORT */
6969 sigma_dut_print(dut, DUT_MSG_ERROR,
6970 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6971 return -1;
6972#endif /* NL80211_SUPPORT */
6973}
6974
6975
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006976static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6977 int enable)
6978{
6979#ifdef NL80211_SUPPORT
6980 struct nl_msg *msg;
6981 int ret = 0;
6982 struct nlattr *params;
6983 int ifindex;
6984
6985 ifindex = if_nametoindex(intf);
6986 if (ifindex == 0) {
6987 sigma_dut_print(dut, DUT_MSG_ERROR,
6988 "%s: Index for interface %s failed",
6989 __func__, intf);
6990 return -1;
6991 }
6992
6993 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6994 NL80211_CMD_VENDOR)) ||
6995 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6996 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6997 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6998 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6999 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7000 nla_put_u8(msg,
7001 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7002 enable)) {
7003 sigma_dut_print(dut, DUT_MSG_ERROR,
7004 "%s: err in adding vendor_cmd and vendor_data",
7005 __func__);
7006 nlmsg_free(msg);
7007 return -1;
7008 }
7009 nla_nest_end(msg, params);
7010
7011 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7012 if (ret) {
7013 sigma_dut_print(dut, DUT_MSG_ERROR,
7014 "%s: err in send_and_recv_msgs, ret=%d",
7015 __func__, ret);
7016 }
7017 return ret;
7018#else /* NL80211_SUPPORT */
7019 sigma_dut_print(dut, DUT_MSG_ERROR,
7020 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7021 return -1;
7022#endif /* NL80211_SUPPORT */
7023}
7024
7025
Arif Hussain9765f7d2018-07-03 08:28:26 -07007026static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7027 int val)
7028{
7029#ifdef NL80211_SUPPORT
7030 struct nl_msg *msg;
7031 int ret = 0;
7032 struct nlattr *params;
7033 int ifindex;
7034
7035 ifindex = if_nametoindex(intf);
7036 if (ifindex == 0) {
7037 sigma_dut_print(dut, DUT_MSG_ERROR,
7038 "%s: Index for interface %s failed, val:%d",
7039 __func__, intf, val);
7040 return -1;
7041 }
7042
7043 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7044 NL80211_CMD_VENDOR)) ||
7045 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7046 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7047 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7048 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7049 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7050 nla_put_u8(msg,
7051 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7052 val)) {
7053 sigma_dut_print(dut, DUT_MSG_ERROR,
7054 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7055 __func__, val);
7056 nlmsg_free(msg);
7057 return -1;
7058 }
7059 nla_nest_end(msg, params);
7060
7061 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7062 if (ret) {
7063 sigma_dut_print(dut, DUT_MSG_ERROR,
7064 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7065 __func__, ret, val);
7066 }
7067 return ret;
7068#else /* NL80211_SUPPORT */
7069 sigma_dut_print(dut, DUT_MSG_ERROR,
7070 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7071 return -1;
7072#endif /* NL80211_SUPPORT */
7073}
7074
7075
Arif Hussain68d23f52018-07-11 13:39:08 -07007076#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007077static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7078 enum qca_wlan_he_mac_padding_dur val)
7079{
Arif Hussain68d23f52018-07-11 13:39:08 -07007080 struct nl_msg *msg;
7081 int ret = 0;
7082 struct nlattr *params;
7083 int ifindex;
7084
7085 ifindex = if_nametoindex(intf);
7086 if (ifindex == 0) {
7087 sigma_dut_print(dut, DUT_MSG_ERROR,
7088 "%s: Index for interface %s failed, val:%d",
7089 __func__, intf, val);
7090 return -1;
7091 }
7092
7093 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7094 NL80211_CMD_VENDOR)) ||
7095 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7096 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7097 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7098 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7099 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7100 nla_put_u8(msg,
7101 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7102 val)) {
7103 sigma_dut_print(dut, DUT_MSG_ERROR,
7104 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7105 __func__, val);
7106 nlmsg_free(msg);
7107 return -1;
7108 }
7109 nla_nest_end(msg, params);
7110
7111 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7112 if (ret) {
7113 sigma_dut_print(dut, DUT_MSG_ERROR,
7114 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7115 __func__, ret, val);
7116 }
7117 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007118}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007119#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007120
7121
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007122static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7123 int val)
7124{
7125#ifdef NL80211_SUPPORT
7126 struct nl_msg *msg;
7127 int ret = 0;
7128 struct nlattr *params;
7129 int ifindex;
7130
7131 ifindex = if_nametoindex(intf);
7132 if (ifindex == 0) {
7133 sigma_dut_print(dut, DUT_MSG_ERROR,
7134 "%s: Index for interface %s failed, val:%d",
7135 __func__, intf, val);
7136 return -1;
7137 }
7138
7139 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7140 NL80211_CMD_VENDOR)) ||
7141 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7142 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7143 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7144 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7145 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7146 nla_put_u8(msg,
7147 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7148 val)) {
7149 sigma_dut_print(dut, DUT_MSG_ERROR,
7150 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7151 __func__, val);
7152 nlmsg_free(msg);
7153 return -1;
7154 }
7155 nla_nest_end(msg, params);
7156
7157 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7158 if (ret) {
7159 sigma_dut_print(dut, DUT_MSG_ERROR,
7160 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7161 __func__, ret, val);
7162 }
7163 return ret;
7164#else /* NL80211_SUPPORT */
7165 sigma_dut_print(dut, DUT_MSG_ERROR,
7166 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7167 return -1;
7168#endif /* NL80211_SUPPORT */
7169}
7170
7171
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007172#ifdef NL80211_SUPPORT
7173static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7174{
7175 struct nl_msg *msg;
7176 int ret = 0;
7177 struct nlattr *params;
7178 int ifindex;
7179
7180 ifindex = if_nametoindex(intf);
7181 if (ifindex == 0) {
7182 sigma_dut_print(dut, DUT_MSG_ERROR,
7183 "%s: Index for interface %s failed",
7184 __func__, intf);
7185 return -1;
7186 }
7187
7188 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7189 NL80211_CMD_VENDOR)) ||
7190 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7191 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7192 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7193 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7194 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7195 nla_put_flag(msg,
7196 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7197 sigma_dut_print(dut, DUT_MSG_ERROR,
7198 "%s: err in adding vendor_cmd and vendor_data",
7199 __func__);
7200 nlmsg_free(msg);
7201 return -1;
7202 }
7203 nla_nest_end(msg, params);
7204
7205 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7206 if (ret) {
7207 sigma_dut_print(dut, DUT_MSG_ERROR,
7208 "%s: err in send_and_recv_msgs, ret=%d",
7209 __func__, ret);
7210 }
7211 return ret;
7212}
7213#endif /* NL80211_SUPPORT */
7214
7215
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007216static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7217 int val)
7218{
7219#ifdef NL80211_SUPPORT
7220 struct nl_msg *msg;
7221 int ret = 0;
7222 struct nlattr *params;
7223 int ifindex;
7224
7225 ifindex = if_nametoindex(intf);
7226 if (ifindex == 0) {
7227 sigma_dut_print(dut, DUT_MSG_ERROR,
7228 "%s: Index for interface %s failed, val:%d",
7229 __func__, intf, val);
7230 return -1;
7231 }
7232
7233 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7234 NL80211_CMD_VENDOR)) ||
7235 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7236 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7237 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7238 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7239 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7240 nla_put_u8(msg,
7241 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7242 val)) {
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7245 __func__, val);
7246 nlmsg_free(msg);
7247 return -1;
7248 }
7249 nla_nest_end(msg, params);
7250
7251 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7252 if (ret) {
7253 sigma_dut_print(dut, DUT_MSG_ERROR,
7254 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7255 __func__, ret, val);
7256 }
7257 return ret;
7258#else /* NL80211_SUPPORT */
7259 sigma_dut_print(dut, DUT_MSG_ERROR,
7260 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7261 return -1;
7262#endif /* NL80211_SUPPORT */
7263}
7264
7265
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007266static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7267 int val)
7268{
7269#ifdef NL80211_SUPPORT
7270 struct nl_msg *msg;
7271 int ret = 0;
7272 struct nlattr *params;
7273 int ifindex;
7274
7275 ifindex = if_nametoindex(intf);
7276 if (ifindex == 0) {
7277 sigma_dut_print(dut, DUT_MSG_ERROR,
7278 "%s: Index for interface %s failed, val:%d",
7279 __func__, intf, val);
7280 return -1;
7281 }
7282
7283 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7284 NL80211_CMD_VENDOR)) ||
7285 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7286 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7287 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7288 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7289 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7290 nla_put_u8(msg,
7291 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7292 val)) {
7293 sigma_dut_print(dut, DUT_MSG_ERROR,
7294 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7295 __func__, val);
7296 nlmsg_free(msg);
7297 return -1;
7298 }
7299 nla_nest_end(msg, params);
7300
7301 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7302 if (ret) {
7303 sigma_dut_print(dut, DUT_MSG_ERROR,
7304 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7305 __func__, ret, val);
7306 }
7307 return ret;
7308#else /* NL80211_SUPPORT */
7309 sigma_dut_print(dut, DUT_MSG_ERROR,
7310 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7311 return -1;
7312#endif /* NL80211_SUPPORT */
7313}
7314
7315
Arif Hussain480d5f42019-03-12 14:40:42 -07007316static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7317 int val)
7318{
7319#ifdef NL80211_SUPPORT
7320 struct nl_msg *msg;
7321 int ret;
7322 struct nlattr *params;
7323 int ifindex;
7324
7325 ifindex = if_nametoindex(intf);
7326 if (ifindex == 0) {
7327 sigma_dut_print(dut, DUT_MSG_ERROR,
7328 "%s: Index for interface %s failed, val:%d",
7329 __func__, intf, val);
7330 return -1;
7331 }
7332
7333 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7334 NL80211_CMD_VENDOR)) ||
7335 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7336 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7337 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7338 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7339 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7340 nla_put_u8(msg,
7341 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7342 val)) {
7343 sigma_dut_print(dut, DUT_MSG_ERROR,
7344 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7345 __func__, val);
7346 nlmsg_free(msg);
7347 return -1;
7348 }
7349 nla_nest_end(msg, params);
7350
7351 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7352 if (ret) {
7353 sigma_dut_print(dut, DUT_MSG_ERROR,
7354 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7355 __func__, ret, val);
7356 }
7357 return ret;
7358#else /* NL80211_SUPPORT */
7359 sigma_dut_print(dut, DUT_MSG_ERROR,
7360 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7361 return -1;
7362#endif /* NL80211_SUPPORT */
7363}
7364
7365
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007366static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7367 const char *type)
7368{
7369 char buf[60];
7370
7371 if (dut->program == PROGRAM_HE) {
7372 /* resetting phymode to auto in case of HE program */
7373 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7374 if (system(buf) != 0) {
7375 sigma_dut_print(dut, DUT_MSG_ERROR,
7376 "iwpriv %s setphymode failed", intf);
7377 }
7378
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007379 /* reset the rate to Auto rate */
7380 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7381 intf);
7382 if (system(buf) != 0) {
7383 sigma_dut_print(dut, DUT_MSG_ERROR,
7384 "iwpriv %s set_11ax_rate 0xff failed",
7385 intf);
7386 }
7387
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007388 /* reset the LDPC setting */
7389 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7390 if (system(buf) != 0) {
7391 sigma_dut_print(dut, DUT_MSG_ERROR,
7392 "iwpriv %s ldpc 1 failed", intf);
7393 }
7394
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007395 /* reset the power save setting */
7396 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7397 if (system(buf) != 0) {
7398 sigma_dut_print(dut, DUT_MSG_ERROR,
7399 "iwpriv %s setPower 2 failed", intf);
7400 }
7401
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007402 /* remove all network profiles */
7403 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007404
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007405 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7406 sta_set_addba_buf_size(dut, intf, 64);
7407
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007408#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007409 /* Reset the device HE capabilities to its default supported
7410 * configuration. */
7411 sta_set_he_testbed_def(dut, intf, 0);
7412
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007413 /* Disable noackpolicy for all AC */
7414 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7415 sigma_dut_print(dut, DUT_MSG_ERROR,
7416 "Disable of noackpolicy for all AC failed");
7417 }
7418#endif /* NL80211_SUPPORT */
7419
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007420 /* Enable WMM by default */
7421 if (wcn_sta_set_wmm(dut, intf, "on")) {
7422 sigma_dut_print(dut, DUT_MSG_ERROR,
7423 "Enable of WMM in sta_reset_default_wcn failed");
7424 }
7425
7426 /* Disable ADDBA_REJECT by default */
7427 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7428 sigma_dut_print(dut, DUT_MSG_ERROR,
7429 "Disable of addba_reject in sta_reset_default_wcn failed");
7430 }
7431
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007432 /* Enable sending of ADDBA by default */
7433 if (nlvendor_config_send_addba(dut, intf, 1)) {
7434 sigma_dut_print(dut, DUT_MSG_ERROR,
7435 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7436 }
7437
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007438 /* Enable AMPDU by default */
7439 iwpriv_sta_set_ampdu(dut, intf, 1);
7440
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007441#ifdef NL80211_SUPPORT
7442 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
7443 sigma_dut_print(dut, DUT_MSG_ERROR,
7444 "Set LTF config to default in sta_reset_default_wcn failed");
7445 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007446
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007447 /* set the beamformee NSTS(maximum number of
7448 * space-time streams) to default DUT config
7449 */
7450 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007451 sigma_dut_print(dut, DUT_MSG_ERROR,
7452 "Failed to set BeamformeeSTS");
7453 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007454
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007455 if (sta_set_mac_padding_duration(
7456 dut, intf,
7457 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007458 sigma_dut_print(dut, DUT_MSG_ERROR,
7459 "Failed to set MAC padding duration");
7460 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007461
7462 if (sta_set_mu_edca_override(dut, intf, 0)) {
7463 sigma_dut_print(dut, DUT_MSG_ERROR,
7464 "ErrorCode,Failed to set MU EDCA override disable");
7465 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007466
7467 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7468 sigma_dut_print(dut, DUT_MSG_ERROR,
7469 "Failed to set OM ctrl supp");
7470 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007471
7472 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7473 sigma_dut_print(dut, DUT_MSG_ERROR,
7474 "Failed to set Tx SU PPDU enable");
7475 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007476
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007477 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7478 sigma_dut_print(dut, DUT_MSG_ERROR,
7479 "failed to send TB PPDU Tx cfg");
7480 }
7481
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007482 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7483 sigma_dut_print(dut, DUT_MSG_ERROR,
7484 "Failed to set OM ctrl reset");
7485 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007486
7487 /* +HTC-HE support default on */
7488 if (sta_set_he_htc_supp(dut, intf, 1)) {
7489 sigma_dut_print(dut, DUT_MSG_ERROR,
7490 "Setting of +HTC-HE support failed");
7491 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007492#endif /* NL80211_SUPPORT */
7493
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007494 if (sta_set_tx_beamformee(dut, intf, 1)) {
7495 sigma_dut_print(dut, DUT_MSG_ERROR,
7496 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7497 }
7498
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007499 /* Set nss to 1 and MCS 0-7 in case of testbed */
7500 if (type && strcasecmp(type, "Testbed") == 0) {
7501#ifdef NL80211_SUPPORT
7502 int ret;
7503#endif /* NL80211_SUPPORT */
7504
7505 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7506 if (system(buf) != 0) {
7507 sigma_dut_print(dut, DUT_MSG_ERROR,
7508 "iwpriv %s nss failed", intf);
7509 }
7510
7511#ifdef NL80211_SUPPORT
7512 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7513 if (ret) {
7514 sigma_dut_print(dut, DUT_MSG_ERROR,
7515 "Setting of MCS failed, ret:%d",
7516 ret);
7517 }
7518#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007519
7520 /* Disable STBC as default */
7521 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007522
7523 /* Disable AMSDU as default */
7524 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007525
7526#ifdef NL80211_SUPPORT
7527 /* HE fragmentation default off */
7528 if (sta_set_he_fragmentation(dut, intf,
7529 HE_FRAG_DISABLE)) {
7530 sigma_dut_print(dut, DUT_MSG_ERROR,
7531 "Setting of HE fragmentation failed");
7532 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007533
7534 /* set the beamformee NSTS(maximum number of
7535 * space-time streams) to default testbed config
7536 */
7537 if (sta_set_beamformee_sts(dut, intf, 3)) {
7538 sigma_dut_print(dut, DUT_MSG_ERROR,
7539 "Failed to set BeamformeeSTS");
7540 }
7541
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007542 /* +HTC-HE support default off */
7543 if (sta_set_he_htc_supp(dut, intf, 0)) {
7544 sigma_dut_print(dut, DUT_MSG_ERROR,
7545 "Setting of +HTC-HE support failed");
7546 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007547
7548 /* Set device HE capabilities to testbed default
7549 * configuration. */
7550 if (sta_set_he_testbed_def(dut, intf, 1)) {
7551 sigma_dut_print(dut, DUT_MSG_DEBUG,
7552 "Failed to set HE defaults");
7553 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007554
7555 /* Disable VHT support in 2.4 GHz for testbed */
7556 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007557#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007558
7559 /* Enable WEP/TKIP with HE capability in testbed */
7560 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7561 sigma_dut_print(dut, DUT_MSG_ERROR,
7562 "Enabling HE config with WEP/TKIP failed");
7563 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007564 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007565
7566 /* Defaults in case of DUT */
7567 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007568 /* Enable STBC by default */
7569 wcn_sta_set_stbc(dut, intf, "1");
7570
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007571 /* set nss to 2 */
7572 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7573 if (system(buf) != 0) {
7574 sigma_dut_print(dut, DUT_MSG_ERROR,
7575 "iwpriv %s nss 2 failed", intf);
7576 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007577 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007578
7579#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007580 /* Set HE_MCS to 0-11 */
7581 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007582 sigma_dut_print(dut, DUT_MSG_ERROR,
7583 "Setting of MCS failed");
7584 }
7585#endif /* NL80211_SUPPORT */
7586
7587 /* Disable WEP/TKIP with HE capability in DUT */
7588 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7589 sigma_dut_print(dut, DUT_MSG_ERROR,
7590 "Enabling HE config with WEP/TKIP failed");
7591 }
7592 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007593 }
7594}
7595
7596
Jouni Malinenf7222712019-06-13 01:50:21 +03007597static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7598 struct sigma_conn *conn,
7599 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007600{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007601 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007602 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007603 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007604 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307605 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007606
Jouni Malinenb21f0542019-11-04 17:53:38 +02007607 if (dut->station_ifname_2g &&
7608 strcmp(dut->station_ifname_2g, intf) == 0)
7609 dut->use_5g = 0;
7610 else if (dut->station_ifname_5g &&
7611 strcmp(dut->station_ifname_5g, intf) == 0)
7612 dut->use_5g = 1;
7613
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007614 if (!program)
7615 program = get_param(cmd, "prog");
7616 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007617 dut->device_type = STA_unknown;
7618 type = get_param(cmd, "type");
7619 if (type && strcasecmp(type, "Testbed") == 0)
7620 dut->device_type = STA_testbed;
7621 if (type && strcasecmp(type, "DUT") == 0)
7622 dut->device_type = STA_dut;
7623
7624 if (dut->program == PROGRAM_TDLS) {
7625 /* Clear TDLS testing mode */
7626 wpa_command(intf, "SET tdls_disabled 0");
7627 wpa_command(intf, "SET tdls_testing 0");
7628 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007629 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307630 /* Enable the WCN driver in TDLS Explicit trigger mode
7631 */
7632 wpa_command(intf, "SET tdls_external_control 0");
7633 wpa_command(intf, "SET tdls_trigger_control 0");
7634 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007635 }
7636
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007637#ifdef MIRACAST
7638 if (dut->program == PROGRAM_WFD ||
7639 dut->program == PROGRAM_DISPLAYR2)
7640 miracast_sta_reset_default(dut, conn, cmd);
7641#endif /* MIRACAST */
7642
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007643 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007644 case DRIVER_ATHEROS:
7645 sta_reset_default_ath(dut, intf, type);
7646 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007647 case DRIVER_WCN:
7648 sta_reset_default_wcn(dut, intf, type);
7649 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007650 default:
7651 break;
7652 }
7653
7654#ifdef ANDROID_NAN
7655 if (dut->program == PROGRAM_NAN)
7656 nan_cmd_sta_reset_default(dut, conn, cmd);
7657#endif /* ANDROID_NAN */
7658
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307659 if (dut->program == PROGRAM_LOC &&
7660 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7661 return ERROR_SEND_STATUS;
7662
Jouni Malinenba630452018-06-22 11:49:59 +03007663 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007664 unlink("SP/wi-fi.org/pps.xml");
7665 if (system("rm -r SP/*") != 0) {
7666 }
7667 unlink("next-client-cert.pem");
7668 unlink("next-client-key.pem");
7669 }
7670
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007671 /* For WPS program of the 60 GHz band the band type needs to be saved */
7672 if (dut->program == PROGRAM_WPS) {
7673 if (band && strcasecmp(band, "60GHz") == 0) {
7674 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007675 /* For 60 GHz enable WPS for WPS TCs */
7676 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007677 } else {
7678 dut->band = WPS_BAND_NON_60G;
7679 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007680 } else if (dut->program == PROGRAM_60GHZ) {
7681 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7682 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007683 }
7684
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007685 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007686 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007687 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007688
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007689 sigma_dut_print(dut, DUT_MSG_INFO,
7690 "WPS 60 GHz program, wps_disable = %d",
7691 dut->wps_disable);
7692
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007693 if (!dev_role) {
7694 send_resp(dut, conn, SIGMA_ERROR,
7695 "errorCode,Missing DevRole argument");
7696 return 0;
7697 }
7698
7699 if (strcasecmp(dev_role, "STA") == 0)
7700 dut->dev_role = DEVROLE_STA;
7701 else if (strcasecmp(dev_role, "PCP") == 0)
7702 dut->dev_role = DEVROLE_PCP;
7703 else {
7704 send_resp(dut, conn, SIGMA_ERROR,
7705 "errorCode,Unknown DevRole");
7706 return 0;
7707 }
7708
7709 if (dut->device_type == STA_unknown) {
7710 sigma_dut_print(dut, DUT_MSG_ERROR,
7711 "Device type is not STA testbed or DUT");
7712 send_resp(dut, conn, SIGMA_ERROR,
7713 "errorCode,Unknown device type");
7714 return 0;
7715 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007716
7717 sigma_dut_print(dut, DUT_MSG_DEBUG,
7718 "Setting msdu_size to MAX: 7912");
7719 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007720 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007721
7722 if (system(buf) != 0) {
7723 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7724 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007725 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007726 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007727
7728 if (sta_set_force_mcs(dut, 0, 1)) {
7729 sigma_dut_print(dut, DUT_MSG_ERROR,
7730 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007731 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007732 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007733 }
7734
7735 wpa_command(intf, "WPS_ER_STOP");
7736 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307737 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007738 wpa_command(intf, "SET radio_disabled 0");
7739
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007740 dut->wps_forced_version = 0;
7741
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007742 if (dut->wsc_fragment) {
7743 dut->wsc_fragment = 0;
7744 wpa_command(intf, "SET device_name Test client");
7745 wpa_command(intf, "SET manufacturer ");
7746 wpa_command(intf, "SET model_name ");
7747 wpa_command(intf, "SET model_number ");
7748 wpa_command(intf, "SET serial_number ");
7749 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007750 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7751 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7752 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7753 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007754
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007755 if (dut->tmp_mac_addr && dut->set_macaddr) {
7756 dut->tmp_mac_addr = 0;
7757 if (system(dut->set_macaddr) != 0) {
7758 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7759 "temporary MAC address");
7760 }
7761 }
7762
7763 set_ps(intf, dut, 0);
7764
Jouni Malinenba630452018-06-22 11:49:59 +03007765 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7766 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007767 wpa_command(intf, "SET interworking 1");
7768 wpa_command(intf, "SET hs20 1");
7769 }
7770
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007771 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007772 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007773 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007774 wpa_command(intf, "SET pmf 1");
7775 } else {
7776 wpa_command(intf, "SET pmf 0");
7777 }
7778
7779 hs2_clear_credentials(intf);
7780 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7781 wpa_command(intf, "SET access_network_type 15");
7782
7783 static_ip_file(0, NULL, NULL, NULL);
7784 kill_dhcp_client(dut, intf);
7785 clear_ip_addr(dut, intf);
7786
7787 dut->er_oper_performed = 0;
7788 dut->er_oper_bssid[0] = '\0';
7789
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007790 if (dut->program == PROGRAM_LOC) {
7791 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007792 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007793 }
7794
Ashwini Patil00402582017-04-13 12:29:39 +05307795 if (dut->program == PROGRAM_MBO) {
7796 free(dut->non_pref_ch_list);
7797 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307798 free(dut->btm_query_cand_list);
7799 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307800 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307801 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307802 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307803 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307804 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307805 }
7806
Jouni Malinen3c367e82017-06-23 17:01:47 +03007807 free(dut->rsne_override);
7808 dut->rsne_override = NULL;
7809
Jouni Malinen68143132017-09-02 02:34:08 +03007810 free(dut->sae_commit_override);
7811 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007812 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen68143132017-09-02 02:34:08 +03007813
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007814 dut->sta_associate_wait_connect = 0;
7815 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007816 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007817 dut->sta_tod_policy = 0;
7818
Jouni Malinend86e5822017-08-29 03:55:32 +03007819 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007820 free(dut->dpp_peer_uri);
7821 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007822 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007823 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007824
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007825 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7826
vamsi krishnaa2799492017-12-05 14:28:01 +05307827 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307828 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307829 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307830 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7831 dut->fils_hlp = 0;
7832#ifdef ANDROID
7833 hlp_thread_cleanup(dut);
7834#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307835 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307836
Jouni Malinen8179fee2019-03-28 03:19:47 +02007837 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007838 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007839
Sunil Dutt076081f2018-02-05 19:45:50 +05307840#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007841 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307842 dut->config_rsnie == 1) {
7843 dut->config_rsnie = 0;
7844 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307845 }
7846#endif /* NL80211_SUPPORT */
7847
Sunil Duttfebf8a82018-02-09 18:50:13 +05307848 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7849 dut->dev_role = DEVROLE_STA_CFON;
7850 return sta_cfon_reset_default(dut, conn, cmd);
7851 }
7852
Jouni Malinen439352d2018-09-13 03:42:23 +03007853 wpa_command(intf, "SET setband AUTO");
7854
Sunil Duttfebf8a82018-02-09 18:50:13 +05307855 if (dut->program != PROGRAM_VHT)
7856 return cmd_sta_p2p_reset(dut, conn, cmd);
7857
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007858 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007859}
7860
7861
Jouni Malinenf7222712019-06-13 01:50:21 +03007862static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7863 struct sigma_conn *conn,
7864 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007865{
7866 const char *program = get_param(cmd, "Program");
7867
7868 if (program == NULL)
7869 return -1;
7870#ifdef ANDROID_NAN
7871 if (strcasecmp(program, "NAN") == 0)
7872 return nan_cmd_sta_get_events(dut, conn, cmd);
7873#endif /* ANDROID_NAN */
7874 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7875 return 0;
7876}
7877
7878
Jouni Malinen82905202018-04-29 17:20:10 +03007879static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7880 struct sigma_cmd *cmd)
7881{
7882 const char *url = get_param(cmd, "url");
7883 const char *method = get_param(cmd, "method");
7884 pid_t pid;
7885 int status;
7886
7887 if (!url || !method)
7888 return -1;
7889
7890 /* TODO: Add support for method,post */
7891 if (strcasecmp(method, "get") != 0) {
7892 send_resp(dut, conn, SIGMA_ERROR,
7893 "ErrorCode,Unsupported method");
7894 return 0;
7895 }
7896
7897 pid = fork();
7898 if (pid < 0) {
7899 perror("fork");
7900 return -1;
7901 }
7902
7903 if (pid == 0) {
7904 char * argv[5] = { "wget", "-O", "/dev/null",
7905 (char *) url, NULL };
7906
7907 execv("/usr/bin/wget", argv);
7908 perror("execv");
7909 exit(0);
7910 return -1;
7911 }
7912
7913 if (waitpid(pid, &status, 0) < 0) {
7914 perror("waitpid");
7915 return -1;
7916 }
7917
7918 if (WIFEXITED(status)) {
7919 const char *errmsg;
7920
7921 if (WEXITSTATUS(status) == 0)
7922 return 1;
7923 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7924 WEXITSTATUS(status));
7925 switch (WEXITSTATUS(status)) {
7926 case 4:
7927 errmsg = "errmsg,Network failure";
7928 break;
7929 case 8:
7930 errmsg = "errmsg,Server issued an error response";
7931 break;
7932 default:
7933 errmsg = "errmsg,Unknown failure from wget";
7934 break;
7935 }
7936 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7937 return 0;
7938 }
7939
7940 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7941 return 0;
7942}
7943
7944
Jouni Malinenf7222712019-06-13 01:50:21 +03007945static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7946 struct sigma_conn *conn,
7947 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007948{
7949 const char *program = get_param(cmd, "Prog");
7950
Jouni Malinen82905202018-04-29 17:20:10 +03007951 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007952 return -1;
7953#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007954 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007955 return nan_cmd_sta_exec_action(dut, conn, cmd);
7956#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007957
7958 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007959 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007960
7961 if (get_param(cmd, "url"))
7962 return sta_exec_action_url(dut, conn, cmd);
7963
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007964 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7965 return 0;
7966}
7967
7968
Jouni Malinenf7222712019-06-13 01:50:21 +03007969static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7970 struct sigma_conn *conn,
7971 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007972{
7973 const char *intf = get_param(cmd, "Interface");
7974 const char *val, *mcs32, *rate;
7975
7976 val = get_param(cmd, "GREENFIELD");
7977 if (val) {
7978 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7979 /* Enable GD */
7980 send_resp(dut, conn, SIGMA_ERROR,
7981 "ErrorCode,GF not supported");
7982 return 0;
7983 }
7984 }
7985
7986 val = get_param(cmd, "SGI20");
7987 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007988 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007989 case DRIVER_ATHEROS:
7990 ath_sta_set_sgi(dut, intf, val);
7991 break;
7992 default:
7993 send_resp(dut, conn, SIGMA_ERROR,
7994 "ErrorCode,SGI20 not supported");
7995 return 0;
7996 }
7997 }
7998
7999 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8000 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8001 if (mcs32 && rate) {
8002 /* TODO */
8003 send_resp(dut, conn, SIGMA_ERROR,
8004 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8005 return 0;
8006 } else if (mcs32 && !rate) {
8007 /* TODO */
8008 send_resp(dut, conn, SIGMA_ERROR,
8009 "ErrorCode,MCS32 not supported");
8010 return 0;
8011 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008012 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008013 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008014 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008015 ath_sta_set_11nrates(dut, intf, rate);
8016 break;
8017 default:
8018 send_resp(dut, conn, SIGMA_ERROR,
8019 "ErrorCode,MCS32_FIXEDRATE not supported");
8020 return 0;
8021 }
8022 }
8023
8024 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8025}
8026
8027
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008028static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8029 int mcs_config)
8030{
8031#ifdef NL80211_SUPPORT
8032 int ret;
8033
8034 switch (mcs_config) {
8035 case HE_80_MCS0_7:
8036 case HE_80_MCS0_9:
8037 case HE_80_MCS0_11:
8038 ret = sta_set_he_mcs(dut, intf, mcs_config);
8039 if (ret) {
8040 sigma_dut_print(dut, DUT_MSG_ERROR,
8041 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8042 mcs_config, ret);
8043 }
8044 break;
8045 default:
8046 sigma_dut_print(dut, DUT_MSG_ERROR,
8047 "cmd_set_max_he_mcs: Invalid mcs %d",
8048 mcs_config);
8049 break;
8050 }
8051#else /* NL80211_SUPPORT */
8052 sigma_dut_print(dut, DUT_MSG_ERROR,
8053 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8054#endif /* NL80211_SUPPORT */
8055}
8056
8057
Arif Hussain480d5f42019-03-12 14:40:42 -07008058static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8059 struct sigma_cmd *cmd)
8060{
8061#ifdef NL80211_SUPPORT
8062 struct nlattr *params;
8063 struct nlattr *attr;
8064 struct nlattr *attr1;
8065 struct nl_msg *msg;
8066 int ifindex, ret;
8067 const char *val;
8068 const char *intf = get_param(cmd, "Interface");
8069 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8070 wake_interval_mantissa = 512;
8071 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8072 protection = 0;
8073
8074 ifindex = if_nametoindex(intf);
8075 if (ifindex == 0) {
8076 sigma_dut_print(dut, DUT_MSG_ERROR,
8077 "%s: Index for interface %s failed",
8078 __func__, intf);
8079 return -1;
8080 }
8081
8082 val = get_param(cmd, "FlowType");
8083 if (val) {
8084 flow_type = atoi(val);
8085 if (flow_type != 0 && flow_type != 1) {
8086 sigma_dut_print(dut, DUT_MSG_ERROR,
8087 "TWT: Invalid FlowType %d", flow_type);
8088 return -1;
8089 }
8090 }
8091
8092 val = get_param(cmd, "TWT_Trigger");
8093 if (val) {
8094 twt_trigger = atoi(val);
8095 if (twt_trigger != 0 && twt_trigger != 1) {
8096 sigma_dut_print(dut, DUT_MSG_ERROR,
8097 "TWT: Invalid TWT_Trigger %d",
8098 twt_trigger);
8099 return -1;
8100 }
8101 }
8102
8103 val = get_param(cmd, "Protection");
8104 if (val) {
8105 protection = atoi(val);
8106 if (protection != 0 && protection != 1) {
8107 sigma_dut_print(dut, DUT_MSG_ERROR,
8108 "TWT: Invalid Protection %d",
8109 protection);
8110 return -1;
8111 }
8112 }
8113
8114 val = get_param(cmd, "TargetWakeTime");
8115 if (val)
8116 target_wake_time = atoi(val);
8117
8118 val = get_param(cmd, "WakeIntervalMantissa");
8119 if (val)
8120 wake_interval_mantissa = atoi(val);
8121
8122 val = get_param(cmd, "WakeIntervalExp");
8123 if (val)
8124 wake_interval_exp = atoi(val);
8125
8126 val = get_param(cmd, "NominalMinWakeDur");
8127 if (val)
8128 nominal_min_wake_dur = atoi(val);
8129
8130 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8131 NL80211_CMD_VENDOR)) ||
8132 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8133 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8134 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8135 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8136 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8137 !(params = nla_nest_start(
8138 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8139 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8140 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8141 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008142 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008143 (twt_trigger &&
8144 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008145 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8146 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008147 (protection &&
8148 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008149 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8150 target_wake_time) ||
8151 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8152 nominal_min_wake_dur) ||
8153 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8154 wake_interval_mantissa)) {
8155 sigma_dut_print(dut, DUT_MSG_ERROR,
8156 "%s: err in adding vendor_cmd and vendor_data",
8157 __func__);
8158 nlmsg_free(msg);
8159 return -1;
8160 }
8161 nla_nest_end(msg, attr1);
8162 nla_nest_end(msg, params);
8163 nla_nest_end(msg, attr);
8164
8165 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8166 if (ret) {
8167 sigma_dut_print(dut, DUT_MSG_ERROR,
8168 "%s: err in send_and_recv_msgs, ret=%d",
8169 __func__, ret);
8170 }
8171
8172 return ret;
8173#else /* NL80211_SUPPORT */
8174 sigma_dut_print(dut, DUT_MSG_ERROR,
8175 "TWT request cannot be done without NL80211_SUPPORT defined");
8176 return -1;
8177#endif /* NL80211_SUPPORT */
8178}
8179
8180
8181static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8182 struct sigma_cmd *cmd)
8183{
8184 #ifdef NL80211_SUPPORT
8185 struct nlattr *params;
8186 struct nlattr *attr;
8187 struct nlattr *attr1;
8188 int ifindex, ret;
8189 struct nl_msg *msg;
8190 const char *intf = get_param(cmd, "Interface");
8191
8192 ifindex = if_nametoindex(intf);
8193 if (ifindex == 0) {
8194 sigma_dut_print(dut, DUT_MSG_ERROR,
8195 "%s: Index for interface %s failed",
8196 __func__, intf);
8197 return -1;
8198 }
8199
8200 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8201 NL80211_CMD_VENDOR)) ||
8202 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8203 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8204 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8205 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8206 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8207 !(params = nla_nest_start(
8208 msg,
8209 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8210 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8211 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8212 sigma_dut_print(dut, DUT_MSG_ERROR,
8213 "%s: err in adding vendor_cmd and vendor_data",
8214 __func__);
8215 nlmsg_free(msg);
8216 return -1;
8217 }
8218 nla_nest_end(msg, attr1);
8219 nla_nest_end(msg, params);
8220 nla_nest_end(msg, attr);
8221
8222 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8223 if (ret) {
8224 sigma_dut_print(dut, DUT_MSG_ERROR,
8225 "%s: err in send_and_recv_msgs, ret=%d",
8226 __func__, ret);
8227 }
8228
8229 return ret;
8230#else /* NL80211_SUPPORT */
8231 sigma_dut_print(dut, DUT_MSG_ERROR,
8232 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8233 return -1;
8234#endif /* NL80211_SUPPORT */
8235}
8236
8237
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008238static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8239 struct sigma_cmd *cmd)
8240{
8241#ifdef NL80211_SUPPORT
8242 struct nlattr *params;
8243 struct nlattr *attr;
8244 struct nlattr *attr1;
8245 struct nl_msg *msg;
8246 int ifindex, ret;
8247 const char *val;
8248 const char *intf = get_param(cmd, "Interface");
8249 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8250 ulmu_data_dis = 0;
8251
8252 ifindex = if_nametoindex(intf);
8253 if (ifindex == 0) {
8254 sigma_dut_print(dut, DUT_MSG_ERROR,
8255 "%s: Index for interface %s failed",
8256 __func__, intf);
8257 return -1;
8258 }
8259 val = get_param(cmd, "OMCtrl_RxNSS");
8260 if (val)
8261 rx_nss = atoi(val);
8262
8263 val = get_param(cmd, "OMCtrl_ChnlWidth");
8264 if (val)
8265 ch_bw = atoi(val);
8266
8267 val = get_param(cmd, "OMCtrl_ULMUDisable");
8268 if (val)
8269 ulmu_dis = atoi(val);
8270
8271 val = get_param(cmd, "OMCtrl_TxNSTS");
8272 if (val)
8273 tx_nsts = atoi(val);
8274
8275 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8276 if (val)
8277 ulmu_data_dis = atoi(val);
8278
8279 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8280 NL80211_CMD_VENDOR)) ||
8281 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8282 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8283 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8284 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8285 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8286 !(params = nla_nest_start(
8287 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8288 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8289 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8290 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8291 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8292 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8293 ulmu_data_dis) ||
8294 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8295 ulmu_dis)) {
8296 sigma_dut_print(dut, DUT_MSG_ERROR,
8297 "%s: err in adding vendor_cmd and vendor_data",
8298 __func__);
8299 nlmsg_free(msg);
8300 return -1;
8301 }
8302 nla_nest_end(msg, attr1);
8303 nla_nest_end(msg, params);
8304 nla_nest_end(msg, attr);
8305
8306 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8307 if (ret) {
8308 sigma_dut_print(dut, DUT_MSG_ERROR,
8309 "%s: err in send_and_recv_msgs, ret=%d",
8310 __func__, ret);
8311 }
8312
8313 return ret;
8314#else /* NL80211_SUPPORT */
8315 sigma_dut_print(dut, DUT_MSG_ERROR,
8316 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8317 return -1;
8318#endif /* NL80211_SUPPORT */
8319}
8320
8321
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008322static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8323 struct sigma_conn *conn,
8324 struct sigma_cmd *cmd)
8325{
8326 const char *intf = get_param(cmd, "Interface");
8327 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008328 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008329 int tkip = -1;
8330 int wep = -1;
8331
Arif Hussaina37e9552018-06-20 17:05:59 -07008332 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008333 val = get_param(cmd, "SGI80");
8334 if (val) {
8335 int sgi80;
8336
8337 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008338 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008339 }
8340
8341 val = get_param(cmd, "TxBF");
8342 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008343 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008344 case DRIVER_WCN:
8345 if (sta_set_tx_beamformee(dut, intf, 1)) {
8346 send_resp(dut, conn, SIGMA_ERROR,
8347 "ErrorCode,Failed to set TX beamformee enable");
8348 return 0;
8349 }
8350 break;
8351 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008352 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008353 send_resp(dut, conn, SIGMA_ERROR,
8354 "ErrorCode,Setting vhtsubfee failed");
8355 return 0;
8356 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008357 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008358 send_resp(dut, conn, SIGMA_ERROR,
8359 "ErrorCode,Setting vhtsubfer failed");
8360 return 0;
8361 }
8362 break;
8363 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008364 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008365 "Unsupported driver type");
8366 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008367 }
8368 }
8369
8370 val = get_param(cmd, "MU_TxBF");
8371 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008372 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008373 case DRIVER_ATHEROS:
8374 ath_sta_set_txsp_stream(dut, intf, "1SS");
8375 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008376 run_iwpriv(dut, intf, "vhtmubfee 1");
8377 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308378 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008379 case DRIVER_WCN:
8380 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8381 send_resp(dut, conn, SIGMA_ERROR,
8382 "ErrorCode,Failed to set RX/TXSP_STREAM");
8383 return 0;
8384 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308385 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008386 default:
8387 sigma_dut_print(dut, DUT_MSG_ERROR,
8388 "Setting SP_STREAM not supported");
8389 break;
8390 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008391 }
8392
8393 val = get_param(cmd, "LDPC");
8394 if (val) {
8395 int ldpc;
8396
8397 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008398 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008399 }
8400
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008401 val = get_param(cmd, "BCC");
8402 if (val) {
8403 int bcc;
8404
8405 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8406 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8407 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008408 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008409 }
8410
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008411 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8412 if (val && dut->sta_nss == 1)
8413 cmd_set_max_he_mcs(dut, intf, atoi(val));
8414
8415 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8416 if (val && dut->sta_nss == 2)
8417 cmd_set_max_he_mcs(dut, intf, atoi(val));
8418
Arif Hussainac6c5112018-05-25 17:34:00 -07008419 val = get_param(cmd, "MCS_FixedRate");
8420 if (val) {
8421#ifdef NL80211_SUPPORT
8422 int mcs, ratecode = 0;
8423 enum he_mcs_config mcs_config;
8424 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008425 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008426
8427 ratecode = (0x07 & dut->sta_nss) << 5;
8428 mcs = atoi(val);
8429 /* Add the MCS to the ratecode */
8430 if (mcs >= 0 && mcs <= 11) {
8431 ratecode += mcs;
8432 if (dut->device_type == STA_testbed &&
8433 mcs > 7 && mcs <= 11) {
8434 if (mcs <= 9)
8435 mcs_config = HE_80_MCS0_9;
8436 else
8437 mcs_config = HE_80_MCS0_11;
8438 ret = sta_set_he_mcs(dut, intf, mcs_config);
8439 if (ret) {
8440 sigma_dut_print(dut, DUT_MSG_ERROR,
8441 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8442 mcs, mcs_config, ret);
8443 }
8444 }
8445 snprintf(buf, sizeof(buf),
8446 "iwpriv %s set_11ax_rate 0x%03x",
8447 intf, ratecode);
8448 if (system(buf) != 0) {
8449 sigma_dut_print(dut, DUT_MSG_ERROR,
8450 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8451 ratecode);
8452 }
8453 } else {
8454 sigma_dut_print(dut, DUT_MSG_ERROR,
8455 "MCS_FixedRate: HE MCS %d not supported",
8456 mcs);
8457 }
8458#else /* NL80211_SUPPORT */
8459 sigma_dut_print(dut, DUT_MSG_ERROR,
8460 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8461#endif /* NL80211_SUPPORT */
8462 }
8463
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008464 val = get_param(cmd, "opt_md_notif_ie");
8465 if (val) {
8466 char *result = NULL;
8467 char delim[] = ";";
8468 char token[30];
8469 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308470 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008471
Peng Xub8fc5cc2017-05-10 17:27:28 -07008472 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308473 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008474
8475 /* Extract the NSS information */
8476 if (result) {
8477 value = atoi(result);
8478 switch (value) {
8479 case 1:
8480 config_val = 1;
8481 break;
8482 case 2:
8483 config_val = 3;
8484 break;
8485 case 3:
8486 config_val = 7;
8487 break;
8488 case 4:
8489 config_val = 15;
8490 break;
8491 default:
8492 config_val = 3;
8493 break;
8494 }
8495
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008496 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8497 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008498
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008499 }
8500
8501 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308502 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008503 if (result) {
8504 value = atoi(result);
8505 switch (value) {
8506 case 20:
8507 config_val = 0;
8508 break;
8509 case 40:
8510 config_val = 1;
8511 break;
8512 case 80:
8513 config_val = 2;
8514 break;
8515 case 160:
8516 config_val = 3;
8517 break;
8518 default:
8519 config_val = 2;
8520 break;
8521 }
8522
8523 dut->chwidth = config_val;
8524
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008525 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008526 }
8527
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008528 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008529 }
8530
8531 val = get_param(cmd, "nss_mcs_cap");
8532 if (val) {
8533 int nss, mcs;
8534 char token[20];
8535 char *result = NULL;
8536 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308537 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008538
Peng Xub8fc5cc2017-05-10 17:27:28 -07008539 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308540 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308541 if (!result) {
8542 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008543 "NSS not specified");
8544 send_resp(dut, conn, SIGMA_ERROR,
8545 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308546 return 0;
8547 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008548 nss = atoi(result);
8549
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008550 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008551 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008552
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308553 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008554 if (result == NULL) {
8555 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008556 "MCS not specified");
8557 send_resp(dut, conn, SIGMA_ERROR,
8558 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008559 return 0;
8560 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308561 result = strtok_r(result, "-", &saveptr);
8562 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308563 if (!result) {
8564 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008565 "MCS not specified");
8566 send_resp(dut, conn, SIGMA_ERROR,
8567 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308568 return 0;
8569 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008570 mcs = atoi(result);
8571
Arif Hussaina37e9552018-06-20 17:05:59 -07008572 if (program && strcasecmp(program, "HE") == 0) {
8573#ifdef NL80211_SUPPORT
8574 enum he_mcs_config mcs_config;
8575 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008576
Arif Hussaina37e9552018-06-20 17:05:59 -07008577 if (mcs >= 0 && mcs <= 7) {
8578 mcs_config = HE_80_MCS0_7;
8579 } else if (mcs > 7 && mcs <= 9) {
8580 mcs_config = HE_80_MCS0_9;
8581 } else if (mcs > 9 && mcs <= 11) {
8582 mcs_config = HE_80_MCS0_11;
8583 } else {
8584 sigma_dut_print(dut, DUT_MSG_ERROR,
8585 "nss_mcs_cap: HE: Invalid mcs: %d",
8586 mcs);
8587 send_resp(dut, conn, SIGMA_ERROR,
8588 "errorCode,Invalid MCS");
8589 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008590 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008591
8592 ret = sta_set_he_mcs(dut, intf, mcs_config);
8593 if (ret) {
8594 sigma_dut_print(dut, DUT_MSG_ERROR,
8595 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8596 mcs_config, ret);
8597 send_resp(dut, conn, SIGMA_ERROR,
8598 "errorCode,Failed to set MCS");
8599 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008600 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008601#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008602 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008603 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8604#endif /* NL80211_SUPPORT */
8605 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008606 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008607
8608 switch (nss) {
8609 case 1:
8610 switch (mcs) {
8611 case 7:
8612 vht_mcsmap = 0xfffc;
8613 break;
8614 case 8:
8615 vht_mcsmap = 0xfffd;
8616 break;
8617 case 9:
8618 vht_mcsmap = 0xfffe;
8619 break;
8620 default:
8621 vht_mcsmap = 0xfffe;
8622 break;
8623 }
8624 break;
8625 case 2:
8626 switch (mcs) {
8627 case 7:
8628 vht_mcsmap = 0xfff0;
8629 break;
8630 case 8:
8631 vht_mcsmap = 0xfff5;
8632 break;
8633 case 9:
8634 vht_mcsmap = 0xfffa;
8635 break;
8636 default:
8637 vht_mcsmap = 0xfffa;
8638 break;
8639 }
8640 break;
8641 case 3:
8642 switch (mcs) {
8643 case 7:
8644 vht_mcsmap = 0xffc0;
8645 break;
8646 case 8:
8647 vht_mcsmap = 0xffd5;
8648 break;
8649 case 9:
8650 vht_mcsmap = 0xffea;
8651 break;
8652 default:
8653 vht_mcsmap = 0xffea;
8654 break;
8655 }
8656 break;
8657 default:
8658 vht_mcsmap = 0xffea;
8659 break;
8660 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008661 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008662 }
8663 }
8664
8665 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8666
8667 val = get_param(cmd, "Vht_tkip");
8668 if (val)
8669 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8670
8671 val = get_param(cmd, "Vht_wep");
8672 if (val)
8673 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8674
8675 if (tkip != -1 || wep != -1) {
8676 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008677 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008678 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008679 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008680 } else {
8681 sigma_dut_print(dut, DUT_MSG_ERROR,
8682 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8683 return 0;
8684 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008685 }
8686
Arif Hussain55f00da2018-07-03 08:28:26 -07008687 val = get_param(cmd, "txBandwidth");
8688 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008689 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008690 case DRIVER_WCN:
8691 if (wcn_sta_set_width(dut, intf, val) < 0) {
8692 send_resp(dut, conn, SIGMA_ERROR,
8693 "ErrorCode,Failed to set txBandwidth");
8694 return 0;
8695 }
8696 break;
8697 case DRIVER_ATHEROS:
8698 if (ath_set_width(dut, conn, intf, val) < 0) {
8699 send_resp(dut, conn, SIGMA_ERROR,
8700 "ErrorCode,Failed to set txBandwidth");
8701 return 0;
8702 }
8703 break;
8704 default:
8705 sigma_dut_print(dut, DUT_MSG_ERROR,
8706 "Setting txBandwidth not supported");
8707 break;
8708 }
8709 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008710
Arif Hussain9765f7d2018-07-03 08:28:26 -07008711 val = get_param(cmd, "BeamformeeSTS");
8712 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008713 if (sta_set_tx_beamformee(dut, intf, 1)) {
8714 send_resp(dut, conn, SIGMA_ERROR,
8715 "ErrorCode,Failed to set TX beamformee enable");
8716 return 0;
8717 }
8718
Arif Hussain9765f7d2018-07-03 08:28:26 -07008719 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8720 send_resp(dut, conn, SIGMA_ERROR,
8721 "ErrorCode,Failed to set BeamformeeSTS");
8722 return 0;
8723 }
8724 }
8725
Arif Hussain68d23f52018-07-11 13:39:08 -07008726 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8727 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008728#ifdef NL80211_SUPPORT
8729 enum qca_wlan_he_mac_padding_dur set_val;
8730
8731 switch (atoi(val)) {
8732 case 16:
8733 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8734 break;
8735 case 8:
8736 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8737 break;
8738 default:
8739 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8740 break;
8741 }
8742 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008743 send_resp(dut, conn, SIGMA_ERROR,
8744 "ErrorCode,Failed to set MAC padding duration");
8745 return 0;
8746 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008747#else /* NL80211_SUPPORT */
8748 sigma_dut_print(dut, DUT_MSG_ERROR,
8749 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8750#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008751 }
8752
Arif Hussain480d5f42019-03-12 14:40:42 -07008753 val = get_param(cmd, "TWT_ReqSupport");
8754 if (val) {
8755 int set_val;
8756
8757 if (strcasecmp(val, "Enable") == 0) {
8758 set_val = 1;
8759 } else if (strcasecmp(val, "Disable") == 0) {
8760 set_val = 0;
8761 } else {
8762 send_resp(dut, conn, SIGMA_ERROR,
8763 "ErrorCode,Invalid TWT_ReqSupport");
8764 return STATUS_SENT;
8765 }
8766
8767 if (sta_set_twt_req_support(dut, intf, set_val)) {
8768 sigma_dut_print(dut, DUT_MSG_ERROR,
8769 "Failed to set TWT req support %d",
8770 set_val);
8771 send_resp(dut, conn, SIGMA_ERROR,
8772 "ErrorCode,Failed to set TWT_ReqSupport");
8773 return STATUS_SENT;
8774 }
8775 }
8776
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008777 val = get_param(cmd, "MU_EDCA");
8778 if (val && (strcasecmp(val, "Override") == 0)) {
8779 if (sta_set_mu_edca_override(dut, intf, 1)) {
8780 send_resp(dut, conn, SIGMA_ERROR,
8781 "ErrorCode,Failed to set MU EDCA override");
8782 return 0;
8783 }
8784 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008785
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008786 val = get_param(cmd, "OMControl");
8787 if (val) {
8788 int set_val = 1;
8789
8790 if (strcasecmp(val, "Enable") == 0)
8791 set_val = 1;
8792 else if (strcasecmp(val, "Disable") == 0)
8793 set_val = 0;
8794
8795 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8796 send_resp(dut, conn, SIGMA_ERROR,
8797 "ErrorCode,Failed to set OM ctrl supp");
8798 return 0;
8799 }
8800 }
8801
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008802 val = get_param(cmd, "ADDBAResp_BufSize");
8803 if (val) {
8804 int buf_size;
8805
8806 if (strcasecmp(val, "gt64") == 0)
8807 buf_size = 256;
8808 else
8809 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008810 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008811 sta_set_addba_buf_size(dut, intf, buf_size)) {
8812 send_resp(dut, conn, SIGMA_ERROR,
8813 "ErrorCode,set addbaresp_buff_size failed");
8814 return 0;
8815 }
8816 }
8817
8818 val = get_param(cmd, "ADDBAReq_BufSize");
8819 if (val) {
8820 int buf_size;
8821
8822 if (strcasecmp(val, "gt64") == 0)
8823 buf_size = 256;
8824 else
8825 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008826 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008827 sta_set_addba_buf_size(dut, intf, buf_size)) {
8828 send_resp(dut, conn, SIGMA_ERROR,
8829 "ErrorCode,set addbareq_buff_size failed");
8830 return 0;
8831 }
8832 }
8833
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008834 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8835}
8836
8837
8838static int sta_set_wireless_60g(struct sigma_dut *dut,
8839 struct sigma_conn *conn,
8840 struct sigma_cmd *cmd)
8841{
8842 const char *dev_role = get_param(cmd, "DevRole");
8843
8844 if (!dev_role) {
8845 send_resp(dut, conn, SIGMA_INVALID,
8846 "ErrorCode,DevRole not specified");
8847 return 0;
8848 }
8849
8850 if (strcasecmp(dev_role, "PCP") == 0)
8851 return sta_set_60g_pcp(dut, conn, cmd);
8852 if (strcasecmp(dev_role, "STA") == 0)
8853 return sta_set_60g_sta(dut, conn, cmd);
8854 send_resp(dut, conn, SIGMA_INVALID,
8855 "ErrorCode,DevRole not supported");
8856 return 0;
8857}
8858
8859
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308860static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8861 struct sigma_cmd *cmd)
8862{
8863 int status;
8864 const char *intf = get_param(cmd, "Interface");
8865 const char *val = get_param(cmd, "DevRole");
8866
8867 if (val && strcasecmp(val, "STA-CFON") == 0) {
8868 status = sta_cfon_set_wireless(dut, conn, cmd);
8869 if (status)
8870 return status;
8871 }
8872 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8873}
8874
8875
Jouni Malinenf7222712019-06-13 01:50:21 +03008876static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
8877 struct sigma_conn *conn,
8878 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008879{
8880 const char *val;
8881
8882 val = get_param(cmd, "Program");
8883 if (val) {
8884 if (strcasecmp(val, "11n") == 0)
8885 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008886 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008887 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8888 if (strcasecmp(val, "60ghz") == 0)
8889 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308890 if (strcasecmp(val, "OCE") == 0)
8891 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008892 /* sta_set_wireless in WPS program is only used for 60G */
8893 if (is_60g_sigma_dut(dut))
8894 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008895 send_resp(dut, conn, SIGMA_ERROR,
8896 "ErrorCode,Program value not supported");
8897 } else {
8898 send_resp(dut, conn, SIGMA_ERROR,
8899 "ErrorCode,Program argument not available");
8900 }
8901
8902 return 0;
8903}
8904
8905
8906static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8907 int tid)
8908{
8909 char buf[100];
8910 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8911
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308912 if (tid < 0 ||
8913 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8914 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8915 return;
8916 }
8917
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008918 /*
8919 * Two ways to ensure that addba request with a
8920 * non zero TID could be sent out. EV 117296
8921 */
8922 snprintf(buf, sizeof(buf),
8923 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8924 tid);
8925 if (system(buf) != 0) {
8926 sigma_dut_print(dut, DUT_MSG_ERROR,
8927 "Ping did not send out");
8928 }
8929
8930 snprintf(buf, sizeof(buf),
8931 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8932 intf, VI_QOS_TMP_FILE);
8933 if (system(buf) != 0)
8934 return;
8935
8936 snprintf(buf, sizeof(buf),
8937 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8938 intf, VI_QOS_TMP_FILE);
8939 if (system(buf) != 0)
8940 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8941
8942 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8943 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8944 if (system(buf) != 0) {
8945 sigma_dut_print(dut, DUT_MSG_ERROR,
8946 "VI_QOS_TEMP_FILE generation error failed");
8947 }
8948 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8949 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8950 if (system(buf) != 0) {
8951 sigma_dut_print(dut, DUT_MSG_ERROR,
8952 "VI_QOS_FILE generation failed");
8953 }
8954
8955 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8956 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8957 if (system(buf) != 0) {
8958 sigma_dut_print(dut, DUT_MSG_ERROR,
8959 "VI_QOS_FILE generation failed");
8960 }
8961
8962 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8963 if (system(buf) != 0) {
8964 }
8965}
8966
8967
8968static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8969 struct sigma_cmd *cmd)
8970{
8971 const char *intf = get_param(cmd, "Interface");
8972 const char *val;
8973 int tid = 0;
8974 char buf[100];
8975
8976 val = get_param(cmd, "TID");
8977 if (val) {
8978 tid = atoi(val);
8979 if (tid)
8980 ath_sta_inject_frame(dut, intf, tid);
8981 }
8982
8983 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008984 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008985
8986 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8987 if (system(buf) != 0) {
8988 sigma_dut_print(dut, DUT_MSG_ERROR,
8989 "wifitool senddelba failed");
8990 }
8991
8992 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8993 if (system(buf) != 0) {
8994 sigma_dut_print(dut, DUT_MSG_ERROR,
8995 "wifitool sendaddba failed");
8996 }
8997
8998 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8999
9000 return 1;
9001}
9002
9003
Lior David9981b512017-01-20 13:16:40 +02009004#ifdef __linux__
9005
9006static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9007 int agg_size)
9008{
9009 char dir[128], buf[128];
9010 FILE *f;
9011 regex_t re;
9012 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009013 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009014
9015 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9016 sigma_dut_print(dut, DUT_MSG_ERROR,
9017 "failed to get wil6210 debugfs dir");
9018 return -1;
9019 }
9020
Jouni Malinen3aa72862019-05-29 23:14:51 +03009021 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9022 if (res < 0 || res >= sizeof(buf))
9023 return -1;
Lior David9981b512017-01-20 13:16:40 +02009024 f = fopen(buf, "r");
9025 if (!f) {
9026 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009027 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009028 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9029 if (res < 0 || res >= sizeof(buf))
9030 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009031 f = fopen(buf, "r");
9032 if (!f) {
9033 sigma_dut_print(dut, DUT_MSG_ERROR,
9034 "failed to open: %s", buf);
9035 return -1;
9036 }
Lior David9981b512017-01-20 13:16:40 +02009037 }
9038
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009039 /* can be either VRING tx... or RING... */
9040 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009041 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9042 goto out;
9043 }
9044
9045 /* find TX VRING for the mac address */
9046 found = 0;
9047 while (fgets(buf, sizeof(buf), f)) {
9048 if (strcasestr(buf, dest_mac)) {
9049 found = 1;
9050 break;
9051 }
9052 }
9053
9054 if (!found) {
9055 sigma_dut_print(dut, DUT_MSG_ERROR,
9056 "no TX VRING for %s", dest_mac);
9057 goto out;
9058 }
9059
9060 /* extract VRING ID, "VRING tx_<id> = {" */
9061 if (!fgets(buf, sizeof(buf), f)) {
9062 sigma_dut_print(dut, DUT_MSG_ERROR,
9063 "no VRING start line for %s", dest_mac);
9064 goto out;
9065 }
9066
9067 rc = regexec(&re, buf, 2, m, 0);
9068 regfree(&re);
9069 if (rc || m[1].rm_so < 0) {
9070 sigma_dut_print(dut, DUT_MSG_ERROR,
9071 "no VRING TX ID for %s", dest_mac);
9072 goto out;
9073 }
9074 buf[m[1].rm_eo] = 0;
9075 vring_id = atoi(&buf[m[1].rm_so]);
9076
9077 /* send the addba command */
9078 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009079 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9080 if (res < 0 || res >= sizeof(buf))
9081 return -1;
Lior David9981b512017-01-20 13:16:40 +02009082 f = fopen(buf, "w");
9083 if (!f) {
9084 sigma_dut_print(dut, DUT_MSG_ERROR,
9085 "failed to open: %s", buf);
9086 return -1;
9087 }
9088
9089 fprintf(f, "add %d %d\n", vring_id, agg_size);
9090
9091 ret = 0;
9092
9093out:
9094 fclose(f);
9095
9096 return ret;
9097}
9098
9099
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009100int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9101 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009102{
9103 const char *val;
9104 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009105
9106 val = get_param(cmd, "TID");
9107 if (val) {
9108 tid = atoi(val);
9109 if (tid != 0) {
9110 sigma_dut_print(dut, DUT_MSG_ERROR,
9111 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9112 tid);
9113 }
9114 }
9115
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009116 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009117 if (!val) {
9118 sigma_dut_print(dut, DUT_MSG_ERROR,
9119 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009120 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009121 }
9122
Lior David9981b512017-01-20 13:16:40 +02009123 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009124 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009125
9126 return 1;
9127}
9128
Lior David9981b512017-01-20 13:16:40 +02009129#endif /* __linux__ */
9130
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009131
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009132static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9133 struct sigma_cmd *cmd)
9134{
9135#ifdef NL80211_SUPPORT
9136 const char *intf = get_param(cmd, "Interface");
9137 const char *val;
9138 int tid = -1;
9139 int bufsize = 64;
9140 struct nl_msg *msg;
9141 int ret = 0;
9142 struct nlattr *params;
9143 int ifindex;
9144
9145 val = get_param(cmd, "TID");
9146 if (val)
9147 tid = atoi(val);
9148
9149 if (tid == -1) {
9150 send_resp(dut, conn, SIGMA_ERROR,
9151 "ErrorCode,sta_send_addba tid invalid");
9152 return 0;
9153 }
9154
9155 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9156
9157 ifindex = if_nametoindex(intf);
9158 if (ifindex == 0) {
9159 sigma_dut_print(dut, DUT_MSG_ERROR,
9160 "%s: Index for interface %s failed",
9161 __func__, intf);
9162 send_resp(dut, conn, SIGMA_ERROR,
9163 "ErrorCode,sta_send_addba interface invalid");
9164 return 0;
9165 }
9166
9167 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9168 NL80211_CMD_VENDOR)) ||
9169 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9170 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9171 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9172 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9173 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9174 nla_put_u8(msg,
9175 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9176 QCA_WLAN_ADD_BA) ||
9177 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9178 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009179 nla_put_u16(msg,
9180 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9181 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009182 sigma_dut_print(dut, DUT_MSG_ERROR,
9183 "%s: err in adding vendor_cmd and vendor_data",
9184 __func__);
9185 nlmsg_free(msg);
9186 send_resp(dut, conn, SIGMA_ERROR,
9187 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9188 return 0;
9189 }
9190 nla_nest_end(msg, params);
9191
9192 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9193 if (ret) {
9194 sigma_dut_print(dut, DUT_MSG_ERROR,
9195 "%s: err in send_and_recv_msgs, ret=%d",
9196 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309197 if (ret == -EOPNOTSUPP)
9198 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009199 send_resp(dut, conn, SIGMA_ERROR,
9200 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9201 return 0;
9202 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009203#else /* NL80211_SUPPORT */
9204 sigma_dut_print(dut, DUT_MSG_ERROR,
9205 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009206#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309207
9208 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009209}
9210
9211
Jouni Malinenf7222712019-06-13 01:50:21 +03009212static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9213 struct sigma_conn *conn,
9214 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009215{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009216 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009217 case DRIVER_ATHEROS:
9218 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009219 case DRIVER_WCN:
9220 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009221#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009222 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009223 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009224#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009225 default:
9226 /*
9227 * There is no driver specific implementation for other drivers.
9228 * Ignore the command and report COMPLETE since the following
9229 * throughput test operation will end up sending ADDBA anyway.
9230 */
9231 return 1;
9232 }
9233}
9234
9235
9236int inject_eth_frame(int s, const void *data, size_t len,
9237 unsigned short ethtype, char *dst, char *src)
9238{
9239 struct iovec iov[4] = {
9240 {
9241 .iov_base = dst,
9242 .iov_len = ETH_ALEN,
9243 },
9244 {
9245 .iov_base = src,
9246 .iov_len = ETH_ALEN,
9247 },
9248 {
9249 .iov_base = &ethtype,
9250 .iov_len = sizeof(unsigned short),
9251 },
9252 {
9253 .iov_base = (void *) data,
9254 .iov_len = len,
9255 }
9256 };
9257 struct msghdr msg = {
9258 .msg_name = NULL,
9259 .msg_namelen = 0,
9260 .msg_iov = iov,
9261 .msg_iovlen = 4,
9262 .msg_control = NULL,
9263 .msg_controllen = 0,
9264 .msg_flags = 0,
9265 };
9266
9267 return sendmsg(s, &msg, 0);
9268}
9269
9270#if defined(__linux__) || defined(__QNXNTO__)
9271
9272int inject_frame(int s, const void *data, size_t len, int encrypt)
9273{
9274#define IEEE80211_RADIOTAP_F_WEP 0x04
9275#define IEEE80211_RADIOTAP_F_FRAG 0x08
9276 unsigned char rtap_hdr[] = {
9277 0x00, 0x00, /* radiotap version */
9278 0x0e, 0x00, /* radiotap length */
9279 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9280 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9281 0x00, /* padding */
9282 0x00, 0x00, /* RX and TX flags to indicate that */
9283 0x00, 0x00, /* this is the injected frame directly */
9284 };
9285 struct iovec iov[2] = {
9286 {
9287 .iov_base = &rtap_hdr,
9288 .iov_len = sizeof(rtap_hdr),
9289 },
9290 {
9291 .iov_base = (void *) data,
9292 .iov_len = len,
9293 }
9294 };
9295 struct msghdr msg = {
9296 .msg_name = NULL,
9297 .msg_namelen = 0,
9298 .msg_iov = iov,
9299 .msg_iovlen = 2,
9300 .msg_control = NULL,
9301 .msg_controllen = 0,
9302 .msg_flags = 0,
9303 };
9304
9305 if (encrypt)
9306 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9307
9308 return sendmsg(s, &msg, 0);
9309}
9310
9311
9312int open_monitor(const char *ifname)
9313{
9314#ifdef __QNXNTO__
9315 struct sockaddr_dl ll;
9316 int s;
9317
9318 memset(&ll, 0, sizeof(ll));
9319 ll.sdl_family = AF_LINK;
9320 ll.sdl_index = if_nametoindex(ifname);
9321 if (ll.sdl_index == 0) {
9322 perror("if_nametoindex");
9323 return -1;
9324 }
9325 s = socket(PF_INET, SOCK_RAW, 0);
9326#else /* __QNXNTO__ */
9327 struct sockaddr_ll ll;
9328 int s;
9329
9330 memset(&ll, 0, sizeof(ll));
9331 ll.sll_family = AF_PACKET;
9332 ll.sll_ifindex = if_nametoindex(ifname);
9333 if (ll.sll_ifindex == 0) {
9334 perror("if_nametoindex");
9335 return -1;
9336 }
9337 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9338#endif /* __QNXNTO__ */
9339 if (s < 0) {
9340 perror("socket[PF_PACKET,SOCK_RAW]");
9341 return -1;
9342 }
9343
9344 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9345 perror("monitor socket bind");
9346 close(s);
9347 return -1;
9348 }
9349
9350 return s;
9351}
9352
9353
9354static int hex2num(char c)
9355{
9356 if (c >= '0' && c <= '9')
9357 return c - '0';
9358 if (c >= 'a' && c <= 'f')
9359 return c - 'a' + 10;
9360 if (c >= 'A' && c <= 'F')
9361 return c - 'A' + 10;
9362 return -1;
9363}
9364
9365
9366int hwaddr_aton(const char *txt, unsigned char *addr)
9367{
9368 int i;
9369
9370 for (i = 0; i < 6; i++) {
9371 int a, b;
9372
9373 a = hex2num(*txt++);
9374 if (a < 0)
9375 return -1;
9376 b = hex2num(*txt++);
9377 if (b < 0)
9378 return -1;
9379 *addr++ = (a << 4) | b;
9380 if (i < 5 && *txt++ != ':')
9381 return -1;
9382 }
9383
9384 return 0;
9385}
9386
9387#endif /* defined(__linux__) || defined(__QNXNTO__) */
9388
9389enum send_frame_type {
9390 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9391};
9392enum send_frame_protection {
9393 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9394};
9395
9396
9397static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9398 enum send_frame_type frame,
9399 enum send_frame_protection protected,
9400 const char *dest)
9401{
9402#ifdef __linux__
9403 unsigned char buf[1000], *pos;
9404 int s, res;
9405 char bssid[20], addr[20];
9406 char result[32], ssid[100];
9407 size_t ssid_len;
9408
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009409 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009410 sizeof(result)) < 0 ||
9411 strncmp(result, "COMPLETED", 9) != 0) {
9412 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9413 return 0;
9414 }
9415
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009416 if (get_wpa_status(get_station_ifname(dut), "bssid",
9417 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009418 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9419 "current BSSID");
9420 return 0;
9421 }
9422
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009423 if (get_wpa_status(get_station_ifname(dut), "address",
9424 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009425 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9426 "own MAC address");
9427 return 0;
9428 }
9429
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009430 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009431 < 0) {
9432 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9433 "current SSID");
9434 return 0;
9435 }
9436 ssid_len = strlen(ssid);
9437
9438 pos = buf;
9439
9440 /* Frame Control */
9441 switch (frame) {
9442 case DISASSOC:
9443 *pos++ = 0xa0;
9444 break;
9445 case DEAUTH:
9446 *pos++ = 0xc0;
9447 break;
9448 case SAQUERY:
9449 *pos++ = 0xd0;
9450 break;
9451 case AUTH:
9452 *pos++ = 0xb0;
9453 break;
9454 case ASSOCREQ:
9455 *pos++ = 0x00;
9456 break;
9457 case REASSOCREQ:
9458 *pos++ = 0x20;
9459 break;
9460 case DLS_REQ:
9461 *pos++ = 0xd0;
9462 break;
9463 }
9464
9465 if (protected == INCORRECT_KEY)
9466 *pos++ = 0x40; /* Set Protected field to 1 */
9467 else
9468 *pos++ = 0x00;
9469
9470 /* Duration */
9471 *pos++ = 0x00;
9472 *pos++ = 0x00;
9473
9474 /* addr1 = DA (current AP) */
9475 hwaddr_aton(bssid, pos);
9476 pos += 6;
9477 /* addr2 = SA (own address) */
9478 hwaddr_aton(addr, pos);
9479 pos += 6;
9480 /* addr3 = BSSID (current AP) */
9481 hwaddr_aton(bssid, pos);
9482 pos += 6;
9483
9484 /* Seq# (to be filled by driver/mac80211) */
9485 *pos++ = 0x00;
9486 *pos++ = 0x00;
9487
9488 if (protected == INCORRECT_KEY) {
9489 /* CCMP parameters */
9490 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9491 pos += 8;
9492 }
9493
9494 if (protected == INCORRECT_KEY) {
9495 switch (frame) {
9496 case DEAUTH:
9497 /* Reason code (encrypted) */
9498 memcpy(pos, "\xa7\x39", 2);
9499 pos += 2;
9500 break;
9501 case DISASSOC:
9502 /* Reason code (encrypted) */
9503 memcpy(pos, "\xa7\x39", 2);
9504 pos += 2;
9505 break;
9506 case SAQUERY:
9507 /* Category|Action|TransID (encrypted) */
9508 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9509 pos += 4;
9510 break;
9511 default:
9512 return -1;
9513 }
9514
9515 /* CCMP MIC */
9516 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9517 pos += 8;
9518 } else {
9519 switch (frame) {
9520 case DEAUTH:
9521 /* reason code = 8 */
9522 *pos++ = 0x08;
9523 *pos++ = 0x00;
9524 break;
9525 case DISASSOC:
9526 /* reason code = 8 */
9527 *pos++ = 0x08;
9528 *pos++ = 0x00;
9529 break;
9530 case SAQUERY:
9531 /* Category - SA Query */
9532 *pos++ = 0x08;
9533 /* SA query Action - Request */
9534 *pos++ = 0x00;
9535 /* Transaction ID */
9536 *pos++ = 0x12;
9537 *pos++ = 0x34;
9538 break;
9539 case AUTH:
9540 /* Auth Alg (Open) */
9541 *pos++ = 0x00;
9542 *pos++ = 0x00;
9543 /* Seq# */
9544 *pos++ = 0x01;
9545 *pos++ = 0x00;
9546 /* Status code */
9547 *pos++ = 0x00;
9548 *pos++ = 0x00;
9549 break;
9550 case ASSOCREQ:
9551 /* Capability Information */
9552 *pos++ = 0x31;
9553 *pos++ = 0x04;
9554 /* Listen Interval */
9555 *pos++ = 0x0a;
9556 *pos++ = 0x00;
9557 /* SSID */
9558 *pos++ = 0x00;
9559 *pos++ = ssid_len;
9560 memcpy(pos, ssid, ssid_len);
9561 pos += ssid_len;
9562 /* Supported Rates */
9563 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9564 10);
9565 pos += 10;
9566 /* Extended Supported Rates */
9567 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9568 pos += 6;
9569 /* RSN */
9570 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9571 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9572 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9573 pos += 28;
9574 break;
9575 case REASSOCREQ:
9576 /* Capability Information */
9577 *pos++ = 0x31;
9578 *pos++ = 0x04;
9579 /* Listen Interval */
9580 *pos++ = 0x0a;
9581 *pos++ = 0x00;
9582 /* Current AP */
9583 hwaddr_aton(bssid, pos);
9584 pos += 6;
9585 /* SSID */
9586 *pos++ = 0x00;
9587 *pos++ = ssid_len;
9588 memcpy(pos, ssid, ssid_len);
9589 pos += ssid_len;
9590 /* Supported Rates */
9591 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9592 10);
9593 pos += 10;
9594 /* Extended Supported Rates */
9595 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9596 pos += 6;
9597 /* RSN */
9598 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9599 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9600 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9601 pos += 28;
9602 break;
9603 case DLS_REQ:
9604 /* Category - DLS */
9605 *pos++ = 0x02;
9606 /* DLS Action - Request */
9607 *pos++ = 0x00;
9608 /* Destination MACAddress */
9609 if (dest)
9610 hwaddr_aton(dest, pos);
9611 else
9612 memset(pos, 0, 6);
9613 pos += 6;
9614 /* Source MACAddress */
9615 hwaddr_aton(addr, pos);
9616 pos += 6;
9617 /* Capability Information */
9618 *pos++ = 0x10; /* Privacy */
9619 *pos++ = 0x06; /* QoS */
9620 /* DLS Timeout Value */
9621 *pos++ = 0x00;
9622 *pos++ = 0x01;
9623 /* Supported rates */
9624 *pos++ = 0x01;
9625 *pos++ = 0x08;
9626 *pos++ = 0x0c; /* 6 Mbps */
9627 *pos++ = 0x12; /* 9 Mbps */
9628 *pos++ = 0x18; /* 12 Mbps */
9629 *pos++ = 0x24; /* 18 Mbps */
9630 *pos++ = 0x30; /* 24 Mbps */
9631 *pos++ = 0x48; /* 36 Mbps */
9632 *pos++ = 0x60; /* 48 Mbps */
9633 *pos++ = 0x6c; /* 54 Mbps */
9634 /* TODO: Extended Supported Rates */
9635 /* TODO: HT Capabilities */
9636 break;
9637 }
9638 }
9639
9640 s = open_monitor("sigmadut");
9641 if (s < 0) {
9642 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9643 "monitor socket");
9644 return 0;
9645 }
9646
9647 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9648 if (res < 0) {
9649 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9650 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309651 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009652 return 0;
9653 }
9654 if (res < pos - buf) {
9655 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9656 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309657 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009658 return 0;
9659 }
9660
9661 close(s);
9662
9663 return 1;
9664#else /* __linux__ */
9665 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9666 "yet supported");
9667 return 0;
9668#endif /* __linux__ */
9669}
9670
9671
9672static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9673 struct sigma_conn *conn,
9674 struct sigma_cmd *cmd)
9675{
9676 const char *intf = get_param(cmd, "Interface");
9677 const char *sta, *val;
9678 unsigned char addr[ETH_ALEN];
9679 char buf[100];
9680
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009681 if (!intf)
9682 return -1;
9683
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009684 sta = get_param(cmd, "peer");
9685 if (sta == NULL)
9686 sta = get_param(cmd, "station");
9687 if (sta == NULL) {
9688 send_resp(dut, conn, SIGMA_ERROR,
9689 "ErrorCode,Missing peer address");
9690 return 0;
9691 }
9692 if (hwaddr_aton(sta, addr) < 0) {
9693 send_resp(dut, conn, SIGMA_ERROR,
9694 "ErrorCode,Invalid peer address");
9695 return 0;
9696 }
9697
9698 val = get_param(cmd, "type");
9699 if (val == NULL)
9700 return -1;
9701
9702 if (strcasecmp(val, "DISCOVERY") == 0) {
9703 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9704 if (wpa_command(intf, buf) < 0) {
9705 send_resp(dut, conn, SIGMA_ERROR,
9706 "ErrorCode,Failed to send TDLS discovery");
9707 return 0;
9708 }
9709 return 1;
9710 }
9711
9712 if (strcasecmp(val, "SETUP") == 0) {
9713 int status = 0, timeout = 0;
9714
9715 val = get_param(cmd, "Status");
9716 if (val)
9717 status = atoi(val);
9718
9719 val = get_param(cmd, "Timeout");
9720 if (val)
9721 timeout = atoi(val);
9722
9723 if (status != 0 && status != 37) {
9724 send_resp(dut, conn, SIGMA_ERROR,
9725 "ErrorCode,Unsupported status value");
9726 return 0;
9727 }
9728
9729 if (timeout != 0 && timeout != 301) {
9730 send_resp(dut, conn, SIGMA_ERROR,
9731 "ErrorCode,Unsupported timeout value");
9732 return 0;
9733 }
9734
9735 if (status && timeout) {
9736 send_resp(dut, conn, SIGMA_ERROR,
9737 "ErrorCode,Unsupported timeout+status "
9738 "combination");
9739 return 0;
9740 }
9741
9742 if (status == 37 &&
9743 wpa_command(intf, "SET tdls_testing 0x200")) {
9744 send_resp(dut, conn, SIGMA_ERROR,
9745 "ErrorCode,Failed to enable "
9746 "decline setup response test mode");
9747 return 0;
9748 }
9749
9750 if (timeout == 301) {
9751 int res;
9752 if (dut->no_tpk_expiration)
9753 res = wpa_command(intf,
9754 "SET tdls_testing 0x108");
9755 else
9756 res = wpa_command(intf,
9757 "SET tdls_testing 0x8");
9758 if (res) {
9759 send_resp(dut, conn, SIGMA_ERROR,
9760 "ErrorCode,Failed to set short TPK "
9761 "lifetime");
9762 return 0;
9763 }
9764 }
9765
9766 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9767 if (wpa_command(intf, buf) < 0) {
9768 send_resp(dut, conn, SIGMA_ERROR,
9769 "ErrorCode,Failed to send TDLS setup");
9770 return 0;
9771 }
9772 return 1;
9773 }
9774
9775 if (strcasecmp(val, "TEARDOWN") == 0) {
9776 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9777 if (wpa_command(intf, buf) < 0) {
9778 send_resp(dut, conn, SIGMA_ERROR,
9779 "ErrorCode,Failed to send TDLS teardown");
9780 return 0;
9781 }
9782 return 1;
9783 }
9784
9785 send_resp(dut, conn, SIGMA_ERROR,
9786 "ErrorCode,Unsupported TDLS frame");
9787 return 0;
9788}
9789
9790
9791static int sta_ap_known(const char *ifname, const char *bssid)
9792{
9793 char buf[4096];
9794
Jouni Malinendd32f192018-09-15 02:55:19 +03009795 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009796 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9797 return 0;
9798 if (strncmp(buf, "id=", 3) != 0)
9799 return 0;
9800 return 1;
9801}
9802
9803
9804static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9805 const char *bssid)
9806{
9807 int res;
9808 struct wpa_ctrl *ctrl;
9809 char buf[256];
9810
9811 if (sta_ap_known(ifname, bssid))
9812 return 0;
9813 sigma_dut_print(dut, DUT_MSG_DEBUG,
9814 "AP not in BSS table - start scan");
9815
9816 ctrl = open_wpa_mon(ifname);
9817 if (ctrl == NULL) {
9818 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9819 "wpa_supplicant monitor connection");
9820 return -1;
9821 }
9822
9823 if (wpa_command(ifname, "SCAN") < 0) {
9824 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9825 wpa_ctrl_detach(ctrl);
9826 wpa_ctrl_close(ctrl);
9827 return -1;
9828 }
9829
9830 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9831 buf, sizeof(buf));
9832
9833 wpa_ctrl_detach(ctrl);
9834 wpa_ctrl_close(ctrl);
9835
9836 if (res < 0) {
9837 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9838 return -1;
9839 }
9840
9841 if (sta_ap_known(ifname, bssid))
9842 return 0;
9843 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9844 return -1;
9845}
9846
9847
9848static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9849 struct sigma_conn *conn,
9850 struct sigma_cmd *cmd,
9851 const char *intf)
9852{
9853 char buf[200];
9854
9855 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9856 if (system(buf) != 0) {
9857 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9858 "ndsend");
9859 return 0;
9860 }
9861
9862 return 1;
9863}
9864
9865
9866static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9867 struct sigma_conn *conn,
9868 struct sigma_cmd *cmd,
9869 const char *intf)
9870{
9871 char buf[200];
9872 const char *ip = get_param(cmd, "SenderIP");
9873
Peng Xu26b356d2017-10-04 17:58:16 -07009874 if (!ip)
9875 return 0;
9876
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009877 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9878 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9879 if (system(buf) == 0) {
9880 sigma_dut_print(dut, DUT_MSG_INFO,
9881 "Neighbor Solicitation got a response "
9882 "for %s@%s", ip, intf);
9883 }
9884
9885 return 1;
9886}
9887
9888
9889static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9890 struct sigma_conn *conn,
9891 struct sigma_cmd *cmd,
9892 const char *ifname)
9893{
9894 char buf[200];
9895 const char *ip = get_param(cmd, "SenderIP");
9896
9897 if (ip == NULL) {
9898 send_resp(dut, conn, SIGMA_ERROR,
9899 "ErrorCode,Missing SenderIP parameter");
9900 return 0;
9901 }
9902 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9903 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9904 if (system(buf) != 0) {
9905 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9906 "for %s@%s", ip, ifname);
9907 }
9908
9909 return 1;
9910}
9911
9912
9913static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9914 struct sigma_conn *conn,
9915 struct sigma_cmd *cmd,
9916 const char *ifname)
9917{
9918 char buf[200];
9919 char ip[16];
9920 int s;
Peng Xub3756882017-10-04 14:39:09 -07009921 struct ifreq ifr;
9922 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009923
9924 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009925 if (s < 0) {
9926 perror("socket");
9927 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009928 }
9929
Peng Xub3756882017-10-04 14:39:09 -07009930 memset(&ifr, 0, sizeof(ifr));
9931 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9932 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9933 sigma_dut_print(dut, DUT_MSG_INFO,
9934 "Failed to get %s IP address: %s",
9935 ifname, strerror(errno));
9936 close(s);
9937 return -1;
9938 }
9939 close(s);
9940
9941 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9942 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9943
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009944 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9945 ip);
9946 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9947 if (system(buf) != 0) {
9948 }
9949
9950 return 1;
9951}
9952
9953
9954static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9955 struct sigma_conn *conn,
9956 struct sigma_cmd *cmd,
9957 const char *ifname)
9958{
9959 char buf[200], addr[20];
9960 char dst[ETH_ALEN], src[ETH_ALEN];
9961 short ethtype = htons(ETH_P_ARP);
9962 char *pos;
9963 int s, res;
9964 const char *val;
9965 struct sockaddr_in taddr;
9966
9967 val = get_param(cmd, "dest");
9968 if (val)
9969 hwaddr_aton(val, (unsigned char *) dst);
9970
9971 val = get_param(cmd, "DestIP");
9972 if (val)
9973 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009974 else
9975 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009976
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009977 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009978 sizeof(addr)) < 0)
9979 return -2;
9980 hwaddr_aton(addr, (unsigned char *) src);
9981
9982 pos = buf;
9983 *pos++ = 0x00;
9984 *pos++ = 0x01;
9985 *pos++ = 0x08;
9986 *pos++ = 0x00;
9987 *pos++ = 0x06;
9988 *pos++ = 0x04;
9989 *pos++ = 0x00;
9990 *pos++ = 0x02;
9991 memcpy(pos, src, ETH_ALEN);
9992 pos += ETH_ALEN;
9993 memcpy(pos, &taddr.sin_addr, 4);
9994 pos += 4;
9995 memcpy(pos, dst, ETH_ALEN);
9996 pos += ETH_ALEN;
9997 memcpy(pos, &taddr.sin_addr, 4);
9998 pos += 4;
9999
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010000 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010001 if (s < 0) {
10002 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10003 "monitor socket");
10004 return 0;
10005 }
10006
10007 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10008 if (res < 0) {
10009 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10010 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010011 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010012 return 0;
10013 }
10014
10015 close(s);
10016
10017 return 1;
10018}
10019
10020
10021static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10022 struct sigma_conn *conn,
10023 struct sigma_cmd *cmd,
10024 const char *intf, const char *dest)
10025{
10026 char buf[100];
10027
10028 if (if_nametoindex("sigmadut") == 0) {
10029 snprintf(buf, sizeof(buf),
10030 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010031 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010032 if (system(buf) != 0 ||
10033 if_nametoindex("sigmadut") == 0) {
10034 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10035 "monitor interface with '%s'", buf);
10036 return -2;
10037 }
10038 }
10039
10040 if (system("ifconfig sigmadut up") != 0) {
10041 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10042 "monitor interface up");
10043 return -2;
10044 }
10045
10046 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10047}
10048
10049
10050static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10051 struct sigma_conn *conn,
10052 struct sigma_cmd *cmd)
10053{
10054 const char *intf = get_param(cmd, "Interface");
10055 const char *dest = get_param(cmd, "Dest");
10056 const char *type = get_param(cmd, "FrameName");
10057 const char *val;
10058 char buf[200], *pos, *end;
10059 int count, count2;
10060
10061 if (type == NULL)
10062 type = get_param(cmd, "Type");
10063
10064 if (intf == NULL || dest == NULL || type == NULL)
10065 return -1;
10066
10067 if (strcasecmp(type, "NeighAdv") == 0)
10068 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10069
10070 if (strcasecmp(type, "NeighSolicitReq") == 0)
10071 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10072
10073 if (strcasecmp(type, "ARPProbe") == 0)
10074 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10075
10076 if (strcasecmp(type, "ARPAnnounce") == 0)
10077 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10078
10079 if (strcasecmp(type, "ARPReply") == 0)
10080 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10081
10082 if (strcasecmp(type, "DLS-request") == 0 ||
10083 strcasecmp(type, "DLSrequest") == 0)
10084 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10085 dest);
10086
10087 if (strcasecmp(type, "ANQPQuery") != 0 &&
10088 strcasecmp(type, "Query") != 0) {
10089 send_resp(dut, conn, SIGMA_ERROR,
10090 "ErrorCode,Unsupported HS 2.0 send frame type");
10091 return 0;
10092 }
10093
10094 if (sta_scan_ap(dut, intf, dest) < 0) {
10095 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10096 "the requested AP");
10097 return 0;
10098 }
10099
10100 pos = buf;
10101 end = buf + sizeof(buf);
10102 count = 0;
10103 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10104
10105 val = get_param(cmd, "ANQP_CAP_LIST");
10106 if (val && atoi(val)) {
10107 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10108 count++;
10109 }
10110
10111 val = get_param(cmd, "VENUE_NAME");
10112 if (val && atoi(val)) {
10113 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10114 count++;
10115 }
10116
10117 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10118 if (val && atoi(val)) {
10119 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10120 count++;
10121 }
10122
10123 val = get_param(cmd, "ROAMING_CONS");
10124 if (val && atoi(val)) {
10125 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10126 count++;
10127 }
10128
10129 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10130 if (val && atoi(val)) {
10131 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10132 count++;
10133 }
10134
10135 val = get_param(cmd, "NAI_REALM_LIST");
10136 if (val && atoi(val)) {
10137 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10138 count++;
10139 }
10140
10141 val = get_param(cmd, "3GPP_INFO");
10142 if (val && atoi(val)) {
10143 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10144 count++;
10145 }
10146
10147 val = get_param(cmd, "DOMAIN_LIST");
10148 if (val && atoi(val)) {
10149 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10150 count++;
10151 }
10152
Jouni Malinen34cf9532018-04-29 19:26:33 +030010153 val = get_param(cmd, "Venue_URL");
10154 if (val && atoi(val)) {
10155 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10156 count++;
10157 }
10158
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010159 val = get_param(cmd, "Advice_Of_Charge");
10160 if (val && atoi(val)) {
10161 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10162 count++;
10163 }
10164
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010165 if (count && wpa_command(intf, buf)) {
10166 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10167 return 0;
10168 }
10169
10170 pos = buf;
10171 end = buf + sizeof(buf);
10172 count2 = 0;
10173 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10174
10175 val = get_param(cmd, "HS_CAP_LIST");
10176 if (val && atoi(val)) {
10177 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10178 count2++;
10179 }
10180
10181 val = get_param(cmd, "OPER_NAME");
10182 if (val && atoi(val)) {
10183 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10184 count2++;
10185 }
10186
10187 val = get_param(cmd, "WAN_METRICS");
10188 if (!val)
10189 val = get_param(cmd, "WAN_MAT");
10190 if (!val)
10191 val = get_param(cmd, "WAN_MET");
10192 if (val && atoi(val)) {
10193 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10194 count2++;
10195 }
10196
10197 val = get_param(cmd, "CONNECTION_CAPABILITY");
10198 if (val && atoi(val)) {
10199 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10200 count2++;
10201 }
10202
10203 val = get_param(cmd, "OP_CLASS");
10204 if (val && atoi(val)) {
10205 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10206 count2++;
10207 }
10208
10209 val = get_param(cmd, "OSU_PROVIDER_LIST");
10210 if (val && atoi(val)) {
10211 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10212 count2++;
10213 }
10214
Jouni Malinenf67afec2018-04-29 19:24:58 +030010215 val = get_param(cmd, "OPER_ICON_METADATA");
10216 if (!val)
10217 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10218 if (val && atoi(val)) {
10219 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10220 count2++;
10221 }
10222
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010223 if (count && count2) {
10224 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10225 "second query");
10226 sleep(1);
10227 }
10228
10229 if (count2 && wpa_command(intf, buf)) {
10230 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10231 "failed");
10232 return 0;
10233 }
10234
10235 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10236 if (val) {
10237 if (count || count2) {
10238 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10239 "sending out second query");
10240 sleep(1);
10241 }
10242
10243 if (strcmp(val, "1") == 0)
10244 val = "mail.example.com";
10245 snprintf(buf, end - pos,
10246 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10247 dest, val);
10248 if (wpa_command(intf, buf)) {
10249 send_resp(dut, conn, SIGMA_ERROR,
10250 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10251 "failed");
10252 return 0;
10253 }
10254 }
10255
10256 val = get_param(cmd, "ICON_REQUEST");
10257 if (val) {
10258 if (count || count2) {
10259 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10260 "sending out second query");
10261 sleep(1);
10262 }
10263
10264 snprintf(buf, end - pos,
10265 "HS20_ICON_REQUEST %s %s", dest, val);
10266 if (wpa_command(intf, buf)) {
10267 send_resp(dut, conn, SIGMA_ERROR,
10268 "ErrorCode,HS20_ICON_REQUEST failed");
10269 return 0;
10270 }
10271 }
10272
10273 return 1;
10274}
10275
10276
10277static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10278 struct sigma_conn *conn,
10279 struct sigma_cmd *cmd)
10280{
10281 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010282 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010283 int chwidth, nss;
10284
10285 val = get_param(cmd, "framename");
10286 if (!val)
10287 return -1;
10288 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10289
10290 /* Command sequence to generate Op mode notification */
10291 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010292 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010293
10294 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010295 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010296
10297 /* Extract Channel width */
10298 val = get_param(cmd, "Channel_width");
10299 if (val) {
10300 switch (atoi(val)) {
10301 case 20:
10302 chwidth = 0;
10303 break;
10304 case 40:
10305 chwidth = 1;
10306 break;
10307 case 80:
10308 chwidth = 2;
10309 break;
10310 case 160:
10311 chwidth = 3;
10312 break;
10313 default:
10314 chwidth = 2;
10315 break;
10316 }
10317
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010318 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010319 }
10320
10321 /* Extract NSS */
10322 val = get_param(cmd, "NSS");
10323 if (val) {
10324 switch (atoi(val)) {
10325 case 1:
10326 nss = 1;
10327 break;
10328 case 2:
10329 nss = 3;
10330 break;
10331 case 3:
10332 nss = 7;
10333 break;
10334 default:
10335 /* We do not support NSS > 3 */
10336 nss = 3;
10337 break;
10338 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010339 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010340 }
10341
10342 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010343 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010344 }
10345
10346 return 1;
10347}
10348
10349
10350static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10351 struct sigma_conn *conn,
10352 struct sigma_cmd *cmd)
10353{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010354 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010355 case DRIVER_ATHEROS:
10356 return ath_sta_send_frame_vht(dut, conn, cmd);
10357 default:
10358 send_resp(dut, conn, SIGMA_ERROR,
10359 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10360 return 0;
10361 }
10362}
10363
10364
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010365static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10366 struct sigma_cmd *cmd)
10367{
10368 const char *val;
10369 const char *intf = get_param(cmd, "Interface");
10370
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010371 if (!intf)
10372 return -1;
10373
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010374 val = get_param(cmd, "framename");
10375 if (!val)
10376 return -1;
10377 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10378
10379 /* Command sequence to generate Op mode notification */
10380 if (val && strcasecmp(val, "action") == 0) {
10381 val = get_param(cmd, "PPDUTxType");
10382 if (val && strcasecmp(val, "TB") == 0) {
10383 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10384 sigma_dut_print(dut, DUT_MSG_ERROR,
10385 "failed to send TB PPDU Tx cfg");
10386 send_resp(dut, conn, SIGMA_ERROR,
10387 "ErrorCode,set TB PPDU Tx cfg failed");
10388 return 0;
10389 }
10390 return 1;
10391 }
10392
10393 sigma_dut_print(dut, DUT_MSG_ERROR,
10394 "Action Tx type is not defined");
10395 }
10396
10397 return 1;
10398}
10399
10400
10401static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10402 struct sigma_conn *conn,
10403 struct sigma_cmd *cmd)
10404{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010405 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010406 case DRIVER_WCN:
10407 return wcn_sta_send_frame_he(dut, conn, cmd);
10408 default:
10409 send_resp(dut, conn, SIGMA_ERROR,
10410 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10411 return 0;
10412 }
10413}
10414
10415
Lior David0fe101e2017-03-09 16:09:50 +020010416#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010417
10418static int
10419wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10420 const char *frame_name, const char *dest_mac)
10421{
10422 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10423 const char *ssid = get_param(cmd, "ssid");
10424 const char *countstr = get_param(cmd, "count");
10425 const char *channelstr = get_param(cmd, "channel");
10426 const char *group_id = get_param(cmd, "groupid");
10427 const char *client_id = get_param(cmd, "clientmac");
10428 int count, channel, freq, i;
10429 const char *fname;
10430 char frame[1024], src_mac[20], group_id_attr[25],
10431 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10432 const char *group_ssid;
10433 const int group_ssid_prefix_len = 9;
10434 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10435 size_t framelen = sizeof(frame);
10436 struct template_frame_tag tags[2];
10437 size_t tags_total = ARRAY_SIZE(tags);
10438 int tag_index, len, dst_len;
10439
10440 if (!countstr || !channelstr) {
10441 sigma_dut_print(dut, DUT_MSG_ERROR,
10442 "Missing argument: count, channel");
10443 return -1;
10444 }
10445 if (isprobereq && !ssid) {
10446 sigma_dut_print(dut, DUT_MSG_ERROR,
10447 "Missing argument: ssid");
10448 return -1;
10449 }
10450 if (!isprobereq && (!group_id || !client_id)) {
10451 sigma_dut_print(dut, DUT_MSG_ERROR,
10452 "Missing argument: group_id, client_id");
10453 return -1;
10454 }
10455
10456 count = atoi(countstr);
10457 channel = atoi(channelstr);
10458 freq = channel_to_freq(dut, channel);
10459
10460 if (!freq) {
10461 sigma_dut_print(dut, DUT_MSG_ERROR,
10462 "invalid channel: %s", channelstr);
10463 return -1;
10464 }
10465
10466 if (isprobereq) {
10467 if (strcasecmp(ssid, "wildcard") == 0) {
10468 fname = "probe_req_wildcard.txt";
10469 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10470 fname = "probe_req_P2P_Wildcard.txt";
10471 } else {
10472 sigma_dut_print(dut, DUT_MSG_ERROR,
10473 "invalid probe request type");
10474 return -1;
10475 }
10476 } else {
10477 fname = "P2P_device_discovery_req.txt";
10478 }
10479
10480 if (parse_template_frame_file(dut, fname, frame, &framelen,
10481 tags, &tags_total)) {
10482 sigma_dut_print(dut, DUT_MSG_ERROR,
10483 "invalid frame template: %s", fname);
10484 return -1;
10485 }
10486
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010487 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010488 src_mac, sizeof(src_mac)) < 0 ||
10489 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10490 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10491 return -1;
10492 /* Use wildcard BSSID, since we are in PBSS */
10493 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10494
10495 if (!isprobereq) {
10496 tag_index = find_template_frame_tag(tags, tags_total, 1);
10497 if (tag_index < 0) {
10498 sigma_dut_print(dut, DUT_MSG_ERROR,
10499 "can't find device id attribute");
10500 return -1;
10501 }
10502 if (parse_mac_address(dut, client_id,
10503 (unsigned char *) client_mac)) {
10504 sigma_dut_print(dut, DUT_MSG_ERROR,
10505 "invalid client_id: %s", client_id);
10506 return -1;
10507 }
10508 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10509 framelen - tags[tag_index].offset,
10510 IEEE80211_P2P_ATTR_DEVICE_ID,
10511 client_mac, ETH_ALEN)) {
10512 sigma_dut_print(dut, DUT_MSG_ERROR,
10513 "fail to replace device id attribute");
10514 return -1;
10515 }
10516
10517 /*
10518 * group_id arg contains device MAC address followed by
10519 * space and SSID (DIRECT-somessid).
10520 * group id attribute contains device address (6 bytes)
10521 * followed by SSID prefix DIRECT-XX (9 bytes)
10522 */
10523 if (strlen(group_id) < sizeof(device_macstr)) {
10524 sigma_dut_print(dut, DUT_MSG_ERROR,
10525 "group_id arg too short");
10526 return -1;
10527 }
10528 memcpy(device_macstr, group_id, sizeof(device_macstr));
10529 device_macstr[sizeof(device_macstr) - 1] = '\0';
10530 if (parse_mac_address(dut, device_macstr,
10531 (unsigned char *) group_id_attr)) {
10532 sigma_dut_print(dut, DUT_MSG_ERROR,
10533 "fail to parse device address from group_id");
10534 return -1;
10535 }
10536 group_ssid = strchr(group_id, ' ');
10537 if (!group_ssid) {
10538 sigma_dut_print(dut, DUT_MSG_ERROR,
10539 "invalid group_id arg, no ssid");
10540 return -1;
10541 }
10542 group_ssid++;
10543 len = strlen(group_ssid);
10544 if (len < group_ssid_prefix_len) {
10545 sigma_dut_print(dut, DUT_MSG_ERROR,
10546 "group_id SSID too short");
10547 return -1;
10548 }
10549 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10550 if (len > dst_len) {
10551 sigma_dut_print(dut, DUT_MSG_ERROR,
10552 "group_id SSID (%s) too long",
10553 group_ssid);
10554 return -1;
10555 }
10556
10557 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10558 tag_index = find_template_frame_tag(tags, tags_total, 2);
10559 if (tag_index < 0) {
10560 sigma_dut_print(dut, DUT_MSG_ERROR,
10561 "can't find group id attribute");
10562 return -1;
10563 }
10564 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10565 framelen - tags[tag_index].offset,
10566 IEEE80211_P2P_ATTR_GROUP_ID,
10567 group_id_attr,
10568 sizeof(group_id_attr))) {
10569 sigma_dut_print(dut, DUT_MSG_ERROR,
10570 "fail to replace group id attribute");
10571 return -1;
10572 }
10573 }
10574
10575 for (i = 0; i < count; i++) {
10576 if (wil6210_transmit_frame(dut, freq,
10577 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10578 frame, framelen)) {
10579 sigma_dut_print(dut, DUT_MSG_ERROR,
10580 "fail to transmit probe request frame");
10581 return -1;
10582 }
10583 }
10584
10585 return 0;
10586}
10587
10588
Lior David0fe101e2017-03-09 16:09:50 +020010589int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10590 struct sigma_cmd *cmd)
10591{
10592 const char *frame_name = get_param(cmd, "framename");
10593 const char *mac = get_param(cmd, "dest_mac");
10594
10595 if (!frame_name || !mac) {
10596 sigma_dut_print(dut, DUT_MSG_ERROR,
10597 "framename and dest_mac must be provided");
10598 return -1;
10599 }
10600
10601 if (strcasecmp(frame_name, "brp") == 0) {
10602 const char *l_rx = get_param(cmd, "L-RX");
10603 int l_rx_i;
10604
10605 if (!l_rx) {
10606 sigma_dut_print(dut, DUT_MSG_ERROR,
10607 "L-RX must be provided");
10608 return -1;
10609 }
10610 l_rx_i = atoi(l_rx);
10611
10612 sigma_dut_print(dut, DUT_MSG_INFO,
10613 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10614 mac, l_rx);
10615 if (l_rx_i != 16) {
10616 sigma_dut_print(dut, DUT_MSG_ERROR,
10617 "unsupported L-RX: %s", l_rx);
10618 return -1;
10619 }
10620
10621 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10622 return -1;
10623 } else if (strcasecmp(frame_name, "ssw") == 0) {
10624 sigma_dut_print(dut, DUT_MSG_INFO,
10625 "dev_send_frame: SLS, dest_mac %s", mac);
10626 if (wil6210_send_sls(dut, mac))
10627 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010628 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10629 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10630 sigma_dut_print(dut, DUT_MSG_INFO,
10631 "dev_send_frame: %s, dest_mac %s", frame_name,
10632 mac);
10633 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10634 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010635 } else {
10636 sigma_dut_print(dut, DUT_MSG_ERROR,
10637 "unsupported frame type: %s", frame_name);
10638 return -1;
10639 }
10640
10641 return 1;
10642}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010643
Lior David0fe101e2017-03-09 16:09:50 +020010644#endif /* __linux__ */
10645
10646
10647static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10648 struct sigma_conn *conn,
10649 struct sigma_cmd *cmd)
10650{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010651 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010652#ifdef __linux__
10653 case DRIVER_WIL6210:
10654 return wil6210_send_frame_60g(dut, conn, cmd);
10655#endif /* __linux__ */
10656 default:
10657 send_resp(dut, conn, SIGMA_ERROR,
10658 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10659 return 0;
10660 }
10661}
10662
10663
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010664static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10665 const char *intf, struct sigma_cmd *cmd)
10666{
10667 const char *val, *addr;
10668 char buf[100];
10669
10670 addr = get_param(cmd, "DestMac");
10671 if (!addr) {
10672 send_resp(dut, conn, SIGMA_INVALID,
10673 "ErrorCode,AP MAC address is missing");
10674 return 0;
10675 }
10676
10677 val = get_param(cmd, "ANQPQuery_ID");
10678 if (!val) {
10679 send_resp(dut, conn, SIGMA_INVALID,
10680 "ErrorCode,Missing ANQPQuery_ID");
10681 return 0;
10682 }
10683
10684 if (strcasecmp(val, "NeighborReportReq") == 0) {
10685 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10686 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10687 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10688 } else {
10689 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10690 val);
10691 send_resp(dut, conn, SIGMA_INVALID,
10692 "ErrorCode,Invalid ANQPQuery_ID");
10693 return 0;
10694 }
10695
Ashwini Patild174f2c2017-04-13 16:49:46 +053010696 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10697 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10698 * if associated, AP BSSID).
10699 */
10700 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10701 send_resp(dut, conn, SIGMA_ERROR,
10702 "ErrorCode,Failed to set gas_address3");
10703 return 0;
10704 }
10705
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010706 if (wpa_command(intf, buf) < 0) {
10707 send_resp(dut, conn, SIGMA_ERROR,
10708 "ErrorCode,Failed to send ANQP query");
10709 return 0;
10710 }
10711
10712 return 1;
10713}
10714
10715
10716static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10717 struct sigma_conn *conn,
10718 const char *intf,
10719 struct sigma_cmd *cmd)
10720{
10721 const char *val = get_param(cmd, "FrameName");
10722
10723 if (val && strcasecmp(val, "ANQPQuery") == 0)
10724 return mbo_send_anqp_query(dut, conn, intf, cmd);
10725
10726 return 2;
10727}
10728
10729
Jouni Malinenf7222712019-06-13 01:50:21 +030010730enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10731 struct sigma_conn *conn,
10732 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010733{
10734 const char *intf = get_param(cmd, "Interface");
10735 const char *val;
10736 enum send_frame_type frame;
10737 enum send_frame_protection protected;
10738 char buf[100];
10739 unsigned char addr[ETH_ALEN];
10740 int res;
10741
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010742 if (!intf)
10743 return -1;
10744
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010745 val = get_param(cmd, "program");
10746 if (val == NULL)
10747 val = get_param(cmd, "frame");
10748 if (val && strcasecmp(val, "TDLS") == 0)
10749 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10750 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010751 strcasecmp(val, "HS2-R2") == 0 ||
10752 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010753 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10754 if (val && strcasecmp(val, "VHT") == 0)
10755 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010756 if (val && strcasecmp(val, "HE") == 0)
10757 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010758 if (val && strcasecmp(val, "LOC") == 0)
10759 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010760 if (val && strcasecmp(val, "60GHz") == 0)
10761 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010762 if (val && strcasecmp(val, "MBO") == 0) {
10763 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10764 if (res != 2)
10765 return res;
10766 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010767
10768 val = get_param(cmd, "TD_DISC");
10769 if (val) {
10770 if (hwaddr_aton(val, addr) < 0)
10771 return -1;
10772 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10773 if (wpa_command(intf, buf) < 0) {
10774 send_resp(dut, conn, SIGMA_ERROR,
10775 "ErrorCode,Failed to send TDLS discovery");
10776 return 0;
10777 }
10778 return 1;
10779 }
10780
10781 val = get_param(cmd, "TD_Setup");
10782 if (val) {
10783 if (hwaddr_aton(val, addr) < 0)
10784 return -1;
10785 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10786 if (wpa_command(intf, buf) < 0) {
10787 send_resp(dut, conn, SIGMA_ERROR,
10788 "ErrorCode,Failed to start TDLS setup");
10789 return 0;
10790 }
10791 return 1;
10792 }
10793
10794 val = get_param(cmd, "TD_TearDown");
10795 if (val) {
10796 if (hwaddr_aton(val, addr) < 0)
10797 return -1;
10798 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10799 if (wpa_command(intf, buf) < 0) {
10800 send_resp(dut, conn, SIGMA_ERROR,
10801 "ErrorCode,Failed to tear down TDLS link");
10802 return 0;
10803 }
10804 return 1;
10805 }
10806
10807 val = get_param(cmd, "TD_ChannelSwitch");
10808 if (val) {
10809 /* TODO */
10810 send_resp(dut, conn, SIGMA_ERROR,
10811 "ErrorCode,TD_ChannelSwitch not yet supported");
10812 return 0;
10813 }
10814
10815 val = get_param(cmd, "TD_NF");
10816 if (val) {
10817 /* TODO */
10818 send_resp(dut, conn, SIGMA_ERROR,
10819 "ErrorCode,TD_NF not yet supported");
10820 return 0;
10821 }
10822
10823 val = get_param(cmd, "PMFFrameType");
10824 if (val == NULL)
10825 val = get_param(cmd, "FrameName");
10826 if (val == NULL)
10827 val = get_param(cmd, "Type");
10828 if (val == NULL)
10829 return -1;
10830 if (strcasecmp(val, "disassoc") == 0)
10831 frame = DISASSOC;
10832 else if (strcasecmp(val, "deauth") == 0)
10833 frame = DEAUTH;
10834 else if (strcasecmp(val, "saquery") == 0)
10835 frame = SAQUERY;
10836 else if (strcasecmp(val, "auth") == 0)
10837 frame = AUTH;
10838 else if (strcasecmp(val, "assocreq") == 0)
10839 frame = ASSOCREQ;
10840 else if (strcasecmp(val, "reassocreq") == 0)
10841 frame = REASSOCREQ;
10842 else if (strcasecmp(val, "neigreq") == 0) {
10843 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10844
10845 val = get_param(cmd, "ssid");
10846 if (val == NULL)
10847 return -1;
10848
10849 res = send_neighbor_request(dut, intf, val);
10850 if (res) {
10851 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10852 "Failed to send neighbor report request");
10853 return 0;
10854 }
10855
10856 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010857 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10858 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010859 sigma_dut_print(dut, DUT_MSG_DEBUG,
10860 "Got Transition Management Query");
10861
Ashwini Patil5acd7382017-04-13 15:55:04 +053010862 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010863 if (res) {
10864 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10865 "Failed to send Transition Management Query");
10866 return 0;
10867 }
10868
10869 return 1;
10870 } else {
10871 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10872 "PMFFrameType");
10873 return 0;
10874 }
10875
10876 val = get_param(cmd, "PMFProtected");
10877 if (val == NULL)
10878 val = get_param(cmd, "Protected");
10879 if (val == NULL)
10880 return -1;
10881 if (strcasecmp(val, "Correct-key") == 0 ||
10882 strcasecmp(val, "CorrectKey") == 0)
10883 protected = CORRECT_KEY;
10884 else if (strcasecmp(val, "IncorrectKey") == 0)
10885 protected = INCORRECT_KEY;
10886 else if (strcasecmp(val, "Unprotected") == 0)
10887 protected = UNPROTECTED;
10888 else {
10889 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10890 "PMFProtected");
10891 return 0;
10892 }
10893
10894 if (protected != UNPROTECTED &&
10895 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10896 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10897 "PMFProtected for auth/assocreq/reassocreq");
10898 return 0;
10899 }
10900
10901 if (if_nametoindex("sigmadut") == 0) {
10902 snprintf(buf, sizeof(buf),
10903 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010904 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010905 if (system(buf) != 0 ||
10906 if_nametoindex("sigmadut") == 0) {
10907 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10908 "monitor interface with '%s'", buf);
10909 return -2;
10910 }
10911 }
10912
10913 if (system("ifconfig sigmadut up") != 0) {
10914 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10915 "monitor interface up");
10916 return -2;
10917 }
10918
10919 return sta_inject_frame(dut, conn, frame, protected, NULL);
10920}
10921
10922
10923static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10924 struct sigma_conn *conn,
10925 struct sigma_cmd *cmd,
10926 const char *ifname)
10927{
10928 char buf[200];
10929 const char *val;
10930
10931 val = get_param(cmd, "ClearARP");
10932 if (val && atoi(val) == 1) {
10933 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10934 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10935 if (system(buf) != 0) {
10936 send_resp(dut, conn, SIGMA_ERROR,
10937 "errorCode,Failed to clear ARP cache");
10938 return 0;
10939 }
10940 }
10941
10942 return 1;
10943}
10944
10945
10946int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10947 struct sigma_cmd *cmd)
10948{
10949 const char *intf = get_param(cmd, "Interface");
10950 const char *val;
10951
10952 if (intf == NULL)
10953 return -1;
10954
10955 val = get_param(cmd, "program");
10956 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010957 strcasecmp(val, "HS2-R2") == 0 ||
10958 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010959 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10960
10961 return -1;
10962}
10963
10964
Jouni Malinenf7222712019-06-13 01:50:21 +030010965static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
10966 struct sigma_conn *conn,
10967 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010968{
10969 const char *intf = get_param(cmd, "Interface");
10970 const char *mac = get_param(cmd, "MAC");
10971
10972 if (intf == NULL || mac == NULL)
10973 return -1;
10974
10975 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10976 "interface %s to %s", intf, mac);
10977
10978 if (dut->set_macaddr) {
10979 char buf[128];
10980 int res;
10981 if (strcasecmp(mac, "default") == 0) {
10982 res = snprintf(buf, sizeof(buf), "%s",
10983 dut->set_macaddr);
10984 dut->tmp_mac_addr = 0;
10985 } else {
10986 res = snprintf(buf, sizeof(buf), "%s %s",
10987 dut->set_macaddr, mac);
10988 dut->tmp_mac_addr = 1;
10989 }
10990 if (res < 0 || res >= (int) sizeof(buf))
10991 return -1;
10992 if (system(buf) != 0) {
10993 send_resp(dut, conn, SIGMA_ERROR,
10994 "errorCode,Failed to set MAC "
10995 "address");
10996 return 0;
10997 }
10998 return 1;
10999 }
11000
11001 if (strcasecmp(mac, "default") == 0)
11002 return 1;
11003
11004 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11005 "command");
11006 return 0;
11007}
11008
11009
11010static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11011 struct sigma_conn *conn, const char *intf,
11012 int val)
11013{
11014 char buf[200];
11015 int res;
11016
11017 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11018 intf, val);
11019 if (res < 0 || res >= (int) sizeof(buf))
11020 return -1;
11021 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11022 if (system(buf) != 0) {
11023 send_resp(dut, conn, SIGMA_ERROR,
11024 "errorCode,Failed to configure offchannel mode");
11025 return 0;
11026 }
11027
11028 return 1;
11029}
11030
11031
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011032static int off_chan_val(enum sec_ch_offset off)
11033{
11034 switch (off) {
11035 case SEC_CH_NO:
11036 return 0;
11037 case SEC_CH_40ABOVE:
11038 return 40;
11039 case SEC_CH_40BELOW:
11040 return -40;
11041 }
11042
11043 return 0;
11044}
11045
11046
11047static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11048 const char *intf, int off_ch_num,
11049 enum sec_ch_offset sec)
11050{
11051 char buf[200];
11052 int res;
11053
11054 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11055 intf, off_ch_num);
11056 if (res < 0 || res >= (int) sizeof(buf))
11057 return -1;
11058 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11059 if (system(buf) != 0) {
11060 send_resp(dut, conn, SIGMA_ERROR,
11061 "errorCode,Failed to set offchan");
11062 return 0;
11063 }
11064
11065 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11066 intf, off_chan_val(sec));
11067 if (res < 0 || res >= (int) sizeof(buf))
11068 return -1;
11069 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11070 if (system(buf) != 0) {
11071 send_resp(dut, conn, SIGMA_ERROR,
11072 "errorCode,Failed to set sec chan offset");
11073 return 0;
11074 }
11075
11076 return 1;
11077}
11078
11079
11080static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11081 struct sigma_conn *conn,
11082 const char *intf, int off_ch_num,
11083 enum sec_ch_offset sec)
11084{
11085 char buf[200];
11086 int res;
11087
11088 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11089 off_ch_num);
11090 if (res < 0 || res >= (int) sizeof(buf))
11091 return -1;
11092 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11093
11094 if (wpa_command(intf, buf) < 0) {
11095 send_resp(dut, conn, SIGMA_ERROR,
11096 "ErrorCode,Failed to set offchan");
11097 return 0;
11098 }
11099 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11100 off_chan_val(sec));
11101 if (res < 0 || res >= (int) sizeof(buf))
11102 return -1;
11103
11104 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11105
11106 if (wpa_command(intf, buf) < 0) {
11107 send_resp(dut, conn, SIGMA_ERROR,
11108 "ErrorCode,Failed to set sec chan offset");
11109 return 0;
11110 }
11111
11112 return 1;
11113}
11114
11115
11116static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11117 struct sigma_conn *conn,
11118 const char *intf, int val)
11119{
11120 char buf[200];
11121 int res;
11122
11123 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11124 val);
11125 if (res < 0 || res >= (int) sizeof(buf))
11126 return -1;
11127 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11128
11129 if (wpa_command(intf, buf) < 0) {
11130 send_resp(dut, conn, SIGMA_ERROR,
11131 "ErrorCode,Failed to configure offchannel mode");
11132 return 0;
11133 }
11134
11135 return 1;
11136}
11137
11138
11139static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11140 struct sigma_conn *conn,
11141 struct sigma_cmd *cmd)
11142{
11143 const char *val;
11144 enum {
11145 CHSM_NOT_SET,
11146 CHSM_ENABLE,
11147 CHSM_DISABLE,
11148 CHSM_REJREQ,
11149 CHSM_UNSOLRESP
11150 } chsm = CHSM_NOT_SET;
11151 int off_ch_num = -1;
11152 enum sec_ch_offset sec_ch = SEC_CH_NO;
11153 int res;
11154
11155 val = get_param(cmd, "Uapsd");
11156 if (val) {
11157 char buf[100];
11158 if (strcasecmp(val, "Enable") == 0)
11159 snprintf(buf, sizeof(buf), "SET ps 99");
11160 else if (strcasecmp(val, "Disable") == 0)
11161 snprintf(buf, sizeof(buf), "SET ps 98");
11162 else {
11163 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11164 "Unsupported uapsd parameter value");
11165 return 0;
11166 }
11167 if (wpa_command(intf, buf)) {
11168 send_resp(dut, conn, SIGMA_ERROR,
11169 "ErrorCode,Failed to change U-APSD "
11170 "powersave mode");
11171 return 0;
11172 }
11173 }
11174
11175 val = get_param(cmd, "TPKTIMER");
11176 if (val && strcasecmp(val, "DISABLE") == 0) {
11177 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11178 send_resp(dut, conn, SIGMA_ERROR,
11179 "ErrorCode,Failed to enable no TPK "
11180 "expiration test mode");
11181 return 0;
11182 }
11183 dut->no_tpk_expiration = 1;
11184 }
11185
11186 val = get_param(cmd, "ChSwitchMode");
11187 if (val) {
11188 if (strcasecmp(val, "Enable") == 0 ||
11189 strcasecmp(val, "Initiate") == 0)
11190 chsm = CHSM_ENABLE;
11191 else if (strcasecmp(val, "Disable") == 0 ||
11192 strcasecmp(val, "passive") == 0)
11193 chsm = CHSM_DISABLE;
11194 else if (strcasecmp(val, "RejReq") == 0)
11195 chsm = CHSM_REJREQ;
11196 else if (strcasecmp(val, "UnSolResp") == 0)
11197 chsm = CHSM_UNSOLRESP;
11198 else {
11199 send_resp(dut, conn, SIGMA_ERROR,
11200 "ErrorCode,Unknown ChSwitchMode value");
11201 return 0;
11202 }
11203 }
11204
11205 val = get_param(cmd, "OffChNum");
11206 if (val) {
11207 off_ch_num = atoi(val);
11208 if (off_ch_num == 0) {
11209 send_resp(dut, conn, SIGMA_ERROR,
11210 "ErrorCode,Invalid OffChNum");
11211 return 0;
11212 }
11213 }
11214
11215 val = get_param(cmd, "SecChOffset");
11216 if (val) {
11217 if (strcmp(val, "20") == 0)
11218 sec_ch = SEC_CH_NO;
11219 else if (strcasecmp(val, "40above") == 0)
11220 sec_ch = SEC_CH_40ABOVE;
11221 else if (strcasecmp(val, "40below") == 0)
11222 sec_ch = SEC_CH_40BELOW;
11223 else {
11224 send_resp(dut, conn, SIGMA_ERROR,
11225 "ErrorCode,Unknown SecChOffset value");
11226 return 0;
11227 }
11228 }
11229
11230 if (chsm == CHSM_NOT_SET) {
11231 /* no offchannel changes requested */
11232 return 1;
11233 }
11234
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011235 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11236 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011237 send_resp(dut, conn, SIGMA_ERROR,
11238 "ErrorCode,Unknown interface");
11239 return 0;
11240 }
11241
11242 switch (chsm) {
11243 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011244 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011245 break;
11246 case CHSM_ENABLE:
11247 if (off_ch_num < 0) {
11248 send_resp(dut, conn, SIGMA_ERROR,
11249 "ErrorCode,Missing OffChNum argument");
11250 return 0;
11251 }
11252 if (wifi_chip_type == DRIVER_WCN) {
11253 res = tdls_set_offchannel_offset(dut, conn, intf,
11254 off_ch_num, sec_ch);
11255 } else {
11256 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11257 sec_ch);
11258 }
11259 if (res != 1)
11260 return res;
11261 if (wifi_chip_type == DRIVER_WCN)
11262 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11263 else
11264 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11265 break;
11266 case CHSM_DISABLE:
11267 if (wifi_chip_type == DRIVER_WCN)
11268 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11269 else
11270 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11271 break;
11272 case CHSM_REJREQ:
11273 if (wifi_chip_type == DRIVER_WCN)
11274 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11275 else
11276 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11277 break;
11278 case CHSM_UNSOLRESP:
11279 if (off_ch_num < 0) {
11280 send_resp(dut, conn, SIGMA_ERROR,
11281 "ErrorCode,Missing OffChNum argument");
11282 return 0;
11283 }
11284 if (wifi_chip_type == DRIVER_WCN) {
11285 res = tdls_set_offchannel_offset(dut, conn, intf,
11286 off_ch_num, sec_ch);
11287 } else {
11288 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11289 sec_ch);
11290 }
11291 if (res != 1)
11292 return res;
11293 if (wifi_chip_type == DRIVER_WCN)
11294 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11295 else
11296 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11297 break;
11298 }
11299
11300 return res;
11301}
11302
11303
11304static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11305 struct sigma_conn *conn,
11306 struct sigma_cmd *cmd)
11307{
11308 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011309 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011310
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011311 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011312
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011313 val = get_param(cmd, "nss_mcs_opt");
11314 if (val) {
11315 /* String (nss_operating_mode; mcs_operating_mode) */
11316 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011317 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011318
11319 token = strdup(val);
11320 if (!token)
11321 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011322 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011323 if (!result) {
11324 sigma_dut_print(dut, DUT_MSG_ERROR,
11325 "VHT NSS not specified");
11326 goto failed;
11327 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011328 if (strcasecmp(result, "def") != 0) {
11329 nss = atoi(result);
11330 if (nss == 4)
11331 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011332 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011333 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011334
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011335 }
11336
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011337 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011338 if (!result) {
11339 sigma_dut_print(dut, DUT_MSG_ERROR,
11340 "VHT MCS not specified");
11341 goto failed;
11342 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011343 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011344 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011345 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011346 } else {
11347 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011348 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011349 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011350 }
11351 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011352 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011353 }
11354
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011355 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011356 return 1;
11357failed:
11358 free(token);
11359 return 0;
11360}
11361
11362
11363static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11364 struct sigma_conn *conn,
11365 struct sigma_cmd *cmd)
11366{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011367 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011368 case DRIVER_ATHEROS:
11369 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11370 default:
11371 send_resp(dut, conn, SIGMA_ERROR,
11372 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11373 return 0;
11374 }
11375}
11376
11377
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011378static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11379 struct sigma_conn *conn,
11380 struct sigma_cmd *cmd)
11381{
11382 const char *val;
11383 char *token = NULL, *result;
11384 char buf[60];
11385
11386 val = get_param(cmd, "nss_mcs_opt");
11387 if (val) {
11388 /* String (nss_operating_mode; mcs_operating_mode) */
11389 int nss, mcs, ratecode;
11390 char *saveptr;
11391
11392 token = strdup(val);
11393 if (!token)
11394 return -2;
11395
11396 result = strtok_r(token, ";", &saveptr);
11397 if (!result) {
11398 sigma_dut_print(dut, DUT_MSG_ERROR,
11399 "HE NSS not specified");
11400 goto failed;
11401 }
11402 nss = 1;
11403 if (strcasecmp(result, "def") != 0)
11404 nss = atoi(result);
11405
11406 result = strtok_r(NULL, ";", &saveptr);
11407 if (!result) {
11408 sigma_dut_print(dut, DUT_MSG_ERROR,
11409 "HE MCS not specified");
11410 goto failed;
11411 }
11412 mcs = 7;
11413 if (strcasecmp(result, "def") != 0)
11414 mcs = atoi(result);
11415
Arif Hussain557bf412018-05-25 17:29:36 -070011416 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011417 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011418 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011419 } else if (nss > 2) {
11420 sigma_dut_print(dut, DUT_MSG_ERROR,
11421 "HE NSS %d not supported", nss);
11422 goto failed;
11423 }
11424
Arif Hussain557bf412018-05-25 17:29:36 -070011425 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11426 if (system(buf) != 0) {
11427 sigma_dut_print(dut, DUT_MSG_ERROR,
11428 "nss_mcs_opt: iwpriv %s nss %d failed",
11429 intf, nss);
11430 goto failed;
11431 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011432 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011433
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011434 /* Add the MCS to the ratecode */
11435 if (mcs >= 0 && mcs <= 11) {
11436 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011437#ifdef NL80211_SUPPORT
11438 if (dut->device_type == STA_testbed) {
11439 enum he_mcs_config mcs_config;
11440 int ret;
11441
11442 if (mcs <= 7)
11443 mcs_config = HE_80_MCS0_7;
11444 else if (mcs <= 9)
11445 mcs_config = HE_80_MCS0_9;
11446 else
11447 mcs_config = HE_80_MCS0_11;
11448 ret = sta_set_he_mcs(dut, intf, mcs_config);
11449 if (ret) {
11450 sigma_dut_print(dut, DUT_MSG_ERROR,
11451 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11452 mcs, mcs_config, ret);
11453 goto failed;
11454 }
11455 }
11456#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011457 } else {
11458 sigma_dut_print(dut, DUT_MSG_ERROR,
11459 "HE MCS %d not supported", mcs);
11460 goto failed;
11461 }
11462 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11463 intf, ratecode);
11464 if (system(buf) != 0) {
11465 sigma_dut_print(dut, DUT_MSG_ERROR,
11466 "iwpriv setting of 11ax rates failed");
11467 goto failed;
11468 }
11469 free(token);
11470 }
11471
11472 val = get_param(cmd, "GI");
11473 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011474 int fix_rate_sgi;
11475
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011476 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011477 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011478 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011479 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011480 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11481 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011482 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011483 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011484 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11485 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011486 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011487 } else {
11488 send_resp(dut, conn, SIGMA_ERROR,
11489 "errorCode,GI value not supported");
11490 return 0;
11491 }
11492 if (system(buf) != 0) {
11493 send_resp(dut, conn, SIGMA_ERROR,
11494 "errorCode,Failed to set shortgi");
11495 return 0;
11496 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011497 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11498 intf, fix_rate_sgi);
11499 if (system(buf) != 0) {
11500 send_resp(dut, conn, SIGMA_ERROR,
11501 "errorCode,Failed to set fix rate shortgi");
11502 return STATUS_SENT;
11503 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011504 }
11505
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011506 val = get_param(cmd, "LTF");
11507 if (val) {
11508#ifdef NL80211_SUPPORT
11509 if (strcmp(val, "3.2") == 0) {
11510 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11511 } if (strcmp(val, "6.4") == 0) {
11512 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11513 } else if (strcmp(val, "12.8") == 0) {
11514 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11515 } else {
11516 send_resp(dut, conn, SIGMA_ERROR,
11517 "errorCode, LTF value not supported");
11518 return 0;
11519 }
11520#else /* NL80211_SUPPORT */
11521 sigma_dut_print(dut, DUT_MSG_ERROR,
11522 "LTF cannot be set without NL80211_SUPPORT defined");
11523 return -2;
11524#endif /* NL80211_SUPPORT */
11525 }
11526
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011527 val = get_param(cmd, "TxSUPPDU");
11528 if (val) {
11529 int set_val = 1;
11530
11531 if (strcasecmp(val, "Enable") == 0)
11532 set_val = 1;
11533 else if (strcasecmp(val, "Disable") == 0)
11534 set_val = 0;
11535
11536 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11537 send_resp(dut, conn, SIGMA_ERROR,
11538 "ErrorCode,Failed to set Tx SU PPDU config");
11539 return 0;
11540 }
11541 }
11542
Arif Hussain480d5f42019-03-12 14:40:42 -070011543 val = get_param(cmd, "TWT_Setup");
11544 if (val) {
11545 if (strcasecmp(val, "Request") == 0) {
11546 if (sta_twt_request(dut, conn, cmd)) {
11547 send_resp(dut, conn, SIGMA_ERROR,
11548 "ErrorCode,sta_twt_request failed");
11549 return STATUS_SENT;
11550 }
11551 } else if (strcasecmp(val, "Teardown") == 0) {
11552 if (sta_twt_teardown(dut, conn, cmd)) {
11553 send_resp(dut, conn, SIGMA_ERROR,
11554 "ErrorCode,sta_twt_teardown failed");
11555 return STATUS_SENT;
11556 }
11557 }
11558 }
11559
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011560 val = get_param(cmd, "transmitOMI");
11561 if (val && sta_transmit_omi(dut, conn, cmd)) {
11562 send_resp(dut, conn, SIGMA_ERROR,
11563 "ErrorCode,sta_transmit_omi failed");
11564 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011565 }
11566
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011567 val = get_param(cmd, "Powersave");
11568 if (val) {
11569 char buf[60];
11570
11571 if (strcasecmp(val, "off") == 0) {
11572 snprintf(buf, sizeof(buf),
11573 "iwpriv %s setPower 2", intf);
11574 if (system(buf) != 0) {
11575 sigma_dut_print(dut, DUT_MSG_ERROR,
11576 "iwpriv setPower 2 failed");
11577 return 0;
11578 }
11579 } else if (strcasecmp(val, "on") == 0) {
11580 snprintf(buf, sizeof(buf),
11581 "iwpriv %s setPower 1", intf);
11582 if (system(buf) != 0) {
11583 sigma_dut_print(dut, DUT_MSG_ERROR,
11584 "iwpriv setPower 1 failed");
11585 return 0;
11586 }
11587 } else {
11588 sigma_dut_print(dut, DUT_MSG_ERROR,
11589 "Unsupported Powersave value '%s'",
11590 val);
11591 return -1;
11592 }
11593 }
11594
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011595 val = get_param(cmd, "MU_EDCA");
11596 if (val) {
11597 if (strcasecmp(val, "Override") == 0) {
11598 if (sta_set_mu_edca_override(dut, intf, 1)) {
11599 send_resp(dut, conn, SIGMA_ERROR,
11600 "errorCode,MU EDCA override set failed");
11601 return STATUS_SENT;
11602 }
11603 } else if (strcasecmp(val, "Disable") == 0) {
11604 if (sta_set_mu_edca_override(dut, intf, 0)) {
11605 send_resp(dut, conn, SIGMA_ERROR,
11606 "errorCode,MU EDCA override disable failed");
11607 return STATUS_SENT;
11608 }
11609 }
11610 }
11611
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011612 return 1;
11613
11614failed:
11615 free(token);
11616 return -2;
11617}
11618
11619
11620static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11621 struct sigma_conn *conn,
11622 struct sigma_cmd *cmd)
11623{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011624 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011625 case DRIVER_WCN:
11626 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11627 default:
11628 send_resp(dut, conn, SIGMA_ERROR,
11629 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11630 return 0;
11631 }
11632}
11633
11634
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011635static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11636 struct sigma_conn *conn,
11637 struct sigma_cmd *cmd)
11638{
11639 const char *val;
11640
11641 val = get_param(cmd, "powersave");
11642 if (val) {
11643 char buf[60];
11644
11645 if (strcasecmp(val, "off") == 0) {
11646 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11647 intf);
11648 if (system(buf) != 0) {
11649 sigma_dut_print(dut, DUT_MSG_ERROR,
11650 "iwpriv setPower 2 failed");
11651 return 0;
11652 }
11653 } else if (strcasecmp(val, "on") == 0) {
11654 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11655 intf);
11656 if (system(buf) != 0) {
11657 sigma_dut_print(dut, DUT_MSG_ERROR,
11658 "iwpriv setPower 1 failed");
11659 return 0;
11660 }
11661 } else {
11662 sigma_dut_print(dut, DUT_MSG_ERROR,
11663 "Unsupported power save config");
11664 return -1;
11665 }
11666 return 1;
11667 }
11668
11669 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11670
11671 return 0;
11672}
11673
11674
Ashwini Patil5acd7382017-04-13 15:55:04 +053011675static int btm_query_candidate_list(struct sigma_dut *dut,
11676 struct sigma_conn *conn,
11677 struct sigma_cmd *cmd)
11678{
11679 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11680 int len, ret;
11681 char buf[10];
11682
11683 /*
11684 * Neighbor Report elements format:
11685 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11686 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11687 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11688 */
11689
11690 bssid = get_param(cmd, "Nebor_BSSID");
11691 if (!bssid) {
11692 send_resp(dut, conn, SIGMA_INVALID,
11693 "errorCode,Nebor_BSSID is missing");
11694 return 0;
11695 }
11696
11697 info = get_param(cmd, "Nebor_Bssid_Info");
11698 if (!info) {
11699 sigma_dut_print(dut, DUT_MSG_INFO,
11700 "Using default value for Nebor_Bssid_Info: %s",
11701 DEFAULT_NEIGHBOR_BSSID_INFO);
11702 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11703 }
11704
11705 op_class = get_param(cmd, "Nebor_Op_Class");
11706 if (!op_class) {
11707 send_resp(dut, conn, SIGMA_INVALID,
11708 "errorCode,Nebor_Op_Class is missing");
11709 return 0;
11710 }
11711
11712 ch = get_param(cmd, "Nebor_Op_Ch");
11713 if (!ch) {
11714 send_resp(dut, conn, SIGMA_INVALID,
11715 "errorCode,Nebor_Op_Ch is missing");
11716 return 0;
11717 }
11718
11719 phy_type = get_param(cmd, "Nebor_Phy_Type");
11720 if (!phy_type) {
11721 sigma_dut_print(dut, DUT_MSG_INFO,
11722 "Using default value for Nebor_Phy_Type: %s",
11723 DEFAULT_NEIGHBOR_PHY_TYPE);
11724 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11725 }
11726
11727 /* Parse optional subelements */
11728 buf[0] = '\0';
11729 pref = get_param(cmd, "Nebor_Pref");
11730 if (pref) {
11731 /* hexdump for preferrence subelement */
11732 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11733 if (ret < 0 || ret >= (int) sizeof(buf)) {
11734 sigma_dut_print(dut, DUT_MSG_ERROR,
11735 "snprintf failed for optional subelement ret: %d",
11736 ret);
11737 send_resp(dut, conn, SIGMA_ERROR,
11738 "errorCode,snprintf failed for subelement");
11739 return 0;
11740 }
11741 }
11742
11743 if (!dut->btm_query_cand_list) {
11744 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11745 if (!dut->btm_query_cand_list) {
11746 send_resp(dut, conn, SIGMA_ERROR,
11747 "errorCode,Failed to allocate memory for btm_query_cand_list");
11748 return 0;
11749 }
11750 }
11751
11752 len = strlen(dut->btm_query_cand_list);
11753 ret = snprintf(dut->btm_query_cand_list + len,
11754 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11755 bssid, info, op_class, ch, phy_type, buf);
11756 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11757 sigma_dut_print(dut, DUT_MSG_ERROR,
11758 "snprintf failed for neighbor report list ret: %d",
11759 ret);
11760 send_resp(dut, conn, SIGMA_ERROR,
11761 "errorCode,snprintf failed for neighbor report");
11762 free(dut->btm_query_cand_list);
11763 dut->btm_query_cand_list = NULL;
11764 return 0;
11765 }
11766
11767 return 1;
11768}
11769
11770
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011771int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11772 struct sigma_ese_alloc *allocs, int *allocs_size)
11773{
11774 int max_count = *allocs_size;
11775 int count = 0, i;
11776 const char *val;
11777
11778 do {
11779 val = get_param_indexed(cmd, "AllocID", count);
11780 if (val)
11781 count++;
11782 } while (val);
11783
11784 if (count == 0 || count > max_count) {
11785 sigma_dut_print(dut, DUT_MSG_ERROR,
11786 "Invalid number of allocations(%d)", count);
11787 return -1;
11788 }
11789
11790 for (i = 0; i < count; i++) {
11791 val = get_param_indexed(cmd, "PercentBI", i);
11792 if (!val) {
11793 sigma_dut_print(dut, DUT_MSG_ERROR,
11794 "Missing PercentBI parameter at index %d",
11795 i);
11796 return -1;
11797 }
11798 allocs[i].percent_bi = atoi(val);
11799
11800 val = get_param_indexed(cmd, "SrcAID", i);
11801 if (val)
11802 allocs[i].src_aid = strtol(val, NULL, 0);
11803 else
11804 allocs[i].src_aid = ESE_BCAST_AID;
11805
11806 val = get_param_indexed(cmd, "DestAID", i);
11807 if (val)
11808 allocs[i].dst_aid = strtol(val, NULL, 0);
11809 else
11810 allocs[i].dst_aid = ESE_BCAST_AID;
11811
11812 allocs[i].type = ESE_CBAP;
11813 sigma_dut_print(dut, DUT_MSG_INFO,
11814 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11815 i, allocs[i].percent_bi, allocs[i].src_aid,
11816 allocs[i].dst_aid);
11817 }
11818
11819 *allocs_size = count;
11820 return 0;
11821}
11822
11823
11824static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11825 struct sigma_ese_alloc *allocs)
11826{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011827 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011828#ifdef __linux__
11829 case DRIVER_WIL6210:
11830 if (wil6210_set_ese(dut, count, allocs))
11831 return -1;
11832 return 1;
11833#endif /* __linux__ */
11834 default:
11835 sigma_dut_print(dut, DUT_MSG_ERROR,
11836 "Unsupported sta_set_60g_ese with the current driver");
11837 return -1;
11838 }
11839}
11840
11841
11842static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11843 struct sigma_conn *conn,
11844 struct sigma_cmd *cmd)
11845{
11846 const char *val;
11847
11848 val = get_param(cmd, "ExtSchIE");
11849 if (val && !strcasecmp(val, "Enable")) {
11850 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11851 int count = MAX_ESE_ALLOCS;
11852
11853 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11854 return -1;
11855 return sta_set_60g_ese(dut, count, allocs);
11856 }
11857
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011858 val = get_param(cmd, "MCS_FixedRate");
11859 if (val) {
11860 int sta_mcs = atoi(val);
11861
11862 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11863 sta_mcs);
11864 wil6210_set_force_mcs(dut, 1, sta_mcs);
11865
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011866 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011867 }
11868
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011869 send_resp(dut, conn, SIGMA_ERROR,
11870 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011871 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011872}
11873
11874
Jouni Malinenf7222712019-06-13 01:50:21 +030011875static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
11876 struct sigma_conn *conn,
11877 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011878{
11879 const char *intf = get_param(cmd, "Interface");
11880 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011881 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011882
11883 if (intf == NULL || prog == NULL)
11884 return -1;
11885
Ashwini Patil5acd7382017-04-13 15:55:04 +053011886 /* BSS Transition candidate list for BTM query */
11887 val = get_param(cmd, "Nebor_BSSID");
11888 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11889 return 0;
11890
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011891 if (strcasecmp(prog, "TDLS") == 0)
11892 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11893
11894 if (strcasecmp(prog, "VHT") == 0)
11895 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11896
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011897 if (strcasecmp(prog, "HE") == 0)
11898 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11899
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011900 if (strcasecmp(prog, "MBO") == 0) {
11901 val = get_param(cmd, "Cellular_Data_Cap");
11902 if (val &&
11903 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11904 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011905
11906 val = get_param(cmd, "Ch_Pref");
11907 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11908 return 0;
11909
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011910 return 1;
11911 }
11912
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011913 if (strcasecmp(prog, "60GHz") == 0)
11914 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11915
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011916 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11917 return 0;
11918}
11919
11920
Jouni Malinenf7222712019-06-13 01:50:21 +030011921static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
11922 struct sigma_conn *conn,
11923 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011924{
11925 const char *intf = get_param(cmd, "Interface");
11926 const char *mode = get_param(cmd, "Mode");
11927 int res;
11928
11929 if (intf == NULL || mode == NULL)
11930 return -1;
11931
11932 if (strcasecmp(mode, "On") == 0)
11933 res = wpa_command(intf, "SET radio_disabled 0");
11934 else if (strcasecmp(mode, "Off") == 0)
11935 res = wpa_command(intf, "SET radio_disabled 1");
11936 else
11937 return -1;
11938
11939 if (res) {
11940 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11941 "radio mode");
11942 return 0;
11943 }
11944
11945 return 1;
11946}
11947
11948
Jouni Malinenf7222712019-06-13 01:50:21 +030011949static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
11950 struct sigma_conn *conn,
11951 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011952{
11953 const char *intf = get_param(cmd, "Interface");
11954 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011955 const char *prog = get_param(cmd, "program");
11956 const char *powersave = get_param(cmd, "powersave");
11957 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011958
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011959 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011960 return -1;
11961
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011962 if (prog && strcasecmp(prog, "60GHz") == 0) {
11963 /*
11964 * The CAPI mode parameter does not exist in 60G
11965 * unscheduled PS.
11966 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080011967 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011968 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011969 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011970 strcasecmp(prog, "HE") == 0) {
11971 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011972 } else {
11973 if (mode == NULL)
11974 return -1;
11975
11976 if (strcasecmp(mode, "On") == 0)
11977 res = set_ps(intf, dut, 1);
11978 else if (strcasecmp(mode, "Off") == 0)
11979 res = set_ps(intf, dut, 0);
11980 else
11981 return -1;
11982 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011983
11984 if (res) {
11985 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11986 "power save mode");
11987 return 0;
11988 }
11989
11990 return 1;
11991}
11992
11993
Jouni Malinenf7222712019-06-13 01:50:21 +030011994static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
11995 struct sigma_conn *conn,
11996 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011997{
11998 const char *intf = get_param(cmd, "Interface");
11999 const char *val, *bssid;
12000 int res;
12001 char *buf;
12002 size_t buf_len;
12003
12004 val = get_param(cmd, "BSSID_FILTER");
12005 if (val == NULL)
12006 return -1;
12007
12008 bssid = get_param(cmd, "BSSID_List");
12009 if (atoi(val) == 0 || bssid == NULL) {
12010 /* Disable BSSID filter */
12011 if (wpa_command(intf, "SET bssid_filter ")) {
12012 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12013 "to disable BSSID filter");
12014 return 0;
12015 }
12016
12017 return 1;
12018 }
12019
12020 buf_len = 100 + strlen(bssid);
12021 buf = malloc(buf_len);
12022 if (buf == NULL)
12023 return -1;
12024
12025 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12026 res = wpa_command(intf, buf);
12027 free(buf);
12028 if (res) {
12029 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12030 "BSSID filter");
12031 return 0;
12032 }
12033
12034 return 1;
12035}
12036
12037
Jouni Malinenf7222712019-06-13 01:50:21 +030012038static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12039 struct sigma_conn *conn,
12040 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012041{
12042 const char *intf = get_param(cmd, "Interface");
12043 const char *val;
12044
12045 /* TODO: ARP */
12046
12047 val = get_param(cmd, "HS2_CACHE_PROFILE");
12048 if (val && strcasecmp(val, "All") == 0)
12049 hs2_clear_credentials(intf);
12050
12051 return 1;
12052}
12053
12054
Jouni Malinenf7222712019-06-13 01:50:21 +030012055static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12056 struct sigma_conn *conn,
12057 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012058{
12059 const char *intf = get_param(cmd, "Interface");
12060 const char *key_type = get_param(cmd, "KeyType");
12061 char buf[100], resp[200];
12062
12063 if (key_type == NULL)
12064 return -1;
12065
12066 if (strcasecmp(key_type, "GTK") == 0) {
12067 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12068 strncmp(buf, "FAIL", 4) == 0) {
12069 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12070 "not fetch current GTK");
12071 return 0;
12072 }
12073 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12074 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12075 return 0;
12076 } else {
12077 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12078 "KeyType");
12079 return 0;
12080 }
12081
12082 return 1;
12083}
12084
12085
12086static int hs2_set_policy(struct sigma_dut *dut)
12087{
12088#ifdef ANDROID
12089 system("ip rule del prio 23000");
12090 if (system("ip rule add from all lookup main prio 23000") != 0) {
12091 sigma_dut_print(dut, DUT_MSG_ERROR,
12092 "Failed to run:ip rule add from all lookup main prio");
12093 return -1;
12094 }
12095 if (system("ip route flush cache") != 0) {
12096 sigma_dut_print(dut, DUT_MSG_ERROR,
12097 "Failed to run ip route flush cache");
12098 return -1;
12099 }
12100 return 1;
12101#else /* ANDROID */
12102 return 0;
12103#endif /* ANDROID */
12104}
12105
12106
Jouni Malinenf7222712019-06-13 01:50:21 +030012107static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12108 struct sigma_conn *conn,
12109 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012110{
12111 const char *intf = get_param(cmd, "Interface");
12112 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012113 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012114 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012115 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012116 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12117 int tries = 0;
12118 int ignore_blacklist = 0;
12119 const char *events[] = {
12120 "CTRL-EVENT-CONNECTED",
12121 "INTERWORKING-BLACKLISTED",
12122 "INTERWORKING-NO-MATCH",
12123 NULL
12124 };
12125
12126 start_sta_mode(dut);
12127
Jouni Malinen439352d2018-09-13 03:42:23 +030012128 if (band) {
12129 if (strcmp(band, "2.4") == 0) {
12130 wpa_command(intf, "SET setband 2G");
12131 } else if (strcmp(band, "5") == 0) {
12132 wpa_command(intf, "SET setband 5G");
12133 } else {
12134 send_resp(dut, conn, SIGMA_ERROR,
12135 "errorCode,Unsupported band");
12136 return 0;
12137 }
12138 }
12139
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012140 blacklisted[0] = '\0';
12141 if (val && atoi(val))
12142 ignore_blacklist = 1;
12143
12144try_again:
12145 ctrl = open_wpa_mon(intf);
12146 if (ctrl == NULL) {
12147 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12148 "wpa_supplicant monitor connection");
12149 return -2;
12150 }
12151
12152 tries++;
12153 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12154 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12155 "Interworking connection");
12156 wpa_ctrl_detach(ctrl);
12157 wpa_ctrl_close(ctrl);
12158 return 0;
12159 }
12160
12161 buf[0] = '\0';
12162 while (1) {
12163 char *pos;
12164 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12165 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12166 if (!pos)
12167 break;
12168 pos += 25;
12169 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12170 pos);
12171 if (!blacklisted[0])
12172 memcpy(blacklisted, pos, strlen(pos) + 1);
12173 }
12174
12175 if (ignore_blacklist && blacklisted[0]) {
12176 char *end;
12177 end = strchr(blacklisted, ' ');
12178 if (end)
12179 *end = '\0';
12180 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12181 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012182 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12183 blacklisted);
12184 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012185 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12186 wpa_ctrl_detach(ctrl);
12187 wpa_ctrl_close(ctrl);
12188 return 0;
12189 }
12190 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12191 buf, sizeof(buf));
12192 }
12193
12194 wpa_ctrl_detach(ctrl);
12195 wpa_ctrl_close(ctrl);
12196
12197 if (res < 0) {
12198 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12199 "connect");
12200 return 0;
12201 }
12202
12203 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12204 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12205 if (tries < 2) {
12206 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12207 goto try_again;
12208 }
12209 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12210 "matching credentials found");
12211 return 0;
12212 }
12213
12214 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12215 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12216 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12217 "get current BSSID/SSID");
12218 return 0;
12219 }
12220
12221 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12222 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12223 hs2_set_policy(dut);
12224 return 0;
12225}
12226
12227
Jouni Malinenf7222712019-06-13 01:50:21 +030012228static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12229 struct sigma_conn *conn,
12230 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012231{
12232 const char *intf = get_param(cmd, "Interface");
12233 const char *display = get_param(cmd, "Display");
12234 struct wpa_ctrl *ctrl;
12235 char buf[300], params[400], *pos;
12236 char bssid[20];
12237 int info_avail = 0;
12238 unsigned int old_timeout;
12239 int res;
12240
12241 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12242 send_resp(dut, conn, SIGMA_ERROR,
12243 "ErrorCode,Could not get current BSSID");
12244 return 0;
12245 }
12246 ctrl = open_wpa_mon(intf);
12247 if (!ctrl) {
12248 sigma_dut_print(dut, DUT_MSG_ERROR,
12249 "Failed to open wpa_supplicant monitor connection");
12250 return -2;
12251 }
12252
12253 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12254 wpa_command(intf, buf);
12255
12256 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12257 if (res < 0) {
12258 send_resp(dut, conn, SIGMA_ERROR,
12259 "ErrorCode,Could not complete GAS query");
12260 goto fail;
12261 }
12262
12263 old_timeout = dut->default_timeout;
12264 dut->default_timeout = 2;
12265 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12266 dut->default_timeout = old_timeout;
12267 if (res < 0)
12268 goto done;
12269 pos = strchr(buf, ' ');
12270 if (!pos)
12271 goto done;
12272 pos++;
12273 pos = strchr(pos, ' ');
12274 if (!pos)
12275 goto done;
12276 pos++;
12277 info_avail = 1;
12278 snprintf(params, sizeof(params), "browser %s", pos);
12279
12280 if (display && strcasecmp(display, "Yes") == 0) {
12281 pid_t pid;
12282
12283 pid = fork();
12284 if (pid < 0) {
12285 perror("fork");
12286 return -1;
12287 }
12288
12289 if (pid == 0) {
12290 run_hs20_osu(dut, params);
12291 exit(0);
12292 }
12293 }
12294
12295done:
12296 snprintf(buf, sizeof(buf), "Info_available,%s",
12297 info_avail ? "Yes" : "No");
12298 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12299fail:
12300 wpa_ctrl_detach(ctrl);
12301 wpa_ctrl_close(ctrl);
12302 return 0;
12303}
12304
12305
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012306static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12307 struct sigma_conn *conn,
12308 const char *ifname,
12309 struct sigma_cmd *cmd)
12310{
12311 const char *val;
12312 int id;
12313
12314 id = add_cred(ifname);
12315 if (id < 0)
12316 return -2;
12317 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12318
12319 val = get_param(cmd, "prefer");
12320 if (val && atoi(val) > 0)
12321 set_cred(ifname, id, "priority", "1");
12322
12323 val = get_param(cmd, "REALM");
12324 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12325 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12326 "realm");
12327 return 0;
12328 }
12329
12330 val = get_param(cmd, "HOME_FQDN");
12331 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12332 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12333 "home_fqdn");
12334 return 0;
12335 }
12336
12337 val = get_param(cmd, "Username");
12338 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12339 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12340 "username");
12341 return 0;
12342 }
12343
12344 val = get_param(cmd, "Password");
12345 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12346 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12347 "password");
12348 return 0;
12349 }
12350
12351 val = get_param(cmd, "ROOT_CA");
12352 if (val) {
12353 char fname[200];
12354 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12355#ifdef __linux__
12356 if (!file_exists(fname)) {
12357 char msg[300];
12358 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12359 "file (%s) not found", fname);
12360 send_resp(dut, conn, SIGMA_ERROR, msg);
12361 return 0;
12362 }
12363#endif /* __linux__ */
12364 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12365 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12366 "not set root CA");
12367 return 0;
12368 }
12369 }
12370
12371 return 1;
12372}
12373
12374
12375static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12376{
12377 FILE *in, *out;
12378 char buf[500];
12379 int found = 0;
12380
12381 in = fopen("devdetail.xml", "r");
12382 if (in == NULL)
12383 return -1;
12384 out = fopen("devdetail.xml.tmp", "w");
12385 if (out == NULL) {
12386 fclose(in);
12387 return -1;
12388 }
12389
12390 while (fgets(buf, sizeof(buf), in)) {
12391 char *pos = strstr(buf, "<IMSI>");
12392 if (pos) {
12393 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12394 imsi);
12395 pos += 6;
12396 *pos = '\0';
12397 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12398 found++;
12399 } else {
12400 fprintf(out, "%s", buf);
12401 }
12402 }
12403
12404 fclose(out);
12405 fclose(in);
12406 if (found)
12407 rename("devdetail.xml.tmp", "devdetail.xml");
12408 else
12409 unlink("devdetail.xml.tmp");
12410
12411 return 0;
12412}
12413
12414
12415static int sta_add_credential_sim(struct sigma_dut *dut,
12416 struct sigma_conn *conn,
12417 const char *ifname, struct sigma_cmd *cmd)
12418{
12419 const char *val, *imsi = NULL;
12420 int id;
12421 char buf[200];
12422 int res;
12423 const char *pos;
12424 size_t mnc_len;
12425 char plmn_mcc[4];
12426 char plmn_mnc[4];
12427
12428 id = add_cred(ifname);
12429 if (id < 0)
12430 return -2;
12431 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12432
12433 val = get_param(cmd, "prefer");
12434 if (val && atoi(val) > 0)
12435 set_cred(ifname, id, "priority", "1");
12436
12437 val = get_param(cmd, "PLMN_MCC");
12438 if (val == NULL) {
12439 send_resp(dut, conn, SIGMA_ERROR,
12440 "errorCode,Missing PLMN_MCC");
12441 return 0;
12442 }
12443 if (strlen(val) != 3) {
12444 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12445 return 0;
12446 }
12447 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12448
12449 val = get_param(cmd, "PLMN_MNC");
12450 if (val == NULL) {
12451 send_resp(dut, conn, SIGMA_ERROR,
12452 "errorCode,Missing PLMN_MNC");
12453 return 0;
12454 }
12455 if (strlen(val) != 2 && strlen(val) != 3) {
12456 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12457 return 0;
12458 }
12459 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12460
12461 val = get_param(cmd, "IMSI");
12462 if (val == NULL) {
12463 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12464 "IMSI");
12465 return 0;
12466 }
12467
12468 imsi = pos = val;
12469
12470 if (strncmp(plmn_mcc, pos, 3) != 0) {
12471 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12472 return 0;
12473 }
12474 pos += 3;
12475
12476 mnc_len = strlen(plmn_mnc);
12477 if (mnc_len < 2) {
12478 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12479 return 0;
12480 }
12481
12482 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12483 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12484 return 0;
12485 }
12486 pos += mnc_len;
12487
12488 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12489 if (res < 0 || res >= (int) sizeof(buf))
12490 return -1;
12491 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12492 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12493 "not set IMSI");
12494 return 0;
12495 }
12496
12497 val = get_param(cmd, "Password");
12498 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12499 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12500 "not set password");
12501 return 0;
12502 }
12503
Jouni Malinenba630452018-06-22 11:49:59 +030012504 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012505 /*
12506 * Set provisioning_sp for the test cases where SIM/USIM
12507 * provisioning is used.
12508 */
12509 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12510 "wi-fi.org") < 0) {
12511 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12512 "not set provisioning_sp");
12513 return 0;
12514 }
12515
12516 update_devdetail_imsi(dut, imsi);
12517 }
12518
12519 return 1;
12520}
12521
12522
12523static int sta_add_credential_cert(struct sigma_dut *dut,
12524 struct sigma_conn *conn,
12525 const char *ifname,
12526 struct sigma_cmd *cmd)
12527{
12528 const char *val;
12529 int id;
12530
12531 id = add_cred(ifname);
12532 if (id < 0)
12533 return -2;
12534 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12535
12536 val = get_param(cmd, "prefer");
12537 if (val && atoi(val) > 0)
12538 set_cred(ifname, id, "priority", "1");
12539
12540 val = get_param(cmd, "REALM");
12541 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12542 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12543 "realm");
12544 return 0;
12545 }
12546
12547 val = get_param(cmd, "HOME_FQDN");
12548 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12549 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12550 "home_fqdn");
12551 return 0;
12552 }
12553
12554 val = get_param(cmd, "Username");
12555 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12556 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12557 "username");
12558 return 0;
12559 }
12560
12561 val = get_param(cmd, "clientCertificate");
12562 if (val) {
12563 char fname[200];
12564 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12565#ifdef __linux__
12566 if (!file_exists(fname)) {
12567 char msg[300];
12568 snprintf(msg, sizeof(msg),
12569 "ErrorCode,clientCertificate "
12570 "file (%s) not found", fname);
12571 send_resp(dut, conn, SIGMA_ERROR, msg);
12572 return 0;
12573 }
12574#endif /* __linux__ */
12575 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12576 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12577 "not set client_cert");
12578 return 0;
12579 }
12580 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12581 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12582 "not set private_key");
12583 return 0;
12584 }
12585 }
12586
12587 val = get_param(cmd, "ROOT_CA");
12588 if (val) {
12589 char fname[200];
12590 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12591#ifdef __linux__
12592 if (!file_exists(fname)) {
12593 char msg[300];
12594 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12595 "file (%s) not found", fname);
12596 send_resp(dut, conn, SIGMA_ERROR, msg);
12597 return 0;
12598 }
12599#endif /* __linux__ */
12600 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12601 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12602 "not set root CA");
12603 return 0;
12604 }
12605 }
12606
12607 return 1;
12608}
12609
12610
Jouni Malinenf7222712019-06-13 01:50:21 +030012611static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12612 struct sigma_conn *conn,
12613 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012614{
12615 const char *intf = get_param(cmd, "Interface");
12616 const char *type;
12617
12618 start_sta_mode(dut);
12619
12620 type = get_param(cmd, "Type");
12621 if (!type)
12622 return -1;
12623
12624 if (strcasecmp(type, "uname_pwd") == 0)
12625 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12626
12627 if (strcasecmp(type, "sim") == 0)
12628 return sta_add_credential_sim(dut, conn, intf, cmd);
12629
12630 if (strcasecmp(type, "cert") == 0)
12631 return sta_add_credential_cert(dut, conn, intf, cmd);
12632
12633 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12634 "type");
12635 return 0;
12636}
12637
12638
Jouni Malinenf7222712019-06-13 01:50:21 +030012639static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12640 struct sigma_conn *conn,
12641 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012642{
12643 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012644 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012645 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012646 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012647 int res;
12648
Arif Hussain66a4af02019-02-07 15:04:51 -080012649 val = get_param(cmd, "GetParameter");
12650 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012651 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012652 buf, sizeof(buf)) < 0) {
12653 sigma_dut_print(dut, DUT_MSG_ERROR,
12654 "Could not get ssid bssid");
12655 return ERROR_SEND_STATUS;
12656 }
12657
12658 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12659 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12660 return STATUS_SENT;
12661 }
12662
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012663 val = get_param(cmd, "HESSID");
12664 if (val) {
12665 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12666 if (res < 0 || res >= (int) sizeof(buf))
12667 return -1;
12668 wpa_command(intf, buf);
12669 }
12670
12671 val = get_param(cmd, "ACCS_NET_TYPE");
12672 if (val) {
12673 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12674 val);
12675 if (res < 0 || res >= (int) sizeof(buf))
12676 return -1;
12677 wpa_command(intf, buf);
12678 }
12679
vamsi krishna89ad8c62017-09-19 12:51:18 +053012680 bssid = get_param(cmd, "Bssid");
12681 ssid = get_param(cmd, "Ssid");
12682
12683 if (ssid) {
12684 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12685 send_resp(dut, conn, SIGMA_ERROR,
12686 "ErrorCode,Too long SSID");
12687 return 0;
12688 }
12689 ascii2hexstr(ssid, ssid_hex);
12690 }
12691
12692 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12693 bssid ? " bssid=": "",
12694 bssid ? bssid : "",
12695 ssid ? " ssid " : "",
12696 ssid ? ssid_hex : "");
12697 if (res < 0 || res >= (int) sizeof(buf))
12698 return -1;
12699
12700 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012701 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12702 "scan");
12703 return 0;
12704 }
12705
12706 return 1;
12707}
12708
12709
Jouni Malinenf7222712019-06-13 01:50:21 +030012710static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12711 struct sigma_conn *conn,
12712 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012713{
12714 const char *intf = get_param(cmd, "Interface");
12715 const char *bssid;
12716 char buf[4096], *pos;
12717 int freq, chan;
12718 char *ssid;
12719 char resp[100];
12720 int res;
12721 struct wpa_ctrl *ctrl;
12722
12723 bssid = get_param(cmd, "BSSID");
12724 if (!bssid) {
12725 send_resp(dut, conn, SIGMA_INVALID,
12726 "errorCode,BSSID argument is missing");
12727 return 0;
12728 }
12729
12730 ctrl = open_wpa_mon(intf);
12731 if (!ctrl) {
12732 sigma_dut_print(dut, DUT_MSG_ERROR,
12733 "Failed to open wpa_supplicant monitor connection");
12734 return -1;
12735 }
12736
12737 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12738 send_resp(dut, conn, SIGMA_ERROR,
12739 "errorCode,Could not start scan");
12740 wpa_ctrl_detach(ctrl);
12741 wpa_ctrl_close(ctrl);
12742 return 0;
12743 }
12744
12745 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12746 buf, sizeof(buf));
12747
12748 wpa_ctrl_detach(ctrl);
12749 wpa_ctrl_close(ctrl);
12750
12751 if (res < 0) {
12752 send_resp(dut, conn, SIGMA_ERROR,
12753 "errorCode,Scan did not complete");
12754 return 0;
12755 }
12756
12757 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12758 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12759 strncmp(buf, "id=", 3) != 0) {
12760 send_resp(dut, conn, SIGMA_ERROR,
12761 "errorCode,Specified BSSID not found");
12762 return 0;
12763 }
12764
12765 pos = strstr(buf, "\nfreq=");
12766 if (!pos) {
12767 send_resp(dut, conn, SIGMA_ERROR,
12768 "errorCode,Channel not found");
12769 return 0;
12770 }
12771 freq = atoi(pos + 6);
12772 chan = freq_to_channel(freq);
12773
12774 pos = strstr(buf, "\nssid=");
12775 if (!pos) {
12776 send_resp(dut, conn, SIGMA_ERROR,
12777 "errorCode,SSID not found");
12778 return 0;
12779 }
12780 ssid = pos + 6;
12781 pos = strchr(ssid, '\n');
12782 if (pos)
12783 *pos = '\0';
12784 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12785 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12786 return 0;
12787}
12788
12789
Jouni Malinenf7222712019-06-13 01:50:21 +030012790static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
12791 struct sigma_conn *conn,
12792 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012793{
12794#ifdef __linux__
12795 struct timeval tv;
12796 struct tm tm;
12797 time_t t;
12798 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012799 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012800
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012801 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012802
12803 memset(&tm, 0, sizeof(tm));
12804 val = get_param(cmd, "seconds");
12805 if (val)
12806 tm.tm_sec = atoi(val);
12807 val = get_param(cmd, "minutes");
12808 if (val)
12809 tm.tm_min = atoi(val);
12810 val = get_param(cmd, "hours");
12811 if (val)
12812 tm.tm_hour = atoi(val);
12813 val = get_param(cmd, "date");
12814 if (val)
12815 tm.tm_mday = atoi(val);
12816 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012817 if (val) {
12818 v = atoi(val);
12819 if (v < 1 || v > 12) {
12820 send_resp(dut, conn, SIGMA_INVALID,
12821 "errorCode,Invalid month");
12822 return 0;
12823 }
12824 tm.tm_mon = v - 1;
12825 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012826 val = get_param(cmd, "year");
12827 if (val) {
12828 int year = atoi(val);
12829#ifdef ANDROID
12830 if (year > 2035)
12831 year = 2035; /* years beyond 2035 not supported */
12832#endif /* ANDROID */
12833 tm.tm_year = year - 1900;
12834 }
12835 t = mktime(&tm);
12836 if (t == (time_t) -1) {
12837 send_resp(dut, conn, SIGMA_ERROR,
12838 "errorCode,Invalid date or time");
12839 return 0;
12840 }
12841
12842 memset(&tv, 0, sizeof(tv));
12843 tv.tv_sec = t;
12844
12845 if (settimeofday(&tv, NULL) < 0) {
12846 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12847 strerror(errno));
12848 send_resp(dut, conn, SIGMA_ERROR,
12849 "errorCode,Failed to set time");
12850 return 0;
12851 }
12852
12853 return 1;
12854#endif /* __linux__ */
12855
12856 return -1;
12857}
12858
12859
Jouni Malinenf7222712019-06-13 01:50:21 +030012860static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
12861 struct sigma_conn *conn,
12862 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012863{
12864 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012865 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012866 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012867 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012868 int res;
12869 struct wpa_ctrl *ctrl;
12870
12871 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012872 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012873
12874 val = get_param(cmd, "ProdESSAssoc");
12875 if (val)
12876 prod_ess_assoc = atoi(val);
12877
12878 kill_dhcp_client(dut, intf);
12879 if (start_dhcp_client(dut, intf) < 0)
12880 return -2;
12881
12882 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12883 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12884 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012885 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012886 prod_ess_assoc ? "" : "-N",
12887 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012888 name ? "'" : "",
12889 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12890 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012891
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012892 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012893 if (run_hs20_osu(dut, buf) < 0) {
12894 FILE *f;
12895
12896 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12897
12898 f = fopen("hs20-osu-client.res", "r");
12899 if (f) {
12900 char resp[400], res[300], *pos;
12901 if (!fgets(res, sizeof(res), f))
12902 res[0] = '\0';
12903 pos = strchr(res, '\n');
12904 if (pos)
12905 *pos = '\0';
12906 fclose(f);
12907 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12908 res);
12909 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12910 if (system(resp) != 0) {
12911 }
12912 snprintf(resp, sizeof(resp),
12913 "SSID,,BSSID,,failureReason,%s", res);
12914 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12915 return 0;
12916 }
12917
12918 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12919 return 0;
12920 }
12921
12922 if (!prod_ess_assoc)
12923 goto report;
12924
12925 ctrl = open_wpa_mon(intf);
12926 if (ctrl == NULL) {
12927 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12928 "wpa_supplicant monitor connection");
12929 return -1;
12930 }
12931
12932 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12933 buf, sizeof(buf));
12934
12935 wpa_ctrl_detach(ctrl);
12936 wpa_ctrl_close(ctrl);
12937
12938 if (res < 0) {
12939 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12940 "network after OSU");
12941 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12942 return 0;
12943 }
12944
12945report:
12946 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12947 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12948 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12949 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12950 return 0;
12951 }
12952
12953 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12954 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012955 return 0;
12956}
12957
12958
Jouni Malinenf7222712019-06-13 01:50:21 +030012959static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
12960 struct sigma_conn *conn,
12961 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012962{
12963 const char *val;
12964 int timeout = 120;
12965
12966 val = get_param(cmd, "PolicyUpdate");
12967 if (val == NULL || atoi(val) == 0)
12968 return 1; /* No operation requested */
12969
12970 val = get_param(cmd, "Timeout");
12971 if (val)
12972 timeout = atoi(val);
12973
12974 if (timeout) {
12975 /* TODO: time out the command and return
12976 * PolicyUpdateStatus,TIMEOUT if needed. */
12977 }
12978
12979 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12980 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12981 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12982 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12983 return 0;
12984 }
12985
12986 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12987 return 0;
12988}
12989
12990
Jouni Malinenf7222712019-06-13 01:50:21 +030012991static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
12992 struct sigma_conn *conn,
12993 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012994{
12995 struct wpa_ctrl *ctrl;
12996 const char *intf = get_param(cmd, "Interface");
12997 const char *bssid = get_param(cmd, "Bssid");
12998 const char *ssid = get_param(cmd, "SSID");
12999 const char *security = get_param(cmd, "Security");
13000 const char *passphrase = get_param(cmd, "Passphrase");
13001 const char *pin = get_param(cmd, "PIN");
13002 char buf[1000];
13003 char ssid_hex[200], passphrase_hex[200];
13004 const char *keymgmt, *cipher;
13005
13006 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013007 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013008
13009 if (!bssid) {
13010 send_resp(dut, conn, SIGMA_ERROR,
13011 "ErrorCode,Missing Bssid argument");
13012 return 0;
13013 }
13014
13015 if (!ssid) {
13016 send_resp(dut, conn, SIGMA_ERROR,
13017 "ErrorCode,Missing SSID argument");
13018 return 0;
13019 }
13020
13021 if (!security) {
13022 send_resp(dut, conn, SIGMA_ERROR,
13023 "ErrorCode,Missing Security argument");
13024 return 0;
13025 }
13026
13027 if (!passphrase) {
13028 send_resp(dut, conn, SIGMA_ERROR,
13029 "ErrorCode,Missing Passphrase argument");
13030 return 0;
13031 }
13032
13033 if (!pin) {
13034 send_resp(dut, conn, SIGMA_ERROR,
13035 "ErrorCode,Missing PIN argument");
13036 return 0;
13037 }
13038
vamsi krishna8c9c1562017-05-12 15:51:46 +053013039 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13040 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013041 send_resp(dut, conn, SIGMA_ERROR,
13042 "ErrorCode,Too long SSID/passphrase");
13043 return 0;
13044 }
13045
13046 ctrl = open_wpa_mon(intf);
13047 if (ctrl == NULL) {
13048 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13049 "wpa_supplicant monitor connection");
13050 return -2;
13051 }
13052
13053 if (strcasecmp(security, "wpa2-psk") == 0) {
13054 keymgmt = "WPA2PSK";
13055 cipher = "CCMP";
13056 } else {
13057 wpa_ctrl_detach(ctrl);
13058 wpa_ctrl_close(ctrl);
13059 send_resp(dut, conn, SIGMA_ERROR,
13060 "ErrorCode,Unsupported Security value");
13061 return 0;
13062 }
13063
13064 ascii2hexstr(ssid, ssid_hex);
13065 ascii2hexstr(passphrase, passphrase_hex);
13066 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13067 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13068
13069 if (wpa_command(intf, buf) < 0) {
13070 wpa_ctrl_detach(ctrl);
13071 wpa_ctrl_close(ctrl);
13072 send_resp(dut, conn, SIGMA_ERROR,
13073 "ErrorCode,Failed to start registrar");
13074 return 0;
13075 }
13076
13077 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13078 dut->er_oper_performed = 1;
13079
13080 return wps_connection_event(dut, conn, ctrl, intf, 0);
13081}
13082
13083
Jouni Malinenf7222712019-06-13 01:50:21 +030013084static enum sigma_cmd_result
13085cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13086 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013087{
13088 struct wpa_ctrl *ctrl;
13089 const char *intf = get_param(cmd, "Interface");
13090 const char *bssid = get_param(cmd, "Bssid");
13091 char buf[100];
13092
13093 if (!bssid) {
13094 send_resp(dut, conn, SIGMA_ERROR,
13095 "ErrorCode,Missing Bssid argument");
13096 return 0;
13097 }
13098
13099 ctrl = open_wpa_mon(intf);
13100 if (ctrl == NULL) {
13101 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13102 "wpa_supplicant monitor connection");
13103 return -2;
13104 }
13105
13106 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13107
13108 if (wpa_command(intf, buf) < 0) {
13109 wpa_ctrl_detach(ctrl);
13110 wpa_ctrl_close(ctrl);
13111 send_resp(dut, conn, SIGMA_ERROR,
13112 "ErrorCode,Failed to start registrar");
13113 return 0;
13114 }
13115
13116 return wps_connection_event(dut, conn, ctrl, intf, 0);
13117}
13118
13119
Jouni Malinenf7222712019-06-13 01:50:21 +030013120static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13121 struct sigma_conn *conn,
13122 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013123{
13124 struct wpa_ctrl *ctrl;
13125 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013126 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013127 const char *config_method = get_param(cmd, "WPSConfigMethod");
13128 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013129 int res;
13130 char buf[256];
13131 const char *events[] = {
13132 "CTRL-EVENT-CONNECTED",
13133 "WPS-OVERLAP-DETECTED",
13134 "WPS-TIMEOUT",
13135 "WPS-FAIL",
13136 NULL
13137 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013138 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013139
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013140 /* 60G WPS tests do not pass Interface parameter */
13141 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013142 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013143
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013144 if (dut->mode == SIGMA_MODE_AP)
13145 return ap_wps_registration(dut, conn, cmd);
13146
13147 if (config_method) {
13148 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13149 * sta_wps_enter_pin before calling start_wps_registration. */
13150 if (strcasecmp(config_method, "PBC") == 0)
13151 dut->wps_method = WFA_CS_WPS_PBC;
13152 }
13153 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13154 send_resp(dut, conn, SIGMA_ERROR,
13155 "ErrorCode,WPS parameters not yet set");
13156 return STATUS_SENT;
13157 }
13158
13159 /* Make sure WPS is enabled (also for STA mode) */
13160 dut->wps_disable = 0;
13161
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013162 if (dut->band == WPS_BAND_60G && network_mode &&
13163 strcasecmp(network_mode, "PBSS") == 0) {
13164 sigma_dut_print(dut, DUT_MSG_DEBUG,
13165 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013166 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013167 return -2;
13168 }
13169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013170 if (dut->force_rsn_ie) {
13171 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13172 dut->force_rsn_ie);
13173 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13174 sigma_dut_print(dut, DUT_MSG_INFO,
13175 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013176 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013177 }
13178 }
13179
vamsi krishna9b144002017-09-20 13:28:13 +053013180 ctrl = open_wpa_mon(intf);
13181 if (!ctrl) {
13182 sigma_dut_print(dut, DUT_MSG_ERROR,
13183 "Failed to open wpa_supplicant monitor connection");
13184 return -2;
13185 }
13186
13187 role = get_param(cmd, "WpsRole");
13188 if (!role) {
13189 send_resp(dut, conn, SIGMA_INVALID,
13190 "ErrorCode,WpsRole not provided");
13191 goto fail;
13192 }
13193
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013194 if (strcasecmp(role, "Enrollee") != 0) {
13195 /* Registrar role for STA not supported */
13196 send_resp(dut, conn, SIGMA_ERROR,
13197 "ErrorCode,Unsupported WpsRole value");
13198 goto fail;
13199 }
13200
13201 if (is_60g_sigma_dut(dut)) {
13202 if (dut->wps_method == WFA_CS_WPS_PBC)
13203 snprintf(buf, sizeof(buf), "WPS_PBC");
13204 else /* WFA_CS_WPS_PIN_KEYPAD */
13205 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13206 dut->wps_pin);
13207 if (wpa_command(intf, buf) < 0) {
13208 send_resp(dut, conn, SIGMA_ERROR,
13209 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013210 goto fail;
13211 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013212 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13213 if (res < 0) {
13214 send_resp(dut, conn, SIGMA_ERROR,
13215 "ErrorCode,WPS connection did not complete");
13216 goto fail;
13217 }
13218 if (strstr(buf, "WPS-TIMEOUT")) {
13219 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13220 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13221 send_resp(dut, conn, SIGMA_COMPLETE,
13222 "WpsState,OverlapSession");
13223 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13224 send_resp(dut, conn, SIGMA_COMPLETE,
13225 "WpsState,Successful");
13226 } else {
13227 send_resp(dut, conn, SIGMA_COMPLETE,
13228 "WpsState,Failure");
13229 }
13230 } else {
13231 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013232 if (wpa_command(intf, "WPS_PBC") < 0) {
13233 send_resp(dut, conn, SIGMA_ERROR,
13234 "ErrorCode,Failed to enable PBC");
13235 goto fail;
13236 }
13237 } else {
13238 /* TODO: PIN method */
13239 send_resp(dut, conn, SIGMA_ERROR,
13240 "ErrorCode,Unsupported WpsConfigMethod value");
13241 goto fail;
13242 }
13243 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13244 if (res < 0) {
13245 send_resp(dut, conn, SIGMA_ERROR,
13246 "ErrorCode,WPS connection did not complete");
13247 goto fail;
13248 }
13249 if (strstr(buf, "WPS-TIMEOUT")) {
13250 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13251 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13252 send_resp(dut, conn, SIGMA_ERROR,
13253 "ErrorCode,OverlapSession");
13254 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13255 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13256 } else {
13257 send_resp(dut, conn, SIGMA_ERROR,
13258 "ErrorCode,WPS operation failed");
13259 }
vamsi krishna9b144002017-09-20 13:28:13 +053013260 }
13261
13262fail:
13263 wpa_ctrl_detach(ctrl);
13264 wpa_ctrl_close(ctrl);
13265 return 0;
13266}
13267
13268
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013269static int req_intf(struct sigma_cmd *cmd)
13270{
13271 return get_param(cmd, "interface") == NULL ? -1 : 0;
13272}
13273
13274
13275void sta_register_cmds(void)
13276{
13277 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13278 cmd_sta_get_ip_config);
13279 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13280 cmd_sta_set_ip_config);
13281 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13282 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13283 cmd_sta_get_mac_address);
13284 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13285 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13286 cmd_sta_verify_ip_connection);
13287 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13288 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13289 cmd_sta_set_encryption);
13290 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13291 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13292 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13293 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13294 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13295 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13296 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13297 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13298 cmd_sta_set_eapakaprime);
13299 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13300 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13301 /* TODO: sta_set_ibss */
13302 /* TODO: sta_set_mode */
13303 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13304 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13305 /* TODO: sta_up_load */
13306 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13307 cmd_sta_preset_testparameters);
13308 /* TODO: sta_set_system */
13309 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13310 /* TODO: sta_set_rifs_test */
13311 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13312 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13313 /* TODO: sta_send_coexist_mgmt */
13314 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13315 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13316 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13317 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13318 cmd_sta_reset_default);
13319 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13320 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13321 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13322 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13323 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013324 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013325 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13326 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13327 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13328 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13329 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013330 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13331 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013332 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13333 cmd_sta_add_credential);
13334 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013335 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013336 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13337 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13338 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13339 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13340 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13341 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013342 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013343 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13344 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013345 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013346 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013347}