blob: 282fe85a43fece8b2ff0918a9b0aac712bad5b2c [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 Malinen9540e012019-11-05 17:08:42 +02001569 start_sta_mode(dut);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001570 if (get_wpa_status(get_station_ifname(dut), "address",
1571 addr, sizeof(addr)) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001572 return -2;
1573
1574 snprintf(resp, sizeof(resp), "mac,%s", addr);
1575 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1576 return 0;
1577}
1578
1579
Jouni Malinenf7222712019-06-13 01:50:21 +03001580static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1581 struct sigma_conn *conn,
1582 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001583{
1584 /* const char *intf = get_param(cmd, "Interface"); */
1585 int connected = 0;
1586 char result[32];
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001587 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001588 sizeof(result)) < 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001589 sigma_dut_print(dut, DUT_MSG_INFO,
1590 "Could not get interface %s status",
1591 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001592 return -2;
1593 }
1594
1595 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1596 if (strncmp(result, "COMPLETED", 9) == 0)
1597 connected = 1;
1598
1599 if (connected)
1600 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1601 else
1602 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1603
1604 return 0;
1605}
1606
1607
Jouni Malinenf7222712019-06-13 01:50:21 +03001608static enum sigma_cmd_result
1609cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1610 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001611{
1612 /* const char *intf = get_param(cmd, "Interface"); */
1613 const char *dst, *timeout;
1614 int wait_time = 90;
1615 char buf[100];
1616 int res;
1617
1618 dst = get_param(cmd, "destination");
1619 if (dst == NULL || !is_ip_addr(dst))
1620 return -1;
1621
1622 timeout = get_param(cmd, "timeout");
1623 if (timeout) {
1624 wait_time = atoi(timeout);
1625 if (wait_time < 1)
1626 wait_time = 1;
1627 }
1628
1629 /* TODO: force renewal of IP lease if DHCP is enabled */
1630
1631 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1632 res = system(buf);
1633 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1634 if (res == 0)
1635 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1636 else if (res == 256)
1637 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1638 else
1639 return -2;
1640
1641 return 0;
1642}
1643
1644
Jouni Malinenf7222712019-06-13 01:50:21 +03001645static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1646 struct sigma_conn *conn,
1647 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001648{
1649 /* const char *intf = get_param(cmd, "Interface"); */
1650 char bssid[20], resp[50];
1651
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001652 if (get_wpa_status(get_station_ifname(dut), "bssid",
1653 bssid, sizeof(bssid)) < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001654 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001655
1656 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1657 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1658 return 0;
1659}
1660
1661
1662#ifdef __SAMSUNG__
1663static int add_use_network(const char *ifname)
1664{
1665 char buf[100];
1666
1667 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1668 wpa_command(ifname, buf);
1669 return 0;
1670}
1671#endif /* __SAMSUNG__ */
1672
1673
1674static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1675 const char *ifname, struct sigma_cmd *cmd)
1676{
1677 const char *ssid = get_param(cmd, "ssid");
1678 int id;
1679 const char *val;
1680
1681 if (ssid == NULL)
1682 return -1;
1683
1684 start_sta_mode(dut);
1685
1686#ifdef __SAMSUNG__
1687 add_use_network(ifname);
1688#endif /* __SAMSUNG__ */
1689
1690 id = add_network(ifname);
1691 if (id < 0)
1692 return -2;
1693 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1694
1695 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1696 return -2;
1697
1698 dut->infra_network_id = id;
1699 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1700
1701 val = get_param(cmd, "program");
1702 if (!val)
1703 val = get_param(cmd, "prog");
1704 if (val && strcasecmp(val, "hs2") == 0) {
1705 char buf[100];
1706 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1707 wpa_command(ifname, buf);
1708
1709 val = get_param(cmd, "prefer");
1710 if (val && atoi(val) > 0)
1711 set_network(ifname, id, "priority", "1");
1712 }
1713
1714 return id;
1715}
1716
1717
Jouni Malinenf7222712019-06-13 01:50:21 +03001718static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1719 struct sigma_conn *conn,
1720 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001721{
1722 const char *intf = get_param(cmd, "Interface");
1723 const char *ssid = get_param(cmd, "ssid");
1724 const char *type = get_param(cmd, "encpType");
1725 const char *ifname;
1726 char buf[200];
1727 int id;
1728
1729 if (intf == NULL || ssid == NULL)
1730 return -1;
1731
Jouni Malinen016ae6c2019-11-04 17:00:01 +02001732 if (strcmp(intf, get_main_ifname(dut)) == 0)
1733 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001734 else
1735 ifname = intf;
1736
1737 id = add_network_common(dut, conn, ifname, cmd);
1738 if (id < 0)
1739 return id;
1740
1741 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1742 return -2;
1743
1744 if (type && strcasecmp(type, "wep") == 0) {
1745 const char *val;
1746 int i;
1747
1748 val = get_param(cmd, "activeKey");
1749 if (val) {
1750 int keyid;
1751 keyid = atoi(val);
1752 if (keyid < 1 || keyid > 4)
1753 return -1;
1754 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1755 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1756 return -2;
1757 }
1758
1759 for (i = 0; i < 4; i++) {
1760 snprintf(buf, sizeof(buf), "key%d", i + 1);
1761 val = get_param(cmd, buf);
1762 if (val == NULL)
1763 continue;
1764 snprintf(buf, sizeof(buf), "wep_key%d", i);
1765 if (set_network(ifname, id, buf, val) < 0)
1766 return -2;
1767 }
1768 }
1769
1770 return 1;
1771}
1772
1773
Jouni Malinene4fde732019-03-25 22:29:37 +02001774static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1775 int id, const char *val)
1776{
1777 char key_mgmt[200], *end, *pos;
1778 const char *in_pos = val;
1779
Jouni Malinen8179fee2019-03-28 03:19:47 +02001780 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001781 pos = key_mgmt;
1782 end = pos + sizeof(key_mgmt);
1783 while (*in_pos) {
1784 int res, akm = atoi(in_pos);
1785 const char *str;
1786
Jouni Malinen8179fee2019-03-28 03:19:47 +02001787 if (akm >= 0 && akm < 32)
1788 dut->akm_values |= 1 << akm;
1789
Jouni Malinene4fde732019-03-25 22:29:37 +02001790 switch (akm) {
1791 case AKM_WPA_EAP:
1792 str = "WPA-EAP";
1793 break;
1794 case AKM_WPA_PSK:
1795 str = "WPA-PSK";
1796 break;
1797 case AKM_FT_EAP:
1798 str = "FT-EAP";
1799 break;
1800 case AKM_FT_PSK:
1801 str = "FT-PSK";
1802 break;
1803 case AKM_EAP_SHA256:
1804 str = "WPA-EAP-SHA256";
1805 break;
1806 case AKM_PSK_SHA256:
1807 str = "WPA-PSK-SHA256";
1808 break;
1809 case AKM_SAE:
1810 str = "SAE";
1811 break;
1812 case AKM_FT_SAE:
1813 str = "FT-SAE";
1814 break;
1815 case AKM_SUITE_B:
1816 str = "WPA-EAP-SUITE-B-192";
1817 break;
1818 case AKM_FT_SUITE_B:
1819 str = "FT-EAP-SHA384";
1820 break;
1821 case AKM_FILS_SHA256:
1822 str = "FILS-SHA256";
1823 break;
1824 case AKM_FILS_SHA384:
1825 str = "FILS-SHA384";
1826 break;
1827 case AKM_FT_FILS_SHA256:
1828 str = "FT-FILS-SHA256";
1829 break;
1830 case AKM_FT_FILS_SHA384:
1831 str = "FT-FILS-SHA384";
1832 break;
1833 default:
1834 sigma_dut_print(dut, DUT_MSG_ERROR,
1835 "Unsupported AKMSuitetype %d", akm);
1836 return -1;
1837 }
1838
1839 res = snprintf(pos, end - pos, "%s%s",
1840 pos == key_mgmt ? "" : " ", str);
1841 if (res < 0 || res >= end - pos)
1842 return -1;
1843 pos += res;
1844
1845 in_pos = strchr(in_pos, ';');
1846 if (!in_pos)
1847 break;
1848 while (*in_pos == ';')
1849 in_pos++;
1850 }
1851 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1852 val, key_mgmt);
1853 return set_network(ifname, id, "key_mgmt", key_mgmt);
1854}
1855
1856
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001857static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1858 const char *ifname, struct sigma_cmd *cmd)
1859{
1860 const char *val;
1861 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001862 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001863 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301864 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001865
1866 id = add_network_common(dut, conn, ifname, cmd);
1867 if (id < 0)
1868 return id;
1869
Jouni Malinen47dcc952017-10-09 16:43:24 +03001870 val = get_param(cmd, "Type");
1871 owe = val && strcasecmp(val, "OWE") == 0;
1872
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001873 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001874 if (!val && owe)
1875 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001876 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001877 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1878 * this missing parameter and assume proto=WPA2. */
1879 if (set_network(ifname, id, "proto", "WPA2") < 0)
1880 return ERROR_SEND_STATUS;
1881 } else if (strcasecmp(val, "wpa") == 0 ||
1882 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001883 if (set_network(ifname, id, "proto", "WPA") < 0)
1884 return -2;
1885 } else if (strcasecmp(val, "wpa2") == 0 ||
1886 strcasecmp(val, "wpa2-psk") == 0 ||
1887 strcasecmp(val, "wpa2-ft") == 0 ||
1888 strcasecmp(val, "wpa2-sha256") == 0) {
1889 if (set_network(ifname, id, "proto", "WPA2") < 0)
1890 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301891 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1892 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001893 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1894 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001895 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301896 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001897 if (set_network(ifname, id, "proto", "WPA2") < 0)
1898 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001899 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001900 } else {
1901 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1902 return 0;
1903 }
1904
1905 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001906 if (val) {
1907 cipher_set = 1;
1908 if (strcasecmp(val, "tkip") == 0) {
1909 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1910 return -2;
1911 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1912 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1913 return -2;
1914 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1915 if (set_network(ifname, id, "pairwise",
1916 "CCMP TKIP") < 0)
1917 return -2;
1918 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1919 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1920 return -2;
1921 if (set_network(ifname, id, "group", "GCMP") < 0)
1922 return -2;
1923 } else {
1924 send_resp(dut, conn, SIGMA_ERROR,
1925 "errorCode,Unrecognized encpType value");
1926 return 0;
1927 }
1928 }
1929
1930 val = get_param(cmd, "PairwiseCipher");
1931 if (val) {
1932 cipher_set = 1;
1933 /* TODO: Support space separated list */
1934 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1935 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1936 return -2;
1937 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1938 if (set_network(ifname, id, "pairwise",
1939 "CCMP-256") < 0)
1940 return -2;
1941 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1942 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1943 return -2;
1944 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1945 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1946 return -2;
1947 } else {
1948 send_resp(dut, conn, SIGMA_ERROR,
1949 "errorCode,Unrecognized PairwiseCipher value");
1950 return 0;
1951 }
1952 }
1953
Jouni Malinen47dcc952017-10-09 16:43:24 +03001954 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001955 send_resp(dut, conn, SIGMA_ERROR,
1956 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001957 return 0;
1958 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001959
1960 val = get_param(cmd, "GroupCipher");
1961 if (val) {
1962 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1963 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1964 return -2;
1965 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1966 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1967 return -2;
1968 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1969 if (set_network(ifname, id, "group", "GCMP") < 0)
1970 return -2;
1971 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1972 if (set_network(ifname, id, "group", "CCMP") < 0)
1973 return -2;
1974 } else {
1975 send_resp(dut, conn, SIGMA_ERROR,
1976 "errorCode,Unrecognized GroupCipher value");
1977 return 0;
1978 }
1979 }
1980
Jouni Malinen7b239522017-09-14 21:37:18 +03001981 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001982 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001983 const char *cipher;
1984
1985 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1986 cipher = "BIP-GMAC-256";
1987 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1988 cipher = "BIP-CMAC-256";
1989 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1990 cipher = "BIP-GMAC-128";
1991 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1992 cipher = "AES-128-CMAC";
1993 } else {
1994 send_resp(dut, conn, SIGMA_INVALID,
1995 "errorCode,Unsupported GroupMgntCipher");
1996 return 0;
1997 }
1998 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1999 send_resp(dut, conn, SIGMA_INVALID,
2000 "errorCode,Failed to set GroupMgntCipher");
2001 return 0;
2002 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002003 }
2004
Jouni Malinene4fde732019-03-25 22:29:37 +02002005 val = get_param(cmd, "AKMSuiteType");
2006 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2007 return ERROR_SEND_STATUS;
2008
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002009 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302010
2011 if (dut->program == PROGRAM_OCE) {
2012 dut->sta_pmf = STA_PMF_OPTIONAL;
2013 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2014 return -2;
2015 }
2016
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002017 val = get_param(cmd, "PMF");
2018 if (val) {
2019 if (strcasecmp(val, "Required") == 0 ||
2020 strcasecmp(val, "Forced_Required") == 0) {
2021 dut->sta_pmf = STA_PMF_REQUIRED;
2022 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2023 return -2;
2024 } else if (strcasecmp(val, "Optional") == 0) {
2025 dut->sta_pmf = STA_PMF_OPTIONAL;
2026 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2027 return -2;
2028 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002029 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002030 strcasecmp(val, "Forced_Disabled") == 0) {
2031 dut->sta_pmf = STA_PMF_DISABLED;
2032 } else {
2033 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2034 return 0;
2035 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302036 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002037 dut->sta_pmf = STA_PMF_REQUIRED;
2038 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2039 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002040 }
2041
2042 return id;
2043}
2044
2045
Jouni Malinenf7222712019-06-13 01:50:21 +03002046static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2047 struct sigma_conn *conn,
2048 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002049{
2050 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002051 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002052 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002053 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002054 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002055 const char *ifname, *val, *alg;
2056 int id;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002057 char buf[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002058
2059 if (intf == NULL)
2060 return -1;
2061
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002062 if (strcmp(intf, get_main_ifname(dut)) == 0)
2063 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002064 else
2065 ifname = intf;
2066
2067 id = set_wpa_common(dut, conn, ifname, cmd);
2068 if (id < 0)
2069 return id;
2070
2071 val = get_param(cmd, "keyMgmtType");
2072 alg = get_param(cmd, "micAlg");
2073
Jouni Malinen992a81e2017-08-22 13:57:47 +03002074 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002075 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002076 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2077 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002078 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002079 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2080 return -2;
2081 }
2082 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2083 sigma_dut_print(dut, DUT_MSG_ERROR,
2084 "Failed to clear sae_groups to default");
2085 return -2;
2086 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002087 if (!pmf) {
2088 dut->sta_pmf = STA_PMF_REQUIRED;
2089 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2090 return -2;
2091 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002092 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2093 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2094 if (set_network(ifname, id, "key_mgmt",
2095 "FT-SAE FT-PSK") < 0)
2096 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002097 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002098 if (set_network(ifname, id, "key_mgmt",
2099 "SAE WPA-PSK") < 0)
2100 return -2;
2101 }
2102 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2103 sigma_dut_print(dut, DUT_MSG_ERROR,
2104 "Failed to clear sae_groups to default");
2105 return -2;
2106 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002107 if (!pmf) {
2108 dut->sta_pmf = STA_PMF_OPTIONAL;
2109 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2110 return -2;
2111 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002112 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002113 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2114 return -2;
2115 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2116 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2117 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302118 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2119 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2120 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002121 } else if (!akm &&
2122 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2123 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002124 if (set_network(ifname, id, "key_mgmt",
2125 "WPA-PSK WPA-PSK-SHA256") < 0)
2126 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002127 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002128 if (set_network(ifname, id, "key_mgmt",
2129 "WPA-PSK WPA-PSK-SHA256") < 0)
2130 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002131 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002132 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2133 return -2;
2134 }
2135
2136 val = get_param(cmd, "passPhrase");
2137 if (val == NULL)
2138 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002139 if (type && strcasecmp(type, "SAE") == 0) {
2140 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2141 return -2;
2142 } else {
2143 if (set_network_quoted(ifname, id, "psk", val) < 0)
2144 return -2;
2145 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002146
Jouni Malinen78d10c42019-03-25 22:34:32 +02002147 val = get_param(cmd, "PasswordId");
2148 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2149 return ERROR_SEND_STATUS;
2150
Jouni Malinen992a81e2017-08-22 13:57:47 +03002151 val = get_param(cmd, "ECGroupID");
2152 if (val) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002153 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
2154 if (wpa_command(ifname, buf) != 0) {
2155 sigma_dut_print(dut, DUT_MSG_ERROR,
2156 "Failed to clear sae_groups");
2157 return -2;
2158 }
2159 }
2160
Jouni Malinen68143132017-09-02 02:34:08 +03002161 val = get_param(cmd, "InvalidSAEElement");
2162 if (val) {
2163 free(dut->sae_commit_override);
2164 dut->sae_commit_override = strdup(val);
2165 }
2166
Jouni Malinen4b3769d2019-10-10 16:20:29 +03002167 val = get_param(cmd, "PMKID_Include");
2168 if (val) {
2169 snprintf(buf, sizeof(buf), "SET sae_pmkid_in_assoc %d",
2170 get_enable_disable(val));
2171 wpa_command(intf, buf);
2172 }
2173
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002174 if (dut->program == PROGRAM_60GHZ && network_mode &&
2175 strcasecmp(network_mode, "PBSS") == 0 &&
2176 set_network(ifname, id, "pbss", "1") < 0)
2177 return -2;
2178
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002179 return 1;
2180}
2181
2182
Jouni Malinen8ac93452019-08-14 15:19:13 +03002183static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2184 struct sigma_conn *conn,
2185 const char *ifname, int id)
2186{
2187 char buf[200];
2188
2189 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2190 if (!file_exists(buf))
2191 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2192 if (!file_exists(buf))
2193 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2194 if (!file_exists(buf)) {
2195 char msg[300];
2196
2197 snprintf(msg, sizeof(msg),
2198 "ErrorCode,trustedRootCA system store (%s) not found",
2199 buf);
2200 send_resp(dut, conn, SIGMA_ERROR, msg);
2201 return STATUS_SENT_ERROR;
2202 }
2203
2204 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2205 return ERROR_SEND_STATUS;
2206
2207 return SUCCESS_SEND_STATUS;
2208}
2209
2210
2211static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2212 struct sigma_conn *conn,
2213 const char *ifname, int id,
2214 const char *val)
2215{
2216 char buf[200];
2217#ifdef ANDROID
2218 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2219 int length;
2220#endif /* ANDROID */
2221
2222 if (strcmp(val, "DEFAULT") == 0)
2223 return set_trust_root_system(dut, conn, ifname, id);
2224
2225#ifdef ANDROID
2226 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2227 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2228 if (length > 0) {
2229 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2230 buf);
2231 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2232 goto ca_cert_selected;
2233 }
2234#endif /* ANDROID */
2235
2236 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2237#ifdef __linux__
2238 if (!file_exists(buf)) {
2239 char msg[300];
2240
2241 snprintf(msg, sizeof(msg),
2242 "ErrorCode,trustedRootCA file (%s) not found", buf);
2243 send_resp(dut, conn, SIGMA_ERROR, msg);
2244 return STATUS_SENT_ERROR;
2245 }
2246#endif /* __linux__ */
2247#ifdef ANDROID
2248ca_cert_selected:
2249#endif /* ANDROID */
2250 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2251 return ERROR_SEND_STATUS;
2252
2253 return SUCCESS_SEND_STATUS;
2254}
2255
2256
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002257static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302258 const char *ifname, int username_identity,
2259 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002260{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002261 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002262 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002263 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002264 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002265 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002266
2267 id = set_wpa_common(dut, conn, ifname, cmd);
2268 if (id < 0)
2269 return id;
2270
2271 val = get_param(cmd, "keyMgmtType");
2272 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302273 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002274 trust_root = get_param(cmd, "trustedRootCA");
2275 domain = get_param(cmd, "Domain");
2276 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002277
Jouni Malinenad395a22017-09-01 21:13:46 +03002278 if (val && strcasecmp(val, "SuiteB") == 0) {
2279 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2280 0)
2281 return -2;
2282 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002283 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2284 return -2;
2285 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2286 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2287 return -2;
2288 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2289 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2290 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002291 } else if (!akm &&
2292 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2293 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002294 if (set_network(ifname, id, "key_mgmt",
2295 "WPA-EAP WPA-EAP-SHA256") < 0)
2296 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302297 } else if (akm && atoi(akm) == 14) {
2298 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2299 dut->sta_pmf == STA_PMF_REQUIRED) {
2300 if (set_network(ifname, id, "key_mgmt",
2301 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2302 return -2;
2303 } else {
2304 if (set_network(ifname, id, "key_mgmt",
2305 "WPA-EAP FILS-SHA256") < 0)
2306 return -2;
2307 }
2308
Jouni Malinen8179fee2019-03-28 03:19:47 +02002309 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302310 } else if (akm && atoi(akm) == 15) {
2311 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2312 dut->sta_pmf == STA_PMF_REQUIRED) {
2313 if (set_network(ifname, id, "key_mgmt",
2314 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2315 return -2;
2316 } else {
2317 if (set_network(ifname, id, "key_mgmt",
2318 "WPA-EAP FILS-SHA384") < 0)
2319 return -2;
2320 }
2321
Jouni Malinen8179fee2019-03-28 03:19:47 +02002322 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002323 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002324 if (set_network(ifname, id, "key_mgmt",
2325 "WPA-EAP WPA-EAP-SHA256") < 0)
2326 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002327 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002328 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2329 return -2;
2330 }
2331
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002332 if (trust_root) {
2333 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2334 !domain_suffix) {
2335 send_resp(dut, conn, SIGMA_ERROR,
2336 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2337 return STATUS_SENT_ERROR;
2338 }
2339 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002340 if (res != SUCCESS_SEND_STATUS)
2341 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002342 }
2343
Jouni Malinen53264f62019-05-03 13:04:40 +03002344 val = get_param(cmd, "ServerCert");
2345 if (val) {
2346 FILE *f;
2347 char *result = NULL, *pos;
2348
2349 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2350 val);
2351 f = fopen(buf, "r");
2352 if (f) {
2353 result = fgets(buf, sizeof(buf), f);
2354 fclose(f);
2355 }
2356 if (!result) {
2357 snprintf(buf2, sizeof(buf2),
2358 "ErrorCode,ServerCert hash could not be read from %s",
2359 buf);
2360 send_resp(dut, conn, SIGMA_ERROR, buf2);
2361 return STATUS_SENT_ERROR;
2362 }
2363 pos = strchr(buf, '\n');
2364 if (pos)
2365 *pos = '\0';
2366 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2367 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2368 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002369
2370 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2371 if (file_exists(buf)) {
2372 sigma_dut_print(dut, DUT_MSG_DEBUG,
2373 "TOD policy enabled for the configured ServerCert hash");
2374 dut->sta_tod_policy = 1;
2375 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002376 }
2377
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002378 if (domain &&
2379 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002380 return ERROR_SEND_STATUS;
2381
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002382 if (domain_suffix &&
2383 set_network_quoted(ifname, id, "domain_suffix_match",
2384 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002385 return ERROR_SEND_STATUS;
2386
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302387 if (username_identity) {
2388 val = get_param(cmd, "username");
2389 if (val) {
2390 if (set_network_quoted(ifname, id, "identity", val) < 0)
2391 return -2;
2392 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002393
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302394 val = get_param(cmd, "password");
2395 if (val) {
2396 if (set_network_quoted(ifname, id, "password", val) < 0)
2397 return -2;
2398 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002399 }
2400
Jouni Malinen8179fee2019-03-28 03:19:47 +02002401 if (dut->akm_values &
2402 ((1 << AKM_FILS_SHA256) |
2403 (1 << AKM_FILS_SHA384) |
2404 (1 << AKM_FT_FILS_SHA256) |
2405 (1 << AKM_FT_FILS_SHA384)))
2406 erp = 1;
2407 if (erp && set_network(ifname, id, "erp", "1") < 0)
2408 return ERROR_SEND_STATUS;
2409
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002410 dut->sta_associate_wait_connect = 1;
2411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002412 return id;
2413}
2414
2415
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002416static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2417{
2418 const char *val;
2419
2420 if (!cipher)
2421 return 0;
2422
2423 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2424 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2425 else if (strcasecmp(cipher,
2426 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2427 val = "ECDHE-RSA-AES256-GCM-SHA384";
2428 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2429 val = "DHE-RSA-AES256-GCM-SHA384";
2430 else if (strcasecmp(cipher,
2431 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2432 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2433 else
2434 return -1;
2435
2436 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2437 set_network_quoted(ifname, id, "phase1", "");
2438
2439 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2440}
2441
2442
Jouni Malinenf7222712019-06-13 01:50:21 +03002443static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2444 struct sigma_conn *conn,
2445 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002446{
2447 const char *intf = get_param(cmd, "Interface");
2448 const char *ifname, *val;
2449 int id;
2450 char buf[200];
2451#ifdef ANDROID
2452 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2453 int length;
2454 int jb_or_newer = 0;
2455 char prop[PROPERTY_VALUE_MAX];
2456#endif /* ANDROID */
2457
2458 if (intf == NULL)
2459 return -1;
2460
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002461 if (strcmp(intf, get_main_ifname(dut)) == 0)
2462 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002463 else
2464 ifname = intf;
2465
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302466 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002467 if (id < 0)
2468 return id;
2469
2470 if (set_network(ifname, id, "eap", "TLS") < 0)
2471 return -2;
2472
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302473 if (!get_param(cmd, "username") &&
2474 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002475 "wifi-user@wifilabs.local") < 0)
2476 return -2;
2477
2478 val = get_param(cmd, "clientCertificate");
2479 if (val == NULL)
2480 return -1;
2481#ifdef ANDROID
2482 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2483 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2484 if (length < 0) {
2485 /*
2486 * JB started reporting keystore type mismatches, so retry with
2487 * the GET_PUBKEY command if the generic GET fails.
2488 */
2489 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2490 buf, kvalue);
2491 }
2492
2493 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2494 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2495 if (strncmp(prop, "4.0", 3) != 0)
2496 jb_or_newer = 1;
2497 } else
2498 jb_or_newer = 1; /* assume newer */
2499
2500 if (jb_or_newer && length > 0) {
2501 sigma_dut_print(dut, DUT_MSG_INFO,
2502 "Use Android keystore [%s]", buf);
2503 if (set_network(ifname, id, "engine", "1") < 0)
2504 return -2;
2505 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2506 return -2;
2507 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2508 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2509 return -2;
2510 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2511 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2512 return -2;
2513 return 1;
2514 } else if (length > 0) {
2515 sigma_dut_print(dut, DUT_MSG_INFO,
2516 "Use Android keystore [%s]", buf);
2517 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2518 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2519 return -2;
2520 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2521 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2522 return -2;
2523 return 1;
2524 }
2525#endif /* ANDROID */
2526
2527 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2528#ifdef __linux__
2529 if (!file_exists(buf)) {
2530 char msg[300];
2531 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2532 "(%s) not found", buf);
2533 send_resp(dut, conn, SIGMA_ERROR, msg);
2534 return -3;
2535 }
2536#endif /* __linux__ */
2537 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2538 return -2;
2539 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2540 return -2;
2541
2542 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2543 return -2;
2544
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002545 val = get_param(cmd, "keyMgmtType");
2546 if (val && strcasecmp(val, "SuiteB") == 0) {
2547 val = get_param(cmd, "CertType");
2548 if (val && strcasecmp(val, "RSA") == 0) {
2549 if (set_network_quoted(ifname, id, "phase1",
2550 "tls_suiteb=1") < 0)
2551 return -2;
2552 } else {
2553 if (set_network_quoted(ifname, id, "openssl_ciphers",
2554 "SUITEB192") < 0)
2555 return -2;
2556 }
2557
2558 val = get_param(cmd, "TLSCipher");
2559 if (set_tls_cipher(ifname, id, val) < 0) {
2560 send_resp(dut, conn, SIGMA_ERROR,
2561 "ErrorCode,Unsupported TLSCipher value");
2562 return -3;
2563 }
2564 }
2565
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002566 return 1;
2567}
2568
2569
Jouni Malinenf7222712019-06-13 01:50:21 +03002570static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2571 struct sigma_conn *conn,
2572 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002573{
2574 const char *intf = get_param(cmd, "Interface");
2575 const char *ifname;
2576 int id;
2577
2578 if (intf == NULL)
2579 return -1;
2580
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002581 if (strcmp(intf, get_main_ifname(dut)) == 0)
2582 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002583 else
2584 ifname = intf;
2585
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302586 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002587 if (id < 0)
2588 return id;
2589
2590 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2591 send_resp(dut, conn, SIGMA_ERROR,
2592 "errorCode,Failed to set TTLS method");
2593 return 0;
2594 }
2595
2596 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2597 send_resp(dut, conn, SIGMA_ERROR,
2598 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2599 return 0;
2600 }
2601
2602 return 1;
2603}
2604
2605
Jouni Malinenf7222712019-06-13 01:50:21 +03002606static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2607 struct sigma_conn *conn,
2608 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002609{
2610 const char *intf = get_param(cmd, "Interface");
2611 const char *ifname;
2612 int id;
2613
2614 if (intf == NULL)
2615 return -1;
2616
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002617 if (strcmp(intf, get_main_ifname(dut)) == 0)
2618 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002619 else
2620 ifname = intf;
2621
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302622 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002623 if (id < 0)
2624 return id;
2625
2626 if (set_network(ifname, id, "eap", "SIM") < 0)
2627 return -2;
2628
2629 return 1;
2630}
2631
2632
Jouni Malinenf7222712019-06-13 01:50:21 +03002633static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2634 struct sigma_conn *conn,
2635 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002636{
2637 const char *intf = get_param(cmd, "Interface");
2638 const char *ifname, *val;
2639 int id;
2640 char buf[100];
2641
2642 if (intf == NULL)
2643 return -1;
2644
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002645 if (strcmp(intf, get_main_ifname(dut)) == 0)
2646 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002647 else
2648 ifname = intf;
2649
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302650 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002651 if (id < 0)
2652 return id;
2653
2654 if (set_network(ifname, id, "eap", "PEAP") < 0)
2655 return -2;
2656
2657 val = get_param(cmd, "innerEAP");
2658 if (val) {
2659 if (strcasecmp(val, "MSCHAPv2") == 0) {
2660 if (set_network_quoted(ifname, id, "phase2",
2661 "auth=MSCHAPV2") < 0)
2662 return -2;
2663 } else if (strcasecmp(val, "GTC") == 0) {
2664 if (set_network_quoted(ifname, id, "phase2",
2665 "auth=GTC") < 0)
2666 return -2;
2667 } else
2668 return -1;
2669 }
2670
2671 val = get_param(cmd, "peapVersion");
2672 if (val) {
2673 int ver = atoi(val);
2674 if (ver < 0 || ver > 1)
2675 return -1;
2676 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2677 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2678 return -2;
2679 }
2680
2681 return 1;
2682}
2683
2684
Jouni Malinenf7222712019-06-13 01:50:21 +03002685static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2686 struct sigma_conn *conn,
2687 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002688{
2689 const char *intf = get_param(cmd, "Interface");
2690 const char *ifname, *val;
2691 int id;
2692 char buf[100];
2693
2694 if (intf == NULL)
2695 return -1;
2696
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002697 if (strcmp(intf, get_main_ifname(dut)) == 0)
2698 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002699 else
2700 ifname = intf;
2701
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302702 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002703 if (id < 0)
2704 return id;
2705
2706 if (set_network(ifname, id, "eap", "FAST") < 0)
2707 return -2;
2708
2709 val = get_param(cmd, "innerEAP");
2710 if (val) {
2711 if (strcasecmp(val, "MSCHAPV2") == 0) {
2712 if (set_network_quoted(ifname, id, "phase2",
2713 "auth=MSCHAPV2") < 0)
2714 return -2;
2715 } else if (strcasecmp(val, "GTC") == 0) {
2716 if (set_network_quoted(ifname, id, "phase2",
2717 "auth=GTC") < 0)
2718 return -2;
2719 } else
2720 return -1;
2721 }
2722
2723 val = get_param(cmd, "validateServer");
2724 if (val) {
2725 /* TODO */
2726 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2727 "validateServer=%s", val);
2728 }
2729
2730 val = get_param(cmd, "pacFile");
2731 if (val) {
2732 snprintf(buf, sizeof(buf), "blob://%s", val);
2733 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2734 return -2;
2735 }
2736
2737 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2738 0)
2739 return -2;
2740
2741 return 1;
2742}
2743
2744
Jouni Malinenf7222712019-06-13 01:50:21 +03002745static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2746 struct sigma_conn *conn,
2747 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002748{
2749 const char *intf = get_param(cmd, "Interface");
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302750 const char *username = get_param(cmd, "Username");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002751 const char *ifname;
2752 int id;
2753
2754 if (intf == NULL)
2755 return -1;
2756
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002757 if (strcmp(intf, get_main_ifname(dut)) == 0)
2758 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002759 else
2760 ifname = intf;
2761
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302762 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002763 if (id < 0)
2764 return id;
2765
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302766 /* RFC 5448: EAP-AKA' MUST use the leading character "6" (ASCII 36
2767 * hexadecimal).
2768 */
2769 if (username && username[0] == '6') {
2770 if (set_network(ifname, id, "eap", "AKA'") < 0)
2771 return -2;
2772 } else if (set_network(ifname, id, "eap", "AKA") < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002773 return -2;
Purushottam Kushwahacdd8cb12019-10-04 11:33:59 +05302774 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002775
2776 return 1;
2777}
2778
2779
Jouni Malinenf7222712019-06-13 01:50:21 +03002780static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2781 struct sigma_conn *conn,
2782 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002783{
2784 const char *intf = get_param(cmd, "Interface");
2785 const char *ifname;
2786 int id;
2787
2788 if (intf == NULL)
2789 return -1;
2790
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002791 if (strcmp(intf, get_main_ifname(dut)) == 0)
2792 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002793 else
2794 ifname = intf;
2795
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302796 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797 if (id < 0)
2798 return id;
2799
2800 if (set_network(ifname, id, "eap", "AKA'") < 0)
2801 return -2;
2802
2803 return 1;
2804}
2805
2806
2807static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2808 struct sigma_cmd *cmd)
2809{
2810 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002811 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002812 const char *ifname;
2813 int id;
2814
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002815 if (strcmp(intf, get_main_ifname(dut)) == 0)
2816 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002817 else
2818 ifname = intf;
2819
2820 id = add_network_common(dut, conn, ifname, cmd);
2821 if (id < 0)
2822 return id;
2823
2824 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2825 return -2;
2826
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002827 if (dut->program == PROGRAM_60GHZ && network_mode &&
2828 strcasecmp(network_mode, "PBSS") == 0 &&
2829 set_network(ifname, id, "pbss", "1") < 0)
2830 return -2;
2831
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002832 return 1;
2833}
2834
2835
Jouni Malinen47dcc952017-10-09 16:43:24 +03002836static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2837 struct sigma_cmd *cmd)
2838{
2839 const char *intf = get_param(cmd, "Interface");
2840 const char *ifname, *val;
2841 int id;
2842
2843 if (intf == NULL)
2844 return -1;
2845
Jouni Malinen016ae6c2019-11-04 17:00:01 +02002846 if (strcmp(intf, get_main_ifname(dut)) == 0)
2847 ifname = get_station_ifname(dut);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002848 else
2849 ifname = intf;
2850
2851 id = set_wpa_common(dut, conn, ifname, cmd);
2852 if (id < 0)
2853 return id;
2854
2855 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2856 return -2;
2857
2858 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002859 if (val && strcmp(val, "0") == 0) {
2860 if (wpa_command(ifname,
2861 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2862 sigma_dut_print(dut, DUT_MSG_ERROR,
2863 "Failed to set OWE DH Param element override");
2864 return -2;
2865 }
2866 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002867 sigma_dut_print(dut, DUT_MSG_ERROR,
2868 "Failed to clear owe_group");
2869 return -2;
2870 }
2871
2872 return 1;
2873}
2874
2875
Jouni Malinenf7222712019-06-13 01:50:21 +03002876static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
2877 struct sigma_conn *conn,
2878 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002879{
2880 const char *type = get_param(cmd, "Type");
2881
2882 if (type == NULL) {
2883 send_resp(dut, conn, SIGMA_ERROR,
2884 "ErrorCode,Missing Type argument");
2885 return 0;
2886 }
2887
2888 if (strcasecmp(type, "OPEN") == 0)
2889 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002890 if (strcasecmp(type, "OWE") == 0)
2891 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002892 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002893 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002894 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002895 return cmd_sta_set_psk(dut, conn, cmd);
2896 if (strcasecmp(type, "EAPTLS") == 0)
2897 return cmd_sta_set_eaptls(dut, conn, cmd);
2898 if (strcasecmp(type, "EAPTTLS") == 0)
2899 return cmd_sta_set_eapttls(dut, conn, cmd);
2900 if (strcasecmp(type, "EAPPEAP") == 0)
2901 return cmd_sta_set_peap(dut, conn, cmd);
2902 if (strcasecmp(type, "EAPSIM") == 0)
2903 return cmd_sta_set_eapsim(dut, conn, cmd);
2904 if (strcasecmp(type, "EAPFAST") == 0)
2905 return cmd_sta_set_eapfast(dut, conn, cmd);
2906 if (strcasecmp(type, "EAPAKA") == 0)
2907 return cmd_sta_set_eapaka(dut, conn, cmd);
2908 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2909 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002910 if (strcasecmp(type, "wep") == 0)
2911 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002912
2913 send_resp(dut, conn, SIGMA_ERROR,
2914 "ErrorCode,Unsupported Type value");
2915 return 0;
2916}
2917
2918
2919int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2920{
2921#ifdef __linux__
2922 /* special handling for ath6kl */
2923 char path[128], fname[128], *pos;
2924 ssize_t res;
2925 FILE *f;
2926
Jouni Malinene39cd562019-05-29 23:39:56 +03002927 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
2928 intf);
2929 if (res < 0 || res >= sizeof(fname))
2930 return 0;
2931 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002932 if (res < 0)
2933 return 0; /* not ath6kl */
2934
2935 if (res >= (int) sizeof(path))
2936 res = sizeof(path) - 1;
2937 path[res] = '\0';
2938 pos = strrchr(path, '/');
2939 if (pos == NULL)
2940 pos = path;
2941 else
2942 pos++;
2943 snprintf(fname, sizeof(fname),
2944 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2945 "create_qos", pos);
2946 if (!file_exists(fname))
2947 return 0; /* not ath6kl */
2948
2949 if (uapsd) {
2950 f = fopen(fname, "w");
2951 if (f == NULL)
2952 return -1;
2953
2954 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2955 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2956 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2957 "20000 0\n");
2958 fclose(f);
2959 } else {
2960 snprintf(fname, sizeof(fname),
2961 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2962 "delete_qos", pos);
2963
2964 f = fopen(fname, "w");
2965 if (f == NULL)
2966 return -1;
2967
2968 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2969 fprintf(f, "2 4\n");
2970 fclose(f);
2971 }
2972#endif /* __linux__ */
2973
2974 return 0;
2975}
2976
2977
Jouni Malinenf7222712019-06-13 01:50:21 +03002978static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
2979 struct sigma_conn *conn,
2980 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002981{
2982 const char *intf = get_param(cmd, "Interface");
2983 /* const char *ssid = get_param(cmd, "ssid"); */
2984 const char *val;
2985 int max_sp_len = 4;
2986 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2987 char buf[100];
2988 int ret1, ret2;
2989
2990 val = get_param(cmd, "maxSPLength");
2991 if (val) {
2992 max_sp_len = atoi(val);
2993 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2994 max_sp_len != 4)
2995 return -1;
2996 }
2997
2998 val = get_param(cmd, "acBE");
2999 if (val)
3000 ac_be = atoi(val);
3001
3002 val = get_param(cmd, "acBK");
3003 if (val)
3004 ac_bk = atoi(val);
3005
3006 val = get_param(cmd, "acVI");
3007 if (val)
3008 ac_vi = atoi(val);
3009
3010 val = get_param(cmd, "acVO");
3011 if (val)
3012 ac_vo = atoi(val);
3013
3014 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
3015
3016 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3017 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3018 ret1 = wpa_command(intf, buf);
3019
3020 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3021 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3022 ret2 = wpa_command(intf, buf);
3023
3024 if (ret1 && ret2) {
3025 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3026 "UAPSD parameters.");
3027 return -2;
3028 }
3029
3030 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3031 send_resp(dut, conn, SIGMA_ERROR,
3032 "ErrorCode,Failed to set ath6kl QoS parameters");
3033 return 0;
3034 }
3035
3036 return 1;
3037}
3038
3039
Jouni Malinenf7222712019-06-13 01:50:21 +03003040static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3041 struct sigma_conn *conn,
3042 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003043{
3044 char buf[1000];
3045 const char *intf = get_param(cmd, "Interface");
3046 const char *grp = get_param(cmd, "Group");
3047 const char *act = get_param(cmd, "Action");
3048 const char *tid = get_param(cmd, "Tid");
3049 const char *dir = get_param(cmd, "Direction");
3050 const char *psb = get_param(cmd, "Psb");
3051 const char *up = get_param(cmd, "Up");
3052 const char *fixed = get_param(cmd, "Fixed");
3053 const char *size = get_param(cmd, "Size");
3054 const char *msize = get_param(cmd, "Maxsize");
3055 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3056 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3057 const char *inact = get_param(cmd, "Inactivity");
3058 const char *sus = get_param(cmd, "Suspension");
3059 const char *mindr = get_param(cmd, "Mindatarate");
3060 const char *meandr = get_param(cmd, "Meandatarate");
3061 const char *peakdr = get_param(cmd, "Peakdatarate");
3062 const char *phyrate = get_param(cmd, "Phyrate");
3063 const char *burstsize = get_param(cmd, "Burstsize");
3064 const char *sba = get_param(cmd, "Sba");
3065 int direction;
3066 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003067 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003068 int fixed_int;
3069 int psb_ts;
3070
3071 if (intf == NULL || grp == NULL || act == NULL )
3072 return -1;
3073
3074 if (strcasecmp(act, "addts") == 0) {
3075 if (tid == NULL || dir == NULL || psb == NULL ||
3076 up == NULL || fixed == NULL || size == NULL)
3077 return -1;
3078
3079 /*
3080 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3081 * possible values, but WMM-AC and V-E test scripts use "UP,
3082 * "DOWN", and "BIDI".
3083 */
3084 if (strcasecmp(dir, "uplink") == 0 ||
3085 strcasecmp(dir, "up") == 0) {
3086 direction = 0;
3087 } else if (strcasecmp(dir, "downlink") == 0 ||
3088 strcasecmp(dir, "down") == 0) {
3089 direction = 1;
3090 } else if (strcasecmp(dir, "bidi") == 0) {
3091 direction = 2;
3092 } else {
3093 sigma_dut_print(dut, DUT_MSG_ERROR,
3094 "Direction %s not supported", dir);
3095 return -1;
3096 }
3097
3098 if (strcasecmp(psb, "legacy") == 0) {
3099 psb_ts = 0;
3100 } else if (strcasecmp(psb, "uapsd") == 0) {
3101 psb_ts = 1;
3102 } else {
3103 sigma_dut_print(dut, DUT_MSG_ERROR,
3104 "PSB %s not supported", psb);
3105 return -1;
3106 }
3107
3108 if (atoi(tid) < 0 || atoi(tid) > 7) {
3109 sigma_dut_print(dut, DUT_MSG_ERROR,
3110 "TID %s not supported", tid);
3111 return -1;
3112 }
3113
3114 if (strcasecmp(fixed, "true") == 0) {
3115 fixed_int = 1;
3116 } else {
3117 fixed_int = 0;
3118 }
3119
Peng Xu93319622017-10-04 17:58:16 -07003120 if (sba)
3121 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003122
3123 dut->dialog_token++;
3124 handle = 7000 + dut->dialog_token;
3125
3126 /*
3127 * size: convert to hex
3128 * maxsi: convert to hex
3129 * mindr: convert to hex
3130 * meandr: convert to hex
3131 * peakdr: convert to hex
3132 * burstsize: convert to hex
3133 * phyrate: convert to hex
3134 * sba: convert to hex with modification
3135 * minsi: convert to integer
3136 * sus: convert to integer
3137 * inact: convert to integer
3138 * maxsi: convert to integer
3139 */
3140
3141 /*
3142 * The Nominal MSDU Size field is 2 octets long and contains an
3143 * unsigned integer that specifies the nominal size, in octets,
3144 * of MSDUs belonging to the traffic under this traffic
3145 * specification and is defined in Figure 16. If the Fixed
3146 * subfield is set to 1, then the size of the MSDU is fixed and
3147 * is indicated by the Size Subfield. If the Fixed subfield is
3148 * set to 0, then the size of the MSDU might not be fixed and
3149 * the Size indicates the nominal MSDU size.
3150 *
3151 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3152 * and specifies the excess allocation of time (and bandwidth)
3153 * over and above the stated rates required to transport an MSDU
3154 * belonging to the traffic in this TSPEC. This field is
3155 * represented as an unsigned binary number with an implicit
3156 * binary point after the leftmost 3 bits. For example, an SBA
3157 * of 1.75 is represented as 0x3800. This field is included to
3158 * account for retransmissions. As such, the value of this field
3159 * must be greater than unity.
3160 */
3161
3162 snprintf(buf, sizeof(buf),
3163 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3164 " 0x%X 0x%X 0x%X"
3165 " 0x%X 0x%X 0x%X"
3166 " 0x%X %d %d %d %d"
3167 " %d %d",
3168 intf, handle, tid, direction, psb_ts, up,
3169 (unsigned int) ((fixed_int << 15) | atoi(size)),
3170 msize ? atoi(msize) : 0,
3171 mindr ? atoi(mindr) : 0,
3172 meandr ? atoi(meandr) : 0,
3173 peakdr ? atoi(peakdr) : 0,
3174 burstsize ? atoi(burstsize) : 0,
3175 phyrate ? atoi(phyrate) : 0,
3176 sba ? ((unsigned int) (((int) sba_fv << 13) |
3177 (int)((sba_fv - (int) sba_fv) *
3178 8192))) : 0,
3179 minsi ? atoi(minsi) : 0,
3180 sus ? atoi(sus) : 0,
3181 0, 0,
3182 inact ? atoi(inact) : 0,
3183 maxsi ? atoi(maxsi) : 0);
3184
3185 if (system(buf) != 0) {
3186 sigma_dut_print(dut, DUT_MSG_ERROR,
3187 "iwpriv addtspec request failed");
3188 send_resp(dut, conn, SIGMA_ERROR,
3189 "errorCode,Failed to execute addTspec command");
3190 return 0;
3191 }
3192
3193 sigma_dut_print(dut, DUT_MSG_INFO,
3194 "iwpriv addtspec request send");
3195
3196 /* Mapping handle to a TID */
3197 dut->tid_to_handle[atoi(tid)] = handle;
3198 } else if (strcasecmp(act, "delts") == 0) {
3199 if (tid == NULL)
3200 return -1;
3201
3202 if (atoi(tid) < 0 || atoi(tid) > 7) {
3203 sigma_dut_print(dut, DUT_MSG_ERROR,
3204 "TID %s not supported", tid);
3205 send_resp(dut, conn, SIGMA_ERROR,
3206 "errorCode,Unsupported TID");
3207 return 0;
3208 }
3209
3210 handle = dut->tid_to_handle[atoi(tid)];
3211
3212 if (handle < 7000 || handle > 7255) {
3213 /* Invalid handle ie no mapping for that TID */
3214 sigma_dut_print(dut, DUT_MSG_ERROR,
3215 "handle-> %d not found", handle);
3216 }
3217
3218 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3219 intf, handle);
3220
3221 if (system(buf) != 0) {
3222 sigma_dut_print(dut, DUT_MSG_ERROR,
3223 "iwpriv deltspec request failed");
3224 send_resp(dut, conn, SIGMA_ERROR,
3225 "errorCode,Failed to execute delTspec command");
3226 return 0;
3227 }
3228
3229 sigma_dut_print(dut, DUT_MSG_INFO,
3230 "iwpriv deltspec request send");
3231
3232 dut->tid_to_handle[atoi(tid)] = 0;
3233 } else {
3234 sigma_dut_print(dut, DUT_MSG_ERROR,
3235 "Action type %s not supported", act);
3236 send_resp(dut, conn, SIGMA_ERROR,
3237 "errorCode,Unsupported Action");
3238 return 0;
3239 }
3240
3241 return 1;
3242}
3243
3244
vamsi krishna52e16f92017-08-29 12:37:34 +05303245static int find_network(struct sigma_dut *dut, const char *ssid)
3246{
3247 char list[4096];
3248 char *pos;
3249
3250 sigma_dut_print(dut, DUT_MSG_DEBUG,
3251 "Search for profile based on SSID: '%s'", ssid);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003252 if (wpa_command_resp(get_station_ifname(dut), "LIST_NETWORKS",
vamsi krishna52e16f92017-08-29 12:37:34 +05303253 list, sizeof(list)) < 0)
3254 return -1;
3255 pos = strstr(list, ssid);
3256 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3257 return -1;
3258
3259 while (pos > list && pos[-1] != '\n')
3260 pos--;
3261 dut->infra_network_id = atoi(pos);
3262 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3263 return 0;
3264}
3265
3266
Sunil Dutt44595082018-02-12 19:41:45 +05303267#ifdef NL80211_SUPPORT
3268static int sta_config_rsnie(struct sigma_dut *dut, int val)
3269{
3270 struct nl_msg *msg;
3271 int ret;
3272 struct nlattr *params;
3273 int ifindex;
3274
3275 ifindex = if_nametoindex("wlan0");
3276 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3277 NL80211_CMD_VENDOR)) ||
3278 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3279 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3280 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3281 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3282 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3283 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3284 sigma_dut_print(dut, DUT_MSG_ERROR,
3285 "%s: err in adding vendor_cmd and vendor_data",
3286 __func__);
3287 nlmsg_free(msg);
3288 return -1;
3289 }
3290 nla_nest_end(msg, params);
3291
3292 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3293 if (ret) {
3294 sigma_dut_print(dut, DUT_MSG_ERROR,
3295 "%s: err in send_and_recv_msgs, ret=%d",
3296 __func__, ret);
3297 return ret;
3298 }
3299
3300 return 0;
3301}
3302#endif /* NL80211_SUPPORT */
3303
3304
Jouni Malinenf7222712019-06-13 01:50:21 +03003305static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3306 struct sigma_conn *conn,
3307 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003308{
3309 /* const char *intf = get_param(cmd, "Interface"); */
3310 const char *ssid = get_param(cmd, "ssid");
3311 const char *wps_param = get_param(cmd, "WPS");
3312 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003313 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003314 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003315 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003316 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003317 int e;
3318 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3319 struct wpa_ctrl *ctrl = NULL;
3320 int num_network_not_found = 0;
3321 int num_disconnected = 0;
3322 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003323
3324 if (ssid == NULL)
3325 return -1;
3326
Jouni Malinen37d5c692019-08-19 16:56:55 +03003327 dut->server_cert_tod = 0;
3328
Jouni Malinen3c367e82017-06-23 17:01:47 +03003329 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303330#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003331 if (get_driver_type(dut) == DRIVER_WCN) {
Sunil Dutt44595082018-02-12 19:41:45 +05303332 sta_config_rsnie(dut, 1);
3333 dut->config_rsnie = 1;
3334 }
3335#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003336 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3337 dut->rsne_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003338 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen3c367e82017-06-23 17:01:47 +03003339 send_resp(dut, conn, SIGMA_ERROR,
3340 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3341 return 0;
3342 }
3343 }
3344
Jouni Malinen68143132017-09-02 02:34:08 +03003345 if (dut->sae_commit_override) {
3346 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3347 dut->sae_commit_override);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003348 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinen68143132017-09-02 02:34:08 +03003349 send_resp(dut, conn, SIGMA_ERROR,
3350 "ErrorCode,Failed to set SAE commit override");
3351 return 0;
3352 }
3353 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303354#ifdef ANDROID
3355 if (dut->fils_hlp)
3356 process_fils_hlp(dut);
3357#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003358
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003359 if (wps_param &&
3360 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3361 wps = 1;
3362
3363 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003364 if (dut->program == PROGRAM_60GHZ && network_mode &&
3365 strcasecmp(network_mode, "PBSS") == 0 &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003366 set_network(get_station_ifname(dut), dut->infra_network_id,
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003367 "pbss", "1") < 0)
3368 return -2;
3369
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003370 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3371 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3372 "parameters not yet set");
3373 return 0;
3374 }
3375 if (dut->wps_method == WFA_CS_WPS_PBC) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003376 if (wpa_command(get_station_ifname(dut), "WPS_PBC") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003377 return -2;
3378 } else {
3379 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3380 dut->wps_pin);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003381 if (wpa_command(get_station_ifname(dut), buf) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003382 return -2;
3383 }
3384 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303385 if (strcmp(ssid, dut->infra_ssid) == 0) {
3386 sigma_dut_print(dut, DUT_MSG_DEBUG,
3387 "sta_associate for the most recently added network");
3388 } else if (find_network(dut, ssid) < 0) {
3389 sigma_dut_print(dut, DUT_MSG_DEBUG,
3390 "sta_associate for a previously stored network profile");
3391 send_resp(dut, conn, SIGMA_ERROR,
3392 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003393 return 0;
3394 }
3395
3396 if (bssid &&
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003397 set_network(get_station_ifname(dut), dut->infra_network_id,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003398 "bssid", bssid) < 0) {
3399 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3400 "Invalid bssid argument");
3401 return 0;
3402 }
3403
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003404 if (dut->program == PROGRAM_WPA3 &&
3405 dut->sta_associate_wait_connect) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003406 ctrl = open_wpa_mon(get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003407 if (!ctrl)
3408 return ERROR_SEND_STATUS;
3409 }
3410
Jouni Malinen46a19b62017-06-23 14:31:27 +03003411 extra[0] = '\0';
3412 if (chan)
3413 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003414 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003415 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3416 dut->infra_network_id, extra);
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003417 if (wpa_command(get_station_ifname(dut), buf) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003418 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3419 "network id %d on %s",
3420 dut->infra_network_id,
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003421 get_station_ifname(dut));
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003422 ret = ERROR_SEND_STATUS;
3423 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003424 }
3425 }
3426
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003427 if (!ctrl)
3428 return SUCCESS_SEND_STATUS;
3429
3430 /* Wait for connection result to be able to store server certificate
3431 * hash for trust root override testing
3432 * (dev_exec_action,ServerCertTrust). */
3433
3434 for (e = 0; e < 20; e++) {
3435 const char *events[] = {
3436 "CTRL-EVENT-EAP-PEER-CERT",
3437 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3438 "CTRL-EVENT-DISCONNECTED",
3439 "CTRL-EVENT-CONNECTED",
3440 "CTRL-EVENT-NETWORK-NOT-FOUND",
3441 NULL
3442 };
3443 char buf[1024];
3444 int res;
3445
3446 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3447 if (res < 0) {
3448 send_resp(dut, conn, SIGMA_ERROR,
3449 "ErrorCode,Association did not complete");
3450 ret = STATUS_SENT_ERROR;
3451 break;
3452 }
3453 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3454 buf);
3455
3456 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3457 strstr(buf, " depth=0")) {
3458 char *pos = strstr(buf, " hash=");
3459
3460 if (pos) {
3461 char *end;
3462
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003463 if (strstr(buf, " tod=1"))
3464 tod = 1;
3465 else if (strstr(buf, " tod=2"))
3466 tod = 2;
3467 else
3468 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003469 sigma_dut_print(dut, DUT_MSG_DEBUG,
3470 "Server certificate TOD policy: %d",
3471 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003472 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003473
3474 pos += 6;
3475 end = strchr(pos, ' ');
3476 if (end)
3477 *end = '\0';
3478 strlcpy(dut->server_cert_hash, pos,
3479 sizeof(dut->server_cert_hash));
3480 sigma_dut_print(dut, DUT_MSG_DEBUG,
3481 "Server certificate hash: %s",
3482 dut->server_cert_hash);
3483 }
3484 }
3485
3486 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3487 send_resp(dut, conn, SIGMA_COMPLETE,
3488 "Result,TLS server certificate validation failed");
3489 ret = STATUS_SENT_ERROR;
3490 break;
3491 }
3492
3493 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3494 num_network_not_found++;
3495
3496 if (num_network_not_found > 2) {
3497 send_resp(dut, conn, SIGMA_COMPLETE,
3498 "Result,Network not found");
3499 ret = STATUS_SENT_ERROR;
3500 break;
3501 }
3502 }
3503
3504 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3505 num_disconnected++;
3506
3507 if (num_disconnected > 2) {
3508 send_resp(dut, conn, SIGMA_COMPLETE,
3509 "Result,Connection failed");
3510 ret = STATUS_SENT_ERROR;
3511 break;
3512 }
3513 }
3514
3515 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3516 if (tod >= 0) {
3517 sigma_dut_print(dut, DUT_MSG_DEBUG,
3518 "Network profile TOD policy update: %d -> %d",
3519 dut->sta_tod_policy, tod);
3520 dut->sta_tod_policy = tod;
3521 }
3522 break;
3523 }
3524 }
3525done:
3526 if (ctrl) {
3527 wpa_ctrl_detach(ctrl);
3528 wpa_ctrl_close(ctrl);
3529 }
3530 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003531}
3532
3533
3534static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3535{
3536 char buf[500], cmd[200];
3537 int res;
3538
3539 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3540 * default path */
3541 res = snprintf(cmd, sizeof(cmd),
3542 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3543 file_exists("./hs20-osu-client") ?
3544 "./hs20-osu-client" : "hs20-osu-client",
3545 sigma_wpas_ctrl,
3546 dut->summary_log ? "-s " : "",
3547 dut->summary_log ? dut->summary_log : "");
3548 if (res < 0 || res >= (int) sizeof(cmd))
3549 return -1;
3550
3551 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3552 if (res < 0 || res >= (int) sizeof(buf))
3553 return -1;
3554 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3555
3556 if (system(buf) != 0) {
3557 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3558 return -1;
3559 }
3560 sigma_dut_print(dut, DUT_MSG_DEBUG,
3561 "Completed hs20-osu-client operation");
3562
3563 return 0;
3564}
3565
3566
3567static int download_ppsmo(struct sigma_dut *dut,
3568 struct sigma_conn *conn,
3569 const char *intf,
3570 struct sigma_cmd *cmd)
3571{
3572 const char *name, *path, *val;
3573 char url[500], buf[600], fbuf[100];
3574 char *fqdn = NULL;
3575
3576 name = get_param(cmd, "FileName");
3577 path = get_param(cmd, "FilePath");
3578 if (name == NULL || path == NULL)
3579 return -1;
3580
3581 if (strcasecmp(path, "VendorSpecific") == 0) {
3582 snprintf(url, sizeof(url), "PPS/%s", name);
3583 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3584 "from the device (%s)", url);
3585 if (!file_exists(url)) {
3586 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3587 "PPS MO file does not exist");
3588 return 0;
3589 }
3590 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3591 if (system(buf) != 0) {
3592 send_resp(dut, conn, SIGMA_ERROR,
3593 "errorCode,Failed to copy PPS MO");
3594 return 0;
3595 }
3596 } else if (strncasecmp(path, "http:", 5) != 0 &&
3597 strncasecmp(path, "https:", 6) != 0) {
3598 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3599 "Unsupported FilePath value");
3600 return 0;
3601 } else {
3602 snprintf(url, sizeof(url), "%s/%s", path, name);
3603 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3604 url);
3605 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3606 remove("pps-tnds.xml");
3607 if (system(buf) != 0) {
3608 send_resp(dut, conn, SIGMA_ERROR,
3609 "errorCode,Failed to download PPS MO");
3610 return 0;
3611 }
3612 }
3613
3614 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3615 send_resp(dut, conn, SIGMA_ERROR,
3616 "errorCode,Failed to parse downloaded PPSMO");
3617 return 0;
3618 }
3619 unlink("pps-tnds.xml");
3620
3621 val = get_param(cmd, "managementTreeURI");
3622 if (val) {
3623 const char *pos, *end;
3624 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3625 val);
3626 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3627 send_resp(dut, conn, SIGMA_ERROR,
3628 "errorCode,Invalid managementTreeURI prefix");
3629 return 0;
3630 }
3631 pos = val + 8;
3632 end = strchr(pos, '/');
3633 if (end == NULL ||
3634 strcmp(end, "/PerProviderSubscription") != 0) {
3635 send_resp(dut, conn, SIGMA_ERROR,
3636 "errorCode,Invalid managementTreeURI postfix");
3637 return 0;
3638 }
3639 if (end - pos >= (int) sizeof(fbuf)) {
3640 send_resp(dut, conn, SIGMA_ERROR,
3641 "errorCode,Too long FQDN in managementTreeURI");
3642 return 0;
3643 }
3644 memcpy(fbuf, pos, end - pos);
3645 fbuf[end - pos] = '\0';
3646 fqdn = fbuf;
3647 sigma_dut_print(dut, DUT_MSG_INFO,
3648 "FQDN from managementTreeURI: %s", fqdn);
3649 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3650 FILE *f = fopen("pps-fqdn", "r");
3651 if (f) {
3652 if (fgets(fbuf, sizeof(fbuf), f)) {
3653 fbuf[sizeof(fbuf) - 1] = '\0';
3654 fqdn = fbuf;
3655 sigma_dut_print(dut, DUT_MSG_DEBUG,
3656 "Use FQDN %s", fqdn);
3657 }
3658 fclose(f);
3659 }
3660 }
3661
3662 if (fqdn == NULL) {
3663 send_resp(dut, conn, SIGMA_ERROR,
3664 "errorCode,No FQDN specified");
3665 return 0;
3666 }
3667
3668 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3669 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3670 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3671
3672 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3673 if (rename("pps.xml", buf) < 0) {
3674 send_resp(dut, conn, SIGMA_ERROR,
3675 "errorCode,Could not move PPS MO");
3676 return 0;
3677 }
3678
3679 if (strcasecmp(path, "VendorSpecific") == 0) {
3680 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3681 fqdn);
3682 if (system(buf)) {
3683 send_resp(dut, conn, SIGMA_ERROR,
3684 "errorCode,Failed to copy OSU CA cert");
3685 return 0;
3686 }
3687
3688 snprintf(buf, sizeof(buf),
3689 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3690 fqdn);
3691 if (system(buf)) {
3692 send_resp(dut, conn, SIGMA_ERROR,
3693 "errorCode,Failed to copy AAA CA cert");
3694 return 0;
3695 }
3696 } else {
3697 snprintf(buf, sizeof(buf),
3698 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3699 fqdn, fqdn);
3700 if (run_hs20_osu(dut, buf) < 0) {
3701 send_resp(dut, conn, SIGMA_ERROR,
3702 "errorCode,Failed to download OSU CA cert");
3703 return 0;
3704 }
3705
3706 snprintf(buf, sizeof(buf),
3707 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3708 fqdn, fqdn);
3709 if (run_hs20_osu(dut, buf) < 0) {
3710 sigma_dut_print(dut, DUT_MSG_INFO,
3711 "Failed to download AAA CA cert");
3712 }
3713 }
3714
3715 if (file_exists("next-client-cert.pem")) {
3716 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3717 if (rename("next-client-cert.pem", buf) < 0) {
3718 send_resp(dut, conn, SIGMA_ERROR,
3719 "errorCode,Could not move client certificate");
3720 return 0;
3721 }
3722 }
3723
3724 if (file_exists("next-client-key.pem")) {
3725 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3726 if (rename("next-client-key.pem", buf) < 0) {
3727 send_resp(dut, conn, SIGMA_ERROR,
3728 "errorCode,Could not move client key");
3729 return 0;
3730 }
3731 }
3732
3733 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3734 if (run_hs20_osu(dut, buf) < 0) {
3735 send_resp(dut, conn, SIGMA_ERROR,
3736 "errorCode,Failed to configure credential from "
3737 "PPSMO");
3738 return 0;
3739 }
3740
3741 return 1;
3742}
3743
3744
3745static int download_cert(struct sigma_dut *dut,
3746 struct sigma_conn *conn,
3747 const char *intf,
3748 struct sigma_cmd *cmd)
3749{
3750 const char *name, *path;
3751 char url[500], buf[600];
3752
3753 name = get_param(cmd, "FileName");
3754 path = get_param(cmd, "FilePath");
3755 if (name == NULL || path == NULL)
3756 return -1;
3757
3758 if (strcasecmp(path, "VendorSpecific") == 0) {
3759 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3760 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3761 "certificate from the device (%s)", url);
3762 if (!file_exists(url)) {
3763 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3764 "certificate file does not exist");
3765 return 0;
3766 }
3767 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3768 if (system(buf) != 0) {
3769 send_resp(dut, conn, SIGMA_ERROR,
3770 "errorCode,Failed to copy client "
3771 "certificate");
3772 return 0;
3773 }
3774
3775 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3776 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3777 "private key from the device (%s)", url);
3778 if (!file_exists(url)) {
3779 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3780 "private key file does not exist");
3781 return 0;
3782 }
3783 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3784 if (system(buf) != 0) {
3785 send_resp(dut, conn, SIGMA_ERROR,
3786 "errorCode,Failed to copy client key");
3787 return 0;
3788 }
3789 } else if (strncasecmp(path, "http:", 5) != 0 &&
3790 strncasecmp(path, "https:", 6) != 0) {
3791 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3792 "Unsupported FilePath value");
3793 return 0;
3794 } else {
3795 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3796 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3797 "certificate/key from %s", url);
3798 snprintf(buf, sizeof(buf),
3799 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3800 if (system(buf) != 0) {
3801 send_resp(dut, conn, SIGMA_ERROR,
3802 "errorCode,Failed to download client "
3803 "certificate");
3804 return 0;
3805 }
3806
3807 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3808 {
3809 send_resp(dut, conn, SIGMA_ERROR,
3810 "errorCode,Failed to copy client key");
3811 return 0;
3812 }
3813 }
3814
3815 return 1;
3816}
3817
3818
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003819static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3820 struct sigma_conn *conn,
3821 struct sigma_cmd *cmd)
3822{
3823 const char *val;
3824 const char *intf = get_param(cmd, "interface");
3825
3826 if (!intf)
3827 return -1;
3828
3829 val = get_param(cmd, "WscIEFragment");
3830 if (val && strcasecmp(val, "enable") == 0) {
3831 sigma_dut_print(dut, DUT_MSG_DEBUG,
3832 "Enable WSC IE fragmentation");
3833
3834 dut->wsc_fragment = 1;
3835 /* set long attributes to force fragmentation */
3836 if (wpa_command(intf, "SET device_name "
3837 WPS_LONG_DEVICE_NAME) < 0)
3838 return -2;
3839 if (wpa_command(intf, "SET manufacturer "
3840 WPS_LONG_MANUFACTURER) < 0)
3841 return -2;
3842 if (wpa_command(intf, "SET model_name "
3843 WPS_LONG_MODEL_NAME) < 0)
3844 return -2;
3845 if (wpa_command(intf, "SET model_number "
3846 WPS_LONG_MODEL_NUMBER) < 0)
3847 return -2;
3848 if (wpa_command(intf, "SET serial_number "
3849 WPS_LONG_SERIAL_NUMBER) < 0)
3850 return -2;
3851 }
3852
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003853 val = get_param(cmd, "RSN_IE");
3854 if (val) {
3855 if (strcasecmp(val, "disable") == 0)
3856 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3857 else if (strcasecmp(val, "enable") == 0)
3858 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3859 }
3860
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003861 val = get_param(cmd, "WpsVersion");
3862 if (val)
3863 dut->wps_forced_version = get_wps_forced_version(dut, val);
3864
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003865 val = get_param(cmd, "WscEAPFragment");
3866 if (val && strcasecmp(val, "enable") == 0)
3867 dut->eap_fragment = 1;
3868
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003869 return 1;
3870}
3871
3872
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003873static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3874 struct sigma_conn *conn,
3875 const char *intf,
3876 struct sigma_cmd *cmd)
3877{
3878 const char *val;
3879
3880 val = get_param(cmd, "FileType");
3881 if (val && strcasecmp(val, "PPSMO") == 0)
3882 return download_ppsmo(dut, conn, intf, cmd);
3883 if (val && strcasecmp(val, "CERT") == 0)
3884 return download_cert(dut, conn, intf, cmd);
3885 if (val) {
3886 send_resp(dut, conn, SIGMA_ERROR,
3887 "ErrorCode,Unsupported FileType");
3888 return 0;
3889 }
3890
3891 return 1;
3892}
3893
3894
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303895static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3896 struct sigma_conn *conn,
3897 const char *intf,
3898 struct sigma_cmd *cmd)
3899{
3900 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303901 char buf[1000];
3902 char text[20];
3903 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303904
3905 val = get_param(cmd, "OCESupport");
3906 if (val && strcasecmp(val, "Disable") == 0) {
3907 if (wpa_command(intf, "SET oce 0") < 0) {
3908 send_resp(dut, conn, SIGMA_ERROR,
3909 "ErrorCode,Failed to disable OCE");
3910 return 0;
3911 }
3912 } else if (val && strcasecmp(val, "Enable") == 0) {
3913 if (wpa_command(intf, "SET oce 1") < 0) {
3914 send_resp(dut, conn, SIGMA_ERROR,
3915 "ErrorCode,Failed to enable OCE");
3916 return 0;
3917 }
3918 }
3919
vamsi krishnaa2799492017-12-05 14:28:01 +05303920 val = get_param(cmd, "FILScap");
3921 if (val && (atoi(val) == 1)) {
3922 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3923 send_resp(dut, conn, SIGMA_ERROR,
3924 "ErrorCode,Failed to enable FILS");
3925 return 0;
3926 }
3927 } else if (val && (atoi(val) == 0)) {
3928 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3929 send_resp(dut, conn, SIGMA_ERROR,
3930 "ErrorCode,Failed to disable FILS");
3931 return 0;
3932 }
3933 }
3934
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303935 val = get_param(cmd, "FILSHLP");
3936 if (val && strcasecmp(val, "Enable") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02003937 if (get_wpa_status(get_station_ifname(dut), "address", text,
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303938 sizeof(text)) < 0)
3939 return -2;
3940 hwaddr_aton(text, addr);
3941 snprintf(buf, sizeof(buf),
3942 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3943 "080045100140000040004011399e00000000ffffffff00440043"
3944 "012cb30001010600fd4f46410000000000000000000000000000"
3945 "000000000000"
3946 "%02x%02x%02x%02x%02x%02x"
3947 "0000000000000000000000000000000000000000000000000000"
3948 "0000000000000000000000000000000000000000000000000000"
3949 "0000000000000000000000000000000000000000000000000000"
3950 "0000000000000000000000000000000000000000000000000000"
3951 "0000000000000000000000000000000000000000000000000000"
3952 "0000000000000000000000000000000000000000000000000000"
3953 "0000000000000000000000000000000000000000000000000000"
3954 "0000000000000000000000000000000000000000638253633501"
3955 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3956 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3957 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3958 if (wpa_command(intf, buf)) {
3959 send_resp(dut, conn, SIGMA_ERROR,
3960 "ErrorCode,Failed to add HLP");
3961 return 0;
3962 }
3963 dut->fils_hlp = 1;
3964 }
3965
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303966 return 1;
3967}
3968
3969
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003970static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3971 const char *val)
3972{
3973 int counter = 0;
3974 char token[50];
3975 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303976 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003977
Peng Xub8fc5cc2017-05-10 17:27:28 -07003978 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003979 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303980 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003981 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003982 if (strcmp(result, "disable") == 0)
3983 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
3984 else
3985 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303986 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003987 counter++;
3988 }
3989}
3990
3991
3992static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3993 const char *val)
3994{
3995 char buf[100];
3996
3997 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3998 if (system(buf) != 0) {
3999 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
4000 }
4001}
4002
4003
4004static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4005 const char *val)
4006{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004007 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004008 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004009 }
4010}
4011
4012
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004013static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
4014 const char *val)
4015{
4016#ifdef NL80211_SUPPORT
4017 struct nl_msg *msg;
4018 int ret = 0;
4019 struct nlattr *params;
4020 int ifindex;
4021 int wmmenable = 1;
4022
4023 if (val &&
4024 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4025 wmmenable = 0;
4026
4027 ifindex = if_nametoindex(intf);
4028 if (ifindex == 0) {
4029 sigma_dut_print(dut, DUT_MSG_ERROR,
4030 "%s: Index for interface %s failed",
4031 __func__, intf);
4032 return -1;
4033 }
4034
4035 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4036 NL80211_CMD_VENDOR)) ||
4037 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4038 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4039 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4040 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4041 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4042 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4043 wmmenable)) {
4044 sigma_dut_print(dut, DUT_MSG_ERROR,
4045 "%s: err in adding vendor_cmd and vendor_data",
4046 __func__);
4047 nlmsg_free(msg);
4048 return -1;
4049 }
4050 nla_nest_end(msg, params);
4051
4052 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4053 if (ret) {
4054 sigma_dut_print(dut, DUT_MSG_ERROR,
4055 "%s: err in send_and_recv_msgs, ret=%d",
4056 __func__, ret);
4057 }
4058 return ret;
4059#else /* NL80211_SUPPORT */
4060 sigma_dut_print(dut, DUT_MSG_ERROR,
4061 "WMM cannot be changed without NL80211_SUPPORT defined");
4062 return -1;
4063#endif /* NL80211_SUPPORT */
4064}
4065
4066
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004067static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4068 const char *val)
4069{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004070 int sgi20;
4071
4072 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4073
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004074 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004075}
4076
4077
4078static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4079 const char *val)
4080{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304081 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004082
4083 /* Disable Tx Beam forming when using a fixed rate */
4084 ath_disable_txbf(dut, intf);
4085
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304086 v = atoi(val);
4087 if (v < 0 || v > 32) {
4088 sigma_dut_print(dut, DUT_MSG_ERROR,
4089 "Invalid Fixed MCS rate: %d", v);
4090 return;
4091 }
4092 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004093
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004094 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004095
4096 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004097 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004098}
4099
4100
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004101static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4102 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004103{
4104 char buf[60];
4105
4106 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4107 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4108 else
4109 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4110
4111 if (system(buf) != 0)
4112 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4113}
4114
4115
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004116static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4117 int ampdu)
4118{
4119 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004120 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004121
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004122 if (ampdu)
4123 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004124 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4125 if (system(buf) != 0) {
4126 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4127 return -1;
4128 }
4129
4130 return 0;
4131}
4132
4133
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004134static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4135 const char *val)
4136{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004137 run_iwpriv(dut, intf, "tx_stbc %s", val);
4138 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004139}
4140
4141
4142static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4143 const char *val)
4144{
4145 char buf[60];
4146
Peng Xucc317ed2017-05-18 16:44:37 -07004147 if (strcmp(val, "160") == 0) {
4148 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4149 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004150 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4151 } else if (strcmp(val, "40") == 0) {
4152 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4153 } else if (strcmp(val, "20") == 0) {
4154 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4155 } else if (strcasecmp(val, "Auto") == 0) {
4156 buf[0] = '\0';
4157 } else {
4158 sigma_dut_print(dut, DUT_MSG_ERROR,
4159 "WIDTH/CTS_WIDTH value not supported");
4160 return -1;
4161 }
4162
4163 if (buf[0] != '\0' && system(buf) != 0) {
4164 sigma_dut_print(dut, DUT_MSG_ERROR,
4165 "Failed to set WIDTH/CTS_WIDTH");
4166 return -1;
4167 }
4168
4169 return 0;
4170}
4171
4172
4173int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4174 const char *intf, const char *val)
4175{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004176 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004177 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004178 dut->chwidth = 0;
4179 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004180 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004181 dut->chwidth = 0;
4182 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004183 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004184 dut->chwidth = 1;
4185 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004186 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004187 dut->chwidth = 2;
4188 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004189 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004190 dut->chwidth = 3;
4191 } else {
4192 send_resp(dut, conn, SIGMA_ERROR,
4193 "ErrorCode,WIDTH not supported");
4194 return -1;
4195 }
4196
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004197 return 0;
4198}
4199
4200
4201static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4202 const char *val)
4203{
4204 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004205 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004206
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004207 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004208 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004209 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004210 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004211 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004212 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004213 } else {
4214 sigma_dut_print(dut, DUT_MSG_ERROR,
4215 "SP_STREAM value not supported");
4216 return -1;
4217 }
4218
4219 if (system(buf) != 0) {
4220 sigma_dut_print(dut, DUT_MSG_ERROR,
4221 "Failed to set SP_STREAM");
4222 return -1;
4223 }
4224
Arif Hussainac6c5112018-05-25 17:34:00 -07004225 dut->sta_nss = sta_nss;
4226
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004227 return 0;
4228}
4229
4230
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304231static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4232 const char *val)
4233{
4234 char buf[60];
4235
4236 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4237 if (system(buf) != 0)
4238 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4239
4240 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4241 if (system(buf) != 0)
4242 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4243}
4244
4245
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304246static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4247 struct sigma_conn *conn,
4248 const char *intf, int capa)
4249{
4250 char buf[32];
4251
4252 if (capa > 0 && capa < 4) {
4253 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4254 if (wpa_command(intf, buf) < 0) {
4255 send_resp(dut, conn, SIGMA_ERROR,
4256 "ErrorCode, Failed to set cellular data capability");
4257 return 0;
4258 }
4259 return 1;
4260 }
4261
4262 sigma_dut_print(dut, DUT_MSG_ERROR,
4263 "Invalid Cellular data capability: %d", capa);
4264 send_resp(dut, conn, SIGMA_INVALID,
4265 "ErrorCode,Invalid cellular data capability");
4266 return 0;
4267}
4268
4269
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304270static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4271 const char *intf, const char *val)
4272{
4273 if (strcasecmp(val, "Disable") == 0) {
4274 if (wpa_command(intf, "SET roaming 0") < 0) {
4275 send_resp(dut, conn, SIGMA_ERROR,
4276 "ErrorCode,Failed to disable roaming");
4277 return 0;
4278 }
4279 return 1;
4280 }
4281
4282 if (strcasecmp(val, "Enable") == 0) {
4283 if (wpa_command(intf, "SET roaming 1") < 0) {
4284 send_resp(dut, conn, SIGMA_ERROR,
4285 "ErrorCode,Failed to enable roaming");
4286 return 0;
4287 }
4288 return 1;
4289 }
4290
4291 sigma_dut_print(dut, DUT_MSG_ERROR,
4292 "Invalid value provided for roaming: %s", val);
4293 send_resp(dut, conn, SIGMA_INVALID,
4294 "ErrorCode,Unknown value provided for Roaming");
4295 return 0;
4296}
4297
4298
Ashwini Patila75de5a2017-04-13 16:35:05 +05304299static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4300 struct sigma_conn *conn,
4301 const char *intf, const char *val)
4302{
4303 if (strcasecmp(val, "Disable") == 0) {
4304 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4305 send_resp(dut, conn, SIGMA_ERROR,
4306 "ErrorCode,Failed to disable Assoc_disallow");
4307 return 0;
4308 }
4309 return 1;
4310 }
4311
4312 if (strcasecmp(val, "Enable") == 0) {
4313 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4314 send_resp(dut, conn, SIGMA_ERROR,
4315 "ErrorCode,Failed to enable Assoc_disallow");
4316 return 0;
4317 }
4318 return 1;
4319 }
4320
4321 sigma_dut_print(dut, DUT_MSG_ERROR,
4322 "Invalid value provided for Assoc_disallow: %s", val);
4323 send_resp(dut, conn, SIGMA_INVALID,
4324 "ErrorCode,Unknown value provided for Assoc_disallow");
4325 return 0;
4326}
4327
4328
Ashwini Patilc63161e2017-04-13 16:30:23 +05304329static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4330 const char *intf, const char *val)
4331{
4332 if (strcasecmp(val, "Reject") == 0) {
4333 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4334 send_resp(dut, conn, SIGMA_ERROR,
4335 "ErrorCode,Failed to Reject BTM Request");
4336 return 0;
4337 }
4338 return 1;
4339 }
4340
4341 if (strcasecmp(val, "Accept") == 0) {
4342 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4343 send_resp(dut, conn, SIGMA_ERROR,
4344 "ErrorCode,Failed to Accept BTM Request");
4345 return 0;
4346 }
4347 return 1;
4348 }
4349
4350 sigma_dut_print(dut, DUT_MSG_ERROR,
4351 "Invalid value provided for BSS_Transition: %s", val);
4352 send_resp(dut, conn, SIGMA_INVALID,
4353 "ErrorCode,Unknown value provided for BSS_Transition");
4354 return 0;
4355}
4356
4357
Ashwini Patil00402582017-04-13 12:29:39 +05304358static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4359 struct sigma_conn *conn,
4360 const char *intf,
4361 struct sigma_cmd *cmd)
4362{
4363 const char *ch, *pref, *op_class, *reason;
4364 char buf[120];
4365 int len, ret;
4366
4367 pref = get_param(cmd, "Ch_Pref");
4368 if (!pref)
4369 return 1;
4370
4371 if (strcasecmp(pref, "clear") == 0) {
4372 free(dut->non_pref_ch_list);
4373 dut->non_pref_ch_list = NULL;
4374 } else {
4375 op_class = get_param(cmd, "Ch_Op_Class");
4376 if (!op_class) {
4377 send_resp(dut, conn, SIGMA_INVALID,
4378 "ErrorCode,Ch_Op_Class not provided");
4379 return 0;
4380 }
4381
4382 ch = get_param(cmd, "Ch_Pref_Num");
4383 if (!ch) {
4384 send_resp(dut, conn, SIGMA_INVALID,
4385 "ErrorCode,Ch_Pref_Num not provided");
4386 return 0;
4387 }
4388
4389 reason = get_param(cmd, "Ch_Reason_Code");
4390 if (!reason) {
4391 send_resp(dut, conn, SIGMA_INVALID,
4392 "ErrorCode,Ch_Reason_Code not provided");
4393 return 0;
4394 }
4395
4396 if (!dut->non_pref_ch_list) {
4397 dut->non_pref_ch_list =
4398 calloc(1, NON_PREF_CH_LIST_SIZE);
4399 if (!dut->non_pref_ch_list) {
4400 send_resp(dut, conn, SIGMA_ERROR,
4401 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4402 return 0;
4403 }
4404 }
4405 len = strlen(dut->non_pref_ch_list);
4406 ret = snprintf(dut->non_pref_ch_list + len,
4407 NON_PREF_CH_LIST_SIZE - len,
4408 " %s:%s:%s:%s", op_class, ch, pref, reason);
4409 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4410 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4411 dut->non_pref_ch_list);
4412 } else {
4413 sigma_dut_print(dut, DUT_MSG_ERROR,
4414 "snprintf failed for non_pref_list, ret = %d",
4415 ret);
4416 send_resp(dut, conn, SIGMA_ERROR,
4417 "ErrorCode,snprintf failed");
4418 free(dut->non_pref_ch_list);
4419 dut->non_pref_ch_list = NULL;
4420 return 0;
4421 }
4422 }
4423
4424 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4425 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4426 if (ret < 0 || ret >= (int) sizeof(buf)) {
4427 sigma_dut_print(dut, DUT_MSG_DEBUG,
4428 "snprintf failed for set non_pref_chan, ret: %d",
4429 ret);
4430 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4431 return 0;
4432 }
4433
4434 if (wpa_command(intf, buf) < 0) {
4435 send_resp(dut, conn, SIGMA_ERROR,
4436 "ErrorCode,Failed to set non-preferred channel list");
4437 return 0;
4438 }
4439
4440 return 1;
4441}
4442
4443
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004444#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004445
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004446static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4447 uint8_t cfg)
4448{
4449 struct nl_msg *msg;
4450 int ret = 0;
4451 struct nlattr *params;
4452 int ifindex;
4453
4454 ifindex = if_nametoindex(intf);
4455 if (ifindex == 0) {
4456 sigma_dut_print(dut, DUT_MSG_ERROR,
4457 "%s: Index for interface %s failed",
4458 __func__, intf);
4459 return -1;
4460 }
4461
4462 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4463 NL80211_CMD_VENDOR)) ||
4464 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4465 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4466 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4467 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4468 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4469 nla_put_u8(msg,
4470 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4471 cfg)) {
4472 sigma_dut_print(dut, DUT_MSG_ERROR,
4473 "%s: err in adding vendor_cmd and vendor_data",
4474 __func__);
4475 nlmsg_free(msg);
4476 return -1;
4477 }
4478 nla_nest_end(msg, params);
4479
4480 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4481 if (ret) {
4482 sigma_dut_print(dut, DUT_MSG_ERROR,
4483 "%s: err in send_and_recv_msgs, ret=%d",
4484 __func__, ret);
4485 }
4486 return ret;
4487}
4488
4489
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004490static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4491 enum he_fragmentation_val frag)
4492{
4493 struct nl_msg *msg;
4494 int ret = 0;
4495 struct nlattr *params;
4496 int ifindex;
4497
4498 ifindex = if_nametoindex(intf);
4499 if (ifindex == 0) {
4500 sigma_dut_print(dut, DUT_MSG_ERROR,
4501 "%s: Index for interface %s failed",
4502 __func__, intf);
4503 return -1;
4504 }
4505
4506 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4507 NL80211_CMD_VENDOR)) ||
4508 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4509 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4510 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4511 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4512 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4513 nla_put_u8(msg,
4514 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4515 frag)) {
4516 sigma_dut_print(dut, DUT_MSG_ERROR,
4517 "%s: err in adding vendor_cmd and vendor_data",
4518 __func__);
4519 nlmsg_free(msg);
4520 return -1;
4521 }
4522 nla_nest_end(msg, params);
4523
4524 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4525 if (ret) {
4526 sigma_dut_print(dut, DUT_MSG_ERROR,
4527 "%s: err in send_and_recv_msgs, ret=%d",
4528 __func__, ret);
4529 }
4530 return ret;
4531}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004532
4533
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004534static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
4535 enum qca_wlan_he_ltf_cfg ltf)
4536{
4537 struct nl_msg *msg;
4538 int ret = 0;
4539 struct nlattr *params;
4540 int ifindex;
4541
4542 ifindex = if_nametoindex(intf);
4543 if (ifindex == 0) {
4544 sigma_dut_print(dut, DUT_MSG_ERROR,
4545 "%s: Index for interface %s failed",
4546 __func__, intf);
4547 return -1;
4548 }
4549
4550 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4551 NL80211_CMD_VENDOR)) ||
4552 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4553 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4554 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4555 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4556 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4557 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4558 ltf)) {
4559 sigma_dut_print(dut, DUT_MSG_ERROR,
4560 "%s: err in adding vendor_cmd and vendor_data",
4561 __func__);
4562 nlmsg_free(msg);
4563 return -1;
4564 }
4565 nla_nest_end(msg, params);
4566
4567 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4568 if (ret) {
4569 sigma_dut_print(dut, DUT_MSG_ERROR,
4570 "%s: err in send_and_recv_msgs, ret=%d",
4571 __func__, ret);
4572 }
4573 return ret;
4574}
4575
4576
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004577static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4578 int noack, enum qca_wlan_ac_type ac)
4579{
4580 struct nl_msg *msg;
4581 int ret = 0;
4582 struct nlattr *params;
4583 int ifindex;
4584
4585 ifindex = if_nametoindex(intf);
4586 if (ifindex == 0) {
4587 sigma_dut_print(dut, DUT_MSG_ERROR,
4588 "%s: Index for interface %s failed",
4589 __func__, intf);
4590 return -1;
4591 }
4592
4593 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4594 NL80211_CMD_VENDOR)) ||
4595 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4596 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4597 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4598 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4599 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4600 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4601 noack) ||
4602 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4603 ac)) {
4604 sigma_dut_print(dut, DUT_MSG_ERROR,
4605 "%s: err in adding vendor_cmd and vendor_data",
4606 __func__);
4607 nlmsg_free(msg);
4608 return -1;
4609 }
4610 nla_nest_end(msg, params);
4611
4612 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4613 if (ret) {
4614 sigma_dut_print(dut, DUT_MSG_ERROR,
4615 "%s: err in send_and_recv_msgs, ret=%d",
4616 __func__, ret);
4617 }
4618 return ret;
4619}
4620
4621
4622static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4623 const char *val)
4624{
4625 int noack, ret;
4626 char token[100];
4627 char *result;
4628 char *saveptr;
4629 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4630
4631 strlcpy(token, val, sizeof(token));
4632 token[sizeof(token) - 1] = '\0';
4633 result = strtok_r(token, ":", &saveptr);
4634 while (result) {
4635 noack = strcasecmp(result, "Disable") != 0;
4636 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4637 if (ret) {
4638 sigma_dut_print(dut, DUT_MSG_ERROR,
4639 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4640 ac, ret);
4641 }
4642 result = strtok_r(NULL, ":", &saveptr);
4643 ac++;
4644 }
4645}
4646
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004647#endif /* NL80211_SUPPORT */
4648
4649
Jouni Malinenf7222712019-06-13 01:50:21 +03004650static enum sigma_cmd_result
4651cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4652 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004653{
4654 const char *intf = get_param(cmd, "Interface");
4655 const char *val;
4656
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004657 val = get_param(cmd, "FT_DS");
4658 if (val) {
4659 if (strcasecmp(val, "Enable") == 0) {
4660 dut->sta_ft_ds = 1;
4661 } else if (strcasecmp(val, "Disable") == 0) {
4662 dut->sta_ft_ds = 0;
4663 } else {
4664 send_resp(dut, conn, SIGMA_ERROR,
4665 "errorCode,Unsupported value for FT_DS");
4666 return STATUS_SENT_ERROR;
4667 }
4668 }
4669
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004670 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004671 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4672 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004673 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4674 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004675
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004676 if (val && strcasecmp(val, "LOC") == 0)
4677 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004678 if (val && strcasecmp(val, "60GHZ") == 0) {
4679 val = get_param(cmd, "WPS");
4680 if (val && strcasecmp(val, "disable") == 0) {
4681 dut->wps_disable = 1;
4682 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4683 } else {
4684 /* wps_disable can have other value from the previous
4685 * test, so make sure it has the correct value.
4686 */
4687 dut->wps_disable = 0;
4688 }
4689
4690 val = get_param(cmd, "P2P");
4691 if (val && strcasecmp(val, "disable") == 0)
4692 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4693 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004694
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004695 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4696 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4697
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004698#ifdef ANDROID_NAN
4699 if (val && strcasecmp(val, "NAN") == 0)
4700 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4701#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004702#ifdef MIRACAST
4703 if (val && (strcasecmp(val, "WFD") == 0 ||
4704 strcasecmp(val, "DisplayR2") == 0))
4705 return miracast_preset_testparameters(dut, conn, cmd);
4706#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004707
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304708 if (val && strcasecmp(val, "MBO") == 0) {
4709 val = get_param(cmd, "Cellular_Data_Cap");
4710 if (val &&
4711 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4712 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304713
4714 val = get_param(cmd, "Ch_Pref");
4715 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4716 return 0;
4717
Ashwini Patilc63161e2017-04-13 16:30:23 +05304718 val = get_param(cmd, "BSS_Transition");
4719 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4720 return 0;
4721
Ashwini Patila75de5a2017-04-13 16:35:05 +05304722 val = get_param(cmd, "Assoc_Disallow");
4723 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4724 return 0;
4725
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304726 val = get_param(cmd, "Roaming");
4727 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4728 return 0;
4729
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304730 return 1;
4731 }
4732
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304733 if (val && strcasecmp(val, "OCE") == 0)
4734 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4735
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004736#if 0
4737 val = get_param(cmd, "Supplicant");
4738 if (val && strcasecmp(val, "Default") != 0) {
4739 send_resp(dut, conn, SIGMA_ERROR,
4740 "ErrorCode,Only default(Vendor) supplicant "
4741 "supported");
4742 return 0;
4743 }
4744#endif
4745
4746 val = get_param(cmd, "RTS");
4747 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004748 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004749 case DRIVER_ATHEROS:
4750 ath_sta_set_rts(dut, intf, val);
4751 break;
4752 default:
4753#if 0
4754 send_resp(dut, conn, SIGMA_ERROR,
4755 "ErrorCode,Setting RTS not supported");
4756 return 0;
4757#else
4758 sigma_dut_print(dut, DUT_MSG_DEBUG,
4759 "Setting RTS not supported");
4760 break;
4761#endif
4762 }
4763 }
4764
4765#if 0
4766 val = get_param(cmd, "FRGMNT");
4767 if (val) {
4768 /* TODO */
4769 send_resp(dut, conn, SIGMA_ERROR,
4770 "ErrorCode,Setting FRGMNT not supported");
4771 return 0;
4772 }
4773#endif
4774
4775#if 0
4776 val = get_param(cmd, "Preamble");
4777 if (val) {
4778 /* TODO: Long/Short */
4779 send_resp(dut, conn, SIGMA_ERROR,
4780 "ErrorCode,Setting Preamble not supported");
4781 return 0;
4782 }
4783#endif
4784
4785 val = get_param(cmd, "Mode");
4786 if (val) {
4787 if (strcmp(val, "11b") == 0 ||
4788 strcmp(val, "11g") == 0 ||
4789 strcmp(val, "11a") == 0 ||
4790 strcmp(val, "11n") == 0 ||
4791 strcmp(val, "11ng") == 0 ||
4792 strcmp(val, "11nl") == 0 ||
4793 strcmp(val, "11nl(nabg)") == 0 ||
4794 strcmp(val, "AC") == 0 ||
4795 strcmp(val, "11AC") == 0 ||
4796 strcmp(val, "11ac") == 0 ||
4797 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004798 strcmp(val, "11an") == 0 ||
4799 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004800 /* STA supports all modes by default */
4801 } else {
4802 send_resp(dut, conn, SIGMA_ERROR,
4803 "ErrorCode,Setting Mode not supported");
4804 return 0;
4805 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004806
4807 /* Change the mode only in case of testbed for HE program
4808 * and for 11a and 11g modes only. */
4809 if (dut->program == PROGRAM_HE &&
4810 dut->device_type == STA_testbed) {
4811 int phymode;
4812 char buf[60];
4813
4814 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004815 phymode = 1; /* IEEE80211_MODE_11A */
4816 } else if (strcmp(val, "11g") == 0) {
4817 phymode = 3; /* IEEE80211_MODE_11G */
4818 } else if (strcmp(val, "11b") == 0) {
4819 phymode = 2; /* IEEE80211_MODE_11B */
4820 } else if (strcmp(val, "11n") == 0 ||
4821 strcmp(val, "11nl") == 0 ||
4822 strcmp(val, "11nl(nabg)") == 0) {
4823 phymode = 22; /* IEEE80211_MODE_11AGN */
4824 } else if (strcmp(val, "11ng") == 0) {
4825 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4826 } else if (strcmp(val, "AC") == 0 ||
4827 strcasecmp(val, "11AC") == 0) {
4828 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4829 } else if (strcmp(val, "11na") == 0 ||
4830 strcasecmp(val, "11an") == 0) {
4831 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4832 } else if (strcmp(val, "11ax") == 0) {
4833 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004834 } else {
4835 sigma_dut_print(dut, DUT_MSG_DEBUG,
4836 "Ignoring mode change for mode: %s",
4837 val);
4838 phymode = -1;
4839 }
4840 if (phymode != -1) {
4841 snprintf(buf, sizeof(buf),
4842 "iwpriv %s setphymode %d",
4843 intf, phymode);
4844 if (system(buf) != 0) {
4845 sigma_dut_print(dut, DUT_MSG_ERROR,
4846 "iwpriv setting of phymode failed");
4847 }
4848 }
4849 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004850 }
4851
4852 val = get_param(cmd, "wmm");
4853 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004854 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004855 case DRIVER_ATHEROS:
4856 ath_sta_set_wmm(dut, intf, val);
4857 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004858 case DRIVER_WCN:
4859 wcn_sta_set_wmm(dut, intf, val);
4860 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004861 default:
4862 sigma_dut_print(dut, DUT_MSG_DEBUG,
4863 "Setting wmm not supported");
4864 break;
4865 }
4866 }
4867
4868 val = get_param(cmd, "Powersave");
4869 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004870 char buf[60];
4871
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004872 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004873 if (get_driver_type(dut) == DRIVER_WCN) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004874 snprintf(buf, sizeof(buf),
4875 "iwpriv %s setPower 2", intf);
4876 if (system(buf) != 0) {
4877 sigma_dut_print(dut, DUT_MSG_ERROR,
4878 "iwpriv setPower 2 failed");
4879 return 0;
4880 }
4881 }
4882
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004883 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004884 "P2P_SET ps 0") < 0)
4885 return -2;
4886 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004887 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
4888 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004889 } else if (strcmp(val, "1") == 0 ||
4890 strcasecmp(val, "PSPoll") == 0 ||
4891 strcasecmp(val, "on") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004892 if (get_driver_type(dut) == DRIVER_WCN) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004893 snprintf(buf, sizeof(buf),
4894 "iwpriv %s setPower 1", intf);
4895 if (system(buf) != 0) {
4896 sigma_dut_print(dut, DUT_MSG_ERROR,
4897 "iwpriv setPower 1 failed");
4898 return 0;
4899 }
4900 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004901 /* Disable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004902 wpa_command(get_station_ifname(dut), "P2P_SET ps 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004903 /* Enable PS-Poll test mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004904 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004905 "P2P_SET ps 97") < 0 ||
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004906 wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004907 "P2P_SET ps 99") < 0)
4908 return -2;
4909 } else if (strcmp(val, "2") == 0 ||
4910 strcasecmp(val, "Fast") == 0) {
4911 /* TODO */
4912 send_resp(dut, conn, SIGMA_ERROR,
4913 "ErrorCode,Powersave=Fast not supported");
4914 return 0;
4915 } else if (strcmp(val, "3") == 0 ||
4916 strcasecmp(val, "PSNonPoll") == 0) {
4917 /* Make sure test modes are disabled */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004918 wpa_command(get_station_ifname(dut), "P2P_SET ps 98");
4919 wpa_command(get_station_ifname(dut), "P2P_SET ps 96");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004920
4921 /* Enable default power save mode */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004922 if (wpa_command(get_station_ifname(dut),
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004923 "P2P_SET ps 1") < 0)
4924 return -2;
4925 } else
4926 return -1;
4927 }
4928
4929 val = get_param(cmd, "NoAck");
4930 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02004931 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004932 case DRIVER_ATHEROS:
4933 ath_sta_set_noack(dut, intf, val);
4934 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004935#ifdef NL80211_SUPPORT
4936 case DRIVER_WCN:
4937 wcn_sta_set_noack(dut, intf, val);
4938 break;
4939#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004940 default:
4941 send_resp(dut, conn, SIGMA_ERROR,
4942 "ErrorCode,Setting NoAck not supported");
4943 return 0;
4944 }
4945 }
4946
4947 val = get_param(cmd, "IgnoreChswitchProhibit");
4948 if (val) {
4949 /* TODO: Enabled/disabled */
4950 if (strcasecmp(val, "Enabled") == 0) {
4951 send_resp(dut, conn, SIGMA_ERROR,
4952 "ErrorCode,Enabling IgnoreChswitchProhibit "
4953 "not supported");
4954 return 0;
4955 }
4956 }
4957
4958 val = get_param(cmd, "TDLS");
4959 if (val) {
4960 if (strcasecmp(val, "Disabled") == 0) {
4961 if (wpa_command(intf, "SET tdls_disabled 1")) {
4962 send_resp(dut, conn, SIGMA_ERROR,
4963 "ErrorCode,Failed to disable TDLS");
4964 return 0;
4965 }
4966 } else if (strcasecmp(val, "Enabled") == 0) {
4967 if (wpa_command(intf, "SET tdls_disabled 0")) {
4968 send_resp(dut, conn, SIGMA_ERROR,
4969 "ErrorCode,Failed to enable TDLS");
4970 return 0;
4971 }
4972 } else {
4973 send_resp(dut, conn, SIGMA_ERROR,
4974 "ErrorCode,Unsupported TDLS value");
4975 return 0;
4976 }
4977 }
4978
4979 val = get_param(cmd, "TDLSmode");
4980 if (val) {
4981 if (strcasecmp(val, "Default") == 0) {
4982 wpa_command(intf, "SET tdls_testing 0");
4983 } else if (strcasecmp(val, "APProhibit") == 0) {
4984 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4985 send_resp(dut, conn, SIGMA_ERROR,
4986 "ErrorCode,Failed to enable ignore "
4987 "APProhibit TDLS mode");
4988 return 0;
4989 }
4990 } else if (strcasecmp(val, "HiLoMac") == 0) {
4991 /* STA should respond with TDLS setup req for a TDLS
4992 * setup req */
4993 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4994 send_resp(dut, conn, SIGMA_ERROR,
4995 "ErrorCode,Failed to enable HiLoMac "
4996 "TDLS mode");
4997 return 0;
4998 }
4999 } else if (strcasecmp(val, "WeakSecurity") == 0) {
5000 /*
5001 * Since all security modes are enabled by default when
5002 * Sigma control is used, there is no need to do
5003 * anything here.
5004 */
5005 } else if (strcasecmp(val, "ExistLink") == 0) {
5006 /*
5007 * Since we allow new TDLS Setup Request even if there
5008 * is an existing link, nothing needs to be done for
5009 * this.
5010 */
5011 } else {
5012 /* TODO:
5013 * ExistLink: STA should send TDLS setup req even if
5014 * direct link already exists
5015 */
5016 send_resp(dut, conn, SIGMA_ERROR,
5017 "ErrorCode,Unsupported TDLSmode value");
5018 return 0;
5019 }
5020 }
5021
5022 val = get_param(cmd, "FakePubKey");
5023 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5024 send_resp(dut, conn, SIGMA_ERROR,
5025 "ErrorCode,Failed to enable FakePubKey");
5026 return 0;
5027 }
5028
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005029#ifdef NL80211_SUPPORT
5030 val = get_param(cmd, "FrgmntSupport");
5031 if (val) {
5032 if (strcasecmp(val, "Enable") == 0) {
5033 if (sta_set_he_fragmentation(dut, intf,
5034 HE_FRAG_LEVEL1)) {
5035 send_resp(dut, conn, SIGMA_ERROR,
5036 "ErrorCode,Failed to enable HE Fragmentation");
5037 return 0;
5038 }
5039 } else if (strcasecmp(val, "Disable") == 0) {
5040 if (sta_set_he_fragmentation(dut, intf,
5041 HE_FRAG_DISABLE)) {
5042 send_resp(dut, conn, SIGMA_ERROR,
5043 "ErrorCode,Failed to disable HE Fragmentation");
5044 return 0;
5045 }
5046 }
5047 }
5048#endif /* NL80211_SUPPORT */
5049
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005050 return 1;
5051}
5052
5053
5054static const char * ath_get_radio_name(const char *radio_name)
5055{
5056 if (radio_name == NULL)
5057 return "wifi0";
5058 if (strcmp(radio_name, "wifi1") == 0)
5059 return "wifi1";
5060 if (strcmp(radio_name, "wifi2") == 0)
5061 return "wifi2";
5062 return "wifi0";
5063}
5064
5065
5066static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5067 const char *val)
5068{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005069 unsigned int vht_mcsmap = 0;
5070 int txchainmask = 0;
5071 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5072
5073 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5074 if (dut->testbed_flag_txsp == 1) {
5075 vht_mcsmap = 0xfffc;
5076 dut->testbed_flag_txsp = 0;
5077 } else {
5078 vht_mcsmap = 0xfffe;
5079 }
5080 txchainmask = 1;
5081 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5082 if (dut->testbed_flag_txsp == 1) {
5083 vht_mcsmap = 0xfff0;
5084 dut->testbed_flag_txsp = 0;
5085 } else {
5086 vht_mcsmap = 0xfffa;
5087 }
5088 txchainmask = 3;
5089 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5090 if (dut->testbed_flag_txsp == 1) {
5091 vht_mcsmap = 0xffc0;
5092 dut->testbed_flag_txsp = 0;
5093 } else {
5094 vht_mcsmap = 0xffea;
5095 }
5096 txchainmask = 7;
5097 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5098 if (dut->testbed_flag_txsp == 1) {
5099 vht_mcsmap = 0xff00;
5100 dut->testbed_flag_txsp = 0;
5101 } else {
5102 vht_mcsmap = 0xffaa;
5103 }
5104 txchainmask = 15;
5105 } else {
5106 if (dut->testbed_flag_txsp == 1) {
5107 vht_mcsmap = 0xffc0;
5108 dut->testbed_flag_txsp = 0;
5109 } else {
5110 vht_mcsmap = 0xffea;
5111 }
5112 }
5113
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005114 if (txchainmask)
5115 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005116
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005117 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005118}
5119
5120
5121static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5122 const char *val)
5123{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005124 unsigned int vht_mcsmap = 0;
5125 int rxchainmask = 0;
5126 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5127
5128 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5129 if (dut->testbed_flag_rxsp == 1) {
5130 vht_mcsmap = 0xfffc;
5131 dut->testbed_flag_rxsp = 0;
5132 } else {
5133 vht_mcsmap = 0xfffe;
5134 }
5135 rxchainmask = 1;
5136 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5137 if (dut->testbed_flag_rxsp == 1) {
5138 vht_mcsmap = 0xfff0;
5139 dut->testbed_flag_rxsp = 0;
5140 } else {
5141 vht_mcsmap = 0xfffa;
5142 }
5143 rxchainmask = 3;
5144 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5145 if (dut->testbed_flag_rxsp == 1) {
5146 vht_mcsmap = 0xffc0;
5147 dut->testbed_flag_rxsp = 0;
5148 } else {
5149 vht_mcsmap = 0xffea;
5150 }
5151 rxchainmask = 7;
5152 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5153 if (dut->testbed_flag_rxsp == 1) {
5154 vht_mcsmap = 0xff00;
5155 dut->testbed_flag_rxsp = 0;
5156 } else {
5157 vht_mcsmap = 0xffaa;
5158 }
5159 rxchainmask = 15;
5160 } else {
5161 if (dut->testbed_flag_rxsp == 1) {
5162 vht_mcsmap = 0xffc0;
5163 dut->testbed_flag_rxsp = 0;
5164 } else {
5165 vht_mcsmap = 0xffea;
5166 }
5167 }
5168
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005169 if (rxchainmask)
5170 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005171
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005172 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005173}
5174
5175
5176void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5177{
5178 if (strcasecmp(val, "enable") == 0) {
5179 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5180 != 0) {
5181 sigma_dut_print(dut, DUT_MSG_ERROR,
5182 "Disable BB_VHTSIGB_CRC_CALC failed");
5183 }
5184
5185 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5186 != 0) {
5187 sigma_dut_print(dut, DUT_MSG_ERROR,
5188 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5189 }
5190 } else {
5191 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5192 != 0) {
5193 sigma_dut_print(dut, DUT_MSG_ERROR,
5194 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5195 }
5196
5197 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5198 != 0) {
5199 sigma_dut_print(dut, DUT_MSG_ERROR,
5200 "Enable BB_VHTSIGB_CRC_CALC failed");
5201 }
5202 }
5203}
5204
5205
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005206static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5207 const char *val)
5208{
5209 char buf[60];
5210
5211 if (strcmp(val, "20") == 0) {
5212 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5213 dut->chwidth = 0;
5214 } else if (strcmp(val, "40") == 0) {
5215 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5216 dut->chwidth = 1;
5217 } else if (strcmp(val, "80") == 0) {
5218 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5219 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305220 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005221 buf[0] = '\0';
5222 } else {
5223 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5224 val);
5225 return -1;
5226 }
5227
5228 if (buf[0] != '\0' && system(buf) != 0) {
5229 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5230 return -1;
5231 }
5232
5233 return 0;
5234}
5235
5236
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005237static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5238 const char *intf, int addbareject)
5239{
5240#ifdef NL80211_SUPPORT
5241 struct nl_msg *msg;
5242 int ret = 0;
5243 struct nlattr *params;
5244 int ifindex;
5245
5246 ifindex = if_nametoindex(intf);
5247 if (ifindex == 0) {
5248 sigma_dut_print(dut, DUT_MSG_ERROR,
5249 "%s: Index for interface %s failed",
5250 __func__, intf);
5251 return -1;
5252 }
5253
5254 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5255 NL80211_CMD_VENDOR)) ||
5256 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5257 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5258 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5259 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5260 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5261 nla_put_u8(msg,
5262 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5263 !addbareject)) {
5264 sigma_dut_print(dut, DUT_MSG_ERROR,
5265 "%s: err in adding vendor_cmd and vendor_data",
5266 __func__);
5267 nlmsg_free(msg);
5268 return -1;
5269 }
5270 nla_nest_end(msg, params);
5271
5272 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5273 if (ret) {
5274 sigma_dut_print(dut, DUT_MSG_ERROR,
5275 "%s: err in send_and_recv_msgs, ret=%d",
5276 __func__, ret);
5277 }
5278 return ret;
5279#else /* NL80211_SUPPORT */
5280 sigma_dut_print(dut, DUT_MSG_ERROR,
5281 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5282 return -1;
5283#endif /* NL80211_SUPPORT */
5284}
5285
5286
5287static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5288 int addbareject)
5289{
5290 int ret;
5291
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005292 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005293 case DRIVER_WCN:
5294 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5295 if (ret) {
5296 sigma_dut_print(dut, DUT_MSG_ERROR,
5297 "nlvendor_sta_set_addba_reject failed, ret:%d",
5298 ret);
5299 return ret;
5300 }
5301 break;
5302 default:
5303 sigma_dut_print(dut, DUT_MSG_ERROR,
5304 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5305 ret = -1;
5306 break;
5307 }
5308
5309 return ret;
5310}
5311
5312
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005313static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5314 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005315{
5316#ifdef NL80211_SUPPORT
5317 struct nl_msg *msg;
5318 int ret = 0;
5319 struct nlattr *params;
5320 int ifindex;
5321
5322 ifindex = if_nametoindex(intf);
5323 if (ifindex == 0) {
5324 sigma_dut_print(dut, DUT_MSG_ERROR,
5325 "%s: Index for interface %s failed",
5326 __func__, intf);
5327 return -1;
5328 }
5329
5330 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5331 NL80211_CMD_VENDOR)) ||
5332 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5333 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5334 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5335 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5336 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5337 nla_put_u8(msg,
5338 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005339 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005340 sigma_dut_print(dut, DUT_MSG_ERROR,
5341 "%s: err in adding vendor_cmd and vendor_data",
5342 __func__);
5343 nlmsg_free(msg);
5344 return -1;
5345 }
5346 nla_nest_end(msg, params);
5347
5348 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5349 if (ret) {
5350 sigma_dut_print(dut, DUT_MSG_ERROR,
5351 "%s: err in send_and_recv_msgs, ret=%d",
5352 __func__, ret);
5353 }
5354 return ret;
5355#else /* NL80211_SUPPORT */
5356 sigma_dut_print(dut, DUT_MSG_ERROR,
5357 "Disable addba not possible without NL80211_SUPPORT defined");
5358 return -1;
5359#endif /* NL80211_SUPPORT */
5360}
5361
5362
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305363#ifdef NL80211_SUPPORT
5364static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5365{
5366 struct nl_msg *msg;
5367 int ret = 0;
5368 int ifindex;
5369
5370 ifindex = if_nametoindex(intf);
5371 if (ifindex == 0) {
5372 sigma_dut_print(dut, DUT_MSG_ERROR,
5373 "%s: Index for interface %s failed",
5374 __func__, intf);
5375 return -1;
5376 }
5377
5378 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5379 NL80211_CMD_SET_WIPHY)) ||
5380 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5381 sigma_dut_print(dut, DUT_MSG_ERROR,
5382 "%s: err in adding RTS threshold",
5383 __func__);
5384 nlmsg_free(msg);
5385 return -1;
5386 }
5387
5388 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5389 if (ret) {
5390 sigma_dut_print(dut, DUT_MSG_ERROR,
5391 "%s: err in send_and_recv_msgs, ret=%d",
5392 __func__, ret);
5393 }
5394 return ret;
5395}
5396#endif /* NL80211_SUPPORT */
5397
5398
5399static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5400{
5401 char buf[100];
5402
5403#ifdef NL80211_SUPPORT
5404 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5405 return 0;
5406 sigma_dut_print(dut, DUT_MSG_DEBUG,
5407 "Fall back to using iwconfig for setting RTS threshold");
5408#endif /* NL80211_SUPPORT */
5409
5410 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5411 if (system(buf) != 0) {
5412 sigma_dut_print(dut, DUT_MSG_ERROR,
5413 "Failed to set RTS threshold %d", val);
5414 return -1;
5415 }
5416 return 0;
5417}
5418
5419
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005420static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5421 struct sigma_conn *conn,
5422 struct sigma_cmd *cmd)
5423{
5424 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005425 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005426 char buf[128];
5427 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005428
5429 val = get_param(cmd, "40_INTOLERANT");
5430 if (val) {
5431 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5432 /* TODO: iwpriv ht40intol through wpa_supplicant */
5433 send_resp(dut, conn, SIGMA_ERROR,
5434 "ErrorCode,40_INTOLERANT not supported");
5435 return 0;
5436 }
5437 }
5438
5439 val = get_param(cmd, "ADDBA_REJECT");
5440 if (val) {
5441 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5442 /* reject any ADDBA with status "decline" */
5443 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005444 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005445 } else {
5446 /* accept ADDBA */
5447 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005448 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005449 }
5450 }
5451
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005452 if (addbareject >= 0 &&
5453 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5454 send_resp(dut, conn, SIGMA_ERROR,
5455 "ErrorCode,set addba_reject failed");
5456 return 0;
5457 }
5458
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005459 val = get_param(cmd, "AMPDU");
5460 if (val) {
5461 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5462 /* enable AMPDU Aggregation */
5463 if (ampdu == 0) {
5464 send_resp(dut, conn, SIGMA_ERROR,
5465 "ErrorCode,Mismatch in "
5466 "addba_reject/ampdu - "
5467 "not supported");
5468 return 0;
5469 }
5470 ampdu = 1;
5471 } else {
5472 /* disable AMPDU Aggregation */
5473 if (ampdu == 1) {
5474 send_resp(dut, conn, SIGMA_ERROR,
5475 "ErrorCode,Mismatch in "
5476 "addba_reject/ampdu - "
5477 "not supported");
5478 return 0;
5479 }
5480 ampdu = 0;
5481 }
5482 }
5483
5484 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005485 int ret;
5486
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005487 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5488 ampdu ? "Enabling" : "Disabling");
5489 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005490 if (wpa_command(intf, buf) < 0 &&
5491 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005492 send_resp(dut, conn, SIGMA_ERROR,
5493 "ErrorCode,set aggr failed");
5494 return 0;
5495 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005496
5497 if (ampdu == 0) {
5498 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005499 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005500 if (ret) {
5501 sigma_dut_print(dut, DUT_MSG_ERROR,
5502 "Failed to disable addba, ret:%d",
5503 ret);
5504 }
5505 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005506 }
5507
5508 val = get_param(cmd, "AMSDU");
5509 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005510 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005511 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005512 case DRIVER_WCN:
5513 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005514 break;
5515 default:
5516 if (strcmp(val, "1") == 0 ||
5517 strcasecmp(val, "Enable") == 0) {
5518 /* Enable AMSDU Aggregation */
5519 send_resp(dut, conn, SIGMA_ERROR,
5520 "ErrorCode,AMSDU aggregation not supported");
5521 return 0;
5522 }
5523 break;
5524 }
5525 }
5526
5527 val = get_param(cmd, "STBC_RX");
5528 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005529 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005530 case DRIVER_ATHEROS:
5531 ath_sta_set_stbc(dut, intf, val);
5532 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305533 case DRIVER_WCN:
5534 wcn_sta_set_stbc(dut, intf, val);
5535 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005536 default:
5537 send_resp(dut, conn, SIGMA_ERROR,
5538 "ErrorCode,STBC_RX not supported");
5539 return 0;
5540 }
5541 }
5542
5543 val = get_param(cmd, "WIDTH");
5544 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005545 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005546 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005547 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005548 send_resp(dut, conn, SIGMA_ERROR,
5549 "ErrorCode,Failed to set WIDTH");
5550 return 0;
5551 }
5552 break;
5553 case DRIVER_ATHEROS:
5554 if (ath_set_width(dut, conn, intf, val) < 0)
5555 return 0;
5556 break;
5557 default:
5558 sigma_dut_print(dut, DUT_MSG_ERROR,
5559 "Setting WIDTH not supported");
5560 break;
5561 }
5562 }
5563
5564 val = get_param(cmd, "SMPS");
5565 if (val) {
5566 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5567 send_resp(dut, conn, SIGMA_ERROR,
5568 "ErrorCode,SMPS not supported");
5569 return 0;
5570 }
5571
5572 val = get_param(cmd, "TXSP_STREAM");
5573 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005574 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005575 case DRIVER_WCN:
5576 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5577 send_resp(dut, conn, SIGMA_ERROR,
5578 "ErrorCode,Failed to set TXSP_STREAM");
5579 return 0;
5580 }
5581 break;
5582 case DRIVER_ATHEROS:
5583 ath_sta_set_txsp_stream(dut, intf, val);
5584 break;
5585 default:
5586 sigma_dut_print(dut, DUT_MSG_ERROR,
5587 "Setting TXSP_STREAM not supported");
5588 break;
5589 }
5590 }
5591
5592 val = get_param(cmd, "RXSP_STREAM");
5593 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005594 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005595 case DRIVER_WCN:
5596 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5597 send_resp(dut, conn, SIGMA_ERROR,
5598 "ErrorCode,Failed to set RXSP_STREAM");
5599 return 0;
5600 }
5601 break;
5602 case DRIVER_ATHEROS:
5603 ath_sta_set_rxsp_stream(dut, intf, val);
5604 break;
5605 default:
5606 sigma_dut_print(dut, DUT_MSG_ERROR,
5607 "Setting RXSP_STREAM not supported");
5608 break;
5609 }
5610 }
5611
5612 val = get_param(cmd, "DYN_BW_SGNL");
5613 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005614 switch (get_driver_type(dut)) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005615 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005616 if (strcasecmp(val, "enable") == 0) {
5617 snprintf(buf, sizeof(buf),
5618 "iwpriv %s cwmenable 1", intf);
5619 if (system(buf) != 0) {
5620 sigma_dut_print(dut, DUT_MSG_ERROR,
5621 "iwpriv cwmenable 1 failed");
5622 return 0;
5623 }
5624 } else if (strcasecmp(val, "disable") == 0) {
5625 snprintf(buf, sizeof(buf),
5626 "iwpriv %s cwmenable 0", intf);
5627 if (system(buf) != 0) {
5628 sigma_dut_print(dut, DUT_MSG_ERROR,
5629 "iwpriv cwmenable 0 failed");
5630 return 0;
5631 }
5632 } else {
5633 sigma_dut_print(dut, DUT_MSG_ERROR,
5634 "Unsupported DYN_BW_SGL");
5635 }
5636
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005637 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5638 if (system(buf) != 0) {
5639 sigma_dut_print(dut, DUT_MSG_ERROR,
5640 "Failed to set cts_cbw in DYN_BW_SGNL");
5641 return 0;
5642 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005643 break;
5644 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005645 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005646 ath_config_dyn_bw_sig(dut, intf, val);
5647 break;
5648 default:
5649 sigma_dut_print(dut, DUT_MSG_ERROR,
5650 "Failed to set DYN_BW_SGNL");
5651 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005652 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005653 }
5654
5655 val = get_param(cmd, "RTS_FORCE");
5656 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005657 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005658 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305659 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005660 sigma_dut_print(dut, DUT_MSG_ERROR,
5661 "Failed to set RTS_FORCE 64");
5662 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005663 res = snprintf(buf, sizeof(buf),
5664 "wifitool %s beeliner_fw_test 100 1",
5665 intf);
5666 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005667 sigma_dut_print(dut, DUT_MSG_ERROR,
5668 "wifitool beeliner_fw_test 100 1 failed");
5669 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005670 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305671 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005672 sigma_dut_print(dut, DUT_MSG_ERROR,
5673 "Failed to set RTS_FORCE 2347");
5674 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005675 } else {
5676 send_resp(dut, conn, SIGMA_ERROR,
5677 "ErrorCode,RTS_FORCE value not supported");
5678 return 0;
5679 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005680 }
5681
5682 val = get_param(cmd, "CTS_WIDTH");
5683 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005684 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005685 case DRIVER_WCN:
5686 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5687 send_resp(dut, conn, SIGMA_ERROR,
5688 "ErrorCode,Failed to set CTS_WIDTH");
5689 return 0;
5690 }
5691 break;
5692 case DRIVER_ATHEROS:
5693 ath_set_cts_width(dut, intf, val);
5694 break;
5695 default:
5696 sigma_dut_print(dut, DUT_MSG_ERROR,
5697 "Setting CTS_WIDTH not supported");
5698 break;
5699 }
5700 }
5701
5702 val = get_param(cmd, "BW_SGNL");
5703 if (val) {
5704 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005705 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005706 } else if (strcasecmp(val, "Disable") == 0) {
5707 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005708 } else {
5709 send_resp(dut, conn, SIGMA_ERROR,
5710 "ErrorCode,BW_SGNL value not supported");
5711 return 0;
5712 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005713 }
5714
5715 val = get_param(cmd, "Band");
5716 if (val) {
5717 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5718 /* STA supports all bands by default */
5719 } else {
5720 send_resp(dut, conn, SIGMA_ERROR,
5721 "ErrorCode,Unsupported Band");
5722 return 0;
5723 }
5724 }
5725
5726 val = get_param(cmd, "zero_crc");
5727 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005728 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005729 case DRIVER_ATHEROS:
5730 ath_set_zero_crc(dut, val);
5731 break;
5732 default:
5733 break;
5734 }
5735 }
5736
5737 return 1;
5738}
5739
5740
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005741static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5742{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005743 switch (get_driver_type(dut)) {
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005744#ifdef __linux__
5745 case DRIVER_WIL6210:
5746 return wil6210_set_force_mcs(dut, force, mcs);
5747#endif /* __linux__ */
5748 default:
5749 sigma_dut_print(dut, DUT_MSG_ERROR,
5750 "Unsupported sta_set_force_mcs with the current driver");
5751 return -1;
5752 }
5753}
5754
5755
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005756static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5757{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005758 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005759#ifdef __linux__
5760 case DRIVER_WIL6210:
5761 return wil6210_force_rsn_ie(dut, state);
5762#endif /* __linux__ */
5763 default:
5764 sigma_dut_print(dut, DUT_MSG_ERROR,
5765 "Unsupported sta_60g_force_rsn_ie with the current driver");
5766 return -1;
5767 }
5768}
5769
5770
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005771static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5772 struct sigma_cmd *cmd)
5773{
5774 const char *val;
5775 char buf[100];
5776
5777 val = get_param(cmd, "MSDUSize");
5778 if (val) {
5779 int mtu;
5780
5781 dut->amsdu_size = atoi(val);
5782 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5783 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5784 sigma_dut_print(dut, DUT_MSG_ERROR,
5785 "MSDUSize %d is above max %d or below min %d",
5786 dut->amsdu_size,
5787 IEEE80211_MAX_DATA_LEN_DMG,
5788 IEEE80211_SNAP_LEN_DMG);
5789 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005790 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005791 }
5792
5793 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5794 sigma_dut_print(dut, DUT_MSG_DEBUG,
5795 "Setting amsdu_size to %d", mtu);
5796 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005797 get_station_ifname(dut), mtu);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005798
5799 if (system(buf) != 0) {
5800 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5801 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005802 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005803 }
5804 }
5805
5806 val = get_param(cmd, "BAckRcvBuf");
5807 if (val) {
5808 dut->back_rcv_buf = atoi(val);
5809 if (dut->back_rcv_buf == 0) {
5810 sigma_dut_print(dut, DUT_MSG_ERROR,
5811 "Failed to convert %s or value is 0",
5812 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005813 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005814 }
5815
5816 sigma_dut_print(dut, DUT_MSG_DEBUG,
5817 "Setting BAckRcvBuf to %s", val);
5818 }
5819
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005820 val = get_param(cmd, "MCS_FixedRate");
5821 if (val) {
5822 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5823 sigma_dut_print(dut, DUT_MSG_ERROR,
5824 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005825 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005826 }
5827 }
5828
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005829 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005830}
5831
5832
5833static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5834 struct sigma_cmd *cmd)
5835{
5836 int net_id;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005837 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005838 const char *val;
5839 char buf[100];
5840
5841 dut->mode = SIGMA_MODE_STATION;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02005842 ifname = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005843 if (wpa_command(ifname, "PING") != 0) {
5844 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005845 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005846 }
5847
5848 wpa_command(ifname, "FLUSH");
5849 net_id = add_network_common(dut, conn, ifname, cmd);
5850 if (net_id < 0) {
5851 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5852 return net_id;
5853 }
5854
5855 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5856 if (set_network(ifname, net_id, "mode", "2") < 0) {
5857 sigma_dut_print(dut, DUT_MSG_ERROR,
5858 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005859 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005860 }
5861
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005862 if (set_network(ifname, net_id, "pbss", "1") < 0)
5863 return -2;
5864
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005865 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005866 "Supplicant set network with mode 2. network_id %d",
5867 net_id);
5868
5869 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5870 sigma_dut_print(dut, DUT_MSG_INFO,
5871 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005872 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005873 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005874
5875 val = get_param(cmd, "Security");
5876 if (val && strcasecmp(val, "OPEN") == 0) {
5877 dut->ap_key_mgmt = AP_OPEN;
5878 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5879 sigma_dut_print(dut, DUT_MSG_ERROR,
5880 "Failed to set supplicant to %s security",
5881 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005882 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005883 }
5884 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5885 dut->ap_key_mgmt = AP_WPA2_PSK;
5886 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5887 sigma_dut_print(dut, DUT_MSG_ERROR,
5888 "Failed to set supplicant to %s security",
5889 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005890 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005891 }
5892
5893 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5894 sigma_dut_print(dut, DUT_MSG_ERROR,
5895 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005896 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005897 }
5898 } else if (val) {
5899 sigma_dut_print(dut, DUT_MSG_ERROR,
5900 "Requested Security %s is not supported on 60GHz",
5901 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005902 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005903 }
5904
5905 val = get_param(cmd, "Encrypt");
5906 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5907 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5908 sigma_dut_print(dut, DUT_MSG_ERROR,
5909 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005910 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005911 }
5912 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5913 sigma_dut_print(dut, DUT_MSG_ERROR,
5914 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005915 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005916 }
5917 } else if (val) {
5918 sigma_dut_print(dut, DUT_MSG_ERROR,
5919 "Requested Encrypt %s is not supported on 60 GHz",
5920 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005921 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005922 }
5923
5924 val = get_param(cmd, "PSK");
5925 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5926 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5927 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005928 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005929 }
5930
5931 /* Convert 60G channel to freq */
5932 switch (dut->ap_channel) {
5933 case 1:
5934 val = "58320";
5935 break;
5936 case 2:
5937 val = "60480";
5938 break;
5939 case 3:
5940 val = "62640";
5941 break;
5942 default:
5943 sigma_dut_print(dut, DUT_MSG_ERROR,
5944 "Failed to configure channel %d. Not supported",
5945 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005946 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005947 }
5948
5949 if (set_network(ifname, net_id, "frequency", val) < 0) {
5950 sigma_dut_print(dut, DUT_MSG_ERROR,
5951 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005952 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005953 }
5954
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005955 if (dut->eap_fragment) {
5956 sigma_dut_print(dut, DUT_MSG_DEBUG,
5957 "Set EAP fragment size to 128 bytes.");
5958 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
5959 return ERROR_SEND_STATUS;
5960 }
5961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005962 sigma_dut_print(dut, DUT_MSG_DEBUG,
5963 "Supplicant set network with frequency");
5964
5965 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5966 if (wpa_command(ifname, buf) < 0) {
5967 sigma_dut_print(dut, DUT_MSG_INFO,
5968 "Failed to select network id %d on %s",
5969 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005970 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005971 }
5972
5973 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5974
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005975 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005976}
5977
5978
Lior David67543f52017-01-03 19:04:22 +02005979static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5980{
5981 char buf[128], fname[128];
5982 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005983 int res;
Lior David67543f52017-01-03 19:04:22 +02005984
5985 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5986 sigma_dut_print(dut, DUT_MSG_ERROR,
5987 "failed to get wil6210 debugfs dir");
5988 return -1;
5989 }
5990
Jouni Malinen3aa72862019-05-29 23:14:51 +03005991 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5992 if (res < 0 || res >= sizeof(fname))
5993 return -1;
Lior David67543f52017-01-03 19:04:22 +02005994 f = fopen(fname, "w");
5995 if (!f) {
5996 sigma_dut_print(dut, DUT_MSG_ERROR,
5997 "failed to open: %s", fname);
5998 return -1;
5999 }
6000
6001 fprintf(f, "%d\n", abft_len);
6002 fclose(f);
6003
6004 return 0;
6005}
6006
6007
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02006008int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
6009 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02006010{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006011 switch (get_driver_type(dut)) {
Lior David67543f52017-01-03 19:04:22 +02006012 case DRIVER_WIL6210:
6013 return wil6210_set_abft_len(dut, abft_len);
6014 default:
6015 sigma_dut_print(dut, DUT_MSG_ERROR,
6016 "set abft_len not supported");
6017 return -1;
6018 }
6019}
6020
6021
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006022static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6023 struct sigma_cmd *cmd)
6024{
6025 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006026 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006027
6028 if (dut->dev_role != DEVROLE_PCP) {
6029 send_resp(dut, conn, SIGMA_INVALID,
6030 "ErrorCode,Invalid DevRole");
6031 return 0;
6032 }
6033
6034 val = get_param(cmd, "SSID");
6035 if (val) {
6036 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6037 send_resp(dut, conn, SIGMA_INVALID,
6038 "ErrorCode,Invalid SSID");
6039 return -1;
6040 }
6041
Peng Xub8fc5cc2017-05-10 17:27:28 -07006042 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006043 }
6044
6045 val = get_param(cmd, "CHANNEL");
6046 if (val) {
6047 const char *pos;
6048
6049 dut->ap_channel = atoi(val);
6050 pos = strchr(val, ';');
6051 if (pos) {
6052 pos++;
6053 dut->ap_channel_1 = atoi(pos);
6054 }
6055 }
6056
6057 switch (dut->ap_channel) {
6058 case 1:
6059 case 2:
6060 case 3:
6061 break;
6062 default:
6063 sigma_dut_print(dut, DUT_MSG_ERROR,
6064 "Channel %d is not supported", dut->ap_channel);
6065 send_resp(dut, conn, SIGMA_ERROR,
6066 "Requested channel is not supported");
6067 return -1;
6068 }
6069
6070 val = get_param(cmd, "BCNINT");
6071 if (val)
6072 dut->ap_bcnint = atoi(val);
6073
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006074 val = get_param(cmd, "AllocType");
6075 if (val) {
6076 send_resp(dut, conn, SIGMA_ERROR,
6077 "ErrorCode,AllocType is not supported yet");
6078 return -1;
6079 }
6080
6081 val = get_param(cmd, "PercentBI");
6082 if (val) {
6083 send_resp(dut, conn, SIGMA_ERROR,
6084 "ErrorCode,PercentBI is not supported yet");
6085 return -1;
6086 }
6087
6088 val = get_param(cmd, "CBAPOnly");
6089 if (val) {
6090 send_resp(dut, conn, SIGMA_ERROR,
6091 "ErrorCode,CBAPOnly is not supported yet");
6092 return -1;
6093 }
6094
6095 val = get_param(cmd, "AMPDU");
6096 if (val) {
6097 if (strcasecmp(val, "Enable") == 0)
6098 dut->ap_ampdu = 1;
6099 else if (strcasecmp(val, "Disable") == 0)
6100 dut->ap_ampdu = 2;
6101 else {
6102 send_resp(dut, conn, SIGMA_ERROR,
6103 "ErrorCode,AMPDU value is not Enable nor Disabled");
6104 return -1;
6105 }
6106 }
6107
6108 val = get_param(cmd, "AMSDU");
6109 if (val) {
6110 if (strcasecmp(val, "Enable") == 0)
6111 dut->ap_amsdu = 1;
6112 else if (strcasecmp(val, "Disable") == 0)
6113 dut->ap_amsdu = 2;
6114 }
6115
6116 val = get_param(cmd, "NumMSDU");
6117 if (val) {
6118 send_resp(dut, conn, SIGMA_ERROR,
6119 "ErrorCode, NumMSDU is not supported yet");
6120 return -1;
6121 }
6122
6123 val = get_param(cmd, "ABFTLRang");
6124 if (val) {
6125 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006126 "ABFTLRang parameter %s", val);
6127 if (strcmp(val, "Gt1") == 0)
6128 abft_len = 2; /* 2 slots in this case */
6129 }
6130
6131 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6132 send_resp(dut, conn, SIGMA_ERROR,
6133 "ErrorCode, Can't set ABFT length");
6134 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006135 }
6136
6137 if (sta_pcp_start(dut, conn, cmd) < 0) {
6138 send_resp(dut, conn, SIGMA_ERROR,
6139 "ErrorCode, Can't start PCP role");
6140 return -1;
6141 }
6142
6143 return sta_set_60g_common(dut, conn, cmd);
6144}
6145
6146
6147static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6148 struct sigma_cmd *cmd)
6149{
6150 const char *val = get_param(cmd, "DiscoveryMode");
6151
6152 if (dut->dev_role != DEVROLE_STA) {
6153 send_resp(dut, conn, SIGMA_INVALID,
6154 "ErrorCode,Invalid DevRole");
6155 return 0;
6156 }
6157
6158 if (val) {
6159 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6160 /* Ignore Discovery mode till Driver expose API. */
6161#if 0
6162 if (strcasecmp(val, "1") == 0) {
6163 send_resp(dut, conn, SIGMA_INVALID,
6164 "ErrorCode,DiscoveryMode 1 not supported");
6165 return 0;
6166 }
6167
6168 if (strcasecmp(val, "0") == 0) {
6169 /* OK */
6170 } else {
6171 send_resp(dut, conn, SIGMA_INVALID,
6172 "ErrorCode,DiscoveryMode not supported");
6173 return 0;
6174 }
6175#endif
6176 }
6177
6178 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006179 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006180 return sta_set_60g_common(dut, conn, cmd);
6181}
6182
6183
Jouni Malinenf7222712019-06-13 01:50:21 +03006184static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6185 struct sigma_conn *conn,
6186 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006187{
6188 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006189 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306190
Jouni Malinened77e672018-01-10 16:45:13 +02006191 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006192 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006193 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306194 wpa_command(intf, "DISCONNECT");
6195 return 1;
6196 }
6197
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006198 disconnect_station(dut);
6199 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6200 * due to cached results. */
6201 wpa_command(intf, "SET ignore_old_scan_res 1");
6202 wpa_command(intf, "BSS_FLUSH");
6203 return 1;
6204}
6205
6206
Jouni Malinenf7222712019-06-13 01:50:21 +03006207static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6208 struct sigma_conn *conn,
6209 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006210{
6211 const char *intf = get_param(cmd, "Interface");
6212 const char *bssid = get_param(cmd, "bssid");
6213 const char *val = get_param(cmd, "CHANNEL");
6214 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306215 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306216 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006217 int res;
6218 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006219 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306220 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006221 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006222
6223 if (bssid == NULL) {
6224 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6225 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006226 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006227 }
6228
6229 if (val)
6230 chan = atoi(val);
6231
6232 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6233 /* The current network may be from sta_associate or
6234 * sta_hs2_associate
6235 */
6236 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6237 0 ||
6238 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006239 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006240 }
6241
6242 ctrl = open_wpa_mon(intf);
6243 if (ctrl == NULL) {
6244 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6245 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006246 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006247 }
6248
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006249 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Sunil Duttd30ce092018-01-11 23:56:29 +05306250 sizeof(result)) < 0 ||
6251 strncmp(result, "COMPLETED", 9) != 0) {
6252 sigma_dut_print(dut, DUT_MSG_DEBUG,
6253 "sta_reassoc: Not connected");
6254 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006255 } else if (dut->sta_ft_ds) {
6256 sigma_dut_print(dut, DUT_MSG_DEBUG,
6257 "sta_reassoc: Use FT-over-DS");
6258 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306259 }
6260
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306261 if (dut->rsne_override) {
6262#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006263 if (get_driver_type(dut) == DRIVER_WCN &&
6264 dut->config_rsnie == 0) {
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306265 sta_config_rsnie(dut, 1);
6266 dut->config_rsnie = 1;
6267 }
6268#endif /* NL80211_SUPPORT */
6269 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6270 dut->rsne_override);
6271 if (wpa_command(intf, buf) < 0) {
6272 send_resp(dut, conn, SIGMA_ERROR,
6273 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6274 return 0;
6275 }
6276 }
6277
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006278 if (ft_ds) {
6279 if (chan) {
6280 unsigned int freq;
6281
6282 freq = channel_to_freq(dut, chan);
6283 if (!freq) {
6284 sigma_dut_print(dut, DUT_MSG_ERROR,
6285 "Invalid channel number provided: %d",
6286 chan);
6287 send_resp(dut, conn, SIGMA_INVALID,
6288 "ErrorCode,Invalid channel number");
6289 goto close_mon_conn;
6290 }
6291 res = snprintf(buf, sizeof(buf),
6292 "SCAN TYPE=ONLY freq=%d", freq);
6293 } else {
6294 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6295 }
6296 if (res < 0 || res >= (int) sizeof(buf)) {
6297 send_resp(dut, conn, SIGMA_ERROR,
6298 "ErrorCode,snprintf failed");
6299 goto close_mon_conn;
6300 }
6301 if (wpa_command(intf, buf) < 0) {
6302 sigma_dut_print(dut, DUT_MSG_INFO,
6303 "Failed to start scan");
6304 send_resp(dut, conn, SIGMA_ERROR,
6305 "ErrorCode,scan failed");
6306 goto close_mon_conn;
6307 }
6308
6309 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6310 buf, sizeof(buf));
6311 if (res < 0) {
6312 sigma_dut_print(dut, DUT_MSG_INFO,
6313 "Scan did not complete");
6314 send_resp(dut, conn, SIGMA_ERROR,
6315 "ErrorCode,scan did not complete");
6316 goto close_mon_conn;
6317 }
6318
6319 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6320 if (res > 0 && res < (int) sizeof(buf))
6321 res = wpa_command(intf, buf);
6322
6323 if (res < 0 || res >= (int) sizeof(buf)) {
6324 send_resp(dut, conn, SIGMA_ERROR,
6325 "errorCode,FT_DS command failed");
6326 status = STATUS_SENT_ERROR;
6327 goto close_mon_conn;
6328 }
6329 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006330#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306331 if (chan) {
6332 unsigned int freq;
6333
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006334 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306335 if (!freq) {
6336 sigma_dut_print(dut, DUT_MSG_ERROR,
6337 "Invalid channel number provided: %d",
6338 chan);
6339 send_resp(dut, conn, SIGMA_INVALID,
6340 "ErrorCode,Invalid channel number");
6341 goto close_mon_conn;
6342 }
6343 res = snprintf(buf, sizeof(buf),
6344 "SCAN TYPE=ONLY freq=%d", freq);
6345 } else {
6346 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6347 }
6348 if (res < 0 || res >= (int) sizeof(buf)) {
6349 send_resp(dut, conn, SIGMA_ERROR,
6350 "ErrorCode,snprintf failed");
6351 goto close_mon_conn;
6352 }
6353 if (wpa_command(intf, buf) < 0) {
6354 sigma_dut_print(dut, DUT_MSG_INFO,
6355 "Failed to start scan");
6356 send_resp(dut, conn, SIGMA_ERROR,
6357 "ErrorCode,scan failed");
6358 goto close_mon_conn;
6359 }
6360
6361 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6362 buf, sizeof(buf));
6363 if (res < 0) {
6364 sigma_dut_print(dut, DUT_MSG_INFO,
6365 "Scan did not complete");
6366 send_resp(dut, conn, SIGMA_ERROR,
6367 "ErrorCode,scan did not complete");
6368 goto close_mon_conn;
6369 }
6370
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006371 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6372 < 0) {
6373 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6374 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006375 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306376 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006377 }
6378 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6379 bssid, chan);
6380 if (res > 0 && res < (int) sizeof(buf))
6381 res = wpa_command(intf, buf);
6382
6383 if (res < 0 || res >= (int) sizeof(buf)) {
6384 send_resp(dut, conn, SIGMA_ERROR,
6385 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306386 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006387 }
6388#else /* ANDROID */
6389 sigma_dut_print(dut, DUT_MSG_DEBUG,
6390 "Reassoc using iwpriv - skip chan=%d info",
6391 chan);
6392 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
6393 if (system(buf) != 0) {
6394 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006395 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306396 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006397 }
6398#endif /* ANDROID */
6399 sigma_dut_print(dut, DUT_MSG_INFO,
6400 "sta_reassoc: Run %s successful", buf);
6401 } else if (wpa_command(intf, "REASSOCIATE")) {
6402 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6403 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306404 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006405 }
6406
6407 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6408 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306409 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006410 send_resp(dut, conn, SIGMA_ERROR,
6411 "errorCode,Connection did not complete");
6412 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306413 goto close_mon_conn;
6414 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006415 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006416
Ashwini Patil467efef2017-05-25 12:18:27 +05306417close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006418 wpa_ctrl_detach(ctrl);
6419 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306420 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006421}
6422
6423
6424static void hs2_clear_credentials(const char *intf)
6425{
6426 wpa_command(intf, "REMOVE_CRED all");
6427}
6428
6429
Lior Davidcc88b562017-01-03 18:52:09 +02006430#ifdef __linux__
6431static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6432 unsigned int *aid)
6433{
Lior David0fe101e2017-03-09 16:09:50 +02006434 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006435
Lior David0fe101e2017-03-09 16:09:50 +02006436 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006437}
6438#endif /* __linux__ */
6439
6440
6441static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6442 unsigned int *aid)
6443{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006444 switch (get_driver_type(dut)) {
Lior Davidcc88b562017-01-03 18:52:09 +02006445#ifdef __linux__
6446 case DRIVER_WIL6210:
6447 return wil6210_get_aid(dut, bssid, aid);
6448#endif /* __linux__ */
6449 default:
6450 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6451 return -1;
6452 }
6453}
6454
6455
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006456static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6457 struct sigma_cmd *cmd)
6458{
6459 char buf[MAX_CMD_LEN];
6460 char bss_list[MAX_CMD_LEN];
6461 const char *parameter = get_param(cmd, "Parameter");
6462
6463 if (parameter == NULL)
6464 return -1;
6465
Lior Davidcc88b562017-01-03 18:52:09 +02006466 if (strcasecmp(parameter, "AID") == 0) {
6467 unsigned int aid = 0;
6468 char bssid[20];
6469
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006470 if (get_wpa_status(get_station_ifname(dut), "bssid",
Lior Davidcc88b562017-01-03 18:52:09 +02006471 bssid, sizeof(bssid)) < 0) {
6472 sigma_dut_print(dut, DUT_MSG_ERROR,
6473 "could not get bssid");
6474 return -2;
6475 }
6476
6477 if (sta_get_aid_60g(dut, bssid, &aid))
6478 return -2;
6479
6480 snprintf(buf, sizeof(buf), "aid,%d", aid);
6481 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6482 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6483 return 0;
6484 }
6485
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006486 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6487 char *bss_line;
6488 char *bss_id = NULL;
6489 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306490 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006491
6492 if (ifname == NULL) {
6493 sigma_dut_print(dut, DUT_MSG_INFO,
6494 "For get DiscoveredDevList need Interface name.");
6495 return -1;
6496 }
6497
6498 /*
6499 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6500 * of BSSIDs in "bssid=<BSSID>\n"
6501 */
6502 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6503 bss_list,
6504 sizeof(bss_list)) < 0) {
6505 sigma_dut_print(dut, DUT_MSG_ERROR,
6506 "Failed to get bss list");
6507 return -1;
6508 }
6509
6510 sigma_dut_print(dut, DUT_MSG_DEBUG,
6511 "bss list for ifname:%s is:%s",
6512 ifname, bss_list);
6513
6514 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306515 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006516 while (bss_line) {
6517 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6518 bss_id) {
6519 int len;
6520
6521 len = snprintf(buf + strlen(buf),
6522 sizeof(buf) - strlen(buf),
6523 ",%s", bss_id);
6524 free(bss_id);
6525 bss_id = NULL;
6526 if (len < 0) {
6527 sigma_dut_print(dut,
6528 DUT_MSG_ERROR,
6529 "Failed to read BSSID");
6530 send_resp(dut, conn, SIGMA_ERROR,
6531 "ErrorCode,Failed to read BSS ID");
6532 return 0;
6533 }
6534
6535 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6536 sigma_dut_print(dut,
6537 DUT_MSG_ERROR,
6538 "Response buf too small for list");
6539 send_resp(dut, conn,
6540 SIGMA_ERROR,
6541 "ErrorCode,Response buf too small for list");
6542 return 0;
6543 }
6544 }
6545
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306546 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006547 }
6548
6549 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6550 buf);
6551 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6552 return 0;
6553 }
6554
6555 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6556 return 0;
6557}
6558
6559
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006560static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6561 struct sigma_cmd *cmd)
6562{
6563 char buf[MAX_CMD_LEN];
6564 const char *parameter = get_param(cmd, "Parameter");
6565
6566 if (!parameter)
6567 return -1;
6568
6569 if (strcasecmp(parameter, "RSSI") == 0) {
6570 char rssi[10];
6571
Jouni Malinen016ae6c2019-11-04 17:00:01 +02006572 if (get_wpa_signal_poll(dut, get_station_ifname(dut), "RSSI",
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006573 rssi, sizeof(rssi)) < 0) {
6574 sigma_dut_print(dut, DUT_MSG_ERROR,
6575 "Could not get RSSI");
6576 return -2;
6577 }
6578
6579 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6580 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6581 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6582 return 0;
6583 }
6584
6585 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6586 return 0;
6587}
6588
6589
Jouni Malinenf7222712019-06-13 01:50:21 +03006590static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6591 struct sigma_conn *conn,
6592 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006593{
6594 const char *program = get_param(cmd, "Program");
6595
6596 if (program == NULL)
6597 return -1;
6598
6599 if (strcasecmp(program, "P2PNFC") == 0)
6600 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6601
6602 if (strcasecmp(program, "60ghz") == 0)
6603 return sta_get_parameter_60g(dut, conn, cmd);
6604
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006605 if (strcasecmp(program, "he") == 0)
6606 return sta_get_parameter_he(dut, conn, cmd);
6607
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006608#ifdef ANDROID_NAN
6609 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006610 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006611#endif /* ANDROID_NAN */
6612
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006613#ifdef MIRACAST
6614 if (strcasecmp(program, "WFD") == 0 ||
6615 strcasecmp(program, "DisplayR2") == 0)
6616 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6617#endif /* MIRACAST */
6618
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006619 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6620 return 0;
6621}
6622
6623
6624static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6625 const char *type)
6626{
6627 char buf[100];
6628
6629 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006630 run_iwpriv(dut, intf, "chwidth 2");
6631 run_iwpriv(dut, intf, "mode 11ACVHT80");
6632 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006633 }
6634
6635 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006636 run_iwpriv(dut, intf, "chwidth 0");
6637 run_iwpriv(dut, intf, "mode 11naht40");
6638 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006639 }
6640
6641 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006642 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006643
6644 /* Reset CTS width */
6645 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6646 intf);
6647 if (system(buf) != 0) {
6648 sigma_dut_print(dut, DUT_MSG_ERROR,
6649 "wifitool %s beeliner_fw_test 54 0 failed",
6650 intf);
6651 }
6652
6653 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006654 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006655
6656 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6657 if (system(buf) != 0) {
6658 sigma_dut_print(dut, DUT_MSG_ERROR,
6659 "iwpriv rts failed");
6660 }
6661 }
6662
6663 if (type && strcasecmp(type, "Testbed") == 0) {
6664 dut->testbed_flag_txsp = 1;
6665 dut->testbed_flag_rxsp = 1;
6666 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006667 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006668
6669 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006670 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006671
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006672 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006673
6674 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006675 run_iwpriv(dut, intf, "tx_stbc 0");
6676 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006677
6678 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006679 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006680 }
6681
6682 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006683 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006684 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006685
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006686 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006687 }
6688}
6689
6690
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006691#ifdef NL80211_SUPPORT
6692static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6693 enum he_mcs_config mcs)
6694{
6695 struct nl_msg *msg;
6696 int ret = 0;
6697 struct nlattr *params;
6698 int ifindex;
6699
6700 ifindex = if_nametoindex(intf);
6701 if (ifindex == 0) {
6702 sigma_dut_print(dut, DUT_MSG_ERROR,
6703 "%s: Index for interface %s failed",
6704 __func__, intf);
6705 return -1;
6706 }
6707
6708 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6709 NL80211_CMD_VENDOR)) ||
6710 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6711 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6712 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6713 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6714 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6715 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6716 mcs)) {
6717 sigma_dut_print(dut, DUT_MSG_ERROR,
6718 "%s: err in adding vendor_cmd and vendor_data",
6719 __func__);
6720 nlmsg_free(msg);
6721 return -1;
6722 }
6723 nla_nest_end(msg, params);
6724
6725 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6726 if (ret) {
6727 sigma_dut_print(dut, DUT_MSG_ERROR,
6728 "%s: err in send_and_recv_msgs, ret=%d",
6729 __func__, ret);
6730 }
6731 return ret;
6732}
6733#endif /* NL80211_SUPPORT */
6734
6735
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006736static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6737 const char *intf, int enable)
6738{
6739#ifdef NL80211_SUPPORT
6740 struct nl_msg *msg;
6741 int ret = 0;
6742 struct nlattr *params;
6743 int ifindex;
6744
6745 ifindex = if_nametoindex(intf);
6746 if (ifindex == 0) {
6747 sigma_dut_print(dut, DUT_MSG_ERROR,
6748 "%s: Index for interface %s failed",
6749 __func__, intf);
6750 return -1;
6751 }
6752
6753 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6754 NL80211_CMD_VENDOR)) ||
6755 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6756 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6757 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6758 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6759 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6760 nla_put_u8(msg,
6761 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6762 enable)) {
6763 sigma_dut_print(dut, DUT_MSG_ERROR,
6764 "%s: err in adding vendor_cmd and vendor_data",
6765 __func__);
6766 nlmsg_free(msg);
6767 return -1;
6768 }
6769 nla_nest_end(msg, params);
6770
6771 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6772 if (ret) {
6773 sigma_dut_print(dut, DUT_MSG_ERROR,
6774 "%s: err in send_and_recv_msgs, ret=%d",
6775 __func__, ret);
6776 }
6777 return ret;
6778#else /* NL80211_SUPPORT */
6779 sigma_dut_print(dut, DUT_MSG_ERROR,
6780 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6781 return -1;
6782#endif /* NL80211_SUPPORT */
6783}
6784
6785
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006786static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6787 const char *intf, int enable)
6788{
6789#ifdef NL80211_SUPPORT
6790 struct nl_msg *msg;
6791 int ret = 0;
6792 struct nlattr *params;
6793 int ifindex;
6794
6795 ifindex = if_nametoindex(intf);
6796 if (ifindex == 0) {
6797 sigma_dut_print(dut, DUT_MSG_ERROR,
6798 "%s: Index for interface %s failed",
6799 __func__, intf);
6800 return -1;
6801 }
6802
6803 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6804 NL80211_CMD_VENDOR)) ||
6805 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6806 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6807 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6808 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6809 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6810 nla_put_u8(msg,
6811 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6812 enable)) {
6813 sigma_dut_print(dut, DUT_MSG_ERROR,
6814 "%s: err in adding vendor_cmd and vendor_data",
6815 __func__);
6816 nlmsg_free(msg);
6817 return -1;
6818 }
6819 nla_nest_end(msg, params);
6820
6821 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6822 if (ret) {
6823 sigma_dut_print(dut, DUT_MSG_ERROR,
6824 "%s: err in send_and_recv_msgs, ret=%d",
6825 __func__, ret);
6826 }
6827 return ret;
6828#else /* NL80211_SUPPORT */
6829 sigma_dut_print(dut, DUT_MSG_ERROR,
6830 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6831 return -1;
6832#endif /* NL80211_SUPPORT */
6833}
6834
6835
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006836#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006837
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006838static int sta_set_he_testbed_def(struct sigma_dut *dut,
6839 const char *intf, int cfg)
6840{
6841 struct nl_msg *msg;
6842 int ret = 0;
6843 struct nlattr *params;
6844 int ifindex;
6845
6846 ifindex = if_nametoindex(intf);
6847 if (ifindex == 0) {
6848 sigma_dut_print(dut, DUT_MSG_ERROR,
6849 "%s: Index for interface %s failed",
6850 __func__, intf);
6851 return -1;
6852 }
6853
6854 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6855 NL80211_CMD_VENDOR)) ||
6856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6857 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6858 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6859 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6860 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6861 nla_put_u8(msg,
6862 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6863 cfg)) {
6864 sigma_dut_print(dut, DUT_MSG_ERROR,
6865 "%s: err in adding vendor_cmd and vendor_data",
6866 __func__);
6867 nlmsg_free(msg);
6868 return -1;
6869 }
6870 nla_nest_end(msg, params);
6871
6872 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6873 if (ret) {
6874 sigma_dut_print(dut, DUT_MSG_ERROR,
6875 "%s: err in send_and_recv_msgs, ret=%d",
6876 __func__, ret);
6877 }
6878 return ret;
6879}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006880
6881
6882static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
6883{
6884 struct nl_msg *msg;
6885 int ret = 0;
6886 struct nlattr *params;
6887 int ifindex;
6888
6889 ifindex = if_nametoindex(intf);
6890 if (ifindex == 0) {
6891 sigma_dut_print(dut, DUT_MSG_ERROR,
6892 "%s: Index for interface %s failed",
6893 __func__, intf);
6894 return -1;
6895 }
6896
6897 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6898 NL80211_CMD_VENDOR)) ||
6899 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6900 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6901 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6902 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6903 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6904 nla_put_u8(msg,
6905 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
6906 cfg)) {
6907 sigma_dut_print(dut, DUT_MSG_ERROR,
6908 "%s: err in adding vendor_cmd and vendor_data",
6909 __func__);
6910 nlmsg_free(msg);
6911 return -1;
6912 }
6913 nla_nest_end(msg, params);
6914
6915 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6916 if (ret) {
6917 sigma_dut_print(dut, DUT_MSG_ERROR,
6918 "%s: err in send_and_recv_msgs, ret=%d",
6919 __func__, ret);
6920 }
6921 return ret;
6922}
6923
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006924#endif /* NL80211_SUPPORT */
6925
6926
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006927static int sta_set_addba_buf_size(struct sigma_dut *dut,
6928 const char *intf, int bufsize)
6929{
6930#ifdef NL80211_SUPPORT
6931 struct nl_msg *msg;
6932 int ret = 0;
6933 struct nlattr *params;
6934 int ifindex;
6935
6936 ifindex = if_nametoindex(intf);
6937 if (ifindex == 0) {
6938 sigma_dut_print(dut, DUT_MSG_ERROR,
6939 "%s: Index for interface %s failed",
6940 __func__, intf);
6941 return -1;
6942 }
6943
6944 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6945 NL80211_CMD_VENDOR)) ||
6946 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6947 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6948 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6949 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6950 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006951 nla_put_u16(msg,
6952 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6953 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006954 sigma_dut_print(dut, DUT_MSG_ERROR,
6955 "%s: err in adding vendor_cmd and vendor_data",
6956 __func__);
6957 nlmsg_free(msg);
6958 return -1;
6959 }
6960 nla_nest_end(msg, params);
6961
6962 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6963 if (ret) {
6964 sigma_dut_print(dut, DUT_MSG_ERROR,
6965 "%s: err in send_and_recv_msgs, ret=%d",
6966 __func__, ret);
6967 }
6968 return ret;
6969#else /* NL80211_SUPPORT */
6970 sigma_dut_print(dut, DUT_MSG_ERROR,
6971 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6972 return -1;
6973#endif /* NL80211_SUPPORT */
6974}
6975
6976
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006977static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6978 int enable)
6979{
6980#ifdef NL80211_SUPPORT
6981 struct nl_msg *msg;
6982 int ret = 0;
6983 struct nlattr *params;
6984 int ifindex;
6985
6986 ifindex = if_nametoindex(intf);
6987 if (ifindex == 0) {
6988 sigma_dut_print(dut, DUT_MSG_ERROR,
6989 "%s: Index for interface %s failed",
6990 __func__, intf);
6991 return -1;
6992 }
6993
6994 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6995 NL80211_CMD_VENDOR)) ||
6996 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6997 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6998 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6999 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7000 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7001 nla_put_u8(msg,
7002 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
7003 enable)) {
7004 sigma_dut_print(dut, DUT_MSG_ERROR,
7005 "%s: err in adding vendor_cmd and vendor_data",
7006 __func__);
7007 nlmsg_free(msg);
7008 return -1;
7009 }
7010 nla_nest_end(msg, params);
7011
7012 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7013 if (ret) {
7014 sigma_dut_print(dut, DUT_MSG_ERROR,
7015 "%s: err in send_and_recv_msgs, ret=%d",
7016 __func__, ret);
7017 }
7018 return ret;
7019#else /* NL80211_SUPPORT */
7020 sigma_dut_print(dut, DUT_MSG_ERROR,
7021 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7022 return -1;
7023#endif /* NL80211_SUPPORT */
7024}
7025
7026
Arif Hussain9765f7d2018-07-03 08:28:26 -07007027static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7028 int val)
7029{
7030#ifdef NL80211_SUPPORT
7031 struct nl_msg *msg;
7032 int ret = 0;
7033 struct nlattr *params;
7034 int ifindex;
7035
7036 ifindex = if_nametoindex(intf);
7037 if (ifindex == 0) {
7038 sigma_dut_print(dut, DUT_MSG_ERROR,
7039 "%s: Index for interface %s failed, val:%d",
7040 __func__, intf, val);
7041 return -1;
7042 }
7043
7044 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7045 NL80211_CMD_VENDOR)) ||
7046 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7047 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7048 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7049 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7050 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7051 nla_put_u8(msg,
7052 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7053 val)) {
7054 sigma_dut_print(dut, DUT_MSG_ERROR,
7055 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7056 __func__, val);
7057 nlmsg_free(msg);
7058 return -1;
7059 }
7060 nla_nest_end(msg, params);
7061
7062 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7063 if (ret) {
7064 sigma_dut_print(dut, DUT_MSG_ERROR,
7065 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7066 __func__, ret, val);
7067 }
7068 return ret;
7069#else /* NL80211_SUPPORT */
7070 sigma_dut_print(dut, DUT_MSG_ERROR,
7071 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7072 return -1;
7073#endif /* NL80211_SUPPORT */
7074}
7075
7076
Arif Hussain68d23f52018-07-11 13:39:08 -07007077#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007078static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7079 enum qca_wlan_he_mac_padding_dur val)
7080{
Arif Hussain68d23f52018-07-11 13:39:08 -07007081 struct nl_msg *msg;
7082 int ret = 0;
7083 struct nlattr *params;
7084 int ifindex;
7085
7086 ifindex = if_nametoindex(intf);
7087 if (ifindex == 0) {
7088 sigma_dut_print(dut, DUT_MSG_ERROR,
7089 "%s: Index for interface %s failed, val:%d",
7090 __func__, intf, val);
7091 return -1;
7092 }
7093
7094 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7095 NL80211_CMD_VENDOR)) ||
7096 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7097 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7098 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7099 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7100 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7101 nla_put_u8(msg,
7102 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7103 val)) {
7104 sigma_dut_print(dut, DUT_MSG_ERROR,
7105 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7106 __func__, val);
7107 nlmsg_free(msg);
7108 return -1;
7109 }
7110 nla_nest_end(msg, params);
7111
7112 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7113 if (ret) {
7114 sigma_dut_print(dut, DUT_MSG_ERROR,
7115 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7116 __func__, ret, val);
7117 }
7118 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007119}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007120#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007121
7122
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007123static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7124 int val)
7125{
7126#ifdef NL80211_SUPPORT
7127 struct nl_msg *msg;
7128 int ret = 0;
7129 struct nlattr *params;
7130 int ifindex;
7131
7132 ifindex = if_nametoindex(intf);
7133 if (ifindex == 0) {
7134 sigma_dut_print(dut, DUT_MSG_ERROR,
7135 "%s: Index for interface %s failed, val:%d",
7136 __func__, intf, val);
7137 return -1;
7138 }
7139
7140 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7141 NL80211_CMD_VENDOR)) ||
7142 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7143 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7144 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7145 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7146 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7147 nla_put_u8(msg,
7148 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7149 val)) {
7150 sigma_dut_print(dut, DUT_MSG_ERROR,
7151 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7152 __func__, val);
7153 nlmsg_free(msg);
7154 return -1;
7155 }
7156 nla_nest_end(msg, params);
7157
7158 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7159 if (ret) {
7160 sigma_dut_print(dut, DUT_MSG_ERROR,
7161 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7162 __func__, ret, val);
7163 }
7164 return ret;
7165#else /* NL80211_SUPPORT */
7166 sigma_dut_print(dut, DUT_MSG_ERROR,
7167 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7168 return -1;
7169#endif /* NL80211_SUPPORT */
7170}
7171
7172
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007173#ifdef NL80211_SUPPORT
7174static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7175{
7176 struct nl_msg *msg;
7177 int ret = 0;
7178 struct nlattr *params;
7179 int ifindex;
7180
7181 ifindex = if_nametoindex(intf);
7182 if (ifindex == 0) {
7183 sigma_dut_print(dut, DUT_MSG_ERROR,
7184 "%s: Index for interface %s failed",
7185 __func__, intf);
7186 return -1;
7187 }
7188
7189 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7190 NL80211_CMD_VENDOR)) ||
7191 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7192 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7193 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7194 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7195 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7196 nla_put_flag(msg,
7197 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7198 sigma_dut_print(dut, DUT_MSG_ERROR,
7199 "%s: err in adding vendor_cmd and vendor_data",
7200 __func__);
7201 nlmsg_free(msg);
7202 return -1;
7203 }
7204 nla_nest_end(msg, params);
7205
7206 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7207 if (ret) {
7208 sigma_dut_print(dut, DUT_MSG_ERROR,
7209 "%s: err in send_and_recv_msgs, ret=%d",
7210 __func__, ret);
7211 }
7212 return ret;
7213}
7214#endif /* NL80211_SUPPORT */
7215
7216
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007217static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7218 int val)
7219{
7220#ifdef NL80211_SUPPORT
7221 struct nl_msg *msg;
7222 int ret = 0;
7223 struct nlattr *params;
7224 int ifindex;
7225
7226 ifindex = if_nametoindex(intf);
7227 if (ifindex == 0) {
7228 sigma_dut_print(dut, DUT_MSG_ERROR,
7229 "%s: Index for interface %s failed, val:%d",
7230 __func__, intf, val);
7231 return -1;
7232 }
7233
7234 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7235 NL80211_CMD_VENDOR)) ||
7236 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7237 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7238 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7239 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7240 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7241 nla_put_u8(msg,
7242 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7243 val)) {
7244 sigma_dut_print(dut, DUT_MSG_ERROR,
7245 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7246 __func__, val);
7247 nlmsg_free(msg);
7248 return -1;
7249 }
7250 nla_nest_end(msg, params);
7251
7252 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7253 if (ret) {
7254 sigma_dut_print(dut, DUT_MSG_ERROR,
7255 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7256 __func__, ret, val);
7257 }
7258 return ret;
7259#else /* NL80211_SUPPORT */
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7262 return -1;
7263#endif /* NL80211_SUPPORT */
7264}
7265
7266
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007267static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7268 int val)
7269{
7270#ifdef NL80211_SUPPORT
7271 struct nl_msg *msg;
7272 int ret = 0;
7273 struct nlattr *params;
7274 int ifindex;
7275
7276 ifindex = if_nametoindex(intf);
7277 if (ifindex == 0) {
7278 sigma_dut_print(dut, DUT_MSG_ERROR,
7279 "%s: Index for interface %s failed, val:%d",
7280 __func__, intf, val);
7281 return -1;
7282 }
7283
7284 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7285 NL80211_CMD_VENDOR)) ||
7286 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7287 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7288 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7289 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7290 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7291 nla_put_u8(msg,
7292 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7293 val)) {
7294 sigma_dut_print(dut, DUT_MSG_ERROR,
7295 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7296 __func__, val);
7297 nlmsg_free(msg);
7298 return -1;
7299 }
7300 nla_nest_end(msg, params);
7301
7302 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7303 if (ret) {
7304 sigma_dut_print(dut, DUT_MSG_ERROR,
7305 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7306 __func__, ret, val);
7307 }
7308 return ret;
7309#else /* NL80211_SUPPORT */
7310 sigma_dut_print(dut, DUT_MSG_ERROR,
7311 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7312 return -1;
7313#endif /* NL80211_SUPPORT */
7314}
7315
7316
Arif Hussain480d5f42019-03-12 14:40:42 -07007317static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7318 int val)
7319{
7320#ifdef NL80211_SUPPORT
7321 struct nl_msg *msg;
7322 int ret;
7323 struct nlattr *params;
7324 int ifindex;
7325
7326 ifindex = if_nametoindex(intf);
7327 if (ifindex == 0) {
7328 sigma_dut_print(dut, DUT_MSG_ERROR,
7329 "%s: Index for interface %s failed, val:%d",
7330 __func__, intf, val);
7331 return -1;
7332 }
7333
7334 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7335 NL80211_CMD_VENDOR)) ||
7336 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7337 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7338 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7339 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7340 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7341 nla_put_u8(msg,
7342 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7343 val)) {
7344 sigma_dut_print(dut, DUT_MSG_ERROR,
7345 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7346 __func__, val);
7347 nlmsg_free(msg);
7348 return -1;
7349 }
7350 nla_nest_end(msg, params);
7351
7352 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7353 if (ret) {
7354 sigma_dut_print(dut, DUT_MSG_ERROR,
7355 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7356 __func__, ret, val);
7357 }
7358 return ret;
7359#else /* NL80211_SUPPORT */
7360 sigma_dut_print(dut, DUT_MSG_ERROR,
7361 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7362 return -1;
7363#endif /* NL80211_SUPPORT */
7364}
7365
7366
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007367static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7368 const char *type)
7369{
7370 char buf[60];
7371
7372 if (dut->program == PROGRAM_HE) {
7373 /* resetting phymode to auto in case of HE program */
7374 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7375 if (system(buf) != 0) {
7376 sigma_dut_print(dut, DUT_MSG_ERROR,
7377 "iwpriv %s setphymode failed", intf);
7378 }
7379
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007380 /* reset the rate to Auto rate */
7381 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7382 intf);
7383 if (system(buf) != 0) {
7384 sigma_dut_print(dut, DUT_MSG_ERROR,
7385 "iwpriv %s set_11ax_rate 0xff failed",
7386 intf);
7387 }
7388
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007389 /* reset the LDPC setting */
7390 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7391 if (system(buf) != 0) {
7392 sigma_dut_print(dut, DUT_MSG_ERROR,
7393 "iwpriv %s ldpc 1 failed", intf);
7394 }
7395
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007396 /* reset the power save setting */
7397 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7398 if (system(buf) != 0) {
7399 sigma_dut_print(dut, DUT_MSG_ERROR,
7400 "iwpriv %s setPower 2 failed", intf);
7401 }
7402
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007403 /* remove all network profiles */
7404 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007405
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007406 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7407 sta_set_addba_buf_size(dut, intf, 64);
7408
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007409#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007410 /* Reset the device HE capabilities to its default supported
7411 * configuration. */
7412 sta_set_he_testbed_def(dut, intf, 0);
7413
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007414 /* Disable noackpolicy for all AC */
7415 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7416 sigma_dut_print(dut, DUT_MSG_ERROR,
7417 "Disable of noackpolicy for all AC failed");
7418 }
7419#endif /* NL80211_SUPPORT */
7420
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007421 /* Enable WMM by default */
7422 if (wcn_sta_set_wmm(dut, intf, "on")) {
7423 sigma_dut_print(dut, DUT_MSG_ERROR,
7424 "Enable of WMM in sta_reset_default_wcn failed");
7425 }
7426
7427 /* Disable ADDBA_REJECT by default */
7428 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7429 sigma_dut_print(dut, DUT_MSG_ERROR,
7430 "Disable of addba_reject in sta_reset_default_wcn failed");
7431 }
7432
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007433 /* Enable sending of ADDBA by default */
7434 if (nlvendor_config_send_addba(dut, intf, 1)) {
7435 sigma_dut_print(dut, DUT_MSG_ERROR,
7436 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7437 }
7438
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007439 /* Enable AMPDU by default */
7440 iwpriv_sta_set_ampdu(dut, intf, 1);
7441
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007442#ifdef NL80211_SUPPORT
7443 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
7444 sigma_dut_print(dut, DUT_MSG_ERROR,
7445 "Set LTF config to default in sta_reset_default_wcn failed");
7446 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007447
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007448 /* set the beamformee NSTS(maximum number of
7449 * space-time streams) to default DUT config
7450 */
7451 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007452 sigma_dut_print(dut, DUT_MSG_ERROR,
7453 "Failed to set BeamformeeSTS");
7454 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007455
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007456 if (sta_set_mac_padding_duration(
7457 dut, intf,
7458 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007459 sigma_dut_print(dut, DUT_MSG_ERROR,
7460 "Failed to set MAC padding duration");
7461 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007462
7463 if (sta_set_mu_edca_override(dut, intf, 0)) {
7464 sigma_dut_print(dut, DUT_MSG_ERROR,
7465 "ErrorCode,Failed to set MU EDCA override disable");
7466 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007467
7468 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7469 sigma_dut_print(dut, DUT_MSG_ERROR,
7470 "Failed to set OM ctrl supp");
7471 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007472
7473 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7474 sigma_dut_print(dut, DUT_MSG_ERROR,
7475 "Failed to set Tx SU PPDU enable");
7476 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007477
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007478 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7479 sigma_dut_print(dut, DUT_MSG_ERROR,
7480 "failed to send TB PPDU Tx cfg");
7481 }
7482
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007483 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7484 sigma_dut_print(dut, DUT_MSG_ERROR,
7485 "Failed to set OM ctrl reset");
7486 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007487
7488 /* +HTC-HE support default on */
7489 if (sta_set_he_htc_supp(dut, intf, 1)) {
7490 sigma_dut_print(dut, DUT_MSG_ERROR,
7491 "Setting of +HTC-HE support failed");
7492 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007493#endif /* NL80211_SUPPORT */
7494
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007495 if (sta_set_tx_beamformee(dut, intf, 1)) {
7496 sigma_dut_print(dut, DUT_MSG_ERROR,
7497 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7498 }
7499
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007500 /* Set nss to 1 and MCS 0-7 in case of testbed */
7501 if (type && strcasecmp(type, "Testbed") == 0) {
7502#ifdef NL80211_SUPPORT
7503 int ret;
7504#endif /* NL80211_SUPPORT */
7505
7506 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7507 if (system(buf) != 0) {
7508 sigma_dut_print(dut, DUT_MSG_ERROR,
7509 "iwpriv %s nss failed", intf);
7510 }
7511
7512#ifdef NL80211_SUPPORT
7513 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7514 if (ret) {
7515 sigma_dut_print(dut, DUT_MSG_ERROR,
7516 "Setting of MCS failed, ret:%d",
7517 ret);
7518 }
7519#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007520
7521 /* Disable STBC as default */
7522 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007523
7524 /* Disable AMSDU as default */
7525 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007526
7527#ifdef NL80211_SUPPORT
7528 /* HE fragmentation default off */
7529 if (sta_set_he_fragmentation(dut, intf,
7530 HE_FRAG_DISABLE)) {
7531 sigma_dut_print(dut, DUT_MSG_ERROR,
7532 "Setting of HE fragmentation failed");
7533 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007534
7535 /* set the beamformee NSTS(maximum number of
7536 * space-time streams) to default testbed config
7537 */
7538 if (sta_set_beamformee_sts(dut, intf, 3)) {
7539 sigma_dut_print(dut, DUT_MSG_ERROR,
7540 "Failed to set BeamformeeSTS");
7541 }
7542
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007543 /* +HTC-HE support default off */
7544 if (sta_set_he_htc_supp(dut, intf, 0)) {
7545 sigma_dut_print(dut, DUT_MSG_ERROR,
7546 "Setting of +HTC-HE support failed");
7547 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007548
7549 /* Set device HE capabilities to testbed default
7550 * configuration. */
7551 if (sta_set_he_testbed_def(dut, intf, 1)) {
7552 sigma_dut_print(dut, DUT_MSG_DEBUG,
7553 "Failed to set HE defaults");
7554 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007555
7556 /* Disable VHT support in 2.4 GHz for testbed */
7557 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007558#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007559
7560 /* Enable WEP/TKIP with HE capability in testbed */
7561 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7562 sigma_dut_print(dut, DUT_MSG_ERROR,
7563 "Enabling HE config with WEP/TKIP failed");
7564 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007565 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007566
7567 /* Defaults in case of DUT */
7568 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007569 /* Enable STBC by default */
7570 wcn_sta_set_stbc(dut, intf, "1");
7571
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007572 /* set nss to 2 */
7573 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7574 if (system(buf) != 0) {
7575 sigma_dut_print(dut, DUT_MSG_ERROR,
7576 "iwpriv %s nss 2 failed", intf);
7577 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007578 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007579
7580#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007581 /* Set HE_MCS to 0-11 */
7582 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007583 sigma_dut_print(dut, DUT_MSG_ERROR,
7584 "Setting of MCS failed");
7585 }
7586#endif /* NL80211_SUPPORT */
7587
7588 /* Disable WEP/TKIP with HE capability in DUT */
7589 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7590 sigma_dut_print(dut, DUT_MSG_ERROR,
7591 "Enabling HE config with WEP/TKIP failed");
7592 }
7593 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007594 }
7595}
7596
7597
Jouni Malinenf7222712019-06-13 01:50:21 +03007598static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7599 struct sigma_conn *conn,
7600 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007601{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007602 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007603 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007604 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007605 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307606 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007607
Jouni Malinenb21f0542019-11-04 17:53:38 +02007608 if (dut->station_ifname_2g &&
7609 strcmp(dut->station_ifname_2g, intf) == 0)
7610 dut->use_5g = 0;
7611 else if (dut->station_ifname_5g &&
7612 strcmp(dut->station_ifname_5g, intf) == 0)
7613 dut->use_5g = 1;
7614
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007615 if (!program)
7616 program = get_param(cmd, "prog");
7617 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007618 dut->device_type = STA_unknown;
7619 type = get_param(cmd, "type");
7620 if (type && strcasecmp(type, "Testbed") == 0)
7621 dut->device_type = STA_testbed;
7622 if (type && strcasecmp(type, "DUT") == 0)
7623 dut->device_type = STA_dut;
7624
7625 if (dut->program == PROGRAM_TDLS) {
7626 /* Clear TDLS testing mode */
7627 wpa_command(intf, "SET tdls_disabled 0");
7628 wpa_command(intf, "SET tdls_testing 0");
7629 dut->no_tpk_expiration = 0;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007630 if (get_driver_type(dut) == DRIVER_WCN) {
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307631 /* Enable the WCN driver in TDLS Explicit trigger mode
7632 */
7633 wpa_command(intf, "SET tdls_external_control 0");
7634 wpa_command(intf, "SET tdls_trigger_control 0");
7635 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007636 }
7637
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007638#ifdef MIRACAST
7639 if (dut->program == PROGRAM_WFD ||
7640 dut->program == PROGRAM_DISPLAYR2)
7641 miracast_sta_reset_default(dut, conn, cmd);
7642#endif /* MIRACAST */
7643
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007644 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007645 case DRIVER_ATHEROS:
7646 sta_reset_default_ath(dut, intf, type);
7647 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007648 case DRIVER_WCN:
7649 sta_reset_default_wcn(dut, intf, type);
7650 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007651 default:
7652 break;
7653 }
7654
7655#ifdef ANDROID_NAN
7656 if (dut->program == PROGRAM_NAN)
7657 nan_cmd_sta_reset_default(dut, conn, cmd);
7658#endif /* ANDROID_NAN */
7659
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307660 if (dut->program == PROGRAM_LOC &&
7661 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7662 return ERROR_SEND_STATUS;
7663
Jouni Malinenba630452018-06-22 11:49:59 +03007664 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007665 unlink("SP/wi-fi.org/pps.xml");
7666 if (system("rm -r SP/*") != 0) {
7667 }
7668 unlink("next-client-cert.pem");
7669 unlink("next-client-key.pem");
7670 }
7671
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007672 /* For WPS program of the 60 GHz band the band type needs to be saved */
7673 if (dut->program == PROGRAM_WPS) {
7674 if (band && strcasecmp(band, "60GHz") == 0) {
7675 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007676 /* For 60 GHz enable WPS for WPS TCs */
7677 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007678 } else {
7679 dut->band = WPS_BAND_NON_60G;
7680 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007681 } else if (dut->program == PROGRAM_60GHZ) {
7682 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7683 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007684 }
7685
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007686 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007687 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007688 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007689
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007690 sigma_dut_print(dut, DUT_MSG_INFO,
7691 "WPS 60 GHz program, wps_disable = %d",
7692 dut->wps_disable);
7693
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007694 if (!dev_role) {
7695 send_resp(dut, conn, SIGMA_ERROR,
7696 "errorCode,Missing DevRole argument");
7697 return 0;
7698 }
7699
7700 if (strcasecmp(dev_role, "STA") == 0)
7701 dut->dev_role = DEVROLE_STA;
7702 else if (strcasecmp(dev_role, "PCP") == 0)
7703 dut->dev_role = DEVROLE_PCP;
7704 else {
7705 send_resp(dut, conn, SIGMA_ERROR,
7706 "errorCode,Unknown DevRole");
7707 return 0;
7708 }
7709
7710 if (dut->device_type == STA_unknown) {
7711 sigma_dut_print(dut, DUT_MSG_ERROR,
7712 "Device type is not STA testbed or DUT");
7713 send_resp(dut, conn, SIGMA_ERROR,
7714 "errorCode,Unknown device type");
7715 return 0;
7716 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007717
7718 sigma_dut_print(dut, DUT_MSG_DEBUG,
7719 "Setting msdu_size to MAX: 7912");
7720 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007721 get_station_ifname(dut));
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007722
7723 if (system(buf) != 0) {
7724 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7725 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007726 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007727 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007728
7729 if (sta_set_force_mcs(dut, 0, 1)) {
7730 sigma_dut_print(dut, DUT_MSG_ERROR,
7731 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007732 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007733 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007734 }
7735
7736 wpa_command(intf, "WPS_ER_STOP");
7737 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307738 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007739 wpa_command(intf, "SET radio_disabled 0");
7740
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007741 dut->wps_forced_version = 0;
7742
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007743 if (dut->wsc_fragment) {
7744 dut->wsc_fragment = 0;
7745 wpa_command(intf, "SET device_name Test client");
7746 wpa_command(intf, "SET manufacturer ");
7747 wpa_command(intf, "SET model_name ");
7748 wpa_command(intf, "SET model_number ");
7749 wpa_command(intf, "SET serial_number ");
7750 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007751 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7752 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7753 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7754 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007755
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007756 if (dut->tmp_mac_addr && dut->set_macaddr) {
7757 dut->tmp_mac_addr = 0;
7758 if (system(dut->set_macaddr) != 0) {
7759 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7760 "temporary MAC address");
7761 }
7762 }
7763
7764 set_ps(intf, dut, 0);
7765
Jouni Malinenba630452018-06-22 11:49:59 +03007766 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7767 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007768 wpa_command(intf, "SET interworking 1");
7769 wpa_command(intf, "SET hs20 1");
7770 }
7771
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007772 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007773 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007774 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007775 wpa_command(intf, "SET pmf 1");
7776 } else {
7777 wpa_command(intf, "SET pmf 0");
7778 }
7779
7780 hs2_clear_credentials(intf);
7781 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7782 wpa_command(intf, "SET access_network_type 15");
7783
7784 static_ip_file(0, NULL, NULL, NULL);
7785 kill_dhcp_client(dut, intf);
7786 clear_ip_addr(dut, intf);
7787
7788 dut->er_oper_performed = 0;
7789 dut->er_oper_bssid[0] = '\0';
7790
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007791 if (dut->program == PROGRAM_LOC) {
7792 /* Disable Interworking by default */
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007793 wpa_command(get_station_ifname(dut), "SET interworking 0");
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007794 }
7795
Ashwini Patil00402582017-04-13 12:29:39 +05307796 if (dut->program == PROGRAM_MBO) {
7797 free(dut->non_pref_ch_list);
7798 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307799 free(dut->btm_query_cand_list);
7800 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307801 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307802 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307803 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307804 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307805 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307806 }
7807
Jouni Malinen3c367e82017-06-23 17:01:47 +03007808 free(dut->rsne_override);
7809 dut->rsne_override = NULL;
7810
Jouni Malinen68143132017-09-02 02:34:08 +03007811 free(dut->sae_commit_override);
7812 dut->sae_commit_override = NULL;
Jouni Malinen4b3769d2019-10-10 16:20:29 +03007813 wpa_command(intf, "SET sae_pmkid_in_assoc 0");
Jouni Malinen68143132017-09-02 02:34:08 +03007814
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007815 dut->sta_associate_wait_connect = 0;
7816 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007817 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007818 dut->sta_tod_policy = 0;
7819
Jouni Malinend86e5822017-08-29 03:55:32 +03007820 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007821 free(dut->dpp_peer_uri);
7822 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007823 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007824 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007825
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007826 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7827
vamsi krishnaa2799492017-12-05 14:28:01 +05307828 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307829 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307830 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307831 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7832 dut->fils_hlp = 0;
7833#ifdef ANDROID
7834 hlp_thread_cleanup(dut);
7835#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307836 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307837
Jouni Malinen8179fee2019-03-28 03:19:47 +02007838 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007839 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007840
Sunil Dutt076081f2018-02-05 19:45:50 +05307841#ifdef NL80211_SUPPORT
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007842 if (get_driver_type(dut) == DRIVER_WCN &&
Sunil Dutt44595082018-02-12 19:41:45 +05307843 dut->config_rsnie == 1) {
7844 dut->config_rsnie = 0;
7845 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307846 }
7847#endif /* NL80211_SUPPORT */
7848
Sunil Duttfebf8a82018-02-09 18:50:13 +05307849 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7850 dut->dev_role = DEVROLE_STA_CFON;
7851 return sta_cfon_reset_default(dut, conn, cmd);
7852 }
7853
Jouni Malinen439352d2018-09-13 03:42:23 +03007854 wpa_command(intf, "SET setband AUTO");
7855
Sunil Duttfebf8a82018-02-09 18:50:13 +05307856 if (dut->program != PROGRAM_VHT)
7857 return cmd_sta_p2p_reset(dut, conn, cmd);
7858
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007859 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007860}
7861
7862
Jouni Malinenf7222712019-06-13 01:50:21 +03007863static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7864 struct sigma_conn *conn,
7865 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007866{
7867 const char *program = get_param(cmd, "Program");
7868
7869 if (program == NULL)
7870 return -1;
7871#ifdef ANDROID_NAN
7872 if (strcasecmp(program, "NAN") == 0)
7873 return nan_cmd_sta_get_events(dut, conn, cmd);
7874#endif /* ANDROID_NAN */
7875 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7876 return 0;
7877}
7878
7879
Jouni Malinen82905202018-04-29 17:20:10 +03007880static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7881 struct sigma_cmd *cmd)
7882{
7883 const char *url = get_param(cmd, "url");
7884 const char *method = get_param(cmd, "method");
7885 pid_t pid;
7886 int status;
7887
7888 if (!url || !method)
7889 return -1;
7890
7891 /* TODO: Add support for method,post */
7892 if (strcasecmp(method, "get") != 0) {
7893 send_resp(dut, conn, SIGMA_ERROR,
7894 "ErrorCode,Unsupported method");
7895 return 0;
7896 }
7897
7898 pid = fork();
7899 if (pid < 0) {
7900 perror("fork");
7901 return -1;
7902 }
7903
7904 if (pid == 0) {
7905 char * argv[5] = { "wget", "-O", "/dev/null",
7906 (char *) url, NULL };
7907
7908 execv("/usr/bin/wget", argv);
7909 perror("execv");
7910 exit(0);
7911 return -1;
7912 }
7913
7914 if (waitpid(pid, &status, 0) < 0) {
7915 perror("waitpid");
7916 return -1;
7917 }
7918
7919 if (WIFEXITED(status)) {
7920 const char *errmsg;
7921
7922 if (WEXITSTATUS(status) == 0)
7923 return 1;
7924 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7925 WEXITSTATUS(status));
7926 switch (WEXITSTATUS(status)) {
7927 case 4:
7928 errmsg = "errmsg,Network failure";
7929 break;
7930 case 8:
7931 errmsg = "errmsg,Server issued an error response";
7932 break;
7933 default:
7934 errmsg = "errmsg,Unknown failure from wget";
7935 break;
7936 }
7937 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7938 return 0;
7939 }
7940
7941 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7942 return 0;
7943}
7944
7945
Jouni Malinenf7222712019-06-13 01:50:21 +03007946static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7947 struct sigma_conn *conn,
7948 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007949{
7950 const char *program = get_param(cmd, "Prog");
7951
Jouni Malinen82905202018-04-29 17:20:10 +03007952 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007953 return -1;
7954#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007955 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007956 return nan_cmd_sta_exec_action(dut, conn, cmd);
7957#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007958
7959 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007960 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007961
7962 if (get_param(cmd, "url"))
7963 return sta_exec_action_url(dut, conn, cmd);
7964
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007965 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7966 return 0;
7967}
7968
7969
Jouni Malinenf7222712019-06-13 01:50:21 +03007970static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7971 struct sigma_conn *conn,
7972 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007973{
7974 const char *intf = get_param(cmd, "Interface");
7975 const char *val, *mcs32, *rate;
7976
7977 val = get_param(cmd, "GREENFIELD");
7978 if (val) {
7979 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7980 /* Enable GD */
7981 send_resp(dut, conn, SIGMA_ERROR,
7982 "ErrorCode,GF not supported");
7983 return 0;
7984 }
7985 }
7986
7987 val = get_param(cmd, "SGI20");
7988 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02007989 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007990 case DRIVER_ATHEROS:
7991 ath_sta_set_sgi(dut, intf, val);
7992 break;
7993 default:
7994 send_resp(dut, conn, SIGMA_ERROR,
7995 "ErrorCode,SGI20 not supported");
7996 return 0;
7997 }
7998 }
7999
8000 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
8001 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
8002 if (mcs32 && rate) {
8003 /* TODO */
8004 send_resp(dut, conn, SIGMA_ERROR,
8005 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
8006 return 0;
8007 } else if (mcs32 && !rate) {
8008 /* TODO */
8009 send_resp(dut, conn, SIGMA_ERROR,
8010 "ErrorCode,MCS32 not supported");
8011 return 0;
8012 } else if (!mcs32 && rate) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008013 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008014 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07008015 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008016 ath_sta_set_11nrates(dut, intf, rate);
8017 break;
8018 default:
8019 send_resp(dut, conn, SIGMA_ERROR,
8020 "ErrorCode,MCS32_FIXEDRATE not supported");
8021 return 0;
8022 }
8023 }
8024
8025 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8026}
8027
8028
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008029static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8030 int mcs_config)
8031{
8032#ifdef NL80211_SUPPORT
8033 int ret;
8034
8035 switch (mcs_config) {
8036 case HE_80_MCS0_7:
8037 case HE_80_MCS0_9:
8038 case HE_80_MCS0_11:
8039 ret = sta_set_he_mcs(dut, intf, mcs_config);
8040 if (ret) {
8041 sigma_dut_print(dut, DUT_MSG_ERROR,
8042 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8043 mcs_config, ret);
8044 }
8045 break;
8046 default:
8047 sigma_dut_print(dut, DUT_MSG_ERROR,
8048 "cmd_set_max_he_mcs: Invalid mcs %d",
8049 mcs_config);
8050 break;
8051 }
8052#else /* NL80211_SUPPORT */
8053 sigma_dut_print(dut, DUT_MSG_ERROR,
8054 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8055#endif /* NL80211_SUPPORT */
8056}
8057
8058
Arif Hussain480d5f42019-03-12 14:40:42 -07008059static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8060 struct sigma_cmd *cmd)
8061{
8062#ifdef NL80211_SUPPORT
8063 struct nlattr *params;
8064 struct nlattr *attr;
8065 struct nlattr *attr1;
8066 struct nl_msg *msg;
8067 int ifindex, ret;
8068 const char *val;
8069 const char *intf = get_param(cmd, "Interface");
8070 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8071 wake_interval_mantissa = 512;
8072 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8073 protection = 0;
8074
8075 ifindex = if_nametoindex(intf);
8076 if (ifindex == 0) {
8077 sigma_dut_print(dut, DUT_MSG_ERROR,
8078 "%s: Index for interface %s failed",
8079 __func__, intf);
8080 return -1;
8081 }
8082
8083 val = get_param(cmd, "FlowType");
8084 if (val) {
8085 flow_type = atoi(val);
8086 if (flow_type != 0 && flow_type != 1) {
8087 sigma_dut_print(dut, DUT_MSG_ERROR,
8088 "TWT: Invalid FlowType %d", flow_type);
8089 return -1;
8090 }
8091 }
8092
8093 val = get_param(cmd, "TWT_Trigger");
8094 if (val) {
8095 twt_trigger = atoi(val);
8096 if (twt_trigger != 0 && twt_trigger != 1) {
8097 sigma_dut_print(dut, DUT_MSG_ERROR,
8098 "TWT: Invalid TWT_Trigger %d",
8099 twt_trigger);
8100 return -1;
8101 }
8102 }
8103
8104 val = get_param(cmd, "Protection");
8105 if (val) {
8106 protection = atoi(val);
8107 if (protection != 0 && protection != 1) {
8108 sigma_dut_print(dut, DUT_MSG_ERROR,
8109 "TWT: Invalid Protection %d",
8110 protection);
8111 return -1;
8112 }
8113 }
8114
8115 val = get_param(cmd, "TargetWakeTime");
8116 if (val)
8117 target_wake_time = atoi(val);
8118
8119 val = get_param(cmd, "WakeIntervalMantissa");
8120 if (val)
8121 wake_interval_mantissa = atoi(val);
8122
8123 val = get_param(cmd, "WakeIntervalExp");
8124 if (val)
8125 wake_interval_exp = atoi(val);
8126
8127 val = get_param(cmd, "NominalMinWakeDur");
8128 if (val)
8129 nominal_min_wake_dur = atoi(val);
8130
8131 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8132 NL80211_CMD_VENDOR)) ||
8133 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8134 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8135 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8136 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8137 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8138 !(params = nla_nest_start(
8139 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8140 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8141 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8142 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008143 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008144 (twt_trigger &&
8145 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008146 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8147 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008148 (protection &&
8149 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008150 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8151 target_wake_time) ||
8152 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8153 nominal_min_wake_dur) ||
8154 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8155 wake_interval_mantissa)) {
8156 sigma_dut_print(dut, DUT_MSG_ERROR,
8157 "%s: err in adding vendor_cmd and vendor_data",
8158 __func__);
8159 nlmsg_free(msg);
8160 return -1;
8161 }
8162 nla_nest_end(msg, attr1);
8163 nla_nest_end(msg, params);
8164 nla_nest_end(msg, attr);
8165
8166 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8167 if (ret) {
8168 sigma_dut_print(dut, DUT_MSG_ERROR,
8169 "%s: err in send_and_recv_msgs, ret=%d",
8170 __func__, ret);
8171 }
8172
8173 return ret;
8174#else /* NL80211_SUPPORT */
8175 sigma_dut_print(dut, DUT_MSG_ERROR,
8176 "TWT request cannot be done without NL80211_SUPPORT defined");
8177 return -1;
8178#endif /* NL80211_SUPPORT */
8179}
8180
8181
8182static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8183 struct sigma_cmd *cmd)
8184{
8185 #ifdef NL80211_SUPPORT
8186 struct nlattr *params;
8187 struct nlattr *attr;
8188 struct nlattr *attr1;
8189 int ifindex, ret;
8190 struct nl_msg *msg;
8191 const char *intf = get_param(cmd, "Interface");
8192
8193 ifindex = if_nametoindex(intf);
8194 if (ifindex == 0) {
8195 sigma_dut_print(dut, DUT_MSG_ERROR,
8196 "%s: Index for interface %s failed",
8197 __func__, intf);
8198 return -1;
8199 }
8200
8201 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8202 NL80211_CMD_VENDOR)) ||
8203 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8204 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8205 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8206 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8207 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8208 !(params = nla_nest_start(
8209 msg,
8210 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8211 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8212 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8213 sigma_dut_print(dut, DUT_MSG_ERROR,
8214 "%s: err in adding vendor_cmd and vendor_data",
8215 __func__);
8216 nlmsg_free(msg);
8217 return -1;
8218 }
8219 nla_nest_end(msg, attr1);
8220 nla_nest_end(msg, params);
8221 nla_nest_end(msg, attr);
8222
8223 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8224 if (ret) {
8225 sigma_dut_print(dut, DUT_MSG_ERROR,
8226 "%s: err in send_and_recv_msgs, ret=%d",
8227 __func__, ret);
8228 }
8229
8230 return ret;
8231#else /* NL80211_SUPPORT */
8232 sigma_dut_print(dut, DUT_MSG_ERROR,
8233 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8234 return -1;
8235#endif /* NL80211_SUPPORT */
8236}
8237
8238
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008239static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8240 struct sigma_cmd *cmd)
8241{
8242#ifdef NL80211_SUPPORT
8243 struct nlattr *params;
8244 struct nlattr *attr;
8245 struct nlattr *attr1;
8246 struct nl_msg *msg;
8247 int ifindex, ret;
8248 const char *val;
8249 const char *intf = get_param(cmd, "Interface");
8250 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8251 ulmu_data_dis = 0;
8252
8253 ifindex = if_nametoindex(intf);
8254 if (ifindex == 0) {
8255 sigma_dut_print(dut, DUT_MSG_ERROR,
8256 "%s: Index for interface %s failed",
8257 __func__, intf);
8258 return -1;
8259 }
8260 val = get_param(cmd, "OMCtrl_RxNSS");
8261 if (val)
8262 rx_nss = atoi(val);
8263
8264 val = get_param(cmd, "OMCtrl_ChnlWidth");
8265 if (val)
8266 ch_bw = atoi(val);
8267
8268 val = get_param(cmd, "OMCtrl_ULMUDisable");
8269 if (val)
8270 ulmu_dis = atoi(val);
8271
8272 val = get_param(cmd, "OMCtrl_TxNSTS");
8273 if (val)
8274 tx_nsts = atoi(val);
8275
8276 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8277 if (val)
8278 ulmu_data_dis = atoi(val);
8279
8280 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8281 NL80211_CMD_VENDOR)) ||
8282 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8283 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8284 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8285 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8286 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8287 !(params = nla_nest_start(
8288 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8289 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8290 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8291 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8292 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8293 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8294 ulmu_data_dis) ||
8295 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8296 ulmu_dis)) {
8297 sigma_dut_print(dut, DUT_MSG_ERROR,
8298 "%s: err in adding vendor_cmd and vendor_data",
8299 __func__);
8300 nlmsg_free(msg);
8301 return -1;
8302 }
8303 nla_nest_end(msg, attr1);
8304 nla_nest_end(msg, params);
8305 nla_nest_end(msg, attr);
8306
8307 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8308 if (ret) {
8309 sigma_dut_print(dut, DUT_MSG_ERROR,
8310 "%s: err in send_and_recv_msgs, ret=%d",
8311 __func__, ret);
8312 }
8313
8314 return ret;
8315#else /* NL80211_SUPPORT */
8316 sigma_dut_print(dut, DUT_MSG_ERROR,
8317 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8318 return -1;
8319#endif /* NL80211_SUPPORT */
8320}
8321
8322
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008323static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8324 struct sigma_conn *conn,
8325 struct sigma_cmd *cmd)
8326{
8327 const char *intf = get_param(cmd, "Interface");
8328 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008329 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008330 int tkip = -1;
8331 int wep = -1;
8332
Arif Hussaina37e9552018-06-20 17:05:59 -07008333 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008334 val = get_param(cmd, "SGI80");
8335 if (val) {
8336 int sgi80;
8337
8338 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008339 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008340 }
8341
8342 val = get_param(cmd, "TxBF");
8343 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008344 switch (get_driver_type(dut)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008345 case DRIVER_WCN:
8346 if (sta_set_tx_beamformee(dut, intf, 1)) {
8347 send_resp(dut, conn, SIGMA_ERROR,
8348 "ErrorCode,Failed to set TX beamformee enable");
8349 return 0;
8350 }
8351 break;
8352 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008353 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008354 send_resp(dut, conn, SIGMA_ERROR,
8355 "ErrorCode,Setting vhtsubfee failed");
8356 return 0;
8357 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008358 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008359 send_resp(dut, conn, SIGMA_ERROR,
8360 "ErrorCode,Setting vhtsubfer failed");
8361 return 0;
8362 }
8363 break;
8364 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008365 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008366 "Unsupported driver type");
8367 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008368 }
8369 }
8370
8371 val = get_param(cmd, "MU_TxBF");
8372 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008373 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008374 case DRIVER_ATHEROS:
8375 ath_sta_set_txsp_stream(dut, intf, "1SS");
8376 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008377 run_iwpriv(dut, intf, "vhtmubfee 1");
8378 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308379 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008380 case DRIVER_WCN:
8381 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8382 send_resp(dut, conn, SIGMA_ERROR,
8383 "ErrorCode,Failed to set RX/TXSP_STREAM");
8384 return 0;
8385 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308386 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008387 default:
8388 sigma_dut_print(dut, DUT_MSG_ERROR,
8389 "Setting SP_STREAM not supported");
8390 break;
8391 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008392 }
8393
8394 val = get_param(cmd, "LDPC");
8395 if (val) {
8396 int ldpc;
8397
8398 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008399 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008400 }
8401
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008402 val = get_param(cmd, "BCC");
8403 if (val) {
8404 int bcc;
8405
8406 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8407 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8408 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008409 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008410 }
8411
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008412 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8413 if (val && dut->sta_nss == 1)
8414 cmd_set_max_he_mcs(dut, intf, atoi(val));
8415
8416 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8417 if (val && dut->sta_nss == 2)
8418 cmd_set_max_he_mcs(dut, intf, atoi(val));
8419
Arif Hussainac6c5112018-05-25 17:34:00 -07008420 val = get_param(cmd, "MCS_FixedRate");
8421 if (val) {
8422#ifdef NL80211_SUPPORT
8423 int mcs, ratecode = 0;
8424 enum he_mcs_config mcs_config;
8425 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008426 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008427
8428 ratecode = (0x07 & dut->sta_nss) << 5;
8429 mcs = atoi(val);
8430 /* Add the MCS to the ratecode */
8431 if (mcs >= 0 && mcs <= 11) {
8432 ratecode += mcs;
8433 if (dut->device_type == STA_testbed &&
8434 mcs > 7 && mcs <= 11) {
8435 if (mcs <= 9)
8436 mcs_config = HE_80_MCS0_9;
8437 else
8438 mcs_config = HE_80_MCS0_11;
8439 ret = sta_set_he_mcs(dut, intf, mcs_config);
8440 if (ret) {
8441 sigma_dut_print(dut, DUT_MSG_ERROR,
8442 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8443 mcs, mcs_config, ret);
8444 }
8445 }
8446 snprintf(buf, sizeof(buf),
8447 "iwpriv %s set_11ax_rate 0x%03x",
8448 intf, ratecode);
8449 if (system(buf) != 0) {
8450 sigma_dut_print(dut, DUT_MSG_ERROR,
8451 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8452 ratecode);
8453 }
8454 } else {
8455 sigma_dut_print(dut, DUT_MSG_ERROR,
8456 "MCS_FixedRate: HE MCS %d not supported",
8457 mcs);
8458 }
8459#else /* NL80211_SUPPORT */
8460 sigma_dut_print(dut, DUT_MSG_ERROR,
8461 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8462#endif /* NL80211_SUPPORT */
8463 }
8464
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008465 val = get_param(cmd, "opt_md_notif_ie");
8466 if (val) {
8467 char *result = NULL;
8468 char delim[] = ";";
8469 char token[30];
8470 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308471 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008472
Peng Xub8fc5cc2017-05-10 17:27:28 -07008473 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308474 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008475
8476 /* Extract the NSS information */
8477 if (result) {
8478 value = atoi(result);
8479 switch (value) {
8480 case 1:
8481 config_val = 1;
8482 break;
8483 case 2:
8484 config_val = 3;
8485 break;
8486 case 3:
8487 config_val = 7;
8488 break;
8489 case 4:
8490 config_val = 15;
8491 break;
8492 default:
8493 config_val = 3;
8494 break;
8495 }
8496
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008497 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8498 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008499
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008500 }
8501
8502 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308503 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008504 if (result) {
8505 value = atoi(result);
8506 switch (value) {
8507 case 20:
8508 config_val = 0;
8509 break;
8510 case 40:
8511 config_val = 1;
8512 break;
8513 case 80:
8514 config_val = 2;
8515 break;
8516 case 160:
8517 config_val = 3;
8518 break;
8519 default:
8520 config_val = 2;
8521 break;
8522 }
8523
8524 dut->chwidth = config_val;
8525
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008526 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008527 }
8528
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008529 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008530 }
8531
8532 val = get_param(cmd, "nss_mcs_cap");
8533 if (val) {
8534 int nss, mcs;
8535 char token[20];
8536 char *result = NULL;
8537 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308538 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008539
Peng Xub8fc5cc2017-05-10 17:27:28 -07008540 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308541 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308542 if (!result) {
8543 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008544 "NSS not specified");
8545 send_resp(dut, conn, SIGMA_ERROR,
8546 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308547 return 0;
8548 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008549 nss = atoi(result);
8550
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008551 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008552 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008553
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308554 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008555 if (result == NULL) {
8556 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008557 "MCS not specified");
8558 send_resp(dut, conn, SIGMA_ERROR,
8559 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008560 return 0;
8561 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308562 result = strtok_r(result, "-", &saveptr);
8563 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308564 if (!result) {
8565 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008566 "MCS not specified");
8567 send_resp(dut, conn, SIGMA_ERROR,
8568 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308569 return 0;
8570 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008571 mcs = atoi(result);
8572
Arif Hussaina37e9552018-06-20 17:05:59 -07008573 if (program && strcasecmp(program, "HE") == 0) {
8574#ifdef NL80211_SUPPORT
8575 enum he_mcs_config mcs_config;
8576 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008577
Arif Hussaina37e9552018-06-20 17:05:59 -07008578 if (mcs >= 0 && mcs <= 7) {
8579 mcs_config = HE_80_MCS0_7;
8580 } else if (mcs > 7 && mcs <= 9) {
8581 mcs_config = HE_80_MCS0_9;
8582 } else if (mcs > 9 && mcs <= 11) {
8583 mcs_config = HE_80_MCS0_11;
8584 } else {
8585 sigma_dut_print(dut, DUT_MSG_ERROR,
8586 "nss_mcs_cap: HE: Invalid mcs: %d",
8587 mcs);
8588 send_resp(dut, conn, SIGMA_ERROR,
8589 "errorCode,Invalid MCS");
8590 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008591 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008592
8593 ret = sta_set_he_mcs(dut, intf, mcs_config);
8594 if (ret) {
8595 sigma_dut_print(dut, DUT_MSG_ERROR,
8596 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8597 mcs_config, ret);
8598 send_resp(dut, conn, SIGMA_ERROR,
8599 "errorCode,Failed to set MCS");
8600 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008601 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008602#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008603 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008604 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8605#endif /* NL80211_SUPPORT */
8606 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008607 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008608
8609 switch (nss) {
8610 case 1:
8611 switch (mcs) {
8612 case 7:
8613 vht_mcsmap = 0xfffc;
8614 break;
8615 case 8:
8616 vht_mcsmap = 0xfffd;
8617 break;
8618 case 9:
8619 vht_mcsmap = 0xfffe;
8620 break;
8621 default:
8622 vht_mcsmap = 0xfffe;
8623 break;
8624 }
8625 break;
8626 case 2:
8627 switch (mcs) {
8628 case 7:
8629 vht_mcsmap = 0xfff0;
8630 break;
8631 case 8:
8632 vht_mcsmap = 0xfff5;
8633 break;
8634 case 9:
8635 vht_mcsmap = 0xfffa;
8636 break;
8637 default:
8638 vht_mcsmap = 0xfffa;
8639 break;
8640 }
8641 break;
8642 case 3:
8643 switch (mcs) {
8644 case 7:
8645 vht_mcsmap = 0xffc0;
8646 break;
8647 case 8:
8648 vht_mcsmap = 0xffd5;
8649 break;
8650 case 9:
8651 vht_mcsmap = 0xffea;
8652 break;
8653 default:
8654 vht_mcsmap = 0xffea;
8655 break;
8656 }
8657 break;
8658 default:
8659 vht_mcsmap = 0xffea;
8660 break;
8661 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008662 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008663 }
8664 }
8665
8666 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8667
8668 val = get_param(cmd, "Vht_tkip");
8669 if (val)
8670 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8671
8672 val = get_param(cmd, "Vht_wep");
8673 if (val)
8674 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8675
8676 if (tkip != -1 || wep != -1) {
8677 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008678 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008679 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008680 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008681 } else {
8682 sigma_dut_print(dut, DUT_MSG_ERROR,
8683 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8684 return 0;
8685 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008686 }
8687
Arif Hussain55f00da2018-07-03 08:28:26 -07008688 val = get_param(cmd, "txBandwidth");
8689 if (val) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008690 switch (get_driver_type(dut)) {
Arif Hussain55f00da2018-07-03 08:28:26 -07008691 case DRIVER_WCN:
8692 if (wcn_sta_set_width(dut, intf, val) < 0) {
8693 send_resp(dut, conn, SIGMA_ERROR,
8694 "ErrorCode,Failed to set txBandwidth");
8695 return 0;
8696 }
8697 break;
8698 case DRIVER_ATHEROS:
8699 if (ath_set_width(dut, conn, intf, val) < 0) {
8700 send_resp(dut, conn, SIGMA_ERROR,
8701 "ErrorCode,Failed to set txBandwidth");
8702 return 0;
8703 }
8704 break;
8705 default:
8706 sigma_dut_print(dut, DUT_MSG_ERROR,
8707 "Setting txBandwidth not supported");
8708 break;
8709 }
8710 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008711
Arif Hussain9765f7d2018-07-03 08:28:26 -07008712 val = get_param(cmd, "BeamformeeSTS");
8713 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008714 if (sta_set_tx_beamformee(dut, intf, 1)) {
8715 send_resp(dut, conn, SIGMA_ERROR,
8716 "ErrorCode,Failed to set TX beamformee enable");
8717 return 0;
8718 }
8719
Arif Hussain9765f7d2018-07-03 08:28:26 -07008720 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8721 send_resp(dut, conn, SIGMA_ERROR,
8722 "ErrorCode,Failed to set BeamformeeSTS");
8723 return 0;
8724 }
8725 }
8726
Arif Hussain68d23f52018-07-11 13:39:08 -07008727 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8728 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008729#ifdef NL80211_SUPPORT
8730 enum qca_wlan_he_mac_padding_dur set_val;
8731
8732 switch (atoi(val)) {
8733 case 16:
8734 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8735 break;
8736 case 8:
8737 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8738 break;
8739 default:
8740 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8741 break;
8742 }
8743 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008744 send_resp(dut, conn, SIGMA_ERROR,
8745 "ErrorCode,Failed to set MAC padding duration");
8746 return 0;
8747 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008748#else /* NL80211_SUPPORT */
8749 sigma_dut_print(dut, DUT_MSG_ERROR,
8750 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8751#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008752 }
8753
Arif Hussain480d5f42019-03-12 14:40:42 -07008754 val = get_param(cmd, "TWT_ReqSupport");
8755 if (val) {
8756 int set_val;
8757
8758 if (strcasecmp(val, "Enable") == 0) {
8759 set_val = 1;
8760 } else if (strcasecmp(val, "Disable") == 0) {
8761 set_val = 0;
8762 } else {
8763 send_resp(dut, conn, SIGMA_ERROR,
8764 "ErrorCode,Invalid TWT_ReqSupport");
8765 return STATUS_SENT;
8766 }
8767
8768 if (sta_set_twt_req_support(dut, intf, set_val)) {
8769 sigma_dut_print(dut, DUT_MSG_ERROR,
8770 "Failed to set TWT req support %d",
8771 set_val);
8772 send_resp(dut, conn, SIGMA_ERROR,
8773 "ErrorCode,Failed to set TWT_ReqSupport");
8774 return STATUS_SENT;
8775 }
8776 }
8777
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008778 val = get_param(cmd, "MU_EDCA");
8779 if (val && (strcasecmp(val, "Override") == 0)) {
8780 if (sta_set_mu_edca_override(dut, intf, 1)) {
8781 send_resp(dut, conn, SIGMA_ERROR,
8782 "ErrorCode,Failed to set MU EDCA override");
8783 return 0;
8784 }
8785 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008786
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008787 val = get_param(cmd, "OMControl");
8788 if (val) {
8789 int set_val = 1;
8790
8791 if (strcasecmp(val, "Enable") == 0)
8792 set_val = 1;
8793 else if (strcasecmp(val, "Disable") == 0)
8794 set_val = 0;
8795
8796 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8797 send_resp(dut, conn, SIGMA_ERROR,
8798 "ErrorCode,Failed to set OM ctrl supp");
8799 return 0;
8800 }
8801 }
8802
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008803 val = get_param(cmd, "ADDBAResp_BufSize");
8804 if (val) {
8805 int buf_size;
8806
8807 if (strcasecmp(val, "gt64") == 0)
8808 buf_size = 256;
8809 else
8810 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008811 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008812 sta_set_addba_buf_size(dut, intf, buf_size)) {
8813 send_resp(dut, conn, SIGMA_ERROR,
8814 "ErrorCode,set addbaresp_buff_size failed");
8815 return 0;
8816 }
8817 }
8818
8819 val = get_param(cmd, "ADDBAReq_BufSize");
8820 if (val) {
8821 int buf_size;
8822
8823 if (strcasecmp(val, "gt64") == 0)
8824 buf_size = 256;
8825 else
8826 buf_size = 64;
Jouni Malinen016ae6c2019-11-04 17:00:01 +02008827 if (get_driver_type(dut) == DRIVER_WCN &&
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008828 sta_set_addba_buf_size(dut, intf, buf_size)) {
8829 send_resp(dut, conn, SIGMA_ERROR,
8830 "ErrorCode,set addbareq_buff_size failed");
8831 return 0;
8832 }
8833 }
8834
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008835 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8836}
8837
8838
8839static int sta_set_wireless_60g(struct sigma_dut *dut,
8840 struct sigma_conn *conn,
8841 struct sigma_cmd *cmd)
8842{
8843 const char *dev_role = get_param(cmd, "DevRole");
8844
8845 if (!dev_role) {
8846 send_resp(dut, conn, SIGMA_INVALID,
8847 "ErrorCode,DevRole not specified");
8848 return 0;
8849 }
8850
8851 if (strcasecmp(dev_role, "PCP") == 0)
8852 return sta_set_60g_pcp(dut, conn, cmd);
8853 if (strcasecmp(dev_role, "STA") == 0)
8854 return sta_set_60g_sta(dut, conn, cmd);
8855 send_resp(dut, conn, SIGMA_INVALID,
8856 "ErrorCode,DevRole not supported");
8857 return 0;
8858}
8859
8860
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308861static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8862 struct sigma_cmd *cmd)
8863{
8864 int status;
8865 const char *intf = get_param(cmd, "Interface");
8866 const char *val = get_param(cmd, "DevRole");
8867
8868 if (val && strcasecmp(val, "STA-CFON") == 0) {
8869 status = sta_cfon_set_wireless(dut, conn, cmd);
8870 if (status)
8871 return status;
8872 }
8873 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8874}
8875
8876
Jouni Malinenf7222712019-06-13 01:50:21 +03008877static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
8878 struct sigma_conn *conn,
8879 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008880{
8881 const char *val;
8882
8883 val = get_param(cmd, "Program");
8884 if (val) {
8885 if (strcasecmp(val, "11n") == 0)
8886 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008887 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008888 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8889 if (strcasecmp(val, "60ghz") == 0)
8890 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308891 if (strcasecmp(val, "OCE") == 0)
8892 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008893 /* sta_set_wireless in WPS program is only used for 60G */
8894 if (is_60g_sigma_dut(dut))
8895 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008896 send_resp(dut, conn, SIGMA_ERROR,
8897 "ErrorCode,Program value not supported");
8898 } else {
8899 send_resp(dut, conn, SIGMA_ERROR,
8900 "ErrorCode,Program argument not available");
8901 }
8902
8903 return 0;
8904}
8905
8906
8907static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8908 int tid)
8909{
8910 char buf[100];
8911 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8912
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308913 if (tid < 0 ||
8914 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8915 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8916 return;
8917 }
8918
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008919 /*
8920 * Two ways to ensure that addba request with a
8921 * non zero TID could be sent out. EV 117296
8922 */
8923 snprintf(buf, sizeof(buf),
8924 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8925 tid);
8926 if (system(buf) != 0) {
8927 sigma_dut_print(dut, DUT_MSG_ERROR,
8928 "Ping did not send out");
8929 }
8930
8931 snprintf(buf, sizeof(buf),
8932 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8933 intf, VI_QOS_TMP_FILE);
8934 if (system(buf) != 0)
8935 return;
8936
8937 snprintf(buf, sizeof(buf),
8938 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8939 intf, VI_QOS_TMP_FILE);
8940 if (system(buf) != 0)
8941 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8942
8943 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8944 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8945 if (system(buf) != 0) {
8946 sigma_dut_print(dut, DUT_MSG_ERROR,
8947 "VI_QOS_TEMP_FILE generation error failed");
8948 }
8949 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8950 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8951 if (system(buf) != 0) {
8952 sigma_dut_print(dut, DUT_MSG_ERROR,
8953 "VI_QOS_FILE generation failed");
8954 }
8955
8956 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8957 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8958 if (system(buf) != 0) {
8959 sigma_dut_print(dut, DUT_MSG_ERROR,
8960 "VI_QOS_FILE generation failed");
8961 }
8962
8963 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8964 if (system(buf) != 0) {
8965 }
8966}
8967
8968
8969static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8970 struct sigma_cmd *cmd)
8971{
8972 const char *intf = get_param(cmd, "Interface");
8973 const char *val;
8974 int tid = 0;
8975 char buf[100];
8976
8977 val = get_param(cmd, "TID");
8978 if (val) {
8979 tid = atoi(val);
8980 if (tid)
8981 ath_sta_inject_frame(dut, intf, tid);
8982 }
8983
8984 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008985 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008986
8987 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8988 if (system(buf) != 0) {
8989 sigma_dut_print(dut, DUT_MSG_ERROR,
8990 "wifitool senddelba failed");
8991 }
8992
8993 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8994 if (system(buf) != 0) {
8995 sigma_dut_print(dut, DUT_MSG_ERROR,
8996 "wifitool sendaddba failed");
8997 }
8998
8999 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9000
9001 return 1;
9002}
9003
9004
Lior David9981b512017-01-20 13:16:40 +02009005#ifdef __linux__
9006
9007static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
9008 int agg_size)
9009{
9010 char dir[128], buf[128];
9011 FILE *f;
9012 regex_t re;
9013 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03009014 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02009015
9016 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
9017 sigma_dut_print(dut, DUT_MSG_ERROR,
9018 "failed to get wil6210 debugfs dir");
9019 return -1;
9020 }
9021
Jouni Malinen3aa72862019-05-29 23:14:51 +03009022 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
9023 if (res < 0 || res >= sizeof(buf))
9024 return -1;
Lior David9981b512017-01-20 13:16:40 +02009025 f = fopen(buf, "r");
9026 if (!f) {
9027 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009028 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009029 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9030 if (res < 0 || res >= sizeof(buf))
9031 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009032 f = fopen(buf, "r");
9033 if (!f) {
9034 sigma_dut_print(dut, DUT_MSG_ERROR,
9035 "failed to open: %s", buf);
9036 return -1;
9037 }
Lior David9981b512017-01-20 13:16:40 +02009038 }
9039
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009040 /* can be either VRING tx... or RING... */
9041 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009042 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9043 goto out;
9044 }
9045
9046 /* find TX VRING for the mac address */
9047 found = 0;
9048 while (fgets(buf, sizeof(buf), f)) {
9049 if (strcasestr(buf, dest_mac)) {
9050 found = 1;
9051 break;
9052 }
9053 }
9054
9055 if (!found) {
9056 sigma_dut_print(dut, DUT_MSG_ERROR,
9057 "no TX VRING for %s", dest_mac);
9058 goto out;
9059 }
9060
9061 /* extract VRING ID, "VRING tx_<id> = {" */
9062 if (!fgets(buf, sizeof(buf), f)) {
9063 sigma_dut_print(dut, DUT_MSG_ERROR,
9064 "no VRING start line for %s", dest_mac);
9065 goto out;
9066 }
9067
9068 rc = regexec(&re, buf, 2, m, 0);
9069 regfree(&re);
9070 if (rc || m[1].rm_so < 0) {
9071 sigma_dut_print(dut, DUT_MSG_ERROR,
9072 "no VRING TX ID for %s", dest_mac);
9073 goto out;
9074 }
9075 buf[m[1].rm_eo] = 0;
9076 vring_id = atoi(&buf[m[1].rm_so]);
9077
9078 /* send the addba command */
9079 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009080 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9081 if (res < 0 || res >= sizeof(buf))
9082 return -1;
Lior David9981b512017-01-20 13:16:40 +02009083 f = fopen(buf, "w");
9084 if (!f) {
9085 sigma_dut_print(dut, DUT_MSG_ERROR,
9086 "failed to open: %s", buf);
9087 return -1;
9088 }
9089
9090 fprintf(f, "add %d %d\n", vring_id, agg_size);
9091
9092 ret = 0;
9093
9094out:
9095 fclose(f);
9096
9097 return ret;
9098}
9099
9100
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009101int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9102 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009103{
9104 const char *val;
9105 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009106
9107 val = get_param(cmd, "TID");
9108 if (val) {
9109 tid = atoi(val);
9110 if (tid != 0) {
9111 sigma_dut_print(dut, DUT_MSG_ERROR,
9112 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9113 tid);
9114 }
9115 }
9116
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009117 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009118 if (!val) {
9119 sigma_dut_print(dut, DUT_MSG_ERROR,
9120 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009121 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009122 }
9123
Lior David9981b512017-01-20 13:16:40 +02009124 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009125 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009126
9127 return 1;
9128}
9129
Lior David9981b512017-01-20 13:16:40 +02009130#endif /* __linux__ */
9131
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009132
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009133static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9134 struct sigma_cmd *cmd)
9135{
9136#ifdef NL80211_SUPPORT
9137 const char *intf = get_param(cmd, "Interface");
9138 const char *val;
9139 int tid = -1;
9140 int bufsize = 64;
9141 struct nl_msg *msg;
9142 int ret = 0;
9143 struct nlattr *params;
9144 int ifindex;
9145
9146 val = get_param(cmd, "TID");
9147 if (val)
9148 tid = atoi(val);
9149
9150 if (tid == -1) {
9151 send_resp(dut, conn, SIGMA_ERROR,
9152 "ErrorCode,sta_send_addba tid invalid");
9153 return 0;
9154 }
9155
9156 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9157
9158 ifindex = if_nametoindex(intf);
9159 if (ifindex == 0) {
9160 sigma_dut_print(dut, DUT_MSG_ERROR,
9161 "%s: Index for interface %s failed",
9162 __func__, intf);
9163 send_resp(dut, conn, SIGMA_ERROR,
9164 "ErrorCode,sta_send_addba interface invalid");
9165 return 0;
9166 }
9167
9168 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9169 NL80211_CMD_VENDOR)) ||
9170 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9171 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9172 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9173 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9174 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9175 nla_put_u8(msg,
9176 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9177 QCA_WLAN_ADD_BA) ||
9178 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9179 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009180 nla_put_u16(msg,
9181 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9182 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009183 sigma_dut_print(dut, DUT_MSG_ERROR,
9184 "%s: err in adding vendor_cmd and vendor_data",
9185 __func__);
9186 nlmsg_free(msg);
9187 send_resp(dut, conn, SIGMA_ERROR,
9188 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9189 return 0;
9190 }
9191 nla_nest_end(msg, params);
9192
9193 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9194 if (ret) {
9195 sigma_dut_print(dut, DUT_MSG_ERROR,
9196 "%s: err in send_and_recv_msgs, ret=%d",
9197 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309198 if (ret == -EOPNOTSUPP)
9199 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009200 send_resp(dut, conn, SIGMA_ERROR,
9201 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9202 return 0;
9203 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009204#else /* NL80211_SUPPORT */
9205 sigma_dut_print(dut, DUT_MSG_ERROR,
9206 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009207#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309208
9209 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009210}
9211
9212
Jouni Malinenf7222712019-06-13 01:50:21 +03009213static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9214 struct sigma_conn *conn,
9215 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009216{
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009217 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009218 case DRIVER_ATHEROS:
9219 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009220 case DRIVER_WCN:
9221 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009222#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009223 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009224 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009225#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009226 default:
9227 /*
9228 * There is no driver specific implementation for other drivers.
9229 * Ignore the command and report COMPLETE since the following
9230 * throughput test operation will end up sending ADDBA anyway.
9231 */
9232 return 1;
9233 }
9234}
9235
9236
9237int inject_eth_frame(int s, const void *data, size_t len,
9238 unsigned short ethtype, char *dst, char *src)
9239{
9240 struct iovec iov[4] = {
9241 {
9242 .iov_base = dst,
9243 .iov_len = ETH_ALEN,
9244 },
9245 {
9246 .iov_base = src,
9247 .iov_len = ETH_ALEN,
9248 },
9249 {
9250 .iov_base = &ethtype,
9251 .iov_len = sizeof(unsigned short),
9252 },
9253 {
9254 .iov_base = (void *) data,
9255 .iov_len = len,
9256 }
9257 };
9258 struct msghdr msg = {
9259 .msg_name = NULL,
9260 .msg_namelen = 0,
9261 .msg_iov = iov,
9262 .msg_iovlen = 4,
9263 .msg_control = NULL,
9264 .msg_controllen = 0,
9265 .msg_flags = 0,
9266 };
9267
9268 return sendmsg(s, &msg, 0);
9269}
9270
9271#if defined(__linux__) || defined(__QNXNTO__)
9272
9273int inject_frame(int s, const void *data, size_t len, int encrypt)
9274{
9275#define IEEE80211_RADIOTAP_F_WEP 0x04
9276#define IEEE80211_RADIOTAP_F_FRAG 0x08
9277 unsigned char rtap_hdr[] = {
9278 0x00, 0x00, /* radiotap version */
9279 0x0e, 0x00, /* radiotap length */
9280 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9281 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9282 0x00, /* padding */
9283 0x00, 0x00, /* RX and TX flags to indicate that */
9284 0x00, 0x00, /* this is the injected frame directly */
9285 };
9286 struct iovec iov[2] = {
9287 {
9288 .iov_base = &rtap_hdr,
9289 .iov_len = sizeof(rtap_hdr),
9290 },
9291 {
9292 .iov_base = (void *) data,
9293 .iov_len = len,
9294 }
9295 };
9296 struct msghdr msg = {
9297 .msg_name = NULL,
9298 .msg_namelen = 0,
9299 .msg_iov = iov,
9300 .msg_iovlen = 2,
9301 .msg_control = NULL,
9302 .msg_controllen = 0,
9303 .msg_flags = 0,
9304 };
9305
9306 if (encrypt)
9307 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9308
9309 return sendmsg(s, &msg, 0);
9310}
9311
9312
9313int open_monitor(const char *ifname)
9314{
9315#ifdef __QNXNTO__
9316 struct sockaddr_dl ll;
9317 int s;
9318
9319 memset(&ll, 0, sizeof(ll));
9320 ll.sdl_family = AF_LINK;
9321 ll.sdl_index = if_nametoindex(ifname);
9322 if (ll.sdl_index == 0) {
9323 perror("if_nametoindex");
9324 return -1;
9325 }
9326 s = socket(PF_INET, SOCK_RAW, 0);
9327#else /* __QNXNTO__ */
9328 struct sockaddr_ll ll;
9329 int s;
9330
9331 memset(&ll, 0, sizeof(ll));
9332 ll.sll_family = AF_PACKET;
9333 ll.sll_ifindex = if_nametoindex(ifname);
9334 if (ll.sll_ifindex == 0) {
9335 perror("if_nametoindex");
9336 return -1;
9337 }
9338 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9339#endif /* __QNXNTO__ */
9340 if (s < 0) {
9341 perror("socket[PF_PACKET,SOCK_RAW]");
9342 return -1;
9343 }
9344
9345 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9346 perror("monitor socket bind");
9347 close(s);
9348 return -1;
9349 }
9350
9351 return s;
9352}
9353
9354
9355static int hex2num(char c)
9356{
9357 if (c >= '0' && c <= '9')
9358 return c - '0';
9359 if (c >= 'a' && c <= 'f')
9360 return c - 'a' + 10;
9361 if (c >= 'A' && c <= 'F')
9362 return c - 'A' + 10;
9363 return -1;
9364}
9365
9366
9367int hwaddr_aton(const char *txt, unsigned char *addr)
9368{
9369 int i;
9370
9371 for (i = 0; i < 6; i++) {
9372 int a, b;
9373
9374 a = hex2num(*txt++);
9375 if (a < 0)
9376 return -1;
9377 b = hex2num(*txt++);
9378 if (b < 0)
9379 return -1;
9380 *addr++ = (a << 4) | b;
9381 if (i < 5 && *txt++ != ':')
9382 return -1;
9383 }
9384
9385 return 0;
9386}
9387
9388#endif /* defined(__linux__) || defined(__QNXNTO__) */
9389
9390enum send_frame_type {
9391 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9392};
9393enum send_frame_protection {
9394 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9395};
9396
9397
9398static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9399 enum send_frame_type frame,
9400 enum send_frame_protection protected,
9401 const char *dest)
9402{
9403#ifdef __linux__
9404 unsigned char buf[1000], *pos;
9405 int s, res;
9406 char bssid[20], addr[20];
9407 char result[32], ssid[100];
9408 size_t ssid_len;
9409
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009410 if (get_wpa_status(get_station_ifname(dut), "wpa_state", result,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009411 sizeof(result)) < 0 ||
9412 strncmp(result, "COMPLETED", 9) != 0) {
9413 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9414 return 0;
9415 }
9416
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009417 if (get_wpa_status(get_station_ifname(dut), "bssid",
9418 bssid, sizeof(bssid)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009419 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9420 "current BSSID");
9421 return 0;
9422 }
9423
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009424 if (get_wpa_status(get_station_ifname(dut), "address",
9425 addr, sizeof(addr)) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009426 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9427 "own MAC address");
9428 return 0;
9429 }
9430
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009431 if (get_wpa_status(get_station_ifname(dut), "ssid", ssid, sizeof(ssid))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009432 < 0) {
9433 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9434 "current SSID");
9435 return 0;
9436 }
9437 ssid_len = strlen(ssid);
9438
9439 pos = buf;
9440
9441 /* Frame Control */
9442 switch (frame) {
9443 case DISASSOC:
9444 *pos++ = 0xa0;
9445 break;
9446 case DEAUTH:
9447 *pos++ = 0xc0;
9448 break;
9449 case SAQUERY:
9450 *pos++ = 0xd0;
9451 break;
9452 case AUTH:
9453 *pos++ = 0xb0;
9454 break;
9455 case ASSOCREQ:
9456 *pos++ = 0x00;
9457 break;
9458 case REASSOCREQ:
9459 *pos++ = 0x20;
9460 break;
9461 case DLS_REQ:
9462 *pos++ = 0xd0;
9463 break;
9464 }
9465
9466 if (protected == INCORRECT_KEY)
9467 *pos++ = 0x40; /* Set Protected field to 1 */
9468 else
9469 *pos++ = 0x00;
9470
9471 /* Duration */
9472 *pos++ = 0x00;
9473 *pos++ = 0x00;
9474
9475 /* addr1 = DA (current AP) */
9476 hwaddr_aton(bssid, pos);
9477 pos += 6;
9478 /* addr2 = SA (own address) */
9479 hwaddr_aton(addr, pos);
9480 pos += 6;
9481 /* addr3 = BSSID (current AP) */
9482 hwaddr_aton(bssid, pos);
9483 pos += 6;
9484
9485 /* Seq# (to be filled by driver/mac80211) */
9486 *pos++ = 0x00;
9487 *pos++ = 0x00;
9488
9489 if (protected == INCORRECT_KEY) {
9490 /* CCMP parameters */
9491 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9492 pos += 8;
9493 }
9494
9495 if (protected == INCORRECT_KEY) {
9496 switch (frame) {
9497 case DEAUTH:
9498 /* Reason code (encrypted) */
9499 memcpy(pos, "\xa7\x39", 2);
9500 pos += 2;
9501 break;
9502 case DISASSOC:
9503 /* Reason code (encrypted) */
9504 memcpy(pos, "\xa7\x39", 2);
9505 pos += 2;
9506 break;
9507 case SAQUERY:
9508 /* Category|Action|TransID (encrypted) */
9509 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9510 pos += 4;
9511 break;
9512 default:
9513 return -1;
9514 }
9515
9516 /* CCMP MIC */
9517 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9518 pos += 8;
9519 } else {
9520 switch (frame) {
9521 case DEAUTH:
9522 /* reason code = 8 */
9523 *pos++ = 0x08;
9524 *pos++ = 0x00;
9525 break;
9526 case DISASSOC:
9527 /* reason code = 8 */
9528 *pos++ = 0x08;
9529 *pos++ = 0x00;
9530 break;
9531 case SAQUERY:
9532 /* Category - SA Query */
9533 *pos++ = 0x08;
9534 /* SA query Action - Request */
9535 *pos++ = 0x00;
9536 /* Transaction ID */
9537 *pos++ = 0x12;
9538 *pos++ = 0x34;
9539 break;
9540 case AUTH:
9541 /* Auth Alg (Open) */
9542 *pos++ = 0x00;
9543 *pos++ = 0x00;
9544 /* Seq# */
9545 *pos++ = 0x01;
9546 *pos++ = 0x00;
9547 /* Status code */
9548 *pos++ = 0x00;
9549 *pos++ = 0x00;
9550 break;
9551 case ASSOCREQ:
9552 /* Capability Information */
9553 *pos++ = 0x31;
9554 *pos++ = 0x04;
9555 /* Listen Interval */
9556 *pos++ = 0x0a;
9557 *pos++ = 0x00;
9558 /* SSID */
9559 *pos++ = 0x00;
9560 *pos++ = ssid_len;
9561 memcpy(pos, ssid, ssid_len);
9562 pos += ssid_len;
9563 /* Supported Rates */
9564 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9565 10);
9566 pos += 10;
9567 /* Extended Supported Rates */
9568 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9569 pos += 6;
9570 /* RSN */
9571 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9572 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9573 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9574 pos += 28;
9575 break;
9576 case REASSOCREQ:
9577 /* Capability Information */
9578 *pos++ = 0x31;
9579 *pos++ = 0x04;
9580 /* Listen Interval */
9581 *pos++ = 0x0a;
9582 *pos++ = 0x00;
9583 /* Current AP */
9584 hwaddr_aton(bssid, pos);
9585 pos += 6;
9586 /* SSID */
9587 *pos++ = 0x00;
9588 *pos++ = ssid_len;
9589 memcpy(pos, ssid, ssid_len);
9590 pos += ssid_len;
9591 /* Supported Rates */
9592 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9593 10);
9594 pos += 10;
9595 /* Extended Supported Rates */
9596 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9597 pos += 6;
9598 /* RSN */
9599 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9600 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9601 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9602 pos += 28;
9603 break;
9604 case DLS_REQ:
9605 /* Category - DLS */
9606 *pos++ = 0x02;
9607 /* DLS Action - Request */
9608 *pos++ = 0x00;
9609 /* Destination MACAddress */
9610 if (dest)
9611 hwaddr_aton(dest, pos);
9612 else
9613 memset(pos, 0, 6);
9614 pos += 6;
9615 /* Source MACAddress */
9616 hwaddr_aton(addr, pos);
9617 pos += 6;
9618 /* Capability Information */
9619 *pos++ = 0x10; /* Privacy */
9620 *pos++ = 0x06; /* QoS */
9621 /* DLS Timeout Value */
9622 *pos++ = 0x00;
9623 *pos++ = 0x01;
9624 /* Supported rates */
9625 *pos++ = 0x01;
9626 *pos++ = 0x08;
9627 *pos++ = 0x0c; /* 6 Mbps */
9628 *pos++ = 0x12; /* 9 Mbps */
9629 *pos++ = 0x18; /* 12 Mbps */
9630 *pos++ = 0x24; /* 18 Mbps */
9631 *pos++ = 0x30; /* 24 Mbps */
9632 *pos++ = 0x48; /* 36 Mbps */
9633 *pos++ = 0x60; /* 48 Mbps */
9634 *pos++ = 0x6c; /* 54 Mbps */
9635 /* TODO: Extended Supported Rates */
9636 /* TODO: HT Capabilities */
9637 break;
9638 }
9639 }
9640
9641 s = open_monitor("sigmadut");
9642 if (s < 0) {
9643 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9644 "monitor socket");
9645 return 0;
9646 }
9647
9648 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9649 if (res < 0) {
9650 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9651 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309652 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009653 return 0;
9654 }
9655 if (res < pos - buf) {
9656 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9657 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309658 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009659 return 0;
9660 }
9661
9662 close(s);
9663
9664 return 1;
9665#else /* __linux__ */
9666 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9667 "yet supported");
9668 return 0;
9669#endif /* __linux__ */
9670}
9671
9672
9673static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9674 struct sigma_conn *conn,
9675 struct sigma_cmd *cmd)
9676{
9677 const char *intf = get_param(cmd, "Interface");
9678 const char *sta, *val;
9679 unsigned char addr[ETH_ALEN];
9680 char buf[100];
9681
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009682 if (!intf)
9683 return -1;
9684
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009685 sta = get_param(cmd, "peer");
9686 if (sta == NULL)
9687 sta = get_param(cmd, "station");
9688 if (sta == NULL) {
9689 send_resp(dut, conn, SIGMA_ERROR,
9690 "ErrorCode,Missing peer address");
9691 return 0;
9692 }
9693 if (hwaddr_aton(sta, addr) < 0) {
9694 send_resp(dut, conn, SIGMA_ERROR,
9695 "ErrorCode,Invalid peer address");
9696 return 0;
9697 }
9698
9699 val = get_param(cmd, "type");
9700 if (val == NULL)
9701 return -1;
9702
9703 if (strcasecmp(val, "DISCOVERY") == 0) {
9704 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9705 if (wpa_command(intf, buf) < 0) {
9706 send_resp(dut, conn, SIGMA_ERROR,
9707 "ErrorCode,Failed to send TDLS discovery");
9708 return 0;
9709 }
9710 return 1;
9711 }
9712
9713 if (strcasecmp(val, "SETUP") == 0) {
9714 int status = 0, timeout = 0;
9715
9716 val = get_param(cmd, "Status");
9717 if (val)
9718 status = atoi(val);
9719
9720 val = get_param(cmd, "Timeout");
9721 if (val)
9722 timeout = atoi(val);
9723
9724 if (status != 0 && status != 37) {
9725 send_resp(dut, conn, SIGMA_ERROR,
9726 "ErrorCode,Unsupported status value");
9727 return 0;
9728 }
9729
9730 if (timeout != 0 && timeout != 301) {
9731 send_resp(dut, conn, SIGMA_ERROR,
9732 "ErrorCode,Unsupported timeout value");
9733 return 0;
9734 }
9735
9736 if (status && timeout) {
9737 send_resp(dut, conn, SIGMA_ERROR,
9738 "ErrorCode,Unsupported timeout+status "
9739 "combination");
9740 return 0;
9741 }
9742
9743 if (status == 37 &&
9744 wpa_command(intf, "SET tdls_testing 0x200")) {
9745 send_resp(dut, conn, SIGMA_ERROR,
9746 "ErrorCode,Failed to enable "
9747 "decline setup response test mode");
9748 return 0;
9749 }
9750
9751 if (timeout == 301) {
9752 int res;
9753 if (dut->no_tpk_expiration)
9754 res = wpa_command(intf,
9755 "SET tdls_testing 0x108");
9756 else
9757 res = wpa_command(intf,
9758 "SET tdls_testing 0x8");
9759 if (res) {
9760 send_resp(dut, conn, SIGMA_ERROR,
9761 "ErrorCode,Failed to set short TPK "
9762 "lifetime");
9763 return 0;
9764 }
9765 }
9766
9767 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9768 if (wpa_command(intf, buf) < 0) {
9769 send_resp(dut, conn, SIGMA_ERROR,
9770 "ErrorCode,Failed to send TDLS setup");
9771 return 0;
9772 }
9773 return 1;
9774 }
9775
9776 if (strcasecmp(val, "TEARDOWN") == 0) {
9777 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9778 if (wpa_command(intf, buf) < 0) {
9779 send_resp(dut, conn, SIGMA_ERROR,
9780 "ErrorCode,Failed to send TDLS teardown");
9781 return 0;
9782 }
9783 return 1;
9784 }
9785
9786 send_resp(dut, conn, SIGMA_ERROR,
9787 "ErrorCode,Unsupported TDLS frame");
9788 return 0;
9789}
9790
9791
9792static int sta_ap_known(const char *ifname, const char *bssid)
9793{
9794 char buf[4096];
9795
Jouni Malinendd32f192018-09-15 02:55:19 +03009796 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009797 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9798 return 0;
9799 if (strncmp(buf, "id=", 3) != 0)
9800 return 0;
9801 return 1;
9802}
9803
9804
9805static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9806 const char *bssid)
9807{
9808 int res;
9809 struct wpa_ctrl *ctrl;
9810 char buf[256];
9811
9812 if (sta_ap_known(ifname, bssid))
9813 return 0;
9814 sigma_dut_print(dut, DUT_MSG_DEBUG,
9815 "AP not in BSS table - start scan");
9816
9817 ctrl = open_wpa_mon(ifname);
9818 if (ctrl == NULL) {
9819 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9820 "wpa_supplicant monitor connection");
9821 return -1;
9822 }
9823
9824 if (wpa_command(ifname, "SCAN") < 0) {
9825 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9826 wpa_ctrl_detach(ctrl);
9827 wpa_ctrl_close(ctrl);
9828 return -1;
9829 }
9830
9831 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9832 buf, sizeof(buf));
9833
9834 wpa_ctrl_detach(ctrl);
9835 wpa_ctrl_close(ctrl);
9836
9837 if (res < 0) {
9838 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9839 return -1;
9840 }
9841
9842 if (sta_ap_known(ifname, bssid))
9843 return 0;
9844 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9845 return -1;
9846}
9847
9848
9849static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9850 struct sigma_conn *conn,
9851 struct sigma_cmd *cmd,
9852 const char *intf)
9853{
9854 char buf[200];
9855
9856 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9857 if (system(buf) != 0) {
9858 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9859 "ndsend");
9860 return 0;
9861 }
9862
9863 return 1;
9864}
9865
9866
9867static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9868 struct sigma_conn *conn,
9869 struct sigma_cmd *cmd,
9870 const char *intf)
9871{
9872 char buf[200];
9873 const char *ip = get_param(cmd, "SenderIP");
9874
Peng Xu26b356d2017-10-04 17:58:16 -07009875 if (!ip)
9876 return 0;
9877
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009878 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9879 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9880 if (system(buf) == 0) {
9881 sigma_dut_print(dut, DUT_MSG_INFO,
9882 "Neighbor Solicitation got a response "
9883 "for %s@%s", ip, intf);
9884 }
9885
9886 return 1;
9887}
9888
9889
9890static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9891 struct sigma_conn *conn,
9892 struct sigma_cmd *cmd,
9893 const char *ifname)
9894{
9895 char buf[200];
9896 const char *ip = get_param(cmd, "SenderIP");
9897
9898 if (ip == NULL) {
9899 send_resp(dut, conn, SIGMA_ERROR,
9900 "ErrorCode,Missing SenderIP parameter");
9901 return 0;
9902 }
9903 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9904 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9905 if (system(buf) != 0) {
9906 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9907 "for %s@%s", ip, ifname);
9908 }
9909
9910 return 1;
9911}
9912
9913
9914static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9915 struct sigma_conn *conn,
9916 struct sigma_cmd *cmd,
9917 const char *ifname)
9918{
9919 char buf[200];
9920 char ip[16];
9921 int s;
Peng Xub3756882017-10-04 14:39:09 -07009922 struct ifreq ifr;
9923 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009924
9925 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009926 if (s < 0) {
9927 perror("socket");
9928 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009929 }
9930
Peng Xub3756882017-10-04 14:39:09 -07009931 memset(&ifr, 0, sizeof(ifr));
9932 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9933 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9934 sigma_dut_print(dut, DUT_MSG_INFO,
9935 "Failed to get %s IP address: %s",
9936 ifname, strerror(errno));
9937 close(s);
9938 return -1;
9939 }
9940 close(s);
9941
9942 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9943 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9944
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009945 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9946 ip);
9947 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9948 if (system(buf) != 0) {
9949 }
9950
9951 return 1;
9952}
9953
9954
9955static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9956 struct sigma_conn *conn,
9957 struct sigma_cmd *cmd,
9958 const char *ifname)
9959{
9960 char buf[200], addr[20];
9961 char dst[ETH_ALEN], src[ETH_ALEN];
9962 short ethtype = htons(ETH_P_ARP);
9963 char *pos;
9964 int s, res;
9965 const char *val;
9966 struct sockaddr_in taddr;
9967
9968 val = get_param(cmd, "dest");
9969 if (val)
9970 hwaddr_aton(val, (unsigned char *) dst);
9971
9972 val = get_param(cmd, "DestIP");
9973 if (val)
9974 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009975 else
9976 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009977
Jouni Malinen016ae6c2019-11-04 17:00:01 +02009978 if (get_wpa_status(get_station_ifname(dut), "address", addr,
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009979 sizeof(addr)) < 0)
9980 return -2;
9981 hwaddr_aton(addr, (unsigned char *) src);
9982
9983 pos = buf;
9984 *pos++ = 0x00;
9985 *pos++ = 0x01;
9986 *pos++ = 0x08;
9987 *pos++ = 0x00;
9988 *pos++ = 0x06;
9989 *pos++ = 0x04;
9990 *pos++ = 0x00;
9991 *pos++ = 0x02;
9992 memcpy(pos, src, ETH_ALEN);
9993 pos += ETH_ALEN;
9994 memcpy(pos, &taddr.sin_addr, 4);
9995 pos += 4;
9996 memcpy(pos, dst, ETH_ALEN);
9997 pos += ETH_ALEN;
9998 memcpy(pos, &taddr.sin_addr, 4);
9999 pos += 4;
10000
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010001 s = open_monitor(get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010002 if (s < 0) {
10003 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
10004 "monitor socket");
10005 return 0;
10006 }
10007
10008 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
10009 if (res < 0) {
10010 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
10011 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +053010012 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010013 return 0;
10014 }
10015
10016 close(s);
10017
10018 return 1;
10019}
10020
10021
10022static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
10023 struct sigma_conn *conn,
10024 struct sigma_cmd *cmd,
10025 const char *intf, const char *dest)
10026{
10027 char buf[100];
10028
10029 if (if_nametoindex("sigmadut") == 0) {
10030 snprintf(buf, sizeof(buf),
10031 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010032 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010033 if (system(buf) != 0 ||
10034 if_nametoindex("sigmadut") == 0) {
10035 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10036 "monitor interface with '%s'", buf);
10037 return -2;
10038 }
10039 }
10040
10041 if (system("ifconfig sigmadut up") != 0) {
10042 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10043 "monitor interface up");
10044 return -2;
10045 }
10046
10047 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10048}
10049
10050
10051static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10052 struct sigma_conn *conn,
10053 struct sigma_cmd *cmd)
10054{
10055 const char *intf = get_param(cmd, "Interface");
10056 const char *dest = get_param(cmd, "Dest");
10057 const char *type = get_param(cmd, "FrameName");
10058 const char *val;
10059 char buf[200], *pos, *end;
10060 int count, count2;
10061
10062 if (type == NULL)
10063 type = get_param(cmd, "Type");
10064
10065 if (intf == NULL || dest == NULL || type == NULL)
10066 return -1;
10067
10068 if (strcasecmp(type, "NeighAdv") == 0)
10069 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10070
10071 if (strcasecmp(type, "NeighSolicitReq") == 0)
10072 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10073
10074 if (strcasecmp(type, "ARPProbe") == 0)
10075 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10076
10077 if (strcasecmp(type, "ARPAnnounce") == 0)
10078 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10079
10080 if (strcasecmp(type, "ARPReply") == 0)
10081 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10082
10083 if (strcasecmp(type, "DLS-request") == 0 ||
10084 strcasecmp(type, "DLSrequest") == 0)
10085 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10086 dest);
10087
10088 if (strcasecmp(type, "ANQPQuery") != 0 &&
10089 strcasecmp(type, "Query") != 0) {
10090 send_resp(dut, conn, SIGMA_ERROR,
10091 "ErrorCode,Unsupported HS 2.0 send frame type");
10092 return 0;
10093 }
10094
10095 if (sta_scan_ap(dut, intf, dest) < 0) {
10096 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10097 "the requested AP");
10098 return 0;
10099 }
10100
10101 pos = buf;
10102 end = buf + sizeof(buf);
10103 count = 0;
10104 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10105
10106 val = get_param(cmd, "ANQP_CAP_LIST");
10107 if (val && atoi(val)) {
10108 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10109 count++;
10110 }
10111
10112 val = get_param(cmd, "VENUE_NAME");
10113 if (val && atoi(val)) {
10114 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10115 count++;
10116 }
10117
10118 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10119 if (val && atoi(val)) {
10120 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10121 count++;
10122 }
10123
10124 val = get_param(cmd, "ROAMING_CONS");
10125 if (val && atoi(val)) {
10126 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10127 count++;
10128 }
10129
10130 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10131 if (val && atoi(val)) {
10132 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10133 count++;
10134 }
10135
10136 val = get_param(cmd, "NAI_REALM_LIST");
10137 if (val && atoi(val)) {
10138 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10139 count++;
10140 }
10141
10142 val = get_param(cmd, "3GPP_INFO");
10143 if (val && atoi(val)) {
10144 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10145 count++;
10146 }
10147
10148 val = get_param(cmd, "DOMAIN_LIST");
10149 if (val && atoi(val)) {
10150 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10151 count++;
10152 }
10153
Jouni Malinen34cf9532018-04-29 19:26:33 +030010154 val = get_param(cmd, "Venue_URL");
10155 if (val && atoi(val)) {
10156 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10157 count++;
10158 }
10159
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010160 val = get_param(cmd, "Advice_Of_Charge");
10161 if (val && atoi(val)) {
10162 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10163 count++;
10164 }
10165
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010166 if (count && wpa_command(intf, buf)) {
10167 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10168 return 0;
10169 }
10170
10171 pos = buf;
10172 end = buf + sizeof(buf);
10173 count2 = 0;
10174 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10175
10176 val = get_param(cmd, "HS_CAP_LIST");
10177 if (val && atoi(val)) {
10178 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10179 count2++;
10180 }
10181
10182 val = get_param(cmd, "OPER_NAME");
10183 if (val && atoi(val)) {
10184 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10185 count2++;
10186 }
10187
10188 val = get_param(cmd, "WAN_METRICS");
10189 if (!val)
10190 val = get_param(cmd, "WAN_MAT");
10191 if (!val)
10192 val = get_param(cmd, "WAN_MET");
10193 if (val && atoi(val)) {
10194 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10195 count2++;
10196 }
10197
10198 val = get_param(cmd, "CONNECTION_CAPABILITY");
10199 if (val && atoi(val)) {
10200 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10201 count2++;
10202 }
10203
10204 val = get_param(cmd, "OP_CLASS");
10205 if (val && atoi(val)) {
10206 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10207 count2++;
10208 }
10209
10210 val = get_param(cmd, "OSU_PROVIDER_LIST");
10211 if (val && atoi(val)) {
10212 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10213 count2++;
10214 }
10215
Jouni Malinenf67afec2018-04-29 19:24:58 +030010216 val = get_param(cmd, "OPER_ICON_METADATA");
10217 if (!val)
10218 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10219 if (val && atoi(val)) {
10220 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10221 count2++;
10222 }
10223
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010224 if (count && count2) {
10225 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10226 "second query");
10227 sleep(1);
10228 }
10229
10230 if (count2 && wpa_command(intf, buf)) {
10231 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10232 "failed");
10233 return 0;
10234 }
10235
10236 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10237 if (val) {
10238 if (count || count2) {
10239 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10240 "sending out second query");
10241 sleep(1);
10242 }
10243
10244 if (strcmp(val, "1") == 0)
10245 val = "mail.example.com";
10246 snprintf(buf, end - pos,
10247 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10248 dest, val);
10249 if (wpa_command(intf, buf)) {
10250 send_resp(dut, conn, SIGMA_ERROR,
10251 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10252 "failed");
10253 return 0;
10254 }
10255 }
10256
10257 val = get_param(cmd, "ICON_REQUEST");
10258 if (val) {
10259 if (count || count2) {
10260 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10261 "sending out second query");
10262 sleep(1);
10263 }
10264
10265 snprintf(buf, end - pos,
10266 "HS20_ICON_REQUEST %s %s", dest, val);
10267 if (wpa_command(intf, buf)) {
10268 send_resp(dut, conn, SIGMA_ERROR,
10269 "ErrorCode,HS20_ICON_REQUEST failed");
10270 return 0;
10271 }
10272 }
10273
10274 return 1;
10275}
10276
10277
10278static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10279 struct sigma_conn *conn,
10280 struct sigma_cmd *cmd)
10281{
10282 const char *val;
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010283 const char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010284 int chwidth, nss;
10285
10286 val = get_param(cmd, "framename");
10287 if (!val)
10288 return -1;
10289 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10290
10291 /* Command sequence to generate Op mode notification */
10292 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010293 ifname = get_station_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010294
10295 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010296 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010297
10298 /* Extract Channel width */
10299 val = get_param(cmd, "Channel_width");
10300 if (val) {
10301 switch (atoi(val)) {
10302 case 20:
10303 chwidth = 0;
10304 break;
10305 case 40:
10306 chwidth = 1;
10307 break;
10308 case 80:
10309 chwidth = 2;
10310 break;
10311 case 160:
10312 chwidth = 3;
10313 break;
10314 default:
10315 chwidth = 2;
10316 break;
10317 }
10318
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010319 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010320 }
10321
10322 /* Extract NSS */
10323 val = get_param(cmd, "NSS");
10324 if (val) {
10325 switch (atoi(val)) {
10326 case 1:
10327 nss = 1;
10328 break;
10329 case 2:
10330 nss = 3;
10331 break;
10332 case 3:
10333 nss = 7;
10334 break;
10335 default:
10336 /* We do not support NSS > 3 */
10337 nss = 3;
10338 break;
10339 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010340 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010341 }
10342
10343 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010344 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010345 }
10346
10347 return 1;
10348}
10349
10350
10351static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10352 struct sigma_conn *conn,
10353 struct sigma_cmd *cmd)
10354{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010355 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010356 case DRIVER_ATHEROS:
10357 return ath_sta_send_frame_vht(dut, conn, cmd);
10358 default:
10359 send_resp(dut, conn, SIGMA_ERROR,
10360 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10361 return 0;
10362 }
10363}
10364
10365
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010366static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10367 struct sigma_cmd *cmd)
10368{
10369 const char *val;
10370 const char *intf = get_param(cmd, "Interface");
10371
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010372 if (!intf)
10373 return -1;
10374
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010375 val = get_param(cmd, "framename");
10376 if (!val)
10377 return -1;
10378 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10379
10380 /* Command sequence to generate Op mode notification */
10381 if (val && strcasecmp(val, "action") == 0) {
10382 val = get_param(cmd, "PPDUTxType");
10383 if (val && strcasecmp(val, "TB") == 0) {
10384 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10385 sigma_dut_print(dut, DUT_MSG_ERROR,
10386 "failed to send TB PPDU Tx cfg");
10387 send_resp(dut, conn, SIGMA_ERROR,
10388 "ErrorCode,set TB PPDU Tx cfg failed");
10389 return 0;
10390 }
10391 return 1;
10392 }
10393
10394 sigma_dut_print(dut, DUT_MSG_ERROR,
10395 "Action Tx type is not defined");
10396 }
10397
10398 return 1;
10399}
10400
10401
10402static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10403 struct sigma_conn *conn,
10404 struct sigma_cmd *cmd)
10405{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010406 switch (get_driver_type(dut)) {
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010407 case DRIVER_WCN:
10408 return wcn_sta_send_frame_he(dut, conn, cmd);
10409 default:
10410 send_resp(dut, conn, SIGMA_ERROR,
10411 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10412 return 0;
10413 }
10414}
10415
10416
Lior David0fe101e2017-03-09 16:09:50 +020010417#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010418
10419static int
10420wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10421 const char *frame_name, const char *dest_mac)
10422{
10423 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10424 const char *ssid = get_param(cmd, "ssid");
10425 const char *countstr = get_param(cmd, "count");
10426 const char *channelstr = get_param(cmd, "channel");
10427 const char *group_id = get_param(cmd, "groupid");
10428 const char *client_id = get_param(cmd, "clientmac");
10429 int count, channel, freq, i;
10430 const char *fname;
10431 char frame[1024], src_mac[20], group_id_attr[25],
10432 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10433 const char *group_ssid;
10434 const int group_ssid_prefix_len = 9;
10435 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10436 size_t framelen = sizeof(frame);
10437 struct template_frame_tag tags[2];
10438 size_t tags_total = ARRAY_SIZE(tags);
10439 int tag_index, len, dst_len;
10440
10441 if (!countstr || !channelstr) {
10442 sigma_dut_print(dut, DUT_MSG_ERROR,
10443 "Missing argument: count, channel");
10444 return -1;
10445 }
10446 if (isprobereq && !ssid) {
10447 sigma_dut_print(dut, DUT_MSG_ERROR,
10448 "Missing argument: ssid");
10449 return -1;
10450 }
10451 if (!isprobereq && (!group_id || !client_id)) {
10452 sigma_dut_print(dut, DUT_MSG_ERROR,
10453 "Missing argument: group_id, client_id");
10454 return -1;
10455 }
10456
10457 count = atoi(countstr);
10458 channel = atoi(channelstr);
10459 freq = channel_to_freq(dut, channel);
10460
10461 if (!freq) {
10462 sigma_dut_print(dut, DUT_MSG_ERROR,
10463 "invalid channel: %s", channelstr);
10464 return -1;
10465 }
10466
10467 if (isprobereq) {
10468 if (strcasecmp(ssid, "wildcard") == 0) {
10469 fname = "probe_req_wildcard.txt";
10470 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10471 fname = "probe_req_P2P_Wildcard.txt";
10472 } else {
10473 sigma_dut_print(dut, DUT_MSG_ERROR,
10474 "invalid probe request type");
10475 return -1;
10476 }
10477 } else {
10478 fname = "P2P_device_discovery_req.txt";
10479 }
10480
10481 if (parse_template_frame_file(dut, fname, frame, &framelen,
10482 tags, &tags_total)) {
10483 sigma_dut_print(dut, DUT_MSG_ERROR,
10484 "invalid frame template: %s", fname);
10485 return -1;
10486 }
10487
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010488 if (get_wpa_status(get_station_ifname(dut), "address",
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010489 src_mac, sizeof(src_mac)) < 0 ||
10490 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10491 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10492 return -1;
10493 /* Use wildcard BSSID, since we are in PBSS */
10494 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10495
10496 if (!isprobereq) {
10497 tag_index = find_template_frame_tag(tags, tags_total, 1);
10498 if (tag_index < 0) {
10499 sigma_dut_print(dut, DUT_MSG_ERROR,
10500 "can't find device id attribute");
10501 return -1;
10502 }
10503 if (parse_mac_address(dut, client_id,
10504 (unsigned char *) client_mac)) {
10505 sigma_dut_print(dut, DUT_MSG_ERROR,
10506 "invalid client_id: %s", client_id);
10507 return -1;
10508 }
10509 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10510 framelen - tags[tag_index].offset,
10511 IEEE80211_P2P_ATTR_DEVICE_ID,
10512 client_mac, ETH_ALEN)) {
10513 sigma_dut_print(dut, DUT_MSG_ERROR,
10514 "fail to replace device id attribute");
10515 return -1;
10516 }
10517
10518 /*
10519 * group_id arg contains device MAC address followed by
10520 * space and SSID (DIRECT-somessid).
10521 * group id attribute contains device address (6 bytes)
10522 * followed by SSID prefix DIRECT-XX (9 bytes)
10523 */
10524 if (strlen(group_id) < sizeof(device_macstr)) {
10525 sigma_dut_print(dut, DUT_MSG_ERROR,
10526 "group_id arg too short");
10527 return -1;
10528 }
10529 memcpy(device_macstr, group_id, sizeof(device_macstr));
10530 device_macstr[sizeof(device_macstr) - 1] = '\0';
10531 if (parse_mac_address(dut, device_macstr,
10532 (unsigned char *) group_id_attr)) {
10533 sigma_dut_print(dut, DUT_MSG_ERROR,
10534 "fail to parse device address from group_id");
10535 return -1;
10536 }
10537 group_ssid = strchr(group_id, ' ');
10538 if (!group_ssid) {
10539 sigma_dut_print(dut, DUT_MSG_ERROR,
10540 "invalid group_id arg, no ssid");
10541 return -1;
10542 }
10543 group_ssid++;
10544 len = strlen(group_ssid);
10545 if (len < group_ssid_prefix_len) {
10546 sigma_dut_print(dut, DUT_MSG_ERROR,
10547 "group_id SSID too short");
10548 return -1;
10549 }
10550 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10551 if (len > dst_len) {
10552 sigma_dut_print(dut, DUT_MSG_ERROR,
10553 "group_id SSID (%s) too long",
10554 group_ssid);
10555 return -1;
10556 }
10557
10558 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10559 tag_index = find_template_frame_tag(tags, tags_total, 2);
10560 if (tag_index < 0) {
10561 sigma_dut_print(dut, DUT_MSG_ERROR,
10562 "can't find group id attribute");
10563 return -1;
10564 }
10565 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10566 framelen - tags[tag_index].offset,
10567 IEEE80211_P2P_ATTR_GROUP_ID,
10568 group_id_attr,
10569 sizeof(group_id_attr))) {
10570 sigma_dut_print(dut, DUT_MSG_ERROR,
10571 "fail to replace group id attribute");
10572 return -1;
10573 }
10574 }
10575
10576 for (i = 0; i < count; i++) {
10577 if (wil6210_transmit_frame(dut, freq,
10578 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10579 frame, framelen)) {
10580 sigma_dut_print(dut, DUT_MSG_ERROR,
10581 "fail to transmit probe request frame");
10582 return -1;
10583 }
10584 }
10585
10586 return 0;
10587}
10588
10589
Lior David0fe101e2017-03-09 16:09:50 +020010590int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10591 struct sigma_cmd *cmd)
10592{
10593 const char *frame_name = get_param(cmd, "framename");
10594 const char *mac = get_param(cmd, "dest_mac");
10595
10596 if (!frame_name || !mac) {
10597 sigma_dut_print(dut, DUT_MSG_ERROR,
10598 "framename and dest_mac must be provided");
10599 return -1;
10600 }
10601
10602 if (strcasecmp(frame_name, "brp") == 0) {
10603 const char *l_rx = get_param(cmd, "L-RX");
10604 int l_rx_i;
10605
10606 if (!l_rx) {
10607 sigma_dut_print(dut, DUT_MSG_ERROR,
10608 "L-RX must be provided");
10609 return -1;
10610 }
10611 l_rx_i = atoi(l_rx);
10612
10613 sigma_dut_print(dut, DUT_MSG_INFO,
10614 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10615 mac, l_rx);
10616 if (l_rx_i != 16) {
10617 sigma_dut_print(dut, DUT_MSG_ERROR,
10618 "unsupported L-RX: %s", l_rx);
10619 return -1;
10620 }
10621
10622 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10623 return -1;
10624 } else if (strcasecmp(frame_name, "ssw") == 0) {
10625 sigma_dut_print(dut, DUT_MSG_INFO,
10626 "dev_send_frame: SLS, dest_mac %s", mac);
10627 if (wil6210_send_sls(dut, mac))
10628 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010629 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10630 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10631 sigma_dut_print(dut, DUT_MSG_INFO,
10632 "dev_send_frame: %s, dest_mac %s", frame_name,
10633 mac);
10634 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10635 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010636 } else {
10637 sigma_dut_print(dut, DUT_MSG_ERROR,
10638 "unsupported frame type: %s", frame_name);
10639 return -1;
10640 }
10641
10642 return 1;
10643}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010644
Lior David0fe101e2017-03-09 16:09:50 +020010645#endif /* __linux__ */
10646
10647
10648static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10649 struct sigma_conn *conn,
10650 struct sigma_cmd *cmd)
10651{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010652 switch (get_driver_type(dut)) {
Lior David0fe101e2017-03-09 16:09:50 +020010653#ifdef __linux__
10654 case DRIVER_WIL6210:
10655 return wil6210_send_frame_60g(dut, conn, cmd);
10656#endif /* __linux__ */
10657 default:
10658 send_resp(dut, conn, SIGMA_ERROR,
10659 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10660 return 0;
10661 }
10662}
10663
10664
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010665static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10666 const char *intf, struct sigma_cmd *cmd)
10667{
10668 const char *val, *addr;
10669 char buf[100];
10670
10671 addr = get_param(cmd, "DestMac");
10672 if (!addr) {
10673 send_resp(dut, conn, SIGMA_INVALID,
10674 "ErrorCode,AP MAC address is missing");
10675 return 0;
10676 }
10677
10678 val = get_param(cmd, "ANQPQuery_ID");
10679 if (!val) {
10680 send_resp(dut, conn, SIGMA_INVALID,
10681 "ErrorCode,Missing ANQPQuery_ID");
10682 return 0;
10683 }
10684
10685 if (strcasecmp(val, "NeighborReportReq") == 0) {
10686 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10687 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10688 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10689 } else {
10690 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10691 val);
10692 send_resp(dut, conn, SIGMA_INVALID,
10693 "ErrorCode,Invalid ANQPQuery_ID");
10694 return 0;
10695 }
10696
Ashwini Patild174f2c2017-04-13 16:49:46 +053010697 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10698 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10699 * if associated, AP BSSID).
10700 */
10701 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10702 send_resp(dut, conn, SIGMA_ERROR,
10703 "ErrorCode,Failed to set gas_address3");
10704 return 0;
10705 }
10706
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010707 if (wpa_command(intf, buf) < 0) {
10708 send_resp(dut, conn, SIGMA_ERROR,
10709 "ErrorCode,Failed to send ANQP query");
10710 return 0;
10711 }
10712
10713 return 1;
10714}
10715
10716
10717static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10718 struct sigma_conn *conn,
10719 const char *intf,
10720 struct sigma_cmd *cmd)
10721{
10722 const char *val = get_param(cmd, "FrameName");
10723
10724 if (val && strcasecmp(val, "ANQPQuery") == 0)
10725 return mbo_send_anqp_query(dut, conn, intf, cmd);
10726
10727 return 2;
10728}
10729
10730
Jouni Malinenf7222712019-06-13 01:50:21 +030010731enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10732 struct sigma_conn *conn,
10733 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010734{
10735 const char *intf = get_param(cmd, "Interface");
10736 const char *val;
10737 enum send_frame_type frame;
10738 enum send_frame_protection protected;
10739 char buf[100];
10740 unsigned char addr[ETH_ALEN];
10741 int res;
10742
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010743 if (!intf)
10744 return -1;
10745
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010746 val = get_param(cmd, "program");
10747 if (val == NULL)
10748 val = get_param(cmd, "frame");
10749 if (val && strcasecmp(val, "TDLS") == 0)
10750 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10751 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010752 strcasecmp(val, "HS2-R2") == 0 ||
10753 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010754 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10755 if (val && strcasecmp(val, "VHT") == 0)
10756 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010757 if (val && strcasecmp(val, "HE") == 0)
10758 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010759 if (val && strcasecmp(val, "LOC") == 0)
10760 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010761 if (val && strcasecmp(val, "60GHz") == 0)
10762 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010763 if (val && strcasecmp(val, "MBO") == 0) {
10764 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10765 if (res != 2)
10766 return res;
10767 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010768
10769 val = get_param(cmd, "TD_DISC");
10770 if (val) {
10771 if (hwaddr_aton(val, addr) < 0)
10772 return -1;
10773 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10774 if (wpa_command(intf, buf) < 0) {
10775 send_resp(dut, conn, SIGMA_ERROR,
10776 "ErrorCode,Failed to send TDLS discovery");
10777 return 0;
10778 }
10779 return 1;
10780 }
10781
10782 val = get_param(cmd, "TD_Setup");
10783 if (val) {
10784 if (hwaddr_aton(val, addr) < 0)
10785 return -1;
10786 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10787 if (wpa_command(intf, buf) < 0) {
10788 send_resp(dut, conn, SIGMA_ERROR,
10789 "ErrorCode,Failed to start TDLS setup");
10790 return 0;
10791 }
10792 return 1;
10793 }
10794
10795 val = get_param(cmd, "TD_TearDown");
10796 if (val) {
10797 if (hwaddr_aton(val, addr) < 0)
10798 return -1;
10799 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10800 if (wpa_command(intf, buf) < 0) {
10801 send_resp(dut, conn, SIGMA_ERROR,
10802 "ErrorCode,Failed to tear down TDLS link");
10803 return 0;
10804 }
10805 return 1;
10806 }
10807
10808 val = get_param(cmd, "TD_ChannelSwitch");
10809 if (val) {
10810 /* TODO */
10811 send_resp(dut, conn, SIGMA_ERROR,
10812 "ErrorCode,TD_ChannelSwitch not yet supported");
10813 return 0;
10814 }
10815
10816 val = get_param(cmd, "TD_NF");
10817 if (val) {
10818 /* TODO */
10819 send_resp(dut, conn, SIGMA_ERROR,
10820 "ErrorCode,TD_NF not yet supported");
10821 return 0;
10822 }
10823
10824 val = get_param(cmd, "PMFFrameType");
10825 if (val == NULL)
10826 val = get_param(cmd, "FrameName");
10827 if (val == NULL)
10828 val = get_param(cmd, "Type");
10829 if (val == NULL)
10830 return -1;
10831 if (strcasecmp(val, "disassoc") == 0)
10832 frame = DISASSOC;
10833 else if (strcasecmp(val, "deauth") == 0)
10834 frame = DEAUTH;
10835 else if (strcasecmp(val, "saquery") == 0)
10836 frame = SAQUERY;
10837 else if (strcasecmp(val, "auth") == 0)
10838 frame = AUTH;
10839 else if (strcasecmp(val, "assocreq") == 0)
10840 frame = ASSOCREQ;
10841 else if (strcasecmp(val, "reassocreq") == 0)
10842 frame = REASSOCREQ;
10843 else if (strcasecmp(val, "neigreq") == 0) {
10844 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10845
10846 val = get_param(cmd, "ssid");
10847 if (val == NULL)
10848 return -1;
10849
10850 res = send_neighbor_request(dut, intf, val);
10851 if (res) {
10852 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10853 "Failed to send neighbor report request");
10854 return 0;
10855 }
10856
10857 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010858 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10859 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010860 sigma_dut_print(dut, DUT_MSG_DEBUG,
10861 "Got Transition Management Query");
10862
Ashwini Patil5acd7382017-04-13 15:55:04 +053010863 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010864 if (res) {
10865 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10866 "Failed to send Transition Management Query");
10867 return 0;
10868 }
10869
10870 return 1;
10871 } else {
10872 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10873 "PMFFrameType");
10874 return 0;
10875 }
10876
10877 val = get_param(cmd, "PMFProtected");
10878 if (val == NULL)
10879 val = get_param(cmd, "Protected");
10880 if (val == NULL)
10881 return -1;
10882 if (strcasecmp(val, "Correct-key") == 0 ||
10883 strcasecmp(val, "CorrectKey") == 0)
10884 protected = CORRECT_KEY;
10885 else if (strcasecmp(val, "IncorrectKey") == 0)
10886 protected = INCORRECT_KEY;
10887 else if (strcasecmp(val, "Unprotected") == 0)
10888 protected = UNPROTECTED;
10889 else {
10890 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10891 "PMFProtected");
10892 return 0;
10893 }
10894
10895 if (protected != UNPROTECTED &&
10896 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10897 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10898 "PMFProtected for auth/assocreq/reassocreq");
10899 return 0;
10900 }
10901
10902 if (if_nametoindex("sigmadut") == 0) {
10903 snprintf(buf, sizeof(buf),
10904 "iw dev %s interface add sigmadut type monitor",
Jouni Malinen016ae6c2019-11-04 17:00:01 +020010905 get_station_ifname(dut));
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010906 if (system(buf) != 0 ||
10907 if_nametoindex("sigmadut") == 0) {
10908 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10909 "monitor interface with '%s'", buf);
10910 return -2;
10911 }
10912 }
10913
10914 if (system("ifconfig sigmadut up") != 0) {
10915 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10916 "monitor interface up");
10917 return -2;
10918 }
10919
10920 return sta_inject_frame(dut, conn, frame, protected, NULL);
10921}
10922
10923
10924static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10925 struct sigma_conn *conn,
10926 struct sigma_cmd *cmd,
10927 const char *ifname)
10928{
10929 char buf[200];
10930 const char *val;
10931
10932 val = get_param(cmd, "ClearARP");
10933 if (val && atoi(val) == 1) {
10934 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10935 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10936 if (system(buf) != 0) {
10937 send_resp(dut, conn, SIGMA_ERROR,
10938 "errorCode,Failed to clear ARP cache");
10939 return 0;
10940 }
10941 }
10942
10943 return 1;
10944}
10945
10946
10947int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10948 struct sigma_cmd *cmd)
10949{
10950 const char *intf = get_param(cmd, "Interface");
10951 const char *val;
10952
10953 if (intf == NULL)
10954 return -1;
10955
10956 val = get_param(cmd, "program");
10957 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010958 strcasecmp(val, "HS2-R2") == 0 ||
10959 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010960 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10961
10962 return -1;
10963}
10964
10965
Jouni Malinenf7222712019-06-13 01:50:21 +030010966static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
10967 struct sigma_conn *conn,
10968 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010969{
10970 const char *intf = get_param(cmd, "Interface");
10971 const char *mac = get_param(cmd, "MAC");
10972
10973 if (intf == NULL || mac == NULL)
10974 return -1;
10975
10976 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10977 "interface %s to %s", intf, mac);
10978
10979 if (dut->set_macaddr) {
10980 char buf[128];
10981 int res;
10982 if (strcasecmp(mac, "default") == 0) {
10983 res = snprintf(buf, sizeof(buf), "%s",
10984 dut->set_macaddr);
10985 dut->tmp_mac_addr = 0;
10986 } else {
10987 res = snprintf(buf, sizeof(buf), "%s %s",
10988 dut->set_macaddr, mac);
10989 dut->tmp_mac_addr = 1;
10990 }
10991 if (res < 0 || res >= (int) sizeof(buf))
10992 return -1;
10993 if (system(buf) != 0) {
10994 send_resp(dut, conn, SIGMA_ERROR,
10995 "errorCode,Failed to set MAC "
10996 "address");
10997 return 0;
10998 }
10999 return 1;
11000 }
11001
11002 if (strcasecmp(mac, "default") == 0)
11003 return 1;
11004
11005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11006 "command");
11007 return 0;
11008}
11009
11010
11011static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
11012 struct sigma_conn *conn, const char *intf,
11013 int val)
11014{
11015 char buf[200];
11016 int res;
11017
11018 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
11019 intf, val);
11020 if (res < 0 || res >= (int) sizeof(buf))
11021 return -1;
11022 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11023 if (system(buf) != 0) {
11024 send_resp(dut, conn, SIGMA_ERROR,
11025 "errorCode,Failed to configure offchannel mode");
11026 return 0;
11027 }
11028
11029 return 1;
11030}
11031
11032
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011033static int off_chan_val(enum sec_ch_offset off)
11034{
11035 switch (off) {
11036 case SEC_CH_NO:
11037 return 0;
11038 case SEC_CH_40ABOVE:
11039 return 40;
11040 case SEC_CH_40BELOW:
11041 return -40;
11042 }
11043
11044 return 0;
11045}
11046
11047
11048static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11049 const char *intf, int off_ch_num,
11050 enum sec_ch_offset sec)
11051{
11052 char buf[200];
11053 int res;
11054
11055 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11056 intf, off_ch_num);
11057 if (res < 0 || res >= (int) sizeof(buf))
11058 return -1;
11059 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11060 if (system(buf) != 0) {
11061 send_resp(dut, conn, SIGMA_ERROR,
11062 "errorCode,Failed to set offchan");
11063 return 0;
11064 }
11065
11066 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11067 intf, off_chan_val(sec));
11068 if (res < 0 || res >= (int) sizeof(buf))
11069 return -1;
11070 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11071 if (system(buf) != 0) {
11072 send_resp(dut, conn, SIGMA_ERROR,
11073 "errorCode,Failed to set sec chan offset");
11074 return 0;
11075 }
11076
11077 return 1;
11078}
11079
11080
11081static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11082 struct sigma_conn *conn,
11083 const char *intf, int off_ch_num,
11084 enum sec_ch_offset sec)
11085{
11086 char buf[200];
11087 int res;
11088
11089 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11090 off_ch_num);
11091 if (res < 0 || res >= (int) sizeof(buf))
11092 return -1;
11093 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11094
11095 if (wpa_command(intf, buf) < 0) {
11096 send_resp(dut, conn, SIGMA_ERROR,
11097 "ErrorCode,Failed to set offchan");
11098 return 0;
11099 }
11100 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11101 off_chan_val(sec));
11102 if (res < 0 || res >= (int) sizeof(buf))
11103 return -1;
11104
11105 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11106
11107 if (wpa_command(intf, buf) < 0) {
11108 send_resp(dut, conn, SIGMA_ERROR,
11109 "ErrorCode,Failed to set sec chan offset");
11110 return 0;
11111 }
11112
11113 return 1;
11114}
11115
11116
11117static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11118 struct sigma_conn *conn,
11119 const char *intf, int val)
11120{
11121 char buf[200];
11122 int res;
11123
11124 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11125 val);
11126 if (res < 0 || res >= (int) sizeof(buf))
11127 return -1;
11128 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11129
11130 if (wpa_command(intf, buf) < 0) {
11131 send_resp(dut, conn, SIGMA_ERROR,
11132 "ErrorCode,Failed to configure offchannel mode");
11133 return 0;
11134 }
11135
11136 return 1;
11137}
11138
11139
11140static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11141 struct sigma_conn *conn,
11142 struct sigma_cmd *cmd)
11143{
11144 const char *val;
11145 enum {
11146 CHSM_NOT_SET,
11147 CHSM_ENABLE,
11148 CHSM_DISABLE,
11149 CHSM_REJREQ,
11150 CHSM_UNSOLRESP
11151 } chsm = CHSM_NOT_SET;
11152 int off_ch_num = -1;
11153 enum sec_ch_offset sec_ch = SEC_CH_NO;
11154 int res;
11155
11156 val = get_param(cmd, "Uapsd");
11157 if (val) {
11158 char buf[100];
11159 if (strcasecmp(val, "Enable") == 0)
11160 snprintf(buf, sizeof(buf), "SET ps 99");
11161 else if (strcasecmp(val, "Disable") == 0)
11162 snprintf(buf, sizeof(buf), "SET ps 98");
11163 else {
11164 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11165 "Unsupported uapsd parameter value");
11166 return 0;
11167 }
11168 if (wpa_command(intf, buf)) {
11169 send_resp(dut, conn, SIGMA_ERROR,
11170 "ErrorCode,Failed to change U-APSD "
11171 "powersave mode");
11172 return 0;
11173 }
11174 }
11175
11176 val = get_param(cmd, "TPKTIMER");
11177 if (val && strcasecmp(val, "DISABLE") == 0) {
11178 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11179 send_resp(dut, conn, SIGMA_ERROR,
11180 "ErrorCode,Failed to enable no TPK "
11181 "expiration test mode");
11182 return 0;
11183 }
11184 dut->no_tpk_expiration = 1;
11185 }
11186
11187 val = get_param(cmd, "ChSwitchMode");
11188 if (val) {
11189 if (strcasecmp(val, "Enable") == 0 ||
11190 strcasecmp(val, "Initiate") == 0)
11191 chsm = CHSM_ENABLE;
11192 else if (strcasecmp(val, "Disable") == 0 ||
11193 strcasecmp(val, "passive") == 0)
11194 chsm = CHSM_DISABLE;
11195 else if (strcasecmp(val, "RejReq") == 0)
11196 chsm = CHSM_REJREQ;
11197 else if (strcasecmp(val, "UnSolResp") == 0)
11198 chsm = CHSM_UNSOLRESP;
11199 else {
11200 send_resp(dut, conn, SIGMA_ERROR,
11201 "ErrorCode,Unknown ChSwitchMode value");
11202 return 0;
11203 }
11204 }
11205
11206 val = get_param(cmd, "OffChNum");
11207 if (val) {
11208 off_ch_num = atoi(val);
11209 if (off_ch_num == 0) {
11210 send_resp(dut, conn, SIGMA_ERROR,
11211 "ErrorCode,Invalid OffChNum");
11212 return 0;
11213 }
11214 }
11215
11216 val = get_param(cmd, "SecChOffset");
11217 if (val) {
11218 if (strcmp(val, "20") == 0)
11219 sec_ch = SEC_CH_NO;
11220 else if (strcasecmp(val, "40above") == 0)
11221 sec_ch = SEC_CH_40ABOVE;
11222 else if (strcasecmp(val, "40below") == 0)
11223 sec_ch = SEC_CH_40BELOW;
11224 else {
11225 send_resp(dut, conn, SIGMA_ERROR,
11226 "ErrorCode,Unknown SecChOffset value");
11227 return 0;
11228 }
11229 }
11230
11231 if (chsm == CHSM_NOT_SET) {
11232 /* no offchannel changes requested */
11233 return 1;
11234 }
11235
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011236 if (strcmp(intf, get_main_ifname(dut)) != 0 &&
11237 strcmp(intf, get_station_ifname(dut)) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011238 send_resp(dut, conn, SIGMA_ERROR,
11239 "ErrorCode,Unknown interface");
11240 return 0;
11241 }
11242
11243 switch (chsm) {
11244 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011245 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011246 break;
11247 case CHSM_ENABLE:
11248 if (off_ch_num < 0) {
11249 send_resp(dut, conn, SIGMA_ERROR,
11250 "ErrorCode,Missing OffChNum argument");
11251 return 0;
11252 }
11253 if (wifi_chip_type == DRIVER_WCN) {
11254 res = tdls_set_offchannel_offset(dut, conn, intf,
11255 off_ch_num, sec_ch);
11256 } else {
11257 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11258 sec_ch);
11259 }
11260 if (res != 1)
11261 return res;
11262 if (wifi_chip_type == DRIVER_WCN)
11263 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11264 else
11265 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11266 break;
11267 case CHSM_DISABLE:
11268 if (wifi_chip_type == DRIVER_WCN)
11269 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11270 else
11271 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11272 break;
11273 case CHSM_REJREQ:
11274 if (wifi_chip_type == DRIVER_WCN)
11275 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11276 else
11277 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11278 break;
11279 case CHSM_UNSOLRESP:
11280 if (off_ch_num < 0) {
11281 send_resp(dut, conn, SIGMA_ERROR,
11282 "ErrorCode,Missing OffChNum argument");
11283 return 0;
11284 }
11285 if (wifi_chip_type == DRIVER_WCN) {
11286 res = tdls_set_offchannel_offset(dut, conn, intf,
11287 off_ch_num, sec_ch);
11288 } else {
11289 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11290 sec_ch);
11291 }
11292 if (res != 1)
11293 return res;
11294 if (wifi_chip_type == DRIVER_WCN)
11295 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11296 else
11297 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11298 break;
11299 }
11300
11301 return res;
11302}
11303
11304
11305static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11306 struct sigma_conn *conn,
11307 struct sigma_cmd *cmd)
11308{
11309 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011310 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011311
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011312 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011313
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011314 val = get_param(cmd, "nss_mcs_opt");
11315 if (val) {
11316 /* String (nss_operating_mode; mcs_operating_mode) */
11317 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011318 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011319
11320 token = strdup(val);
11321 if (!token)
11322 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011323 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011324 if (!result) {
11325 sigma_dut_print(dut, DUT_MSG_ERROR,
11326 "VHT NSS not specified");
11327 goto failed;
11328 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011329 if (strcasecmp(result, "def") != 0) {
11330 nss = atoi(result);
11331 if (nss == 4)
11332 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011333 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011334 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011335
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011336 }
11337
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011338 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011339 if (!result) {
11340 sigma_dut_print(dut, DUT_MSG_ERROR,
11341 "VHT MCS not specified");
11342 goto failed;
11343 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011344 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011345 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011346 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011347 } else {
11348 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011349 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011350 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011351 }
11352 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011353 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011354 }
11355
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011356 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011357 return 1;
11358failed:
11359 free(token);
11360 return 0;
11361}
11362
11363
11364static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11365 struct sigma_conn *conn,
11366 struct sigma_cmd *cmd)
11367{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011368 switch (get_driver_type(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011369 case DRIVER_ATHEROS:
11370 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11371 default:
11372 send_resp(dut, conn, SIGMA_ERROR,
11373 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11374 return 0;
11375 }
11376}
11377
11378
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011379static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11380 struct sigma_conn *conn,
11381 struct sigma_cmd *cmd)
11382{
11383 const char *val;
11384 char *token = NULL, *result;
11385 char buf[60];
11386
11387 val = get_param(cmd, "nss_mcs_opt");
11388 if (val) {
11389 /* String (nss_operating_mode; mcs_operating_mode) */
11390 int nss, mcs, ratecode;
11391 char *saveptr;
11392
11393 token = strdup(val);
11394 if (!token)
11395 return -2;
11396
11397 result = strtok_r(token, ";", &saveptr);
11398 if (!result) {
11399 sigma_dut_print(dut, DUT_MSG_ERROR,
11400 "HE NSS not specified");
11401 goto failed;
11402 }
11403 nss = 1;
11404 if (strcasecmp(result, "def") != 0)
11405 nss = atoi(result);
11406
11407 result = strtok_r(NULL, ";", &saveptr);
11408 if (!result) {
11409 sigma_dut_print(dut, DUT_MSG_ERROR,
11410 "HE MCS not specified");
11411 goto failed;
11412 }
11413 mcs = 7;
11414 if (strcasecmp(result, "def") != 0)
11415 mcs = atoi(result);
11416
Arif Hussain557bf412018-05-25 17:29:36 -070011417 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011418 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011419 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011420 } else if (nss > 2) {
11421 sigma_dut_print(dut, DUT_MSG_ERROR,
11422 "HE NSS %d not supported", nss);
11423 goto failed;
11424 }
11425
Arif Hussain557bf412018-05-25 17:29:36 -070011426 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11427 if (system(buf) != 0) {
11428 sigma_dut_print(dut, DUT_MSG_ERROR,
11429 "nss_mcs_opt: iwpriv %s nss %d failed",
11430 intf, nss);
11431 goto failed;
11432 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011433 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011434
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011435 /* Add the MCS to the ratecode */
11436 if (mcs >= 0 && mcs <= 11) {
11437 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011438#ifdef NL80211_SUPPORT
11439 if (dut->device_type == STA_testbed) {
11440 enum he_mcs_config mcs_config;
11441 int ret;
11442
11443 if (mcs <= 7)
11444 mcs_config = HE_80_MCS0_7;
11445 else if (mcs <= 9)
11446 mcs_config = HE_80_MCS0_9;
11447 else
11448 mcs_config = HE_80_MCS0_11;
11449 ret = sta_set_he_mcs(dut, intf, mcs_config);
11450 if (ret) {
11451 sigma_dut_print(dut, DUT_MSG_ERROR,
11452 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11453 mcs, mcs_config, ret);
11454 goto failed;
11455 }
11456 }
11457#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011458 } else {
11459 sigma_dut_print(dut, DUT_MSG_ERROR,
11460 "HE MCS %d not supported", mcs);
11461 goto failed;
11462 }
11463 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11464 intf, ratecode);
11465 if (system(buf) != 0) {
11466 sigma_dut_print(dut, DUT_MSG_ERROR,
11467 "iwpriv setting of 11ax rates failed");
11468 goto failed;
11469 }
11470 free(token);
11471 }
11472
11473 val = get_param(cmd, "GI");
11474 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011475 int fix_rate_sgi;
11476
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011477 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011478 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011479 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011480 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011481 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11482 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011483 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011484 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011485 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11486 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011487 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011488 } else {
11489 send_resp(dut, conn, SIGMA_ERROR,
11490 "errorCode,GI value not supported");
11491 return 0;
11492 }
11493 if (system(buf) != 0) {
11494 send_resp(dut, conn, SIGMA_ERROR,
11495 "errorCode,Failed to set shortgi");
11496 return 0;
11497 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011498 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11499 intf, fix_rate_sgi);
11500 if (system(buf) != 0) {
11501 send_resp(dut, conn, SIGMA_ERROR,
11502 "errorCode,Failed to set fix rate shortgi");
11503 return STATUS_SENT;
11504 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011505 }
11506
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011507 val = get_param(cmd, "LTF");
11508 if (val) {
11509#ifdef NL80211_SUPPORT
11510 if (strcmp(val, "3.2") == 0) {
11511 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11512 } if (strcmp(val, "6.4") == 0) {
11513 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11514 } else if (strcmp(val, "12.8") == 0) {
11515 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11516 } else {
11517 send_resp(dut, conn, SIGMA_ERROR,
11518 "errorCode, LTF value not supported");
11519 return 0;
11520 }
11521#else /* NL80211_SUPPORT */
11522 sigma_dut_print(dut, DUT_MSG_ERROR,
11523 "LTF cannot be set without NL80211_SUPPORT defined");
11524 return -2;
11525#endif /* NL80211_SUPPORT */
11526 }
11527
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011528 val = get_param(cmd, "TxSUPPDU");
11529 if (val) {
11530 int set_val = 1;
11531
11532 if (strcasecmp(val, "Enable") == 0)
11533 set_val = 1;
11534 else if (strcasecmp(val, "Disable") == 0)
11535 set_val = 0;
11536
11537 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11538 send_resp(dut, conn, SIGMA_ERROR,
11539 "ErrorCode,Failed to set Tx SU PPDU config");
11540 return 0;
11541 }
11542 }
11543
Arif Hussain480d5f42019-03-12 14:40:42 -070011544 val = get_param(cmd, "TWT_Setup");
11545 if (val) {
11546 if (strcasecmp(val, "Request") == 0) {
11547 if (sta_twt_request(dut, conn, cmd)) {
11548 send_resp(dut, conn, SIGMA_ERROR,
11549 "ErrorCode,sta_twt_request failed");
11550 return STATUS_SENT;
11551 }
11552 } else if (strcasecmp(val, "Teardown") == 0) {
11553 if (sta_twt_teardown(dut, conn, cmd)) {
11554 send_resp(dut, conn, SIGMA_ERROR,
11555 "ErrorCode,sta_twt_teardown failed");
11556 return STATUS_SENT;
11557 }
11558 }
11559 }
11560
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011561 val = get_param(cmd, "transmitOMI");
11562 if (val && sta_transmit_omi(dut, conn, cmd)) {
11563 send_resp(dut, conn, SIGMA_ERROR,
11564 "ErrorCode,sta_transmit_omi failed");
11565 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011566 }
11567
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011568 val = get_param(cmd, "Powersave");
11569 if (val) {
11570 char buf[60];
11571
11572 if (strcasecmp(val, "off") == 0) {
11573 snprintf(buf, sizeof(buf),
11574 "iwpriv %s setPower 2", intf);
11575 if (system(buf) != 0) {
11576 sigma_dut_print(dut, DUT_MSG_ERROR,
11577 "iwpriv setPower 2 failed");
11578 return 0;
11579 }
11580 } else if (strcasecmp(val, "on") == 0) {
11581 snprintf(buf, sizeof(buf),
11582 "iwpriv %s setPower 1", intf);
11583 if (system(buf) != 0) {
11584 sigma_dut_print(dut, DUT_MSG_ERROR,
11585 "iwpriv setPower 1 failed");
11586 return 0;
11587 }
11588 } else {
11589 sigma_dut_print(dut, DUT_MSG_ERROR,
11590 "Unsupported Powersave value '%s'",
11591 val);
11592 return -1;
11593 }
11594 }
11595
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011596 val = get_param(cmd, "MU_EDCA");
11597 if (val) {
11598 if (strcasecmp(val, "Override") == 0) {
11599 if (sta_set_mu_edca_override(dut, intf, 1)) {
11600 send_resp(dut, conn, SIGMA_ERROR,
11601 "errorCode,MU EDCA override set failed");
11602 return STATUS_SENT;
11603 }
11604 } else if (strcasecmp(val, "Disable") == 0) {
11605 if (sta_set_mu_edca_override(dut, intf, 0)) {
11606 send_resp(dut, conn, SIGMA_ERROR,
11607 "errorCode,MU EDCA override disable failed");
11608 return STATUS_SENT;
11609 }
11610 }
11611 }
11612
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011613 return 1;
11614
11615failed:
11616 free(token);
11617 return -2;
11618}
11619
11620
11621static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11622 struct sigma_conn *conn,
11623 struct sigma_cmd *cmd)
11624{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011625 switch (get_driver_type(dut)) {
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011626 case DRIVER_WCN:
11627 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11628 default:
11629 send_resp(dut, conn, SIGMA_ERROR,
11630 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11631 return 0;
11632 }
11633}
11634
11635
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011636static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11637 struct sigma_conn *conn,
11638 struct sigma_cmd *cmd)
11639{
11640 const char *val;
11641
11642 val = get_param(cmd, "powersave");
11643 if (val) {
11644 char buf[60];
11645
11646 if (strcasecmp(val, "off") == 0) {
11647 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11648 intf);
11649 if (system(buf) != 0) {
11650 sigma_dut_print(dut, DUT_MSG_ERROR,
11651 "iwpriv setPower 2 failed");
11652 return 0;
11653 }
11654 } else if (strcasecmp(val, "on") == 0) {
11655 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11656 intf);
11657 if (system(buf) != 0) {
11658 sigma_dut_print(dut, DUT_MSG_ERROR,
11659 "iwpriv setPower 1 failed");
11660 return 0;
11661 }
11662 } else {
11663 sigma_dut_print(dut, DUT_MSG_ERROR,
11664 "Unsupported power save config");
11665 return -1;
11666 }
11667 return 1;
11668 }
11669
11670 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11671
11672 return 0;
11673}
11674
11675
Ashwini Patil5acd7382017-04-13 15:55:04 +053011676static int btm_query_candidate_list(struct sigma_dut *dut,
11677 struct sigma_conn *conn,
11678 struct sigma_cmd *cmd)
11679{
11680 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11681 int len, ret;
11682 char buf[10];
11683
11684 /*
11685 * Neighbor Report elements format:
11686 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11687 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11688 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11689 */
11690
11691 bssid = get_param(cmd, "Nebor_BSSID");
11692 if (!bssid) {
11693 send_resp(dut, conn, SIGMA_INVALID,
11694 "errorCode,Nebor_BSSID is missing");
11695 return 0;
11696 }
11697
11698 info = get_param(cmd, "Nebor_Bssid_Info");
11699 if (!info) {
11700 sigma_dut_print(dut, DUT_MSG_INFO,
11701 "Using default value for Nebor_Bssid_Info: %s",
11702 DEFAULT_NEIGHBOR_BSSID_INFO);
11703 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11704 }
11705
11706 op_class = get_param(cmd, "Nebor_Op_Class");
11707 if (!op_class) {
11708 send_resp(dut, conn, SIGMA_INVALID,
11709 "errorCode,Nebor_Op_Class is missing");
11710 return 0;
11711 }
11712
11713 ch = get_param(cmd, "Nebor_Op_Ch");
11714 if (!ch) {
11715 send_resp(dut, conn, SIGMA_INVALID,
11716 "errorCode,Nebor_Op_Ch is missing");
11717 return 0;
11718 }
11719
11720 phy_type = get_param(cmd, "Nebor_Phy_Type");
11721 if (!phy_type) {
11722 sigma_dut_print(dut, DUT_MSG_INFO,
11723 "Using default value for Nebor_Phy_Type: %s",
11724 DEFAULT_NEIGHBOR_PHY_TYPE);
11725 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11726 }
11727
11728 /* Parse optional subelements */
11729 buf[0] = '\0';
11730 pref = get_param(cmd, "Nebor_Pref");
11731 if (pref) {
11732 /* hexdump for preferrence subelement */
11733 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11734 if (ret < 0 || ret >= (int) sizeof(buf)) {
11735 sigma_dut_print(dut, DUT_MSG_ERROR,
11736 "snprintf failed for optional subelement ret: %d",
11737 ret);
11738 send_resp(dut, conn, SIGMA_ERROR,
11739 "errorCode,snprintf failed for subelement");
11740 return 0;
11741 }
11742 }
11743
11744 if (!dut->btm_query_cand_list) {
11745 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11746 if (!dut->btm_query_cand_list) {
11747 send_resp(dut, conn, SIGMA_ERROR,
11748 "errorCode,Failed to allocate memory for btm_query_cand_list");
11749 return 0;
11750 }
11751 }
11752
11753 len = strlen(dut->btm_query_cand_list);
11754 ret = snprintf(dut->btm_query_cand_list + len,
11755 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11756 bssid, info, op_class, ch, phy_type, buf);
11757 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11758 sigma_dut_print(dut, DUT_MSG_ERROR,
11759 "snprintf failed for neighbor report list ret: %d",
11760 ret);
11761 send_resp(dut, conn, SIGMA_ERROR,
11762 "errorCode,snprintf failed for neighbor report");
11763 free(dut->btm_query_cand_list);
11764 dut->btm_query_cand_list = NULL;
11765 return 0;
11766 }
11767
11768 return 1;
11769}
11770
11771
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011772int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11773 struct sigma_ese_alloc *allocs, int *allocs_size)
11774{
11775 int max_count = *allocs_size;
11776 int count = 0, i;
11777 const char *val;
11778
11779 do {
11780 val = get_param_indexed(cmd, "AllocID", count);
11781 if (val)
11782 count++;
11783 } while (val);
11784
11785 if (count == 0 || count > max_count) {
11786 sigma_dut_print(dut, DUT_MSG_ERROR,
11787 "Invalid number of allocations(%d)", count);
11788 return -1;
11789 }
11790
11791 for (i = 0; i < count; i++) {
11792 val = get_param_indexed(cmd, "PercentBI", i);
11793 if (!val) {
11794 sigma_dut_print(dut, DUT_MSG_ERROR,
11795 "Missing PercentBI parameter at index %d",
11796 i);
11797 return -1;
11798 }
11799 allocs[i].percent_bi = atoi(val);
11800
11801 val = get_param_indexed(cmd, "SrcAID", i);
11802 if (val)
11803 allocs[i].src_aid = strtol(val, NULL, 0);
11804 else
11805 allocs[i].src_aid = ESE_BCAST_AID;
11806
11807 val = get_param_indexed(cmd, "DestAID", i);
11808 if (val)
11809 allocs[i].dst_aid = strtol(val, NULL, 0);
11810 else
11811 allocs[i].dst_aid = ESE_BCAST_AID;
11812
11813 allocs[i].type = ESE_CBAP;
11814 sigma_dut_print(dut, DUT_MSG_INFO,
11815 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11816 i, allocs[i].percent_bi, allocs[i].src_aid,
11817 allocs[i].dst_aid);
11818 }
11819
11820 *allocs_size = count;
11821 return 0;
11822}
11823
11824
11825static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11826 struct sigma_ese_alloc *allocs)
11827{
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011828 switch (get_driver_type(dut)) {
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011829#ifdef __linux__
11830 case DRIVER_WIL6210:
11831 if (wil6210_set_ese(dut, count, allocs))
11832 return -1;
11833 return 1;
11834#endif /* __linux__ */
11835 default:
11836 sigma_dut_print(dut, DUT_MSG_ERROR,
11837 "Unsupported sta_set_60g_ese with the current driver");
11838 return -1;
11839 }
11840}
11841
11842
11843static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11844 struct sigma_conn *conn,
11845 struct sigma_cmd *cmd)
11846{
11847 const char *val;
11848
11849 val = get_param(cmd, "ExtSchIE");
11850 if (val && !strcasecmp(val, "Enable")) {
11851 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11852 int count = MAX_ESE_ALLOCS;
11853
11854 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11855 return -1;
11856 return sta_set_60g_ese(dut, count, allocs);
11857 }
11858
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011859 val = get_param(cmd, "MCS_FixedRate");
11860 if (val) {
11861 int sta_mcs = atoi(val);
11862
11863 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11864 sta_mcs);
11865 wil6210_set_force_mcs(dut, 1, sta_mcs);
11866
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011867 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011868 }
11869
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011870 send_resp(dut, conn, SIGMA_ERROR,
11871 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011872 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011873}
11874
11875
Jouni Malinenf7222712019-06-13 01:50:21 +030011876static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
11877 struct sigma_conn *conn,
11878 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011879{
11880 const char *intf = get_param(cmd, "Interface");
11881 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011882 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011883
11884 if (intf == NULL || prog == NULL)
11885 return -1;
11886
Ashwini Patil5acd7382017-04-13 15:55:04 +053011887 /* BSS Transition candidate list for BTM query */
11888 val = get_param(cmd, "Nebor_BSSID");
11889 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11890 return 0;
11891
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011892 if (strcasecmp(prog, "TDLS") == 0)
11893 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11894
11895 if (strcasecmp(prog, "VHT") == 0)
11896 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11897
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011898 if (strcasecmp(prog, "HE") == 0)
11899 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11900
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011901 if (strcasecmp(prog, "MBO") == 0) {
11902 val = get_param(cmd, "Cellular_Data_Cap");
11903 if (val &&
11904 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11905 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011906
11907 val = get_param(cmd, "Ch_Pref");
11908 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11909 return 0;
11910
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011911 return 1;
11912 }
11913
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011914 if (strcasecmp(prog, "60GHz") == 0)
11915 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11916
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011917 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11918 return 0;
11919}
11920
11921
Jouni Malinenf7222712019-06-13 01:50:21 +030011922static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
11923 struct sigma_conn *conn,
11924 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011925{
11926 const char *intf = get_param(cmd, "Interface");
11927 const char *mode = get_param(cmd, "Mode");
11928 int res;
11929
11930 if (intf == NULL || mode == NULL)
11931 return -1;
11932
11933 if (strcasecmp(mode, "On") == 0)
11934 res = wpa_command(intf, "SET radio_disabled 0");
11935 else if (strcasecmp(mode, "Off") == 0)
11936 res = wpa_command(intf, "SET radio_disabled 1");
11937 else
11938 return -1;
11939
11940 if (res) {
11941 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11942 "radio mode");
11943 return 0;
11944 }
11945
11946 return 1;
11947}
11948
11949
Jouni Malinenf7222712019-06-13 01:50:21 +030011950static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
11951 struct sigma_conn *conn,
11952 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011953{
11954 const char *intf = get_param(cmd, "Interface");
11955 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011956 const char *prog = get_param(cmd, "program");
11957 const char *powersave = get_param(cmd, "powersave");
11958 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011959
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011960 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011961 return -1;
11962
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011963 if (prog && strcasecmp(prog, "60GHz") == 0) {
11964 /*
11965 * The CAPI mode parameter does not exist in 60G
11966 * unscheduled PS.
11967 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080011968 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011969 res = set_ps(intf, dut, 1);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020011970 } else if (prog && get_driver_type(dut) == DRIVER_WCN &&
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011971 strcasecmp(prog, "HE") == 0) {
11972 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011973 } else {
11974 if (mode == NULL)
11975 return -1;
11976
11977 if (strcasecmp(mode, "On") == 0)
11978 res = set_ps(intf, dut, 1);
11979 else if (strcasecmp(mode, "Off") == 0)
11980 res = set_ps(intf, dut, 0);
11981 else
11982 return -1;
11983 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011984
11985 if (res) {
11986 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11987 "power save mode");
11988 return 0;
11989 }
11990
11991 return 1;
11992}
11993
11994
Jouni Malinenf7222712019-06-13 01:50:21 +030011995static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
11996 struct sigma_conn *conn,
11997 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011998{
11999 const char *intf = get_param(cmd, "Interface");
12000 const char *val, *bssid;
12001 int res;
12002 char *buf;
12003 size_t buf_len;
12004
12005 val = get_param(cmd, "BSSID_FILTER");
12006 if (val == NULL)
12007 return -1;
12008
12009 bssid = get_param(cmd, "BSSID_List");
12010 if (atoi(val) == 0 || bssid == NULL) {
12011 /* Disable BSSID filter */
12012 if (wpa_command(intf, "SET bssid_filter ")) {
12013 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
12014 "to disable BSSID filter");
12015 return 0;
12016 }
12017
12018 return 1;
12019 }
12020
12021 buf_len = 100 + strlen(bssid);
12022 buf = malloc(buf_len);
12023 if (buf == NULL)
12024 return -1;
12025
12026 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12027 res = wpa_command(intf, buf);
12028 free(buf);
12029 if (res) {
12030 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12031 "BSSID filter");
12032 return 0;
12033 }
12034
12035 return 1;
12036}
12037
12038
Jouni Malinenf7222712019-06-13 01:50:21 +030012039static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12040 struct sigma_conn *conn,
12041 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012042{
12043 const char *intf = get_param(cmd, "Interface");
12044 const char *val;
12045
12046 /* TODO: ARP */
12047
12048 val = get_param(cmd, "HS2_CACHE_PROFILE");
12049 if (val && strcasecmp(val, "All") == 0)
12050 hs2_clear_credentials(intf);
12051
12052 return 1;
12053}
12054
12055
Jouni Malinenf7222712019-06-13 01:50:21 +030012056static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12057 struct sigma_conn *conn,
12058 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012059{
12060 const char *intf = get_param(cmd, "Interface");
12061 const char *key_type = get_param(cmd, "KeyType");
12062 char buf[100], resp[200];
12063
12064 if (key_type == NULL)
12065 return -1;
12066
12067 if (strcasecmp(key_type, "GTK") == 0) {
12068 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12069 strncmp(buf, "FAIL", 4) == 0) {
12070 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12071 "not fetch current GTK");
12072 return 0;
12073 }
12074 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12075 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12076 return 0;
12077 } else {
12078 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12079 "KeyType");
12080 return 0;
12081 }
12082
12083 return 1;
12084}
12085
12086
12087static int hs2_set_policy(struct sigma_dut *dut)
12088{
12089#ifdef ANDROID
12090 system("ip rule del prio 23000");
12091 if (system("ip rule add from all lookup main prio 23000") != 0) {
12092 sigma_dut_print(dut, DUT_MSG_ERROR,
12093 "Failed to run:ip rule add from all lookup main prio");
12094 return -1;
12095 }
12096 if (system("ip route flush cache") != 0) {
12097 sigma_dut_print(dut, DUT_MSG_ERROR,
12098 "Failed to run ip route flush cache");
12099 return -1;
12100 }
12101 return 1;
12102#else /* ANDROID */
12103 return 0;
12104#endif /* ANDROID */
12105}
12106
12107
Jouni Malinenf7222712019-06-13 01:50:21 +030012108static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12109 struct sigma_conn *conn,
12110 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012111{
12112 const char *intf = get_param(cmd, "Interface");
12113 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012114 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012115 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012116 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012117 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12118 int tries = 0;
12119 int ignore_blacklist = 0;
12120 const char *events[] = {
12121 "CTRL-EVENT-CONNECTED",
12122 "INTERWORKING-BLACKLISTED",
12123 "INTERWORKING-NO-MATCH",
12124 NULL
12125 };
12126
12127 start_sta_mode(dut);
12128
Jouni Malinen439352d2018-09-13 03:42:23 +030012129 if (band) {
12130 if (strcmp(band, "2.4") == 0) {
12131 wpa_command(intf, "SET setband 2G");
12132 } else if (strcmp(band, "5") == 0) {
12133 wpa_command(intf, "SET setband 5G");
12134 } else {
12135 send_resp(dut, conn, SIGMA_ERROR,
12136 "errorCode,Unsupported band");
12137 return 0;
12138 }
12139 }
12140
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012141 blacklisted[0] = '\0';
12142 if (val && atoi(val))
12143 ignore_blacklist = 1;
12144
12145try_again:
12146 ctrl = open_wpa_mon(intf);
12147 if (ctrl == NULL) {
12148 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12149 "wpa_supplicant monitor connection");
12150 return -2;
12151 }
12152
12153 tries++;
12154 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12155 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12156 "Interworking connection");
12157 wpa_ctrl_detach(ctrl);
12158 wpa_ctrl_close(ctrl);
12159 return 0;
12160 }
12161
12162 buf[0] = '\0';
12163 while (1) {
12164 char *pos;
12165 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12166 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12167 if (!pos)
12168 break;
12169 pos += 25;
12170 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12171 pos);
12172 if (!blacklisted[0])
12173 memcpy(blacklisted, pos, strlen(pos) + 1);
12174 }
12175
12176 if (ignore_blacklist && blacklisted[0]) {
12177 char *end;
12178 end = strchr(blacklisted, ' ');
12179 if (end)
12180 *end = '\0';
12181 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12182 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012183 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12184 blacklisted);
12185 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012186 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12187 wpa_ctrl_detach(ctrl);
12188 wpa_ctrl_close(ctrl);
12189 return 0;
12190 }
12191 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12192 buf, sizeof(buf));
12193 }
12194
12195 wpa_ctrl_detach(ctrl);
12196 wpa_ctrl_close(ctrl);
12197
12198 if (res < 0) {
12199 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12200 "connect");
12201 return 0;
12202 }
12203
12204 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12205 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12206 if (tries < 2) {
12207 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12208 goto try_again;
12209 }
12210 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12211 "matching credentials found");
12212 return 0;
12213 }
12214
12215 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12216 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12217 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12218 "get current BSSID/SSID");
12219 return 0;
12220 }
12221
12222 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12223 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12224 hs2_set_policy(dut);
12225 return 0;
12226}
12227
12228
Jouni Malinenf7222712019-06-13 01:50:21 +030012229static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12230 struct sigma_conn *conn,
12231 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012232{
12233 const char *intf = get_param(cmd, "Interface");
12234 const char *display = get_param(cmd, "Display");
12235 struct wpa_ctrl *ctrl;
12236 char buf[300], params[400], *pos;
12237 char bssid[20];
12238 int info_avail = 0;
12239 unsigned int old_timeout;
12240 int res;
12241
12242 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12243 send_resp(dut, conn, SIGMA_ERROR,
12244 "ErrorCode,Could not get current BSSID");
12245 return 0;
12246 }
12247 ctrl = open_wpa_mon(intf);
12248 if (!ctrl) {
12249 sigma_dut_print(dut, DUT_MSG_ERROR,
12250 "Failed to open wpa_supplicant monitor connection");
12251 return -2;
12252 }
12253
12254 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12255 wpa_command(intf, buf);
12256
12257 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12258 if (res < 0) {
12259 send_resp(dut, conn, SIGMA_ERROR,
12260 "ErrorCode,Could not complete GAS query");
12261 goto fail;
12262 }
12263
12264 old_timeout = dut->default_timeout;
12265 dut->default_timeout = 2;
12266 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12267 dut->default_timeout = old_timeout;
12268 if (res < 0)
12269 goto done;
12270 pos = strchr(buf, ' ');
12271 if (!pos)
12272 goto done;
12273 pos++;
12274 pos = strchr(pos, ' ');
12275 if (!pos)
12276 goto done;
12277 pos++;
12278 info_avail = 1;
12279 snprintf(params, sizeof(params), "browser %s", pos);
12280
12281 if (display && strcasecmp(display, "Yes") == 0) {
12282 pid_t pid;
12283
12284 pid = fork();
12285 if (pid < 0) {
12286 perror("fork");
12287 return -1;
12288 }
12289
12290 if (pid == 0) {
12291 run_hs20_osu(dut, params);
12292 exit(0);
12293 }
12294 }
12295
12296done:
12297 snprintf(buf, sizeof(buf), "Info_available,%s",
12298 info_avail ? "Yes" : "No");
12299 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12300fail:
12301 wpa_ctrl_detach(ctrl);
12302 wpa_ctrl_close(ctrl);
12303 return 0;
12304}
12305
12306
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012307static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12308 struct sigma_conn *conn,
12309 const char *ifname,
12310 struct sigma_cmd *cmd)
12311{
12312 const char *val;
12313 int id;
12314
12315 id = add_cred(ifname);
12316 if (id < 0)
12317 return -2;
12318 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12319
12320 val = get_param(cmd, "prefer");
12321 if (val && atoi(val) > 0)
12322 set_cred(ifname, id, "priority", "1");
12323
12324 val = get_param(cmd, "REALM");
12325 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12326 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12327 "realm");
12328 return 0;
12329 }
12330
12331 val = get_param(cmd, "HOME_FQDN");
12332 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12333 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12334 "home_fqdn");
12335 return 0;
12336 }
12337
12338 val = get_param(cmd, "Username");
12339 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12340 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12341 "username");
12342 return 0;
12343 }
12344
12345 val = get_param(cmd, "Password");
12346 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12347 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12348 "password");
12349 return 0;
12350 }
12351
12352 val = get_param(cmd, "ROOT_CA");
12353 if (val) {
12354 char fname[200];
12355 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12356#ifdef __linux__
12357 if (!file_exists(fname)) {
12358 char msg[300];
12359 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12360 "file (%s) not found", fname);
12361 send_resp(dut, conn, SIGMA_ERROR, msg);
12362 return 0;
12363 }
12364#endif /* __linux__ */
12365 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12366 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12367 "not set root CA");
12368 return 0;
12369 }
12370 }
12371
12372 return 1;
12373}
12374
12375
12376static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12377{
12378 FILE *in, *out;
12379 char buf[500];
12380 int found = 0;
12381
12382 in = fopen("devdetail.xml", "r");
12383 if (in == NULL)
12384 return -1;
12385 out = fopen("devdetail.xml.tmp", "w");
12386 if (out == NULL) {
12387 fclose(in);
12388 return -1;
12389 }
12390
12391 while (fgets(buf, sizeof(buf), in)) {
12392 char *pos = strstr(buf, "<IMSI>");
12393 if (pos) {
12394 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12395 imsi);
12396 pos += 6;
12397 *pos = '\0';
12398 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12399 found++;
12400 } else {
12401 fprintf(out, "%s", buf);
12402 }
12403 }
12404
12405 fclose(out);
12406 fclose(in);
12407 if (found)
12408 rename("devdetail.xml.tmp", "devdetail.xml");
12409 else
12410 unlink("devdetail.xml.tmp");
12411
12412 return 0;
12413}
12414
12415
12416static int sta_add_credential_sim(struct sigma_dut *dut,
12417 struct sigma_conn *conn,
12418 const char *ifname, struct sigma_cmd *cmd)
12419{
12420 const char *val, *imsi = NULL;
12421 int id;
12422 char buf[200];
12423 int res;
12424 const char *pos;
12425 size_t mnc_len;
12426 char plmn_mcc[4];
12427 char plmn_mnc[4];
12428
12429 id = add_cred(ifname);
12430 if (id < 0)
12431 return -2;
12432 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12433
12434 val = get_param(cmd, "prefer");
12435 if (val && atoi(val) > 0)
12436 set_cred(ifname, id, "priority", "1");
12437
12438 val = get_param(cmd, "PLMN_MCC");
12439 if (val == NULL) {
12440 send_resp(dut, conn, SIGMA_ERROR,
12441 "errorCode,Missing PLMN_MCC");
12442 return 0;
12443 }
12444 if (strlen(val) != 3) {
12445 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12446 return 0;
12447 }
12448 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12449
12450 val = get_param(cmd, "PLMN_MNC");
12451 if (val == NULL) {
12452 send_resp(dut, conn, SIGMA_ERROR,
12453 "errorCode,Missing PLMN_MNC");
12454 return 0;
12455 }
12456 if (strlen(val) != 2 && strlen(val) != 3) {
12457 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12458 return 0;
12459 }
12460 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12461
12462 val = get_param(cmd, "IMSI");
12463 if (val == NULL) {
12464 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12465 "IMSI");
12466 return 0;
12467 }
12468
12469 imsi = pos = val;
12470
12471 if (strncmp(plmn_mcc, pos, 3) != 0) {
12472 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12473 return 0;
12474 }
12475 pos += 3;
12476
12477 mnc_len = strlen(plmn_mnc);
12478 if (mnc_len < 2) {
12479 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12480 return 0;
12481 }
12482
12483 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12485 return 0;
12486 }
12487 pos += mnc_len;
12488
12489 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12490 if (res < 0 || res >= (int) sizeof(buf))
12491 return -1;
12492 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12493 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12494 "not set IMSI");
12495 return 0;
12496 }
12497
12498 val = get_param(cmd, "Password");
12499 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12500 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12501 "not set password");
12502 return 0;
12503 }
12504
Jouni Malinenba630452018-06-22 11:49:59 +030012505 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012506 /*
12507 * Set provisioning_sp for the test cases where SIM/USIM
12508 * provisioning is used.
12509 */
12510 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12511 "wi-fi.org") < 0) {
12512 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12513 "not set provisioning_sp");
12514 return 0;
12515 }
12516
12517 update_devdetail_imsi(dut, imsi);
12518 }
12519
12520 return 1;
12521}
12522
12523
12524static int sta_add_credential_cert(struct sigma_dut *dut,
12525 struct sigma_conn *conn,
12526 const char *ifname,
12527 struct sigma_cmd *cmd)
12528{
12529 const char *val;
12530 int id;
12531
12532 id = add_cred(ifname);
12533 if (id < 0)
12534 return -2;
12535 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12536
12537 val = get_param(cmd, "prefer");
12538 if (val && atoi(val) > 0)
12539 set_cred(ifname, id, "priority", "1");
12540
12541 val = get_param(cmd, "REALM");
12542 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12544 "realm");
12545 return 0;
12546 }
12547
12548 val = get_param(cmd, "HOME_FQDN");
12549 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12550 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12551 "home_fqdn");
12552 return 0;
12553 }
12554
12555 val = get_param(cmd, "Username");
12556 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12557 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12558 "username");
12559 return 0;
12560 }
12561
12562 val = get_param(cmd, "clientCertificate");
12563 if (val) {
12564 char fname[200];
12565 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12566#ifdef __linux__
12567 if (!file_exists(fname)) {
12568 char msg[300];
12569 snprintf(msg, sizeof(msg),
12570 "ErrorCode,clientCertificate "
12571 "file (%s) not found", fname);
12572 send_resp(dut, conn, SIGMA_ERROR, msg);
12573 return 0;
12574 }
12575#endif /* __linux__ */
12576 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12577 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12578 "not set client_cert");
12579 return 0;
12580 }
12581 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12582 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12583 "not set private_key");
12584 return 0;
12585 }
12586 }
12587
12588 val = get_param(cmd, "ROOT_CA");
12589 if (val) {
12590 char fname[200];
12591 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12592#ifdef __linux__
12593 if (!file_exists(fname)) {
12594 char msg[300];
12595 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12596 "file (%s) not found", fname);
12597 send_resp(dut, conn, SIGMA_ERROR, msg);
12598 return 0;
12599 }
12600#endif /* __linux__ */
12601 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12603 "not set root CA");
12604 return 0;
12605 }
12606 }
12607
12608 return 1;
12609}
12610
12611
Jouni Malinenf7222712019-06-13 01:50:21 +030012612static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12613 struct sigma_conn *conn,
12614 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012615{
12616 const char *intf = get_param(cmd, "Interface");
12617 const char *type;
12618
12619 start_sta_mode(dut);
12620
12621 type = get_param(cmd, "Type");
12622 if (!type)
12623 return -1;
12624
12625 if (strcasecmp(type, "uname_pwd") == 0)
12626 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12627
12628 if (strcasecmp(type, "sim") == 0)
12629 return sta_add_credential_sim(dut, conn, intf, cmd);
12630
12631 if (strcasecmp(type, "cert") == 0)
12632 return sta_add_credential_cert(dut, conn, intf, cmd);
12633
12634 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12635 "type");
12636 return 0;
12637}
12638
12639
Jouni Malinenf7222712019-06-13 01:50:21 +030012640static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12641 struct sigma_conn *conn,
12642 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012643{
12644 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012645 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012646 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012647 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012648 int res;
12649
Jouni Malinen8c1abeb2019-11-06 18:48:34 +020012650 start_sta_mode(dut);
12651
Arif Hussain66a4af02019-02-07 15:04:51 -080012652 val = get_param(cmd, "GetParameter");
12653 if (val && strcmp(val, "SSID_BSSID") == 0) {
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012654 if (get_wpa_ssid_bssid(dut, get_station_ifname(dut),
Arif Hussain66a4af02019-02-07 15:04:51 -080012655 buf, sizeof(buf)) < 0) {
12656 sigma_dut_print(dut, DUT_MSG_ERROR,
12657 "Could not get ssid bssid");
12658 return ERROR_SEND_STATUS;
12659 }
12660
12661 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12662 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12663 return STATUS_SENT;
12664 }
12665
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012666 val = get_param(cmd, "HESSID");
12667 if (val) {
12668 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12669 if (res < 0 || res >= (int) sizeof(buf))
12670 return -1;
12671 wpa_command(intf, buf);
12672 }
12673
12674 val = get_param(cmd, "ACCS_NET_TYPE");
12675 if (val) {
12676 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12677 val);
12678 if (res < 0 || res >= (int) sizeof(buf))
12679 return -1;
12680 wpa_command(intf, buf);
12681 }
12682
vamsi krishna89ad8c62017-09-19 12:51:18 +053012683 bssid = get_param(cmd, "Bssid");
12684 ssid = get_param(cmd, "Ssid");
12685
12686 if (ssid) {
12687 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12688 send_resp(dut, conn, SIGMA_ERROR,
12689 "ErrorCode,Too long SSID");
12690 return 0;
12691 }
12692 ascii2hexstr(ssid, ssid_hex);
12693 }
12694
12695 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12696 bssid ? " bssid=": "",
12697 bssid ? bssid : "",
12698 ssid ? " ssid " : "",
12699 ssid ? ssid_hex : "");
12700 if (res < 0 || res >= (int) sizeof(buf))
12701 return -1;
12702
12703 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012704 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12705 "scan");
12706 return 0;
12707 }
12708
12709 return 1;
12710}
12711
12712
Jouni Malinenf7222712019-06-13 01:50:21 +030012713static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12714 struct sigma_conn *conn,
12715 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012716{
12717 const char *intf = get_param(cmd, "Interface");
12718 const char *bssid;
12719 char buf[4096], *pos;
12720 int freq, chan;
12721 char *ssid;
12722 char resp[100];
12723 int res;
12724 struct wpa_ctrl *ctrl;
12725
12726 bssid = get_param(cmd, "BSSID");
12727 if (!bssid) {
12728 send_resp(dut, conn, SIGMA_INVALID,
12729 "errorCode,BSSID argument is missing");
12730 return 0;
12731 }
12732
12733 ctrl = open_wpa_mon(intf);
12734 if (!ctrl) {
12735 sigma_dut_print(dut, DUT_MSG_ERROR,
12736 "Failed to open wpa_supplicant monitor connection");
12737 return -1;
12738 }
12739
12740 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12741 send_resp(dut, conn, SIGMA_ERROR,
12742 "errorCode,Could not start scan");
12743 wpa_ctrl_detach(ctrl);
12744 wpa_ctrl_close(ctrl);
12745 return 0;
12746 }
12747
12748 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12749 buf, sizeof(buf));
12750
12751 wpa_ctrl_detach(ctrl);
12752 wpa_ctrl_close(ctrl);
12753
12754 if (res < 0) {
12755 send_resp(dut, conn, SIGMA_ERROR,
12756 "errorCode,Scan did not complete");
12757 return 0;
12758 }
12759
12760 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12761 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12762 strncmp(buf, "id=", 3) != 0) {
12763 send_resp(dut, conn, SIGMA_ERROR,
12764 "errorCode,Specified BSSID not found");
12765 return 0;
12766 }
12767
12768 pos = strstr(buf, "\nfreq=");
12769 if (!pos) {
12770 send_resp(dut, conn, SIGMA_ERROR,
12771 "errorCode,Channel not found");
12772 return 0;
12773 }
12774 freq = atoi(pos + 6);
12775 chan = freq_to_channel(freq);
12776
12777 pos = strstr(buf, "\nssid=");
12778 if (!pos) {
12779 send_resp(dut, conn, SIGMA_ERROR,
12780 "errorCode,SSID not found");
12781 return 0;
12782 }
12783 ssid = pos + 6;
12784 pos = strchr(ssid, '\n');
12785 if (pos)
12786 *pos = '\0';
12787 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12788 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12789 return 0;
12790}
12791
12792
Jouni Malinenf7222712019-06-13 01:50:21 +030012793static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
12794 struct sigma_conn *conn,
12795 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012796{
12797#ifdef __linux__
12798 struct timeval tv;
12799 struct tm tm;
12800 time_t t;
12801 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012802 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012803
Jouni Malinen016ae6c2019-11-04 17:00:01 +020012804 wpa_command(get_station_ifname(dut), "PMKSA_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012805
12806 memset(&tm, 0, sizeof(tm));
12807 val = get_param(cmd, "seconds");
12808 if (val)
12809 tm.tm_sec = atoi(val);
12810 val = get_param(cmd, "minutes");
12811 if (val)
12812 tm.tm_min = atoi(val);
12813 val = get_param(cmd, "hours");
12814 if (val)
12815 tm.tm_hour = atoi(val);
12816 val = get_param(cmd, "date");
12817 if (val)
12818 tm.tm_mday = atoi(val);
12819 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012820 if (val) {
12821 v = atoi(val);
12822 if (v < 1 || v > 12) {
12823 send_resp(dut, conn, SIGMA_INVALID,
12824 "errorCode,Invalid month");
12825 return 0;
12826 }
12827 tm.tm_mon = v - 1;
12828 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012829 val = get_param(cmd, "year");
12830 if (val) {
12831 int year = atoi(val);
12832#ifdef ANDROID
12833 if (year > 2035)
12834 year = 2035; /* years beyond 2035 not supported */
12835#endif /* ANDROID */
12836 tm.tm_year = year - 1900;
12837 }
12838 t = mktime(&tm);
12839 if (t == (time_t) -1) {
12840 send_resp(dut, conn, SIGMA_ERROR,
12841 "errorCode,Invalid date or time");
12842 return 0;
12843 }
12844
12845 memset(&tv, 0, sizeof(tv));
12846 tv.tv_sec = t;
12847
12848 if (settimeofday(&tv, NULL) < 0) {
12849 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12850 strerror(errno));
12851 send_resp(dut, conn, SIGMA_ERROR,
12852 "errorCode,Failed to set time");
12853 return 0;
12854 }
12855
12856 return 1;
12857#endif /* __linux__ */
12858
12859 return -1;
12860}
12861
12862
Jouni Malinenf7222712019-06-13 01:50:21 +030012863static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
12864 struct sigma_conn *conn,
12865 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012866{
12867 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012868 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012869 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012870 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012871 int res;
12872 struct wpa_ctrl *ctrl;
12873
12874 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012875 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012876
12877 val = get_param(cmd, "ProdESSAssoc");
12878 if (val)
12879 prod_ess_assoc = atoi(val);
12880
12881 kill_dhcp_client(dut, intf);
12882 if (start_dhcp_client(dut, intf) < 0)
12883 return -2;
12884
12885 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12886 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12887 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012888 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012889 prod_ess_assoc ? "" : "-N",
12890 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012891 name ? "'" : "",
12892 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12893 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012894
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012895 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012896 if (run_hs20_osu(dut, buf) < 0) {
12897 FILE *f;
12898
12899 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12900
12901 f = fopen("hs20-osu-client.res", "r");
12902 if (f) {
12903 char resp[400], res[300], *pos;
12904 if (!fgets(res, sizeof(res), f))
12905 res[0] = '\0';
12906 pos = strchr(res, '\n');
12907 if (pos)
12908 *pos = '\0';
12909 fclose(f);
12910 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12911 res);
12912 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12913 if (system(resp) != 0) {
12914 }
12915 snprintf(resp, sizeof(resp),
12916 "SSID,,BSSID,,failureReason,%s", res);
12917 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12918 return 0;
12919 }
12920
12921 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12922 return 0;
12923 }
12924
12925 if (!prod_ess_assoc)
12926 goto report;
12927
12928 ctrl = open_wpa_mon(intf);
12929 if (ctrl == NULL) {
12930 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12931 "wpa_supplicant monitor connection");
12932 return -1;
12933 }
12934
12935 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12936 buf, sizeof(buf));
12937
12938 wpa_ctrl_detach(ctrl);
12939 wpa_ctrl_close(ctrl);
12940
12941 if (res < 0) {
12942 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12943 "network after OSU");
12944 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12945 return 0;
12946 }
12947
12948report:
12949 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12950 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12951 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12952 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12953 return 0;
12954 }
12955
12956 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12957 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012958 return 0;
12959}
12960
12961
Jouni Malinenf7222712019-06-13 01:50:21 +030012962static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
12963 struct sigma_conn *conn,
12964 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012965{
12966 const char *val;
12967 int timeout = 120;
12968
12969 val = get_param(cmd, "PolicyUpdate");
12970 if (val == NULL || atoi(val) == 0)
12971 return 1; /* No operation requested */
12972
12973 val = get_param(cmd, "Timeout");
12974 if (val)
12975 timeout = atoi(val);
12976
12977 if (timeout) {
12978 /* TODO: time out the command and return
12979 * PolicyUpdateStatus,TIMEOUT if needed. */
12980 }
12981
12982 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12983 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12984 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12985 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12986 return 0;
12987 }
12988
12989 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12990 return 0;
12991}
12992
12993
Jouni Malinenf7222712019-06-13 01:50:21 +030012994static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
12995 struct sigma_conn *conn,
12996 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012997{
12998 struct wpa_ctrl *ctrl;
12999 const char *intf = get_param(cmd, "Interface");
13000 const char *bssid = get_param(cmd, "Bssid");
13001 const char *ssid = get_param(cmd, "SSID");
13002 const char *security = get_param(cmd, "Security");
13003 const char *passphrase = get_param(cmd, "Passphrase");
13004 const char *pin = get_param(cmd, "PIN");
13005 char buf[1000];
13006 char ssid_hex[200], passphrase_hex[200];
13007 const char *keymgmt, *cipher;
13008
13009 if (intf == NULL)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013010 intf = get_main_ifname(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013011
13012 if (!bssid) {
13013 send_resp(dut, conn, SIGMA_ERROR,
13014 "ErrorCode,Missing Bssid argument");
13015 return 0;
13016 }
13017
13018 if (!ssid) {
13019 send_resp(dut, conn, SIGMA_ERROR,
13020 "ErrorCode,Missing SSID argument");
13021 return 0;
13022 }
13023
13024 if (!security) {
13025 send_resp(dut, conn, SIGMA_ERROR,
13026 "ErrorCode,Missing Security argument");
13027 return 0;
13028 }
13029
13030 if (!passphrase) {
13031 send_resp(dut, conn, SIGMA_ERROR,
13032 "ErrorCode,Missing Passphrase argument");
13033 return 0;
13034 }
13035
13036 if (!pin) {
13037 send_resp(dut, conn, SIGMA_ERROR,
13038 "ErrorCode,Missing PIN argument");
13039 return 0;
13040 }
13041
vamsi krishna8c9c1562017-05-12 15:51:46 +053013042 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13043 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013044 send_resp(dut, conn, SIGMA_ERROR,
13045 "ErrorCode,Too long SSID/passphrase");
13046 return 0;
13047 }
13048
13049 ctrl = open_wpa_mon(intf);
13050 if (ctrl == NULL) {
13051 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13052 "wpa_supplicant monitor connection");
13053 return -2;
13054 }
13055
13056 if (strcasecmp(security, "wpa2-psk") == 0) {
13057 keymgmt = "WPA2PSK";
13058 cipher = "CCMP";
13059 } else {
13060 wpa_ctrl_detach(ctrl);
13061 wpa_ctrl_close(ctrl);
13062 send_resp(dut, conn, SIGMA_ERROR,
13063 "ErrorCode,Unsupported Security value");
13064 return 0;
13065 }
13066
13067 ascii2hexstr(ssid, ssid_hex);
13068 ascii2hexstr(passphrase, passphrase_hex);
13069 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13070 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13071
13072 if (wpa_command(intf, buf) < 0) {
13073 wpa_ctrl_detach(ctrl);
13074 wpa_ctrl_close(ctrl);
13075 send_resp(dut, conn, SIGMA_ERROR,
13076 "ErrorCode,Failed to start registrar");
13077 return 0;
13078 }
13079
13080 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13081 dut->er_oper_performed = 1;
13082
13083 return wps_connection_event(dut, conn, ctrl, intf, 0);
13084}
13085
13086
Jouni Malinenf7222712019-06-13 01:50:21 +030013087static enum sigma_cmd_result
13088cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13089 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013090{
13091 struct wpa_ctrl *ctrl;
13092 const char *intf = get_param(cmd, "Interface");
13093 const char *bssid = get_param(cmd, "Bssid");
13094 char buf[100];
13095
13096 if (!bssid) {
13097 send_resp(dut, conn, SIGMA_ERROR,
13098 "ErrorCode,Missing Bssid argument");
13099 return 0;
13100 }
13101
13102 ctrl = open_wpa_mon(intf);
13103 if (ctrl == NULL) {
13104 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13105 "wpa_supplicant monitor connection");
13106 return -2;
13107 }
13108
13109 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13110
13111 if (wpa_command(intf, buf) < 0) {
13112 wpa_ctrl_detach(ctrl);
13113 wpa_ctrl_close(ctrl);
13114 send_resp(dut, conn, SIGMA_ERROR,
13115 "ErrorCode,Failed to start registrar");
13116 return 0;
13117 }
13118
13119 return wps_connection_event(dut, conn, ctrl, intf, 0);
13120}
13121
13122
Jouni Malinenf7222712019-06-13 01:50:21 +030013123static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13124 struct sigma_conn *conn,
13125 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013126{
13127 struct wpa_ctrl *ctrl;
13128 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013129 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013130 const char *config_method = get_param(cmd, "WPSConfigMethod");
13131 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013132 int res;
13133 char buf[256];
13134 const char *events[] = {
13135 "CTRL-EVENT-CONNECTED",
13136 "WPS-OVERLAP-DETECTED",
13137 "WPS-TIMEOUT",
13138 "WPS-FAIL",
13139 NULL
13140 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013141 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013142
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013143 /* 60G WPS tests do not pass Interface parameter */
13144 if (!intf)
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013145 intf = get_main_ifname(dut);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013146
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013147 if (dut->mode == SIGMA_MODE_AP)
13148 return ap_wps_registration(dut, conn, cmd);
13149
13150 if (config_method) {
13151 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13152 * sta_wps_enter_pin before calling start_wps_registration. */
13153 if (strcasecmp(config_method, "PBC") == 0)
13154 dut->wps_method = WFA_CS_WPS_PBC;
13155 }
13156 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13157 send_resp(dut, conn, SIGMA_ERROR,
13158 "ErrorCode,WPS parameters not yet set");
13159 return STATUS_SENT;
13160 }
13161
13162 /* Make sure WPS is enabled (also for STA mode) */
13163 dut->wps_disable = 0;
13164
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013165 if (dut->band == WPS_BAND_60G && network_mode &&
13166 strcasecmp(network_mode, "PBSS") == 0) {
13167 sigma_dut_print(dut, DUT_MSG_DEBUG,
13168 "Set PBSS network mode, network id %d", id);
Jouni Malinen016ae6c2019-11-04 17:00:01 +020013169 if (set_network(get_station_ifname(dut), id, "pbss", "1") < 0)
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013170 return -2;
13171 }
13172
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013173 if (dut->force_rsn_ie) {
13174 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13175 dut->force_rsn_ie);
13176 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13177 sigma_dut_print(dut, DUT_MSG_INFO,
13178 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013179 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013180 }
13181 }
13182
vamsi krishna9b144002017-09-20 13:28:13 +053013183 ctrl = open_wpa_mon(intf);
13184 if (!ctrl) {
13185 sigma_dut_print(dut, DUT_MSG_ERROR,
13186 "Failed to open wpa_supplicant monitor connection");
13187 return -2;
13188 }
13189
13190 role = get_param(cmd, "WpsRole");
13191 if (!role) {
13192 send_resp(dut, conn, SIGMA_INVALID,
13193 "ErrorCode,WpsRole not provided");
13194 goto fail;
13195 }
13196
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013197 if (strcasecmp(role, "Enrollee") != 0) {
13198 /* Registrar role for STA not supported */
13199 send_resp(dut, conn, SIGMA_ERROR,
13200 "ErrorCode,Unsupported WpsRole value");
13201 goto fail;
13202 }
13203
13204 if (is_60g_sigma_dut(dut)) {
13205 if (dut->wps_method == WFA_CS_WPS_PBC)
13206 snprintf(buf, sizeof(buf), "WPS_PBC");
13207 else /* WFA_CS_WPS_PIN_KEYPAD */
13208 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13209 dut->wps_pin);
13210 if (wpa_command(intf, buf) < 0) {
13211 send_resp(dut, conn, SIGMA_ERROR,
13212 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013213 goto fail;
13214 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013215 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13216 if (res < 0) {
13217 send_resp(dut, conn, SIGMA_ERROR,
13218 "ErrorCode,WPS connection did not complete");
13219 goto fail;
13220 }
13221 if (strstr(buf, "WPS-TIMEOUT")) {
13222 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13223 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13224 send_resp(dut, conn, SIGMA_COMPLETE,
13225 "WpsState,OverlapSession");
13226 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13227 send_resp(dut, conn, SIGMA_COMPLETE,
13228 "WpsState,Successful");
13229 } else {
13230 send_resp(dut, conn, SIGMA_COMPLETE,
13231 "WpsState,Failure");
13232 }
13233 } else {
13234 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013235 if (wpa_command(intf, "WPS_PBC") < 0) {
13236 send_resp(dut, conn, SIGMA_ERROR,
13237 "ErrorCode,Failed to enable PBC");
13238 goto fail;
13239 }
13240 } else {
13241 /* TODO: PIN method */
13242 send_resp(dut, conn, SIGMA_ERROR,
13243 "ErrorCode,Unsupported WpsConfigMethod value");
13244 goto fail;
13245 }
13246 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13247 if (res < 0) {
13248 send_resp(dut, conn, SIGMA_ERROR,
13249 "ErrorCode,WPS connection did not complete");
13250 goto fail;
13251 }
13252 if (strstr(buf, "WPS-TIMEOUT")) {
13253 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13254 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13255 send_resp(dut, conn, SIGMA_ERROR,
13256 "ErrorCode,OverlapSession");
13257 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13258 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13259 } else {
13260 send_resp(dut, conn, SIGMA_ERROR,
13261 "ErrorCode,WPS operation failed");
13262 }
vamsi krishna9b144002017-09-20 13:28:13 +053013263 }
13264
13265fail:
13266 wpa_ctrl_detach(ctrl);
13267 wpa_ctrl_close(ctrl);
13268 return 0;
13269}
13270
13271
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013272static int req_intf(struct sigma_cmd *cmd)
13273{
13274 return get_param(cmd, "interface") == NULL ? -1 : 0;
13275}
13276
13277
13278void sta_register_cmds(void)
13279{
13280 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13281 cmd_sta_get_ip_config);
13282 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13283 cmd_sta_set_ip_config);
13284 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13285 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13286 cmd_sta_get_mac_address);
13287 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13288 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13289 cmd_sta_verify_ip_connection);
13290 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13291 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13292 cmd_sta_set_encryption);
13293 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13294 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13295 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13296 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13297 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13298 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13299 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13300 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13301 cmd_sta_set_eapakaprime);
13302 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13303 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13304 /* TODO: sta_set_ibss */
13305 /* TODO: sta_set_mode */
13306 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13307 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13308 /* TODO: sta_up_load */
13309 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13310 cmd_sta_preset_testparameters);
13311 /* TODO: sta_set_system */
13312 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13313 /* TODO: sta_set_rifs_test */
13314 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13315 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13316 /* TODO: sta_send_coexist_mgmt */
13317 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13318 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13319 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13320 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13321 cmd_sta_reset_default);
13322 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13323 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13324 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13325 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13326 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013327 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013328 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13329 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13330 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13331 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13332 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013333 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13334 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013335 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13336 cmd_sta_add_credential);
13337 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013338 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013339 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13340 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13341 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13342 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13343 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13344 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013345 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013346 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13347 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013348 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013349 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013350}