blob: e04be608ef6f32d997ad19e0adeea19c5253b1bd [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
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007607 if (!program)
7608 program = get_param(cmd, "prog");
7609 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007610 dut->device_type = STA_unknown;
7611 type = get_param(cmd, "type");
7612 if (type && strcasecmp(type, "Testbed") == 0)
7613 dut->device_type = STA_testbed;
7614 if (type && strcasecmp(type, "DUT") == 0)
7615 dut->device_type = STA_dut;
7616
7617 if (dut->program == PROGRAM_TDLS) {
7618 /* Clear TDLS testing mode */
7619 wpa_command(intf, "SET tdls_disabled 0");
7620 wpa_command(intf, "SET tdls_testing 0");
7621 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007622 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307623 /* Enable the WCN driver in TDLS Explicit trigger mode
7624 */
7625 wpa_command(intf, "SET tdls_external_control 0");
7626 wpa_command(intf, "SET tdls_trigger_control 0");
7627 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007628 }
7629
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007630#ifdef MIRACAST
7631 if (dut->program == PROGRAM_WFD ||
7632 dut->program == PROGRAM_DISPLAYR2)
7633 miracast_sta_reset_default(dut, conn, cmd);
7634#endif /* MIRACAST */
7635
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007636 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007637 case DRIVER_ATHEROS:
7638 sta_reset_default_ath(dut, intf, type);
7639 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007640 case DRIVER_WCN:
7641 sta_reset_default_wcn(dut, intf, type);
7642 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007643 default:
7644 break;
7645 }
7646
7647#ifdef ANDROID_NAN
7648 if (dut->program == PROGRAM_NAN)
7649 nan_cmd_sta_reset_default(dut, conn, cmd);
7650#endif /* ANDROID_NAN */
7651
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307652 if (dut->program == PROGRAM_LOC &&
7653 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7654 return ERROR_SEND_STATUS;
7655
Jouni Malinenba630452018-06-22 11:49:59 +03007656 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007657 unlink("SP/wi-fi.org/pps.xml");
7658 if (system("rm -r SP/*") != 0) {
7659 }
7660 unlink("next-client-cert.pem");
7661 unlink("next-client-key.pem");
7662 }
7663
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007664 /* For WPS program of the 60 GHz band the band type needs to be saved */
7665 if (dut->program == PROGRAM_WPS) {
7666 if (band && strcasecmp(band, "60GHz") == 0) {
7667 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007668 /* For 60 GHz enable WPS for WPS TCs */
7669 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007670 } else {
7671 dut->band = WPS_BAND_NON_60G;
7672 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007673 } else if (dut->program == PROGRAM_60GHZ) {
7674 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7675 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007676 }
7677
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007678 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007679 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007680 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007681
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007682 sigma_dut_print(dut, DUT_MSG_INFO,
7683 "WPS 60 GHz program, wps_disable = %d",
7684 dut->wps_disable);
7685
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007686 if (!dev_role) {
7687 send_resp(dut, conn, SIGMA_ERROR,
7688 "errorCode,Missing DevRole argument");
7689 return 0;
7690 }
7691
7692 if (strcasecmp(dev_role, "STA") == 0)
7693 dut->dev_role = DEVROLE_STA;
7694 else if (strcasecmp(dev_role, "PCP") == 0)
7695 dut->dev_role = DEVROLE_PCP;
7696 else {
7697 send_resp(dut, conn, SIGMA_ERROR,
7698 "errorCode,Unknown DevRole");
7699 return 0;
7700 }
7701
7702 if (dut->device_type == STA_unknown) {
7703 sigma_dut_print(dut, DUT_MSG_ERROR,
7704 "Device type is not STA testbed or DUT");
7705 send_resp(dut, conn, SIGMA_ERROR,
7706 "errorCode,Unknown device type");
7707 return 0;
7708 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007709
7710 sigma_dut_print(dut, DUT_MSG_DEBUG,
7711 "Setting msdu_size to MAX: 7912");
7712 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007713 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007714
7715 if (system(buf) != 0) {
7716 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7717 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007718 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007719 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007720
7721 if (sta_set_force_mcs(dut, 0, 1)) {
7722 sigma_dut_print(dut, DUT_MSG_ERROR,
7723 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007724 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007725 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007726 }
7727
7728 wpa_command(intf, "WPS_ER_STOP");
7729 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307730 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007731 wpa_command(intf, "SET radio_disabled 0");
7732
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007733 dut->wps_forced_version = 0;
7734
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007735 if (dut->wsc_fragment) {
7736 dut->wsc_fragment = 0;
7737 wpa_command(intf, "SET device_name Test client");
7738 wpa_command(intf, "SET manufacturer ");
7739 wpa_command(intf, "SET model_name ");
7740 wpa_command(intf, "SET model_number ");
7741 wpa_command(intf, "SET serial_number ");
7742 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007743 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7744 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7745 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7746 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007747
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007748 if (dut->tmp_mac_addr && dut->set_macaddr) {
7749 dut->tmp_mac_addr = 0;
7750 if (system(dut->set_macaddr) != 0) {
7751 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7752 "temporary MAC address");
7753 }
7754 }
7755
7756 set_ps(intf, dut, 0);
7757
Jouni Malinenba630452018-06-22 11:49:59 +03007758 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7759 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007760 wpa_command(intf, "SET interworking 1");
7761 wpa_command(intf, "SET hs20 1");
7762 }
7763
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007764 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007765 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007766 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007767 wpa_command(intf, "SET pmf 1");
7768 } else {
7769 wpa_command(intf, "SET pmf 0");
7770 }
7771
7772 hs2_clear_credentials(intf);
7773 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7774 wpa_command(intf, "SET access_network_type 15");
7775
7776 static_ip_file(0, NULL, NULL, NULL);
7777 kill_dhcp_client(dut, intf);
7778 clear_ip_addr(dut, intf);
7779
7780 dut->er_oper_performed = 0;
7781 dut->er_oper_bssid[0] = '\0';
7782
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007783 if (dut->program == PROGRAM_LOC) {
7784 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007785 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007786 }
7787
Ashwini Patil00402582017-04-13 12:29:39 +05307788 if (dut->program == PROGRAM_MBO) {
7789 free(dut->non_pref_ch_list);
7790 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307791 free(dut->btm_query_cand_list);
7792 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307793 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307794 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307795 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307796 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307797 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307798 }
7799
Jouni Malinen3c367e82017-06-23 17:01:47 +03007800 free(dut->rsne_override);
7801 dut->rsne_override = NULL;
7802
Jouni Malinen68143132017-09-02 02:34:08 +03007803 free(dut->sae_commit_override);
7804 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007805 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen68143132017-09-02 02:34:08 +03007806
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007807 dut->sta_associate_wait_connect = 0;
7808 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007809 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007810 dut->sta_tod_policy = 0;
7811
Jouni Malinend86e5822017-08-29 03:55:32 +03007812 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007813 free(dut->dpp_peer_uri);
7814 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007815 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007816 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007817
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007818 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7819
vamsi krishnaa2799492017-12-05 14:28:01 +05307820 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307821 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307822 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307823 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7824 dut->fils_hlp = 0;
7825#ifdef ANDROID
7826 hlp_thread_cleanup(dut);
7827#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307828 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307829
Jouni Malinen8179fee2019-03-28 03:19:47 +02007830 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007831 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007832
Sunil Dutt076081f2018-02-05 19:45:50 +05307833#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007834 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307835 dut->config_rsnie == 1) {
7836 dut->config_rsnie = 0;
7837 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307838 }
7839#endif /* NL80211_SUPPORT */
7840
Sunil Duttfebf8a82018-02-09 18:50:13 +05307841 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7842 dut->dev_role = DEVROLE_STA_CFON;
7843 return sta_cfon_reset_default(dut, conn, cmd);
7844 }
7845
Jouni Malinen439352d2018-09-13 03:42:23 +03007846 wpa_command(intf, "SET setband AUTO");
7847
Sunil Duttfebf8a82018-02-09 18:50:13 +05307848 if (dut->program != PROGRAM_VHT)
7849 return cmd_sta_p2p_reset(dut, conn, cmd);
7850
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007851 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007852}
7853
7854
Jouni Malinenf7222712019-06-13 01:50:21 +03007855static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7856 struct sigma_conn *conn,
7857 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007858{
7859 const char *program = get_param(cmd, "Program");
7860
7861 if (program == NULL)
7862 return -1;
7863#ifdef ANDROID_NAN
7864 if (strcasecmp(program, "NAN") == 0)
7865 return nan_cmd_sta_get_events(dut, conn, cmd);
7866#endif /* ANDROID_NAN */
7867 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7868 return 0;
7869}
7870
7871
Jouni Malinen82905202018-04-29 17:20:10 +03007872static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7873 struct sigma_cmd *cmd)
7874{
7875 const char *url = get_param(cmd, "url");
7876 const char *method = get_param(cmd, "method");
7877 pid_t pid;
7878 int status;
7879
7880 if (!url || !method)
7881 return -1;
7882
7883 /* TODO: Add support for method,post */
7884 if (strcasecmp(method, "get") != 0) {
7885 send_resp(dut, conn, SIGMA_ERROR,
7886 "ErrorCode,Unsupported method");
7887 return 0;
7888 }
7889
7890 pid = fork();
7891 if (pid < 0) {
7892 perror("fork");
7893 return -1;
7894 }
7895
7896 if (pid == 0) {
7897 char * argv[5] = { "wget", "-O", "/dev/null",
7898 (char *) url, NULL };
7899
7900 execv("/usr/bin/wget", argv);
7901 perror("execv");
7902 exit(0);
7903 return -1;
7904 }
7905
7906 if (waitpid(pid, &status, 0) < 0) {
7907 perror("waitpid");
7908 return -1;
7909 }
7910
7911 if (WIFEXITED(status)) {
7912 const char *errmsg;
7913
7914 if (WEXITSTATUS(status) == 0)
7915 return 1;
7916 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7917 WEXITSTATUS(status));
7918 switch (WEXITSTATUS(status)) {
7919 case 4:
7920 errmsg = "errmsg,Network failure";
7921 break;
7922 case 8:
7923 errmsg = "errmsg,Server issued an error response";
7924 break;
7925 default:
7926 errmsg = "errmsg,Unknown failure from wget";
7927 break;
7928 }
7929 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7930 return 0;
7931 }
7932
7933 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7934 return 0;
7935}
7936
7937
Jouni Malinenf7222712019-06-13 01:50:21 +03007938static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7939 struct sigma_conn *conn,
7940 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007941{
7942 const char *program = get_param(cmd, "Prog");
7943
Jouni Malinen82905202018-04-29 17:20:10 +03007944 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007945 return -1;
7946#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007947 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007948 return nan_cmd_sta_exec_action(dut, conn, cmd);
7949#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007950
7951 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007952 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007953
7954 if (get_param(cmd, "url"))
7955 return sta_exec_action_url(dut, conn, cmd);
7956
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007957 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7958 return 0;
7959}
7960
7961
Jouni Malinenf7222712019-06-13 01:50:21 +03007962static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7963 struct sigma_conn *conn,
7964 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007965{
7966 const char *intf = get_param(cmd, "Interface");
7967 const char *val, *mcs32, *rate;
7968
7969 val = get_param(cmd, "GREENFIELD");
7970 if (val) {
7971 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7972 /* Enable GD */
7973 send_resp(dut, conn, SIGMA_ERROR,
7974 "ErrorCode,GF not supported");
7975 return 0;
7976 }
7977 }
7978
7979 val = get_param(cmd, "SGI20");
7980 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007981 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007982 case DRIVER_ATHEROS:
7983 ath_sta_set_sgi(dut, intf, val);
7984 break;
7985 default:
7986 send_resp(dut, conn, SIGMA_ERROR,
7987 "ErrorCode,SGI20 not supported");
7988 return 0;
7989 }
7990 }
7991
7992 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7993 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7994 if (mcs32 && rate) {
7995 /* TODO */
7996 send_resp(dut, conn, SIGMA_ERROR,
7997 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7998 return 0;
7999 } else if (mcs32 && !rate) {
8000 /* TODO */
8001 send_resp(dut, conn, SIGMA_ERROR,
8002 "ErrorCode,MCS32 not supported");
8003 return 0;
8004 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008005 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008006 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008007 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008008 ath_sta_set_11nrates(dut, intf, rate);
8009 break;
8010 default:
8011 send_resp(dut, conn, SIGMA_ERROR,
8012 "ErrorCode,MCS32_FIXEDRATE not supported");
8013 return 0;
8014 }
8015 }
8016
8017 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8018}
8019
8020
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008021static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8022 int mcs_config)
8023{
8024#ifdef NL80211_SUPPORT
8025 int ret;
8026
8027 switch (mcs_config) {
8028 case HE_80_MCS0_7:
8029 case HE_80_MCS0_9:
8030 case HE_80_MCS0_11:
8031 ret = sta_set_he_mcs(dut, intf, mcs_config);
8032 if (ret) {
8033 sigma_dut_print(dut, DUT_MSG_ERROR,
8034 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8035 mcs_config, ret);
8036 }
8037 break;
8038 default:
8039 sigma_dut_print(dut, DUT_MSG_ERROR,
8040 "cmd_set_max_he_mcs: Invalid mcs %d",
8041 mcs_config);
8042 break;
8043 }
8044#else /* NL80211_SUPPORT */
8045 sigma_dut_print(dut, DUT_MSG_ERROR,
8046 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8047#endif /* NL80211_SUPPORT */
8048}
8049
8050
Arif Hussain480d5f42019-03-12 14:40:42 -07008051static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8052 struct sigma_cmd *cmd)
8053{
8054#ifdef NL80211_SUPPORT
8055 struct nlattr *params;
8056 struct nlattr *attr;
8057 struct nlattr *attr1;
8058 struct nl_msg *msg;
8059 int ifindex, ret;
8060 const char *val;
8061 const char *intf = get_param(cmd, "Interface");
8062 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8063 wake_interval_mantissa = 512;
8064 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8065 protection = 0;
8066
8067 ifindex = if_nametoindex(intf);
8068 if (ifindex == 0) {
8069 sigma_dut_print(dut, DUT_MSG_ERROR,
8070 "%s: Index for interface %s failed",
8071 __func__, intf);
8072 return -1;
8073 }
8074
8075 val = get_param(cmd, "FlowType");
8076 if (val) {
8077 flow_type = atoi(val);
8078 if (flow_type != 0 && flow_type != 1) {
8079 sigma_dut_print(dut, DUT_MSG_ERROR,
8080 "TWT: Invalid FlowType %d", flow_type);
8081 return -1;
8082 }
8083 }
8084
8085 val = get_param(cmd, "TWT_Trigger");
8086 if (val) {
8087 twt_trigger = atoi(val);
8088 if (twt_trigger != 0 && twt_trigger != 1) {
8089 sigma_dut_print(dut, DUT_MSG_ERROR,
8090 "TWT: Invalid TWT_Trigger %d",
8091 twt_trigger);
8092 return -1;
8093 }
8094 }
8095
8096 val = get_param(cmd, "Protection");
8097 if (val) {
8098 protection = atoi(val);
8099 if (protection != 0 && protection != 1) {
8100 sigma_dut_print(dut, DUT_MSG_ERROR,
8101 "TWT: Invalid Protection %d",
8102 protection);
8103 return -1;
8104 }
8105 }
8106
8107 val = get_param(cmd, "TargetWakeTime");
8108 if (val)
8109 target_wake_time = atoi(val);
8110
8111 val = get_param(cmd, "WakeIntervalMantissa");
8112 if (val)
8113 wake_interval_mantissa = atoi(val);
8114
8115 val = get_param(cmd, "WakeIntervalExp");
8116 if (val)
8117 wake_interval_exp = atoi(val);
8118
8119 val = get_param(cmd, "NominalMinWakeDur");
8120 if (val)
8121 nominal_min_wake_dur = atoi(val);
8122
8123 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8124 NL80211_CMD_VENDOR)) ||
8125 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8126 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8127 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8128 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8129 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8130 !(params = nla_nest_start(
8131 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8132 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8133 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8134 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008135 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008136 (twt_trigger &&
8137 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008138 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8139 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008140 (protection &&
8141 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008142 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8143 target_wake_time) ||
8144 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8145 nominal_min_wake_dur) ||
8146 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8147 wake_interval_mantissa)) {
8148 sigma_dut_print(dut, DUT_MSG_ERROR,
8149 "%s: err in adding vendor_cmd and vendor_data",
8150 __func__);
8151 nlmsg_free(msg);
8152 return -1;
8153 }
8154 nla_nest_end(msg, attr1);
8155 nla_nest_end(msg, params);
8156 nla_nest_end(msg, attr);
8157
8158 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8159 if (ret) {
8160 sigma_dut_print(dut, DUT_MSG_ERROR,
8161 "%s: err in send_and_recv_msgs, ret=%d",
8162 __func__, ret);
8163 }
8164
8165 return ret;
8166#else /* NL80211_SUPPORT */
8167 sigma_dut_print(dut, DUT_MSG_ERROR,
8168 "TWT request cannot be done without NL80211_SUPPORT defined");
8169 return -1;
8170#endif /* NL80211_SUPPORT */
8171}
8172
8173
8174static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8175 struct sigma_cmd *cmd)
8176{
8177 #ifdef NL80211_SUPPORT
8178 struct nlattr *params;
8179 struct nlattr *attr;
8180 struct nlattr *attr1;
8181 int ifindex, ret;
8182 struct nl_msg *msg;
8183 const char *intf = get_param(cmd, "Interface");
8184
8185 ifindex = if_nametoindex(intf);
8186 if (ifindex == 0) {
8187 sigma_dut_print(dut, DUT_MSG_ERROR,
8188 "%s: Index for interface %s failed",
8189 __func__, intf);
8190 return -1;
8191 }
8192
8193 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8194 NL80211_CMD_VENDOR)) ||
8195 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8196 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8197 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8198 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8199 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8200 !(params = nla_nest_start(
8201 msg,
8202 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8203 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8204 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8205 sigma_dut_print(dut, DUT_MSG_ERROR,
8206 "%s: err in adding vendor_cmd and vendor_data",
8207 __func__);
8208 nlmsg_free(msg);
8209 return -1;
8210 }
8211 nla_nest_end(msg, attr1);
8212 nla_nest_end(msg, params);
8213 nla_nest_end(msg, attr);
8214
8215 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8216 if (ret) {
8217 sigma_dut_print(dut, DUT_MSG_ERROR,
8218 "%s: err in send_and_recv_msgs, ret=%d",
8219 __func__, ret);
8220 }
8221
8222 return ret;
8223#else /* NL80211_SUPPORT */
8224 sigma_dut_print(dut, DUT_MSG_ERROR,
8225 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8226 return -1;
8227#endif /* NL80211_SUPPORT */
8228}
8229
8230
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008231static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8232 struct sigma_cmd *cmd)
8233{
8234#ifdef NL80211_SUPPORT
8235 struct nlattr *params;
8236 struct nlattr *attr;
8237 struct nlattr *attr1;
8238 struct nl_msg *msg;
8239 int ifindex, ret;
8240 const char *val;
8241 const char *intf = get_param(cmd, "Interface");
8242 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8243 ulmu_data_dis = 0;
8244
8245 ifindex = if_nametoindex(intf);
8246 if (ifindex == 0) {
8247 sigma_dut_print(dut, DUT_MSG_ERROR,
8248 "%s: Index for interface %s failed",
8249 __func__, intf);
8250 return -1;
8251 }
8252 val = get_param(cmd, "OMCtrl_RxNSS");
8253 if (val)
8254 rx_nss = atoi(val);
8255
8256 val = get_param(cmd, "OMCtrl_ChnlWidth");
8257 if (val)
8258 ch_bw = atoi(val);
8259
8260 val = get_param(cmd, "OMCtrl_ULMUDisable");
8261 if (val)
8262 ulmu_dis = atoi(val);
8263
8264 val = get_param(cmd, "OMCtrl_TxNSTS");
8265 if (val)
8266 tx_nsts = atoi(val);
8267
8268 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8269 if (val)
8270 ulmu_data_dis = atoi(val);
8271
8272 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8273 NL80211_CMD_VENDOR)) ||
8274 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8275 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8276 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8277 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8278 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8279 !(params = nla_nest_start(
8280 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8281 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8282 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8283 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8284 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8285 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8286 ulmu_data_dis) ||
8287 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8288 ulmu_dis)) {
8289 sigma_dut_print(dut, DUT_MSG_ERROR,
8290 "%s: err in adding vendor_cmd and vendor_data",
8291 __func__);
8292 nlmsg_free(msg);
8293 return -1;
8294 }
8295 nla_nest_end(msg, attr1);
8296 nla_nest_end(msg, params);
8297 nla_nest_end(msg, attr);
8298
8299 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8300 if (ret) {
8301 sigma_dut_print(dut, DUT_MSG_ERROR,
8302 "%s: err in send_and_recv_msgs, ret=%d",
8303 __func__, ret);
8304 }
8305
8306 return ret;
8307#else /* NL80211_SUPPORT */
8308 sigma_dut_print(dut, DUT_MSG_ERROR,
8309 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8310 return -1;
8311#endif /* NL80211_SUPPORT */
8312}
8313
8314
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008315static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8316 struct sigma_conn *conn,
8317 struct sigma_cmd *cmd)
8318{
8319 const char *intf = get_param(cmd, "Interface");
8320 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008321 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008322 int tkip = -1;
8323 int wep = -1;
8324
Arif Hussaina37e9552018-06-20 17:05:59 -07008325 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008326 val = get_param(cmd, "SGI80");
8327 if (val) {
8328 int sgi80;
8329
8330 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008331 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008332 }
8333
8334 val = get_param(cmd, "TxBF");
8335 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008336 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008337 case DRIVER_WCN:
8338 if (sta_set_tx_beamformee(dut, intf, 1)) {
8339 send_resp(dut, conn, SIGMA_ERROR,
8340 "ErrorCode,Failed to set TX beamformee enable");
8341 return 0;
8342 }
8343 break;
8344 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008345 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008346 send_resp(dut, conn, SIGMA_ERROR,
8347 "ErrorCode,Setting vhtsubfee failed");
8348 return 0;
8349 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008350 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008351 send_resp(dut, conn, SIGMA_ERROR,
8352 "ErrorCode,Setting vhtsubfer failed");
8353 return 0;
8354 }
8355 break;
8356 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008357 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008358 "Unsupported driver type");
8359 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008360 }
8361 }
8362
8363 val = get_param(cmd, "MU_TxBF");
8364 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008365 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008366 case DRIVER_ATHEROS:
8367 ath_sta_set_txsp_stream(dut, intf, "1SS");
8368 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008369 run_iwpriv(dut, intf, "vhtmubfee 1");
8370 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308371 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008372 case DRIVER_WCN:
8373 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8374 send_resp(dut, conn, SIGMA_ERROR,
8375 "ErrorCode,Failed to set RX/TXSP_STREAM");
8376 return 0;
8377 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308378 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008379 default:
8380 sigma_dut_print(dut, DUT_MSG_ERROR,
8381 "Setting SP_STREAM not supported");
8382 break;
8383 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008384 }
8385
8386 val = get_param(cmd, "LDPC");
8387 if (val) {
8388 int ldpc;
8389
8390 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008391 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008392 }
8393
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008394 val = get_param(cmd, "BCC");
8395 if (val) {
8396 int bcc;
8397
8398 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8399 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8400 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008401 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008402 }
8403
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008404 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8405 if (val && dut->sta_nss == 1)
8406 cmd_set_max_he_mcs(dut, intf, atoi(val));
8407
8408 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8409 if (val && dut->sta_nss == 2)
8410 cmd_set_max_he_mcs(dut, intf, atoi(val));
8411
Arif Hussainac6c5112018-05-25 17:34:00 -07008412 val = get_param(cmd, "MCS_FixedRate");
8413 if (val) {
8414#ifdef NL80211_SUPPORT
8415 int mcs, ratecode = 0;
8416 enum he_mcs_config mcs_config;
8417 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008418 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008419
8420 ratecode = (0x07 & dut->sta_nss) << 5;
8421 mcs = atoi(val);
8422 /* Add the MCS to the ratecode */
8423 if (mcs >= 0 && mcs <= 11) {
8424 ratecode += mcs;
8425 if (dut->device_type == STA_testbed &&
8426 mcs > 7 && mcs <= 11) {
8427 if (mcs <= 9)
8428 mcs_config = HE_80_MCS0_9;
8429 else
8430 mcs_config = HE_80_MCS0_11;
8431 ret = sta_set_he_mcs(dut, intf, mcs_config);
8432 if (ret) {
8433 sigma_dut_print(dut, DUT_MSG_ERROR,
8434 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8435 mcs, mcs_config, ret);
8436 }
8437 }
8438 snprintf(buf, sizeof(buf),
8439 "iwpriv %s set_11ax_rate 0x%03x",
8440 intf, ratecode);
8441 if (system(buf) != 0) {
8442 sigma_dut_print(dut, DUT_MSG_ERROR,
8443 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8444 ratecode);
8445 }
8446 } else {
8447 sigma_dut_print(dut, DUT_MSG_ERROR,
8448 "MCS_FixedRate: HE MCS %d not supported",
8449 mcs);
8450 }
8451#else /* NL80211_SUPPORT */
8452 sigma_dut_print(dut, DUT_MSG_ERROR,
8453 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8454#endif /* NL80211_SUPPORT */
8455 }
8456
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008457 val = get_param(cmd, "opt_md_notif_ie");
8458 if (val) {
8459 char *result = NULL;
8460 char delim[] = ";";
8461 char token[30];
8462 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308463 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008464
Peng Xub8fc5cc2017-05-10 17:27:28 -07008465 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308466 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008467
8468 /* Extract the NSS information */
8469 if (result) {
8470 value = atoi(result);
8471 switch (value) {
8472 case 1:
8473 config_val = 1;
8474 break;
8475 case 2:
8476 config_val = 3;
8477 break;
8478 case 3:
8479 config_val = 7;
8480 break;
8481 case 4:
8482 config_val = 15;
8483 break;
8484 default:
8485 config_val = 3;
8486 break;
8487 }
8488
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008489 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8490 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008491
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008492 }
8493
8494 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308495 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008496 if (result) {
8497 value = atoi(result);
8498 switch (value) {
8499 case 20:
8500 config_val = 0;
8501 break;
8502 case 40:
8503 config_val = 1;
8504 break;
8505 case 80:
8506 config_val = 2;
8507 break;
8508 case 160:
8509 config_val = 3;
8510 break;
8511 default:
8512 config_val = 2;
8513 break;
8514 }
8515
8516 dut->chwidth = config_val;
8517
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008518 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008519 }
8520
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008521 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008522 }
8523
8524 val = get_param(cmd, "nss_mcs_cap");
8525 if (val) {
8526 int nss, mcs;
8527 char token[20];
8528 char *result = NULL;
8529 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308530 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008531
Peng Xub8fc5cc2017-05-10 17:27:28 -07008532 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308533 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308534 if (!result) {
8535 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008536 "NSS not specified");
8537 send_resp(dut, conn, SIGMA_ERROR,
8538 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308539 return 0;
8540 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008541 nss = atoi(result);
8542
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008543 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008544 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008545
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308546 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008547 if (result == NULL) {
8548 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008549 "MCS not specified");
8550 send_resp(dut, conn, SIGMA_ERROR,
8551 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008552 return 0;
8553 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308554 result = strtok_r(result, "-", &saveptr);
8555 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308556 if (!result) {
8557 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008558 "MCS not specified");
8559 send_resp(dut, conn, SIGMA_ERROR,
8560 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308561 return 0;
8562 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008563 mcs = atoi(result);
8564
Arif Hussaina37e9552018-06-20 17:05:59 -07008565 if (program && strcasecmp(program, "HE") == 0) {
8566#ifdef NL80211_SUPPORT
8567 enum he_mcs_config mcs_config;
8568 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008569
Arif Hussaina37e9552018-06-20 17:05:59 -07008570 if (mcs >= 0 && mcs <= 7) {
8571 mcs_config = HE_80_MCS0_7;
8572 } else if (mcs > 7 && mcs <= 9) {
8573 mcs_config = HE_80_MCS0_9;
8574 } else if (mcs > 9 && mcs <= 11) {
8575 mcs_config = HE_80_MCS0_11;
8576 } else {
8577 sigma_dut_print(dut, DUT_MSG_ERROR,
8578 "nss_mcs_cap: HE: Invalid mcs: %d",
8579 mcs);
8580 send_resp(dut, conn, SIGMA_ERROR,
8581 "errorCode,Invalid MCS");
8582 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008583 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008584
8585 ret = sta_set_he_mcs(dut, intf, mcs_config);
8586 if (ret) {
8587 sigma_dut_print(dut, DUT_MSG_ERROR,
8588 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8589 mcs_config, ret);
8590 send_resp(dut, conn, SIGMA_ERROR,
8591 "errorCode,Failed to set MCS");
8592 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008593 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008594#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008595 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008596 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8597#endif /* NL80211_SUPPORT */
8598 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008599 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008600
8601 switch (nss) {
8602 case 1:
8603 switch (mcs) {
8604 case 7:
8605 vht_mcsmap = 0xfffc;
8606 break;
8607 case 8:
8608 vht_mcsmap = 0xfffd;
8609 break;
8610 case 9:
8611 vht_mcsmap = 0xfffe;
8612 break;
8613 default:
8614 vht_mcsmap = 0xfffe;
8615 break;
8616 }
8617 break;
8618 case 2:
8619 switch (mcs) {
8620 case 7:
8621 vht_mcsmap = 0xfff0;
8622 break;
8623 case 8:
8624 vht_mcsmap = 0xfff5;
8625 break;
8626 case 9:
8627 vht_mcsmap = 0xfffa;
8628 break;
8629 default:
8630 vht_mcsmap = 0xfffa;
8631 break;
8632 }
8633 break;
8634 case 3:
8635 switch (mcs) {
8636 case 7:
8637 vht_mcsmap = 0xffc0;
8638 break;
8639 case 8:
8640 vht_mcsmap = 0xffd5;
8641 break;
8642 case 9:
8643 vht_mcsmap = 0xffea;
8644 break;
8645 default:
8646 vht_mcsmap = 0xffea;
8647 break;
8648 }
8649 break;
8650 default:
8651 vht_mcsmap = 0xffea;
8652 break;
8653 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008654 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008655 }
8656 }
8657
8658 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8659
8660 val = get_param(cmd, "Vht_tkip");
8661 if (val)
8662 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8663
8664 val = get_param(cmd, "Vht_wep");
8665 if (val)
8666 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8667
8668 if (tkip != -1 || wep != -1) {
8669 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008670 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008671 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008672 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008673 } else {
8674 sigma_dut_print(dut, DUT_MSG_ERROR,
8675 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8676 return 0;
8677 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008678 }
8679
Arif Hussain55f00da2018-07-03 08:28:26 -07008680 val = get_param(cmd, "txBandwidth");
8681 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008682 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008683 case DRIVER_WCN:
8684 if (wcn_sta_set_width(dut, intf, val) < 0) {
8685 send_resp(dut, conn, SIGMA_ERROR,
8686 "ErrorCode,Failed to set txBandwidth");
8687 return 0;
8688 }
8689 break;
8690 case DRIVER_ATHEROS:
8691 if (ath_set_width(dut, conn, intf, val) < 0) {
8692 send_resp(dut, conn, SIGMA_ERROR,
8693 "ErrorCode,Failed to set txBandwidth");
8694 return 0;
8695 }
8696 break;
8697 default:
8698 sigma_dut_print(dut, DUT_MSG_ERROR,
8699 "Setting txBandwidth not supported");
8700 break;
8701 }
8702 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008703
Arif Hussain9765f7d2018-07-03 08:28:26 -07008704 val = get_param(cmd, "BeamformeeSTS");
8705 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008706 if (sta_set_tx_beamformee(dut, intf, 1)) {
8707 send_resp(dut, conn, SIGMA_ERROR,
8708 "ErrorCode,Failed to set TX beamformee enable");
8709 return 0;
8710 }
8711
Arif Hussain9765f7d2018-07-03 08:28:26 -07008712 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8713 send_resp(dut, conn, SIGMA_ERROR,
8714 "ErrorCode,Failed to set BeamformeeSTS");
8715 return 0;
8716 }
8717 }
8718
Arif Hussain68d23f52018-07-11 13:39:08 -07008719 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8720 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008721#ifdef NL80211_SUPPORT
8722 enum qca_wlan_he_mac_padding_dur set_val;
8723
8724 switch (atoi(val)) {
8725 case 16:
8726 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8727 break;
8728 case 8:
8729 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8730 break;
8731 default:
8732 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8733 break;
8734 }
8735 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008736 send_resp(dut, conn, SIGMA_ERROR,
8737 "ErrorCode,Failed to set MAC padding duration");
8738 return 0;
8739 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008740#else /* NL80211_SUPPORT */
8741 sigma_dut_print(dut, DUT_MSG_ERROR,
8742 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8743#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008744 }
8745
Arif Hussain480d5f42019-03-12 14:40:42 -07008746 val = get_param(cmd, "TWT_ReqSupport");
8747 if (val) {
8748 int set_val;
8749
8750 if (strcasecmp(val, "Enable") == 0) {
8751 set_val = 1;
8752 } else if (strcasecmp(val, "Disable") == 0) {
8753 set_val = 0;
8754 } else {
8755 send_resp(dut, conn, SIGMA_ERROR,
8756 "ErrorCode,Invalid TWT_ReqSupport");
8757 return STATUS_SENT;
8758 }
8759
8760 if (sta_set_twt_req_support(dut, intf, set_val)) {
8761 sigma_dut_print(dut, DUT_MSG_ERROR,
8762 "Failed to set TWT req support %d",
8763 set_val);
8764 send_resp(dut, conn, SIGMA_ERROR,
8765 "ErrorCode,Failed to set TWT_ReqSupport");
8766 return STATUS_SENT;
8767 }
8768 }
8769
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008770 val = get_param(cmd, "MU_EDCA");
8771 if (val && (strcasecmp(val, "Override") == 0)) {
8772 if (sta_set_mu_edca_override(dut, intf, 1)) {
8773 send_resp(dut, conn, SIGMA_ERROR,
8774 "ErrorCode,Failed to set MU EDCA override");
8775 return 0;
8776 }
8777 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008778
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008779 val = get_param(cmd, "OMControl");
8780 if (val) {
8781 int set_val = 1;
8782
8783 if (strcasecmp(val, "Enable") == 0)
8784 set_val = 1;
8785 else if (strcasecmp(val, "Disable") == 0)
8786 set_val = 0;
8787
8788 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8789 send_resp(dut, conn, SIGMA_ERROR,
8790 "ErrorCode,Failed to set OM ctrl supp");
8791 return 0;
8792 }
8793 }
8794
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008795 val = get_param(cmd, "ADDBAResp_BufSize");
8796 if (val) {
8797 int buf_size;
8798
8799 if (strcasecmp(val, "gt64") == 0)
8800 buf_size = 256;
8801 else
8802 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008803 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008804 sta_set_addba_buf_size(dut, intf, buf_size)) {
8805 send_resp(dut, conn, SIGMA_ERROR,
8806 "ErrorCode,set addbaresp_buff_size failed");
8807 return 0;
8808 }
8809 }
8810
8811 val = get_param(cmd, "ADDBAReq_BufSize");
8812 if (val) {
8813 int buf_size;
8814
8815 if (strcasecmp(val, "gt64") == 0)
8816 buf_size = 256;
8817 else
8818 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008819 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008820 sta_set_addba_buf_size(dut, intf, buf_size)) {
8821 send_resp(dut, conn, SIGMA_ERROR,
8822 "ErrorCode,set addbareq_buff_size failed");
8823 return 0;
8824 }
8825 }
8826
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008827 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8828}
8829
8830
8831static int sta_set_wireless_60g(struct sigma_dut *dut,
8832 struct sigma_conn *conn,
8833 struct sigma_cmd *cmd)
8834{
8835 const char *dev_role = get_param(cmd, "DevRole");
8836
8837 if (!dev_role) {
8838 send_resp(dut, conn, SIGMA_INVALID,
8839 "ErrorCode,DevRole not specified");
8840 return 0;
8841 }
8842
8843 if (strcasecmp(dev_role, "PCP") == 0)
8844 return sta_set_60g_pcp(dut, conn, cmd);
8845 if (strcasecmp(dev_role, "STA") == 0)
8846 return sta_set_60g_sta(dut, conn, cmd);
8847 send_resp(dut, conn, SIGMA_INVALID,
8848 "ErrorCode,DevRole not supported");
8849 return 0;
8850}
8851
8852
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308853static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8854 struct sigma_cmd *cmd)
8855{
8856 int status;
8857 const char *intf = get_param(cmd, "Interface");
8858 const char *val = get_param(cmd, "DevRole");
8859
8860 if (val && strcasecmp(val, "STA-CFON") == 0) {
8861 status = sta_cfon_set_wireless(dut, conn, cmd);
8862 if (status)
8863 return status;
8864 }
8865 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8866}
8867
8868
Jouni Malinenf7222712019-06-13 01:50:21 +03008869static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
8870 struct sigma_conn *conn,
8871 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008872{
8873 const char *val;
8874
8875 val = get_param(cmd, "Program");
8876 if (val) {
8877 if (strcasecmp(val, "11n") == 0)
8878 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008879 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008880 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8881 if (strcasecmp(val, "60ghz") == 0)
8882 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308883 if (strcasecmp(val, "OCE") == 0)
8884 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008885 /* sta_set_wireless in WPS program is only used for 60G */
8886 if (is_60g_sigma_dut(dut))
8887 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008888 send_resp(dut, conn, SIGMA_ERROR,
8889 "ErrorCode,Program value not supported");
8890 } else {
8891 send_resp(dut, conn, SIGMA_ERROR,
8892 "ErrorCode,Program argument not available");
8893 }
8894
8895 return 0;
8896}
8897
8898
8899static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8900 int tid)
8901{
8902 char buf[100];
8903 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8904
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308905 if (tid < 0 ||
8906 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8907 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8908 return;
8909 }
8910
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008911 /*
8912 * Two ways to ensure that addba request with a
8913 * non zero TID could be sent out. EV 117296
8914 */
8915 snprintf(buf, sizeof(buf),
8916 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8917 tid);
8918 if (system(buf) != 0) {
8919 sigma_dut_print(dut, DUT_MSG_ERROR,
8920 "Ping did not send out");
8921 }
8922
8923 snprintf(buf, sizeof(buf),
8924 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8925 intf, VI_QOS_TMP_FILE);
8926 if (system(buf) != 0)
8927 return;
8928
8929 snprintf(buf, sizeof(buf),
8930 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8931 intf, VI_QOS_TMP_FILE);
8932 if (system(buf) != 0)
8933 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8934
8935 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8936 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8937 if (system(buf) != 0) {
8938 sigma_dut_print(dut, DUT_MSG_ERROR,
8939 "VI_QOS_TEMP_FILE generation error failed");
8940 }
8941 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8942 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8943 if (system(buf) != 0) {
8944 sigma_dut_print(dut, DUT_MSG_ERROR,
8945 "VI_QOS_FILE generation failed");
8946 }
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), "ethinject %s %s", intf, VI_QOS_FILE);
8956 if (system(buf) != 0) {
8957 }
8958}
8959
8960
8961static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8962 struct sigma_cmd *cmd)
8963{
8964 const char *intf = get_param(cmd, "Interface");
8965 const char *val;
8966 int tid = 0;
8967 char buf[100];
8968
8969 val = get_param(cmd, "TID");
8970 if (val) {
8971 tid = atoi(val);
8972 if (tid)
8973 ath_sta_inject_frame(dut, intf, tid);
8974 }
8975
8976 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008977 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008978
8979 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8980 if (system(buf) != 0) {
8981 sigma_dut_print(dut, DUT_MSG_ERROR,
8982 "wifitool senddelba failed");
8983 }
8984
8985 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8986 if (system(buf) != 0) {
8987 sigma_dut_print(dut, DUT_MSG_ERROR,
8988 "wifitool sendaddba failed");
8989 }
8990
8991 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8992
8993 return 1;
8994}
8995
8996
Lior David9981b512017-01-20 13:16:40 +02008997#ifdef __linux__
8998
8999static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9000 int agg_size)
9001{
9002 char dir[128], buf[128];
9003 FILE *f;
9004 regex_t re;
9005 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009006 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009007
9008 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9009 sigma_dut_print(dut, DUT_MSG_ERROR,
9010 "failed to get wil6210 debugfs dir");
9011 return -1;
9012 }
9013
Jouni Malinen3aa72862019-05-29 23:14:51 +03009014 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9015 if (res < 0 || res >= sizeof(buf))
9016 return -1;
Lior David9981b512017-01-20 13:16:40 +02009017 f = fopen(buf, "r");
9018 if (!f) {
9019 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009020 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009021 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9022 if (res < 0 || res >= sizeof(buf))
9023 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009024 f = fopen(buf, "r");
9025 if (!f) {
9026 sigma_dut_print(dut, DUT_MSG_ERROR,
9027 "failed to open: %s", buf);
9028 return -1;
9029 }
Lior David9981b512017-01-20 13:16:40 +02009030 }
9031
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009032 /* can be either VRING tx... or RING... */
9033 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009034 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9035 goto out;
9036 }
9037
9038 /* find TX VRING for the mac address */
9039 found = 0;
9040 while (fgets(buf, sizeof(buf), f)) {
9041 if (strcasestr(buf, dest_mac)) {
9042 found = 1;
9043 break;
9044 }
9045 }
9046
9047 if (!found) {
9048 sigma_dut_print(dut, DUT_MSG_ERROR,
9049 "no TX VRING for %s", dest_mac);
9050 goto out;
9051 }
9052
9053 /* extract VRING ID, "VRING tx_<id> = {" */
9054 if (!fgets(buf, sizeof(buf), f)) {
9055 sigma_dut_print(dut, DUT_MSG_ERROR,
9056 "no VRING start line for %s", dest_mac);
9057 goto out;
9058 }
9059
9060 rc = regexec(&re, buf, 2, m, 0);
9061 regfree(&re);
9062 if (rc || m[1].rm_so < 0) {
9063 sigma_dut_print(dut, DUT_MSG_ERROR,
9064 "no VRING TX ID for %s", dest_mac);
9065 goto out;
9066 }
9067 buf[m[1].rm_eo] = 0;
9068 vring_id = atoi(&buf[m[1].rm_so]);
9069
9070 /* send the addba command */
9071 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009072 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9073 if (res < 0 || res >= sizeof(buf))
9074 return -1;
Lior David9981b512017-01-20 13:16:40 +02009075 f = fopen(buf, "w");
9076 if (!f) {
9077 sigma_dut_print(dut, DUT_MSG_ERROR,
9078 "failed to open: %s", buf);
9079 return -1;
9080 }
9081
9082 fprintf(f, "add %d %d\n", vring_id, agg_size);
9083
9084 ret = 0;
9085
9086out:
9087 fclose(f);
9088
9089 return ret;
9090}
9091
9092
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009093int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9094 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009095{
9096 const char *val;
9097 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009098
9099 val = get_param(cmd, "TID");
9100 if (val) {
9101 tid = atoi(val);
9102 if (tid != 0) {
9103 sigma_dut_print(dut, DUT_MSG_ERROR,
9104 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9105 tid);
9106 }
9107 }
9108
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009109 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009110 if (!val) {
9111 sigma_dut_print(dut, DUT_MSG_ERROR,
9112 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009113 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009114 }
9115
Lior David9981b512017-01-20 13:16:40 +02009116 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009117 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009118
9119 return 1;
9120}
9121
Lior David9981b512017-01-20 13:16:40 +02009122#endif /* __linux__ */
9123
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009124
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009125static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9126 struct sigma_cmd *cmd)
9127{
9128#ifdef NL80211_SUPPORT
9129 const char *intf = get_param(cmd, "Interface");
9130 const char *val;
9131 int tid = -1;
9132 int bufsize = 64;
9133 struct nl_msg *msg;
9134 int ret = 0;
9135 struct nlattr *params;
9136 int ifindex;
9137
9138 val = get_param(cmd, "TID");
9139 if (val)
9140 tid = atoi(val);
9141
9142 if (tid == -1) {
9143 send_resp(dut, conn, SIGMA_ERROR,
9144 "ErrorCode,sta_send_addba tid invalid");
9145 return 0;
9146 }
9147
9148 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9149
9150 ifindex = if_nametoindex(intf);
9151 if (ifindex == 0) {
9152 sigma_dut_print(dut, DUT_MSG_ERROR,
9153 "%s: Index for interface %s failed",
9154 __func__, intf);
9155 send_resp(dut, conn, SIGMA_ERROR,
9156 "ErrorCode,sta_send_addba interface invalid");
9157 return 0;
9158 }
9159
9160 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9161 NL80211_CMD_VENDOR)) ||
9162 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9163 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9164 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9165 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9166 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9167 nla_put_u8(msg,
9168 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9169 QCA_WLAN_ADD_BA) ||
9170 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9171 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009172 nla_put_u16(msg,
9173 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9174 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009175 sigma_dut_print(dut, DUT_MSG_ERROR,
9176 "%s: err in adding vendor_cmd and vendor_data",
9177 __func__);
9178 nlmsg_free(msg);
9179 send_resp(dut, conn, SIGMA_ERROR,
9180 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9181 return 0;
9182 }
9183 nla_nest_end(msg, params);
9184
9185 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9186 if (ret) {
9187 sigma_dut_print(dut, DUT_MSG_ERROR,
9188 "%s: err in send_and_recv_msgs, ret=%d",
9189 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309190 if (ret == -EOPNOTSUPP)
9191 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009192 send_resp(dut, conn, SIGMA_ERROR,
9193 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9194 return 0;
9195 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009196#else /* NL80211_SUPPORT */
9197 sigma_dut_print(dut, DUT_MSG_ERROR,
9198 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009199#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309200
9201 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009202}
9203
9204
Jouni Malinenf7222712019-06-13 01:50:21 +03009205static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9206 struct sigma_conn *conn,
9207 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009208{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009209 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009210 case DRIVER_ATHEROS:
9211 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009212 case DRIVER_WCN:
9213 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009214#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009215 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009216 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009217#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009218 default:
9219 /*
9220 * There is no driver specific implementation for other drivers.
9221 * Ignore the command and report COMPLETE since the following
9222 * throughput test operation will end up sending ADDBA anyway.
9223 */
9224 return 1;
9225 }
9226}
9227
9228
9229int inject_eth_frame(int s, const void *data, size_t len,
9230 unsigned short ethtype, char *dst, char *src)
9231{
9232 struct iovec iov[4] = {
9233 {
9234 .iov_base = dst,
9235 .iov_len = ETH_ALEN,
9236 },
9237 {
9238 .iov_base = src,
9239 .iov_len = ETH_ALEN,
9240 },
9241 {
9242 .iov_base = &ethtype,
9243 .iov_len = sizeof(unsigned short),
9244 },
9245 {
9246 .iov_base = (void *) data,
9247 .iov_len = len,
9248 }
9249 };
9250 struct msghdr msg = {
9251 .msg_name = NULL,
9252 .msg_namelen = 0,
9253 .msg_iov = iov,
9254 .msg_iovlen = 4,
9255 .msg_control = NULL,
9256 .msg_controllen = 0,
9257 .msg_flags = 0,
9258 };
9259
9260 return sendmsg(s, &msg, 0);
9261}
9262
9263#if defined(__linux__) || defined(__QNXNTO__)
9264
9265int inject_frame(int s, const void *data, size_t len, int encrypt)
9266{
9267#define IEEE80211_RADIOTAP_F_WEP 0x04
9268#define IEEE80211_RADIOTAP_F_FRAG 0x08
9269 unsigned char rtap_hdr[] = {
9270 0x00, 0x00, /* radiotap version */
9271 0x0e, 0x00, /* radiotap length */
9272 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9273 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9274 0x00, /* padding */
9275 0x00, 0x00, /* RX and TX flags to indicate that */
9276 0x00, 0x00, /* this is the injected frame directly */
9277 };
9278 struct iovec iov[2] = {
9279 {
9280 .iov_base = &rtap_hdr,
9281 .iov_len = sizeof(rtap_hdr),
9282 },
9283 {
9284 .iov_base = (void *) data,
9285 .iov_len = len,
9286 }
9287 };
9288 struct msghdr msg = {
9289 .msg_name = NULL,
9290 .msg_namelen = 0,
9291 .msg_iov = iov,
9292 .msg_iovlen = 2,
9293 .msg_control = NULL,
9294 .msg_controllen = 0,
9295 .msg_flags = 0,
9296 };
9297
9298 if (encrypt)
9299 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9300
9301 return sendmsg(s, &msg, 0);
9302}
9303
9304
9305int open_monitor(const char *ifname)
9306{
9307#ifdef __QNXNTO__
9308 struct sockaddr_dl ll;
9309 int s;
9310
9311 memset(&ll, 0, sizeof(ll));
9312 ll.sdl_family = AF_LINK;
9313 ll.sdl_index = if_nametoindex(ifname);
9314 if (ll.sdl_index == 0) {
9315 perror("if_nametoindex");
9316 return -1;
9317 }
9318 s = socket(PF_INET, SOCK_RAW, 0);
9319#else /* __QNXNTO__ */
9320 struct sockaddr_ll ll;
9321 int s;
9322
9323 memset(&ll, 0, sizeof(ll));
9324 ll.sll_family = AF_PACKET;
9325 ll.sll_ifindex = if_nametoindex(ifname);
9326 if (ll.sll_ifindex == 0) {
9327 perror("if_nametoindex");
9328 return -1;
9329 }
9330 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9331#endif /* __QNXNTO__ */
9332 if (s < 0) {
9333 perror("socket[PF_PACKET,SOCK_RAW]");
9334 return -1;
9335 }
9336
9337 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9338 perror("monitor socket bind");
9339 close(s);
9340 return -1;
9341 }
9342
9343 return s;
9344}
9345
9346
9347static int hex2num(char c)
9348{
9349 if (c >= '0' && c <= '9')
9350 return c - '0';
9351 if (c >= 'a' && c <= 'f')
9352 return c - 'a' + 10;
9353 if (c >= 'A' && c <= 'F')
9354 return c - 'A' + 10;
9355 return -1;
9356}
9357
9358
9359int hwaddr_aton(const char *txt, unsigned char *addr)
9360{
9361 int i;
9362
9363 for (i = 0; i < 6; i++) {
9364 int a, b;
9365
9366 a = hex2num(*txt++);
9367 if (a < 0)
9368 return -1;
9369 b = hex2num(*txt++);
9370 if (b < 0)
9371 return -1;
9372 *addr++ = (a << 4) | b;
9373 if (i < 5 && *txt++ != ':')
9374 return -1;
9375 }
9376
9377 return 0;
9378}
9379
9380#endif /* defined(__linux__) || defined(__QNXNTO__) */
9381
9382enum send_frame_type {
9383 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9384};
9385enum send_frame_protection {
9386 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9387};
9388
9389
9390static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9391 enum send_frame_type frame,
9392 enum send_frame_protection protected,
9393 const char *dest)
9394{
9395#ifdef __linux__
9396 unsigned char buf[1000], *pos;
9397 int s, res;
9398 char bssid[20], addr[20];
9399 char result[32], ssid[100];
9400 size_t ssid_len;
9401
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009402 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009403 sizeof(result)) < 0 ||
9404 strncmp(result, "COMPLETED", 9) != 0) {
9405 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9406 return 0;
9407 }
9408
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009409 if (get_wpa_status(get_station_ifname(dut), "bssid",
9410 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009411 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9412 "current BSSID");
9413 return 0;
9414 }
9415
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009416 if (get_wpa_status(get_station_ifname(dut), "address",
9417 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009418 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9419 "own MAC address");
9420 return 0;
9421 }
9422
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009423 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009424 < 0) {
9425 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9426 "current SSID");
9427 return 0;
9428 }
9429 ssid_len = strlen(ssid);
9430
9431 pos = buf;
9432
9433 /* Frame Control */
9434 switch (frame) {
9435 case DISASSOC:
9436 *pos++ = 0xa0;
9437 break;
9438 case DEAUTH:
9439 *pos++ = 0xc0;
9440 break;
9441 case SAQUERY:
9442 *pos++ = 0xd0;
9443 break;
9444 case AUTH:
9445 *pos++ = 0xb0;
9446 break;
9447 case ASSOCREQ:
9448 *pos++ = 0x00;
9449 break;
9450 case REASSOCREQ:
9451 *pos++ = 0x20;
9452 break;
9453 case DLS_REQ:
9454 *pos++ = 0xd0;
9455 break;
9456 }
9457
9458 if (protected == INCORRECT_KEY)
9459 *pos++ = 0x40; /* Set Protected field to 1 */
9460 else
9461 *pos++ = 0x00;
9462
9463 /* Duration */
9464 *pos++ = 0x00;
9465 *pos++ = 0x00;
9466
9467 /* addr1 = DA (current AP) */
9468 hwaddr_aton(bssid, pos);
9469 pos += 6;
9470 /* addr2 = SA (own address) */
9471 hwaddr_aton(addr, pos);
9472 pos += 6;
9473 /* addr3 = BSSID (current AP) */
9474 hwaddr_aton(bssid, pos);
9475 pos += 6;
9476
9477 /* Seq# (to be filled by driver/mac80211) */
9478 *pos++ = 0x00;
9479 *pos++ = 0x00;
9480
9481 if (protected == INCORRECT_KEY) {
9482 /* CCMP parameters */
9483 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9484 pos += 8;
9485 }
9486
9487 if (protected == INCORRECT_KEY) {
9488 switch (frame) {
9489 case DEAUTH:
9490 /* Reason code (encrypted) */
9491 memcpy(pos, "\xa7\x39", 2);
9492 pos += 2;
9493 break;
9494 case DISASSOC:
9495 /* Reason code (encrypted) */
9496 memcpy(pos, "\xa7\x39", 2);
9497 pos += 2;
9498 break;
9499 case SAQUERY:
9500 /* Category|Action|TransID (encrypted) */
9501 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9502 pos += 4;
9503 break;
9504 default:
9505 return -1;
9506 }
9507
9508 /* CCMP MIC */
9509 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9510 pos += 8;
9511 } else {
9512 switch (frame) {
9513 case DEAUTH:
9514 /* reason code = 8 */
9515 *pos++ = 0x08;
9516 *pos++ = 0x00;
9517 break;
9518 case DISASSOC:
9519 /* reason code = 8 */
9520 *pos++ = 0x08;
9521 *pos++ = 0x00;
9522 break;
9523 case SAQUERY:
9524 /* Category - SA Query */
9525 *pos++ = 0x08;
9526 /* SA query Action - Request */
9527 *pos++ = 0x00;
9528 /* Transaction ID */
9529 *pos++ = 0x12;
9530 *pos++ = 0x34;
9531 break;
9532 case AUTH:
9533 /* Auth Alg (Open) */
9534 *pos++ = 0x00;
9535 *pos++ = 0x00;
9536 /* Seq# */
9537 *pos++ = 0x01;
9538 *pos++ = 0x00;
9539 /* Status code */
9540 *pos++ = 0x00;
9541 *pos++ = 0x00;
9542 break;
9543 case ASSOCREQ:
9544 /* Capability Information */
9545 *pos++ = 0x31;
9546 *pos++ = 0x04;
9547 /* Listen Interval */
9548 *pos++ = 0x0a;
9549 *pos++ = 0x00;
9550 /* SSID */
9551 *pos++ = 0x00;
9552 *pos++ = ssid_len;
9553 memcpy(pos, ssid, ssid_len);
9554 pos += ssid_len;
9555 /* Supported Rates */
9556 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9557 10);
9558 pos += 10;
9559 /* Extended Supported Rates */
9560 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9561 pos += 6;
9562 /* RSN */
9563 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9564 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9565 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9566 pos += 28;
9567 break;
9568 case REASSOCREQ:
9569 /* Capability Information */
9570 *pos++ = 0x31;
9571 *pos++ = 0x04;
9572 /* Listen Interval */
9573 *pos++ = 0x0a;
9574 *pos++ = 0x00;
9575 /* Current AP */
9576 hwaddr_aton(bssid, pos);
9577 pos += 6;
9578 /* SSID */
9579 *pos++ = 0x00;
9580 *pos++ = ssid_len;
9581 memcpy(pos, ssid, ssid_len);
9582 pos += ssid_len;
9583 /* Supported Rates */
9584 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9585 10);
9586 pos += 10;
9587 /* Extended Supported Rates */
9588 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9589 pos += 6;
9590 /* RSN */
9591 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9592 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9593 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9594 pos += 28;
9595 break;
9596 case DLS_REQ:
9597 /* Category - DLS */
9598 *pos++ = 0x02;
9599 /* DLS Action - Request */
9600 *pos++ = 0x00;
9601 /* Destination MACAddress */
9602 if (dest)
9603 hwaddr_aton(dest, pos);
9604 else
9605 memset(pos, 0, 6);
9606 pos += 6;
9607 /* Source MACAddress */
9608 hwaddr_aton(addr, pos);
9609 pos += 6;
9610 /* Capability Information */
9611 *pos++ = 0x10; /* Privacy */
9612 *pos++ = 0x06; /* QoS */
9613 /* DLS Timeout Value */
9614 *pos++ = 0x00;
9615 *pos++ = 0x01;
9616 /* Supported rates */
9617 *pos++ = 0x01;
9618 *pos++ = 0x08;
9619 *pos++ = 0x0c; /* 6 Mbps */
9620 *pos++ = 0x12; /* 9 Mbps */
9621 *pos++ = 0x18; /* 12 Mbps */
9622 *pos++ = 0x24; /* 18 Mbps */
9623 *pos++ = 0x30; /* 24 Mbps */
9624 *pos++ = 0x48; /* 36 Mbps */
9625 *pos++ = 0x60; /* 48 Mbps */
9626 *pos++ = 0x6c; /* 54 Mbps */
9627 /* TODO: Extended Supported Rates */
9628 /* TODO: HT Capabilities */
9629 break;
9630 }
9631 }
9632
9633 s = open_monitor("sigmadut");
9634 if (s < 0) {
9635 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9636 "monitor socket");
9637 return 0;
9638 }
9639
9640 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9641 if (res < 0) {
9642 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9643 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309644 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009645 return 0;
9646 }
9647 if (res < pos - buf) {
9648 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9649 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309650 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009651 return 0;
9652 }
9653
9654 close(s);
9655
9656 return 1;
9657#else /* __linux__ */
9658 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9659 "yet supported");
9660 return 0;
9661#endif /* __linux__ */
9662}
9663
9664
9665static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9666 struct sigma_conn *conn,
9667 struct sigma_cmd *cmd)
9668{
9669 const char *intf = get_param(cmd, "Interface");
9670 const char *sta, *val;
9671 unsigned char addr[ETH_ALEN];
9672 char buf[100];
9673
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009674 if (!intf)
9675 return -1;
9676
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009677 sta = get_param(cmd, "peer");
9678 if (sta == NULL)
9679 sta = get_param(cmd, "station");
9680 if (sta == NULL) {
9681 send_resp(dut, conn, SIGMA_ERROR,
9682 "ErrorCode,Missing peer address");
9683 return 0;
9684 }
9685 if (hwaddr_aton(sta, addr) < 0) {
9686 send_resp(dut, conn, SIGMA_ERROR,
9687 "ErrorCode,Invalid peer address");
9688 return 0;
9689 }
9690
9691 val = get_param(cmd, "type");
9692 if (val == NULL)
9693 return -1;
9694
9695 if (strcasecmp(val, "DISCOVERY") == 0) {
9696 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9697 if (wpa_command(intf, buf) < 0) {
9698 send_resp(dut, conn, SIGMA_ERROR,
9699 "ErrorCode,Failed to send TDLS discovery");
9700 return 0;
9701 }
9702 return 1;
9703 }
9704
9705 if (strcasecmp(val, "SETUP") == 0) {
9706 int status = 0, timeout = 0;
9707
9708 val = get_param(cmd, "Status");
9709 if (val)
9710 status = atoi(val);
9711
9712 val = get_param(cmd, "Timeout");
9713 if (val)
9714 timeout = atoi(val);
9715
9716 if (status != 0 && status != 37) {
9717 send_resp(dut, conn, SIGMA_ERROR,
9718 "ErrorCode,Unsupported status value");
9719 return 0;
9720 }
9721
9722 if (timeout != 0 && timeout != 301) {
9723 send_resp(dut, conn, SIGMA_ERROR,
9724 "ErrorCode,Unsupported timeout value");
9725 return 0;
9726 }
9727
9728 if (status && timeout) {
9729 send_resp(dut, conn, SIGMA_ERROR,
9730 "ErrorCode,Unsupported timeout+status "
9731 "combination");
9732 return 0;
9733 }
9734
9735 if (status == 37 &&
9736 wpa_command(intf, "SET tdls_testing 0x200")) {
9737 send_resp(dut, conn, SIGMA_ERROR,
9738 "ErrorCode,Failed to enable "
9739 "decline setup response test mode");
9740 return 0;
9741 }
9742
9743 if (timeout == 301) {
9744 int res;
9745 if (dut->no_tpk_expiration)
9746 res = wpa_command(intf,
9747 "SET tdls_testing 0x108");
9748 else
9749 res = wpa_command(intf,
9750 "SET tdls_testing 0x8");
9751 if (res) {
9752 send_resp(dut, conn, SIGMA_ERROR,
9753 "ErrorCode,Failed to set short TPK "
9754 "lifetime");
9755 return 0;
9756 }
9757 }
9758
9759 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9760 if (wpa_command(intf, buf) < 0) {
9761 send_resp(dut, conn, SIGMA_ERROR,
9762 "ErrorCode,Failed to send TDLS setup");
9763 return 0;
9764 }
9765 return 1;
9766 }
9767
9768 if (strcasecmp(val, "TEARDOWN") == 0) {
9769 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9770 if (wpa_command(intf, buf) < 0) {
9771 send_resp(dut, conn, SIGMA_ERROR,
9772 "ErrorCode,Failed to send TDLS teardown");
9773 return 0;
9774 }
9775 return 1;
9776 }
9777
9778 send_resp(dut, conn, SIGMA_ERROR,
9779 "ErrorCode,Unsupported TDLS frame");
9780 return 0;
9781}
9782
9783
9784static int sta_ap_known(const char *ifname, const char *bssid)
9785{
9786 char buf[4096];
9787
Jouni Malinendd32f192018-09-15 02:55:19 +03009788 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009789 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9790 return 0;
9791 if (strncmp(buf, "id=", 3) != 0)
9792 return 0;
9793 return 1;
9794}
9795
9796
9797static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9798 const char *bssid)
9799{
9800 int res;
9801 struct wpa_ctrl *ctrl;
9802 char buf[256];
9803
9804 if (sta_ap_known(ifname, bssid))
9805 return 0;
9806 sigma_dut_print(dut, DUT_MSG_DEBUG,
9807 "AP not in BSS table - start scan");
9808
9809 ctrl = open_wpa_mon(ifname);
9810 if (ctrl == NULL) {
9811 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9812 "wpa_supplicant monitor connection");
9813 return -1;
9814 }
9815
9816 if (wpa_command(ifname, "SCAN") < 0) {
9817 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9818 wpa_ctrl_detach(ctrl);
9819 wpa_ctrl_close(ctrl);
9820 return -1;
9821 }
9822
9823 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9824 buf, sizeof(buf));
9825
9826 wpa_ctrl_detach(ctrl);
9827 wpa_ctrl_close(ctrl);
9828
9829 if (res < 0) {
9830 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9831 return -1;
9832 }
9833
9834 if (sta_ap_known(ifname, bssid))
9835 return 0;
9836 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9837 return -1;
9838}
9839
9840
9841static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9842 struct sigma_conn *conn,
9843 struct sigma_cmd *cmd,
9844 const char *intf)
9845{
9846 char buf[200];
9847
9848 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9849 if (system(buf) != 0) {
9850 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9851 "ndsend");
9852 return 0;
9853 }
9854
9855 return 1;
9856}
9857
9858
9859static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9860 struct sigma_conn *conn,
9861 struct sigma_cmd *cmd,
9862 const char *intf)
9863{
9864 char buf[200];
9865 const char *ip = get_param(cmd, "SenderIP");
9866
Peng Xu26b356d2017-10-04 17:58:16 -07009867 if (!ip)
9868 return 0;
9869
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009870 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9871 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9872 if (system(buf) == 0) {
9873 sigma_dut_print(dut, DUT_MSG_INFO,
9874 "Neighbor Solicitation got a response "
9875 "for %s@%s", ip, intf);
9876 }
9877
9878 return 1;
9879}
9880
9881
9882static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9883 struct sigma_conn *conn,
9884 struct sigma_cmd *cmd,
9885 const char *ifname)
9886{
9887 char buf[200];
9888 const char *ip = get_param(cmd, "SenderIP");
9889
9890 if (ip == NULL) {
9891 send_resp(dut, conn, SIGMA_ERROR,
9892 "ErrorCode,Missing SenderIP parameter");
9893 return 0;
9894 }
9895 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9896 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9897 if (system(buf) != 0) {
9898 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9899 "for %s@%s", ip, ifname);
9900 }
9901
9902 return 1;
9903}
9904
9905
9906static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9907 struct sigma_conn *conn,
9908 struct sigma_cmd *cmd,
9909 const char *ifname)
9910{
9911 char buf[200];
9912 char ip[16];
9913 int s;
Peng Xub3756882017-10-04 14:39:09 -07009914 struct ifreq ifr;
9915 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009916
9917 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009918 if (s < 0) {
9919 perror("socket");
9920 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009921 }
9922
Peng Xub3756882017-10-04 14:39:09 -07009923 memset(&ifr, 0, sizeof(ifr));
9924 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9925 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9926 sigma_dut_print(dut, DUT_MSG_INFO,
9927 "Failed to get %s IP address: %s",
9928 ifname, strerror(errno));
9929 close(s);
9930 return -1;
9931 }
9932 close(s);
9933
9934 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9935 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9936
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009937 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9938 ip);
9939 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9940 if (system(buf) != 0) {
9941 }
9942
9943 return 1;
9944}
9945
9946
9947static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9948 struct sigma_conn *conn,
9949 struct sigma_cmd *cmd,
9950 const char *ifname)
9951{
9952 char buf[200], addr[20];
9953 char dst[ETH_ALEN], src[ETH_ALEN];
9954 short ethtype = htons(ETH_P_ARP);
9955 char *pos;
9956 int s, res;
9957 const char *val;
9958 struct sockaddr_in taddr;
9959
9960 val = get_param(cmd, "dest");
9961 if (val)
9962 hwaddr_aton(val, (unsigned char *) dst);
9963
9964 val = get_param(cmd, "DestIP");
9965 if (val)
9966 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009967 else
9968 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009969
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009970 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009971 sizeof(addr)) < 0)
9972 return -2;
9973 hwaddr_aton(addr, (unsigned char *) src);
9974
9975 pos = buf;
9976 *pos++ = 0x00;
9977 *pos++ = 0x01;
9978 *pos++ = 0x08;
9979 *pos++ = 0x00;
9980 *pos++ = 0x06;
9981 *pos++ = 0x04;
9982 *pos++ = 0x00;
9983 *pos++ = 0x02;
9984 memcpy(pos, src, ETH_ALEN);
9985 pos += ETH_ALEN;
9986 memcpy(pos, &taddr.sin_addr, 4);
9987 pos += 4;
9988 memcpy(pos, dst, ETH_ALEN);
9989 pos += ETH_ALEN;
9990 memcpy(pos, &taddr.sin_addr, 4);
9991 pos += 4;
9992
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009993 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009994 if (s < 0) {
9995 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9996 "monitor socket");
9997 return 0;
9998 }
9999
10000 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10001 if (res < 0) {
10002 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10003 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010004 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010005 return 0;
10006 }
10007
10008 close(s);
10009
10010 return 1;
10011}
10012
10013
10014static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10015 struct sigma_conn *conn,
10016 struct sigma_cmd *cmd,
10017 const char *intf, const char *dest)
10018{
10019 char buf[100];
10020
10021 if (if_nametoindex("sigmadut") == 0) {
10022 snprintf(buf, sizeof(buf),
10023 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010024 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010025 if (system(buf) != 0 ||
10026 if_nametoindex("sigmadut") == 0) {
10027 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10028 "monitor interface with '%s'", buf);
10029 return -2;
10030 }
10031 }
10032
10033 if (system("ifconfig sigmadut up") != 0) {
10034 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10035 "monitor interface up");
10036 return -2;
10037 }
10038
10039 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10040}
10041
10042
10043static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10044 struct sigma_conn *conn,
10045 struct sigma_cmd *cmd)
10046{
10047 const char *intf = get_param(cmd, "Interface");
10048 const char *dest = get_param(cmd, "Dest");
10049 const char *type = get_param(cmd, "FrameName");
10050 const char *val;
10051 char buf[200], *pos, *end;
10052 int count, count2;
10053
10054 if (type == NULL)
10055 type = get_param(cmd, "Type");
10056
10057 if (intf == NULL || dest == NULL || type == NULL)
10058 return -1;
10059
10060 if (strcasecmp(type, "NeighAdv") == 0)
10061 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10062
10063 if (strcasecmp(type, "NeighSolicitReq") == 0)
10064 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10065
10066 if (strcasecmp(type, "ARPProbe") == 0)
10067 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10068
10069 if (strcasecmp(type, "ARPAnnounce") == 0)
10070 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10071
10072 if (strcasecmp(type, "ARPReply") == 0)
10073 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10074
10075 if (strcasecmp(type, "DLS-request") == 0 ||
10076 strcasecmp(type, "DLSrequest") == 0)
10077 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10078 dest);
10079
10080 if (strcasecmp(type, "ANQPQuery") != 0 &&
10081 strcasecmp(type, "Query") != 0) {
10082 send_resp(dut, conn, SIGMA_ERROR,
10083 "ErrorCode,Unsupported HS 2.0 send frame type");
10084 return 0;
10085 }
10086
10087 if (sta_scan_ap(dut, intf, dest) < 0) {
10088 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10089 "the requested AP");
10090 return 0;
10091 }
10092
10093 pos = buf;
10094 end = buf + sizeof(buf);
10095 count = 0;
10096 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10097
10098 val = get_param(cmd, "ANQP_CAP_LIST");
10099 if (val && atoi(val)) {
10100 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10101 count++;
10102 }
10103
10104 val = get_param(cmd, "VENUE_NAME");
10105 if (val && atoi(val)) {
10106 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10107 count++;
10108 }
10109
10110 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10111 if (val && atoi(val)) {
10112 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10113 count++;
10114 }
10115
10116 val = get_param(cmd, "ROAMING_CONS");
10117 if (val && atoi(val)) {
10118 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10119 count++;
10120 }
10121
10122 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10123 if (val && atoi(val)) {
10124 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10125 count++;
10126 }
10127
10128 val = get_param(cmd, "NAI_REALM_LIST");
10129 if (val && atoi(val)) {
10130 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10131 count++;
10132 }
10133
10134 val = get_param(cmd, "3GPP_INFO");
10135 if (val && atoi(val)) {
10136 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10137 count++;
10138 }
10139
10140 val = get_param(cmd, "DOMAIN_LIST");
10141 if (val && atoi(val)) {
10142 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10143 count++;
10144 }
10145
Jouni Malinen34cf9532018-04-29 19:26:33 +030010146 val = get_param(cmd, "Venue_URL");
10147 if (val && atoi(val)) {
10148 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10149 count++;
10150 }
10151
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010152 val = get_param(cmd, "Advice_Of_Charge");
10153 if (val && atoi(val)) {
10154 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10155 count++;
10156 }
10157
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010158 if (count && wpa_command(intf, buf)) {
10159 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10160 return 0;
10161 }
10162
10163 pos = buf;
10164 end = buf + sizeof(buf);
10165 count2 = 0;
10166 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10167
10168 val = get_param(cmd, "HS_CAP_LIST");
10169 if (val && atoi(val)) {
10170 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10171 count2++;
10172 }
10173
10174 val = get_param(cmd, "OPER_NAME");
10175 if (val && atoi(val)) {
10176 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10177 count2++;
10178 }
10179
10180 val = get_param(cmd, "WAN_METRICS");
10181 if (!val)
10182 val = get_param(cmd, "WAN_MAT");
10183 if (!val)
10184 val = get_param(cmd, "WAN_MET");
10185 if (val && atoi(val)) {
10186 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10187 count2++;
10188 }
10189
10190 val = get_param(cmd, "CONNECTION_CAPABILITY");
10191 if (val && atoi(val)) {
10192 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10193 count2++;
10194 }
10195
10196 val = get_param(cmd, "OP_CLASS");
10197 if (val && atoi(val)) {
10198 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10199 count2++;
10200 }
10201
10202 val = get_param(cmd, "OSU_PROVIDER_LIST");
10203 if (val && atoi(val)) {
10204 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10205 count2++;
10206 }
10207
Jouni Malinenf67afec2018-04-29 19:24:58 +030010208 val = get_param(cmd, "OPER_ICON_METADATA");
10209 if (!val)
10210 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10211 if (val && atoi(val)) {
10212 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10213 count2++;
10214 }
10215
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010216 if (count && count2) {
10217 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10218 "second query");
10219 sleep(1);
10220 }
10221
10222 if (count2 && wpa_command(intf, buf)) {
10223 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10224 "failed");
10225 return 0;
10226 }
10227
10228 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10229 if (val) {
10230 if (count || count2) {
10231 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10232 "sending out second query");
10233 sleep(1);
10234 }
10235
10236 if (strcmp(val, "1") == 0)
10237 val = "mail.example.com";
10238 snprintf(buf, end - pos,
10239 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10240 dest, val);
10241 if (wpa_command(intf, buf)) {
10242 send_resp(dut, conn, SIGMA_ERROR,
10243 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10244 "failed");
10245 return 0;
10246 }
10247 }
10248
10249 val = get_param(cmd, "ICON_REQUEST");
10250 if (val) {
10251 if (count || count2) {
10252 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10253 "sending out second query");
10254 sleep(1);
10255 }
10256
10257 snprintf(buf, end - pos,
10258 "HS20_ICON_REQUEST %s %s", dest, val);
10259 if (wpa_command(intf, buf)) {
10260 send_resp(dut, conn, SIGMA_ERROR,
10261 "ErrorCode,HS20_ICON_REQUEST failed");
10262 return 0;
10263 }
10264 }
10265
10266 return 1;
10267}
10268
10269
10270static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10271 struct sigma_conn *conn,
10272 struct sigma_cmd *cmd)
10273{
10274 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010275 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010276 int chwidth, nss;
10277
10278 val = get_param(cmd, "framename");
10279 if (!val)
10280 return -1;
10281 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10282
10283 /* Command sequence to generate Op mode notification */
10284 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010285 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010286
10287 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010288 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010289
10290 /* Extract Channel width */
10291 val = get_param(cmd, "Channel_width");
10292 if (val) {
10293 switch (atoi(val)) {
10294 case 20:
10295 chwidth = 0;
10296 break;
10297 case 40:
10298 chwidth = 1;
10299 break;
10300 case 80:
10301 chwidth = 2;
10302 break;
10303 case 160:
10304 chwidth = 3;
10305 break;
10306 default:
10307 chwidth = 2;
10308 break;
10309 }
10310
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010311 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010312 }
10313
10314 /* Extract NSS */
10315 val = get_param(cmd, "NSS");
10316 if (val) {
10317 switch (atoi(val)) {
10318 case 1:
10319 nss = 1;
10320 break;
10321 case 2:
10322 nss = 3;
10323 break;
10324 case 3:
10325 nss = 7;
10326 break;
10327 default:
10328 /* We do not support NSS > 3 */
10329 nss = 3;
10330 break;
10331 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010332 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010333 }
10334
10335 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010336 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010337 }
10338
10339 return 1;
10340}
10341
10342
10343static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10344 struct sigma_conn *conn,
10345 struct sigma_cmd *cmd)
10346{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010347 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010348 case DRIVER_ATHEROS:
10349 return ath_sta_send_frame_vht(dut, conn, cmd);
10350 default:
10351 send_resp(dut, conn, SIGMA_ERROR,
10352 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10353 return 0;
10354 }
10355}
10356
10357
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010358static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10359 struct sigma_cmd *cmd)
10360{
10361 const char *val;
10362 const char *intf = get_param(cmd, "Interface");
10363
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010364 if (!intf)
10365 return -1;
10366
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010367 val = get_param(cmd, "framename");
10368 if (!val)
10369 return -1;
10370 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10371
10372 /* Command sequence to generate Op mode notification */
10373 if (val && strcasecmp(val, "action") == 0) {
10374 val = get_param(cmd, "PPDUTxType");
10375 if (val && strcasecmp(val, "TB") == 0) {
10376 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10377 sigma_dut_print(dut, DUT_MSG_ERROR,
10378 "failed to send TB PPDU Tx cfg");
10379 send_resp(dut, conn, SIGMA_ERROR,
10380 "ErrorCode,set TB PPDU Tx cfg failed");
10381 return 0;
10382 }
10383 return 1;
10384 }
10385
10386 sigma_dut_print(dut, DUT_MSG_ERROR,
10387 "Action Tx type is not defined");
10388 }
10389
10390 return 1;
10391}
10392
10393
10394static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10395 struct sigma_conn *conn,
10396 struct sigma_cmd *cmd)
10397{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010398 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010399 case DRIVER_WCN:
10400 return wcn_sta_send_frame_he(dut, conn, cmd);
10401 default:
10402 send_resp(dut, conn, SIGMA_ERROR,
10403 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10404 return 0;
10405 }
10406}
10407
10408
Lior David0fe101e2017-03-09 16:09:50 +020010409#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010410
10411static int
10412wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10413 const char *frame_name, const char *dest_mac)
10414{
10415 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10416 const char *ssid = get_param(cmd, "ssid");
10417 const char *countstr = get_param(cmd, "count");
10418 const char *channelstr = get_param(cmd, "channel");
10419 const char *group_id = get_param(cmd, "groupid");
10420 const char *client_id = get_param(cmd, "clientmac");
10421 int count, channel, freq, i;
10422 const char *fname;
10423 char frame[1024], src_mac[20], group_id_attr[25],
10424 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10425 const char *group_ssid;
10426 const int group_ssid_prefix_len = 9;
10427 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10428 size_t framelen = sizeof(frame);
10429 struct template_frame_tag tags[2];
10430 size_t tags_total = ARRAY_SIZE(tags);
10431 int tag_index, len, dst_len;
10432
10433 if (!countstr || !channelstr) {
10434 sigma_dut_print(dut, DUT_MSG_ERROR,
10435 "Missing argument: count, channel");
10436 return -1;
10437 }
10438 if (isprobereq && !ssid) {
10439 sigma_dut_print(dut, DUT_MSG_ERROR,
10440 "Missing argument: ssid");
10441 return -1;
10442 }
10443 if (!isprobereq && (!group_id || !client_id)) {
10444 sigma_dut_print(dut, DUT_MSG_ERROR,
10445 "Missing argument: group_id, client_id");
10446 return -1;
10447 }
10448
10449 count = atoi(countstr);
10450 channel = atoi(channelstr);
10451 freq = channel_to_freq(dut, channel);
10452
10453 if (!freq) {
10454 sigma_dut_print(dut, DUT_MSG_ERROR,
10455 "invalid channel: %s", channelstr);
10456 return -1;
10457 }
10458
10459 if (isprobereq) {
10460 if (strcasecmp(ssid, "wildcard") == 0) {
10461 fname = "probe_req_wildcard.txt";
10462 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10463 fname = "probe_req_P2P_Wildcard.txt";
10464 } else {
10465 sigma_dut_print(dut, DUT_MSG_ERROR,
10466 "invalid probe request type");
10467 return -1;
10468 }
10469 } else {
10470 fname = "P2P_device_discovery_req.txt";
10471 }
10472
10473 if (parse_template_frame_file(dut, fname, frame, &framelen,
10474 tags, &tags_total)) {
10475 sigma_dut_print(dut, DUT_MSG_ERROR,
10476 "invalid frame template: %s", fname);
10477 return -1;
10478 }
10479
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010480 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010481 src_mac, sizeof(src_mac)) < 0 ||
10482 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10483 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10484 return -1;
10485 /* Use wildcard BSSID, since we are in PBSS */
10486 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10487
10488 if (!isprobereq) {
10489 tag_index = find_template_frame_tag(tags, tags_total, 1);
10490 if (tag_index < 0) {
10491 sigma_dut_print(dut, DUT_MSG_ERROR,
10492 "can't find device id attribute");
10493 return -1;
10494 }
10495 if (parse_mac_address(dut, client_id,
10496 (unsigned char *) client_mac)) {
10497 sigma_dut_print(dut, DUT_MSG_ERROR,
10498 "invalid client_id: %s", client_id);
10499 return -1;
10500 }
10501 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10502 framelen - tags[tag_index].offset,
10503 IEEE80211_P2P_ATTR_DEVICE_ID,
10504 client_mac, ETH_ALEN)) {
10505 sigma_dut_print(dut, DUT_MSG_ERROR,
10506 "fail to replace device id attribute");
10507 return -1;
10508 }
10509
10510 /*
10511 * group_id arg contains device MAC address followed by
10512 * space and SSID (DIRECT-somessid).
10513 * group id attribute contains device address (6 bytes)
10514 * followed by SSID prefix DIRECT-XX (9 bytes)
10515 */
10516 if (strlen(group_id) < sizeof(device_macstr)) {
10517 sigma_dut_print(dut, DUT_MSG_ERROR,
10518 "group_id arg too short");
10519 return -1;
10520 }
10521 memcpy(device_macstr, group_id, sizeof(device_macstr));
10522 device_macstr[sizeof(device_macstr) - 1] = '\0';
10523 if (parse_mac_address(dut, device_macstr,
10524 (unsigned char *) group_id_attr)) {
10525 sigma_dut_print(dut, DUT_MSG_ERROR,
10526 "fail to parse device address from group_id");
10527 return -1;
10528 }
10529 group_ssid = strchr(group_id, ' ');
10530 if (!group_ssid) {
10531 sigma_dut_print(dut, DUT_MSG_ERROR,
10532 "invalid group_id arg, no ssid");
10533 return -1;
10534 }
10535 group_ssid++;
10536 len = strlen(group_ssid);
10537 if (len < group_ssid_prefix_len) {
10538 sigma_dut_print(dut, DUT_MSG_ERROR,
10539 "group_id SSID too short");
10540 return -1;
10541 }
10542 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10543 if (len > dst_len) {
10544 sigma_dut_print(dut, DUT_MSG_ERROR,
10545 "group_id SSID (%s) too long",
10546 group_ssid);
10547 return -1;
10548 }
10549
10550 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10551 tag_index = find_template_frame_tag(tags, tags_total, 2);
10552 if (tag_index < 0) {
10553 sigma_dut_print(dut, DUT_MSG_ERROR,
10554 "can't find group id attribute");
10555 return -1;
10556 }
10557 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10558 framelen - tags[tag_index].offset,
10559 IEEE80211_P2P_ATTR_GROUP_ID,
10560 group_id_attr,
10561 sizeof(group_id_attr))) {
10562 sigma_dut_print(dut, DUT_MSG_ERROR,
10563 "fail to replace group id attribute");
10564 return -1;
10565 }
10566 }
10567
10568 for (i = 0; i < count; i++) {
10569 if (wil6210_transmit_frame(dut, freq,
10570 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10571 frame, framelen)) {
10572 sigma_dut_print(dut, DUT_MSG_ERROR,
10573 "fail to transmit probe request frame");
10574 return -1;
10575 }
10576 }
10577
10578 return 0;
10579}
10580
10581
Lior David0fe101e2017-03-09 16:09:50 +020010582int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10583 struct sigma_cmd *cmd)
10584{
10585 const char *frame_name = get_param(cmd, "framename");
10586 const char *mac = get_param(cmd, "dest_mac");
10587
10588 if (!frame_name || !mac) {
10589 sigma_dut_print(dut, DUT_MSG_ERROR,
10590 "framename and dest_mac must be provided");
10591 return -1;
10592 }
10593
10594 if (strcasecmp(frame_name, "brp") == 0) {
10595 const char *l_rx = get_param(cmd, "L-RX");
10596 int l_rx_i;
10597
10598 if (!l_rx) {
10599 sigma_dut_print(dut, DUT_MSG_ERROR,
10600 "L-RX must be provided");
10601 return -1;
10602 }
10603 l_rx_i = atoi(l_rx);
10604
10605 sigma_dut_print(dut, DUT_MSG_INFO,
10606 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10607 mac, l_rx);
10608 if (l_rx_i != 16) {
10609 sigma_dut_print(dut, DUT_MSG_ERROR,
10610 "unsupported L-RX: %s", l_rx);
10611 return -1;
10612 }
10613
10614 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10615 return -1;
10616 } else if (strcasecmp(frame_name, "ssw") == 0) {
10617 sigma_dut_print(dut, DUT_MSG_INFO,
10618 "dev_send_frame: SLS, dest_mac %s", mac);
10619 if (wil6210_send_sls(dut, mac))
10620 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010621 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10622 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10623 sigma_dut_print(dut, DUT_MSG_INFO,
10624 "dev_send_frame: %s, dest_mac %s", frame_name,
10625 mac);
10626 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10627 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010628 } else {
10629 sigma_dut_print(dut, DUT_MSG_ERROR,
10630 "unsupported frame type: %s", frame_name);
10631 return -1;
10632 }
10633
10634 return 1;
10635}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010636
Lior David0fe101e2017-03-09 16:09:50 +020010637#endif /* __linux__ */
10638
10639
10640static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10641 struct sigma_conn *conn,
10642 struct sigma_cmd *cmd)
10643{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010644 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010645#ifdef __linux__
10646 case DRIVER_WIL6210:
10647 return wil6210_send_frame_60g(dut, conn, cmd);
10648#endif /* __linux__ */
10649 default:
10650 send_resp(dut, conn, SIGMA_ERROR,
10651 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10652 return 0;
10653 }
10654}
10655
10656
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010657static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10658 const char *intf, struct sigma_cmd *cmd)
10659{
10660 const char *val, *addr;
10661 char buf[100];
10662
10663 addr = get_param(cmd, "DestMac");
10664 if (!addr) {
10665 send_resp(dut, conn, SIGMA_INVALID,
10666 "ErrorCode,AP MAC address is missing");
10667 return 0;
10668 }
10669
10670 val = get_param(cmd, "ANQPQuery_ID");
10671 if (!val) {
10672 send_resp(dut, conn, SIGMA_INVALID,
10673 "ErrorCode,Missing ANQPQuery_ID");
10674 return 0;
10675 }
10676
10677 if (strcasecmp(val, "NeighborReportReq") == 0) {
10678 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10679 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10680 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10681 } else {
10682 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10683 val);
10684 send_resp(dut, conn, SIGMA_INVALID,
10685 "ErrorCode,Invalid ANQPQuery_ID");
10686 return 0;
10687 }
10688
Ashwini Patild174f2c2017-04-13 16:49:46 +053010689 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10690 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10691 * if associated, AP BSSID).
10692 */
10693 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10694 send_resp(dut, conn, SIGMA_ERROR,
10695 "ErrorCode,Failed to set gas_address3");
10696 return 0;
10697 }
10698
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010699 if (wpa_command(intf, buf) < 0) {
10700 send_resp(dut, conn, SIGMA_ERROR,
10701 "ErrorCode,Failed to send ANQP query");
10702 return 0;
10703 }
10704
10705 return 1;
10706}
10707
10708
10709static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10710 struct sigma_conn *conn,
10711 const char *intf,
10712 struct sigma_cmd *cmd)
10713{
10714 const char *val = get_param(cmd, "FrameName");
10715
10716 if (val && strcasecmp(val, "ANQPQuery") == 0)
10717 return mbo_send_anqp_query(dut, conn, intf, cmd);
10718
10719 return 2;
10720}
10721
10722
Jouni Malinenf7222712019-06-13 01:50:21 +030010723enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10724 struct sigma_conn *conn,
10725 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010726{
10727 const char *intf = get_param(cmd, "Interface");
10728 const char *val;
10729 enum send_frame_type frame;
10730 enum send_frame_protection protected;
10731 char buf[100];
10732 unsigned char addr[ETH_ALEN];
10733 int res;
10734
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010735 if (!intf)
10736 return -1;
10737
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010738 val = get_param(cmd, "program");
10739 if (val == NULL)
10740 val = get_param(cmd, "frame");
10741 if (val && strcasecmp(val, "TDLS") == 0)
10742 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10743 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010744 strcasecmp(val, "HS2-R2") == 0 ||
10745 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010746 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10747 if (val && strcasecmp(val, "VHT") == 0)
10748 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010749 if (val && strcasecmp(val, "HE") == 0)
10750 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010751 if (val && strcasecmp(val, "LOC") == 0)
10752 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010753 if (val && strcasecmp(val, "60GHz") == 0)
10754 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010755 if (val && strcasecmp(val, "MBO") == 0) {
10756 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10757 if (res != 2)
10758 return res;
10759 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010760
10761 val = get_param(cmd, "TD_DISC");
10762 if (val) {
10763 if (hwaddr_aton(val, addr) < 0)
10764 return -1;
10765 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10766 if (wpa_command(intf, buf) < 0) {
10767 send_resp(dut, conn, SIGMA_ERROR,
10768 "ErrorCode,Failed to send TDLS discovery");
10769 return 0;
10770 }
10771 return 1;
10772 }
10773
10774 val = get_param(cmd, "TD_Setup");
10775 if (val) {
10776 if (hwaddr_aton(val, addr) < 0)
10777 return -1;
10778 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10779 if (wpa_command(intf, buf) < 0) {
10780 send_resp(dut, conn, SIGMA_ERROR,
10781 "ErrorCode,Failed to start TDLS setup");
10782 return 0;
10783 }
10784 return 1;
10785 }
10786
10787 val = get_param(cmd, "TD_TearDown");
10788 if (val) {
10789 if (hwaddr_aton(val, addr) < 0)
10790 return -1;
10791 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10792 if (wpa_command(intf, buf) < 0) {
10793 send_resp(dut, conn, SIGMA_ERROR,
10794 "ErrorCode,Failed to tear down TDLS link");
10795 return 0;
10796 }
10797 return 1;
10798 }
10799
10800 val = get_param(cmd, "TD_ChannelSwitch");
10801 if (val) {
10802 /* TODO */
10803 send_resp(dut, conn, SIGMA_ERROR,
10804 "ErrorCode,TD_ChannelSwitch not yet supported");
10805 return 0;
10806 }
10807
10808 val = get_param(cmd, "TD_NF");
10809 if (val) {
10810 /* TODO */
10811 send_resp(dut, conn, SIGMA_ERROR,
10812 "ErrorCode,TD_NF not yet supported");
10813 return 0;
10814 }
10815
10816 val = get_param(cmd, "PMFFrameType");
10817 if (val == NULL)
10818 val = get_param(cmd, "FrameName");
10819 if (val == NULL)
10820 val = get_param(cmd, "Type");
10821 if (val == NULL)
10822 return -1;
10823 if (strcasecmp(val, "disassoc") == 0)
10824 frame = DISASSOC;
10825 else if (strcasecmp(val, "deauth") == 0)
10826 frame = DEAUTH;
10827 else if (strcasecmp(val, "saquery") == 0)
10828 frame = SAQUERY;
10829 else if (strcasecmp(val, "auth") == 0)
10830 frame = AUTH;
10831 else if (strcasecmp(val, "assocreq") == 0)
10832 frame = ASSOCREQ;
10833 else if (strcasecmp(val, "reassocreq") == 0)
10834 frame = REASSOCREQ;
10835 else if (strcasecmp(val, "neigreq") == 0) {
10836 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10837
10838 val = get_param(cmd, "ssid");
10839 if (val == NULL)
10840 return -1;
10841
10842 res = send_neighbor_request(dut, intf, val);
10843 if (res) {
10844 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10845 "Failed to send neighbor report request");
10846 return 0;
10847 }
10848
10849 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010850 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10851 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010852 sigma_dut_print(dut, DUT_MSG_DEBUG,
10853 "Got Transition Management Query");
10854
Ashwini Patil5acd7382017-04-13 15:55:04 +053010855 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010856 if (res) {
10857 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10858 "Failed to send Transition Management Query");
10859 return 0;
10860 }
10861
10862 return 1;
10863 } else {
10864 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10865 "PMFFrameType");
10866 return 0;
10867 }
10868
10869 val = get_param(cmd, "PMFProtected");
10870 if (val == NULL)
10871 val = get_param(cmd, "Protected");
10872 if (val == NULL)
10873 return -1;
10874 if (strcasecmp(val, "Correct-key") == 0 ||
10875 strcasecmp(val, "CorrectKey") == 0)
10876 protected = CORRECT_KEY;
10877 else if (strcasecmp(val, "IncorrectKey") == 0)
10878 protected = INCORRECT_KEY;
10879 else if (strcasecmp(val, "Unprotected") == 0)
10880 protected = UNPROTECTED;
10881 else {
10882 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10883 "PMFProtected");
10884 return 0;
10885 }
10886
10887 if (protected != UNPROTECTED &&
10888 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10889 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10890 "PMFProtected for auth/assocreq/reassocreq");
10891 return 0;
10892 }
10893
10894 if (if_nametoindex("sigmadut") == 0) {
10895 snprintf(buf, sizeof(buf),
10896 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010897 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010898 if (system(buf) != 0 ||
10899 if_nametoindex("sigmadut") == 0) {
10900 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10901 "monitor interface with '%s'", buf);
10902 return -2;
10903 }
10904 }
10905
10906 if (system("ifconfig sigmadut up") != 0) {
10907 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10908 "monitor interface up");
10909 return -2;
10910 }
10911
10912 return sta_inject_frame(dut, conn, frame, protected, NULL);
10913}
10914
10915
10916static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10917 struct sigma_conn *conn,
10918 struct sigma_cmd *cmd,
10919 const char *ifname)
10920{
10921 char buf[200];
10922 const char *val;
10923
10924 val = get_param(cmd, "ClearARP");
10925 if (val && atoi(val) == 1) {
10926 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10927 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10928 if (system(buf) != 0) {
10929 send_resp(dut, conn, SIGMA_ERROR,
10930 "errorCode,Failed to clear ARP cache");
10931 return 0;
10932 }
10933 }
10934
10935 return 1;
10936}
10937
10938
10939int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10940 struct sigma_cmd *cmd)
10941{
10942 const char *intf = get_param(cmd, "Interface");
10943 const char *val;
10944
10945 if (intf == NULL)
10946 return -1;
10947
10948 val = get_param(cmd, "program");
10949 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010950 strcasecmp(val, "HS2-R2") == 0 ||
10951 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010952 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10953
10954 return -1;
10955}
10956
10957
Jouni Malinenf7222712019-06-13 01:50:21 +030010958static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
10959 struct sigma_conn *conn,
10960 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010961{
10962 const char *intf = get_param(cmd, "Interface");
10963 const char *mac = get_param(cmd, "MAC");
10964
10965 if (intf == NULL || mac == NULL)
10966 return -1;
10967
10968 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10969 "interface %s to %s", intf, mac);
10970
10971 if (dut->set_macaddr) {
10972 char buf[128];
10973 int res;
10974 if (strcasecmp(mac, "default") == 0) {
10975 res = snprintf(buf, sizeof(buf), "%s",
10976 dut->set_macaddr);
10977 dut->tmp_mac_addr = 0;
10978 } else {
10979 res = snprintf(buf, sizeof(buf), "%s %s",
10980 dut->set_macaddr, mac);
10981 dut->tmp_mac_addr = 1;
10982 }
10983 if (res < 0 || res >= (int) sizeof(buf))
10984 return -1;
10985 if (system(buf) != 0) {
10986 send_resp(dut, conn, SIGMA_ERROR,
10987 "errorCode,Failed to set MAC "
10988 "address");
10989 return 0;
10990 }
10991 return 1;
10992 }
10993
10994 if (strcasecmp(mac, "default") == 0)
10995 return 1;
10996
10997 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10998 "command");
10999 return 0;
11000}
11001
11002
11003static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11004 struct sigma_conn *conn, const char *intf,
11005 int val)
11006{
11007 char buf[200];
11008 int res;
11009
11010 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11011 intf, val);
11012 if (res < 0 || res >= (int) sizeof(buf))
11013 return -1;
11014 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11015 if (system(buf) != 0) {
11016 send_resp(dut, conn, SIGMA_ERROR,
11017 "errorCode,Failed to configure offchannel mode");
11018 return 0;
11019 }
11020
11021 return 1;
11022}
11023
11024
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011025static int off_chan_val(enum sec_ch_offset off)
11026{
11027 switch (off) {
11028 case SEC_CH_NO:
11029 return 0;
11030 case SEC_CH_40ABOVE:
11031 return 40;
11032 case SEC_CH_40BELOW:
11033 return -40;
11034 }
11035
11036 return 0;
11037}
11038
11039
11040static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11041 const char *intf, int off_ch_num,
11042 enum sec_ch_offset sec)
11043{
11044 char buf[200];
11045 int res;
11046
11047 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11048 intf, off_ch_num);
11049 if (res < 0 || res >= (int) sizeof(buf))
11050 return -1;
11051 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11052 if (system(buf) != 0) {
11053 send_resp(dut, conn, SIGMA_ERROR,
11054 "errorCode,Failed to set offchan");
11055 return 0;
11056 }
11057
11058 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11059 intf, off_chan_val(sec));
11060 if (res < 0 || res >= (int) sizeof(buf))
11061 return -1;
11062 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11063 if (system(buf) != 0) {
11064 send_resp(dut, conn, SIGMA_ERROR,
11065 "errorCode,Failed to set sec chan offset");
11066 return 0;
11067 }
11068
11069 return 1;
11070}
11071
11072
11073static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11074 struct sigma_conn *conn,
11075 const char *intf, int off_ch_num,
11076 enum sec_ch_offset sec)
11077{
11078 char buf[200];
11079 int res;
11080
11081 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11082 off_ch_num);
11083 if (res < 0 || res >= (int) sizeof(buf))
11084 return -1;
11085 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11086
11087 if (wpa_command(intf, buf) < 0) {
11088 send_resp(dut, conn, SIGMA_ERROR,
11089 "ErrorCode,Failed to set offchan");
11090 return 0;
11091 }
11092 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11093 off_chan_val(sec));
11094 if (res < 0 || res >= (int) sizeof(buf))
11095 return -1;
11096
11097 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11098
11099 if (wpa_command(intf, buf) < 0) {
11100 send_resp(dut, conn, SIGMA_ERROR,
11101 "ErrorCode,Failed to set sec chan offset");
11102 return 0;
11103 }
11104
11105 return 1;
11106}
11107
11108
11109static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11110 struct sigma_conn *conn,
11111 const char *intf, int val)
11112{
11113 char buf[200];
11114 int res;
11115
11116 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11117 val);
11118 if (res < 0 || res >= (int) sizeof(buf))
11119 return -1;
11120 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11121
11122 if (wpa_command(intf, buf) < 0) {
11123 send_resp(dut, conn, SIGMA_ERROR,
11124 "ErrorCode,Failed to configure offchannel mode");
11125 return 0;
11126 }
11127
11128 return 1;
11129}
11130
11131
11132static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11133 struct sigma_conn *conn,
11134 struct sigma_cmd *cmd)
11135{
11136 const char *val;
11137 enum {
11138 CHSM_NOT_SET,
11139 CHSM_ENABLE,
11140 CHSM_DISABLE,
11141 CHSM_REJREQ,
11142 CHSM_UNSOLRESP
11143 } chsm = CHSM_NOT_SET;
11144 int off_ch_num = -1;
11145 enum sec_ch_offset sec_ch = SEC_CH_NO;
11146 int res;
11147
11148 val = get_param(cmd, "Uapsd");
11149 if (val) {
11150 char buf[100];
11151 if (strcasecmp(val, "Enable") == 0)
11152 snprintf(buf, sizeof(buf), "SET ps 99");
11153 else if (strcasecmp(val, "Disable") == 0)
11154 snprintf(buf, sizeof(buf), "SET ps 98");
11155 else {
11156 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11157 "Unsupported uapsd parameter value");
11158 return 0;
11159 }
11160 if (wpa_command(intf, buf)) {
11161 send_resp(dut, conn, SIGMA_ERROR,
11162 "ErrorCode,Failed to change U-APSD "
11163 "powersave mode");
11164 return 0;
11165 }
11166 }
11167
11168 val = get_param(cmd, "TPKTIMER");
11169 if (val && strcasecmp(val, "DISABLE") == 0) {
11170 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11171 send_resp(dut, conn, SIGMA_ERROR,
11172 "ErrorCode,Failed to enable no TPK "
11173 "expiration test mode");
11174 return 0;
11175 }
11176 dut->no_tpk_expiration = 1;
11177 }
11178
11179 val = get_param(cmd, "ChSwitchMode");
11180 if (val) {
11181 if (strcasecmp(val, "Enable") == 0 ||
11182 strcasecmp(val, "Initiate") == 0)
11183 chsm = CHSM_ENABLE;
11184 else if (strcasecmp(val, "Disable") == 0 ||
11185 strcasecmp(val, "passive") == 0)
11186 chsm = CHSM_DISABLE;
11187 else if (strcasecmp(val, "RejReq") == 0)
11188 chsm = CHSM_REJREQ;
11189 else if (strcasecmp(val, "UnSolResp") == 0)
11190 chsm = CHSM_UNSOLRESP;
11191 else {
11192 send_resp(dut, conn, SIGMA_ERROR,
11193 "ErrorCode,Unknown ChSwitchMode value");
11194 return 0;
11195 }
11196 }
11197
11198 val = get_param(cmd, "OffChNum");
11199 if (val) {
11200 off_ch_num = atoi(val);
11201 if (off_ch_num == 0) {
11202 send_resp(dut, conn, SIGMA_ERROR,
11203 "ErrorCode,Invalid OffChNum");
11204 return 0;
11205 }
11206 }
11207
11208 val = get_param(cmd, "SecChOffset");
11209 if (val) {
11210 if (strcmp(val, "20") == 0)
11211 sec_ch = SEC_CH_NO;
11212 else if (strcasecmp(val, "40above") == 0)
11213 sec_ch = SEC_CH_40ABOVE;
11214 else if (strcasecmp(val, "40below") == 0)
11215 sec_ch = SEC_CH_40BELOW;
11216 else {
11217 send_resp(dut, conn, SIGMA_ERROR,
11218 "ErrorCode,Unknown SecChOffset value");
11219 return 0;
11220 }
11221 }
11222
11223 if (chsm == CHSM_NOT_SET) {
11224 /* no offchannel changes requested */
11225 return 1;
11226 }
11227
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011228 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11229 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011230 send_resp(dut, conn, SIGMA_ERROR,
11231 "ErrorCode,Unknown interface");
11232 return 0;
11233 }
11234
11235 switch (chsm) {
11236 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011237 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011238 break;
11239 case CHSM_ENABLE:
11240 if (off_ch_num < 0) {
11241 send_resp(dut, conn, SIGMA_ERROR,
11242 "ErrorCode,Missing OffChNum argument");
11243 return 0;
11244 }
11245 if (wifi_chip_type == DRIVER_WCN) {
11246 res = tdls_set_offchannel_offset(dut, conn, intf,
11247 off_ch_num, sec_ch);
11248 } else {
11249 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11250 sec_ch);
11251 }
11252 if (res != 1)
11253 return res;
11254 if (wifi_chip_type == DRIVER_WCN)
11255 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11256 else
11257 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11258 break;
11259 case CHSM_DISABLE:
11260 if (wifi_chip_type == DRIVER_WCN)
11261 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11262 else
11263 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11264 break;
11265 case CHSM_REJREQ:
11266 if (wifi_chip_type == DRIVER_WCN)
11267 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11268 else
11269 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11270 break;
11271 case CHSM_UNSOLRESP:
11272 if (off_ch_num < 0) {
11273 send_resp(dut, conn, SIGMA_ERROR,
11274 "ErrorCode,Missing OffChNum argument");
11275 return 0;
11276 }
11277 if (wifi_chip_type == DRIVER_WCN) {
11278 res = tdls_set_offchannel_offset(dut, conn, intf,
11279 off_ch_num, sec_ch);
11280 } else {
11281 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11282 sec_ch);
11283 }
11284 if (res != 1)
11285 return res;
11286 if (wifi_chip_type == DRIVER_WCN)
11287 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11288 else
11289 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11290 break;
11291 }
11292
11293 return res;
11294}
11295
11296
11297static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11298 struct sigma_conn *conn,
11299 struct sigma_cmd *cmd)
11300{
11301 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011302 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011303
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011304 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011305
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011306 val = get_param(cmd, "nss_mcs_opt");
11307 if (val) {
11308 /* String (nss_operating_mode; mcs_operating_mode) */
11309 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011310 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011311
11312 token = strdup(val);
11313 if (!token)
11314 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011315 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011316 if (!result) {
11317 sigma_dut_print(dut, DUT_MSG_ERROR,
11318 "VHT NSS not specified");
11319 goto failed;
11320 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011321 if (strcasecmp(result, "def") != 0) {
11322 nss = atoi(result);
11323 if (nss == 4)
11324 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011325 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011326 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011327
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011328 }
11329
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011330 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011331 if (!result) {
11332 sigma_dut_print(dut, DUT_MSG_ERROR,
11333 "VHT MCS not specified");
11334 goto failed;
11335 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011336 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011337 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011338 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011339 } else {
11340 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011341 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011342 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011343 }
11344 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011345 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011346 }
11347
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011348 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011349 return 1;
11350failed:
11351 free(token);
11352 return 0;
11353}
11354
11355
11356static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11357 struct sigma_conn *conn,
11358 struct sigma_cmd *cmd)
11359{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011360 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011361 case DRIVER_ATHEROS:
11362 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11363 default:
11364 send_resp(dut, conn, SIGMA_ERROR,
11365 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11366 return 0;
11367 }
11368}
11369
11370
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011371static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11372 struct sigma_conn *conn,
11373 struct sigma_cmd *cmd)
11374{
11375 const char *val;
11376 char *token = NULL, *result;
11377 char buf[60];
11378
11379 val = get_param(cmd, "nss_mcs_opt");
11380 if (val) {
11381 /* String (nss_operating_mode; mcs_operating_mode) */
11382 int nss, mcs, ratecode;
11383 char *saveptr;
11384
11385 token = strdup(val);
11386 if (!token)
11387 return -2;
11388
11389 result = strtok_r(token, ";", &saveptr);
11390 if (!result) {
11391 sigma_dut_print(dut, DUT_MSG_ERROR,
11392 "HE NSS not specified");
11393 goto failed;
11394 }
11395 nss = 1;
11396 if (strcasecmp(result, "def") != 0)
11397 nss = atoi(result);
11398
11399 result = strtok_r(NULL, ";", &saveptr);
11400 if (!result) {
11401 sigma_dut_print(dut, DUT_MSG_ERROR,
11402 "HE MCS not specified");
11403 goto failed;
11404 }
11405 mcs = 7;
11406 if (strcasecmp(result, "def") != 0)
11407 mcs = atoi(result);
11408
Arif Hussain557bf412018-05-25 17:29:36 -070011409 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011410 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011411 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011412 } else if (nss > 2) {
11413 sigma_dut_print(dut, DUT_MSG_ERROR,
11414 "HE NSS %d not supported", nss);
11415 goto failed;
11416 }
11417
Arif Hussain557bf412018-05-25 17:29:36 -070011418 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11419 if (system(buf) != 0) {
11420 sigma_dut_print(dut, DUT_MSG_ERROR,
11421 "nss_mcs_opt: iwpriv %s nss %d failed",
11422 intf, nss);
11423 goto failed;
11424 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011425 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011426
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011427 /* Add the MCS to the ratecode */
11428 if (mcs >= 0 && mcs <= 11) {
11429 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011430#ifdef NL80211_SUPPORT
11431 if (dut->device_type == STA_testbed) {
11432 enum he_mcs_config mcs_config;
11433 int ret;
11434
11435 if (mcs <= 7)
11436 mcs_config = HE_80_MCS0_7;
11437 else if (mcs <= 9)
11438 mcs_config = HE_80_MCS0_9;
11439 else
11440 mcs_config = HE_80_MCS0_11;
11441 ret = sta_set_he_mcs(dut, intf, mcs_config);
11442 if (ret) {
11443 sigma_dut_print(dut, DUT_MSG_ERROR,
11444 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11445 mcs, mcs_config, ret);
11446 goto failed;
11447 }
11448 }
11449#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011450 } else {
11451 sigma_dut_print(dut, DUT_MSG_ERROR,
11452 "HE MCS %d not supported", mcs);
11453 goto failed;
11454 }
11455 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11456 intf, ratecode);
11457 if (system(buf) != 0) {
11458 sigma_dut_print(dut, DUT_MSG_ERROR,
11459 "iwpriv setting of 11ax rates failed");
11460 goto failed;
11461 }
11462 free(token);
11463 }
11464
11465 val = get_param(cmd, "GI");
11466 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011467 int fix_rate_sgi;
11468
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011469 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011470 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011471 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011472 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011473 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11474 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011475 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011476 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011477 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11478 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011479 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011480 } else {
11481 send_resp(dut, conn, SIGMA_ERROR,
11482 "errorCode,GI value not supported");
11483 return 0;
11484 }
11485 if (system(buf) != 0) {
11486 send_resp(dut, conn, SIGMA_ERROR,
11487 "errorCode,Failed to set shortgi");
11488 return 0;
11489 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011490 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11491 intf, fix_rate_sgi);
11492 if (system(buf) != 0) {
11493 send_resp(dut, conn, SIGMA_ERROR,
11494 "errorCode,Failed to set fix rate shortgi");
11495 return STATUS_SENT;
11496 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011497 }
11498
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011499 val = get_param(cmd, "LTF");
11500 if (val) {
11501#ifdef NL80211_SUPPORT
11502 if (strcmp(val, "3.2") == 0) {
11503 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11504 } if (strcmp(val, "6.4") == 0) {
11505 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11506 } else if (strcmp(val, "12.8") == 0) {
11507 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11508 } else {
11509 send_resp(dut, conn, SIGMA_ERROR,
11510 "errorCode, LTF value not supported");
11511 return 0;
11512 }
11513#else /* NL80211_SUPPORT */
11514 sigma_dut_print(dut, DUT_MSG_ERROR,
11515 "LTF cannot be set without NL80211_SUPPORT defined");
11516 return -2;
11517#endif /* NL80211_SUPPORT */
11518 }
11519
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011520 val = get_param(cmd, "TxSUPPDU");
11521 if (val) {
11522 int set_val = 1;
11523
11524 if (strcasecmp(val, "Enable") == 0)
11525 set_val = 1;
11526 else if (strcasecmp(val, "Disable") == 0)
11527 set_val = 0;
11528
11529 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11530 send_resp(dut, conn, SIGMA_ERROR,
11531 "ErrorCode,Failed to set Tx SU PPDU config");
11532 return 0;
11533 }
11534 }
11535
Arif Hussain480d5f42019-03-12 14:40:42 -070011536 val = get_param(cmd, "TWT_Setup");
11537 if (val) {
11538 if (strcasecmp(val, "Request") == 0) {
11539 if (sta_twt_request(dut, conn, cmd)) {
11540 send_resp(dut, conn, SIGMA_ERROR,
11541 "ErrorCode,sta_twt_request failed");
11542 return STATUS_SENT;
11543 }
11544 } else if (strcasecmp(val, "Teardown") == 0) {
11545 if (sta_twt_teardown(dut, conn, cmd)) {
11546 send_resp(dut, conn, SIGMA_ERROR,
11547 "ErrorCode,sta_twt_teardown failed");
11548 return STATUS_SENT;
11549 }
11550 }
11551 }
11552
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011553 val = get_param(cmd, "transmitOMI");
11554 if (val && sta_transmit_omi(dut, conn, cmd)) {
11555 send_resp(dut, conn, SIGMA_ERROR,
11556 "ErrorCode,sta_transmit_omi failed");
11557 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011558 }
11559
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011560 val = get_param(cmd, "Powersave");
11561 if (val) {
11562 char buf[60];
11563
11564 if (strcasecmp(val, "off") == 0) {
11565 snprintf(buf, sizeof(buf),
11566 "iwpriv %s setPower 2", intf);
11567 if (system(buf) != 0) {
11568 sigma_dut_print(dut, DUT_MSG_ERROR,
11569 "iwpriv setPower 2 failed");
11570 return 0;
11571 }
11572 } else if (strcasecmp(val, "on") == 0) {
11573 snprintf(buf, sizeof(buf),
11574 "iwpriv %s setPower 1", intf);
11575 if (system(buf) != 0) {
11576 sigma_dut_print(dut, DUT_MSG_ERROR,
11577 "iwpriv setPower 1 failed");
11578 return 0;
11579 }
11580 } else {
11581 sigma_dut_print(dut, DUT_MSG_ERROR,
11582 "Unsupported Powersave value '%s'",
11583 val);
11584 return -1;
11585 }
11586 }
11587
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011588 val = get_param(cmd, "MU_EDCA");
11589 if (val) {
11590 if (strcasecmp(val, "Override") == 0) {
11591 if (sta_set_mu_edca_override(dut, intf, 1)) {
11592 send_resp(dut, conn, SIGMA_ERROR,
11593 "errorCode,MU EDCA override set failed");
11594 return STATUS_SENT;
11595 }
11596 } else if (strcasecmp(val, "Disable") == 0) {
11597 if (sta_set_mu_edca_override(dut, intf, 0)) {
11598 send_resp(dut, conn, SIGMA_ERROR,
11599 "errorCode,MU EDCA override disable failed");
11600 return STATUS_SENT;
11601 }
11602 }
11603 }
11604
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011605 return 1;
11606
11607failed:
11608 free(token);
11609 return -2;
11610}
11611
11612
11613static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11614 struct sigma_conn *conn,
11615 struct sigma_cmd *cmd)
11616{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011617 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011618 case DRIVER_WCN:
11619 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11620 default:
11621 send_resp(dut, conn, SIGMA_ERROR,
11622 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11623 return 0;
11624 }
11625}
11626
11627
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011628static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11629 struct sigma_conn *conn,
11630 struct sigma_cmd *cmd)
11631{
11632 const char *val;
11633
11634 val = get_param(cmd, "powersave");
11635 if (val) {
11636 char buf[60];
11637
11638 if (strcasecmp(val, "off") == 0) {
11639 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11640 intf);
11641 if (system(buf) != 0) {
11642 sigma_dut_print(dut, DUT_MSG_ERROR,
11643 "iwpriv setPower 2 failed");
11644 return 0;
11645 }
11646 } else if (strcasecmp(val, "on") == 0) {
11647 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11648 intf);
11649 if (system(buf) != 0) {
11650 sigma_dut_print(dut, DUT_MSG_ERROR,
11651 "iwpriv setPower 1 failed");
11652 return 0;
11653 }
11654 } else {
11655 sigma_dut_print(dut, DUT_MSG_ERROR,
11656 "Unsupported power save config");
11657 return -1;
11658 }
11659 return 1;
11660 }
11661
11662 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11663
11664 return 0;
11665}
11666
11667
Ashwini Patil5acd7382017-04-13 15:55:04 +053011668static int btm_query_candidate_list(struct sigma_dut *dut,
11669 struct sigma_conn *conn,
11670 struct sigma_cmd *cmd)
11671{
11672 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11673 int len, ret;
11674 char buf[10];
11675
11676 /*
11677 * Neighbor Report elements format:
11678 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11679 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11680 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11681 */
11682
11683 bssid = get_param(cmd, "Nebor_BSSID");
11684 if (!bssid) {
11685 send_resp(dut, conn, SIGMA_INVALID,
11686 "errorCode,Nebor_BSSID is missing");
11687 return 0;
11688 }
11689
11690 info = get_param(cmd, "Nebor_Bssid_Info");
11691 if (!info) {
11692 sigma_dut_print(dut, DUT_MSG_INFO,
11693 "Using default value for Nebor_Bssid_Info: %s",
11694 DEFAULT_NEIGHBOR_BSSID_INFO);
11695 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11696 }
11697
11698 op_class = get_param(cmd, "Nebor_Op_Class");
11699 if (!op_class) {
11700 send_resp(dut, conn, SIGMA_INVALID,
11701 "errorCode,Nebor_Op_Class is missing");
11702 return 0;
11703 }
11704
11705 ch = get_param(cmd, "Nebor_Op_Ch");
11706 if (!ch) {
11707 send_resp(dut, conn, SIGMA_INVALID,
11708 "errorCode,Nebor_Op_Ch is missing");
11709 return 0;
11710 }
11711
11712 phy_type = get_param(cmd, "Nebor_Phy_Type");
11713 if (!phy_type) {
11714 sigma_dut_print(dut, DUT_MSG_INFO,
11715 "Using default value for Nebor_Phy_Type: %s",
11716 DEFAULT_NEIGHBOR_PHY_TYPE);
11717 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11718 }
11719
11720 /* Parse optional subelements */
11721 buf[0] = '\0';
11722 pref = get_param(cmd, "Nebor_Pref");
11723 if (pref) {
11724 /* hexdump for preferrence subelement */
11725 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11726 if (ret < 0 || ret >= (int) sizeof(buf)) {
11727 sigma_dut_print(dut, DUT_MSG_ERROR,
11728 "snprintf failed for optional subelement ret: %d",
11729 ret);
11730 send_resp(dut, conn, SIGMA_ERROR,
11731 "errorCode,snprintf failed for subelement");
11732 return 0;
11733 }
11734 }
11735
11736 if (!dut->btm_query_cand_list) {
11737 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11738 if (!dut->btm_query_cand_list) {
11739 send_resp(dut, conn, SIGMA_ERROR,
11740 "errorCode,Failed to allocate memory for btm_query_cand_list");
11741 return 0;
11742 }
11743 }
11744
11745 len = strlen(dut->btm_query_cand_list);
11746 ret = snprintf(dut->btm_query_cand_list + len,
11747 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11748 bssid, info, op_class, ch, phy_type, buf);
11749 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11750 sigma_dut_print(dut, DUT_MSG_ERROR,
11751 "snprintf failed for neighbor report list ret: %d",
11752 ret);
11753 send_resp(dut, conn, SIGMA_ERROR,
11754 "errorCode,snprintf failed for neighbor report");
11755 free(dut->btm_query_cand_list);
11756 dut->btm_query_cand_list = NULL;
11757 return 0;
11758 }
11759
11760 return 1;
11761}
11762
11763
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011764int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11765 struct sigma_ese_alloc *allocs, int *allocs_size)
11766{
11767 int max_count = *allocs_size;
11768 int count = 0, i;
11769 const char *val;
11770
11771 do {
11772 val = get_param_indexed(cmd, "AllocID", count);
11773 if (val)
11774 count++;
11775 } while (val);
11776
11777 if (count == 0 || count > max_count) {
11778 sigma_dut_print(dut, DUT_MSG_ERROR,
11779 "Invalid number of allocations(%d)", count);
11780 return -1;
11781 }
11782
11783 for (i = 0; i < count; i++) {
11784 val = get_param_indexed(cmd, "PercentBI", i);
11785 if (!val) {
11786 sigma_dut_print(dut, DUT_MSG_ERROR,
11787 "Missing PercentBI parameter at index %d",
11788 i);
11789 return -1;
11790 }
11791 allocs[i].percent_bi = atoi(val);
11792
11793 val = get_param_indexed(cmd, "SrcAID", i);
11794 if (val)
11795 allocs[i].src_aid = strtol(val, NULL, 0);
11796 else
11797 allocs[i].src_aid = ESE_BCAST_AID;
11798
11799 val = get_param_indexed(cmd, "DestAID", i);
11800 if (val)
11801 allocs[i].dst_aid = strtol(val, NULL, 0);
11802 else
11803 allocs[i].dst_aid = ESE_BCAST_AID;
11804
11805 allocs[i].type = ESE_CBAP;
11806 sigma_dut_print(dut, DUT_MSG_INFO,
11807 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11808 i, allocs[i].percent_bi, allocs[i].src_aid,
11809 allocs[i].dst_aid);
11810 }
11811
11812 *allocs_size = count;
11813 return 0;
11814}
11815
11816
11817static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11818 struct sigma_ese_alloc *allocs)
11819{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011820 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011821#ifdef __linux__
11822 case DRIVER_WIL6210:
11823 if (wil6210_set_ese(dut, count, allocs))
11824 return -1;
11825 return 1;
11826#endif /* __linux__ */
11827 default:
11828 sigma_dut_print(dut, DUT_MSG_ERROR,
11829 "Unsupported sta_set_60g_ese with the current driver");
11830 return -1;
11831 }
11832}
11833
11834
11835static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11836 struct sigma_conn *conn,
11837 struct sigma_cmd *cmd)
11838{
11839 const char *val;
11840
11841 val = get_param(cmd, "ExtSchIE");
11842 if (val && !strcasecmp(val, "Enable")) {
11843 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11844 int count = MAX_ESE_ALLOCS;
11845
11846 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11847 return -1;
11848 return sta_set_60g_ese(dut, count, allocs);
11849 }
11850
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011851 val = get_param(cmd, "MCS_FixedRate");
11852 if (val) {
11853 int sta_mcs = atoi(val);
11854
11855 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11856 sta_mcs);
11857 wil6210_set_force_mcs(dut, 1, sta_mcs);
11858
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011859 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011860 }
11861
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011862 send_resp(dut, conn, SIGMA_ERROR,
11863 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011864 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011865}
11866
11867
Jouni Malinenf7222712019-06-13 01:50:21 +030011868static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
11869 struct sigma_conn *conn,
11870 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011871{
11872 const char *intf = get_param(cmd, "Interface");
11873 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011874 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011875
11876 if (intf == NULL || prog == NULL)
11877 return -1;
11878
Ashwini Patil5acd7382017-04-13 15:55:04 +053011879 /* BSS Transition candidate list for BTM query */
11880 val = get_param(cmd, "Nebor_BSSID");
11881 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11882 return 0;
11883
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011884 if (strcasecmp(prog, "TDLS") == 0)
11885 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11886
11887 if (strcasecmp(prog, "VHT") == 0)
11888 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11889
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011890 if (strcasecmp(prog, "HE") == 0)
11891 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11892
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011893 if (strcasecmp(prog, "MBO") == 0) {
11894 val = get_param(cmd, "Cellular_Data_Cap");
11895 if (val &&
11896 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11897 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011898
11899 val = get_param(cmd, "Ch_Pref");
11900 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11901 return 0;
11902
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011903 return 1;
11904 }
11905
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011906 if (strcasecmp(prog, "60GHz") == 0)
11907 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11908
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011909 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11910 return 0;
11911}
11912
11913
Jouni Malinenf7222712019-06-13 01:50:21 +030011914static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
11915 struct sigma_conn *conn,
11916 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011917{
11918 const char *intf = get_param(cmd, "Interface");
11919 const char *mode = get_param(cmd, "Mode");
11920 int res;
11921
11922 if (intf == NULL || mode == NULL)
11923 return -1;
11924
11925 if (strcasecmp(mode, "On") == 0)
11926 res = wpa_command(intf, "SET radio_disabled 0");
11927 else if (strcasecmp(mode, "Off") == 0)
11928 res = wpa_command(intf, "SET radio_disabled 1");
11929 else
11930 return -1;
11931
11932 if (res) {
11933 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11934 "radio mode");
11935 return 0;
11936 }
11937
11938 return 1;
11939}
11940
11941
Jouni Malinenf7222712019-06-13 01:50:21 +030011942static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
11943 struct sigma_conn *conn,
11944 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011945{
11946 const char *intf = get_param(cmd, "Interface");
11947 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011948 const char *prog = get_param(cmd, "program");
11949 const char *powersave = get_param(cmd, "powersave");
11950 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011951
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011952 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011953 return -1;
11954
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011955 if (prog && strcasecmp(prog, "60GHz") == 0) {
11956 /*
11957 * The CAPI mode parameter does not exist in 60G
11958 * unscheduled PS.
11959 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080011960 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011961 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011962 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011963 strcasecmp(prog, "HE") == 0) {
11964 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011965 } else {
11966 if (mode == NULL)
11967 return -1;
11968
11969 if (strcasecmp(mode, "On") == 0)
11970 res = set_ps(intf, dut, 1);
11971 else if (strcasecmp(mode, "Off") == 0)
11972 res = set_ps(intf, dut, 0);
11973 else
11974 return -1;
11975 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011976
11977 if (res) {
11978 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11979 "power save mode");
11980 return 0;
11981 }
11982
11983 return 1;
11984}
11985
11986
Jouni Malinenf7222712019-06-13 01:50:21 +030011987static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
11988 struct sigma_conn *conn,
11989 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011990{
11991 const char *intf = get_param(cmd, "Interface");
11992 const char *val, *bssid;
11993 int res;
11994 char *buf;
11995 size_t buf_len;
11996
11997 val = get_param(cmd, "BSSID_FILTER");
11998 if (val == NULL)
11999 return -1;
12000
12001 bssid = get_param(cmd, "BSSID_List");
12002 if (atoi(val) == 0 || bssid == NULL) {
12003 /* Disable BSSID filter */
12004 if (wpa_command(intf, "SET bssid_filter ")) {
12005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12006 "to disable BSSID filter");
12007 return 0;
12008 }
12009
12010 return 1;
12011 }
12012
12013 buf_len = 100 + strlen(bssid);
12014 buf = malloc(buf_len);
12015 if (buf == NULL)
12016 return -1;
12017
12018 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12019 res = wpa_command(intf, buf);
12020 free(buf);
12021 if (res) {
12022 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12023 "BSSID filter");
12024 return 0;
12025 }
12026
12027 return 1;
12028}
12029
12030
Jouni Malinenf7222712019-06-13 01:50:21 +030012031static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12032 struct sigma_conn *conn,
12033 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012034{
12035 const char *intf = get_param(cmd, "Interface");
12036 const char *val;
12037
12038 /* TODO: ARP */
12039
12040 val = get_param(cmd, "HS2_CACHE_PROFILE");
12041 if (val && strcasecmp(val, "All") == 0)
12042 hs2_clear_credentials(intf);
12043
12044 return 1;
12045}
12046
12047
Jouni Malinenf7222712019-06-13 01:50:21 +030012048static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12049 struct sigma_conn *conn,
12050 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012051{
12052 const char *intf = get_param(cmd, "Interface");
12053 const char *key_type = get_param(cmd, "KeyType");
12054 char buf[100], resp[200];
12055
12056 if (key_type == NULL)
12057 return -1;
12058
12059 if (strcasecmp(key_type, "GTK") == 0) {
12060 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12061 strncmp(buf, "FAIL", 4) == 0) {
12062 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12063 "not fetch current GTK");
12064 return 0;
12065 }
12066 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12067 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12068 return 0;
12069 } else {
12070 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12071 "KeyType");
12072 return 0;
12073 }
12074
12075 return 1;
12076}
12077
12078
12079static int hs2_set_policy(struct sigma_dut *dut)
12080{
12081#ifdef ANDROID
12082 system("ip rule del prio 23000");
12083 if (system("ip rule add from all lookup main prio 23000") != 0) {
12084 sigma_dut_print(dut, DUT_MSG_ERROR,
12085 "Failed to run:ip rule add from all lookup main prio");
12086 return -1;
12087 }
12088 if (system("ip route flush cache") != 0) {
12089 sigma_dut_print(dut, DUT_MSG_ERROR,
12090 "Failed to run ip route flush cache");
12091 return -1;
12092 }
12093 return 1;
12094#else /* ANDROID */
12095 return 0;
12096#endif /* ANDROID */
12097}
12098
12099
Jouni Malinenf7222712019-06-13 01:50:21 +030012100static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12101 struct sigma_conn *conn,
12102 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012103{
12104 const char *intf = get_param(cmd, "Interface");
12105 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012106 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012107 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012108 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012109 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12110 int tries = 0;
12111 int ignore_blacklist = 0;
12112 const char *events[] = {
12113 "CTRL-EVENT-CONNECTED",
12114 "INTERWORKING-BLACKLISTED",
12115 "INTERWORKING-NO-MATCH",
12116 NULL
12117 };
12118
12119 start_sta_mode(dut);
12120
Jouni Malinen439352d2018-09-13 03:42:23 +030012121 if (band) {
12122 if (strcmp(band, "2.4") == 0) {
12123 wpa_command(intf, "SET setband 2G");
12124 } else if (strcmp(band, "5") == 0) {
12125 wpa_command(intf, "SET setband 5G");
12126 } else {
12127 send_resp(dut, conn, SIGMA_ERROR,
12128 "errorCode,Unsupported band");
12129 return 0;
12130 }
12131 }
12132
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012133 blacklisted[0] = '\0';
12134 if (val && atoi(val))
12135 ignore_blacklist = 1;
12136
12137try_again:
12138 ctrl = open_wpa_mon(intf);
12139 if (ctrl == NULL) {
12140 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12141 "wpa_supplicant monitor connection");
12142 return -2;
12143 }
12144
12145 tries++;
12146 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12147 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12148 "Interworking connection");
12149 wpa_ctrl_detach(ctrl);
12150 wpa_ctrl_close(ctrl);
12151 return 0;
12152 }
12153
12154 buf[0] = '\0';
12155 while (1) {
12156 char *pos;
12157 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12158 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12159 if (!pos)
12160 break;
12161 pos += 25;
12162 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12163 pos);
12164 if (!blacklisted[0])
12165 memcpy(blacklisted, pos, strlen(pos) + 1);
12166 }
12167
12168 if (ignore_blacklist && blacklisted[0]) {
12169 char *end;
12170 end = strchr(blacklisted, ' ');
12171 if (end)
12172 *end = '\0';
12173 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12174 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012175 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12176 blacklisted);
12177 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012178 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12179 wpa_ctrl_detach(ctrl);
12180 wpa_ctrl_close(ctrl);
12181 return 0;
12182 }
12183 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12184 buf, sizeof(buf));
12185 }
12186
12187 wpa_ctrl_detach(ctrl);
12188 wpa_ctrl_close(ctrl);
12189
12190 if (res < 0) {
12191 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12192 "connect");
12193 return 0;
12194 }
12195
12196 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12197 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12198 if (tries < 2) {
12199 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12200 goto try_again;
12201 }
12202 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12203 "matching credentials found");
12204 return 0;
12205 }
12206
12207 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12208 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12209 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12210 "get current BSSID/SSID");
12211 return 0;
12212 }
12213
12214 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12215 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12216 hs2_set_policy(dut);
12217 return 0;
12218}
12219
12220
Jouni Malinenf7222712019-06-13 01:50:21 +030012221static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12222 struct sigma_conn *conn,
12223 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012224{
12225 const char *intf = get_param(cmd, "Interface");
12226 const char *display = get_param(cmd, "Display");
12227 struct wpa_ctrl *ctrl;
12228 char buf[300], params[400], *pos;
12229 char bssid[20];
12230 int info_avail = 0;
12231 unsigned int old_timeout;
12232 int res;
12233
12234 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12235 send_resp(dut, conn, SIGMA_ERROR,
12236 "ErrorCode,Could not get current BSSID");
12237 return 0;
12238 }
12239 ctrl = open_wpa_mon(intf);
12240 if (!ctrl) {
12241 sigma_dut_print(dut, DUT_MSG_ERROR,
12242 "Failed to open wpa_supplicant monitor connection");
12243 return -2;
12244 }
12245
12246 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12247 wpa_command(intf, buf);
12248
12249 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12250 if (res < 0) {
12251 send_resp(dut, conn, SIGMA_ERROR,
12252 "ErrorCode,Could not complete GAS query");
12253 goto fail;
12254 }
12255
12256 old_timeout = dut->default_timeout;
12257 dut->default_timeout = 2;
12258 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12259 dut->default_timeout = old_timeout;
12260 if (res < 0)
12261 goto done;
12262 pos = strchr(buf, ' ');
12263 if (!pos)
12264 goto done;
12265 pos++;
12266 pos = strchr(pos, ' ');
12267 if (!pos)
12268 goto done;
12269 pos++;
12270 info_avail = 1;
12271 snprintf(params, sizeof(params), "browser %s", pos);
12272
12273 if (display && strcasecmp(display, "Yes") == 0) {
12274 pid_t pid;
12275
12276 pid = fork();
12277 if (pid < 0) {
12278 perror("fork");
12279 return -1;
12280 }
12281
12282 if (pid == 0) {
12283 run_hs20_osu(dut, params);
12284 exit(0);
12285 }
12286 }
12287
12288done:
12289 snprintf(buf, sizeof(buf), "Info_available,%s",
12290 info_avail ? "Yes" : "No");
12291 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12292fail:
12293 wpa_ctrl_detach(ctrl);
12294 wpa_ctrl_close(ctrl);
12295 return 0;
12296}
12297
12298
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012299static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12300 struct sigma_conn *conn,
12301 const char *ifname,
12302 struct sigma_cmd *cmd)
12303{
12304 const char *val;
12305 int id;
12306
12307 id = add_cred(ifname);
12308 if (id < 0)
12309 return -2;
12310 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12311
12312 val = get_param(cmd, "prefer");
12313 if (val && atoi(val) > 0)
12314 set_cred(ifname, id, "priority", "1");
12315
12316 val = get_param(cmd, "REALM");
12317 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12318 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12319 "realm");
12320 return 0;
12321 }
12322
12323 val = get_param(cmd, "HOME_FQDN");
12324 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12325 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12326 "home_fqdn");
12327 return 0;
12328 }
12329
12330 val = get_param(cmd, "Username");
12331 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12332 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12333 "username");
12334 return 0;
12335 }
12336
12337 val = get_param(cmd, "Password");
12338 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12339 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12340 "password");
12341 return 0;
12342 }
12343
12344 val = get_param(cmd, "ROOT_CA");
12345 if (val) {
12346 char fname[200];
12347 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12348#ifdef __linux__
12349 if (!file_exists(fname)) {
12350 char msg[300];
12351 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12352 "file (%s) not found", fname);
12353 send_resp(dut, conn, SIGMA_ERROR, msg);
12354 return 0;
12355 }
12356#endif /* __linux__ */
12357 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12358 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12359 "not set root CA");
12360 return 0;
12361 }
12362 }
12363
12364 return 1;
12365}
12366
12367
12368static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12369{
12370 FILE *in, *out;
12371 char buf[500];
12372 int found = 0;
12373
12374 in = fopen("devdetail.xml", "r");
12375 if (in == NULL)
12376 return -1;
12377 out = fopen("devdetail.xml.tmp", "w");
12378 if (out == NULL) {
12379 fclose(in);
12380 return -1;
12381 }
12382
12383 while (fgets(buf, sizeof(buf), in)) {
12384 char *pos = strstr(buf, "<IMSI>");
12385 if (pos) {
12386 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12387 imsi);
12388 pos += 6;
12389 *pos = '\0';
12390 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12391 found++;
12392 } else {
12393 fprintf(out, "%s", buf);
12394 }
12395 }
12396
12397 fclose(out);
12398 fclose(in);
12399 if (found)
12400 rename("devdetail.xml.tmp", "devdetail.xml");
12401 else
12402 unlink("devdetail.xml.tmp");
12403
12404 return 0;
12405}
12406
12407
12408static int sta_add_credential_sim(struct sigma_dut *dut,
12409 struct sigma_conn *conn,
12410 const char *ifname, struct sigma_cmd *cmd)
12411{
12412 const char *val, *imsi = NULL;
12413 int id;
12414 char buf[200];
12415 int res;
12416 const char *pos;
12417 size_t mnc_len;
12418 char plmn_mcc[4];
12419 char plmn_mnc[4];
12420
12421 id = add_cred(ifname);
12422 if (id < 0)
12423 return -2;
12424 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12425
12426 val = get_param(cmd, "prefer");
12427 if (val && atoi(val) > 0)
12428 set_cred(ifname, id, "priority", "1");
12429
12430 val = get_param(cmd, "PLMN_MCC");
12431 if (val == NULL) {
12432 send_resp(dut, conn, SIGMA_ERROR,
12433 "errorCode,Missing PLMN_MCC");
12434 return 0;
12435 }
12436 if (strlen(val) != 3) {
12437 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12438 return 0;
12439 }
12440 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12441
12442 val = get_param(cmd, "PLMN_MNC");
12443 if (val == NULL) {
12444 send_resp(dut, conn, SIGMA_ERROR,
12445 "errorCode,Missing PLMN_MNC");
12446 return 0;
12447 }
12448 if (strlen(val) != 2 && strlen(val) != 3) {
12449 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12450 return 0;
12451 }
12452 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12453
12454 val = get_param(cmd, "IMSI");
12455 if (val == NULL) {
12456 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12457 "IMSI");
12458 return 0;
12459 }
12460
12461 imsi = pos = val;
12462
12463 if (strncmp(plmn_mcc, pos, 3) != 0) {
12464 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12465 return 0;
12466 }
12467 pos += 3;
12468
12469 mnc_len = strlen(plmn_mnc);
12470 if (mnc_len < 2) {
12471 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12472 return 0;
12473 }
12474
12475 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12476 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12477 return 0;
12478 }
12479 pos += mnc_len;
12480
12481 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12482 if (res < 0 || res >= (int) sizeof(buf))
12483 return -1;
12484 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12485 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12486 "not set IMSI");
12487 return 0;
12488 }
12489
12490 val = get_param(cmd, "Password");
12491 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12492 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12493 "not set password");
12494 return 0;
12495 }
12496
Jouni Malinenba630452018-06-22 11:49:59 +030012497 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012498 /*
12499 * Set provisioning_sp for the test cases where SIM/USIM
12500 * provisioning is used.
12501 */
12502 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12503 "wi-fi.org") < 0) {
12504 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12505 "not set provisioning_sp");
12506 return 0;
12507 }
12508
12509 update_devdetail_imsi(dut, imsi);
12510 }
12511
12512 return 1;
12513}
12514
12515
12516static int sta_add_credential_cert(struct sigma_dut *dut,
12517 struct sigma_conn *conn,
12518 const char *ifname,
12519 struct sigma_cmd *cmd)
12520{
12521 const char *val;
12522 int id;
12523
12524 id = add_cred(ifname);
12525 if (id < 0)
12526 return -2;
12527 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12528
12529 val = get_param(cmd, "prefer");
12530 if (val && atoi(val) > 0)
12531 set_cred(ifname, id, "priority", "1");
12532
12533 val = get_param(cmd, "REALM");
12534 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12535 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12536 "realm");
12537 return 0;
12538 }
12539
12540 val = get_param(cmd, "HOME_FQDN");
12541 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12542 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12543 "home_fqdn");
12544 return 0;
12545 }
12546
12547 val = get_param(cmd, "Username");
12548 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12549 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12550 "username");
12551 return 0;
12552 }
12553
12554 val = get_param(cmd, "clientCertificate");
12555 if (val) {
12556 char fname[200];
12557 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12558#ifdef __linux__
12559 if (!file_exists(fname)) {
12560 char msg[300];
12561 snprintf(msg, sizeof(msg),
12562 "ErrorCode,clientCertificate "
12563 "file (%s) not found", fname);
12564 send_resp(dut, conn, SIGMA_ERROR, msg);
12565 return 0;
12566 }
12567#endif /* __linux__ */
12568 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12569 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12570 "not set client_cert");
12571 return 0;
12572 }
12573 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12574 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12575 "not set private_key");
12576 return 0;
12577 }
12578 }
12579
12580 val = get_param(cmd, "ROOT_CA");
12581 if (val) {
12582 char fname[200];
12583 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12584#ifdef __linux__
12585 if (!file_exists(fname)) {
12586 char msg[300];
12587 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12588 "file (%s) not found", fname);
12589 send_resp(dut, conn, SIGMA_ERROR, msg);
12590 return 0;
12591 }
12592#endif /* __linux__ */
12593 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12594 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12595 "not set root CA");
12596 return 0;
12597 }
12598 }
12599
12600 return 1;
12601}
12602
12603
Jouni Malinenf7222712019-06-13 01:50:21 +030012604static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12605 struct sigma_conn *conn,
12606 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012607{
12608 const char *intf = get_param(cmd, "Interface");
12609 const char *type;
12610
12611 start_sta_mode(dut);
12612
12613 type = get_param(cmd, "Type");
12614 if (!type)
12615 return -1;
12616
12617 if (strcasecmp(type, "uname_pwd") == 0)
12618 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12619
12620 if (strcasecmp(type, "sim") == 0)
12621 return sta_add_credential_sim(dut, conn, intf, cmd);
12622
12623 if (strcasecmp(type, "cert") == 0)
12624 return sta_add_credential_cert(dut, conn, intf, cmd);
12625
12626 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12627 "type");
12628 return 0;
12629}
12630
12631
Jouni Malinenf7222712019-06-13 01:50:21 +030012632static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12633 struct sigma_conn *conn,
12634 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012635{
12636 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012637 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012638 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012639 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012640 int res;
12641
Arif Hussain66a4af02019-02-07 15:04:51 -080012642 val = get_param(cmd, "GetParameter");
12643 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012644 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012645 buf, sizeof(buf)) < 0) {
12646 sigma_dut_print(dut, DUT_MSG_ERROR,
12647 "Could not get ssid bssid");
12648 return ERROR_SEND_STATUS;
12649 }
12650
12651 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12652 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12653 return STATUS_SENT;
12654 }
12655
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012656 val = get_param(cmd, "HESSID");
12657 if (val) {
12658 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12659 if (res < 0 || res >= (int) sizeof(buf))
12660 return -1;
12661 wpa_command(intf, buf);
12662 }
12663
12664 val = get_param(cmd, "ACCS_NET_TYPE");
12665 if (val) {
12666 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12667 val);
12668 if (res < 0 || res >= (int) sizeof(buf))
12669 return -1;
12670 wpa_command(intf, buf);
12671 }
12672
vamsi krishna89ad8c62017-09-19 12:51:18 +053012673 bssid = get_param(cmd, "Bssid");
12674 ssid = get_param(cmd, "Ssid");
12675
12676 if (ssid) {
12677 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12678 send_resp(dut, conn, SIGMA_ERROR,
12679 "ErrorCode,Too long SSID");
12680 return 0;
12681 }
12682 ascii2hexstr(ssid, ssid_hex);
12683 }
12684
12685 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12686 bssid ? " bssid=": "",
12687 bssid ? bssid : "",
12688 ssid ? " ssid " : "",
12689 ssid ? ssid_hex : "");
12690 if (res < 0 || res >= (int) sizeof(buf))
12691 return -1;
12692
12693 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012694 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12695 "scan");
12696 return 0;
12697 }
12698
12699 return 1;
12700}
12701
12702
Jouni Malinenf7222712019-06-13 01:50:21 +030012703static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12704 struct sigma_conn *conn,
12705 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012706{
12707 const char *intf = get_param(cmd, "Interface");
12708 const char *bssid;
12709 char buf[4096], *pos;
12710 int freq, chan;
12711 char *ssid;
12712 char resp[100];
12713 int res;
12714 struct wpa_ctrl *ctrl;
12715
12716 bssid = get_param(cmd, "BSSID");
12717 if (!bssid) {
12718 send_resp(dut, conn, SIGMA_INVALID,
12719 "errorCode,BSSID argument is missing");
12720 return 0;
12721 }
12722
12723 ctrl = open_wpa_mon(intf);
12724 if (!ctrl) {
12725 sigma_dut_print(dut, DUT_MSG_ERROR,
12726 "Failed to open wpa_supplicant monitor connection");
12727 return -1;
12728 }
12729
12730 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12731 send_resp(dut, conn, SIGMA_ERROR,
12732 "errorCode,Could not start scan");
12733 wpa_ctrl_detach(ctrl);
12734 wpa_ctrl_close(ctrl);
12735 return 0;
12736 }
12737
12738 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12739 buf, sizeof(buf));
12740
12741 wpa_ctrl_detach(ctrl);
12742 wpa_ctrl_close(ctrl);
12743
12744 if (res < 0) {
12745 send_resp(dut, conn, SIGMA_ERROR,
12746 "errorCode,Scan did not complete");
12747 return 0;
12748 }
12749
12750 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12751 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12752 strncmp(buf, "id=", 3) != 0) {
12753 send_resp(dut, conn, SIGMA_ERROR,
12754 "errorCode,Specified BSSID not found");
12755 return 0;
12756 }
12757
12758 pos = strstr(buf, "\nfreq=");
12759 if (!pos) {
12760 send_resp(dut, conn, SIGMA_ERROR,
12761 "errorCode,Channel not found");
12762 return 0;
12763 }
12764 freq = atoi(pos + 6);
12765 chan = freq_to_channel(freq);
12766
12767 pos = strstr(buf, "\nssid=");
12768 if (!pos) {
12769 send_resp(dut, conn, SIGMA_ERROR,
12770 "errorCode,SSID not found");
12771 return 0;
12772 }
12773 ssid = pos + 6;
12774 pos = strchr(ssid, '\n');
12775 if (pos)
12776 *pos = '\0';
12777 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12778 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12779 return 0;
12780}
12781
12782
Jouni Malinenf7222712019-06-13 01:50:21 +030012783static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
12784 struct sigma_conn *conn,
12785 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012786{
12787#ifdef __linux__
12788 struct timeval tv;
12789 struct tm tm;
12790 time_t t;
12791 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012792 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012793
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012794 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012795
12796 memset(&tm, 0, sizeof(tm));
12797 val = get_param(cmd, "seconds");
12798 if (val)
12799 tm.tm_sec = atoi(val);
12800 val = get_param(cmd, "minutes");
12801 if (val)
12802 tm.tm_min = atoi(val);
12803 val = get_param(cmd, "hours");
12804 if (val)
12805 tm.tm_hour = atoi(val);
12806 val = get_param(cmd, "date");
12807 if (val)
12808 tm.tm_mday = atoi(val);
12809 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012810 if (val) {
12811 v = atoi(val);
12812 if (v < 1 || v > 12) {
12813 send_resp(dut, conn, SIGMA_INVALID,
12814 "errorCode,Invalid month");
12815 return 0;
12816 }
12817 tm.tm_mon = v - 1;
12818 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012819 val = get_param(cmd, "year");
12820 if (val) {
12821 int year = atoi(val);
12822#ifdef ANDROID
12823 if (year > 2035)
12824 year = 2035; /* years beyond 2035 not supported */
12825#endif /* ANDROID */
12826 tm.tm_year = year - 1900;
12827 }
12828 t = mktime(&tm);
12829 if (t == (time_t) -1) {
12830 send_resp(dut, conn, SIGMA_ERROR,
12831 "errorCode,Invalid date or time");
12832 return 0;
12833 }
12834
12835 memset(&tv, 0, sizeof(tv));
12836 tv.tv_sec = t;
12837
12838 if (settimeofday(&tv, NULL) < 0) {
12839 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12840 strerror(errno));
12841 send_resp(dut, conn, SIGMA_ERROR,
12842 "errorCode,Failed to set time");
12843 return 0;
12844 }
12845
12846 return 1;
12847#endif /* __linux__ */
12848
12849 return -1;
12850}
12851
12852
Jouni Malinenf7222712019-06-13 01:50:21 +030012853static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
12854 struct sigma_conn *conn,
12855 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012856{
12857 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012858 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012859 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012860 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012861 int res;
12862 struct wpa_ctrl *ctrl;
12863
12864 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012865 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012866
12867 val = get_param(cmd, "ProdESSAssoc");
12868 if (val)
12869 prod_ess_assoc = atoi(val);
12870
12871 kill_dhcp_client(dut, intf);
12872 if (start_dhcp_client(dut, intf) < 0)
12873 return -2;
12874
12875 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12876 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12877 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012878 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012879 prod_ess_assoc ? "" : "-N",
12880 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012881 name ? "'" : "",
12882 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12883 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012884
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012885 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012886 if (run_hs20_osu(dut, buf) < 0) {
12887 FILE *f;
12888
12889 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12890
12891 f = fopen("hs20-osu-client.res", "r");
12892 if (f) {
12893 char resp[400], res[300], *pos;
12894 if (!fgets(res, sizeof(res), f))
12895 res[0] = '\0';
12896 pos = strchr(res, '\n');
12897 if (pos)
12898 *pos = '\0';
12899 fclose(f);
12900 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12901 res);
12902 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12903 if (system(resp) != 0) {
12904 }
12905 snprintf(resp, sizeof(resp),
12906 "SSID,,BSSID,,failureReason,%s", res);
12907 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12908 return 0;
12909 }
12910
12911 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12912 return 0;
12913 }
12914
12915 if (!prod_ess_assoc)
12916 goto report;
12917
12918 ctrl = open_wpa_mon(intf);
12919 if (ctrl == NULL) {
12920 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12921 "wpa_supplicant monitor connection");
12922 return -1;
12923 }
12924
12925 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12926 buf, sizeof(buf));
12927
12928 wpa_ctrl_detach(ctrl);
12929 wpa_ctrl_close(ctrl);
12930
12931 if (res < 0) {
12932 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12933 "network after OSU");
12934 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12935 return 0;
12936 }
12937
12938report:
12939 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12940 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12941 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12942 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12943 return 0;
12944 }
12945
12946 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12947 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012948 return 0;
12949}
12950
12951
Jouni Malinenf7222712019-06-13 01:50:21 +030012952static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
12953 struct sigma_conn *conn,
12954 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012955{
12956 const char *val;
12957 int timeout = 120;
12958
12959 val = get_param(cmd, "PolicyUpdate");
12960 if (val == NULL || atoi(val) == 0)
12961 return 1; /* No operation requested */
12962
12963 val = get_param(cmd, "Timeout");
12964 if (val)
12965 timeout = atoi(val);
12966
12967 if (timeout) {
12968 /* TODO: time out the command and return
12969 * PolicyUpdateStatus,TIMEOUT if needed. */
12970 }
12971
12972 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12973 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12974 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12975 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12976 return 0;
12977 }
12978
12979 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12980 return 0;
12981}
12982
12983
Jouni Malinenf7222712019-06-13 01:50:21 +030012984static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
12985 struct sigma_conn *conn,
12986 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012987{
12988 struct wpa_ctrl *ctrl;
12989 const char *intf = get_param(cmd, "Interface");
12990 const char *bssid = get_param(cmd, "Bssid");
12991 const char *ssid = get_param(cmd, "SSID");
12992 const char *security = get_param(cmd, "Security");
12993 const char *passphrase = get_param(cmd, "Passphrase");
12994 const char *pin = get_param(cmd, "PIN");
12995 char buf[1000];
12996 char ssid_hex[200], passphrase_hex[200];
12997 const char *keymgmt, *cipher;
12998
12999 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013000 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013001
13002 if (!bssid) {
13003 send_resp(dut, conn, SIGMA_ERROR,
13004 "ErrorCode,Missing Bssid argument");
13005 return 0;
13006 }
13007
13008 if (!ssid) {
13009 send_resp(dut, conn, SIGMA_ERROR,
13010 "ErrorCode,Missing SSID argument");
13011 return 0;
13012 }
13013
13014 if (!security) {
13015 send_resp(dut, conn, SIGMA_ERROR,
13016 "ErrorCode,Missing Security argument");
13017 return 0;
13018 }
13019
13020 if (!passphrase) {
13021 send_resp(dut, conn, SIGMA_ERROR,
13022 "ErrorCode,Missing Passphrase argument");
13023 return 0;
13024 }
13025
13026 if (!pin) {
13027 send_resp(dut, conn, SIGMA_ERROR,
13028 "ErrorCode,Missing PIN argument");
13029 return 0;
13030 }
13031
vamsi krishna8c9c1562017-05-12 15:51:46 +053013032 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13033 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013034 send_resp(dut, conn, SIGMA_ERROR,
13035 "ErrorCode,Too long SSID/passphrase");
13036 return 0;
13037 }
13038
13039 ctrl = open_wpa_mon(intf);
13040 if (ctrl == NULL) {
13041 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13042 "wpa_supplicant monitor connection");
13043 return -2;
13044 }
13045
13046 if (strcasecmp(security, "wpa2-psk") == 0) {
13047 keymgmt = "WPA2PSK";
13048 cipher = "CCMP";
13049 } else {
13050 wpa_ctrl_detach(ctrl);
13051 wpa_ctrl_close(ctrl);
13052 send_resp(dut, conn, SIGMA_ERROR,
13053 "ErrorCode,Unsupported Security value");
13054 return 0;
13055 }
13056
13057 ascii2hexstr(ssid, ssid_hex);
13058 ascii2hexstr(passphrase, passphrase_hex);
13059 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13060 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13061
13062 if (wpa_command(intf, buf) < 0) {
13063 wpa_ctrl_detach(ctrl);
13064 wpa_ctrl_close(ctrl);
13065 send_resp(dut, conn, SIGMA_ERROR,
13066 "ErrorCode,Failed to start registrar");
13067 return 0;
13068 }
13069
13070 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13071 dut->er_oper_performed = 1;
13072
13073 return wps_connection_event(dut, conn, ctrl, intf, 0);
13074}
13075
13076
Jouni Malinenf7222712019-06-13 01:50:21 +030013077static enum sigma_cmd_result
13078cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13079 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013080{
13081 struct wpa_ctrl *ctrl;
13082 const char *intf = get_param(cmd, "Interface");
13083 const char *bssid = get_param(cmd, "Bssid");
13084 char buf[100];
13085
13086 if (!bssid) {
13087 send_resp(dut, conn, SIGMA_ERROR,
13088 "ErrorCode,Missing Bssid argument");
13089 return 0;
13090 }
13091
13092 ctrl = open_wpa_mon(intf);
13093 if (ctrl == NULL) {
13094 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13095 "wpa_supplicant monitor connection");
13096 return -2;
13097 }
13098
13099 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13100
13101 if (wpa_command(intf, buf) < 0) {
13102 wpa_ctrl_detach(ctrl);
13103 wpa_ctrl_close(ctrl);
13104 send_resp(dut, conn, SIGMA_ERROR,
13105 "ErrorCode,Failed to start registrar");
13106 return 0;
13107 }
13108
13109 return wps_connection_event(dut, conn, ctrl, intf, 0);
13110}
13111
13112
Jouni Malinenf7222712019-06-13 01:50:21 +030013113static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13114 struct sigma_conn *conn,
13115 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013116{
13117 struct wpa_ctrl *ctrl;
13118 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013119 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013120 const char *config_method = get_param(cmd, "WPSConfigMethod");
13121 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013122 int res;
13123 char buf[256];
13124 const char *events[] = {
13125 "CTRL-EVENT-CONNECTED",
13126 "WPS-OVERLAP-DETECTED",
13127 "WPS-TIMEOUT",
13128 "WPS-FAIL",
13129 NULL
13130 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013131 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013132
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013133 /* 60G WPS tests do not pass Interface parameter */
13134 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013135 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013136
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013137 if (dut->mode == SIGMA_MODE_AP)
13138 return ap_wps_registration(dut, conn, cmd);
13139
13140 if (config_method) {
13141 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13142 * sta_wps_enter_pin before calling start_wps_registration. */
13143 if (strcasecmp(config_method, "PBC") == 0)
13144 dut->wps_method = WFA_CS_WPS_PBC;
13145 }
13146 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13147 send_resp(dut, conn, SIGMA_ERROR,
13148 "ErrorCode,WPS parameters not yet set");
13149 return STATUS_SENT;
13150 }
13151
13152 /* Make sure WPS is enabled (also for STA mode) */
13153 dut->wps_disable = 0;
13154
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013155 if (dut->band == WPS_BAND_60G && network_mode &&
13156 strcasecmp(network_mode, "PBSS") == 0) {
13157 sigma_dut_print(dut, DUT_MSG_DEBUG,
13158 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013159 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013160 return -2;
13161 }
13162
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013163 if (dut->force_rsn_ie) {
13164 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13165 dut->force_rsn_ie);
13166 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13167 sigma_dut_print(dut, DUT_MSG_INFO,
13168 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013169 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013170 }
13171 }
13172
vamsi krishna9b144002017-09-20 13:28:13 +053013173 ctrl = open_wpa_mon(intf);
13174 if (!ctrl) {
13175 sigma_dut_print(dut, DUT_MSG_ERROR,
13176 "Failed to open wpa_supplicant monitor connection");
13177 return -2;
13178 }
13179
13180 role = get_param(cmd, "WpsRole");
13181 if (!role) {
13182 send_resp(dut, conn, SIGMA_INVALID,
13183 "ErrorCode,WpsRole not provided");
13184 goto fail;
13185 }
13186
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013187 if (strcasecmp(role, "Enrollee") != 0) {
13188 /* Registrar role for STA not supported */
13189 send_resp(dut, conn, SIGMA_ERROR,
13190 "ErrorCode,Unsupported WpsRole value");
13191 goto fail;
13192 }
13193
13194 if (is_60g_sigma_dut(dut)) {
13195 if (dut->wps_method == WFA_CS_WPS_PBC)
13196 snprintf(buf, sizeof(buf), "WPS_PBC");
13197 else /* WFA_CS_WPS_PIN_KEYPAD */
13198 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13199 dut->wps_pin);
13200 if (wpa_command(intf, buf) < 0) {
13201 send_resp(dut, conn, SIGMA_ERROR,
13202 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013203 goto fail;
13204 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013205 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13206 if (res < 0) {
13207 send_resp(dut, conn, SIGMA_ERROR,
13208 "ErrorCode,WPS connection did not complete");
13209 goto fail;
13210 }
13211 if (strstr(buf, "WPS-TIMEOUT")) {
13212 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13213 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13214 send_resp(dut, conn, SIGMA_COMPLETE,
13215 "WpsState,OverlapSession");
13216 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13217 send_resp(dut, conn, SIGMA_COMPLETE,
13218 "WpsState,Successful");
13219 } else {
13220 send_resp(dut, conn, SIGMA_COMPLETE,
13221 "WpsState,Failure");
13222 }
13223 } else {
13224 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013225 if (wpa_command(intf, "WPS_PBC") < 0) {
13226 send_resp(dut, conn, SIGMA_ERROR,
13227 "ErrorCode,Failed to enable PBC");
13228 goto fail;
13229 }
13230 } else {
13231 /* TODO: PIN method */
13232 send_resp(dut, conn, SIGMA_ERROR,
13233 "ErrorCode,Unsupported WpsConfigMethod value");
13234 goto fail;
13235 }
13236 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13237 if (res < 0) {
13238 send_resp(dut, conn, SIGMA_ERROR,
13239 "ErrorCode,WPS connection did not complete");
13240 goto fail;
13241 }
13242 if (strstr(buf, "WPS-TIMEOUT")) {
13243 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13244 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13245 send_resp(dut, conn, SIGMA_ERROR,
13246 "ErrorCode,OverlapSession");
13247 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13248 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13249 } else {
13250 send_resp(dut, conn, SIGMA_ERROR,
13251 "ErrorCode,WPS operation failed");
13252 }
vamsi krishna9b144002017-09-20 13:28:13 +053013253 }
13254
13255fail:
13256 wpa_ctrl_detach(ctrl);
13257 wpa_ctrl_close(ctrl);
13258 return 0;
13259}
13260
13261
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013262static int req_intf(struct sigma_cmd *cmd)
13263{
13264 return get_param(cmd, "interface") == NULL ? -1 : 0;
13265}
13266
13267
13268void sta_register_cmds(void)
13269{
13270 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13271 cmd_sta_get_ip_config);
13272 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13273 cmd_sta_set_ip_config);
13274 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13275 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13276 cmd_sta_get_mac_address);
13277 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13278 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13279 cmd_sta_verify_ip_connection);
13280 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13281 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13282 cmd_sta_set_encryption);
13283 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13284 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13285 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13286 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13287 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13288 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13289 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13290 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13291 cmd_sta_set_eapakaprime);
13292 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13293 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13294 /* TODO: sta_set_ibss */
13295 /* TODO: sta_set_mode */
13296 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13297 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13298 /* TODO: sta_up_load */
13299 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13300 cmd_sta_preset_testparameters);
13301 /* TODO: sta_set_system */
13302 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13303 /* TODO: sta_set_rifs_test */
13304 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13305 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13306 /* TODO: sta_send_coexist_mgmt */
13307 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13308 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13309 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13310 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13311 cmd_sta_reset_default);
13312 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13313 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13314 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13315 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13316 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013317 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013318 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13319 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13320 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13321 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13322 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013323 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13324 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013325 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13326 cmd_sta_add_credential);
13327 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013328 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013329 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13330 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13331 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13332 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13333 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13334 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013335 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013336 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13337 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013338 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013339 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013340}