blob: 3e57e08dc20dcd993b773bf6b8c3194d8a6f3cb2 [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__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530957 if (get_driver_type() == DRIVER_OPENWRT)
958 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
1115 if (strcmp(intf, get_main_ifname()) == 0)
1116 ifname = get_station_ifname();
1117 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
1390 if (strcmp(intf, get_main_ifname()) == 0)
1391 ifname = get_station_ifname();
1392 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 Malinencd4e3c32015-10-29 12:39:56 +02001569 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1570 < 0)
1571 return -2;
1572
1573 snprintf(resp, sizeof(resp), "mac,%s", addr);
1574 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1575 return 0;
1576}
1577
1578
Jouni Malinenf7222712019-06-13 01:50:21 +03001579static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1580 struct sigma_conn *conn,
1581 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001582{
1583 /* const char *intf = get_param(cmd, "Interface"); */
1584 int connected = 0;
1585 char result[32];
1586 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1587 sizeof(result)) < 0) {
1588 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1589 "%s status", get_station_ifname());
1590 return -2;
1591 }
1592
1593 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1594 if (strncmp(result, "COMPLETED", 9) == 0)
1595 connected = 1;
1596
1597 if (connected)
1598 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1599 else
1600 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1601
1602 return 0;
1603}
1604
1605
Jouni Malinenf7222712019-06-13 01:50:21 +03001606static enum sigma_cmd_result
1607cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1608 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001609{
1610 /* const char *intf = get_param(cmd, "Interface"); */
1611 const char *dst, *timeout;
1612 int wait_time = 90;
1613 char buf[100];
1614 int res;
1615
1616 dst = get_param(cmd, "destination");
1617 if (dst == NULL || !is_ip_addr(dst))
1618 return -1;
1619
1620 timeout = get_param(cmd, "timeout");
1621 if (timeout) {
1622 wait_time = atoi(timeout);
1623 if (wait_time < 1)
1624 wait_time = 1;
1625 }
1626
1627 /* TODO: force renewal of IP lease if DHCP is enabled */
1628
1629 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1630 res = system(buf);
1631 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1632 if (res == 0)
1633 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1634 else if (res == 256)
1635 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1636 else
1637 return -2;
1638
1639 return 0;
1640}
1641
1642
Jouni Malinenf7222712019-06-13 01:50:21 +03001643static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1644 struct sigma_conn *conn,
1645 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001646{
1647 /* const char *intf = get_param(cmd, "Interface"); */
1648 char bssid[20], resp[50];
1649
1650 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1651 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001652 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001653
1654 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1655 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1656 return 0;
1657}
1658
1659
1660#ifdef __SAMSUNG__
1661static int add_use_network(const char *ifname)
1662{
1663 char buf[100];
1664
1665 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1666 wpa_command(ifname, buf);
1667 return 0;
1668}
1669#endif /* __SAMSUNG__ */
1670
1671
1672static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1673 const char *ifname, struct sigma_cmd *cmd)
1674{
1675 const char *ssid = get_param(cmd, "ssid");
1676 int id;
1677 const char *val;
1678
1679 if (ssid == NULL)
1680 return -1;
1681
1682 start_sta_mode(dut);
1683
1684#ifdef __SAMSUNG__
1685 add_use_network(ifname);
1686#endif /* __SAMSUNG__ */
1687
1688 id = add_network(ifname);
1689 if (id < 0)
1690 return -2;
1691 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1692
1693 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1694 return -2;
1695
1696 dut->infra_network_id = id;
1697 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1698
1699 val = get_param(cmd, "program");
1700 if (!val)
1701 val = get_param(cmd, "prog");
1702 if (val && strcasecmp(val, "hs2") == 0) {
1703 char buf[100];
1704 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1705 wpa_command(ifname, buf);
1706
1707 val = get_param(cmd, "prefer");
1708 if (val && atoi(val) > 0)
1709 set_network(ifname, id, "priority", "1");
1710 }
1711
1712 return id;
1713}
1714
1715
Jouni Malinenf7222712019-06-13 01:50:21 +03001716static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1717 struct sigma_conn *conn,
1718 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001719{
1720 const char *intf = get_param(cmd, "Interface");
1721 const char *ssid = get_param(cmd, "ssid");
1722 const char *type = get_param(cmd, "encpType");
1723 const char *ifname;
1724 char buf[200];
1725 int id;
1726
1727 if (intf == NULL || ssid == NULL)
1728 return -1;
1729
1730 if (strcmp(intf, get_main_ifname()) == 0)
1731 ifname = get_station_ifname();
1732 else
1733 ifname = intf;
1734
1735 id = add_network_common(dut, conn, ifname, cmd);
1736 if (id < 0)
1737 return id;
1738
1739 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1740 return -2;
1741
1742 if (type && strcasecmp(type, "wep") == 0) {
1743 const char *val;
1744 int i;
1745
1746 val = get_param(cmd, "activeKey");
1747 if (val) {
1748 int keyid;
1749 keyid = atoi(val);
1750 if (keyid < 1 || keyid > 4)
1751 return -1;
1752 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1753 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1754 return -2;
1755 }
1756
1757 for (i = 0; i < 4; i++) {
1758 snprintf(buf, sizeof(buf), "key%d", i + 1);
1759 val = get_param(cmd, buf);
1760 if (val == NULL)
1761 continue;
1762 snprintf(buf, sizeof(buf), "wep_key%d", i);
1763 if (set_network(ifname, id, buf, val) < 0)
1764 return -2;
1765 }
1766 }
1767
1768 return 1;
1769}
1770
1771
Jouni Malinene4fde732019-03-25 22:29:37 +02001772static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1773 int id, const char *val)
1774{
1775 char key_mgmt[200], *end, *pos;
1776 const char *in_pos = val;
1777
Jouni Malinen8179fee2019-03-28 03:19:47 +02001778 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001779 pos = key_mgmt;
1780 end = pos + sizeof(key_mgmt);
1781 while (*in_pos) {
1782 int res, akm = atoi(in_pos);
1783 const char *str;
1784
Jouni Malinen8179fee2019-03-28 03:19:47 +02001785 if (akm >= 0 && akm < 32)
1786 dut->akm_values |= 1 << akm;
1787
Jouni Malinene4fde732019-03-25 22:29:37 +02001788 switch (akm) {
1789 case AKM_WPA_EAP:
1790 str = "WPA-EAP";
1791 break;
1792 case AKM_WPA_PSK:
1793 str = "WPA-PSK";
1794 break;
1795 case AKM_FT_EAP:
1796 str = "FT-EAP";
1797 break;
1798 case AKM_FT_PSK:
1799 str = "FT-PSK";
1800 break;
1801 case AKM_EAP_SHA256:
1802 str = "WPA-EAP-SHA256";
1803 break;
1804 case AKM_PSK_SHA256:
1805 str = "WPA-PSK-SHA256";
1806 break;
1807 case AKM_SAE:
1808 str = "SAE";
1809 break;
1810 case AKM_FT_SAE:
1811 str = "FT-SAE";
1812 break;
1813 case AKM_SUITE_B:
1814 str = "WPA-EAP-SUITE-B-192";
1815 break;
1816 case AKM_FT_SUITE_B:
1817 str = "FT-EAP-SHA384";
1818 break;
1819 case AKM_FILS_SHA256:
1820 str = "FILS-SHA256";
1821 break;
1822 case AKM_FILS_SHA384:
1823 str = "FILS-SHA384";
1824 break;
1825 case AKM_FT_FILS_SHA256:
1826 str = "FT-FILS-SHA256";
1827 break;
1828 case AKM_FT_FILS_SHA384:
1829 str = "FT-FILS-SHA384";
1830 break;
1831 default:
1832 sigma_dut_print(dut, DUT_MSG_ERROR,
1833 "Unsupported AKMSuitetype %d", akm);
1834 return -1;
1835 }
1836
1837 res = snprintf(pos, end - pos, "%s%s",
1838 pos == key_mgmt ? "" : " ", str);
1839 if (res < 0 || res >= end - pos)
1840 return -1;
1841 pos += res;
1842
1843 in_pos = strchr(in_pos, ';');
1844 if (!in_pos)
1845 break;
1846 while (*in_pos == ';')
1847 in_pos++;
1848 }
1849 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1850 val, key_mgmt);
1851 return set_network(ifname, id, "key_mgmt", key_mgmt);
1852}
1853
1854
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001855static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1856 const char *ifname, struct sigma_cmd *cmd)
1857{
1858 const char *val;
1859 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001860 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001861 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301862 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001863
1864 id = add_network_common(dut, conn, ifname, cmd);
1865 if (id < 0)
1866 return id;
1867
Jouni Malinen47dcc952017-10-09 16:43:24 +03001868 val = get_param(cmd, "Type");
1869 owe = val && strcasecmp(val, "OWE") == 0;
1870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001871 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001872 if (!val && owe)
1873 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001874 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001875 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1876 * this missing parameter and assume proto=WPA2. */
1877 if (set_network(ifname, id, "proto", "WPA2") < 0)
1878 return ERROR_SEND_STATUS;
1879 } else if (strcasecmp(val, "wpa") == 0 ||
1880 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001881 if (set_network(ifname, id, "proto", "WPA") < 0)
1882 return -2;
1883 } else if (strcasecmp(val, "wpa2") == 0 ||
1884 strcasecmp(val, "wpa2-psk") == 0 ||
1885 strcasecmp(val, "wpa2-ft") == 0 ||
1886 strcasecmp(val, "wpa2-sha256") == 0) {
1887 if (set_network(ifname, id, "proto", "WPA2") < 0)
1888 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301889 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1890 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001891 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1892 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001893 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301894 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001895 if (set_network(ifname, id, "proto", "WPA2") < 0)
1896 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001897 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001898 } else {
1899 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1900 return 0;
1901 }
1902
1903 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001904 if (val) {
1905 cipher_set = 1;
1906 if (strcasecmp(val, "tkip") == 0) {
1907 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1908 return -2;
1909 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1910 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1911 return -2;
1912 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1913 if (set_network(ifname, id, "pairwise",
1914 "CCMP TKIP") < 0)
1915 return -2;
1916 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1917 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1918 return -2;
1919 if (set_network(ifname, id, "group", "GCMP") < 0)
1920 return -2;
1921 } else {
1922 send_resp(dut, conn, SIGMA_ERROR,
1923 "errorCode,Unrecognized encpType value");
1924 return 0;
1925 }
1926 }
1927
1928 val = get_param(cmd, "PairwiseCipher");
1929 if (val) {
1930 cipher_set = 1;
1931 /* TODO: Support space separated list */
1932 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1933 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1934 return -2;
1935 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1936 if (set_network(ifname, id, "pairwise",
1937 "CCMP-256") < 0)
1938 return -2;
1939 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1940 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1941 return -2;
1942 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1943 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1944 return -2;
1945 } else {
1946 send_resp(dut, conn, SIGMA_ERROR,
1947 "errorCode,Unrecognized PairwiseCipher value");
1948 return 0;
1949 }
1950 }
1951
Jouni Malinen47dcc952017-10-09 16:43:24 +03001952 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 send_resp(dut, conn, SIGMA_ERROR,
1954 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 return 0;
1956 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001957
1958 val = get_param(cmd, "GroupCipher");
1959 if (val) {
1960 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1961 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1962 return -2;
1963 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1964 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1965 return -2;
1966 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1967 if (set_network(ifname, id, "group", "GCMP") < 0)
1968 return -2;
1969 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1970 if (set_network(ifname, id, "group", "CCMP") < 0)
1971 return -2;
1972 } else {
1973 send_resp(dut, conn, SIGMA_ERROR,
1974 "errorCode,Unrecognized GroupCipher value");
1975 return 0;
1976 }
1977 }
1978
Jouni Malinen7b239522017-09-14 21:37:18 +03001979 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001980 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001981 const char *cipher;
1982
1983 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1984 cipher = "BIP-GMAC-256";
1985 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1986 cipher = "BIP-CMAC-256";
1987 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1988 cipher = "BIP-GMAC-128";
1989 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1990 cipher = "AES-128-CMAC";
1991 } else {
1992 send_resp(dut, conn, SIGMA_INVALID,
1993 "errorCode,Unsupported GroupMgntCipher");
1994 return 0;
1995 }
1996 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1997 send_resp(dut, conn, SIGMA_INVALID,
1998 "errorCode,Failed to set GroupMgntCipher");
1999 return 0;
2000 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002001 }
2002
Jouni Malinene4fde732019-03-25 22:29:37 +02002003 val = get_param(cmd, "AKMSuiteType");
2004 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2005 return ERROR_SEND_STATUS;
2006
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002007 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302008
2009 if (dut->program == PROGRAM_OCE) {
2010 dut->sta_pmf = STA_PMF_OPTIONAL;
2011 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2012 return -2;
2013 }
2014
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002015 val = get_param(cmd, "PMF");
2016 if (val) {
2017 if (strcasecmp(val, "Required") == 0 ||
2018 strcasecmp(val, "Forced_Required") == 0) {
2019 dut->sta_pmf = STA_PMF_REQUIRED;
2020 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2021 return -2;
2022 } else if (strcasecmp(val, "Optional") == 0) {
2023 dut->sta_pmf = STA_PMF_OPTIONAL;
2024 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2025 return -2;
2026 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002027 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002028 strcasecmp(val, "Forced_Disabled") == 0) {
2029 dut->sta_pmf = STA_PMF_DISABLED;
2030 } else {
2031 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2032 return 0;
2033 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302034 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002035 dut->sta_pmf = STA_PMF_REQUIRED;
2036 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2037 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002038 }
2039
2040 return id;
2041}
2042
2043
Jouni Malinenf7222712019-06-13 01:50:21 +03002044static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2045 struct sigma_conn *conn,
2046 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002047{
2048 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002049 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002050 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002051 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002052 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002053 const char *ifname, *val, *alg;
2054 int id;
2055
2056 if (intf == NULL)
2057 return -1;
2058
2059 if (strcmp(intf, get_main_ifname()) == 0)
2060 ifname = get_station_ifname();
2061 else
2062 ifname = intf;
2063
2064 id = set_wpa_common(dut, conn, ifname, cmd);
2065 if (id < 0)
2066 return id;
2067
2068 val = get_param(cmd, "keyMgmtType");
2069 alg = get_param(cmd, "micAlg");
2070
Jouni Malinen992a81e2017-08-22 13:57:47 +03002071 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002072 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002073 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2074 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002075 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002076 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2077 return -2;
2078 }
2079 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2080 sigma_dut_print(dut, DUT_MSG_ERROR,
2081 "Failed to clear sae_groups to default");
2082 return -2;
2083 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002084 if (!pmf) {
2085 dut->sta_pmf = STA_PMF_REQUIRED;
2086 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2087 return -2;
2088 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002089 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2090 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2091 if (set_network(ifname, id, "key_mgmt",
2092 "FT-SAE FT-PSK") < 0)
2093 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002094 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002095 if (set_network(ifname, id, "key_mgmt",
2096 "SAE WPA-PSK") < 0)
2097 return -2;
2098 }
2099 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2100 sigma_dut_print(dut, DUT_MSG_ERROR,
2101 "Failed to clear sae_groups to default");
2102 return -2;
2103 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002104 if (!pmf) {
2105 dut->sta_pmf = STA_PMF_OPTIONAL;
2106 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2107 return -2;
2108 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002109 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2111 return -2;
2112 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2113 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2114 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302115 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2116 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2117 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002118 } else if (!akm &&
2119 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2120 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002121 if (set_network(ifname, id, "key_mgmt",
2122 "WPA-PSK WPA-PSK-SHA256") < 0)
2123 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002124 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002125 if (set_network(ifname, id, "key_mgmt",
2126 "WPA-PSK WPA-PSK-SHA256") < 0)
2127 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002128 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002129 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2130 return -2;
2131 }
2132
2133 val = get_param(cmd, "passPhrase");
2134 if (val == NULL)
2135 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002136 if (type && strcasecmp(type, "SAE") == 0) {
2137 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2138 return -2;
2139 } else {
2140 if (set_network_quoted(ifname, id, "psk", val) < 0)
2141 return -2;
2142 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002143
Jouni Malinen78d10c42019-03-25 22:34:32 +02002144 val = get_param(cmd, "PasswordId");
2145 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2146 return ERROR_SEND_STATUS;
2147
Jouni Malinen992a81e2017-08-22 13:57:47 +03002148 val = get_param(cmd, "ECGroupID");
2149 if (val) {
2150 char buf[50];
2151
2152 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
2153 if (wpa_command(ifname, buf) != 0) {
2154 sigma_dut_print(dut, DUT_MSG_ERROR,
2155 "Failed to clear sae_groups");
2156 return -2;
2157 }
2158 }
2159
Jouni Malinen68143132017-09-02 02:34:08 +03002160 val = get_param(cmd, "InvalidSAEElement");
2161 if (val) {
2162 free(dut->sae_commit_override);
2163 dut->sae_commit_override = strdup(val);
2164 }
2165
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002166 if (dut->program == PROGRAM_60GHZ && network_mode &&
2167 strcasecmp(network_mode, "PBSS") == 0 &&
2168 set_network(ifname, id, "pbss", "1") < 0)
2169 return -2;
2170
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002171 return 1;
2172}
2173
2174
2175static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302176 const char *ifname, int username_identity,
2177 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002178{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302179 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002180 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002181 char buf[200], buf2[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002182#ifdef ANDROID
2183 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2184 int length;
2185#endif /* ANDROID */
Jouni Malinen8179fee2019-03-28 03:19:47 +02002186 int erp = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002187
2188 id = set_wpa_common(dut, conn, ifname, cmd);
2189 if (id < 0)
2190 return id;
2191
2192 val = get_param(cmd, "keyMgmtType");
2193 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302194 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002195
Jouni Malinenad395a22017-09-01 21:13:46 +03002196 if (val && strcasecmp(val, "SuiteB") == 0) {
2197 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2198 0)
2199 return -2;
2200 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002201 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2202 return -2;
2203 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2204 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2205 return -2;
2206 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2207 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2208 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002209 } else if (!akm &&
2210 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2211 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002212 if (set_network(ifname, id, "key_mgmt",
2213 "WPA-EAP WPA-EAP-SHA256") < 0)
2214 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302215 } else if (akm && atoi(akm) == 14) {
2216 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2217 dut->sta_pmf == STA_PMF_REQUIRED) {
2218 if (set_network(ifname, id, "key_mgmt",
2219 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2220 return -2;
2221 } else {
2222 if (set_network(ifname, id, "key_mgmt",
2223 "WPA-EAP FILS-SHA256") < 0)
2224 return -2;
2225 }
2226
Jouni Malinen8179fee2019-03-28 03:19:47 +02002227 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302228 } else if (akm && atoi(akm) == 15) {
2229 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2230 dut->sta_pmf == STA_PMF_REQUIRED) {
2231 if (set_network(ifname, id, "key_mgmt",
2232 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2233 return -2;
2234 } else {
2235 if (set_network(ifname, id, "key_mgmt",
2236 "WPA-EAP FILS-SHA384") < 0)
2237 return -2;
2238 }
2239
Jouni Malinen8179fee2019-03-28 03:19:47 +02002240 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002241 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002242 if (set_network(ifname, id, "key_mgmt",
2243 "WPA-EAP WPA-EAP-SHA256") < 0)
2244 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002245 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002246 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2247 return -2;
2248 }
2249
2250 val = get_param(cmd, "trustedRootCA");
2251 if (val) {
2252#ifdef ANDROID
2253 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2254 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
2255 kvalue);
2256 if (length > 0) {
2257 sigma_dut_print(dut, DUT_MSG_INFO,
2258 "Use Android keystore [%s]", buf);
2259 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
2260 val);
2261 goto ca_cert_selected;
2262 }
2263#endif /* ANDROID */
2264
2265 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2266#ifdef __linux__
2267 if (!file_exists(buf)) {
2268 char msg[300];
2269 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
2270 "file (%s) not found", buf);
2271 send_resp(dut, conn, SIGMA_ERROR, msg);
2272 return -3;
2273 }
2274#endif /* __linux__ */
2275#ifdef ANDROID
2276ca_cert_selected:
2277#endif /* ANDROID */
2278 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2279 return -2;
2280 }
2281
Jouni Malinen53264f62019-05-03 13:04:40 +03002282 val = get_param(cmd, "ServerCert");
2283 if (val) {
2284 FILE *f;
2285 char *result = NULL, *pos;
2286
2287 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2288 val);
2289 f = fopen(buf, "r");
2290 if (f) {
2291 result = fgets(buf, sizeof(buf), f);
2292 fclose(f);
2293 }
2294 if (!result) {
2295 snprintf(buf2, sizeof(buf2),
2296 "ErrorCode,ServerCert hash could not be read from %s",
2297 buf);
2298 send_resp(dut, conn, SIGMA_ERROR, buf2);
2299 return STATUS_SENT_ERROR;
2300 }
2301 pos = strchr(buf, '\n');
2302 if (pos)
2303 *pos = '\0';
2304 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2305 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2306 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002307
2308 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2309 if (file_exists(buf)) {
2310 sigma_dut_print(dut, DUT_MSG_DEBUG,
2311 "TOD policy enabled for the configured ServerCert hash");
2312 dut->sta_tod_policy = 1;
2313 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002314 }
2315
Jouni Malinen96f84b02019-05-03 12:32:56 +03002316 val = get_param(cmd, "Domain");
2317 if (val && set_network_quoted(ifname, id, "domain_match", val) < 0)
2318 return ERROR_SEND_STATUS;
2319
2320 val = get_param(cmd, "DomainSuffix");
2321 if (val &&
2322 set_network_quoted(ifname, id, "domain_suffix_match", val) < 0)
2323 return ERROR_SEND_STATUS;
2324
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302325 if (username_identity) {
2326 val = get_param(cmd, "username");
2327 if (val) {
2328 if (set_network_quoted(ifname, id, "identity", val) < 0)
2329 return -2;
2330 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002331
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302332 val = get_param(cmd, "password");
2333 if (val) {
2334 if (set_network_quoted(ifname, id, "password", val) < 0)
2335 return -2;
2336 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002337 }
2338
Jouni Malinen8179fee2019-03-28 03:19:47 +02002339 if (dut->akm_values &
2340 ((1 << AKM_FILS_SHA256) |
2341 (1 << AKM_FILS_SHA384) |
2342 (1 << AKM_FT_FILS_SHA256) |
2343 (1 << AKM_FT_FILS_SHA384)))
2344 erp = 1;
2345 if (erp && set_network(ifname, id, "erp", "1") < 0)
2346 return ERROR_SEND_STATUS;
2347
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002348 dut->sta_associate_wait_connect = 1;
2349
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002350 return id;
2351}
2352
2353
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002354static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2355{
2356 const char *val;
2357
2358 if (!cipher)
2359 return 0;
2360
2361 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2362 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2363 else if (strcasecmp(cipher,
2364 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2365 val = "ECDHE-RSA-AES256-GCM-SHA384";
2366 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2367 val = "DHE-RSA-AES256-GCM-SHA384";
2368 else if (strcasecmp(cipher,
2369 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2370 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2371 else
2372 return -1;
2373
2374 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2375 set_network_quoted(ifname, id, "phase1", "");
2376
2377 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2378}
2379
2380
Jouni Malinenf7222712019-06-13 01:50:21 +03002381static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2382 struct sigma_conn *conn,
2383 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002384{
2385 const char *intf = get_param(cmd, "Interface");
2386 const char *ifname, *val;
2387 int id;
2388 char buf[200];
2389#ifdef ANDROID
2390 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2391 int length;
2392 int jb_or_newer = 0;
2393 char prop[PROPERTY_VALUE_MAX];
2394#endif /* ANDROID */
2395
2396 if (intf == NULL)
2397 return -1;
2398
2399 if (strcmp(intf, get_main_ifname()) == 0)
2400 ifname = get_station_ifname();
2401 else
2402 ifname = intf;
2403
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302404 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002405 if (id < 0)
2406 return id;
2407
2408 if (set_network(ifname, id, "eap", "TLS") < 0)
2409 return -2;
2410
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302411 if (!get_param(cmd, "username") &&
2412 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002413 "wifi-user@wifilabs.local") < 0)
2414 return -2;
2415
2416 val = get_param(cmd, "clientCertificate");
2417 if (val == NULL)
2418 return -1;
2419#ifdef ANDROID
2420 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2421 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2422 if (length < 0) {
2423 /*
2424 * JB started reporting keystore type mismatches, so retry with
2425 * the GET_PUBKEY command if the generic GET fails.
2426 */
2427 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2428 buf, kvalue);
2429 }
2430
2431 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2432 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2433 if (strncmp(prop, "4.0", 3) != 0)
2434 jb_or_newer = 1;
2435 } else
2436 jb_or_newer = 1; /* assume newer */
2437
2438 if (jb_or_newer && length > 0) {
2439 sigma_dut_print(dut, DUT_MSG_INFO,
2440 "Use Android keystore [%s]", buf);
2441 if (set_network(ifname, id, "engine", "1") < 0)
2442 return -2;
2443 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2444 return -2;
2445 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2446 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2447 return -2;
2448 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2449 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2450 return -2;
2451 return 1;
2452 } else if (length > 0) {
2453 sigma_dut_print(dut, DUT_MSG_INFO,
2454 "Use Android keystore [%s]", buf);
2455 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2456 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2457 return -2;
2458 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2459 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2460 return -2;
2461 return 1;
2462 }
2463#endif /* ANDROID */
2464
2465 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2466#ifdef __linux__
2467 if (!file_exists(buf)) {
2468 char msg[300];
2469 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2470 "(%s) not found", buf);
2471 send_resp(dut, conn, SIGMA_ERROR, msg);
2472 return -3;
2473 }
2474#endif /* __linux__ */
2475 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2476 return -2;
2477 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2478 return -2;
2479
2480 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2481 return -2;
2482
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002483 val = get_param(cmd, "keyMgmtType");
2484 if (val && strcasecmp(val, "SuiteB") == 0) {
2485 val = get_param(cmd, "CertType");
2486 if (val && strcasecmp(val, "RSA") == 0) {
2487 if (set_network_quoted(ifname, id, "phase1",
2488 "tls_suiteb=1") < 0)
2489 return -2;
2490 } else {
2491 if (set_network_quoted(ifname, id, "openssl_ciphers",
2492 "SUITEB192") < 0)
2493 return -2;
2494 }
2495
2496 val = get_param(cmd, "TLSCipher");
2497 if (set_tls_cipher(ifname, id, val) < 0) {
2498 send_resp(dut, conn, SIGMA_ERROR,
2499 "ErrorCode,Unsupported TLSCipher value");
2500 return -3;
2501 }
2502 }
2503
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002504 return 1;
2505}
2506
2507
Jouni Malinenf7222712019-06-13 01:50:21 +03002508static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2509 struct sigma_conn *conn,
2510 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002511{
2512 const char *intf = get_param(cmd, "Interface");
2513 const char *ifname;
2514 int id;
2515
2516 if (intf == NULL)
2517 return -1;
2518
2519 if (strcmp(intf, get_main_ifname()) == 0)
2520 ifname = get_station_ifname();
2521 else
2522 ifname = intf;
2523
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302524 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002525 if (id < 0)
2526 return id;
2527
2528 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2529 send_resp(dut, conn, SIGMA_ERROR,
2530 "errorCode,Failed to set TTLS method");
2531 return 0;
2532 }
2533
2534 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2535 send_resp(dut, conn, SIGMA_ERROR,
2536 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2537 return 0;
2538 }
2539
2540 return 1;
2541}
2542
2543
Jouni Malinenf7222712019-06-13 01:50:21 +03002544static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2545 struct sigma_conn *conn,
2546 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547{
2548 const char *intf = get_param(cmd, "Interface");
2549 const char *ifname;
2550 int id;
2551
2552 if (intf == NULL)
2553 return -1;
2554
2555 if (strcmp(intf, get_main_ifname()) == 0)
2556 ifname = get_station_ifname();
2557 else
2558 ifname = intf;
2559
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302560 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002561 if (id < 0)
2562 return id;
2563
2564 if (set_network(ifname, id, "eap", "SIM") < 0)
2565 return -2;
2566
2567 return 1;
2568}
2569
2570
Jouni Malinenf7222712019-06-13 01:50:21 +03002571static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2572 struct sigma_conn *conn,
2573 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002574{
2575 const char *intf = get_param(cmd, "Interface");
2576 const char *ifname, *val;
2577 int id;
2578 char buf[100];
2579
2580 if (intf == NULL)
2581 return -1;
2582
2583 if (strcmp(intf, get_main_ifname()) == 0)
2584 ifname = get_station_ifname();
2585 else
2586 ifname = intf;
2587
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302588 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002589 if (id < 0)
2590 return id;
2591
2592 if (set_network(ifname, id, "eap", "PEAP") < 0)
2593 return -2;
2594
2595 val = get_param(cmd, "innerEAP");
2596 if (val) {
2597 if (strcasecmp(val, "MSCHAPv2") == 0) {
2598 if (set_network_quoted(ifname, id, "phase2",
2599 "auth=MSCHAPV2") < 0)
2600 return -2;
2601 } else if (strcasecmp(val, "GTC") == 0) {
2602 if (set_network_quoted(ifname, id, "phase2",
2603 "auth=GTC") < 0)
2604 return -2;
2605 } else
2606 return -1;
2607 }
2608
2609 val = get_param(cmd, "peapVersion");
2610 if (val) {
2611 int ver = atoi(val);
2612 if (ver < 0 || ver > 1)
2613 return -1;
2614 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2615 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2616 return -2;
2617 }
2618
2619 return 1;
2620}
2621
2622
Jouni Malinenf7222712019-06-13 01:50:21 +03002623static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2624 struct sigma_conn *conn,
2625 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002626{
2627 const char *intf = get_param(cmd, "Interface");
2628 const char *ifname, *val;
2629 int id;
2630 char buf[100];
2631
2632 if (intf == NULL)
2633 return -1;
2634
2635 if (strcmp(intf, get_main_ifname()) == 0)
2636 ifname = get_station_ifname();
2637 else
2638 ifname = intf;
2639
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302640 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002641 if (id < 0)
2642 return id;
2643
2644 if (set_network(ifname, id, "eap", "FAST") < 0)
2645 return -2;
2646
2647 val = get_param(cmd, "innerEAP");
2648 if (val) {
2649 if (strcasecmp(val, "MSCHAPV2") == 0) {
2650 if (set_network_quoted(ifname, id, "phase2",
2651 "auth=MSCHAPV2") < 0)
2652 return -2;
2653 } else if (strcasecmp(val, "GTC") == 0) {
2654 if (set_network_quoted(ifname, id, "phase2",
2655 "auth=GTC") < 0)
2656 return -2;
2657 } else
2658 return -1;
2659 }
2660
2661 val = get_param(cmd, "validateServer");
2662 if (val) {
2663 /* TODO */
2664 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2665 "validateServer=%s", val);
2666 }
2667
2668 val = get_param(cmd, "pacFile");
2669 if (val) {
2670 snprintf(buf, sizeof(buf), "blob://%s", val);
2671 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2672 return -2;
2673 }
2674
2675 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2676 0)
2677 return -2;
2678
2679 return 1;
2680}
2681
2682
Jouni Malinenf7222712019-06-13 01:50:21 +03002683static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2684 struct sigma_conn *conn,
2685 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002686{
2687 const char *intf = get_param(cmd, "Interface");
2688 const char *ifname;
2689 int id;
2690
2691 if (intf == NULL)
2692 return -1;
2693
2694 if (strcmp(intf, get_main_ifname()) == 0)
2695 ifname = get_station_ifname();
2696 else
2697 ifname = intf;
2698
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302699 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002700 if (id < 0)
2701 return id;
2702
2703 if (set_network(ifname, id, "eap", "AKA") < 0)
2704 return -2;
2705
2706 return 1;
2707}
2708
2709
Jouni Malinenf7222712019-06-13 01:50:21 +03002710static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2711 struct sigma_conn *conn,
2712 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002713{
2714 const char *intf = get_param(cmd, "Interface");
2715 const char *ifname;
2716 int id;
2717
2718 if (intf == NULL)
2719 return -1;
2720
2721 if (strcmp(intf, get_main_ifname()) == 0)
2722 ifname = get_station_ifname();
2723 else
2724 ifname = intf;
2725
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302726 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002727 if (id < 0)
2728 return id;
2729
2730 if (set_network(ifname, id, "eap", "AKA'") < 0)
2731 return -2;
2732
2733 return 1;
2734}
2735
2736
2737static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2738 struct sigma_cmd *cmd)
2739{
2740 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002741 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002742 const char *ifname;
2743 int id;
2744
2745 if (strcmp(intf, get_main_ifname()) == 0)
2746 ifname = get_station_ifname();
2747 else
2748 ifname = intf;
2749
2750 id = add_network_common(dut, conn, ifname, cmd);
2751 if (id < 0)
2752 return id;
2753
2754 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2755 return -2;
2756
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002757 if (dut->program == PROGRAM_60GHZ && network_mode &&
2758 strcasecmp(network_mode, "PBSS") == 0 &&
2759 set_network(ifname, id, "pbss", "1") < 0)
2760 return -2;
2761
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002762 return 1;
2763}
2764
2765
Jouni Malinen47dcc952017-10-09 16:43:24 +03002766static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2767 struct sigma_cmd *cmd)
2768{
2769 const char *intf = get_param(cmd, "Interface");
2770 const char *ifname, *val;
2771 int id;
2772
2773 if (intf == NULL)
2774 return -1;
2775
2776 if (strcmp(intf, get_main_ifname()) == 0)
2777 ifname = get_station_ifname();
2778 else
2779 ifname = intf;
2780
2781 id = set_wpa_common(dut, conn, ifname, cmd);
2782 if (id < 0)
2783 return id;
2784
2785 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2786 return -2;
2787
2788 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002789 if (val && strcmp(val, "0") == 0) {
2790 if (wpa_command(ifname,
2791 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2792 sigma_dut_print(dut, DUT_MSG_ERROR,
2793 "Failed to set OWE DH Param element override");
2794 return -2;
2795 }
2796 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002797 sigma_dut_print(dut, DUT_MSG_ERROR,
2798 "Failed to clear owe_group");
2799 return -2;
2800 }
2801
2802 return 1;
2803}
2804
2805
Jouni Malinenf7222712019-06-13 01:50:21 +03002806static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
2807 struct sigma_conn *conn,
2808 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002809{
2810 const char *type = get_param(cmd, "Type");
2811
2812 if (type == NULL) {
2813 send_resp(dut, conn, SIGMA_ERROR,
2814 "ErrorCode,Missing Type argument");
2815 return 0;
2816 }
2817
2818 if (strcasecmp(type, "OPEN") == 0)
2819 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002820 if (strcasecmp(type, "OWE") == 0)
2821 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002822 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002823 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002824 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002825 return cmd_sta_set_psk(dut, conn, cmd);
2826 if (strcasecmp(type, "EAPTLS") == 0)
2827 return cmd_sta_set_eaptls(dut, conn, cmd);
2828 if (strcasecmp(type, "EAPTTLS") == 0)
2829 return cmd_sta_set_eapttls(dut, conn, cmd);
2830 if (strcasecmp(type, "EAPPEAP") == 0)
2831 return cmd_sta_set_peap(dut, conn, cmd);
2832 if (strcasecmp(type, "EAPSIM") == 0)
2833 return cmd_sta_set_eapsim(dut, conn, cmd);
2834 if (strcasecmp(type, "EAPFAST") == 0)
2835 return cmd_sta_set_eapfast(dut, conn, cmd);
2836 if (strcasecmp(type, "EAPAKA") == 0)
2837 return cmd_sta_set_eapaka(dut, conn, cmd);
2838 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2839 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002840 if (strcasecmp(type, "wep") == 0)
2841 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002842
2843 send_resp(dut, conn, SIGMA_ERROR,
2844 "ErrorCode,Unsupported Type value");
2845 return 0;
2846}
2847
2848
2849int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2850{
2851#ifdef __linux__
2852 /* special handling for ath6kl */
2853 char path[128], fname[128], *pos;
2854 ssize_t res;
2855 FILE *f;
2856
Jouni Malinene39cd562019-05-29 23:39:56 +03002857 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
2858 intf);
2859 if (res < 0 || res >= sizeof(fname))
2860 return 0;
2861 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002862 if (res < 0)
2863 return 0; /* not ath6kl */
2864
2865 if (res >= (int) sizeof(path))
2866 res = sizeof(path) - 1;
2867 path[res] = '\0';
2868 pos = strrchr(path, '/');
2869 if (pos == NULL)
2870 pos = path;
2871 else
2872 pos++;
2873 snprintf(fname, sizeof(fname),
2874 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2875 "create_qos", pos);
2876 if (!file_exists(fname))
2877 return 0; /* not ath6kl */
2878
2879 if (uapsd) {
2880 f = fopen(fname, "w");
2881 if (f == NULL)
2882 return -1;
2883
2884 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2885 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2886 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2887 "20000 0\n");
2888 fclose(f);
2889 } else {
2890 snprintf(fname, sizeof(fname),
2891 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2892 "delete_qos", pos);
2893
2894 f = fopen(fname, "w");
2895 if (f == NULL)
2896 return -1;
2897
2898 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2899 fprintf(f, "2 4\n");
2900 fclose(f);
2901 }
2902#endif /* __linux__ */
2903
2904 return 0;
2905}
2906
2907
Jouni Malinenf7222712019-06-13 01:50:21 +03002908static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
2909 struct sigma_conn *conn,
2910 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002911{
2912 const char *intf = get_param(cmd, "Interface");
2913 /* const char *ssid = get_param(cmd, "ssid"); */
2914 const char *val;
2915 int max_sp_len = 4;
2916 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2917 char buf[100];
2918 int ret1, ret2;
2919
2920 val = get_param(cmd, "maxSPLength");
2921 if (val) {
2922 max_sp_len = atoi(val);
2923 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2924 max_sp_len != 4)
2925 return -1;
2926 }
2927
2928 val = get_param(cmd, "acBE");
2929 if (val)
2930 ac_be = atoi(val);
2931
2932 val = get_param(cmd, "acBK");
2933 if (val)
2934 ac_bk = atoi(val);
2935
2936 val = get_param(cmd, "acVI");
2937 if (val)
2938 ac_vi = atoi(val);
2939
2940 val = get_param(cmd, "acVO");
2941 if (val)
2942 ac_vo = atoi(val);
2943
2944 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2945
2946 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2947 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2948 ret1 = wpa_command(intf, buf);
2949
2950 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2951 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2952 ret2 = wpa_command(intf, buf);
2953
2954 if (ret1 && ret2) {
2955 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2956 "UAPSD parameters.");
2957 return -2;
2958 }
2959
2960 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2961 send_resp(dut, conn, SIGMA_ERROR,
2962 "ErrorCode,Failed to set ath6kl QoS parameters");
2963 return 0;
2964 }
2965
2966 return 1;
2967}
2968
2969
Jouni Malinenf7222712019-06-13 01:50:21 +03002970static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
2971 struct sigma_conn *conn,
2972 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002973{
2974 char buf[1000];
2975 const char *intf = get_param(cmd, "Interface");
2976 const char *grp = get_param(cmd, "Group");
2977 const char *act = get_param(cmd, "Action");
2978 const char *tid = get_param(cmd, "Tid");
2979 const char *dir = get_param(cmd, "Direction");
2980 const char *psb = get_param(cmd, "Psb");
2981 const char *up = get_param(cmd, "Up");
2982 const char *fixed = get_param(cmd, "Fixed");
2983 const char *size = get_param(cmd, "Size");
2984 const char *msize = get_param(cmd, "Maxsize");
2985 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2986 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2987 const char *inact = get_param(cmd, "Inactivity");
2988 const char *sus = get_param(cmd, "Suspension");
2989 const char *mindr = get_param(cmd, "Mindatarate");
2990 const char *meandr = get_param(cmd, "Meandatarate");
2991 const char *peakdr = get_param(cmd, "Peakdatarate");
2992 const char *phyrate = get_param(cmd, "Phyrate");
2993 const char *burstsize = get_param(cmd, "Burstsize");
2994 const char *sba = get_param(cmd, "Sba");
2995 int direction;
2996 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002997 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002998 int fixed_int;
2999 int psb_ts;
3000
3001 if (intf == NULL || grp == NULL || act == NULL )
3002 return -1;
3003
3004 if (strcasecmp(act, "addts") == 0) {
3005 if (tid == NULL || dir == NULL || psb == NULL ||
3006 up == NULL || fixed == NULL || size == NULL)
3007 return -1;
3008
3009 /*
3010 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3011 * possible values, but WMM-AC and V-E test scripts use "UP,
3012 * "DOWN", and "BIDI".
3013 */
3014 if (strcasecmp(dir, "uplink") == 0 ||
3015 strcasecmp(dir, "up") == 0) {
3016 direction = 0;
3017 } else if (strcasecmp(dir, "downlink") == 0 ||
3018 strcasecmp(dir, "down") == 0) {
3019 direction = 1;
3020 } else if (strcasecmp(dir, "bidi") == 0) {
3021 direction = 2;
3022 } else {
3023 sigma_dut_print(dut, DUT_MSG_ERROR,
3024 "Direction %s not supported", dir);
3025 return -1;
3026 }
3027
3028 if (strcasecmp(psb, "legacy") == 0) {
3029 psb_ts = 0;
3030 } else if (strcasecmp(psb, "uapsd") == 0) {
3031 psb_ts = 1;
3032 } else {
3033 sigma_dut_print(dut, DUT_MSG_ERROR,
3034 "PSB %s not supported", psb);
3035 return -1;
3036 }
3037
3038 if (atoi(tid) < 0 || atoi(tid) > 7) {
3039 sigma_dut_print(dut, DUT_MSG_ERROR,
3040 "TID %s not supported", tid);
3041 return -1;
3042 }
3043
3044 if (strcasecmp(fixed, "true") == 0) {
3045 fixed_int = 1;
3046 } else {
3047 fixed_int = 0;
3048 }
3049
Peng Xu93319622017-10-04 17:58:16 -07003050 if (sba)
3051 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003052
3053 dut->dialog_token++;
3054 handle = 7000 + dut->dialog_token;
3055
3056 /*
3057 * size: convert to hex
3058 * maxsi: convert to hex
3059 * mindr: convert to hex
3060 * meandr: convert to hex
3061 * peakdr: convert to hex
3062 * burstsize: convert to hex
3063 * phyrate: convert to hex
3064 * sba: convert to hex with modification
3065 * minsi: convert to integer
3066 * sus: convert to integer
3067 * inact: convert to integer
3068 * maxsi: convert to integer
3069 */
3070
3071 /*
3072 * The Nominal MSDU Size field is 2 octets long and contains an
3073 * unsigned integer that specifies the nominal size, in octets,
3074 * of MSDUs belonging to the traffic under this traffic
3075 * specification and is defined in Figure 16. If the Fixed
3076 * subfield is set to 1, then the size of the MSDU is fixed and
3077 * is indicated by the Size Subfield. If the Fixed subfield is
3078 * set to 0, then the size of the MSDU might not be fixed and
3079 * the Size indicates the nominal MSDU size.
3080 *
3081 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3082 * and specifies the excess allocation of time (and bandwidth)
3083 * over and above the stated rates required to transport an MSDU
3084 * belonging to the traffic in this TSPEC. This field is
3085 * represented as an unsigned binary number with an implicit
3086 * binary point after the leftmost 3 bits. For example, an SBA
3087 * of 1.75 is represented as 0x3800. This field is included to
3088 * account for retransmissions. As such, the value of this field
3089 * must be greater than unity.
3090 */
3091
3092 snprintf(buf, sizeof(buf),
3093 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3094 " 0x%X 0x%X 0x%X"
3095 " 0x%X 0x%X 0x%X"
3096 " 0x%X %d %d %d %d"
3097 " %d %d",
3098 intf, handle, tid, direction, psb_ts, up,
3099 (unsigned int) ((fixed_int << 15) | atoi(size)),
3100 msize ? atoi(msize) : 0,
3101 mindr ? atoi(mindr) : 0,
3102 meandr ? atoi(meandr) : 0,
3103 peakdr ? atoi(peakdr) : 0,
3104 burstsize ? atoi(burstsize) : 0,
3105 phyrate ? atoi(phyrate) : 0,
3106 sba ? ((unsigned int) (((int) sba_fv << 13) |
3107 (int)((sba_fv - (int) sba_fv) *
3108 8192))) : 0,
3109 minsi ? atoi(minsi) : 0,
3110 sus ? atoi(sus) : 0,
3111 0, 0,
3112 inact ? atoi(inact) : 0,
3113 maxsi ? atoi(maxsi) : 0);
3114
3115 if (system(buf) != 0) {
3116 sigma_dut_print(dut, DUT_MSG_ERROR,
3117 "iwpriv addtspec request failed");
3118 send_resp(dut, conn, SIGMA_ERROR,
3119 "errorCode,Failed to execute addTspec command");
3120 return 0;
3121 }
3122
3123 sigma_dut_print(dut, DUT_MSG_INFO,
3124 "iwpriv addtspec request send");
3125
3126 /* Mapping handle to a TID */
3127 dut->tid_to_handle[atoi(tid)] = handle;
3128 } else if (strcasecmp(act, "delts") == 0) {
3129 if (tid == NULL)
3130 return -1;
3131
3132 if (atoi(tid) < 0 || atoi(tid) > 7) {
3133 sigma_dut_print(dut, DUT_MSG_ERROR,
3134 "TID %s not supported", tid);
3135 send_resp(dut, conn, SIGMA_ERROR,
3136 "errorCode,Unsupported TID");
3137 return 0;
3138 }
3139
3140 handle = dut->tid_to_handle[atoi(tid)];
3141
3142 if (handle < 7000 || handle > 7255) {
3143 /* Invalid handle ie no mapping for that TID */
3144 sigma_dut_print(dut, DUT_MSG_ERROR,
3145 "handle-> %d not found", handle);
3146 }
3147
3148 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3149 intf, handle);
3150
3151 if (system(buf) != 0) {
3152 sigma_dut_print(dut, DUT_MSG_ERROR,
3153 "iwpriv deltspec request failed");
3154 send_resp(dut, conn, SIGMA_ERROR,
3155 "errorCode,Failed to execute delTspec command");
3156 return 0;
3157 }
3158
3159 sigma_dut_print(dut, DUT_MSG_INFO,
3160 "iwpriv deltspec request send");
3161
3162 dut->tid_to_handle[atoi(tid)] = 0;
3163 } else {
3164 sigma_dut_print(dut, DUT_MSG_ERROR,
3165 "Action type %s not supported", act);
3166 send_resp(dut, conn, SIGMA_ERROR,
3167 "errorCode,Unsupported Action");
3168 return 0;
3169 }
3170
3171 return 1;
3172}
3173
3174
vamsi krishna52e16f92017-08-29 12:37:34 +05303175static int find_network(struct sigma_dut *dut, const char *ssid)
3176{
3177 char list[4096];
3178 char *pos;
3179
3180 sigma_dut_print(dut, DUT_MSG_DEBUG,
3181 "Search for profile based on SSID: '%s'", ssid);
3182 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
3183 list, sizeof(list)) < 0)
3184 return -1;
3185 pos = strstr(list, ssid);
3186 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3187 return -1;
3188
3189 while (pos > list && pos[-1] != '\n')
3190 pos--;
3191 dut->infra_network_id = atoi(pos);
3192 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3193 return 0;
3194}
3195
3196
Sunil Dutt44595082018-02-12 19:41:45 +05303197#ifdef NL80211_SUPPORT
3198static int sta_config_rsnie(struct sigma_dut *dut, int val)
3199{
3200 struct nl_msg *msg;
3201 int ret;
3202 struct nlattr *params;
3203 int ifindex;
3204
3205 ifindex = if_nametoindex("wlan0");
3206 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3207 NL80211_CMD_VENDOR)) ||
3208 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3209 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3210 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3211 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3212 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3213 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3214 sigma_dut_print(dut, DUT_MSG_ERROR,
3215 "%s: err in adding vendor_cmd and vendor_data",
3216 __func__);
3217 nlmsg_free(msg);
3218 return -1;
3219 }
3220 nla_nest_end(msg, params);
3221
3222 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3223 if (ret) {
3224 sigma_dut_print(dut, DUT_MSG_ERROR,
3225 "%s: err in send_and_recv_msgs, ret=%d",
3226 __func__, ret);
3227 return ret;
3228 }
3229
3230 return 0;
3231}
3232#endif /* NL80211_SUPPORT */
3233
3234
Jouni Malinenf7222712019-06-13 01:50:21 +03003235static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3236 struct sigma_conn *conn,
3237 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003238{
3239 /* const char *intf = get_param(cmd, "Interface"); */
3240 const char *ssid = get_param(cmd, "ssid");
3241 const char *wps_param = get_param(cmd, "WPS");
3242 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003243 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003244 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003245 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003246 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003247 int e;
3248 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3249 struct wpa_ctrl *ctrl = NULL;
3250 int num_network_not_found = 0;
3251 int num_disconnected = 0;
3252 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003253
3254 if (ssid == NULL)
3255 return -1;
3256
Jouni Malinen3c367e82017-06-23 17:01:47 +03003257 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303258#ifdef NL80211_SUPPORT
3259 if (get_driver_type() == DRIVER_WCN) {
3260 sta_config_rsnie(dut, 1);
3261 dut->config_rsnie = 1;
3262 }
3263#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003264 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3265 dut->rsne_override);
3266 if (wpa_command(get_station_ifname(), buf) < 0) {
3267 send_resp(dut, conn, SIGMA_ERROR,
3268 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3269 return 0;
3270 }
3271 }
3272
Jouni Malinen68143132017-09-02 02:34:08 +03003273 if (dut->sae_commit_override) {
3274 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3275 dut->sae_commit_override);
3276 if (wpa_command(get_station_ifname(), buf) < 0) {
3277 send_resp(dut, conn, SIGMA_ERROR,
3278 "ErrorCode,Failed to set SAE commit override");
3279 return 0;
3280 }
3281 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303282#ifdef ANDROID
3283 if (dut->fils_hlp)
3284 process_fils_hlp(dut);
3285#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003286
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003287 if (wps_param &&
3288 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3289 wps = 1;
3290
3291 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003292 if (dut->program == PROGRAM_60GHZ && network_mode &&
3293 strcasecmp(network_mode, "PBSS") == 0 &&
3294 set_network(get_station_ifname(), dut->infra_network_id,
3295 "pbss", "1") < 0)
3296 return -2;
3297
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003298 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3299 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3300 "parameters not yet set");
3301 return 0;
3302 }
3303 if (dut->wps_method == WFA_CS_WPS_PBC) {
3304 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
3305 return -2;
3306 } else {
3307 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3308 dut->wps_pin);
3309 if (wpa_command(get_station_ifname(), buf) < 0)
3310 return -2;
3311 }
3312 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303313 if (strcmp(ssid, dut->infra_ssid) == 0) {
3314 sigma_dut_print(dut, DUT_MSG_DEBUG,
3315 "sta_associate for the most recently added network");
3316 } else if (find_network(dut, ssid) < 0) {
3317 sigma_dut_print(dut, DUT_MSG_DEBUG,
3318 "sta_associate for a previously stored network profile");
3319 send_resp(dut, conn, SIGMA_ERROR,
3320 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003321 return 0;
3322 }
3323
3324 if (bssid &&
3325 set_network(get_station_ifname(), dut->infra_network_id,
3326 "bssid", bssid) < 0) {
3327 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3328 "Invalid bssid argument");
3329 return 0;
3330 }
3331
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003332 if (dut->program == PROGRAM_WPA3 &&
3333 dut->sta_associate_wait_connect) {
3334 ctrl = open_wpa_mon(get_station_ifname());
3335 if (!ctrl)
3336 return ERROR_SEND_STATUS;
3337 }
3338
Jouni Malinen46a19b62017-06-23 14:31:27 +03003339 extra[0] = '\0';
3340 if (chan)
3341 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003342 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003343 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3344 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003345 if (wpa_command(get_station_ifname(), buf) < 0) {
3346 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3347 "network id %d on %s",
3348 dut->infra_network_id,
3349 get_station_ifname());
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003350 ret = ERROR_SEND_STATUS;
3351 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003352 }
3353 }
3354
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003355 if (!ctrl)
3356 return SUCCESS_SEND_STATUS;
3357
3358 /* Wait for connection result to be able to store server certificate
3359 * hash for trust root override testing
3360 * (dev_exec_action,ServerCertTrust). */
3361
3362 for (e = 0; e < 20; e++) {
3363 const char *events[] = {
3364 "CTRL-EVENT-EAP-PEER-CERT",
3365 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3366 "CTRL-EVENT-DISCONNECTED",
3367 "CTRL-EVENT-CONNECTED",
3368 "CTRL-EVENT-NETWORK-NOT-FOUND",
3369 NULL
3370 };
3371 char buf[1024];
3372 int res;
3373
3374 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3375 if (res < 0) {
3376 send_resp(dut, conn, SIGMA_ERROR,
3377 "ErrorCode,Association did not complete");
3378 ret = STATUS_SENT_ERROR;
3379 break;
3380 }
3381 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3382 buf);
3383
3384 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3385 strstr(buf, " depth=0")) {
3386 char *pos = strstr(buf, " hash=");
3387
3388 if (pos) {
3389 char *end;
3390
3391 tod = strstr(buf, " tod=1") != NULL;
3392 sigma_dut_print(dut, DUT_MSG_DEBUG,
3393 "Server certificate TOD policy: %d",
3394 tod);
3395
3396 pos += 6;
3397 end = strchr(pos, ' ');
3398 if (end)
3399 *end = '\0';
3400 strlcpy(dut->server_cert_hash, pos,
3401 sizeof(dut->server_cert_hash));
3402 sigma_dut_print(dut, DUT_MSG_DEBUG,
3403 "Server certificate hash: %s",
3404 dut->server_cert_hash);
3405 }
3406 }
3407
3408 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3409 send_resp(dut, conn, SIGMA_COMPLETE,
3410 "Result,TLS server certificate validation failed");
3411 ret = STATUS_SENT_ERROR;
3412 break;
3413 }
3414
3415 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3416 num_network_not_found++;
3417
3418 if (num_network_not_found > 2) {
3419 send_resp(dut, conn, SIGMA_COMPLETE,
3420 "Result,Network not found");
3421 ret = STATUS_SENT_ERROR;
3422 break;
3423 }
3424 }
3425
3426 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3427 num_disconnected++;
3428
3429 if (num_disconnected > 2) {
3430 send_resp(dut, conn, SIGMA_COMPLETE,
3431 "Result,Connection failed");
3432 ret = STATUS_SENT_ERROR;
3433 break;
3434 }
3435 }
3436
3437 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3438 if (tod >= 0) {
3439 sigma_dut_print(dut, DUT_MSG_DEBUG,
3440 "Network profile TOD policy update: %d -> %d",
3441 dut->sta_tod_policy, tod);
3442 dut->sta_tod_policy = tod;
3443 }
3444 break;
3445 }
3446 }
3447done:
3448 if (ctrl) {
3449 wpa_ctrl_detach(ctrl);
3450 wpa_ctrl_close(ctrl);
3451 }
3452 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003453}
3454
3455
3456static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3457{
3458 char buf[500], cmd[200];
3459 int res;
3460
3461 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3462 * default path */
3463 res = snprintf(cmd, sizeof(cmd),
3464 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3465 file_exists("./hs20-osu-client") ?
3466 "./hs20-osu-client" : "hs20-osu-client",
3467 sigma_wpas_ctrl,
3468 dut->summary_log ? "-s " : "",
3469 dut->summary_log ? dut->summary_log : "");
3470 if (res < 0 || res >= (int) sizeof(cmd))
3471 return -1;
3472
3473 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3474 if (res < 0 || res >= (int) sizeof(buf))
3475 return -1;
3476 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3477
3478 if (system(buf) != 0) {
3479 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3480 return -1;
3481 }
3482 sigma_dut_print(dut, DUT_MSG_DEBUG,
3483 "Completed hs20-osu-client operation");
3484
3485 return 0;
3486}
3487
3488
3489static int download_ppsmo(struct sigma_dut *dut,
3490 struct sigma_conn *conn,
3491 const char *intf,
3492 struct sigma_cmd *cmd)
3493{
3494 const char *name, *path, *val;
3495 char url[500], buf[600], fbuf[100];
3496 char *fqdn = NULL;
3497
3498 name = get_param(cmd, "FileName");
3499 path = get_param(cmd, "FilePath");
3500 if (name == NULL || path == NULL)
3501 return -1;
3502
3503 if (strcasecmp(path, "VendorSpecific") == 0) {
3504 snprintf(url, sizeof(url), "PPS/%s", name);
3505 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3506 "from the device (%s)", url);
3507 if (!file_exists(url)) {
3508 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3509 "PPS MO file does not exist");
3510 return 0;
3511 }
3512 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3513 if (system(buf) != 0) {
3514 send_resp(dut, conn, SIGMA_ERROR,
3515 "errorCode,Failed to copy PPS MO");
3516 return 0;
3517 }
3518 } else if (strncasecmp(path, "http:", 5) != 0 &&
3519 strncasecmp(path, "https:", 6) != 0) {
3520 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3521 "Unsupported FilePath value");
3522 return 0;
3523 } else {
3524 snprintf(url, sizeof(url), "%s/%s", path, name);
3525 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3526 url);
3527 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3528 remove("pps-tnds.xml");
3529 if (system(buf) != 0) {
3530 send_resp(dut, conn, SIGMA_ERROR,
3531 "errorCode,Failed to download PPS MO");
3532 return 0;
3533 }
3534 }
3535
3536 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3537 send_resp(dut, conn, SIGMA_ERROR,
3538 "errorCode,Failed to parse downloaded PPSMO");
3539 return 0;
3540 }
3541 unlink("pps-tnds.xml");
3542
3543 val = get_param(cmd, "managementTreeURI");
3544 if (val) {
3545 const char *pos, *end;
3546 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3547 val);
3548 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3549 send_resp(dut, conn, SIGMA_ERROR,
3550 "errorCode,Invalid managementTreeURI prefix");
3551 return 0;
3552 }
3553 pos = val + 8;
3554 end = strchr(pos, '/');
3555 if (end == NULL ||
3556 strcmp(end, "/PerProviderSubscription") != 0) {
3557 send_resp(dut, conn, SIGMA_ERROR,
3558 "errorCode,Invalid managementTreeURI postfix");
3559 return 0;
3560 }
3561 if (end - pos >= (int) sizeof(fbuf)) {
3562 send_resp(dut, conn, SIGMA_ERROR,
3563 "errorCode,Too long FQDN in managementTreeURI");
3564 return 0;
3565 }
3566 memcpy(fbuf, pos, end - pos);
3567 fbuf[end - pos] = '\0';
3568 fqdn = fbuf;
3569 sigma_dut_print(dut, DUT_MSG_INFO,
3570 "FQDN from managementTreeURI: %s", fqdn);
3571 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3572 FILE *f = fopen("pps-fqdn", "r");
3573 if (f) {
3574 if (fgets(fbuf, sizeof(fbuf), f)) {
3575 fbuf[sizeof(fbuf) - 1] = '\0';
3576 fqdn = fbuf;
3577 sigma_dut_print(dut, DUT_MSG_DEBUG,
3578 "Use FQDN %s", fqdn);
3579 }
3580 fclose(f);
3581 }
3582 }
3583
3584 if (fqdn == NULL) {
3585 send_resp(dut, conn, SIGMA_ERROR,
3586 "errorCode,No FQDN specified");
3587 return 0;
3588 }
3589
3590 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3591 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3592 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3593
3594 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3595 if (rename("pps.xml", buf) < 0) {
3596 send_resp(dut, conn, SIGMA_ERROR,
3597 "errorCode,Could not move PPS MO");
3598 return 0;
3599 }
3600
3601 if (strcasecmp(path, "VendorSpecific") == 0) {
3602 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3603 fqdn);
3604 if (system(buf)) {
3605 send_resp(dut, conn, SIGMA_ERROR,
3606 "errorCode,Failed to copy OSU CA cert");
3607 return 0;
3608 }
3609
3610 snprintf(buf, sizeof(buf),
3611 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3612 fqdn);
3613 if (system(buf)) {
3614 send_resp(dut, conn, SIGMA_ERROR,
3615 "errorCode,Failed to copy AAA CA cert");
3616 return 0;
3617 }
3618 } else {
3619 snprintf(buf, sizeof(buf),
3620 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3621 fqdn, fqdn);
3622 if (run_hs20_osu(dut, buf) < 0) {
3623 send_resp(dut, conn, SIGMA_ERROR,
3624 "errorCode,Failed to download OSU CA cert");
3625 return 0;
3626 }
3627
3628 snprintf(buf, sizeof(buf),
3629 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3630 fqdn, fqdn);
3631 if (run_hs20_osu(dut, buf) < 0) {
3632 sigma_dut_print(dut, DUT_MSG_INFO,
3633 "Failed to download AAA CA cert");
3634 }
3635 }
3636
3637 if (file_exists("next-client-cert.pem")) {
3638 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3639 if (rename("next-client-cert.pem", buf) < 0) {
3640 send_resp(dut, conn, SIGMA_ERROR,
3641 "errorCode,Could not move client certificate");
3642 return 0;
3643 }
3644 }
3645
3646 if (file_exists("next-client-key.pem")) {
3647 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3648 if (rename("next-client-key.pem", buf) < 0) {
3649 send_resp(dut, conn, SIGMA_ERROR,
3650 "errorCode,Could not move client key");
3651 return 0;
3652 }
3653 }
3654
3655 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3656 if (run_hs20_osu(dut, buf) < 0) {
3657 send_resp(dut, conn, SIGMA_ERROR,
3658 "errorCode,Failed to configure credential from "
3659 "PPSMO");
3660 return 0;
3661 }
3662
3663 return 1;
3664}
3665
3666
3667static int download_cert(struct sigma_dut *dut,
3668 struct sigma_conn *conn,
3669 const char *intf,
3670 struct sigma_cmd *cmd)
3671{
3672 const char *name, *path;
3673 char url[500], buf[600];
3674
3675 name = get_param(cmd, "FileName");
3676 path = get_param(cmd, "FilePath");
3677 if (name == NULL || path == NULL)
3678 return -1;
3679
3680 if (strcasecmp(path, "VendorSpecific") == 0) {
3681 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3682 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3683 "certificate from the device (%s)", url);
3684 if (!file_exists(url)) {
3685 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3686 "certificate file does not exist");
3687 return 0;
3688 }
3689 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3690 if (system(buf) != 0) {
3691 send_resp(dut, conn, SIGMA_ERROR,
3692 "errorCode,Failed to copy client "
3693 "certificate");
3694 return 0;
3695 }
3696
3697 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3698 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3699 "private key from the device (%s)", url);
3700 if (!file_exists(url)) {
3701 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3702 "private key file does not exist");
3703 return 0;
3704 }
3705 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3706 if (system(buf) != 0) {
3707 send_resp(dut, conn, SIGMA_ERROR,
3708 "errorCode,Failed to copy client key");
3709 return 0;
3710 }
3711 } else if (strncasecmp(path, "http:", 5) != 0 &&
3712 strncasecmp(path, "https:", 6) != 0) {
3713 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3714 "Unsupported FilePath value");
3715 return 0;
3716 } else {
3717 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3718 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3719 "certificate/key from %s", url);
3720 snprintf(buf, sizeof(buf),
3721 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3722 if (system(buf) != 0) {
3723 send_resp(dut, conn, SIGMA_ERROR,
3724 "errorCode,Failed to download client "
3725 "certificate");
3726 return 0;
3727 }
3728
3729 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3730 {
3731 send_resp(dut, conn, SIGMA_ERROR,
3732 "errorCode,Failed to copy client key");
3733 return 0;
3734 }
3735 }
3736
3737 return 1;
3738}
3739
3740
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003741static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3742 struct sigma_conn *conn,
3743 struct sigma_cmd *cmd)
3744{
3745 const char *val;
3746 const char *intf = get_param(cmd, "interface");
3747
3748 if (!intf)
3749 return -1;
3750
3751 val = get_param(cmd, "WscIEFragment");
3752 if (val && strcasecmp(val, "enable") == 0) {
3753 sigma_dut_print(dut, DUT_MSG_DEBUG,
3754 "Enable WSC IE fragmentation");
3755
3756 dut->wsc_fragment = 1;
3757 /* set long attributes to force fragmentation */
3758 if (wpa_command(intf, "SET device_name "
3759 WPS_LONG_DEVICE_NAME) < 0)
3760 return -2;
3761 if (wpa_command(intf, "SET manufacturer "
3762 WPS_LONG_MANUFACTURER) < 0)
3763 return -2;
3764 if (wpa_command(intf, "SET model_name "
3765 WPS_LONG_MODEL_NAME) < 0)
3766 return -2;
3767 if (wpa_command(intf, "SET model_number "
3768 WPS_LONG_MODEL_NUMBER) < 0)
3769 return -2;
3770 if (wpa_command(intf, "SET serial_number "
3771 WPS_LONG_SERIAL_NUMBER) < 0)
3772 return -2;
3773 }
3774
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003775 val = get_param(cmd, "RSN_IE");
3776 if (val) {
3777 if (strcasecmp(val, "disable") == 0)
3778 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3779 else if (strcasecmp(val, "enable") == 0)
3780 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3781 }
3782
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003783 val = get_param(cmd, "WpsVersion");
3784 if (val)
3785 dut->wps_forced_version = get_wps_forced_version(dut, val);
3786
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003787 val = get_param(cmd, "WscEAPFragment");
3788 if (val && strcasecmp(val, "enable") == 0)
3789 dut->eap_fragment = 1;
3790
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003791 return 1;
3792}
3793
3794
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003795static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3796 struct sigma_conn *conn,
3797 const char *intf,
3798 struct sigma_cmd *cmd)
3799{
3800 const char *val;
3801
3802 val = get_param(cmd, "FileType");
3803 if (val && strcasecmp(val, "PPSMO") == 0)
3804 return download_ppsmo(dut, conn, intf, cmd);
3805 if (val && strcasecmp(val, "CERT") == 0)
3806 return download_cert(dut, conn, intf, cmd);
3807 if (val) {
3808 send_resp(dut, conn, SIGMA_ERROR,
3809 "ErrorCode,Unsupported FileType");
3810 return 0;
3811 }
3812
3813 return 1;
3814}
3815
3816
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303817static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3818 struct sigma_conn *conn,
3819 const char *intf,
3820 struct sigma_cmd *cmd)
3821{
3822 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303823 char buf[1000];
3824 char text[20];
3825 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303826
3827 val = get_param(cmd, "OCESupport");
3828 if (val && strcasecmp(val, "Disable") == 0) {
3829 if (wpa_command(intf, "SET oce 0") < 0) {
3830 send_resp(dut, conn, SIGMA_ERROR,
3831 "ErrorCode,Failed to disable OCE");
3832 return 0;
3833 }
3834 } else if (val && strcasecmp(val, "Enable") == 0) {
3835 if (wpa_command(intf, "SET oce 1") < 0) {
3836 send_resp(dut, conn, SIGMA_ERROR,
3837 "ErrorCode,Failed to enable OCE");
3838 return 0;
3839 }
3840 }
3841
vamsi krishnaa2799492017-12-05 14:28:01 +05303842 val = get_param(cmd, "FILScap");
3843 if (val && (atoi(val) == 1)) {
3844 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3845 send_resp(dut, conn, SIGMA_ERROR,
3846 "ErrorCode,Failed to enable FILS");
3847 return 0;
3848 }
3849 } else if (val && (atoi(val) == 0)) {
3850 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3851 send_resp(dut, conn, SIGMA_ERROR,
3852 "ErrorCode,Failed to disable FILS");
3853 return 0;
3854 }
3855 }
3856
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303857 val = get_param(cmd, "FILSHLP");
3858 if (val && strcasecmp(val, "Enable") == 0) {
3859 if (get_wpa_status(get_station_ifname(), "address", text,
3860 sizeof(text)) < 0)
3861 return -2;
3862 hwaddr_aton(text, addr);
3863 snprintf(buf, sizeof(buf),
3864 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3865 "080045100140000040004011399e00000000ffffffff00440043"
3866 "012cb30001010600fd4f46410000000000000000000000000000"
3867 "000000000000"
3868 "%02x%02x%02x%02x%02x%02x"
3869 "0000000000000000000000000000000000000000000000000000"
3870 "0000000000000000000000000000000000000000000000000000"
3871 "0000000000000000000000000000000000000000000000000000"
3872 "0000000000000000000000000000000000000000000000000000"
3873 "0000000000000000000000000000000000000000000000000000"
3874 "0000000000000000000000000000000000000000000000000000"
3875 "0000000000000000000000000000000000000000000000000000"
3876 "0000000000000000000000000000000000000000638253633501"
3877 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3878 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3879 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3880 if (wpa_command(intf, buf)) {
3881 send_resp(dut, conn, SIGMA_ERROR,
3882 "ErrorCode,Failed to add HLP");
3883 return 0;
3884 }
3885 dut->fils_hlp = 1;
3886 }
3887
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303888 return 1;
3889}
3890
3891
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003892static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3893 const char *val)
3894{
3895 int counter = 0;
3896 char token[50];
3897 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303898 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003899
Peng Xub8fc5cc2017-05-10 17:27:28 -07003900 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003901 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303902 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003903 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003904 if (strcmp(result, "disable") == 0)
3905 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
3906 else
3907 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303908 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003909 counter++;
3910 }
3911}
3912
3913
3914static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3915 const char *val)
3916{
3917 char buf[100];
3918
3919 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3920 if (system(buf) != 0) {
3921 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3922 }
3923}
3924
3925
3926static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3927 const char *val)
3928{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003929 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003930 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003931 }
3932}
3933
3934
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003935static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3936 const char *val)
3937{
3938#ifdef NL80211_SUPPORT
3939 struct nl_msg *msg;
3940 int ret = 0;
3941 struct nlattr *params;
3942 int ifindex;
3943 int wmmenable = 1;
3944
3945 if (val &&
3946 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3947 wmmenable = 0;
3948
3949 ifindex = if_nametoindex(intf);
3950 if (ifindex == 0) {
3951 sigma_dut_print(dut, DUT_MSG_ERROR,
3952 "%s: Index for interface %s failed",
3953 __func__, intf);
3954 return -1;
3955 }
3956
3957 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3958 NL80211_CMD_VENDOR)) ||
3959 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3960 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3961 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3962 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3963 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3964 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3965 wmmenable)) {
3966 sigma_dut_print(dut, DUT_MSG_ERROR,
3967 "%s: err in adding vendor_cmd and vendor_data",
3968 __func__);
3969 nlmsg_free(msg);
3970 return -1;
3971 }
3972 nla_nest_end(msg, params);
3973
3974 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3975 if (ret) {
3976 sigma_dut_print(dut, DUT_MSG_ERROR,
3977 "%s: err in send_and_recv_msgs, ret=%d",
3978 __func__, ret);
3979 }
3980 return ret;
3981#else /* NL80211_SUPPORT */
3982 sigma_dut_print(dut, DUT_MSG_ERROR,
3983 "WMM cannot be changed without NL80211_SUPPORT defined");
3984 return -1;
3985#endif /* NL80211_SUPPORT */
3986}
3987
3988
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003989static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3990 const char *val)
3991{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003992 int sgi20;
3993
3994 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3995
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003996 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003997}
3998
3999
4000static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4001 const char *val)
4002{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304003 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004004
4005 /* Disable Tx Beam forming when using a fixed rate */
4006 ath_disable_txbf(dut, intf);
4007
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304008 v = atoi(val);
4009 if (v < 0 || v > 32) {
4010 sigma_dut_print(dut, DUT_MSG_ERROR,
4011 "Invalid Fixed MCS rate: %d", v);
4012 return;
4013 }
4014 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004015
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004016 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004017
4018 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004019 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004020}
4021
4022
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004023static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4024 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004025{
4026 char buf[60];
4027
4028 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4029 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4030 else
4031 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4032
4033 if (system(buf) != 0)
4034 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4035}
4036
4037
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004038static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4039 int ampdu)
4040{
4041 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004042 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004043
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004044 if (ampdu)
4045 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004046 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4047 if (system(buf) != 0) {
4048 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4049 return -1;
4050 }
4051
4052 return 0;
4053}
4054
4055
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004056static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4057 const char *val)
4058{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004059 run_iwpriv(dut, intf, "tx_stbc %s", val);
4060 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004061}
4062
4063
4064static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4065 const char *val)
4066{
4067 char buf[60];
4068
Peng Xucc317ed2017-05-18 16:44:37 -07004069 if (strcmp(val, "160") == 0) {
4070 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4071 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004072 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4073 } else if (strcmp(val, "40") == 0) {
4074 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4075 } else if (strcmp(val, "20") == 0) {
4076 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4077 } else if (strcasecmp(val, "Auto") == 0) {
4078 buf[0] = '\0';
4079 } else {
4080 sigma_dut_print(dut, DUT_MSG_ERROR,
4081 "WIDTH/CTS_WIDTH value not supported");
4082 return -1;
4083 }
4084
4085 if (buf[0] != '\0' && system(buf) != 0) {
4086 sigma_dut_print(dut, DUT_MSG_ERROR,
4087 "Failed to set WIDTH/CTS_WIDTH");
4088 return -1;
4089 }
4090
4091 return 0;
4092}
4093
4094
4095int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4096 const char *intf, const char *val)
4097{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004098 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004099 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004100 dut->chwidth = 0;
4101 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004102 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004103 dut->chwidth = 0;
4104 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004105 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004106 dut->chwidth = 1;
4107 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004108 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004109 dut->chwidth = 2;
4110 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004111 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004112 dut->chwidth = 3;
4113 } else {
4114 send_resp(dut, conn, SIGMA_ERROR,
4115 "ErrorCode,WIDTH not supported");
4116 return -1;
4117 }
4118
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004119 return 0;
4120}
4121
4122
4123static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4124 const char *val)
4125{
4126 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004127 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004128
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004129 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004130 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004131 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004132 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004133 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004134 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004135 } else {
4136 sigma_dut_print(dut, DUT_MSG_ERROR,
4137 "SP_STREAM value not supported");
4138 return -1;
4139 }
4140
4141 if (system(buf) != 0) {
4142 sigma_dut_print(dut, DUT_MSG_ERROR,
4143 "Failed to set SP_STREAM");
4144 return -1;
4145 }
4146
Arif Hussainac6c5112018-05-25 17:34:00 -07004147 dut->sta_nss = sta_nss;
4148
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004149 return 0;
4150}
4151
4152
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304153static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4154 const char *val)
4155{
4156 char buf[60];
4157
4158 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4159 if (system(buf) != 0)
4160 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4161
4162 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4163 if (system(buf) != 0)
4164 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4165}
4166
4167
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304168static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4169 struct sigma_conn *conn,
4170 const char *intf, int capa)
4171{
4172 char buf[32];
4173
4174 if (capa > 0 && capa < 4) {
4175 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4176 if (wpa_command(intf, buf) < 0) {
4177 send_resp(dut, conn, SIGMA_ERROR,
4178 "ErrorCode, Failed to set cellular data capability");
4179 return 0;
4180 }
4181 return 1;
4182 }
4183
4184 sigma_dut_print(dut, DUT_MSG_ERROR,
4185 "Invalid Cellular data capability: %d", capa);
4186 send_resp(dut, conn, SIGMA_INVALID,
4187 "ErrorCode,Invalid cellular data capability");
4188 return 0;
4189}
4190
4191
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304192static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4193 const char *intf, const char *val)
4194{
4195 if (strcasecmp(val, "Disable") == 0) {
4196 if (wpa_command(intf, "SET roaming 0") < 0) {
4197 send_resp(dut, conn, SIGMA_ERROR,
4198 "ErrorCode,Failed to disable roaming");
4199 return 0;
4200 }
4201 return 1;
4202 }
4203
4204 if (strcasecmp(val, "Enable") == 0) {
4205 if (wpa_command(intf, "SET roaming 1") < 0) {
4206 send_resp(dut, conn, SIGMA_ERROR,
4207 "ErrorCode,Failed to enable roaming");
4208 return 0;
4209 }
4210 return 1;
4211 }
4212
4213 sigma_dut_print(dut, DUT_MSG_ERROR,
4214 "Invalid value provided for roaming: %s", val);
4215 send_resp(dut, conn, SIGMA_INVALID,
4216 "ErrorCode,Unknown value provided for Roaming");
4217 return 0;
4218}
4219
4220
Ashwini Patila75de5a2017-04-13 16:35:05 +05304221static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4222 struct sigma_conn *conn,
4223 const char *intf, const char *val)
4224{
4225 if (strcasecmp(val, "Disable") == 0) {
4226 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4227 send_resp(dut, conn, SIGMA_ERROR,
4228 "ErrorCode,Failed to disable Assoc_disallow");
4229 return 0;
4230 }
4231 return 1;
4232 }
4233
4234 if (strcasecmp(val, "Enable") == 0) {
4235 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4236 send_resp(dut, conn, SIGMA_ERROR,
4237 "ErrorCode,Failed to enable Assoc_disallow");
4238 return 0;
4239 }
4240 return 1;
4241 }
4242
4243 sigma_dut_print(dut, DUT_MSG_ERROR,
4244 "Invalid value provided for Assoc_disallow: %s", val);
4245 send_resp(dut, conn, SIGMA_INVALID,
4246 "ErrorCode,Unknown value provided for Assoc_disallow");
4247 return 0;
4248}
4249
4250
Ashwini Patilc63161e2017-04-13 16:30:23 +05304251static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4252 const char *intf, const char *val)
4253{
4254 if (strcasecmp(val, "Reject") == 0) {
4255 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4256 send_resp(dut, conn, SIGMA_ERROR,
4257 "ErrorCode,Failed to Reject BTM Request");
4258 return 0;
4259 }
4260 return 1;
4261 }
4262
4263 if (strcasecmp(val, "Accept") == 0) {
4264 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4265 send_resp(dut, conn, SIGMA_ERROR,
4266 "ErrorCode,Failed to Accept BTM Request");
4267 return 0;
4268 }
4269 return 1;
4270 }
4271
4272 sigma_dut_print(dut, DUT_MSG_ERROR,
4273 "Invalid value provided for BSS_Transition: %s", val);
4274 send_resp(dut, conn, SIGMA_INVALID,
4275 "ErrorCode,Unknown value provided for BSS_Transition");
4276 return 0;
4277}
4278
4279
Ashwini Patil00402582017-04-13 12:29:39 +05304280static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4281 struct sigma_conn *conn,
4282 const char *intf,
4283 struct sigma_cmd *cmd)
4284{
4285 const char *ch, *pref, *op_class, *reason;
4286 char buf[120];
4287 int len, ret;
4288
4289 pref = get_param(cmd, "Ch_Pref");
4290 if (!pref)
4291 return 1;
4292
4293 if (strcasecmp(pref, "clear") == 0) {
4294 free(dut->non_pref_ch_list);
4295 dut->non_pref_ch_list = NULL;
4296 } else {
4297 op_class = get_param(cmd, "Ch_Op_Class");
4298 if (!op_class) {
4299 send_resp(dut, conn, SIGMA_INVALID,
4300 "ErrorCode,Ch_Op_Class not provided");
4301 return 0;
4302 }
4303
4304 ch = get_param(cmd, "Ch_Pref_Num");
4305 if (!ch) {
4306 send_resp(dut, conn, SIGMA_INVALID,
4307 "ErrorCode,Ch_Pref_Num not provided");
4308 return 0;
4309 }
4310
4311 reason = get_param(cmd, "Ch_Reason_Code");
4312 if (!reason) {
4313 send_resp(dut, conn, SIGMA_INVALID,
4314 "ErrorCode,Ch_Reason_Code not provided");
4315 return 0;
4316 }
4317
4318 if (!dut->non_pref_ch_list) {
4319 dut->non_pref_ch_list =
4320 calloc(1, NON_PREF_CH_LIST_SIZE);
4321 if (!dut->non_pref_ch_list) {
4322 send_resp(dut, conn, SIGMA_ERROR,
4323 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4324 return 0;
4325 }
4326 }
4327 len = strlen(dut->non_pref_ch_list);
4328 ret = snprintf(dut->non_pref_ch_list + len,
4329 NON_PREF_CH_LIST_SIZE - len,
4330 " %s:%s:%s:%s", op_class, ch, pref, reason);
4331 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4332 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4333 dut->non_pref_ch_list);
4334 } else {
4335 sigma_dut_print(dut, DUT_MSG_ERROR,
4336 "snprintf failed for non_pref_list, ret = %d",
4337 ret);
4338 send_resp(dut, conn, SIGMA_ERROR,
4339 "ErrorCode,snprintf failed");
4340 free(dut->non_pref_ch_list);
4341 dut->non_pref_ch_list = NULL;
4342 return 0;
4343 }
4344 }
4345
4346 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4347 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4348 if (ret < 0 || ret >= (int) sizeof(buf)) {
4349 sigma_dut_print(dut, DUT_MSG_DEBUG,
4350 "snprintf failed for set non_pref_chan, ret: %d",
4351 ret);
4352 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4353 return 0;
4354 }
4355
4356 if (wpa_command(intf, buf) < 0) {
4357 send_resp(dut, conn, SIGMA_ERROR,
4358 "ErrorCode,Failed to set non-preferred channel list");
4359 return 0;
4360 }
4361
4362 return 1;
4363}
4364
4365
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004366#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004367
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004368static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4369 uint8_t cfg)
4370{
4371 struct nl_msg *msg;
4372 int ret = 0;
4373 struct nlattr *params;
4374 int ifindex;
4375
4376 ifindex = if_nametoindex(intf);
4377 if (ifindex == 0) {
4378 sigma_dut_print(dut, DUT_MSG_ERROR,
4379 "%s: Index for interface %s failed",
4380 __func__, intf);
4381 return -1;
4382 }
4383
4384 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4385 NL80211_CMD_VENDOR)) ||
4386 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4387 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4388 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4389 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4390 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4391 nla_put_u8(msg,
4392 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4393 cfg)) {
4394 sigma_dut_print(dut, DUT_MSG_ERROR,
4395 "%s: err in adding vendor_cmd and vendor_data",
4396 __func__);
4397 nlmsg_free(msg);
4398 return -1;
4399 }
4400 nla_nest_end(msg, params);
4401
4402 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4403 if (ret) {
4404 sigma_dut_print(dut, DUT_MSG_ERROR,
4405 "%s: err in send_and_recv_msgs, ret=%d",
4406 __func__, ret);
4407 }
4408 return ret;
4409}
4410
4411
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004412static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4413 enum he_fragmentation_val frag)
4414{
4415 struct nl_msg *msg;
4416 int ret = 0;
4417 struct nlattr *params;
4418 int ifindex;
4419
4420 ifindex = if_nametoindex(intf);
4421 if (ifindex == 0) {
4422 sigma_dut_print(dut, DUT_MSG_ERROR,
4423 "%s: Index for interface %s failed",
4424 __func__, intf);
4425 return -1;
4426 }
4427
4428 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4429 NL80211_CMD_VENDOR)) ||
4430 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4431 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4432 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4433 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4434 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4435 nla_put_u8(msg,
4436 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4437 frag)) {
4438 sigma_dut_print(dut, DUT_MSG_ERROR,
4439 "%s: err in adding vendor_cmd and vendor_data",
4440 __func__);
4441 nlmsg_free(msg);
4442 return -1;
4443 }
4444 nla_nest_end(msg, params);
4445
4446 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4447 if (ret) {
4448 sigma_dut_print(dut, DUT_MSG_ERROR,
4449 "%s: err in send_and_recv_msgs, ret=%d",
4450 __func__, ret);
4451 }
4452 return ret;
4453}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004454
4455
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004456static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
4457 enum qca_wlan_he_ltf_cfg ltf)
4458{
4459 struct nl_msg *msg;
4460 int ret = 0;
4461 struct nlattr *params;
4462 int ifindex;
4463
4464 ifindex = if_nametoindex(intf);
4465 if (ifindex == 0) {
4466 sigma_dut_print(dut, DUT_MSG_ERROR,
4467 "%s: Index for interface %s failed",
4468 __func__, intf);
4469 return -1;
4470 }
4471
4472 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4473 NL80211_CMD_VENDOR)) ||
4474 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4475 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4476 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4477 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4478 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4479 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4480 ltf)) {
4481 sigma_dut_print(dut, DUT_MSG_ERROR,
4482 "%s: err in adding vendor_cmd and vendor_data",
4483 __func__);
4484 nlmsg_free(msg);
4485 return -1;
4486 }
4487 nla_nest_end(msg, params);
4488
4489 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4490 if (ret) {
4491 sigma_dut_print(dut, DUT_MSG_ERROR,
4492 "%s: err in send_and_recv_msgs, ret=%d",
4493 __func__, ret);
4494 }
4495 return ret;
4496}
4497
4498
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004499static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4500 int noack, enum qca_wlan_ac_type ac)
4501{
4502 struct nl_msg *msg;
4503 int ret = 0;
4504 struct nlattr *params;
4505 int ifindex;
4506
4507 ifindex = if_nametoindex(intf);
4508 if (ifindex == 0) {
4509 sigma_dut_print(dut, DUT_MSG_ERROR,
4510 "%s: Index for interface %s failed",
4511 __func__, intf);
4512 return -1;
4513 }
4514
4515 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4516 NL80211_CMD_VENDOR)) ||
4517 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4518 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4519 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4520 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4521 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4522 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4523 noack) ||
4524 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4525 ac)) {
4526 sigma_dut_print(dut, DUT_MSG_ERROR,
4527 "%s: err in adding vendor_cmd and vendor_data",
4528 __func__);
4529 nlmsg_free(msg);
4530 return -1;
4531 }
4532 nla_nest_end(msg, params);
4533
4534 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4535 if (ret) {
4536 sigma_dut_print(dut, DUT_MSG_ERROR,
4537 "%s: err in send_and_recv_msgs, ret=%d",
4538 __func__, ret);
4539 }
4540 return ret;
4541}
4542
4543
4544static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4545 const char *val)
4546{
4547 int noack, ret;
4548 char token[100];
4549 char *result;
4550 char *saveptr;
4551 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4552
4553 strlcpy(token, val, sizeof(token));
4554 token[sizeof(token) - 1] = '\0';
4555 result = strtok_r(token, ":", &saveptr);
4556 while (result) {
4557 noack = strcasecmp(result, "Disable") != 0;
4558 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4559 if (ret) {
4560 sigma_dut_print(dut, DUT_MSG_ERROR,
4561 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4562 ac, ret);
4563 }
4564 result = strtok_r(NULL, ":", &saveptr);
4565 ac++;
4566 }
4567}
4568
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004569#endif /* NL80211_SUPPORT */
4570
4571
Jouni Malinenf7222712019-06-13 01:50:21 +03004572static enum sigma_cmd_result
4573cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4574 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004575{
4576 const char *intf = get_param(cmd, "Interface");
4577 const char *val;
4578
4579 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004580 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4581 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004582 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4583 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004584
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004585 if (val && strcasecmp(val, "LOC") == 0)
4586 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004587 if (val && strcasecmp(val, "60GHZ") == 0) {
4588 val = get_param(cmd, "WPS");
4589 if (val && strcasecmp(val, "disable") == 0) {
4590 dut->wps_disable = 1;
4591 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4592 } else {
4593 /* wps_disable can have other value from the previous
4594 * test, so make sure it has the correct value.
4595 */
4596 dut->wps_disable = 0;
4597 }
4598
4599 val = get_param(cmd, "P2P");
4600 if (val && strcasecmp(val, "disable") == 0)
4601 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4602 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004603
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004604 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4605 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4606
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004607#ifdef ANDROID_NAN
4608 if (val && strcasecmp(val, "NAN") == 0)
4609 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4610#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004611#ifdef MIRACAST
4612 if (val && (strcasecmp(val, "WFD") == 0 ||
4613 strcasecmp(val, "DisplayR2") == 0))
4614 return miracast_preset_testparameters(dut, conn, cmd);
4615#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004616
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304617 if (val && strcasecmp(val, "MBO") == 0) {
4618 val = get_param(cmd, "Cellular_Data_Cap");
4619 if (val &&
4620 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4621 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304622
4623 val = get_param(cmd, "Ch_Pref");
4624 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4625 return 0;
4626
Ashwini Patilc63161e2017-04-13 16:30:23 +05304627 val = get_param(cmd, "BSS_Transition");
4628 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4629 return 0;
4630
Ashwini Patila75de5a2017-04-13 16:35:05 +05304631 val = get_param(cmd, "Assoc_Disallow");
4632 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4633 return 0;
4634
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304635 val = get_param(cmd, "Roaming");
4636 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4637 return 0;
4638
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304639 return 1;
4640 }
4641
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304642 if (val && strcasecmp(val, "OCE") == 0)
4643 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4644
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004645#if 0
4646 val = get_param(cmd, "Supplicant");
4647 if (val && strcasecmp(val, "Default") != 0) {
4648 send_resp(dut, conn, SIGMA_ERROR,
4649 "ErrorCode,Only default(Vendor) supplicant "
4650 "supported");
4651 return 0;
4652 }
4653#endif
4654
4655 val = get_param(cmd, "RTS");
4656 if (val) {
4657 switch (get_driver_type()) {
4658 case DRIVER_ATHEROS:
4659 ath_sta_set_rts(dut, intf, val);
4660 break;
4661 default:
4662#if 0
4663 send_resp(dut, conn, SIGMA_ERROR,
4664 "ErrorCode,Setting RTS not supported");
4665 return 0;
4666#else
4667 sigma_dut_print(dut, DUT_MSG_DEBUG,
4668 "Setting RTS not supported");
4669 break;
4670#endif
4671 }
4672 }
4673
4674#if 0
4675 val = get_param(cmd, "FRGMNT");
4676 if (val) {
4677 /* TODO */
4678 send_resp(dut, conn, SIGMA_ERROR,
4679 "ErrorCode,Setting FRGMNT not supported");
4680 return 0;
4681 }
4682#endif
4683
4684#if 0
4685 val = get_param(cmd, "Preamble");
4686 if (val) {
4687 /* TODO: Long/Short */
4688 send_resp(dut, conn, SIGMA_ERROR,
4689 "ErrorCode,Setting Preamble not supported");
4690 return 0;
4691 }
4692#endif
4693
4694 val = get_param(cmd, "Mode");
4695 if (val) {
4696 if (strcmp(val, "11b") == 0 ||
4697 strcmp(val, "11g") == 0 ||
4698 strcmp(val, "11a") == 0 ||
4699 strcmp(val, "11n") == 0 ||
4700 strcmp(val, "11ng") == 0 ||
4701 strcmp(val, "11nl") == 0 ||
4702 strcmp(val, "11nl(nabg)") == 0 ||
4703 strcmp(val, "AC") == 0 ||
4704 strcmp(val, "11AC") == 0 ||
4705 strcmp(val, "11ac") == 0 ||
4706 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004707 strcmp(val, "11an") == 0 ||
4708 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004709 /* STA supports all modes by default */
4710 } else {
4711 send_resp(dut, conn, SIGMA_ERROR,
4712 "ErrorCode,Setting Mode not supported");
4713 return 0;
4714 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004715
4716 /* Change the mode only in case of testbed for HE program
4717 * and for 11a and 11g modes only. */
4718 if (dut->program == PROGRAM_HE &&
4719 dut->device_type == STA_testbed) {
4720 int phymode;
4721 char buf[60];
4722
4723 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004724 phymode = 1; /* IEEE80211_MODE_11A */
4725 } else if (strcmp(val, "11g") == 0) {
4726 phymode = 3; /* IEEE80211_MODE_11G */
4727 } else if (strcmp(val, "11b") == 0) {
4728 phymode = 2; /* IEEE80211_MODE_11B */
4729 } else if (strcmp(val, "11n") == 0 ||
4730 strcmp(val, "11nl") == 0 ||
4731 strcmp(val, "11nl(nabg)") == 0) {
4732 phymode = 22; /* IEEE80211_MODE_11AGN */
4733 } else if (strcmp(val, "11ng") == 0) {
4734 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4735 } else if (strcmp(val, "AC") == 0 ||
4736 strcasecmp(val, "11AC") == 0) {
4737 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4738 } else if (strcmp(val, "11na") == 0 ||
4739 strcasecmp(val, "11an") == 0) {
4740 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4741 } else if (strcmp(val, "11ax") == 0) {
4742 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004743 } else {
4744 sigma_dut_print(dut, DUT_MSG_DEBUG,
4745 "Ignoring mode change for mode: %s",
4746 val);
4747 phymode = -1;
4748 }
4749 if (phymode != -1) {
4750 snprintf(buf, sizeof(buf),
4751 "iwpriv %s setphymode %d",
4752 intf, phymode);
4753 if (system(buf) != 0) {
4754 sigma_dut_print(dut, DUT_MSG_ERROR,
4755 "iwpriv setting of phymode failed");
4756 }
4757 }
4758 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004759 }
4760
4761 val = get_param(cmd, "wmm");
4762 if (val) {
4763 switch (get_driver_type()) {
4764 case DRIVER_ATHEROS:
4765 ath_sta_set_wmm(dut, intf, val);
4766 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004767 case DRIVER_WCN:
4768 wcn_sta_set_wmm(dut, intf, val);
4769 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004770 default:
4771 sigma_dut_print(dut, DUT_MSG_DEBUG,
4772 "Setting wmm not supported");
4773 break;
4774 }
4775 }
4776
4777 val = get_param(cmd, "Powersave");
4778 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004779 char buf[60];
4780
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004781 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004782 if (get_driver_type() == DRIVER_WCN) {
4783 snprintf(buf, sizeof(buf),
4784 "iwpriv %s setPower 2", intf);
4785 if (system(buf) != 0) {
4786 sigma_dut_print(dut, DUT_MSG_ERROR,
4787 "iwpriv setPower 2 failed");
4788 return 0;
4789 }
4790 }
4791
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004792 if (wpa_command(get_station_ifname(),
4793 "P2P_SET ps 0") < 0)
4794 return -2;
4795 /* Make sure test modes are disabled */
4796 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4797 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4798 } else if (strcmp(val, "1") == 0 ||
4799 strcasecmp(val, "PSPoll") == 0 ||
4800 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004801 if (get_driver_type() == DRIVER_WCN) {
4802 snprintf(buf, sizeof(buf),
4803 "iwpriv %s setPower 1", intf);
4804 if (system(buf) != 0) {
4805 sigma_dut_print(dut, DUT_MSG_ERROR,
4806 "iwpriv setPower 1 failed");
4807 return 0;
4808 }
4809 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004810 /* Disable default power save mode */
4811 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4812 /* Enable PS-Poll test mode */
4813 if (wpa_command(get_station_ifname(),
4814 "P2P_SET ps 97") < 0 ||
4815 wpa_command(get_station_ifname(),
4816 "P2P_SET ps 99") < 0)
4817 return -2;
4818 } else if (strcmp(val, "2") == 0 ||
4819 strcasecmp(val, "Fast") == 0) {
4820 /* TODO */
4821 send_resp(dut, conn, SIGMA_ERROR,
4822 "ErrorCode,Powersave=Fast not supported");
4823 return 0;
4824 } else if (strcmp(val, "3") == 0 ||
4825 strcasecmp(val, "PSNonPoll") == 0) {
4826 /* Make sure test modes are disabled */
4827 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4828 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4829
4830 /* Enable default power save mode */
4831 if (wpa_command(get_station_ifname(),
4832 "P2P_SET ps 1") < 0)
4833 return -2;
4834 } else
4835 return -1;
4836 }
4837
4838 val = get_param(cmd, "NoAck");
4839 if (val) {
4840 switch (get_driver_type()) {
4841 case DRIVER_ATHEROS:
4842 ath_sta_set_noack(dut, intf, val);
4843 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004844#ifdef NL80211_SUPPORT
4845 case DRIVER_WCN:
4846 wcn_sta_set_noack(dut, intf, val);
4847 break;
4848#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004849 default:
4850 send_resp(dut, conn, SIGMA_ERROR,
4851 "ErrorCode,Setting NoAck not supported");
4852 return 0;
4853 }
4854 }
4855
4856 val = get_param(cmd, "IgnoreChswitchProhibit");
4857 if (val) {
4858 /* TODO: Enabled/disabled */
4859 if (strcasecmp(val, "Enabled") == 0) {
4860 send_resp(dut, conn, SIGMA_ERROR,
4861 "ErrorCode,Enabling IgnoreChswitchProhibit "
4862 "not supported");
4863 return 0;
4864 }
4865 }
4866
4867 val = get_param(cmd, "TDLS");
4868 if (val) {
4869 if (strcasecmp(val, "Disabled") == 0) {
4870 if (wpa_command(intf, "SET tdls_disabled 1")) {
4871 send_resp(dut, conn, SIGMA_ERROR,
4872 "ErrorCode,Failed to disable TDLS");
4873 return 0;
4874 }
4875 } else if (strcasecmp(val, "Enabled") == 0) {
4876 if (wpa_command(intf, "SET tdls_disabled 0")) {
4877 send_resp(dut, conn, SIGMA_ERROR,
4878 "ErrorCode,Failed to enable TDLS");
4879 return 0;
4880 }
4881 } else {
4882 send_resp(dut, conn, SIGMA_ERROR,
4883 "ErrorCode,Unsupported TDLS value");
4884 return 0;
4885 }
4886 }
4887
4888 val = get_param(cmd, "TDLSmode");
4889 if (val) {
4890 if (strcasecmp(val, "Default") == 0) {
4891 wpa_command(intf, "SET tdls_testing 0");
4892 } else if (strcasecmp(val, "APProhibit") == 0) {
4893 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4894 send_resp(dut, conn, SIGMA_ERROR,
4895 "ErrorCode,Failed to enable ignore "
4896 "APProhibit TDLS mode");
4897 return 0;
4898 }
4899 } else if (strcasecmp(val, "HiLoMac") == 0) {
4900 /* STA should respond with TDLS setup req for a TDLS
4901 * setup req */
4902 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4903 send_resp(dut, conn, SIGMA_ERROR,
4904 "ErrorCode,Failed to enable HiLoMac "
4905 "TDLS mode");
4906 return 0;
4907 }
4908 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4909 /*
4910 * Since all security modes are enabled by default when
4911 * Sigma control is used, there is no need to do
4912 * anything here.
4913 */
4914 } else if (strcasecmp(val, "ExistLink") == 0) {
4915 /*
4916 * Since we allow new TDLS Setup Request even if there
4917 * is an existing link, nothing needs to be done for
4918 * this.
4919 */
4920 } else {
4921 /* TODO:
4922 * ExistLink: STA should send TDLS setup req even if
4923 * direct link already exists
4924 */
4925 send_resp(dut, conn, SIGMA_ERROR,
4926 "ErrorCode,Unsupported TDLSmode value");
4927 return 0;
4928 }
4929 }
4930
4931 val = get_param(cmd, "FakePubKey");
4932 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4933 send_resp(dut, conn, SIGMA_ERROR,
4934 "ErrorCode,Failed to enable FakePubKey");
4935 return 0;
4936 }
4937
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004938#ifdef NL80211_SUPPORT
4939 val = get_param(cmd, "FrgmntSupport");
4940 if (val) {
4941 if (strcasecmp(val, "Enable") == 0) {
4942 if (sta_set_he_fragmentation(dut, intf,
4943 HE_FRAG_LEVEL1)) {
4944 send_resp(dut, conn, SIGMA_ERROR,
4945 "ErrorCode,Failed to enable HE Fragmentation");
4946 return 0;
4947 }
4948 } else if (strcasecmp(val, "Disable") == 0) {
4949 if (sta_set_he_fragmentation(dut, intf,
4950 HE_FRAG_DISABLE)) {
4951 send_resp(dut, conn, SIGMA_ERROR,
4952 "ErrorCode,Failed to disable HE Fragmentation");
4953 return 0;
4954 }
4955 }
4956 }
4957#endif /* NL80211_SUPPORT */
4958
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004959 return 1;
4960}
4961
4962
4963static const char * ath_get_radio_name(const char *radio_name)
4964{
4965 if (radio_name == NULL)
4966 return "wifi0";
4967 if (strcmp(radio_name, "wifi1") == 0)
4968 return "wifi1";
4969 if (strcmp(radio_name, "wifi2") == 0)
4970 return "wifi2";
4971 return "wifi0";
4972}
4973
4974
4975static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4976 const char *val)
4977{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004978 unsigned int vht_mcsmap = 0;
4979 int txchainmask = 0;
4980 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4981
4982 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4983 if (dut->testbed_flag_txsp == 1) {
4984 vht_mcsmap = 0xfffc;
4985 dut->testbed_flag_txsp = 0;
4986 } else {
4987 vht_mcsmap = 0xfffe;
4988 }
4989 txchainmask = 1;
4990 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4991 if (dut->testbed_flag_txsp == 1) {
4992 vht_mcsmap = 0xfff0;
4993 dut->testbed_flag_txsp = 0;
4994 } else {
4995 vht_mcsmap = 0xfffa;
4996 }
4997 txchainmask = 3;
4998 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4999 if (dut->testbed_flag_txsp == 1) {
5000 vht_mcsmap = 0xffc0;
5001 dut->testbed_flag_txsp = 0;
5002 } else {
5003 vht_mcsmap = 0xffea;
5004 }
5005 txchainmask = 7;
5006 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5007 if (dut->testbed_flag_txsp == 1) {
5008 vht_mcsmap = 0xff00;
5009 dut->testbed_flag_txsp = 0;
5010 } else {
5011 vht_mcsmap = 0xffaa;
5012 }
5013 txchainmask = 15;
5014 } else {
5015 if (dut->testbed_flag_txsp == 1) {
5016 vht_mcsmap = 0xffc0;
5017 dut->testbed_flag_txsp = 0;
5018 } else {
5019 vht_mcsmap = 0xffea;
5020 }
5021 }
5022
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005023 if (txchainmask)
5024 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005025
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005026 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005027}
5028
5029
5030static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5031 const char *val)
5032{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005033 unsigned int vht_mcsmap = 0;
5034 int rxchainmask = 0;
5035 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5036
5037 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5038 if (dut->testbed_flag_rxsp == 1) {
5039 vht_mcsmap = 0xfffc;
5040 dut->testbed_flag_rxsp = 0;
5041 } else {
5042 vht_mcsmap = 0xfffe;
5043 }
5044 rxchainmask = 1;
5045 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5046 if (dut->testbed_flag_rxsp == 1) {
5047 vht_mcsmap = 0xfff0;
5048 dut->testbed_flag_rxsp = 0;
5049 } else {
5050 vht_mcsmap = 0xfffa;
5051 }
5052 rxchainmask = 3;
5053 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5054 if (dut->testbed_flag_rxsp == 1) {
5055 vht_mcsmap = 0xffc0;
5056 dut->testbed_flag_rxsp = 0;
5057 } else {
5058 vht_mcsmap = 0xffea;
5059 }
5060 rxchainmask = 7;
5061 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5062 if (dut->testbed_flag_rxsp == 1) {
5063 vht_mcsmap = 0xff00;
5064 dut->testbed_flag_rxsp = 0;
5065 } else {
5066 vht_mcsmap = 0xffaa;
5067 }
5068 rxchainmask = 15;
5069 } else {
5070 if (dut->testbed_flag_rxsp == 1) {
5071 vht_mcsmap = 0xffc0;
5072 dut->testbed_flag_rxsp = 0;
5073 } else {
5074 vht_mcsmap = 0xffea;
5075 }
5076 }
5077
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005078 if (rxchainmask)
5079 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005080
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005081 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005082}
5083
5084
5085void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5086{
5087 if (strcasecmp(val, "enable") == 0) {
5088 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5089 != 0) {
5090 sigma_dut_print(dut, DUT_MSG_ERROR,
5091 "Disable BB_VHTSIGB_CRC_CALC failed");
5092 }
5093
5094 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5095 != 0) {
5096 sigma_dut_print(dut, DUT_MSG_ERROR,
5097 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5098 }
5099 } else {
5100 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5101 != 0) {
5102 sigma_dut_print(dut, DUT_MSG_ERROR,
5103 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5104 }
5105
5106 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5107 != 0) {
5108 sigma_dut_print(dut, DUT_MSG_ERROR,
5109 "Enable BB_VHTSIGB_CRC_CALC failed");
5110 }
5111 }
5112}
5113
5114
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005115static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5116 const char *val)
5117{
5118 char buf[60];
5119
5120 if (strcmp(val, "20") == 0) {
5121 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5122 dut->chwidth = 0;
5123 } else if (strcmp(val, "40") == 0) {
5124 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5125 dut->chwidth = 1;
5126 } else if (strcmp(val, "80") == 0) {
5127 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5128 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305129 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005130 buf[0] = '\0';
5131 } else {
5132 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5133 val);
5134 return -1;
5135 }
5136
5137 if (buf[0] != '\0' && system(buf) != 0) {
5138 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5139 return -1;
5140 }
5141
5142 return 0;
5143}
5144
5145
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005146static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5147 const char *intf, int addbareject)
5148{
5149#ifdef NL80211_SUPPORT
5150 struct nl_msg *msg;
5151 int ret = 0;
5152 struct nlattr *params;
5153 int ifindex;
5154
5155 ifindex = if_nametoindex(intf);
5156 if (ifindex == 0) {
5157 sigma_dut_print(dut, DUT_MSG_ERROR,
5158 "%s: Index for interface %s failed",
5159 __func__, intf);
5160 return -1;
5161 }
5162
5163 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5164 NL80211_CMD_VENDOR)) ||
5165 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5166 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5167 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5168 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5169 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5170 nla_put_u8(msg,
5171 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5172 !addbareject)) {
5173 sigma_dut_print(dut, DUT_MSG_ERROR,
5174 "%s: err in adding vendor_cmd and vendor_data",
5175 __func__);
5176 nlmsg_free(msg);
5177 return -1;
5178 }
5179 nla_nest_end(msg, params);
5180
5181 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5182 if (ret) {
5183 sigma_dut_print(dut, DUT_MSG_ERROR,
5184 "%s: err in send_and_recv_msgs, ret=%d",
5185 __func__, ret);
5186 }
5187 return ret;
5188#else /* NL80211_SUPPORT */
5189 sigma_dut_print(dut, DUT_MSG_ERROR,
5190 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5191 return -1;
5192#endif /* NL80211_SUPPORT */
5193}
5194
5195
5196static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5197 int addbareject)
5198{
5199 int ret;
5200
5201 switch (get_driver_type()) {
5202 case DRIVER_WCN:
5203 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5204 if (ret) {
5205 sigma_dut_print(dut, DUT_MSG_ERROR,
5206 "nlvendor_sta_set_addba_reject failed, ret:%d",
5207 ret);
5208 return ret;
5209 }
5210 break;
5211 default:
5212 sigma_dut_print(dut, DUT_MSG_ERROR,
5213 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5214 ret = -1;
5215 break;
5216 }
5217
5218 return ret;
5219}
5220
5221
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005222static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5223 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005224{
5225#ifdef NL80211_SUPPORT
5226 struct nl_msg *msg;
5227 int ret = 0;
5228 struct nlattr *params;
5229 int ifindex;
5230
5231 ifindex = if_nametoindex(intf);
5232 if (ifindex == 0) {
5233 sigma_dut_print(dut, DUT_MSG_ERROR,
5234 "%s: Index for interface %s failed",
5235 __func__, intf);
5236 return -1;
5237 }
5238
5239 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5240 NL80211_CMD_VENDOR)) ||
5241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5242 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5243 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5244 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5245 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5246 nla_put_u8(msg,
5247 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005248 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005249 sigma_dut_print(dut, DUT_MSG_ERROR,
5250 "%s: err in adding vendor_cmd and vendor_data",
5251 __func__);
5252 nlmsg_free(msg);
5253 return -1;
5254 }
5255 nla_nest_end(msg, params);
5256
5257 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5258 if (ret) {
5259 sigma_dut_print(dut, DUT_MSG_ERROR,
5260 "%s: err in send_and_recv_msgs, ret=%d",
5261 __func__, ret);
5262 }
5263 return ret;
5264#else /* NL80211_SUPPORT */
5265 sigma_dut_print(dut, DUT_MSG_ERROR,
5266 "Disable addba not possible without NL80211_SUPPORT defined");
5267 return -1;
5268#endif /* NL80211_SUPPORT */
5269}
5270
5271
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305272#ifdef NL80211_SUPPORT
5273static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5274{
5275 struct nl_msg *msg;
5276 int ret = 0;
5277 int ifindex;
5278
5279 ifindex = if_nametoindex(intf);
5280 if (ifindex == 0) {
5281 sigma_dut_print(dut, DUT_MSG_ERROR,
5282 "%s: Index for interface %s failed",
5283 __func__, intf);
5284 return -1;
5285 }
5286
5287 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5288 NL80211_CMD_SET_WIPHY)) ||
5289 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5290 sigma_dut_print(dut, DUT_MSG_ERROR,
5291 "%s: err in adding RTS threshold",
5292 __func__);
5293 nlmsg_free(msg);
5294 return -1;
5295 }
5296
5297 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5298 if (ret) {
5299 sigma_dut_print(dut, DUT_MSG_ERROR,
5300 "%s: err in send_and_recv_msgs, ret=%d",
5301 __func__, ret);
5302 }
5303 return ret;
5304}
5305#endif /* NL80211_SUPPORT */
5306
5307
5308static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5309{
5310 char buf[100];
5311
5312#ifdef NL80211_SUPPORT
5313 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5314 return 0;
5315 sigma_dut_print(dut, DUT_MSG_DEBUG,
5316 "Fall back to using iwconfig for setting RTS threshold");
5317#endif /* NL80211_SUPPORT */
5318
5319 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5320 if (system(buf) != 0) {
5321 sigma_dut_print(dut, DUT_MSG_ERROR,
5322 "Failed to set RTS threshold %d", val);
5323 return -1;
5324 }
5325 return 0;
5326}
5327
5328
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005329static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5330 struct sigma_conn *conn,
5331 struct sigma_cmd *cmd)
5332{
5333 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005334 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005335 char buf[128];
5336 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005337
5338 val = get_param(cmd, "40_INTOLERANT");
5339 if (val) {
5340 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5341 /* TODO: iwpriv ht40intol through wpa_supplicant */
5342 send_resp(dut, conn, SIGMA_ERROR,
5343 "ErrorCode,40_INTOLERANT not supported");
5344 return 0;
5345 }
5346 }
5347
5348 val = get_param(cmd, "ADDBA_REJECT");
5349 if (val) {
5350 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5351 /* reject any ADDBA with status "decline" */
5352 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005353 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005354 } else {
5355 /* accept ADDBA */
5356 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005357 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005358 }
5359 }
5360
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005361 if (addbareject >= 0 &&
5362 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5363 send_resp(dut, conn, SIGMA_ERROR,
5364 "ErrorCode,set addba_reject failed");
5365 return 0;
5366 }
5367
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005368 val = get_param(cmd, "AMPDU");
5369 if (val) {
5370 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5371 /* enable AMPDU Aggregation */
5372 if (ampdu == 0) {
5373 send_resp(dut, conn, SIGMA_ERROR,
5374 "ErrorCode,Mismatch in "
5375 "addba_reject/ampdu - "
5376 "not supported");
5377 return 0;
5378 }
5379 ampdu = 1;
5380 } else {
5381 /* disable AMPDU Aggregation */
5382 if (ampdu == 1) {
5383 send_resp(dut, conn, SIGMA_ERROR,
5384 "ErrorCode,Mismatch in "
5385 "addba_reject/ampdu - "
5386 "not supported");
5387 return 0;
5388 }
5389 ampdu = 0;
5390 }
5391 }
5392
5393 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005394 int ret;
5395
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005396 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5397 ampdu ? "Enabling" : "Disabling");
5398 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005399 if (wpa_command(intf, buf) < 0 &&
5400 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005401 send_resp(dut, conn, SIGMA_ERROR,
5402 "ErrorCode,set aggr failed");
5403 return 0;
5404 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005405
5406 if (ampdu == 0) {
5407 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005408 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005409 if (ret) {
5410 sigma_dut_print(dut, DUT_MSG_ERROR,
5411 "Failed to disable addba, ret:%d",
5412 ret);
5413 }
5414 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005415 }
5416
5417 val = get_param(cmd, "AMSDU");
5418 if (val) {
5419 switch (get_driver_type()) {
5420 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005421 case DRIVER_WCN:
5422 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005423 break;
5424 default:
5425 if (strcmp(val, "1") == 0 ||
5426 strcasecmp(val, "Enable") == 0) {
5427 /* Enable AMSDU Aggregation */
5428 send_resp(dut, conn, SIGMA_ERROR,
5429 "ErrorCode,AMSDU aggregation not supported");
5430 return 0;
5431 }
5432 break;
5433 }
5434 }
5435
5436 val = get_param(cmd, "STBC_RX");
5437 if (val) {
5438 switch (get_driver_type()) {
5439 case DRIVER_ATHEROS:
5440 ath_sta_set_stbc(dut, intf, val);
5441 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305442 case DRIVER_WCN:
5443 wcn_sta_set_stbc(dut, intf, val);
5444 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005445 default:
5446 send_resp(dut, conn, SIGMA_ERROR,
5447 "ErrorCode,STBC_RX not supported");
5448 return 0;
5449 }
5450 }
5451
5452 val = get_param(cmd, "WIDTH");
5453 if (val) {
5454 switch (get_driver_type()) {
5455 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005456 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005457 send_resp(dut, conn, SIGMA_ERROR,
5458 "ErrorCode,Failed to set WIDTH");
5459 return 0;
5460 }
5461 break;
5462 case DRIVER_ATHEROS:
5463 if (ath_set_width(dut, conn, intf, val) < 0)
5464 return 0;
5465 break;
5466 default:
5467 sigma_dut_print(dut, DUT_MSG_ERROR,
5468 "Setting WIDTH not supported");
5469 break;
5470 }
5471 }
5472
5473 val = get_param(cmd, "SMPS");
5474 if (val) {
5475 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5476 send_resp(dut, conn, SIGMA_ERROR,
5477 "ErrorCode,SMPS not supported");
5478 return 0;
5479 }
5480
5481 val = get_param(cmd, "TXSP_STREAM");
5482 if (val) {
5483 switch (get_driver_type()) {
5484 case DRIVER_WCN:
5485 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5486 send_resp(dut, conn, SIGMA_ERROR,
5487 "ErrorCode,Failed to set TXSP_STREAM");
5488 return 0;
5489 }
5490 break;
5491 case DRIVER_ATHEROS:
5492 ath_sta_set_txsp_stream(dut, intf, val);
5493 break;
5494 default:
5495 sigma_dut_print(dut, DUT_MSG_ERROR,
5496 "Setting TXSP_STREAM not supported");
5497 break;
5498 }
5499 }
5500
5501 val = get_param(cmd, "RXSP_STREAM");
5502 if (val) {
5503 switch (get_driver_type()) {
5504 case DRIVER_WCN:
5505 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5506 send_resp(dut, conn, SIGMA_ERROR,
5507 "ErrorCode,Failed to set RXSP_STREAM");
5508 return 0;
5509 }
5510 break;
5511 case DRIVER_ATHEROS:
5512 ath_sta_set_rxsp_stream(dut, intf, val);
5513 break;
5514 default:
5515 sigma_dut_print(dut, DUT_MSG_ERROR,
5516 "Setting RXSP_STREAM not supported");
5517 break;
5518 }
5519 }
5520
5521 val = get_param(cmd, "DYN_BW_SGNL");
5522 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005523 switch (get_driver_type()) {
5524 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005525 if (strcasecmp(val, "enable") == 0) {
5526 snprintf(buf, sizeof(buf),
5527 "iwpriv %s cwmenable 1", intf);
5528 if (system(buf) != 0) {
5529 sigma_dut_print(dut, DUT_MSG_ERROR,
5530 "iwpriv cwmenable 1 failed");
5531 return 0;
5532 }
5533 } else if (strcasecmp(val, "disable") == 0) {
5534 snprintf(buf, sizeof(buf),
5535 "iwpriv %s cwmenable 0", intf);
5536 if (system(buf) != 0) {
5537 sigma_dut_print(dut, DUT_MSG_ERROR,
5538 "iwpriv cwmenable 0 failed");
5539 return 0;
5540 }
5541 } else {
5542 sigma_dut_print(dut, DUT_MSG_ERROR,
5543 "Unsupported DYN_BW_SGL");
5544 }
5545
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005546 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5547 if (system(buf) != 0) {
5548 sigma_dut_print(dut, DUT_MSG_ERROR,
5549 "Failed to set cts_cbw in DYN_BW_SGNL");
5550 return 0;
5551 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005552 break;
5553 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005554 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005555 ath_config_dyn_bw_sig(dut, intf, val);
5556 break;
5557 default:
5558 sigma_dut_print(dut, DUT_MSG_ERROR,
5559 "Failed to set DYN_BW_SGNL");
5560 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005561 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005562 }
5563
5564 val = get_param(cmd, "RTS_FORCE");
5565 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005566 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005567 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305568 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005569 sigma_dut_print(dut, DUT_MSG_ERROR,
5570 "Failed to set RTS_FORCE 64");
5571 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005572 res = snprintf(buf, sizeof(buf),
5573 "wifitool %s beeliner_fw_test 100 1",
5574 intf);
5575 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005576 sigma_dut_print(dut, DUT_MSG_ERROR,
5577 "wifitool beeliner_fw_test 100 1 failed");
5578 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005579 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305580 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005581 sigma_dut_print(dut, DUT_MSG_ERROR,
5582 "Failed to set RTS_FORCE 2347");
5583 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005584 } else {
5585 send_resp(dut, conn, SIGMA_ERROR,
5586 "ErrorCode,RTS_FORCE value not supported");
5587 return 0;
5588 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589 }
5590
5591 val = get_param(cmd, "CTS_WIDTH");
5592 if (val) {
5593 switch (get_driver_type()) {
5594 case DRIVER_WCN:
5595 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5596 send_resp(dut, conn, SIGMA_ERROR,
5597 "ErrorCode,Failed to set CTS_WIDTH");
5598 return 0;
5599 }
5600 break;
5601 case DRIVER_ATHEROS:
5602 ath_set_cts_width(dut, intf, val);
5603 break;
5604 default:
5605 sigma_dut_print(dut, DUT_MSG_ERROR,
5606 "Setting CTS_WIDTH not supported");
5607 break;
5608 }
5609 }
5610
5611 val = get_param(cmd, "BW_SGNL");
5612 if (val) {
5613 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005614 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005615 } else if (strcasecmp(val, "Disable") == 0) {
5616 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005617 } else {
5618 send_resp(dut, conn, SIGMA_ERROR,
5619 "ErrorCode,BW_SGNL value not supported");
5620 return 0;
5621 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005622 }
5623
5624 val = get_param(cmd, "Band");
5625 if (val) {
5626 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5627 /* STA supports all bands by default */
5628 } else {
5629 send_resp(dut, conn, SIGMA_ERROR,
5630 "ErrorCode,Unsupported Band");
5631 return 0;
5632 }
5633 }
5634
5635 val = get_param(cmd, "zero_crc");
5636 if (val) {
5637 switch (get_driver_type()) {
5638 case DRIVER_ATHEROS:
5639 ath_set_zero_crc(dut, val);
5640 break;
5641 default:
5642 break;
5643 }
5644 }
5645
5646 return 1;
5647}
5648
5649
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005650static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5651{
5652 switch (get_driver_type()) {
5653#ifdef __linux__
5654 case DRIVER_WIL6210:
5655 return wil6210_set_force_mcs(dut, force, mcs);
5656#endif /* __linux__ */
5657 default:
5658 sigma_dut_print(dut, DUT_MSG_ERROR,
5659 "Unsupported sta_set_force_mcs with the current driver");
5660 return -1;
5661 }
5662}
5663
5664
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005665static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5666{
5667 switch (get_driver_type()) {
5668#ifdef __linux__
5669 case DRIVER_WIL6210:
5670 return wil6210_force_rsn_ie(dut, state);
5671#endif /* __linux__ */
5672 default:
5673 sigma_dut_print(dut, DUT_MSG_ERROR,
5674 "Unsupported sta_60g_force_rsn_ie with the current driver");
5675 return -1;
5676 }
5677}
5678
5679
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005680static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5681 struct sigma_cmd *cmd)
5682{
5683 const char *val;
5684 char buf[100];
5685
5686 val = get_param(cmd, "MSDUSize");
5687 if (val) {
5688 int mtu;
5689
5690 dut->amsdu_size = atoi(val);
5691 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5692 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5693 sigma_dut_print(dut, DUT_MSG_ERROR,
5694 "MSDUSize %d is above max %d or below min %d",
5695 dut->amsdu_size,
5696 IEEE80211_MAX_DATA_LEN_DMG,
5697 IEEE80211_SNAP_LEN_DMG);
5698 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005699 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005700 }
5701
5702 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5703 sigma_dut_print(dut, DUT_MSG_DEBUG,
5704 "Setting amsdu_size to %d", mtu);
5705 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
5706 get_station_ifname(), mtu);
5707
5708 if (system(buf) != 0) {
5709 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5710 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005711 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005712 }
5713 }
5714
5715 val = get_param(cmd, "BAckRcvBuf");
5716 if (val) {
5717 dut->back_rcv_buf = atoi(val);
5718 if (dut->back_rcv_buf == 0) {
5719 sigma_dut_print(dut, DUT_MSG_ERROR,
5720 "Failed to convert %s or value is 0",
5721 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005722 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005723 }
5724
5725 sigma_dut_print(dut, DUT_MSG_DEBUG,
5726 "Setting BAckRcvBuf to %s", val);
5727 }
5728
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005729 val = get_param(cmd, "MCS_FixedRate");
5730 if (val) {
5731 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5732 sigma_dut_print(dut, DUT_MSG_ERROR,
5733 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005734 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005735 }
5736 }
5737
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005738 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005739}
5740
5741
5742static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5743 struct sigma_cmd *cmd)
5744{
5745 int net_id;
5746 char *ifname;
5747 const char *val;
5748 char buf[100];
5749
5750 dut->mode = SIGMA_MODE_STATION;
5751 ifname = get_main_ifname();
5752 if (wpa_command(ifname, "PING") != 0) {
5753 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005754 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005755 }
5756
5757 wpa_command(ifname, "FLUSH");
5758 net_id = add_network_common(dut, conn, ifname, cmd);
5759 if (net_id < 0) {
5760 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5761 return net_id;
5762 }
5763
5764 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5765 if (set_network(ifname, net_id, "mode", "2") < 0) {
5766 sigma_dut_print(dut, DUT_MSG_ERROR,
5767 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005768 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005769 }
5770
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005771 if (set_network(ifname, net_id, "pbss", "1") < 0)
5772 return -2;
5773
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005774 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005775 "Supplicant set network with mode 2. network_id %d",
5776 net_id);
5777
5778 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5779 sigma_dut_print(dut, DUT_MSG_INFO,
5780 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005781 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005782 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005783
5784 val = get_param(cmd, "Security");
5785 if (val && strcasecmp(val, "OPEN") == 0) {
5786 dut->ap_key_mgmt = AP_OPEN;
5787 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5788 sigma_dut_print(dut, DUT_MSG_ERROR,
5789 "Failed to set supplicant to %s security",
5790 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005791 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005792 }
5793 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5794 dut->ap_key_mgmt = AP_WPA2_PSK;
5795 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5796 sigma_dut_print(dut, DUT_MSG_ERROR,
5797 "Failed to set supplicant to %s security",
5798 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005799 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005800 }
5801
5802 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5803 sigma_dut_print(dut, DUT_MSG_ERROR,
5804 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005805 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005806 }
5807 } else if (val) {
5808 sigma_dut_print(dut, DUT_MSG_ERROR,
5809 "Requested Security %s is not supported on 60GHz",
5810 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005811 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005812 }
5813
5814 val = get_param(cmd, "Encrypt");
5815 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5816 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5817 sigma_dut_print(dut, DUT_MSG_ERROR,
5818 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005819 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005820 }
5821 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5822 sigma_dut_print(dut, DUT_MSG_ERROR,
5823 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005824 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005825 }
5826 } else if (val) {
5827 sigma_dut_print(dut, DUT_MSG_ERROR,
5828 "Requested Encrypt %s is not supported on 60 GHz",
5829 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005830 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005831 }
5832
5833 val = get_param(cmd, "PSK");
5834 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5835 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5836 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005837 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005838 }
5839
5840 /* Convert 60G channel to freq */
5841 switch (dut->ap_channel) {
5842 case 1:
5843 val = "58320";
5844 break;
5845 case 2:
5846 val = "60480";
5847 break;
5848 case 3:
5849 val = "62640";
5850 break;
5851 default:
5852 sigma_dut_print(dut, DUT_MSG_ERROR,
5853 "Failed to configure channel %d. Not supported",
5854 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005855 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005856 }
5857
5858 if (set_network(ifname, net_id, "frequency", val) < 0) {
5859 sigma_dut_print(dut, DUT_MSG_ERROR,
5860 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005861 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005862 }
5863
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005864 if (dut->eap_fragment) {
5865 sigma_dut_print(dut, DUT_MSG_DEBUG,
5866 "Set EAP fragment size to 128 bytes.");
5867 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
5868 return ERROR_SEND_STATUS;
5869 }
5870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005871 sigma_dut_print(dut, DUT_MSG_DEBUG,
5872 "Supplicant set network with frequency");
5873
5874 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5875 if (wpa_command(ifname, buf) < 0) {
5876 sigma_dut_print(dut, DUT_MSG_INFO,
5877 "Failed to select network id %d on %s",
5878 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005879 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005880 }
5881
5882 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5883
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005884 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005885}
5886
5887
Lior David67543f52017-01-03 19:04:22 +02005888static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5889{
5890 char buf[128], fname[128];
5891 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005892 int res;
Lior David67543f52017-01-03 19:04:22 +02005893
5894 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5895 sigma_dut_print(dut, DUT_MSG_ERROR,
5896 "failed to get wil6210 debugfs dir");
5897 return -1;
5898 }
5899
Jouni Malinen3aa72862019-05-29 23:14:51 +03005900 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5901 if (res < 0 || res >= sizeof(fname))
5902 return -1;
Lior David67543f52017-01-03 19:04:22 +02005903 f = fopen(fname, "w");
5904 if (!f) {
5905 sigma_dut_print(dut, DUT_MSG_ERROR,
5906 "failed to open: %s", fname);
5907 return -1;
5908 }
5909
5910 fprintf(f, "%d\n", abft_len);
5911 fclose(f);
5912
5913 return 0;
5914}
5915
5916
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02005917int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5918 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02005919{
5920 switch (get_driver_type()) {
5921 case DRIVER_WIL6210:
5922 return wil6210_set_abft_len(dut, abft_len);
5923 default:
5924 sigma_dut_print(dut, DUT_MSG_ERROR,
5925 "set abft_len not supported");
5926 return -1;
5927 }
5928}
5929
5930
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005931static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5932 struct sigma_cmd *cmd)
5933{
5934 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005935 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005936
5937 if (dut->dev_role != DEVROLE_PCP) {
5938 send_resp(dut, conn, SIGMA_INVALID,
5939 "ErrorCode,Invalid DevRole");
5940 return 0;
5941 }
5942
5943 val = get_param(cmd, "SSID");
5944 if (val) {
5945 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5946 send_resp(dut, conn, SIGMA_INVALID,
5947 "ErrorCode,Invalid SSID");
5948 return -1;
5949 }
5950
Peng Xub8fc5cc2017-05-10 17:27:28 -07005951 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005952 }
5953
5954 val = get_param(cmd, "CHANNEL");
5955 if (val) {
5956 const char *pos;
5957
5958 dut->ap_channel = atoi(val);
5959 pos = strchr(val, ';');
5960 if (pos) {
5961 pos++;
5962 dut->ap_channel_1 = atoi(pos);
5963 }
5964 }
5965
5966 switch (dut->ap_channel) {
5967 case 1:
5968 case 2:
5969 case 3:
5970 break;
5971 default:
5972 sigma_dut_print(dut, DUT_MSG_ERROR,
5973 "Channel %d is not supported", dut->ap_channel);
5974 send_resp(dut, conn, SIGMA_ERROR,
5975 "Requested channel is not supported");
5976 return -1;
5977 }
5978
5979 val = get_param(cmd, "BCNINT");
5980 if (val)
5981 dut->ap_bcnint = atoi(val);
5982
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005983 val = get_param(cmd, "AllocType");
5984 if (val) {
5985 send_resp(dut, conn, SIGMA_ERROR,
5986 "ErrorCode,AllocType is not supported yet");
5987 return -1;
5988 }
5989
5990 val = get_param(cmd, "PercentBI");
5991 if (val) {
5992 send_resp(dut, conn, SIGMA_ERROR,
5993 "ErrorCode,PercentBI is not supported yet");
5994 return -1;
5995 }
5996
5997 val = get_param(cmd, "CBAPOnly");
5998 if (val) {
5999 send_resp(dut, conn, SIGMA_ERROR,
6000 "ErrorCode,CBAPOnly is not supported yet");
6001 return -1;
6002 }
6003
6004 val = get_param(cmd, "AMPDU");
6005 if (val) {
6006 if (strcasecmp(val, "Enable") == 0)
6007 dut->ap_ampdu = 1;
6008 else if (strcasecmp(val, "Disable") == 0)
6009 dut->ap_ampdu = 2;
6010 else {
6011 send_resp(dut, conn, SIGMA_ERROR,
6012 "ErrorCode,AMPDU value is not Enable nor Disabled");
6013 return -1;
6014 }
6015 }
6016
6017 val = get_param(cmd, "AMSDU");
6018 if (val) {
6019 if (strcasecmp(val, "Enable") == 0)
6020 dut->ap_amsdu = 1;
6021 else if (strcasecmp(val, "Disable") == 0)
6022 dut->ap_amsdu = 2;
6023 }
6024
6025 val = get_param(cmd, "NumMSDU");
6026 if (val) {
6027 send_resp(dut, conn, SIGMA_ERROR,
6028 "ErrorCode, NumMSDU is not supported yet");
6029 return -1;
6030 }
6031
6032 val = get_param(cmd, "ABFTLRang");
6033 if (val) {
6034 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006035 "ABFTLRang parameter %s", val);
6036 if (strcmp(val, "Gt1") == 0)
6037 abft_len = 2; /* 2 slots in this case */
6038 }
6039
6040 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6041 send_resp(dut, conn, SIGMA_ERROR,
6042 "ErrorCode, Can't set ABFT length");
6043 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006044 }
6045
6046 if (sta_pcp_start(dut, conn, cmd) < 0) {
6047 send_resp(dut, conn, SIGMA_ERROR,
6048 "ErrorCode, Can't start PCP role");
6049 return -1;
6050 }
6051
6052 return sta_set_60g_common(dut, conn, cmd);
6053}
6054
6055
6056static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6057 struct sigma_cmd *cmd)
6058{
6059 const char *val = get_param(cmd, "DiscoveryMode");
6060
6061 if (dut->dev_role != DEVROLE_STA) {
6062 send_resp(dut, conn, SIGMA_INVALID,
6063 "ErrorCode,Invalid DevRole");
6064 return 0;
6065 }
6066
6067 if (val) {
6068 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6069 /* Ignore Discovery mode till Driver expose API. */
6070#if 0
6071 if (strcasecmp(val, "1") == 0) {
6072 send_resp(dut, conn, SIGMA_INVALID,
6073 "ErrorCode,DiscoveryMode 1 not supported");
6074 return 0;
6075 }
6076
6077 if (strcasecmp(val, "0") == 0) {
6078 /* OK */
6079 } else {
6080 send_resp(dut, conn, SIGMA_INVALID,
6081 "ErrorCode,DiscoveryMode not supported");
6082 return 0;
6083 }
6084#endif
6085 }
6086
6087 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006088 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006089 return sta_set_60g_common(dut, conn, cmd);
6090}
6091
6092
Jouni Malinenf7222712019-06-13 01:50:21 +03006093static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6094 struct sigma_conn *conn,
6095 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006096{
6097 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006098 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306099
Jouni Malinened77e672018-01-10 16:45:13 +02006100 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006101 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006102 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306103 wpa_command(intf, "DISCONNECT");
6104 return 1;
6105 }
6106
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006107 disconnect_station(dut);
6108 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6109 * due to cached results. */
6110 wpa_command(intf, "SET ignore_old_scan_res 1");
6111 wpa_command(intf, "BSS_FLUSH");
6112 return 1;
6113}
6114
6115
Jouni Malinenf7222712019-06-13 01:50:21 +03006116static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6117 struct sigma_conn *conn,
6118 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006119{
6120 const char *intf = get_param(cmd, "Interface");
6121 const char *bssid = get_param(cmd, "bssid");
6122 const char *val = get_param(cmd, "CHANNEL");
6123 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306124 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306125 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006126 int res;
6127 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05306128 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05306129 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006130
6131 if (bssid == NULL) {
6132 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6133 "argument");
6134 return 0;
6135 }
6136
6137 if (val)
6138 chan = atoi(val);
6139
6140 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6141 /* The current network may be from sta_associate or
6142 * sta_hs2_associate
6143 */
6144 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6145 0 ||
6146 set_network(intf, 0, "bssid", bssid) < 0)
6147 return -2;
6148 }
6149
6150 ctrl = open_wpa_mon(intf);
6151 if (ctrl == NULL) {
6152 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6153 "wpa_supplicant monitor connection");
6154 return -1;
6155 }
6156
Sunil Duttd30ce092018-01-11 23:56:29 +05306157 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6158 sizeof(result)) < 0 ||
6159 strncmp(result, "COMPLETED", 9) != 0) {
6160 sigma_dut_print(dut, DUT_MSG_DEBUG,
6161 "sta_reassoc: Not connected");
6162 fastreassoc = 0;
6163 }
6164
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306165 if (dut->rsne_override) {
6166#ifdef NL80211_SUPPORT
6167 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
6168 sta_config_rsnie(dut, 1);
6169 dut->config_rsnie = 1;
6170 }
6171#endif /* NL80211_SUPPORT */
6172 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6173 dut->rsne_override);
6174 if (wpa_command(intf, buf) < 0) {
6175 send_resp(dut, conn, SIGMA_ERROR,
6176 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6177 return 0;
6178 }
6179 }
6180
Sunil Duttd30ce092018-01-11 23:56:29 +05306181 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006182#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306183 if (chan) {
6184 unsigned int freq;
6185
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006186 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306187 if (!freq) {
6188 sigma_dut_print(dut, DUT_MSG_ERROR,
6189 "Invalid channel number provided: %d",
6190 chan);
6191 send_resp(dut, conn, SIGMA_INVALID,
6192 "ErrorCode,Invalid channel number");
6193 goto close_mon_conn;
6194 }
6195 res = snprintf(buf, sizeof(buf),
6196 "SCAN TYPE=ONLY freq=%d", freq);
6197 } else {
6198 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6199 }
6200 if (res < 0 || res >= (int) sizeof(buf)) {
6201 send_resp(dut, conn, SIGMA_ERROR,
6202 "ErrorCode,snprintf failed");
6203 goto close_mon_conn;
6204 }
6205 if (wpa_command(intf, buf) < 0) {
6206 sigma_dut_print(dut, DUT_MSG_INFO,
6207 "Failed to start scan");
6208 send_resp(dut, conn, SIGMA_ERROR,
6209 "ErrorCode,scan failed");
6210 goto close_mon_conn;
6211 }
6212
6213 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6214 buf, sizeof(buf));
6215 if (res < 0) {
6216 sigma_dut_print(dut, DUT_MSG_INFO,
6217 "Scan did not complete");
6218 send_resp(dut, conn, SIGMA_ERROR,
6219 "ErrorCode,scan did not complete");
6220 goto close_mon_conn;
6221 }
6222
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006223 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6224 < 0) {
6225 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6226 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306227 status = -2;
6228 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006229 }
6230 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6231 bssid, chan);
6232 if (res > 0 && res < (int) sizeof(buf))
6233 res = wpa_command(intf, buf);
6234
6235 if (res < 0 || res >= (int) sizeof(buf)) {
6236 send_resp(dut, conn, SIGMA_ERROR,
6237 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306238 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006239 }
6240#else /* ANDROID */
6241 sigma_dut_print(dut, DUT_MSG_DEBUG,
6242 "Reassoc using iwpriv - skip chan=%d info",
6243 chan);
6244 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
6245 if (system(buf) != 0) {
6246 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05306247 status = -2;
6248 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006249 }
6250#endif /* ANDROID */
6251 sigma_dut_print(dut, DUT_MSG_INFO,
6252 "sta_reassoc: Run %s successful", buf);
6253 } else if (wpa_command(intf, "REASSOCIATE")) {
6254 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6255 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306256 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 }
6258
6259 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6260 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306261 if (res < 0) {
6262 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
6263 status = -1;
6264 goto close_mon_conn;
6265 }
6266 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006267
Ashwini Patil467efef2017-05-25 12:18:27 +05306268close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006269 wpa_ctrl_detach(ctrl);
6270 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306271 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006272}
6273
6274
6275static void hs2_clear_credentials(const char *intf)
6276{
6277 wpa_command(intf, "REMOVE_CRED all");
6278}
6279
6280
Lior Davidcc88b562017-01-03 18:52:09 +02006281#ifdef __linux__
6282static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6283 unsigned int *aid)
6284{
Lior David0fe101e2017-03-09 16:09:50 +02006285 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006286
Lior David0fe101e2017-03-09 16:09:50 +02006287 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006288}
6289#endif /* __linux__ */
6290
6291
6292static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6293 unsigned int *aid)
6294{
6295 switch (get_driver_type()) {
6296#ifdef __linux__
6297 case DRIVER_WIL6210:
6298 return wil6210_get_aid(dut, bssid, aid);
6299#endif /* __linux__ */
6300 default:
6301 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6302 return -1;
6303 }
6304}
6305
6306
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006307static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6308 struct sigma_cmd *cmd)
6309{
6310 char buf[MAX_CMD_LEN];
6311 char bss_list[MAX_CMD_LEN];
6312 const char *parameter = get_param(cmd, "Parameter");
6313
6314 if (parameter == NULL)
6315 return -1;
6316
Lior Davidcc88b562017-01-03 18:52:09 +02006317 if (strcasecmp(parameter, "AID") == 0) {
6318 unsigned int aid = 0;
6319 char bssid[20];
6320
6321 if (get_wpa_status(get_station_ifname(), "bssid",
6322 bssid, sizeof(bssid)) < 0) {
6323 sigma_dut_print(dut, DUT_MSG_ERROR,
6324 "could not get bssid");
6325 return -2;
6326 }
6327
6328 if (sta_get_aid_60g(dut, bssid, &aid))
6329 return -2;
6330
6331 snprintf(buf, sizeof(buf), "aid,%d", aid);
6332 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6333 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6334 return 0;
6335 }
6336
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006337 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6338 char *bss_line;
6339 char *bss_id = NULL;
6340 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306341 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006342
6343 if (ifname == NULL) {
6344 sigma_dut_print(dut, DUT_MSG_INFO,
6345 "For get DiscoveredDevList need Interface name.");
6346 return -1;
6347 }
6348
6349 /*
6350 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6351 * of BSSIDs in "bssid=<BSSID>\n"
6352 */
6353 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6354 bss_list,
6355 sizeof(bss_list)) < 0) {
6356 sigma_dut_print(dut, DUT_MSG_ERROR,
6357 "Failed to get bss list");
6358 return -1;
6359 }
6360
6361 sigma_dut_print(dut, DUT_MSG_DEBUG,
6362 "bss list for ifname:%s is:%s",
6363 ifname, bss_list);
6364
6365 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306366 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006367 while (bss_line) {
6368 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6369 bss_id) {
6370 int len;
6371
6372 len = snprintf(buf + strlen(buf),
6373 sizeof(buf) - strlen(buf),
6374 ",%s", bss_id);
6375 free(bss_id);
6376 bss_id = NULL;
6377 if (len < 0) {
6378 sigma_dut_print(dut,
6379 DUT_MSG_ERROR,
6380 "Failed to read BSSID");
6381 send_resp(dut, conn, SIGMA_ERROR,
6382 "ErrorCode,Failed to read BSS ID");
6383 return 0;
6384 }
6385
6386 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6387 sigma_dut_print(dut,
6388 DUT_MSG_ERROR,
6389 "Response buf too small for list");
6390 send_resp(dut, conn,
6391 SIGMA_ERROR,
6392 "ErrorCode,Response buf too small for list");
6393 return 0;
6394 }
6395 }
6396
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306397 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006398 }
6399
6400 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6401 buf);
6402 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6403 return 0;
6404 }
6405
6406 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6407 return 0;
6408}
6409
6410
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006411static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6412 struct sigma_cmd *cmd)
6413{
6414 char buf[MAX_CMD_LEN];
6415 const char *parameter = get_param(cmd, "Parameter");
6416
6417 if (!parameter)
6418 return -1;
6419
6420 if (strcasecmp(parameter, "RSSI") == 0) {
6421 char rssi[10];
6422
6423 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
6424 rssi, sizeof(rssi)) < 0) {
6425 sigma_dut_print(dut, DUT_MSG_ERROR,
6426 "Could not get RSSI");
6427 return -2;
6428 }
6429
6430 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6431 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6432 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6433 return 0;
6434 }
6435
6436 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6437 return 0;
6438}
6439
6440
Jouni Malinenf7222712019-06-13 01:50:21 +03006441static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6442 struct sigma_conn *conn,
6443 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006444{
6445 const char *program = get_param(cmd, "Program");
6446
6447 if (program == NULL)
6448 return -1;
6449
6450 if (strcasecmp(program, "P2PNFC") == 0)
6451 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6452
6453 if (strcasecmp(program, "60ghz") == 0)
6454 return sta_get_parameter_60g(dut, conn, cmd);
6455
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006456 if (strcasecmp(program, "he") == 0)
6457 return sta_get_parameter_he(dut, conn, cmd);
6458
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006459#ifdef ANDROID_NAN
6460 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006461 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006462#endif /* ANDROID_NAN */
6463
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006464#ifdef MIRACAST
6465 if (strcasecmp(program, "WFD") == 0 ||
6466 strcasecmp(program, "DisplayR2") == 0)
6467 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6468#endif /* MIRACAST */
6469
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006470 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6471 return 0;
6472}
6473
6474
6475static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6476 const char *type)
6477{
6478 char buf[100];
6479
6480 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006481 run_iwpriv(dut, intf, "chwidth 2");
6482 run_iwpriv(dut, intf, "mode 11ACVHT80");
6483 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006484 }
6485
6486 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006487 run_iwpriv(dut, intf, "chwidth 0");
6488 run_iwpriv(dut, intf, "mode 11naht40");
6489 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006490 }
6491
6492 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006493 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006494
6495 /* Reset CTS width */
6496 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6497 intf);
6498 if (system(buf) != 0) {
6499 sigma_dut_print(dut, DUT_MSG_ERROR,
6500 "wifitool %s beeliner_fw_test 54 0 failed",
6501 intf);
6502 }
6503
6504 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006505 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006506
6507 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6508 if (system(buf) != 0) {
6509 sigma_dut_print(dut, DUT_MSG_ERROR,
6510 "iwpriv rts failed");
6511 }
6512 }
6513
6514 if (type && strcasecmp(type, "Testbed") == 0) {
6515 dut->testbed_flag_txsp = 1;
6516 dut->testbed_flag_rxsp = 1;
6517 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006518 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006519
6520 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006521 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006522
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006523 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006524
6525 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006526 run_iwpriv(dut, intf, "tx_stbc 0");
6527 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006528
6529 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006530 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006531 }
6532
6533 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006534 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006535 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006536
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006537 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006538 }
6539}
6540
6541
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006542#ifdef NL80211_SUPPORT
6543static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6544 enum he_mcs_config mcs)
6545{
6546 struct nl_msg *msg;
6547 int ret = 0;
6548 struct nlattr *params;
6549 int ifindex;
6550
6551 ifindex = if_nametoindex(intf);
6552 if (ifindex == 0) {
6553 sigma_dut_print(dut, DUT_MSG_ERROR,
6554 "%s: Index for interface %s failed",
6555 __func__, intf);
6556 return -1;
6557 }
6558
6559 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6560 NL80211_CMD_VENDOR)) ||
6561 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6562 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6563 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6564 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6565 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6566 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6567 mcs)) {
6568 sigma_dut_print(dut, DUT_MSG_ERROR,
6569 "%s: err in adding vendor_cmd and vendor_data",
6570 __func__);
6571 nlmsg_free(msg);
6572 return -1;
6573 }
6574 nla_nest_end(msg, params);
6575
6576 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6577 if (ret) {
6578 sigma_dut_print(dut, DUT_MSG_ERROR,
6579 "%s: err in send_and_recv_msgs, ret=%d",
6580 __func__, ret);
6581 }
6582 return ret;
6583}
6584#endif /* NL80211_SUPPORT */
6585
6586
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006587static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6588 const char *intf, int enable)
6589{
6590#ifdef NL80211_SUPPORT
6591 struct nl_msg *msg;
6592 int ret = 0;
6593 struct nlattr *params;
6594 int ifindex;
6595
6596 ifindex = if_nametoindex(intf);
6597 if (ifindex == 0) {
6598 sigma_dut_print(dut, DUT_MSG_ERROR,
6599 "%s: Index for interface %s failed",
6600 __func__, intf);
6601 return -1;
6602 }
6603
6604 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6605 NL80211_CMD_VENDOR)) ||
6606 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6607 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6608 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6609 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6610 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6611 nla_put_u8(msg,
6612 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6613 enable)) {
6614 sigma_dut_print(dut, DUT_MSG_ERROR,
6615 "%s: err in adding vendor_cmd and vendor_data",
6616 __func__);
6617 nlmsg_free(msg);
6618 return -1;
6619 }
6620 nla_nest_end(msg, params);
6621
6622 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6623 if (ret) {
6624 sigma_dut_print(dut, DUT_MSG_ERROR,
6625 "%s: err in send_and_recv_msgs, ret=%d",
6626 __func__, ret);
6627 }
6628 return ret;
6629#else /* NL80211_SUPPORT */
6630 sigma_dut_print(dut, DUT_MSG_ERROR,
6631 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6632 return -1;
6633#endif /* NL80211_SUPPORT */
6634}
6635
6636
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006637static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6638 const char *intf, int enable)
6639{
6640#ifdef NL80211_SUPPORT
6641 struct nl_msg *msg;
6642 int ret = 0;
6643 struct nlattr *params;
6644 int ifindex;
6645
6646 ifindex = if_nametoindex(intf);
6647 if (ifindex == 0) {
6648 sigma_dut_print(dut, DUT_MSG_ERROR,
6649 "%s: Index for interface %s failed",
6650 __func__, intf);
6651 return -1;
6652 }
6653
6654 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6655 NL80211_CMD_VENDOR)) ||
6656 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6657 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6658 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6659 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6660 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6661 nla_put_u8(msg,
6662 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6663 enable)) {
6664 sigma_dut_print(dut, DUT_MSG_ERROR,
6665 "%s: err in adding vendor_cmd and vendor_data",
6666 __func__);
6667 nlmsg_free(msg);
6668 return -1;
6669 }
6670 nla_nest_end(msg, params);
6671
6672 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6673 if (ret) {
6674 sigma_dut_print(dut, DUT_MSG_ERROR,
6675 "%s: err in send_and_recv_msgs, ret=%d",
6676 __func__, ret);
6677 }
6678 return ret;
6679#else /* NL80211_SUPPORT */
6680 sigma_dut_print(dut, DUT_MSG_ERROR,
6681 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6682 return -1;
6683#endif /* NL80211_SUPPORT */
6684}
6685
6686
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006687#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006688
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006689static int sta_set_he_testbed_def(struct sigma_dut *dut,
6690 const char *intf, int cfg)
6691{
6692 struct nl_msg *msg;
6693 int ret = 0;
6694 struct nlattr *params;
6695 int ifindex;
6696
6697 ifindex = if_nametoindex(intf);
6698 if (ifindex == 0) {
6699 sigma_dut_print(dut, DUT_MSG_ERROR,
6700 "%s: Index for interface %s failed",
6701 __func__, intf);
6702 return -1;
6703 }
6704
6705 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6706 NL80211_CMD_VENDOR)) ||
6707 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6708 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6709 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6710 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6711 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6712 nla_put_u8(msg,
6713 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6714 cfg)) {
6715 sigma_dut_print(dut, DUT_MSG_ERROR,
6716 "%s: err in adding vendor_cmd and vendor_data",
6717 __func__);
6718 nlmsg_free(msg);
6719 return -1;
6720 }
6721 nla_nest_end(msg, params);
6722
6723 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6724 if (ret) {
6725 sigma_dut_print(dut, DUT_MSG_ERROR,
6726 "%s: err in send_and_recv_msgs, ret=%d",
6727 __func__, ret);
6728 }
6729 return ret;
6730}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006731
6732
6733static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
6734{
6735 struct nl_msg *msg;
6736 int ret = 0;
6737 struct nlattr *params;
6738 int ifindex;
6739
6740 ifindex = if_nametoindex(intf);
6741 if (ifindex == 0) {
6742 sigma_dut_print(dut, DUT_MSG_ERROR,
6743 "%s: Index for interface %s failed",
6744 __func__, intf);
6745 return -1;
6746 }
6747
6748 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6749 NL80211_CMD_VENDOR)) ||
6750 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6751 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6752 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6753 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6754 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6755 nla_put_u8(msg,
6756 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
6757 cfg)) {
6758 sigma_dut_print(dut, DUT_MSG_ERROR,
6759 "%s: err in adding vendor_cmd and vendor_data",
6760 __func__);
6761 nlmsg_free(msg);
6762 return -1;
6763 }
6764 nla_nest_end(msg, params);
6765
6766 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6767 if (ret) {
6768 sigma_dut_print(dut, DUT_MSG_ERROR,
6769 "%s: err in send_and_recv_msgs, ret=%d",
6770 __func__, ret);
6771 }
6772 return ret;
6773}
6774
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006775#endif /* NL80211_SUPPORT */
6776
6777
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006778static int sta_set_addba_buf_size(struct sigma_dut *dut,
6779 const char *intf, int bufsize)
6780{
6781#ifdef NL80211_SUPPORT
6782 struct nl_msg *msg;
6783 int ret = 0;
6784 struct nlattr *params;
6785 int ifindex;
6786
6787 ifindex = if_nametoindex(intf);
6788 if (ifindex == 0) {
6789 sigma_dut_print(dut, DUT_MSG_ERROR,
6790 "%s: Index for interface %s failed",
6791 __func__, intf);
6792 return -1;
6793 }
6794
6795 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6796 NL80211_CMD_VENDOR)) ||
6797 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6798 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6799 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6800 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6801 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006802 nla_put_u16(msg,
6803 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6804 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006805 sigma_dut_print(dut, DUT_MSG_ERROR,
6806 "%s: err in adding vendor_cmd and vendor_data",
6807 __func__);
6808 nlmsg_free(msg);
6809 return -1;
6810 }
6811 nla_nest_end(msg, params);
6812
6813 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6814 if (ret) {
6815 sigma_dut_print(dut, DUT_MSG_ERROR,
6816 "%s: err in send_and_recv_msgs, ret=%d",
6817 __func__, ret);
6818 }
6819 return ret;
6820#else /* NL80211_SUPPORT */
6821 sigma_dut_print(dut, DUT_MSG_ERROR,
6822 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6823 return -1;
6824#endif /* NL80211_SUPPORT */
6825}
6826
6827
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006828static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6829 int enable)
6830{
6831#ifdef NL80211_SUPPORT
6832 struct nl_msg *msg;
6833 int ret = 0;
6834 struct nlattr *params;
6835 int ifindex;
6836
6837 ifindex = if_nametoindex(intf);
6838 if (ifindex == 0) {
6839 sigma_dut_print(dut, DUT_MSG_ERROR,
6840 "%s: Index for interface %s failed",
6841 __func__, intf);
6842 return -1;
6843 }
6844
6845 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6846 NL80211_CMD_VENDOR)) ||
6847 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6848 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6849 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6850 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6851 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6852 nla_put_u8(msg,
6853 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
6854 enable)) {
6855 sigma_dut_print(dut, DUT_MSG_ERROR,
6856 "%s: err in adding vendor_cmd and vendor_data",
6857 __func__);
6858 nlmsg_free(msg);
6859 return -1;
6860 }
6861 nla_nest_end(msg, params);
6862
6863 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6864 if (ret) {
6865 sigma_dut_print(dut, DUT_MSG_ERROR,
6866 "%s: err in send_and_recv_msgs, ret=%d",
6867 __func__, ret);
6868 }
6869 return ret;
6870#else /* NL80211_SUPPORT */
6871 sigma_dut_print(dut, DUT_MSG_ERROR,
6872 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
6873 return -1;
6874#endif /* NL80211_SUPPORT */
6875}
6876
6877
Arif Hussain9765f7d2018-07-03 08:28:26 -07006878static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
6879 int val)
6880{
6881#ifdef NL80211_SUPPORT
6882 struct nl_msg *msg;
6883 int ret = 0;
6884 struct nlattr *params;
6885 int ifindex;
6886
6887 ifindex = if_nametoindex(intf);
6888 if (ifindex == 0) {
6889 sigma_dut_print(dut, DUT_MSG_ERROR,
6890 "%s: Index for interface %s failed, val:%d",
6891 __func__, intf, val);
6892 return -1;
6893 }
6894
6895 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6896 NL80211_CMD_VENDOR)) ||
6897 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6898 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6899 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6900 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6901 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6902 nla_put_u8(msg,
6903 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
6904 val)) {
6905 sigma_dut_print(dut, DUT_MSG_ERROR,
6906 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6907 __func__, val);
6908 nlmsg_free(msg);
6909 return -1;
6910 }
6911 nla_nest_end(msg, params);
6912
6913 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6914 if (ret) {
6915 sigma_dut_print(dut, DUT_MSG_ERROR,
6916 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6917 __func__, ret, val);
6918 }
6919 return ret;
6920#else /* NL80211_SUPPORT */
6921 sigma_dut_print(dut, DUT_MSG_ERROR,
6922 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
6923 return -1;
6924#endif /* NL80211_SUPPORT */
6925}
6926
6927
Arif Hussain68d23f52018-07-11 13:39:08 -07006928#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006929static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
6930 enum qca_wlan_he_mac_padding_dur val)
6931{
Arif Hussain68d23f52018-07-11 13:39:08 -07006932 struct nl_msg *msg;
6933 int ret = 0;
6934 struct nlattr *params;
6935 int ifindex;
6936
6937 ifindex = if_nametoindex(intf);
6938 if (ifindex == 0) {
6939 sigma_dut_print(dut, DUT_MSG_ERROR,
6940 "%s: Index for interface %s failed, val:%d",
6941 __func__, intf, val);
6942 return -1;
6943 }
6944
6945 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6946 NL80211_CMD_VENDOR)) ||
6947 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6948 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6949 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6950 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6951 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6952 nla_put_u8(msg,
6953 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
6954 val)) {
6955 sigma_dut_print(dut, DUT_MSG_ERROR,
6956 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6957 __func__, val);
6958 nlmsg_free(msg);
6959 return -1;
6960 }
6961 nla_nest_end(msg, params);
6962
6963 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6964 if (ret) {
6965 sigma_dut_print(dut, DUT_MSG_ERROR,
6966 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6967 __func__, ret, val);
6968 }
6969 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07006970}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006971#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07006972
6973
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006974static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
6975 int val)
6976{
6977#ifdef NL80211_SUPPORT
6978 struct nl_msg *msg;
6979 int ret = 0;
6980 struct nlattr *params;
6981 int ifindex;
6982
6983 ifindex = if_nametoindex(intf);
6984 if (ifindex == 0) {
6985 sigma_dut_print(dut, DUT_MSG_ERROR,
6986 "%s: Index for interface %s failed, val:%d",
6987 __func__, intf, val);
6988 return -1;
6989 }
6990
6991 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6992 NL80211_CMD_VENDOR)) ||
6993 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6994 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6995 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6996 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6997 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6998 nla_put_u8(msg,
6999 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7000 val)) {
7001 sigma_dut_print(dut, DUT_MSG_ERROR,
7002 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7003 __func__, val);
7004 nlmsg_free(msg);
7005 return -1;
7006 }
7007 nla_nest_end(msg, params);
7008
7009 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7010 if (ret) {
7011 sigma_dut_print(dut, DUT_MSG_ERROR,
7012 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7013 __func__, ret, val);
7014 }
7015 return ret;
7016#else /* NL80211_SUPPORT */
7017 sigma_dut_print(dut, DUT_MSG_ERROR,
7018 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7019 return -1;
7020#endif /* NL80211_SUPPORT */
7021}
7022
7023
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007024#ifdef NL80211_SUPPORT
7025static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7026{
7027 struct nl_msg *msg;
7028 int ret = 0;
7029 struct nlattr *params;
7030 int ifindex;
7031
7032 ifindex = if_nametoindex(intf);
7033 if (ifindex == 0) {
7034 sigma_dut_print(dut, DUT_MSG_ERROR,
7035 "%s: Index for interface %s failed",
7036 __func__, intf);
7037 return -1;
7038 }
7039
7040 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7041 NL80211_CMD_VENDOR)) ||
7042 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7043 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7044 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7045 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7046 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7047 nla_put_flag(msg,
7048 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7049 sigma_dut_print(dut, DUT_MSG_ERROR,
7050 "%s: err in adding vendor_cmd and vendor_data",
7051 __func__);
7052 nlmsg_free(msg);
7053 return -1;
7054 }
7055 nla_nest_end(msg, params);
7056
7057 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7058 if (ret) {
7059 sigma_dut_print(dut, DUT_MSG_ERROR,
7060 "%s: err in send_and_recv_msgs, ret=%d",
7061 __func__, ret);
7062 }
7063 return ret;
7064}
7065#endif /* NL80211_SUPPORT */
7066
7067
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007068static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7069 int val)
7070{
7071#ifdef NL80211_SUPPORT
7072 struct nl_msg *msg;
7073 int ret = 0;
7074 struct nlattr *params;
7075 int ifindex;
7076
7077 ifindex = if_nametoindex(intf);
7078 if (ifindex == 0) {
7079 sigma_dut_print(dut, DUT_MSG_ERROR,
7080 "%s: Index for interface %s failed, val:%d",
7081 __func__, intf, val);
7082 return -1;
7083 }
7084
7085 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7086 NL80211_CMD_VENDOR)) ||
7087 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7088 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7089 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7090 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7091 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7092 nla_put_u8(msg,
7093 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7094 val)) {
7095 sigma_dut_print(dut, DUT_MSG_ERROR,
7096 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7097 __func__, val);
7098 nlmsg_free(msg);
7099 return -1;
7100 }
7101 nla_nest_end(msg, params);
7102
7103 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7104 if (ret) {
7105 sigma_dut_print(dut, DUT_MSG_ERROR,
7106 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7107 __func__, ret, val);
7108 }
7109 return ret;
7110#else /* NL80211_SUPPORT */
7111 sigma_dut_print(dut, DUT_MSG_ERROR,
7112 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7113 return -1;
7114#endif /* NL80211_SUPPORT */
7115}
7116
7117
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007118static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7119 int val)
7120{
7121#ifdef NL80211_SUPPORT
7122 struct nl_msg *msg;
7123 int ret = 0;
7124 struct nlattr *params;
7125 int ifindex;
7126
7127 ifindex = if_nametoindex(intf);
7128 if (ifindex == 0) {
7129 sigma_dut_print(dut, DUT_MSG_ERROR,
7130 "%s: Index for interface %s failed, val:%d",
7131 __func__, intf, val);
7132 return -1;
7133 }
7134
7135 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7136 NL80211_CMD_VENDOR)) ||
7137 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7138 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7139 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7140 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7141 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7142 nla_put_u8(msg,
7143 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7144 val)) {
7145 sigma_dut_print(dut, DUT_MSG_ERROR,
7146 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7147 __func__, val);
7148 nlmsg_free(msg);
7149 return -1;
7150 }
7151 nla_nest_end(msg, params);
7152
7153 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7154 if (ret) {
7155 sigma_dut_print(dut, DUT_MSG_ERROR,
7156 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7157 __func__, ret, val);
7158 }
7159 return ret;
7160#else /* NL80211_SUPPORT */
7161 sigma_dut_print(dut, DUT_MSG_ERROR,
7162 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7163 return -1;
7164#endif /* NL80211_SUPPORT */
7165}
7166
7167
Arif Hussain480d5f42019-03-12 14:40:42 -07007168static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7169 int val)
7170{
7171#ifdef NL80211_SUPPORT
7172 struct nl_msg *msg;
7173 int ret;
7174 struct nlattr *params;
7175 int ifindex;
7176
7177 ifindex = if_nametoindex(intf);
7178 if (ifindex == 0) {
7179 sigma_dut_print(dut, DUT_MSG_ERROR,
7180 "%s: Index for interface %s failed, val:%d",
7181 __func__, intf, val);
7182 return -1;
7183 }
7184
7185 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7186 NL80211_CMD_VENDOR)) ||
7187 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7188 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7189 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7190 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7191 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7192 nla_put_u8(msg,
7193 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7194 val)) {
7195 sigma_dut_print(dut, DUT_MSG_ERROR,
7196 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7197 __func__, val);
7198 nlmsg_free(msg);
7199 return -1;
7200 }
7201 nla_nest_end(msg, params);
7202
7203 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7204 if (ret) {
7205 sigma_dut_print(dut, DUT_MSG_ERROR,
7206 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7207 __func__, ret, val);
7208 }
7209 return ret;
7210#else /* NL80211_SUPPORT */
7211 sigma_dut_print(dut, DUT_MSG_ERROR,
7212 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7213 return -1;
7214#endif /* NL80211_SUPPORT */
7215}
7216
7217
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007218static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7219 const char *type)
7220{
7221 char buf[60];
7222
7223 if (dut->program == PROGRAM_HE) {
7224 /* resetting phymode to auto in case of HE program */
7225 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7226 if (system(buf) != 0) {
7227 sigma_dut_print(dut, DUT_MSG_ERROR,
7228 "iwpriv %s setphymode failed", intf);
7229 }
7230
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007231 /* reset the rate to Auto rate */
7232 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7233 intf);
7234 if (system(buf) != 0) {
7235 sigma_dut_print(dut, DUT_MSG_ERROR,
7236 "iwpriv %s set_11ax_rate 0xff failed",
7237 intf);
7238 }
7239
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007240 /* reset the LDPC setting */
7241 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7242 if (system(buf) != 0) {
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "iwpriv %s ldpc 1 failed", intf);
7245 }
7246
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007247 /* reset the power save setting */
7248 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7249 if (system(buf) != 0) {
7250 sigma_dut_print(dut, DUT_MSG_ERROR,
7251 "iwpriv %s setPower 2 failed", intf);
7252 }
7253
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007254 /* remove all network profiles */
7255 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007256
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007257 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7258 sta_set_addba_buf_size(dut, intf, 64);
7259
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007260#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007261 /* Reset the device HE capabilities to its default supported
7262 * configuration. */
7263 sta_set_he_testbed_def(dut, intf, 0);
7264
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007265 /* Disable noackpolicy for all AC */
7266 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7267 sigma_dut_print(dut, DUT_MSG_ERROR,
7268 "Disable of noackpolicy for all AC failed");
7269 }
7270#endif /* NL80211_SUPPORT */
7271
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007272 /* Enable WMM by default */
7273 if (wcn_sta_set_wmm(dut, intf, "on")) {
7274 sigma_dut_print(dut, DUT_MSG_ERROR,
7275 "Enable of WMM in sta_reset_default_wcn failed");
7276 }
7277
7278 /* Disable ADDBA_REJECT by default */
7279 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7280 sigma_dut_print(dut, DUT_MSG_ERROR,
7281 "Disable of addba_reject in sta_reset_default_wcn failed");
7282 }
7283
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007284 /* Enable sending of ADDBA by default */
7285 if (nlvendor_config_send_addba(dut, intf, 1)) {
7286 sigma_dut_print(dut, DUT_MSG_ERROR,
7287 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7288 }
7289
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007290 /* Enable AMPDU by default */
7291 iwpriv_sta_set_ampdu(dut, intf, 1);
7292
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007293#ifdef NL80211_SUPPORT
7294 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
7295 sigma_dut_print(dut, DUT_MSG_ERROR,
7296 "Set LTF config to default in sta_reset_default_wcn failed");
7297 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007298
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007299 /* set the beamformee NSTS(maximum number of
7300 * space-time streams) to default DUT config
7301 */
7302 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007303 sigma_dut_print(dut, DUT_MSG_ERROR,
7304 "Failed to set BeamformeeSTS");
7305 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007306
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007307 if (sta_set_mac_padding_duration(
7308 dut, intf,
7309 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007310 sigma_dut_print(dut, DUT_MSG_ERROR,
7311 "Failed to set MAC padding duration");
7312 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007313
7314 if (sta_set_mu_edca_override(dut, intf, 0)) {
7315 sigma_dut_print(dut, DUT_MSG_ERROR,
7316 "ErrorCode,Failed to set MU EDCA override disable");
7317 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007318
7319 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7320 sigma_dut_print(dut, DUT_MSG_ERROR,
7321 "Failed to set OM ctrl supp");
7322 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007323
7324 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7325 sigma_dut_print(dut, DUT_MSG_ERROR,
7326 "Failed to set Tx SU PPDU enable");
7327 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007328
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007329 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7330 sigma_dut_print(dut, DUT_MSG_ERROR,
7331 "failed to send TB PPDU Tx cfg");
7332 }
7333
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007334 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7335 sigma_dut_print(dut, DUT_MSG_ERROR,
7336 "Failed to set OM ctrl reset");
7337 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007338
7339 /* +HTC-HE support default on */
7340 if (sta_set_he_htc_supp(dut, intf, 1)) {
7341 sigma_dut_print(dut, DUT_MSG_ERROR,
7342 "Setting of +HTC-HE support failed");
7343 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007344#endif /* NL80211_SUPPORT */
7345
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007346 if (sta_set_tx_beamformee(dut, intf, 1)) {
7347 sigma_dut_print(dut, DUT_MSG_ERROR,
7348 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7349 }
7350
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007351 /* Set nss to 1 and MCS 0-7 in case of testbed */
7352 if (type && strcasecmp(type, "Testbed") == 0) {
7353#ifdef NL80211_SUPPORT
7354 int ret;
7355#endif /* NL80211_SUPPORT */
7356
7357 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7358 if (system(buf) != 0) {
7359 sigma_dut_print(dut, DUT_MSG_ERROR,
7360 "iwpriv %s nss failed", intf);
7361 }
7362
7363#ifdef NL80211_SUPPORT
7364 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7365 if (ret) {
7366 sigma_dut_print(dut, DUT_MSG_ERROR,
7367 "Setting of MCS failed, ret:%d",
7368 ret);
7369 }
7370#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007371
7372 /* Disable STBC as default */
7373 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007374
7375 /* Disable AMSDU as default */
7376 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007377
7378#ifdef NL80211_SUPPORT
7379 /* HE fragmentation default off */
7380 if (sta_set_he_fragmentation(dut, intf,
7381 HE_FRAG_DISABLE)) {
7382 sigma_dut_print(dut, DUT_MSG_ERROR,
7383 "Setting of HE fragmentation failed");
7384 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007385
7386 /* set the beamformee NSTS(maximum number of
7387 * space-time streams) to default testbed config
7388 */
7389 if (sta_set_beamformee_sts(dut, intf, 3)) {
7390 sigma_dut_print(dut, DUT_MSG_ERROR,
7391 "Failed to set BeamformeeSTS");
7392 }
7393
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007394 /* +HTC-HE support default off */
7395 if (sta_set_he_htc_supp(dut, intf, 0)) {
7396 sigma_dut_print(dut, DUT_MSG_ERROR,
7397 "Setting of +HTC-HE support failed");
7398 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007399
7400 /* Set device HE capabilities to testbed default
7401 * configuration. */
7402 if (sta_set_he_testbed_def(dut, intf, 1)) {
7403 sigma_dut_print(dut, DUT_MSG_DEBUG,
7404 "Failed to set HE defaults");
7405 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007406
7407 /* Disable VHT support in 2.4 GHz for testbed */
7408 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007409#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007410
7411 /* Enable WEP/TKIP with HE capability in testbed */
7412 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7413 sigma_dut_print(dut, DUT_MSG_ERROR,
7414 "Enabling HE config with WEP/TKIP failed");
7415 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007416 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007417
7418 /* Defaults in case of DUT */
7419 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007420 /* Enable STBC by default */
7421 wcn_sta_set_stbc(dut, intf, "1");
7422
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007423 /* set nss to 2 */
7424 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7425 if (system(buf) != 0) {
7426 sigma_dut_print(dut, DUT_MSG_ERROR,
7427 "iwpriv %s nss 2 failed", intf);
7428 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007429 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007430
7431#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007432 /* Set HE_MCS to 0-11 */
7433 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007434 sigma_dut_print(dut, DUT_MSG_ERROR,
7435 "Setting of MCS failed");
7436 }
7437#endif /* NL80211_SUPPORT */
7438
7439 /* Disable WEP/TKIP with HE capability in DUT */
7440 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7441 sigma_dut_print(dut, DUT_MSG_ERROR,
7442 "Enabling HE config with WEP/TKIP failed");
7443 }
7444 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007445 }
7446}
7447
7448
Jouni Malinenf7222712019-06-13 01:50:21 +03007449static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7450 struct sigma_conn *conn,
7451 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007452{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007453 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007454 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007455 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007456 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307457 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007458
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007459 if (!program)
7460 program = get_param(cmd, "prog");
7461 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007462 dut->device_type = STA_unknown;
7463 type = get_param(cmd, "type");
7464 if (type && strcasecmp(type, "Testbed") == 0)
7465 dut->device_type = STA_testbed;
7466 if (type && strcasecmp(type, "DUT") == 0)
7467 dut->device_type = STA_dut;
7468
7469 if (dut->program == PROGRAM_TDLS) {
7470 /* Clear TDLS testing mode */
7471 wpa_command(intf, "SET tdls_disabled 0");
7472 wpa_command(intf, "SET tdls_testing 0");
7473 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307474 if (get_driver_type() == DRIVER_WCN) {
7475 /* Enable the WCN driver in TDLS Explicit trigger mode
7476 */
7477 wpa_command(intf, "SET tdls_external_control 0");
7478 wpa_command(intf, "SET tdls_trigger_control 0");
7479 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007480 }
7481
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007482#ifdef MIRACAST
7483 if (dut->program == PROGRAM_WFD ||
7484 dut->program == PROGRAM_DISPLAYR2)
7485 miracast_sta_reset_default(dut, conn, cmd);
7486#endif /* MIRACAST */
7487
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007488 switch (get_driver_type()) {
7489 case DRIVER_ATHEROS:
7490 sta_reset_default_ath(dut, intf, type);
7491 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007492 case DRIVER_WCN:
7493 sta_reset_default_wcn(dut, intf, type);
7494 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007495 default:
7496 break;
7497 }
7498
7499#ifdef ANDROID_NAN
7500 if (dut->program == PROGRAM_NAN)
7501 nan_cmd_sta_reset_default(dut, conn, cmd);
7502#endif /* ANDROID_NAN */
7503
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307504 if (dut->program == PROGRAM_LOC &&
7505 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7506 return ERROR_SEND_STATUS;
7507
Jouni Malinenba630452018-06-22 11:49:59 +03007508 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007509 unlink("SP/wi-fi.org/pps.xml");
7510 if (system("rm -r SP/*") != 0) {
7511 }
7512 unlink("next-client-cert.pem");
7513 unlink("next-client-key.pem");
7514 }
7515
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007516 /* For WPS program of the 60 GHz band the band type needs to be saved */
7517 if (dut->program == PROGRAM_WPS) {
7518 if (band && strcasecmp(band, "60GHz") == 0) {
7519 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007520 /* For 60 GHz enable WPS for WPS TCs */
7521 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007522 } else {
7523 dut->band = WPS_BAND_NON_60G;
7524 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007525 } else if (dut->program == PROGRAM_60GHZ) {
7526 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7527 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007528 }
7529
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007530 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007531 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007532 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007533
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007534 sigma_dut_print(dut, DUT_MSG_INFO,
7535 "WPS 60 GHz program, wps_disable = %d",
7536 dut->wps_disable);
7537
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007538 if (!dev_role) {
7539 send_resp(dut, conn, SIGMA_ERROR,
7540 "errorCode,Missing DevRole argument");
7541 return 0;
7542 }
7543
7544 if (strcasecmp(dev_role, "STA") == 0)
7545 dut->dev_role = DEVROLE_STA;
7546 else if (strcasecmp(dev_role, "PCP") == 0)
7547 dut->dev_role = DEVROLE_PCP;
7548 else {
7549 send_resp(dut, conn, SIGMA_ERROR,
7550 "errorCode,Unknown DevRole");
7551 return 0;
7552 }
7553
7554 if (dut->device_type == STA_unknown) {
7555 sigma_dut_print(dut, DUT_MSG_ERROR,
7556 "Device type is not STA testbed or DUT");
7557 send_resp(dut, conn, SIGMA_ERROR,
7558 "errorCode,Unknown device type");
7559 return 0;
7560 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007561
7562 sigma_dut_print(dut, DUT_MSG_DEBUG,
7563 "Setting msdu_size to MAX: 7912");
7564 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
7565 get_station_ifname());
7566
7567 if (system(buf) != 0) {
7568 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7569 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007570 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007571 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007572
7573 if (sta_set_force_mcs(dut, 0, 1)) {
7574 sigma_dut_print(dut, DUT_MSG_ERROR,
7575 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007576 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007577 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007578 }
7579
7580 wpa_command(intf, "WPS_ER_STOP");
7581 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307582 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007583 wpa_command(intf, "SET radio_disabled 0");
7584
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007585 dut->wps_forced_version = 0;
7586
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007587 if (dut->wsc_fragment) {
7588 dut->wsc_fragment = 0;
7589 wpa_command(intf, "SET device_name Test client");
7590 wpa_command(intf, "SET manufacturer ");
7591 wpa_command(intf, "SET model_name ");
7592 wpa_command(intf, "SET model_number ");
7593 wpa_command(intf, "SET serial_number ");
7594 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007595 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7596 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7597 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7598 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007599
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007600 if (dut->tmp_mac_addr && dut->set_macaddr) {
7601 dut->tmp_mac_addr = 0;
7602 if (system(dut->set_macaddr) != 0) {
7603 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7604 "temporary MAC address");
7605 }
7606 }
7607
7608 set_ps(intf, dut, 0);
7609
Jouni Malinenba630452018-06-22 11:49:59 +03007610 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7611 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007612 wpa_command(intf, "SET interworking 1");
7613 wpa_command(intf, "SET hs20 1");
7614 }
7615
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007616 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007617 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007618 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007619 wpa_command(intf, "SET pmf 1");
7620 } else {
7621 wpa_command(intf, "SET pmf 0");
7622 }
7623
7624 hs2_clear_credentials(intf);
7625 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7626 wpa_command(intf, "SET access_network_type 15");
7627
7628 static_ip_file(0, NULL, NULL, NULL);
7629 kill_dhcp_client(dut, intf);
7630 clear_ip_addr(dut, intf);
7631
7632 dut->er_oper_performed = 0;
7633 dut->er_oper_bssid[0] = '\0';
7634
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007635 if (dut->program == PROGRAM_LOC) {
7636 /* Disable Interworking by default */
7637 wpa_command(get_station_ifname(), "SET interworking 0");
7638 }
7639
Ashwini Patil00402582017-04-13 12:29:39 +05307640 if (dut->program == PROGRAM_MBO) {
7641 free(dut->non_pref_ch_list);
7642 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307643 free(dut->btm_query_cand_list);
7644 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307645 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307646 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307647 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307648 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307649 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307650 }
7651
Jouni Malinen3c367e82017-06-23 17:01:47 +03007652 free(dut->rsne_override);
7653 dut->rsne_override = NULL;
7654
Jouni Malinen68143132017-09-02 02:34:08 +03007655 free(dut->sae_commit_override);
7656 dut->sae_commit_override = NULL;
7657
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007658 dut->sta_associate_wait_connect = 0;
7659 dut->server_cert_hash[0] = '\0';
7660 dut->sta_tod_policy = 0;
7661
Jouni Malinend86e5822017-08-29 03:55:32 +03007662 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007663 free(dut->dpp_peer_uri);
7664 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007665 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007666 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007667
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007668 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7669
vamsi krishnaa2799492017-12-05 14:28:01 +05307670 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307671 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307672 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307673 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7674 dut->fils_hlp = 0;
7675#ifdef ANDROID
7676 hlp_thread_cleanup(dut);
7677#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307678 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307679
Jouni Malinen8179fee2019-03-28 03:19:47 +02007680 dut->akm_values = 0;
7681
Sunil Dutt076081f2018-02-05 19:45:50 +05307682#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05307683 if (get_driver_type() == DRIVER_WCN &&
7684 dut->config_rsnie == 1) {
7685 dut->config_rsnie = 0;
7686 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307687 }
7688#endif /* NL80211_SUPPORT */
7689
Sunil Duttfebf8a82018-02-09 18:50:13 +05307690 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7691 dut->dev_role = DEVROLE_STA_CFON;
7692 return sta_cfon_reset_default(dut, conn, cmd);
7693 }
7694
Jouni Malinen439352d2018-09-13 03:42:23 +03007695 wpa_command(intf, "SET setband AUTO");
7696
Sunil Duttfebf8a82018-02-09 18:50:13 +05307697 if (dut->program != PROGRAM_VHT)
7698 return cmd_sta_p2p_reset(dut, conn, cmd);
7699
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007700 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007701}
7702
7703
Jouni Malinenf7222712019-06-13 01:50:21 +03007704static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7705 struct sigma_conn *conn,
7706 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007707{
7708 const char *program = get_param(cmd, "Program");
7709
7710 if (program == NULL)
7711 return -1;
7712#ifdef ANDROID_NAN
7713 if (strcasecmp(program, "NAN") == 0)
7714 return nan_cmd_sta_get_events(dut, conn, cmd);
7715#endif /* ANDROID_NAN */
7716 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7717 return 0;
7718}
7719
7720
Jouni Malinen82905202018-04-29 17:20:10 +03007721static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7722 struct sigma_cmd *cmd)
7723{
7724 const char *url = get_param(cmd, "url");
7725 const char *method = get_param(cmd, "method");
7726 pid_t pid;
7727 int status;
7728
7729 if (!url || !method)
7730 return -1;
7731
7732 /* TODO: Add support for method,post */
7733 if (strcasecmp(method, "get") != 0) {
7734 send_resp(dut, conn, SIGMA_ERROR,
7735 "ErrorCode,Unsupported method");
7736 return 0;
7737 }
7738
7739 pid = fork();
7740 if (pid < 0) {
7741 perror("fork");
7742 return -1;
7743 }
7744
7745 if (pid == 0) {
7746 char * argv[5] = { "wget", "-O", "/dev/null",
7747 (char *) url, NULL };
7748
7749 execv("/usr/bin/wget", argv);
7750 perror("execv");
7751 exit(0);
7752 return -1;
7753 }
7754
7755 if (waitpid(pid, &status, 0) < 0) {
7756 perror("waitpid");
7757 return -1;
7758 }
7759
7760 if (WIFEXITED(status)) {
7761 const char *errmsg;
7762
7763 if (WEXITSTATUS(status) == 0)
7764 return 1;
7765 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7766 WEXITSTATUS(status));
7767 switch (WEXITSTATUS(status)) {
7768 case 4:
7769 errmsg = "errmsg,Network failure";
7770 break;
7771 case 8:
7772 errmsg = "errmsg,Server issued an error response";
7773 break;
7774 default:
7775 errmsg = "errmsg,Unknown failure from wget";
7776 break;
7777 }
7778 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7779 return 0;
7780 }
7781
7782 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7783 return 0;
7784}
7785
7786
Jouni Malinenf7222712019-06-13 01:50:21 +03007787static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7788 struct sigma_conn *conn,
7789 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007790{
7791 const char *program = get_param(cmd, "Prog");
7792
Jouni Malinen82905202018-04-29 17:20:10 +03007793 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007794 return -1;
7795#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007796 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007797 return nan_cmd_sta_exec_action(dut, conn, cmd);
7798#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007799
7800 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007801 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007802
7803 if (get_param(cmd, "url"))
7804 return sta_exec_action_url(dut, conn, cmd);
7805
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007806 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7807 return 0;
7808}
7809
7810
Jouni Malinenf7222712019-06-13 01:50:21 +03007811static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7812 struct sigma_conn *conn,
7813 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007814{
7815 const char *intf = get_param(cmd, "Interface");
7816 const char *val, *mcs32, *rate;
7817
7818 val = get_param(cmd, "GREENFIELD");
7819 if (val) {
7820 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7821 /* Enable GD */
7822 send_resp(dut, conn, SIGMA_ERROR,
7823 "ErrorCode,GF not supported");
7824 return 0;
7825 }
7826 }
7827
7828 val = get_param(cmd, "SGI20");
7829 if (val) {
7830 switch (get_driver_type()) {
7831 case DRIVER_ATHEROS:
7832 ath_sta_set_sgi(dut, intf, val);
7833 break;
7834 default:
7835 send_resp(dut, conn, SIGMA_ERROR,
7836 "ErrorCode,SGI20 not supported");
7837 return 0;
7838 }
7839 }
7840
7841 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7842 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7843 if (mcs32 && rate) {
7844 /* TODO */
7845 send_resp(dut, conn, SIGMA_ERROR,
7846 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7847 return 0;
7848 } else if (mcs32 && !rate) {
7849 /* TODO */
7850 send_resp(dut, conn, SIGMA_ERROR,
7851 "ErrorCode,MCS32 not supported");
7852 return 0;
7853 } else if (!mcs32 && rate) {
7854 switch (get_driver_type()) {
7855 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08007856 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007857 ath_sta_set_11nrates(dut, intf, rate);
7858 break;
7859 default:
7860 send_resp(dut, conn, SIGMA_ERROR,
7861 "ErrorCode,MCS32_FIXEDRATE not supported");
7862 return 0;
7863 }
7864 }
7865
7866 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7867}
7868
7869
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007870static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
7871 int mcs_config)
7872{
7873#ifdef NL80211_SUPPORT
7874 int ret;
7875
7876 switch (mcs_config) {
7877 case HE_80_MCS0_7:
7878 case HE_80_MCS0_9:
7879 case HE_80_MCS0_11:
7880 ret = sta_set_he_mcs(dut, intf, mcs_config);
7881 if (ret) {
7882 sigma_dut_print(dut, DUT_MSG_ERROR,
7883 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
7884 mcs_config, ret);
7885 }
7886 break;
7887 default:
7888 sigma_dut_print(dut, DUT_MSG_ERROR,
7889 "cmd_set_max_he_mcs: Invalid mcs %d",
7890 mcs_config);
7891 break;
7892 }
7893#else /* NL80211_SUPPORT */
7894 sigma_dut_print(dut, DUT_MSG_ERROR,
7895 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
7896#endif /* NL80211_SUPPORT */
7897}
7898
7899
Arif Hussain480d5f42019-03-12 14:40:42 -07007900static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
7901 struct sigma_cmd *cmd)
7902{
7903#ifdef NL80211_SUPPORT
7904 struct nlattr *params;
7905 struct nlattr *attr;
7906 struct nlattr *attr1;
7907 struct nl_msg *msg;
7908 int ifindex, ret;
7909 const char *val;
7910 const char *intf = get_param(cmd, "Interface");
7911 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
7912 wake_interval_mantissa = 512;
7913 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
7914 protection = 0;
7915
7916 ifindex = if_nametoindex(intf);
7917 if (ifindex == 0) {
7918 sigma_dut_print(dut, DUT_MSG_ERROR,
7919 "%s: Index for interface %s failed",
7920 __func__, intf);
7921 return -1;
7922 }
7923
7924 val = get_param(cmd, "FlowType");
7925 if (val) {
7926 flow_type = atoi(val);
7927 if (flow_type != 0 && flow_type != 1) {
7928 sigma_dut_print(dut, DUT_MSG_ERROR,
7929 "TWT: Invalid FlowType %d", flow_type);
7930 return -1;
7931 }
7932 }
7933
7934 val = get_param(cmd, "TWT_Trigger");
7935 if (val) {
7936 twt_trigger = atoi(val);
7937 if (twt_trigger != 0 && twt_trigger != 1) {
7938 sigma_dut_print(dut, DUT_MSG_ERROR,
7939 "TWT: Invalid TWT_Trigger %d",
7940 twt_trigger);
7941 return -1;
7942 }
7943 }
7944
7945 val = get_param(cmd, "Protection");
7946 if (val) {
7947 protection = atoi(val);
7948 if (protection != 0 && protection != 1) {
7949 sigma_dut_print(dut, DUT_MSG_ERROR,
7950 "TWT: Invalid Protection %d",
7951 protection);
7952 return -1;
7953 }
7954 }
7955
7956 val = get_param(cmd, "TargetWakeTime");
7957 if (val)
7958 target_wake_time = atoi(val);
7959
7960 val = get_param(cmd, "WakeIntervalMantissa");
7961 if (val)
7962 wake_interval_mantissa = atoi(val);
7963
7964 val = get_param(cmd, "WakeIntervalExp");
7965 if (val)
7966 wake_interval_exp = atoi(val);
7967
7968 val = get_param(cmd, "NominalMinWakeDur");
7969 if (val)
7970 nominal_min_wake_dur = atoi(val);
7971
7972 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7973 NL80211_CMD_VENDOR)) ||
7974 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7975 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7976 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7977 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7978 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7979 !(params = nla_nest_start(
7980 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
7981 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7982 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
7983 wake_interval_exp) ||
7984 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST, 0) ||
7985 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
7986 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER,
7987 twt_trigger) ||
7988 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
7989 flow_type) ||
7990 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION,
7991 protection) ||
7992 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
7993 target_wake_time) ||
7994 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
7995 nominal_min_wake_dur) ||
7996 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
7997 wake_interval_mantissa)) {
7998 sigma_dut_print(dut, DUT_MSG_ERROR,
7999 "%s: err in adding vendor_cmd and vendor_data",
8000 __func__);
8001 nlmsg_free(msg);
8002 return -1;
8003 }
8004 nla_nest_end(msg, attr1);
8005 nla_nest_end(msg, params);
8006 nla_nest_end(msg, attr);
8007
8008 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8009 if (ret) {
8010 sigma_dut_print(dut, DUT_MSG_ERROR,
8011 "%s: err in send_and_recv_msgs, ret=%d",
8012 __func__, ret);
8013 }
8014
8015 return ret;
8016#else /* NL80211_SUPPORT */
8017 sigma_dut_print(dut, DUT_MSG_ERROR,
8018 "TWT request cannot be done without NL80211_SUPPORT defined");
8019 return -1;
8020#endif /* NL80211_SUPPORT */
8021}
8022
8023
8024static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8025 struct sigma_cmd *cmd)
8026{
8027 #ifdef NL80211_SUPPORT
8028 struct nlattr *params;
8029 struct nlattr *attr;
8030 struct nlattr *attr1;
8031 int ifindex, ret;
8032 struct nl_msg *msg;
8033 const char *intf = get_param(cmd, "Interface");
8034
8035 ifindex = if_nametoindex(intf);
8036 if (ifindex == 0) {
8037 sigma_dut_print(dut, DUT_MSG_ERROR,
8038 "%s: Index for interface %s failed",
8039 __func__, intf);
8040 return -1;
8041 }
8042
8043 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8044 NL80211_CMD_VENDOR)) ||
8045 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8046 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8047 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8048 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8049 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8050 !(params = nla_nest_start(
8051 msg,
8052 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8053 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8054 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8055 sigma_dut_print(dut, DUT_MSG_ERROR,
8056 "%s: err in adding vendor_cmd and vendor_data",
8057 __func__);
8058 nlmsg_free(msg);
8059 return -1;
8060 }
8061 nla_nest_end(msg, attr1);
8062 nla_nest_end(msg, params);
8063 nla_nest_end(msg, attr);
8064
8065 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8066 if (ret) {
8067 sigma_dut_print(dut, DUT_MSG_ERROR,
8068 "%s: err in send_and_recv_msgs, ret=%d",
8069 __func__, ret);
8070 }
8071
8072 return ret;
8073#else /* NL80211_SUPPORT */
8074 sigma_dut_print(dut, DUT_MSG_ERROR,
8075 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8076 return -1;
8077#endif /* NL80211_SUPPORT */
8078}
8079
8080
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008081static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8082 struct sigma_cmd *cmd)
8083{
8084#ifdef NL80211_SUPPORT
8085 struct nlattr *params;
8086 struct nlattr *attr;
8087 struct nlattr *attr1;
8088 struct nl_msg *msg;
8089 int ifindex, ret;
8090 const char *val;
8091 const char *intf = get_param(cmd, "Interface");
8092 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8093 ulmu_data_dis = 0;
8094
8095 ifindex = if_nametoindex(intf);
8096 if (ifindex == 0) {
8097 sigma_dut_print(dut, DUT_MSG_ERROR,
8098 "%s: Index for interface %s failed",
8099 __func__, intf);
8100 return -1;
8101 }
8102 val = get_param(cmd, "OMCtrl_RxNSS");
8103 if (val)
8104 rx_nss = atoi(val);
8105
8106 val = get_param(cmd, "OMCtrl_ChnlWidth");
8107 if (val)
8108 ch_bw = atoi(val);
8109
8110 val = get_param(cmd, "OMCtrl_ULMUDisable");
8111 if (val)
8112 ulmu_dis = atoi(val);
8113
8114 val = get_param(cmd, "OMCtrl_TxNSTS");
8115 if (val)
8116 tx_nsts = atoi(val);
8117
8118 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8119 if (val)
8120 ulmu_data_dis = atoi(val);
8121
8122 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8123 NL80211_CMD_VENDOR)) ||
8124 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8125 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8126 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8127 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8128 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8129 !(params = nla_nest_start(
8130 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8131 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8132 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8133 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8134 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8135 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8136 ulmu_data_dis) ||
8137 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8138 ulmu_dis)) {
8139 sigma_dut_print(dut, DUT_MSG_ERROR,
8140 "%s: err in adding vendor_cmd and vendor_data",
8141 __func__);
8142 nlmsg_free(msg);
8143 return -1;
8144 }
8145 nla_nest_end(msg, attr1);
8146 nla_nest_end(msg, params);
8147 nla_nest_end(msg, attr);
8148
8149 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8150 if (ret) {
8151 sigma_dut_print(dut, DUT_MSG_ERROR,
8152 "%s: err in send_and_recv_msgs, ret=%d",
8153 __func__, ret);
8154 }
8155
8156 return ret;
8157#else /* NL80211_SUPPORT */
8158 sigma_dut_print(dut, DUT_MSG_ERROR,
8159 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8160 return -1;
8161#endif /* NL80211_SUPPORT */
8162}
8163
8164
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008165static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8166 struct sigma_conn *conn,
8167 struct sigma_cmd *cmd)
8168{
8169 const char *intf = get_param(cmd, "Interface");
8170 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008171 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008172 int tkip = -1;
8173 int wep = -1;
8174
Arif Hussaina37e9552018-06-20 17:05:59 -07008175 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008176 val = get_param(cmd, "SGI80");
8177 if (val) {
8178 int sgi80;
8179
8180 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008181 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008182 }
8183
8184 val = get_param(cmd, "TxBF");
8185 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008186 switch (get_driver_type()) {
8187 case DRIVER_WCN:
8188 if (sta_set_tx_beamformee(dut, intf, 1)) {
8189 send_resp(dut, conn, SIGMA_ERROR,
8190 "ErrorCode,Failed to set TX beamformee enable");
8191 return 0;
8192 }
8193 break;
8194 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008195 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008196 send_resp(dut, conn, SIGMA_ERROR,
8197 "ErrorCode,Setting vhtsubfee failed");
8198 return 0;
8199 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008200 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008201 send_resp(dut, conn, SIGMA_ERROR,
8202 "ErrorCode,Setting vhtsubfer failed");
8203 return 0;
8204 }
8205 break;
8206 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008207 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008208 "Unsupported driver type");
8209 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008210 }
8211 }
8212
8213 val = get_param(cmd, "MU_TxBF");
8214 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
8215 switch (get_driver_type()) {
8216 case DRIVER_ATHEROS:
8217 ath_sta_set_txsp_stream(dut, intf, "1SS");
8218 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008219 run_iwpriv(dut, intf, "vhtmubfee 1");
8220 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308221 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008222 case DRIVER_WCN:
8223 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8224 send_resp(dut, conn, SIGMA_ERROR,
8225 "ErrorCode,Failed to set RX/TXSP_STREAM");
8226 return 0;
8227 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308228 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008229 default:
8230 sigma_dut_print(dut, DUT_MSG_ERROR,
8231 "Setting SP_STREAM not supported");
8232 break;
8233 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008234 }
8235
8236 val = get_param(cmd, "LDPC");
8237 if (val) {
8238 int ldpc;
8239
8240 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008241 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008242 }
8243
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008244 val = get_param(cmd, "BCC");
8245 if (val) {
8246 int bcc;
8247
8248 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8249 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8250 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008251 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008252 }
8253
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008254 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8255 if (val && dut->sta_nss == 1)
8256 cmd_set_max_he_mcs(dut, intf, atoi(val));
8257
8258 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8259 if (val && dut->sta_nss == 2)
8260 cmd_set_max_he_mcs(dut, intf, atoi(val));
8261
Arif Hussainac6c5112018-05-25 17:34:00 -07008262 val = get_param(cmd, "MCS_FixedRate");
8263 if (val) {
8264#ifdef NL80211_SUPPORT
8265 int mcs, ratecode = 0;
8266 enum he_mcs_config mcs_config;
8267 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008268 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008269
8270 ratecode = (0x07 & dut->sta_nss) << 5;
8271 mcs = atoi(val);
8272 /* Add the MCS to the ratecode */
8273 if (mcs >= 0 && mcs <= 11) {
8274 ratecode += mcs;
8275 if (dut->device_type == STA_testbed &&
8276 mcs > 7 && mcs <= 11) {
8277 if (mcs <= 9)
8278 mcs_config = HE_80_MCS0_9;
8279 else
8280 mcs_config = HE_80_MCS0_11;
8281 ret = sta_set_he_mcs(dut, intf, mcs_config);
8282 if (ret) {
8283 sigma_dut_print(dut, DUT_MSG_ERROR,
8284 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8285 mcs, mcs_config, ret);
8286 }
8287 }
8288 snprintf(buf, sizeof(buf),
8289 "iwpriv %s set_11ax_rate 0x%03x",
8290 intf, ratecode);
8291 if (system(buf) != 0) {
8292 sigma_dut_print(dut, DUT_MSG_ERROR,
8293 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8294 ratecode);
8295 }
8296 } else {
8297 sigma_dut_print(dut, DUT_MSG_ERROR,
8298 "MCS_FixedRate: HE MCS %d not supported",
8299 mcs);
8300 }
8301#else /* NL80211_SUPPORT */
8302 sigma_dut_print(dut, DUT_MSG_ERROR,
8303 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8304#endif /* NL80211_SUPPORT */
8305 }
8306
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008307 val = get_param(cmd, "opt_md_notif_ie");
8308 if (val) {
8309 char *result = NULL;
8310 char delim[] = ";";
8311 char token[30];
8312 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308313 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008314
Peng Xub8fc5cc2017-05-10 17:27:28 -07008315 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308316 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008317
8318 /* Extract the NSS information */
8319 if (result) {
8320 value = atoi(result);
8321 switch (value) {
8322 case 1:
8323 config_val = 1;
8324 break;
8325 case 2:
8326 config_val = 3;
8327 break;
8328 case 3:
8329 config_val = 7;
8330 break;
8331 case 4:
8332 config_val = 15;
8333 break;
8334 default:
8335 config_val = 3;
8336 break;
8337 }
8338
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008339 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8340 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008341
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008342 }
8343
8344 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308345 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008346 if (result) {
8347 value = atoi(result);
8348 switch (value) {
8349 case 20:
8350 config_val = 0;
8351 break;
8352 case 40:
8353 config_val = 1;
8354 break;
8355 case 80:
8356 config_val = 2;
8357 break;
8358 case 160:
8359 config_val = 3;
8360 break;
8361 default:
8362 config_val = 2;
8363 break;
8364 }
8365
8366 dut->chwidth = config_val;
8367
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008368 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008369 }
8370
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008371 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008372 }
8373
8374 val = get_param(cmd, "nss_mcs_cap");
8375 if (val) {
8376 int nss, mcs;
8377 char token[20];
8378 char *result = NULL;
8379 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308380 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008381
Peng Xub8fc5cc2017-05-10 17:27:28 -07008382 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308383 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308384 if (!result) {
8385 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008386 "NSS not specified");
8387 send_resp(dut, conn, SIGMA_ERROR,
8388 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308389 return 0;
8390 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008391 nss = atoi(result);
8392
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008393 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008394 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008395
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308396 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008397 if (result == NULL) {
8398 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008399 "MCS not specified");
8400 send_resp(dut, conn, SIGMA_ERROR,
8401 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008402 return 0;
8403 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308404 result = strtok_r(result, "-", &saveptr);
8405 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308406 if (!result) {
8407 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008408 "MCS not specified");
8409 send_resp(dut, conn, SIGMA_ERROR,
8410 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308411 return 0;
8412 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008413 mcs = atoi(result);
8414
Arif Hussaina37e9552018-06-20 17:05:59 -07008415 if (program && strcasecmp(program, "HE") == 0) {
8416#ifdef NL80211_SUPPORT
8417 enum he_mcs_config mcs_config;
8418 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008419
Arif Hussaina37e9552018-06-20 17:05:59 -07008420 if (mcs >= 0 && mcs <= 7) {
8421 mcs_config = HE_80_MCS0_7;
8422 } else if (mcs > 7 && mcs <= 9) {
8423 mcs_config = HE_80_MCS0_9;
8424 } else if (mcs > 9 && mcs <= 11) {
8425 mcs_config = HE_80_MCS0_11;
8426 } else {
8427 sigma_dut_print(dut, DUT_MSG_ERROR,
8428 "nss_mcs_cap: HE: Invalid mcs: %d",
8429 mcs);
8430 send_resp(dut, conn, SIGMA_ERROR,
8431 "errorCode,Invalid MCS");
8432 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008433 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008434
8435 ret = sta_set_he_mcs(dut, intf, mcs_config);
8436 if (ret) {
8437 sigma_dut_print(dut, DUT_MSG_ERROR,
8438 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8439 mcs_config, ret);
8440 send_resp(dut, conn, SIGMA_ERROR,
8441 "errorCode,Failed to set MCS");
8442 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008443 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008444#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008445 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008446 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8447#endif /* NL80211_SUPPORT */
8448 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008449 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008450
8451 switch (nss) {
8452 case 1:
8453 switch (mcs) {
8454 case 7:
8455 vht_mcsmap = 0xfffc;
8456 break;
8457 case 8:
8458 vht_mcsmap = 0xfffd;
8459 break;
8460 case 9:
8461 vht_mcsmap = 0xfffe;
8462 break;
8463 default:
8464 vht_mcsmap = 0xfffe;
8465 break;
8466 }
8467 break;
8468 case 2:
8469 switch (mcs) {
8470 case 7:
8471 vht_mcsmap = 0xfff0;
8472 break;
8473 case 8:
8474 vht_mcsmap = 0xfff5;
8475 break;
8476 case 9:
8477 vht_mcsmap = 0xfffa;
8478 break;
8479 default:
8480 vht_mcsmap = 0xfffa;
8481 break;
8482 }
8483 break;
8484 case 3:
8485 switch (mcs) {
8486 case 7:
8487 vht_mcsmap = 0xffc0;
8488 break;
8489 case 8:
8490 vht_mcsmap = 0xffd5;
8491 break;
8492 case 9:
8493 vht_mcsmap = 0xffea;
8494 break;
8495 default:
8496 vht_mcsmap = 0xffea;
8497 break;
8498 }
8499 break;
8500 default:
8501 vht_mcsmap = 0xffea;
8502 break;
8503 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008504 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008505 }
8506 }
8507
8508 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8509
8510 val = get_param(cmd, "Vht_tkip");
8511 if (val)
8512 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8513
8514 val = get_param(cmd, "Vht_wep");
8515 if (val)
8516 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8517
8518 if (tkip != -1 || wep != -1) {
8519 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008520 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008521 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008522 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008523 } else {
8524 sigma_dut_print(dut, DUT_MSG_ERROR,
8525 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8526 return 0;
8527 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008528 }
8529
Arif Hussain55f00da2018-07-03 08:28:26 -07008530 val = get_param(cmd, "txBandwidth");
8531 if (val) {
8532 switch (get_driver_type()) {
8533 case DRIVER_WCN:
8534 if (wcn_sta_set_width(dut, intf, val) < 0) {
8535 send_resp(dut, conn, SIGMA_ERROR,
8536 "ErrorCode,Failed to set txBandwidth");
8537 return 0;
8538 }
8539 break;
8540 case DRIVER_ATHEROS:
8541 if (ath_set_width(dut, conn, intf, val) < 0) {
8542 send_resp(dut, conn, SIGMA_ERROR,
8543 "ErrorCode,Failed to set txBandwidth");
8544 return 0;
8545 }
8546 break;
8547 default:
8548 sigma_dut_print(dut, DUT_MSG_ERROR,
8549 "Setting txBandwidth not supported");
8550 break;
8551 }
8552 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008553
Arif Hussain9765f7d2018-07-03 08:28:26 -07008554 val = get_param(cmd, "BeamformeeSTS");
8555 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008556 if (sta_set_tx_beamformee(dut, intf, 1)) {
8557 send_resp(dut, conn, SIGMA_ERROR,
8558 "ErrorCode,Failed to set TX beamformee enable");
8559 return 0;
8560 }
8561
Arif Hussain9765f7d2018-07-03 08:28:26 -07008562 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8563 send_resp(dut, conn, SIGMA_ERROR,
8564 "ErrorCode,Failed to set BeamformeeSTS");
8565 return 0;
8566 }
8567 }
8568
Arif Hussain68d23f52018-07-11 13:39:08 -07008569 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8570 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008571#ifdef NL80211_SUPPORT
8572 enum qca_wlan_he_mac_padding_dur set_val;
8573
8574 switch (atoi(val)) {
8575 case 16:
8576 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8577 break;
8578 case 8:
8579 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8580 break;
8581 default:
8582 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8583 break;
8584 }
8585 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008586 send_resp(dut, conn, SIGMA_ERROR,
8587 "ErrorCode,Failed to set MAC padding duration");
8588 return 0;
8589 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008590#else /* NL80211_SUPPORT */
8591 sigma_dut_print(dut, DUT_MSG_ERROR,
8592 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8593#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008594 }
8595
Arif Hussain480d5f42019-03-12 14:40:42 -07008596 val = get_param(cmd, "TWT_ReqSupport");
8597 if (val) {
8598 int set_val;
8599
8600 if (strcasecmp(val, "Enable") == 0) {
8601 set_val = 1;
8602 } else if (strcasecmp(val, "Disable") == 0) {
8603 set_val = 0;
8604 } else {
8605 send_resp(dut, conn, SIGMA_ERROR,
8606 "ErrorCode,Invalid TWT_ReqSupport");
8607 return STATUS_SENT;
8608 }
8609
8610 if (sta_set_twt_req_support(dut, intf, set_val)) {
8611 sigma_dut_print(dut, DUT_MSG_ERROR,
8612 "Failed to set TWT req support %d",
8613 set_val);
8614 send_resp(dut, conn, SIGMA_ERROR,
8615 "ErrorCode,Failed to set TWT_ReqSupport");
8616 return STATUS_SENT;
8617 }
8618 }
8619
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008620 val = get_param(cmd, "MU_EDCA");
8621 if (val && (strcasecmp(val, "Override") == 0)) {
8622 if (sta_set_mu_edca_override(dut, intf, 1)) {
8623 send_resp(dut, conn, SIGMA_ERROR,
8624 "ErrorCode,Failed to set MU EDCA override");
8625 return 0;
8626 }
8627 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008628
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008629 val = get_param(cmd, "OMControl");
8630 if (val) {
8631 int set_val = 1;
8632
8633 if (strcasecmp(val, "Enable") == 0)
8634 set_val = 1;
8635 else if (strcasecmp(val, "Disable") == 0)
8636 set_val = 0;
8637
8638 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8639 send_resp(dut, conn, SIGMA_ERROR,
8640 "ErrorCode,Failed to set OM ctrl supp");
8641 return 0;
8642 }
8643 }
8644
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008645 val = get_param(cmd, "ADDBAResp_BufSize");
8646 if (val) {
8647 int buf_size;
8648
8649 if (strcasecmp(val, "gt64") == 0)
8650 buf_size = 256;
8651 else
8652 buf_size = 64;
8653 if (get_driver_type() == DRIVER_WCN &&
8654 sta_set_addba_buf_size(dut, intf, buf_size)) {
8655 send_resp(dut, conn, SIGMA_ERROR,
8656 "ErrorCode,set addbaresp_buff_size failed");
8657 return 0;
8658 }
8659 }
8660
8661 val = get_param(cmd, "ADDBAReq_BufSize");
8662 if (val) {
8663 int buf_size;
8664
8665 if (strcasecmp(val, "gt64") == 0)
8666 buf_size = 256;
8667 else
8668 buf_size = 64;
8669 if (get_driver_type() == DRIVER_WCN &&
8670 sta_set_addba_buf_size(dut, intf, buf_size)) {
8671 send_resp(dut, conn, SIGMA_ERROR,
8672 "ErrorCode,set addbareq_buff_size failed");
8673 return 0;
8674 }
8675 }
8676
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008677 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8678}
8679
8680
8681static int sta_set_wireless_60g(struct sigma_dut *dut,
8682 struct sigma_conn *conn,
8683 struct sigma_cmd *cmd)
8684{
8685 const char *dev_role = get_param(cmd, "DevRole");
8686
8687 if (!dev_role) {
8688 send_resp(dut, conn, SIGMA_INVALID,
8689 "ErrorCode,DevRole not specified");
8690 return 0;
8691 }
8692
8693 if (strcasecmp(dev_role, "PCP") == 0)
8694 return sta_set_60g_pcp(dut, conn, cmd);
8695 if (strcasecmp(dev_role, "STA") == 0)
8696 return sta_set_60g_sta(dut, conn, cmd);
8697 send_resp(dut, conn, SIGMA_INVALID,
8698 "ErrorCode,DevRole not supported");
8699 return 0;
8700}
8701
8702
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308703static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8704 struct sigma_cmd *cmd)
8705{
8706 int status;
8707 const char *intf = get_param(cmd, "Interface");
8708 const char *val = get_param(cmd, "DevRole");
8709
8710 if (val && strcasecmp(val, "STA-CFON") == 0) {
8711 status = sta_cfon_set_wireless(dut, conn, cmd);
8712 if (status)
8713 return status;
8714 }
8715 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8716}
8717
8718
Jouni Malinenf7222712019-06-13 01:50:21 +03008719static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
8720 struct sigma_conn *conn,
8721 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008722{
8723 const char *val;
8724
8725 val = get_param(cmd, "Program");
8726 if (val) {
8727 if (strcasecmp(val, "11n") == 0)
8728 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008729 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008730 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8731 if (strcasecmp(val, "60ghz") == 0)
8732 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308733 if (strcasecmp(val, "OCE") == 0)
8734 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008735 /* sta_set_wireless in WPS program is only used for 60G */
8736 if (is_60g_sigma_dut(dut))
8737 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008738 send_resp(dut, conn, SIGMA_ERROR,
8739 "ErrorCode,Program value not supported");
8740 } else {
8741 send_resp(dut, conn, SIGMA_ERROR,
8742 "ErrorCode,Program argument not available");
8743 }
8744
8745 return 0;
8746}
8747
8748
8749static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8750 int tid)
8751{
8752 char buf[100];
8753 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8754
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308755 if (tid < 0 ||
8756 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8757 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8758 return;
8759 }
8760
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008761 /*
8762 * Two ways to ensure that addba request with a
8763 * non zero TID could be sent out. EV 117296
8764 */
8765 snprintf(buf, sizeof(buf),
8766 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8767 tid);
8768 if (system(buf) != 0) {
8769 sigma_dut_print(dut, DUT_MSG_ERROR,
8770 "Ping did not send out");
8771 }
8772
8773 snprintf(buf, sizeof(buf),
8774 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8775 intf, VI_QOS_TMP_FILE);
8776 if (system(buf) != 0)
8777 return;
8778
8779 snprintf(buf, sizeof(buf),
8780 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8781 intf, VI_QOS_TMP_FILE);
8782 if (system(buf) != 0)
8783 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8784
8785 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8786 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8787 if (system(buf) != 0) {
8788 sigma_dut_print(dut, DUT_MSG_ERROR,
8789 "VI_QOS_TEMP_FILE generation error failed");
8790 }
8791 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8792 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8793 if (system(buf) != 0) {
8794 sigma_dut_print(dut, DUT_MSG_ERROR,
8795 "VI_QOS_FILE generation failed");
8796 }
8797
8798 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8799 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8800 if (system(buf) != 0) {
8801 sigma_dut_print(dut, DUT_MSG_ERROR,
8802 "VI_QOS_FILE generation failed");
8803 }
8804
8805 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8806 if (system(buf) != 0) {
8807 }
8808}
8809
8810
8811static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8812 struct sigma_cmd *cmd)
8813{
8814 const char *intf = get_param(cmd, "Interface");
8815 const char *val;
8816 int tid = 0;
8817 char buf[100];
8818
8819 val = get_param(cmd, "TID");
8820 if (val) {
8821 tid = atoi(val);
8822 if (tid)
8823 ath_sta_inject_frame(dut, intf, tid);
8824 }
8825
8826 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008827 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008828
8829 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8830 if (system(buf) != 0) {
8831 sigma_dut_print(dut, DUT_MSG_ERROR,
8832 "wifitool senddelba failed");
8833 }
8834
8835 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8836 if (system(buf) != 0) {
8837 sigma_dut_print(dut, DUT_MSG_ERROR,
8838 "wifitool sendaddba failed");
8839 }
8840
8841 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8842
8843 return 1;
8844}
8845
8846
Lior David9981b512017-01-20 13:16:40 +02008847#ifdef __linux__
8848
8849static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
8850 int agg_size)
8851{
8852 char dir[128], buf[128];
8853 FILE *f;
8854 regex_t re;
8855 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03008856 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02008857
8858 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
8859 sigma_dut_print(dut, DUT_MSG_ERROR,
8860 "failed to get wil6210 debugfs dir");
8861 return -1;
8862 }
8863
Jouni Malinen3aa72862019-05-29 23:14:51 +03008864 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
8865 if (res < 0 || res >= sizeof(buf))
8866 return -1;
Lior David9981b512017-01-20 13:16:40 +02008867 f = fopen(buf, "r");
8868 if (!f) {
8869 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008870 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03008871 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
8872 if (res < 0 || res >= sizeof(buf))
8873 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008874 f = fopen(buf, "r");
8875 if (!f) {
8876 sigma_dut_print(dut, DUT_MSG_ERROR,
8877 "failed to open: %s", buf);
8878 return -1;
8879 }
Lior David9981b512017-01-20 13:16:40 +02008880 }
8881
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008882 /* can be either VRING tx... or RING... */
8883 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02008884 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
8885 goto out;
8886 }
8887
8888 /* find TX VRING for the mac address */
8889 found = 0;
8890 while (fgets(buf, sizeof(buf), f)) {
8891 if (strcasestr(buf, dest_mac)) {
8892 found = 1;
8893 break;
8894 }
8895 }
8896
8897 if (!found) {
8898 sigma_dut_print(dut, DUT_MSG_ERROR,
8899 "no TX VRING for %s", dest_mac);
8900 goto out;
8901 }
8902
8903 /* extract VRING ID, "VRING tx_<id> = {" */
8904 if (!fgets(buf, sizeof(buf), f)) {
8905 sigma_dut_print(dut, DUT_MSG_ERROR,
8906 "no VRING start line for %s", dest_mac);
8907 goto out;
8908 }
8909
8910 rc = regexec(&re, buf, 2, m, 0);
8911 regfree(&re);
8912 if (rc || m[1].rm_so < 0) {
8913 sigma_dut_print(dut, DUT_MSG_ERROR,
8914 "no VRING TX ID for %s", dest_mac);
8915 goto out;
8916 }
8917 buf[m[1].rm_eo] = 0;
8918 vring_id = atoi(&buf[m[1].rm_so]);
8919
8920 /* send the addba command */
8921 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03008922 res = snprintf(buf, sizeof(buf), "%s/back", dir);
8923 if (res < 0 || res >= sizeof(buf))
8924 return -1;
Lior David9981b512017-01-20 13:16:40 +02008925 f = fopen(buf, "w");
8926 if (!f) {
8927 sigma_dut_print(dut, DUT_MSG_ERROR,
8928 "failed to open: %s", buf);
8929 return -1;
8930 }
8931
8932 fprintf(f, "add %d %d\n", vring_id, agg_size);
8933
8934 ret = 0;
8935
8936out:
8937 fclose(f);
8938
8939 return ret;
8940}
8941
8942
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008943int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8944 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008945{
8946 const char *val;
8947 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008948
8949 val = get_param(cmd, "TID");
8950 if (val) {
8951 tid = atoi(val);
8952 if (tid != 0) {
8953 sigma_dut_print(dut, DUT_MSG_ERROR,
8954 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
8955 tid);
8956 }
8957 }
8958
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008959 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008960 if (!val) {
8961 sigma_dut_print(dut, DUT_MSG_ERROR,
8962 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008963 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008964 }
8965
Lior David9981b512017-01-20 13:16:40 +02008966 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008967 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008968
8969 return 1;
8970}
8971
Lior David9981b512017-01-20 13:16:40 +02008972#endif /* __linux__ */
8973
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008974
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008975static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8976 struct sigma_cmd *cmd)
8977{
8978#ifdef NL80211_SUPPORT
8979 const char *intf = get_param(cmd, "Interface");
8980 const char *val;
8981 int tid = -1;
8982 int bufsize = 64;
8983 struct nl_msg *msg;
8984 int ret = 0;
8985 struct nlattr *params;
8986 int ifindex;
8987
8988 val = get_param(cmd, "TID");
8989 if (val)
8990 tid = atoi(val);
8991
8992 if (tid == -1) {
8993 send_resp(dut, conn, SIGMA_ERROR,
8994 "ErrorCode,sta_send_addba tid invalid");
8995 return 0;
8996 }
8997
8998 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8999
9000 ifindex = if_nametoindex(intf);
9001 if (ifindex == 0) {
9002 sigma_dut_print(dut, DUT_MSG_ERROR,
9003 "%s: Index for interface %s failed",
9004 __func__, intf);
9005 send_resp(dut, conn, SIGMA_ERROR,
9006 "ErrorCode,sta_send_addba interface invalid");
9007 return 0;
9008 }
9009
9010 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9011 NL80211_CMD_VENDOR)) ||
9012 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9013 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9014 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9015 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9016 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9017 nla_put_u8(msg,
9018 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9019 QCA_WLAN_ADD_BA) ||
9020 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9021 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009022 nla_put_u16(msg,
9023 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9024 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009025 sigma_dut_print(dut, DUT_MSG_ERROR,
9026 "%s: err in adding vendor_cmd and vendor_data",
9027 __func__);
9028 nlmsg_free(msg);
9029 send_resp(dut, conn, SIGMA_ERROR,
9030 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9031 return 0;
9032 }
9033 nla_nest_end(msg, params);
9034
9035 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9036 if (ret) {
9037 sigma_dut_print(dut, DUT_MSG_ERROR,
9038 "%s: err in send_and_recv_msgs, ret=%d",
9039 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309040 if (ret == -EOPNOTSUPP)
9041 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009042 send_resp(dut, conn, SIGMA_ERROR,
9043 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9044 return 0;
9045 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009046#else /* NL80211_SUPPORT */
9047 sigma_dut_print(dut, DUT_MSG_ERROR,
9048 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009049#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309050
9051 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009052}
9053
9054
Jouni Malinenf7222712019-06-13 01:50:21 +03009055static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9056 struct sigma_conn *conn,
9057 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009058{
9059 switch (get_driver_type()) {
9060 case DRIVER_ATHEROS:
9061 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009062 case DRIVER_WCN:
9063 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009064#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009065 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009066 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009067#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009068 default:
9069 /*
9070 * There is no driver specific implementation for other drivers.
9071 * Ignore the command and report COMPLETE since the following
9072 * throughput test operation will end up sending ADDBA anyway.
9073 */
9074 return 1;
9075 }
9076}
9077
9078
9079int inject_eth_frame(int s, const void *data, size_t len,
9080 unsigned short ethtype, char *dst, char *src)
9081{
9082 struct iovec iov[4] = {
9083 {
9084 .iov_base = dst,
9085 .iov_len = ETH_ALEN,
9086 },
9087 {
9088 .iov_base = src,
9089 .iov_len = ETH_ALEN,
9090 },
9091 {
9092 .iov_base = &ethtype,
9093 .iov_len = sizeof(unsigned short),
9094 },
9095 {
9096 .iov_base = (void *) data,
9097 .iov_len = len,
9098 }
9099 };
9100 struct msghdr msg = {
9101 .msg_name = NULL,
9102 .msg_namelen = 0,
9103 .msg_iov = iov,
9104 .msg_iovlen = 4,
9105 .msg_control = NULL,
9106 .msg_controllen = 0,
9107 .msg_flags = 0,
9108 };
9109
9110 return sendmsg(s, &msg, 0);
9111}
9112
9113#if defined(__linux__) || defined(__QNXNTO__)
9114
9115int inject_frame(int s, const void *data, size_t len, int encrypt)
9116{
9117#define IEEE80211_RADIOTAP_F_WEP 0x04
9118#define IEEE80211_RADIOTAP_F_FRAG 0x08
9119 unsigned char rtap_hdr[] = {
9120 0x00, 0x00, /* radiotap version */
9121 0x0e, 0x00, /* radiotap length */
9122 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9123 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9124 0x00, /* padding */
9125 0x00, 0x00, /* RX and TX flags to indicate that */
9126 0x00, 0x00, /* this is the injected frame directly */
9127 };
9128 struct iovec iov[2] = {
9129 {
9130 .iov_base = &rtap_hdr,
9131 .iov_len = sizeof(rtap_hdr),
9132 },
9133 {
9134 .iov_base = (void *) data,
9135 .iov_len = len,
9136 }
9137 };
9138 struct msghdr msg = {
9139 .msg_name = NULL,
9140 .msg_namelen = 0,
9141 .msg_iov = iov,
9142 .msg_iovlen = 2,
9143 .msg_control = NULL,
9144 .msg_controllen = 0,
9145 .msg_flags = 0,
9146 };
9147
9148 if (encrypt)
9149 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9150
9151 return sendmsg(s, &msg, 0);
9152}
9153
9154
9155int open_monitor(const char *ifname)
9156{
9157#ifdef __QNXNTO__
9158 struct sockaddr_dl ll;
9159 int s;
9160
9161 memset(&ll, 0, sizeof(ll));
9162 ll.sdl_family = AF_LINK;
9163 ll.sdl_index = if_nametoindex(ifname);
9164 if (ll.sdl_index == 0) {
9165 perror("if_nametoindex");
9166 return -1;
9167 }
9168 s = socket(PF_INET, SOCK_RAW, 0);
9169#else /* __QNXNTO__ */
9170 struct sockaddr_ll ll;
9171 int s;
9172
9173 memset(&ll, 0, sizeof(ll));
9174 ll.sll_family = AF_PACKET;
9175 ll.sll_ifindex = if_nametoindex(ifname);
9176 if (ll.sll_ifindex == 0) {
9177 perror("if_nametoindex");
9178 return -1;
9179 }
9180 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9181#endif /* __QNXNTO__ */
9182 if (s < 0) {
9183 perror("socket[PF_PACKET,SOCK_RAW]");
9184 return -1;
9185 }
9186
9187 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9188 perror("monitor socket bind");
9189 close(s);
9190 return -1;
9191 }
9192
9193 return s;
9194}
9195
9196
9197static int hex2num(char c)
9198{
9199 if (c >= '0' && c <= '9')
9200 return c - '0';
9201 if (c >= 'a' && c <= 'f')
9202 return c - 'a' + 10;
9203 if (c >= 'A' && c <= 'F')
9204 return c - 'A' + 10;
9205 return -1;
9206}
9207
9208
9209int hwaddr_aton(const char *txt, unsigned char *addr)
9210{
9211 int i;
9212
9213 for (i = 0; i < 6; i++) {
9214 int a, b;
9215
9216 a = hex2num(*txt++);
9217 if (a < 0)
9218 return -1;
9219 b = hex2num(*txt++);
9220 if (b < 0)
9221 return -1;
9222 *addr++ = (a << 4) | b;
9223 if (i < 5 && *txt++ != ':')
9224 return -1;
9225 }
9226
9227 return 0;
9228}
9229
9230#endif /* defined(__linux__) || defined(__QNXNTO__) */
9231
9232enum send_frame_type {
9233 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9234};
9235enum send_frame_protection {
9236 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9237};
9238
9239
9240static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9241 enum send_frame_type frame,
9242 enum send_frame_protection protected,
9243 const char *dest)
9244{
9245#ifdef __linux__
9246 unsigned char buf[1000], *pos;
9247 int s, res;
9248 char bssid[20], addr[20];
9249 char result[32], ssid[100];
9250 size_t ssid_len;
9251
9252 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
9253 sizeof(result)) < 0 ||
9254 strncmp(result, "COMPLETED", 9) != 0) {
9255 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9256 return 0;
9257 }
9258
9259 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
9260 < 0) {
9261 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9262 "current BSSID");
9263 return 0;
9264 }
9265
9266 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
9267 < 0) {
9268 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9269 "own MAC address");
9270 return 0;
9271 }
9272
9273 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
9274 < 0) {
9275 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9276 "current SSID");
9277 return 0;
9278 }
9279 ssid_len = strlen(ssid);
9280
9281 pos = buf;
9282
9283 /* Frame Control */
9284 switch (frame) {
9285 case DISASSOC:
9286 *pos++ = 0xa0;
9287 break;
9288 case DEAUTH:
9289 *pos++ = 0xc0;
9290 break;
9291 case SAQUERY:
9292 *pos++ = 0xd0;
9293 break;
9294 case AUTH:
9295 *pos++ = 0xb0;
9296 break;
9297 case ASSOCREQ:
9298 *pos++ = 0x00;
9299 break;
9300 case REASSOCREQ:
9301 *pos++ = 0x20;
9302 break;
9303 case DLS_REQ:
9304 *pos++ = 0xd0;
9305 break;
9306 }
9307
9308 if (protected == INCORRECT_KEY)
9309 *pos++ = 0x40; /* Set Protected field to 1 */
9310 else
9311 *pos++ = 0x00;
9312
9313 /* Duration */
9314 *pos++ = 0x00;
9315 *pos++ = 0x00;
9316
9317 /* addr1 = DA (current AP) */
9318 hwaddr_aton(bssid, pos);
9319 pos += 6;
9320 /* addr2 = SA (own address) */
9321 hwaddr_aton(addr, pos);
9322 pos += 6;
9323 /* addr3 = BSSID (current AP) */
9324 hwaddr_aton(bssid, pos);
9325 pos += 6;
9326
9327 /* Seq# (to be filled by driver/mac80211) */
9328 *pos++ = 0x00;
9329 *pos++ = 0x00;
9330
9331 if (protected == INCORRECT_KEY) {
9332 /* CCMP parameters */
9333 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9334 pos += 8;
9335 }
9336
9337 if (protected == INCORRECT_KEY) {
9338 switch (frame) {
9339 case DEAUTH:
9340 /* Reason code (encrypted) */
9341 memcpy(pos, "\xa7\x39", 2);
9342 pos += 2;
9343 break;
9344 case DISASSOC:
9345 /* Reason code (encrypted) */
9346 memcpy(pos, "\xa7\x39", 2);
9347 pos += 2;
9348 break;
9349 case SAQUERY:
9350 /* Category|Action|TransID (encrypted) */
9351 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9352 pos += 4;
9353 break;
9354 default:
9355 return -1;
9356 }
9357
9358 /* CCMP MIC */
9359 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9360 pos += 8;
9361 } else {
9362 switch (frame) {
9363 case DEAUTH:
9364 /* reason code = 8 */
9365 *pos++ = 0x08;
9366 *pos++ = 0x00;
9367 break;
9368 case DISASSOC:
9369 /* reason code = 8 */
9370 *pos++ = 0x08;
9371 *pos++ = 0x00;
9372 break;
9373 case SAQUERY:
9374 /* Category - SA Query */
9375 *pos++ = 0x08;
9376 /* SA query Action - Request */
9377 *pos++ = 0x00;
9378 /* Transaction ID */
9379 *pos++ = 0x12;
9380 *pos++ = 0x34;
9381 break;
9382 case AUTH:
9383 /* Auth Alg (Open) */
9384 *pos++ = 0x00;
9385 *pos++ = 0x00;
9386 /* Seq# */
9387 *pos++ = 0x01;
9388 *pos++ = 0x00;
9389 /* Status code */
9390 *pos++ = 0x00;
9391 *pos++ = 0x00;
9392 break;
9393 case ASSOCREQ:
9394 /* Capability Information */
9395 *pos++ = 0x31;
9396 *pos++ = 0x04;
9397 /* Listen Interval */
9398 *pos++ = 0x0a;
9399 *pos++ = 0x00;
9400 /* SSID */
9401 *pos++ = 0x00;
9402 *pos++ = ssid_len;
9403 memcpy(pos, ssid, ssid_len);
9404 pos += ssid_len;
9405 /* Supported Rates */
9406 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9407 10);
9408 pos += 10;
9409 /* Extended Supported Rates */
9410 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9411 pos += 6;
9412 /* RSN */
9413 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9414 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9415 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9416 pos += 28;
9417 break;
9418 case REASSOCREQ:
9419 /* Capability Information */
9420 *pos++ = 0x31;
9421 *pos++ = 0x04;
9422 /* Listen Interval */
9423 *pos++ = 0x0a;
9424 *pos++ = 0x00;
9425 /* Current AP */
9426 hwaddr_aton(bssid, pos);
9427 pos += 6;
9428 /* SSID */
9429 *pos++ = 0x00;
9430 *pos++ = ssid_len;
9431 memcpy(pos, ssid, ssid_len);
9432 pos += ssid_len;
9433 /* Supported Rates */
9434 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9435 10);
9436 pos += 10;
9437 /* Extended Supported Rates */
9438 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9439 pos += 6;
9440 /* RSN */
9441 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9442 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9443 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9444 pos += 28;
9445 break;
9446 case DLS_REQ:
9447 /* Category - DLS */
9448 *pos++ = 0x02;
9449 /* DLS Action - Request */
9450 *pos++ = 0x00;
9451 /* Destination MACAddress */
9452 if (dest)
9453 hwaddr_aton(dest, pos);
9454 else
9455 memset(pos, 0, 6);
9456 pos += 6;
9457 /* Source MACAddress */
9458 hwaddr_aton(addr, pos);
9459 pos += 6;
9460 /* Capability Information */
9461 *pos++ = 0x10; /* Privacy */
9462 *pos++ = 0x06; /* QoS */
9463 /* DLS Timeout Value */
9464 *pos++ = 0x00;
9465 *pos++ = 0x01;
9466 /* Supported rates */
9467 *pos++ = 0x01;
9468 *pos++ = 0x08;
9469 *pos++ = 0x0c; /* 6 Mbps */
9470 *pos++ = 0x12; /* 9 Mbps */
9471 *pos++ = 0x18; /* 12 Mbps */
9472 *pos++ = 0x24; /* 18 Mbps */
9473 *pos++ = 0x30; /* 24 Mbps */
9474 *pos++ = 0x48; /* 36 Mbps */
9475 *pos++ = 0x60; /* 48 Mbps */
9476 *pos++ = 0x6c; /* 54 Mbps */
9477 /* TODO: Extended Supported Rates */
9478 /* TODO: HT Capabilities */
9479 break;
9480 }
9481 }
9482
9483 s = open_monitor("sigmadut");
9484 if (s < 0) {
9485 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9486 "monitor socket");
9487 return 0;
9488 }
9489
9490 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9491 if (res < 0) {
9492 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9493 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309494 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009495 return 0;
9496 }
9497 if (res < pos - buf) {
9498 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9499 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309500 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009501 return 0;
9502 }
9503
9504 close(s);
9505
9506 return 1;
9507#else /* __linux__ */
9508 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9509 "yet supported");
9510 return 0;
9511#endif /* __linux__ */
9512}
9513
9514
9515static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9516 struct sigma_conn *conn,
9517 struct sigma_cmd *cmd)
9518{
9519 const char *intf = get_param(cmd, "Interface");
9520 const char *sta, *val;
9521 unsigned char addr[ETH_ALEN];
9522 char buf[100];
9523
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009524 if (!intf)
9525 return -1;
9526
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009527 sta = get_param(cmd, "peer");
9528 if (sta == NULL)
9529 sta = get_param(cmd, "station");
9530 if (sta == NULL) {
9531 send_resp(dut, conn, SIGMA_ERROR,
9532 "ErrorCode,Missing peer address");
9533 return 0;
9534 }
9535 if (hwaddr_aton(sta, addr) < 0) {
9536 send_resp(dut, conn, SIGMA_ERROR,
9537 "ErrorCode,Invalid peer address");
9538 return 0;
9539 }
9540
9541 val = get_param(cmd, "type");
9542 if (val == NULL)
9543 return -1;
9544
9545 if (strcasecmp(val, "DISCOVERY") == 0) {
9546 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9547 if (wpa_command(intf, buf) < 0) {
9548 send_resp(dut, conn, SIGMA_ERROR,
9549 "ErrorCode,Failed to send TDLS discovery");
9550 return 0;
9551 }
9552 return 1;
9553 }
9554
9555 if (strcasecmp(val, "SETUP") == 0) {
9556 int status = 0, timeout = 0;
9557
9558 val = get_param(cmd, "Status");
9559 if (val)
9560 status = atoi(val);
9561
9562 val = get_param(cmd, "Timeout");
9563 if (val)
9564 timeout = atoi(val);
9565
9566 if (status != 0 && status != 37) {
9567 send_resp(dut, conn, SIGMA_ERROR,
9568 "ErrorCode,Unsupported status value");
9569 return 0;
9570 }
9571
9572 if (timeout != 0 && timeout != 301) {
9573 send_resp(dut, conn, SIGMA_ERROR,
9574 "ErrorCode,Unsupported timeout value");
9575 return 0;
9576 }
9577
9578 if (status && timeout) {
9579 send_resp(dut, conn, SIGMA_ERROR,
9580 "ErrorCode,Unsupported timeout+status "
9581 "combination");
9582 return 0;
9583 }
9584
9585 if (status == 37 &&
9586 wpa_command(intf, "SET tdls_testing 0x200")) {
9587 send_resp(dut, conn, SIGMA_ERROR,
9588 "ErrorCode,Failed to enable "
9589 "decline setup response test mode");
9590 return 0;
9591 }
9592
9593 if (timeout == 301) {
9594 int res;
9595 if (dut->no_tpk_expiration)
9596 res = wpa_command(intf,
9597 "SET tdls_testing 0x108");
9598 else
9599 res = wpa_command(intf,
9600 "SET tdls_testing 0x8");
9601 if (res) {
9602 send_resp(dut, conn, SIGMA_ERROR,
9603 "ErrorCode,Failed to set short TPK "
9604 "lifetime");
9605 return 0;
9606 }
9607 }
9608
9609 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9610 if (wpa_command(intf, buf) < 0) {
9611 send_resp(dut, conn, SIGMA_ERROR,
9612 "ErrorCode,Failed to send TDLS setup");
9613 return 0;
9614 }
9615 return 1;
9616 }
9617
9618 if (strcasecmp(val, "TEARDOWN") == 0) {
9619 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9620 if (wpa_command(intf, buf) < 0) {
9621 send_resp(dut, conn, SIGMA_ERROR,
9622 "ErrorCode,Failed to send TDLS teardown");
9623 return 0;
9624 }
9625 return 1;
9626 }
9627
9628 send_resp(dut, conn, SIGMA_ERROR,
9629 "ErrorCode,Unsupported TDLS frame");
9630 return 0;
9631}
9632
9633
9634static int sta_ap_known(const char *ifname, const char *bssid)
9635{
9636 char buf[4096];
9637
Jouni Malinendd32f192018-09-15 02:55:19 +03009638 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009639 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9640 return 0;
9641 if (strncmp(buf, "id=", 3) != 0)
9642 return 0;
9643 return 1;
9644}
9645
9646
9647static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9648 const char *bssid)
9649{
9650 int res;
9651 struct wpa_ctrl *ctrl;
9652 char buf[256];
9653
9654 if (sta_ap_known(ifname, bssid))
9655 return 0;
9656 sigma_dut_print(dut, DUT_MSG_DEBUG,
9657 "AP not in BSS table - start scan");
9658
9659 ctrl = open_wpa_mon(ifname);
9660 if (ctrl == NULL) {
9661 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9662 "wpa_supplicant monitor connection");
9663 return -1;
9664 }
9665
9666 if (wpa_command(ifname, "SCAN") < 0) {
9667 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9668 wpa_ctrl_detach(ctrl);
9669 wpa_ctrl_close(ctrl);
9670 return -1;
9671 }
9672
9673 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9674 buf, sizeof(buf));
9675
9676 wpa_ctrl_detach(ctrl);
9677 wpa_ctrl_close(ctrl);
9678
9679 if (res < 0) {
9680 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9681 return -1;
9682 }
9683
9684 if (sta_ap_known(ifname, bssid))
9685 return 0;
9686 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9687 return -1;
9688}
9689
9690
9691static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9692 struct sigma_conn *conn,
9693 struct sigma_cmd *cmd,
9694 const char *intf)
9695{
9696 char buf[200];
9697
9698 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9699 if (system(buf) != 0) {
9700 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9701 "ndsend");
9702 return 0;
9703 }
9704
9705 return 1;
9706}
9707
9708
9709static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9710 struct sigma_conn *conn,
9711 struct sigma_cmd *cmd,
9712 const char *intf)
9713{
9714 char buf[200];
9715 const char *ip = get_param(cmd, "SenderIP");
9716
Peng Xu26b356d2017-10-04 17:58:16 -07009717 if (!ip)
9718 return 0;
9719
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009720 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9721 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9722 if (system(buf) == 0) {
9723 sigma_dut_print(dut, DUT_MSG_INFO,
9724 "Neighbor Solicitation got a response "
9725 "for %s@%s", ip, intf);
9726 }
9727
9728 return 1;
9729}
9730
9731
9732static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9733 struct sigma_conn *conn,
9734 struct sigma_cmd *cmd,
9735 const char *ifname)
9736{
9737 char buf[200];
9738 const char *ip = get_param(cmd, "SenderIP");
9739
9740 if (ip == NULL) {
9741 send_resp(dut, conn, SIGMA_ERROR,
9742 "ErrorCode,Missing SenderIP parameter");
9743 return 0;
9744 }
9745 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9746 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9747 if (system(buf) != 0) {
9748 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9749 "for %s@%s", ip, ifname);
9750 }
9751
9752 return 1;
9753}
9754
9755
9756static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9757 struct sigma_conn *conn,
9758 struct sigma_cmd *cmd,
9759 const char *ifname)
9760{
9761 char buf[200];
9762 char ip[16];
9763 int s;
Peng Xub3756882017-10-04 14:39:09 -07009764 struct ifreq ifr;
9765 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009766
9767 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009768 if (s < 0) {
9769 perror("socket");
9770 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009771 }
9772
Peng Xub3756882017-10-04 14:39:09 -07009773 memset(&ifr, 0, sizeof(ifr));
9774 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9775 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9776 sigma_dut_print(dut, DUT_MSG_INFO,
9777 "Failed to get %s IP address: %s",
9778 ifname, strerror(errno));
9779 close(s);
9780 return -1;
9781 }
9782 close(s);
9783
9784 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9785 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9786
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009787 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9788 ip);
9789 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9790 if (system(buf) != 0) {
9791 }
9792
9793 return 1;
9794}
9795
9796
9797static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9798 struct sigma_conn *conn,
9799 struct sigma_cmd *cmd,
9800 const char *ifname)
9801{
9802 char buf[200], addr[20];
9803 char dst[ETH_ALEN], src[ETH_ALEN];
9804 short ethtype = htons(ETH_P_ARP);
9805 char *pos;
9806 int s, res;
9807 const char *val;
9808 struct sockaddr_in taddr;
9809
9810 val = get_param(cmd, "dest");
9811 if (val)
9812 hwaddr_aton(val, (unsigned char *) dst);
9813
9814 val = get_param(cmd, "DestIP");
9815 if (val)
9816 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009817 else
9818 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009819
9820 if (get_wpa_status(get_station_ifname(), "address", addr,
9821 sizeof(addr)) < 0)
9822 return -2;
9823 hwaddr_aton(addr, (unsigned char *) src);
9824
9825 pos = buf;
9826 *pos++ = 0x00;
9827 *pos++ = 0x01;
9828 *pos++ = 0x08;
9829 *pos++ = 0x00;
9830 *pos++ = 0x06;
9831 *pos++ = 0x04;
9832 *pos++ = 0x00;
9833 *pos++ = 0x02;
9834 memcpy(pos, src, ETH_ALEN);
9835 pos += ETH_ALEN;
9836 memcpy(pos, &taddr.sin_addr, 4);
9837 pos += 4;
9838 memcpy(pos, dst, ETH_ALEN);
9839 pos += ETH_ALEN;
9840 memcpy(pos, &taddr.sin_addr, 4);
9841 pos += 4;
9842
9843 s = open_monitor(get_station_ifname());
9844 if (s < 0) {
9845 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9846 "monitor socket");
9847 return 0;
9848 }
9849
9850 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
9851 if (res < 0) {
9852 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9853 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309854 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009855 return 0;
9856 }
9857
9858 close(s);
9859
9860 return 1;
9861}
9862
9863
9864static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
9865 struct sigma_conn *conn,
9866 struct sigma_cmd *cmd,
9867 const char *intf, const char *dest)
9868{
9869 char buf[100];
9870
9871 if (if_nametoindex("sigmadut") == 0) {
9872 snprintf(buf, sizeof(buf),
9873 "iw dev %s interface add sigmadut type monitor",
9874 get_station_ifname());
9875 if (system(buf) != 0 ||
9876 if_nametoindex("sigmadut") == 0) {
9877 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9878 "monitor interface with '%s'", buf);
9879 return -2;
9880 }
9881 }
9882
9883 if (system("ifconfig sigmadut up") != 0) {
9884 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9885 "monitor interface up");
9886 return -2;
9887 }
9888
9889 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
9890}
9891
9892
9893static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
9894 struct sigma_conn *conn,
9895 struct sigma_cmd *cmd)
9896{
9897 const char *intf = get_param(cmd, "Interface");
9898 const char *dest = get_param(cmd, "Dest");
9899 const char *type = get_param(cmd, "FrameName");
9900 const char *val;
9901 char buf[200], *pos, *end;
9902 int count, count2;
9903
9904 if (type == NULL)
9905 type = get_param(cmd, "Type");
9906
9907 if (intf == NULL || dest == NULL || type == NULL)
9908 return -1;
9909
9910 if (strcasecmp(type, "NeighAdv") == 0)
9911 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
9912
9913 if (strcasecmp(type, "NeighSolicitReq") == 0)
9914 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
9915
9916 if (strcasecmp(type, "ARPProbe") == 0)
9917 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
9918
9919 if (strcasecmp(type, "ARPAnnounce") == 0)
9920 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
9921
9922 if (strcasecmp(type, "ARPReply") == 0)
9923 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
9924
9925 if (strcasecmp(type, "DLS-request") == 0 ||
9926 strcasecmp(type, "DLSrequest") == 0)
9927 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
9928 dest);
9929
9930 if (strcasecmp(type, "ANQPQuery") != 0 &&
9931 strcasecmp(type, "Query") != 0) {
9932 send_resp(dut, conn, SIGMA_ERROR,
9933 "ErrorCode,Unsupported HS 2.0 send frame type");
9934 return 0;
9935 }
9936
9937 if (sta_scan_ap(dut, intf, dest) < 0) {
9938 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
9939 "the requested AP");
9940 return 0;
9941 }
9942
9943 pos = buf;
9944 end = buf + sizeof(buf);
9945 count = 0;
9946 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
9947
9948 val = get_param(cmd, "ANQP_CAP_LIST");
9949 if (val && atoi(val)) {
9950 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
9951 count++;
9952 }
9953
9954 val = get_param(cmd, "VENUE_NAME");
9955 if (val && atoi(val)) {
9956 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
9957 count++;
9958 }
9959
9960 val = get_param(cmd, "NETWORK_AUTH_TYPE");
9961 if (val && atoi(val)) {
9962 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
9963 count++;
9964 }
9965
9966 val = get_param(cmd, "ROAMING_CONS");
9967 if (val && atoi(val)) {
9968 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
9969 count++;
9970 }
9971
9972 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
9973 if (val && atoi(val)) {
9974 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
9975 count++;
9976 }
9977
9978 val = get_param(cmd, "NAI_REALM_LIST");
9979 if (val && atoi(val)) {
9980 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
9981 count++;
9982 }
9983
9984 val = get_param(cmd, "3GPP_INFO");
9985 if (val && atoi(val)) {
9986 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
9987 count++;
9988 }
9989
9990 val = get_param(cmd, "DOMAIN_LIST");
9991 if (val && atoi(val)) {
9992 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
9993 count++;
9994 }
9995
Jouni Malinen34cf9532018-04-29 19:26:33 +03009996 val = get_param(cmd, "Venue_URL");
9997 if (val && atoi(val)) {
9998 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
9999 count++;
10000 }
10001
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010002 val = get_param(cmd, "Advice_Of_Charge");
10003 if (val && atoi(val)) {
10004 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10005 count++;
10006 }
10007
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010008 if (count && wpa_command(intf, buf)) {
10009 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10010 return 0;
10011 }
10012
10013 pos = buf;
10014 end = buf + sizeof(buf);
10015 count2 = 0;
10016 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10017
10018 val = get_param(cmd, "HS_CAP_LIST");
10019 if (val && atoi(val)) {
10020 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10021 count2++;
10022 }
10023
10024 val = get_param(cmd, "OPER_NAME");
10025 if (val && atoi(val)) {
10026 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10027 count2++;
10028 }
10029
10030 val = get_param(cmd, "WAN_METRICS");
10031 if (!val)
10032 val = get_param(cmd, "WAN_MAT");
10033 if (!val)
10034 val = get_param(cmd, "WAN_MET");
10035 if (val && atoi(val)) {
10036 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10037 count2++;
10038 }
10039
10040 val = get_param(cmd, "CONNECTION_CAPABILITY");
10041 if (val && atoi(val)) {
10042 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10043 count2++;
10044 }
10045
10046 val = get_param(cmd, "OP_CLASS");
10047 if (val && atoi(val)) {
10048 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10049 count2++;
10050 }
10051
10052 val = get_param(cmd, "OSU_PROVIDER_LIST");
10053 if (val && atoi(val)) {
10054 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10055 count2++;
10056 }
10057
Jouni Malinenf67afec2018-04-29 19:24:58 +030010058 val = get_param(cmd, "OPER_ICON_METADATA");
10059 if (!val)
10060 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10061 if (val && atoi(val)) {
10062 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10063 count2++;
10064 }
10065
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010066 if (count && count2) {
10067 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10068 "second query");
10069 sleep(1);
10070 }
10071
10072 if (count2 && wpa_command(intf, buf)) {
10073 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10074 "failed");
10075 return 0;
10076 }
10077
10078 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10079 if (val) {
10080 if (count || count2) {
10081 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10082 "sending out second query");
10083 sleep(1);
10084 }
10085
10086 if (strcmp(val, "1") == 0)
10087 val = "mail.example.com";
10088 snprintf(buf, end - pos,
10089 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10090 dest, val);
10091 if (wpa_command(intf, buf)) {
10092 send_resp(dut, conn, SIGMA_ERROR,
10093 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10094 "failed");
10095 return 0;
10096 }
10097 }
10098
10099 val = get_param(cmd, "ICON_REQUEST");
10100 if (val) {
10101 if (count || count2) {
10102 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10103 "sending out second query");
10104 sleep(1);
10105 }
10106
10107 snprintf(buf, end - pos,
10108 "HS20_ICON_REQUEST %s %s", dest, val);
10109 if (wpa_command(intf, buf)) {
10110 send_resp(dut, conn, SIGMA_ERROR,
10111 "ErrorCode,HS20_ICON_REQUEST failed");
10112 return 0;
10113 }
10114 }
10115
10116 return 1;
10117}
10118
10119
10120static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10121 struct sigma_conn *conn,
10122 struct sigma_cmd *cmd)
10123{
10124 const char *val;
10125 char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010126 int chwidth, nss;
10127
10128 val = get_param(cmd, "framename");
10129 if (!val)
10130 return -1;
10131 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10132
10133 /* Command sequence to generate Op mode notification */
10134 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
10135 ifname = get_station_ifname();
10136
10137 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010138 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010139
10140 /* Extract Channel width */
10141 val = get_param(cmd, "Channel_width");
10142 if (val) {
10143 switch (atoi(val)) {
10144 case 20:
10145 chwidth = 0;
10146 break;
10147 case 40:
10148 chwidth = 1;
10149 break;
10150 case 80:
10151 chwidth = 2;
10152 break;
10153 case 160:
10154 chwidth = 3;
10155 break;
10156 default:
10157 chwidth = 2;
10158 break;
10159 }
10160
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010161 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010162 }
10163
10164 /* Extract NSS */
10165 val = get_param(cmd, "NSS");
10166 if (val) {
10167 switch (atoi(val)) {
10168 case 1:
10169 nss = 1;
10170 break;
10171 case 2:
10172 nss = 3;
10173 break;
10174 case 3:
10175 nss = 7;
10176 break;
10177 default:
10178 /* We do not support NSS > 3 */
10179 nss = 3;
10180 break;
10181 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010182 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010183 }
10184
10185 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010186 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010187 }
10188
10189 return 1;
10190}
10191
10192
10193static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10194 struct sigma_conn *conn,
10195 struct sigma_cmd *cmd)
10196{
10197 switch (get_driver_type()) {
10198 case DRIVER_ATHEROS:
10199 return ath_sta_send_frame_vht(dut, conn, cmd);
10200 default:
10201 send_resp(dut, conn, SIGMA_ERROR,
10202 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10203 return 0;
10204 }
10205}
10206
10207
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010208static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10209 struct sigma_cmd *cmd)
10210{
10211 const char *val;
10212 const char *intf = get_param(cmd, "Interface");
10213
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010214 if (!intf)
10215 return -1;
10216
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010217 val = get_param(cmd, "framename");
10218 if (!val)
10219 return -1;
10220 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10221
10222 /* Command sequence to generate Op mode notification */
10223 if (val && strcasecmp(val, "action") == 0) {
10224 val = get_param(cmd, "PPDUTxType");
10225 if (val && strcasecmp(val, "TB") == 0) {
10226 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10227 sigma_dut_print(dut, DUT_MSG_ERROR,
10228 "failed to send TB PPDU Tx cfg");
10229 send_resp(dut, conn, SIGMA_ERROR,
10230 "ErrorCode,set TB PPDU Tx cfg failed");
10231 return 0;
10232 }
10233 return 1;
10234 }
10235
10236 sigma_dut_print(dut, DUT_MSG_ERROR,
10237 "Action Tx type is not defined");
10238 }
10239
10240 return 1;
10241}
10242
10243
10244static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10245 struct sigma_conn *conn,
10246 struct sigma_cmd *cmd)
10247{
10248 switch (get_driver_type()) {
10249 case DRIVER_WCN:
10250 return wcn_sta_send_frame_he(dut, conn, cmd);
10251 default:
10252 send_resp(dut, conn, SIGMA_ERROR,
10253 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10254 return 0;
10255 }
10256}
10257
10258
Lior David0fe101e2017-03-09 16:09:50 +020010259#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010260
10261static int
10262wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10263 const char *frame_name, const char *dest_mac)
10264{
10265 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10266 const char *ssid = get_param(cmd, "ssid");
10267 const char *countstr = get_param(cmd, "count");
10268 const char *channelstr = get_param(cmd, "channel");
10269 const char *group_id = get_param(cmd, "groupid");
10270 const char *client_id = get_param(cmd, "clientmac");
10271 int count, channel, freq, i;
10272 const char *fname;
10273 char frame[1024], src_mac[20], group_id_attr[25],
10274 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10275 const char *group_ssid;
10276 const int group_ssid_prefix_len = 9;
10277 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10278 size_t framelen = sizeof(frame);
10279 struct template_frame_tag tags[2];
10280 size_t tags_total = ARRAY_SIZE(tags);
10281 int tag_index, len, dst_len;
10282
10283 if (!countstr || !channelstr) {
10284 sigma_dut_print(dut, DUT_MSG_ERROR,
10285 "Missing argument: count, channel");
10286 return -1;
10287 }
10288 if (isprobereq && !ssid) {
10289 sigma_dut_print(dut, DUT_MSG_ERROR,
10290 "Missing argument: ssid");
10291 return -1;
10292 }
10293 if (!isprobereq && (!group_id || !client_id)) {
10294 sigma_dut_print(dut, DUT_MSG_ERROR,
10295 "Missing argument: group_id, client_id");
10296 return -1;
10297 }
10298
10299 count = atoi(countstr);
10300 channel = atoi(channelstr);
10301 freq = channel_to_freq(dut, channel);
10302
10303 if (!freq) {
10304 sigma_dut_print(dut, DUT_MSG_ERROR,
10305 "invalid channel: %s", channelstr);
10306 return -1;
10307 }
10308
10309 if (isprobereq) {
10310 if (strcasecmp(ssid, "wildcard") == 0) {
10311 fname = "probe_req_wildcard.txt";
10312 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10313 fname = "probe_req_P2P_Wildcard.txt";
10314 } else {
10315 sigma_dut_print(dut, DUT_MSG_ERROR,
10316 "invalid probe request type");
10317 return -1;
10318 }
10319 } else {
10320 fname = "P2P_device_discovery_req.txt";
10321 }
10322
10323 if (parse_template_frame_file(dut, fname, frame, &framelen,
10324 tags, &tags_total)) {
10325 sigma_dut_print(dut, DUT_MSG_ERROR,
10326 "invalid frame template: %s", fname);
10327 return -1;
10328 }
10329
10330 if (get_wpa_status(get_station_ifname(), "address",
10331 src_mac, sizeof(src_mac)) < 0 ||
10332 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10333 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10334 return -1;
10335 /* Use wildcard BSSID, since we are in PBSS */
10336 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10337
10338 if (!isprobereq) {
10339 tag_index = find_template_frame_tag(tags, tags_total, 1);
10340 if (tag_index < 0) {
10341 sigma_dut_print(dut, DUT_MSG_ERROR,
10342 "can't find device id attribute");
10343 return -1;
10344 }
10345 if (parse_mac_address(dut, client_id,
10346 (unsigned char *) client_mac)) {
10347 sigma_dut_print(dut, DUT_MSG_ERROR,
10348 "invalid client_id: %s", client_id);
10349 return -1;
10350 }
10351 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10352 framelen - tags[tag_index].offset,
10353 IEEE80211_P2P_ATTR_DEVICE_ID,
10354 client_mac, ETH_ALEN)) {
10355 sigma_dut_print(dut, DUT_MSG_ERROR,
10356 "fail to replace device id attribute");
10357 return -1;
10358 }
10359
10360 /*
10361 * group_id arg contains device MAC address followed by
10362 * space and SSID (DIRECT-somessid).
10363 * group id attribute contains device address (6 bytes)
10364 * followed by SSID prefix DIRECT-XX (9 bytes)
10365 */
10366 if (strlen(group_id) < sizeof(device_macstr)) {
10367 sigma_dut_print(dut, DUT_MSG_ERROR,
10368 "group_id arg too short");
10369 return -1;
10370 }
10371 memcpy(device_macstr, group_id, sizeof(device_macstr));
10372 device_macstr[sizeof(device_macstr) - 1] = '\0';
10373 if (parse_mac_address(dut, device_macstr,
10374 (unsigned char *) group_id_attr)) {
10375 sigma_dut_print(dut, DUT_MSG_ERROR,
10376 "fail to parse device address from group_id");
10377 return -1;
10378 }
10379 group_ssid = strchr(group_id, ' ');
10380 if (!group_ssid) {
10381 sigma_dut_print(dut, DUT_MSG_ERROR,
10382 "invalid group_id arg, no ssid");
10383 return -1;
10384 }
10385 group_ssid++;
10386 len = strlen(group_ssid);
10387 if (len < group_ssid_prefix_len) {
10388 sigma_dut_print(dut, DUT_MSG_ERROR,
10389 "group_id SSID too short");
10390 return -1;
10391 }
10392 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10393 if (len > dst_len) {
10394 sigma_dut_print(dut, DUT_MSG_ERROR,
10395 "group_id SSID (%s) too long",
10396 group_ssid);
10397 return -1;
10398 }
10399
10400 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10401 tag_index = find_template_frame_tag(tags, tags_total, 2);
10402 if (tag_index < 0) {
10403 sigma_dut_print(dut, DUT_MSG_ERROR,
10404 "can't find group id attribute");
10405 return -1;
10406 }
10407 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10408 framelen - tags[tag_index].offset,
10409 IEEE80211_P2P_ATTR_GROUP_ID,
10410 group_id_attr,
10411 sizeof(group_id_attr))) {
10412 sigma_dut_print(dut, DUT_MSG_ERROR,
10413 "fail to replace group id attribute");
10414 return -1;
10415 }
10416 }
10417
10418 for (i = 0; i < count; i++) {
10419 if (wil6210_transmit_frame(dut, freq,
10420 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10421 frame, framelen)) {
10422 sigma_dut_print(dut, DUT_MSG_ERROR,
10423 "fail to transmit probe request frame");
10424 return -1;
10425 }
10426 }
10427
10428 return 0;
10429}
10430
10431
Lior David0fe101e2017-03-09 16:09:50 +020010432int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10433 struct sigma_cmd *cmd)
10434{
10435 const char *frame_name = get_param(cmd, "framename");
10436 const char *mac = get_param(cmd, "dest_mac");
10437
10438 if (!frame_name || !mac) {
10439 sigma_dut_print(dut, DUT_MSG_ERROR,
10440 "framename and dest_mac must be provided");
10441 return -1;
10442 }
10443
10444 if (strcasecmp(frame_name, "brp") == 0) {
10445 const char *l_rx = get_param(cmd, "L-RX");
10446 int l_rx_i;
10447
10448 if (!l_rx) {
10449 sigma_dut_print(dut, DUT_MSG_ERROR,
10450 "L-RX must be provided");
10451 return -1;
10452 }
10453 l_rx_i = atoi(l_rx);
10454
10455 sigma_dut_print(dut, DUT_MSG_INFO,
10456 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10457 mac, l_rx);
10458 if (l_rx_i != 16) {
10459 sigma_dut_print(dut, DUT_MSG_ERROR,
10460 "unsupported L-RX: %s", l_rx);
10461 return -1;
10462 }
10463
10464 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10465 return -1;
10466 } else if (strcasecmp(frame_name, "ssw") == 0) {
10467 sigma_dut_print(dut, DUT_MSG_INFO,
10468 "dev_send_frame: SLS, dest_mac %s", mac);
10469 if (wil6210_send_sls(dut, mac))
10470 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010471 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10472 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10473 sigma_dut_print(dut, DUT_MSG_INFO,
10474 "dev_send_frame: %s, dest_mac %s", frame_name,
10475 mac);
10476 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10477 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010478 } else {
10479 sigma_dut_print(dut, DUT_MSG_ERROR,
10480 "unsupported frame type: %s", frame_name);
10481 return -1;
10482 }
10483
10484 return 1;
10485}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010486
Lior David0fe101e2017-03-09 16:09:50 +020010487#endif /* __linux__ */
10488
10489
10490static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10491 struct sigma_conn *conn,
10492 struct sigma_cmd *cmd)
10493{
10494 switch (get_driver_type()) {
10495#ifdef __linux__
10496 case DRIVER_WIL6210:
10497 return wil6210_send_frame_60g(dut, conn, cmd);
10498#endif /* __linux__ */
10499 default:
10500 send_resp(dut, conn, SIGMA_ERROR,
10501 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10502 return 0;
10503 }
10504}
10505
10506
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010507static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10508 const char *intf, struct sigma_cmd *cmd)
10509{
10510 const char *val, *addr;
10511 char buf[100];
10512
10513 addr = get_param(cmd, "DestMac");
10514 if (!addr) {
10515 send_resp(dut, conn, SIGMA_INVALID,
10516 "ErrorCode,AP MAC address is missing");
10517 return 0;
10518 }
10519
10520 val = get_param(cmd, "ANQPQuery_ID");
10521 if (!val) {
10522 send_resp(dut, conn, SIGMA_INVALID,
10523 "ErrorCode,Missing ANQPQuery_ID");
10524 return 0;
10525 }
10526
10527 if (strcasecmp(val, "NeighborReportReq") == 0) {
10528 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10529 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10530 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10531 } else {
10532 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10533 val);
10534 send_resp(dut, conn, SIGMA_INVALID,
10535 "ErrorCode,Invalid ANQPQuery_ID");
10536 return 0;
10537 }
10538
Ashwini Patild174f2c2017-04-13 16:49:46 +053010539 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10540 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10541 * if associated, AP BSSID).
10542 */
10543 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10544 send_resp(dut, conn, SIGMA_ERROR,
10545 "ErrorCode,Failed to set gas_address3");
10546 return 0;
10547 }
10548
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010549 if (wpa_command(intf, buf) < 0) {
10550 send_resp(dut, conn, SIGMA_ERROR,
10551 "ErrorCode,Failed to send ANQP query");
10552 return 0;
10553 }
10554
10555 return 1;
10556}
10557
10558
10559static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10560 struct sigma_conn *conn,
10561 const char *intf,
10562 struct sigma_cmd *cmd)
10563{
10564 const char *val = get_param(cmd, "FrameName");
10565
10566 if (val && strcasecmp(val, "ANQPQuery") == 0)
10567 return mbo_send_anqp_query(dut, conn, intf, cmd);
10568
10569 return 2;
10570}
10571
10572
Jouni Malinenf7222712019-06-13 01:50:21 +030010573enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10574 struct sigma_conn *conn,
10575 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010576{
10577 const char *intf = get_param(cmd, "Interface");
10578 const char *val;
10579 enum send_frame_type frame;
10580 enum send_frame_protection protected;
10581 char buf[100];
10582 unsigned char addr[ETH_ALEN];
10583 int res;
10584
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010585 if (!intf)
10586 return -1;
10587
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010588 val = get_param(cmd, "program");
10589 if (val == NULL)
10590 val = get_param(cmd, "frame");
10591 if (val && strcasecmp(val, "TDLS") == 0)
10592 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10593 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010594 strcasecmp(val, "HS2-R2") == 0 ||
10595 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010596 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10597 if (val && strcasecmp(val, "VHT") == 0)
10598 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010599 if (val && strcasecmp(val, "HE") == 0)
10600 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010601 if (val && strcasecmp(val, "LOC") == 0)
10602 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010603 if (val && strcasecmp(val, "60GHz") == 0)
10604 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010605 if (val && strcasecmp(val, "MBO") == 0) {
10606 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10607 if (res != 2)
10608 return res;
10609 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010610
10611 val = get_param(cmd, "TD_DISC");
10612 if (val) {
10613 if (hwaddr_aton(val, addr) < 0)
10614 return -1;
10615 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10616 if (wpa_command(intf, buf) < 0) {
10617 send_resp(dut, conn, SIGMA_ERROR,
10618 "ErrorCode,Failed to send TDLS discovery");
10619 return 0;
10620 }
10621 return 1;
10622 }
10623
10624 val = get_param(cmd, "TD_Setup");
10625 if (val) {
10626 if (hwaddr_aton(val, addr) < 0)
10627 return -1;
10628 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10629 if (wpa_command(intf, buf) < 0) {
10630 send_resp(dut, conn, SIGMA_ERROR,
10631 "ErrorCode,Failed to start TDLS setup");
10632 return 0;
10633 }
10634 return 1;
10635 }
10636
10637 val = get_param(cmd, "TD_TearDown");
10638 if (val) {
10639 if (hwaddr_aton(val, addr) < 0)
10640 return -1;
10641 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10642 if (wpa_command(intf, buf) < 0) {
10643 send_resp(dut, conn, SIGMA_ERROR,
10644 "ErrorCode,Failed to tear down TDLS link");
10645 return 0;
10646 }
10647 return 1;
10648 }
10649
10650 val = get_param(cmd, "TD_ChannelSwitch");
10651 if (val) {
10652 /* TODO */
10653 send_resp(dut, conn, SIGMA_ERROR,
10654 "ErrorCode,TD_ChannelSwitch not yet supported");
10655 return 0;
10656 }
10657
10658 val = get_param(cmd, "TD_NF");
10659 if (val) {
10660 /* TODO */
10661 send_resp(dut, conn, SIGMA_ERROR,
10662 "ErrorCode,TD_NF not yet supported");
10663 return 0;
10664 }
10665
10666 val = get_param(cmd, "PMFFrameType");
10667 if (val == NULL)
10668 val = get_param(cmd, "FrameName");
10669 if (val == NULL)
10670 val = get_param(cmd, "Type");
10671 if (val == NULL)
10672 return -1;
10673 if (strcasecmp(val, "disassoc") == 0)
10674 frame = DISASSOC;
10675 else if (strcasecmp(val, "deauth") == 0)
10676 frame = DEAUTH;
10677 else if (strcasecmp(val, "saquery") == 0)
10678 frame = SAQUERY;
10679 else if (strcasecmp(val, "auth") == 0)
10680 frame = AUTH;
10681 else if (strcasecmp(val, "assocreq") == 0)
10682 frame = ASSOCREQ;
10683 else if (strcasecmp(val, "reassocreq") == 0)
10684 frame = REASSOCREQ;
10685 else if (strcasecmp(val, "neigreq") == 0) {
10686 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10687
10688 val = get_param(cmd, "ssid");
10689 if (val == NULL)
10690 return -1;
10691
10692 res = send_neighbor_request(dut, intf, val);
10693 if (res) {
10694 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10695 "Failed to send neighbor report request");
10696 return 0;
10697 }
10698
10699 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010700 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10701 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010702 sigma_dut_print(dut, DUT_MSG_DEBUG,
10703 "Got Transition Management Query");
10704
Ashwini Patil5acd7382017-04-13 15:55:04 +053010705 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010706 if (res) {
10707 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10708 "Failed to send Transition Management Query");
10709 return 0;
10710 }
10711
10712 return 1;
10713 } else {
10714 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10715 "PMFFrameType");
10716 return 0;
10717 }
10718
10719 val = get_param(cmd, "PMFProtected");
10720 if (val == NULL)
10721 val = get_param(cmd, "Protected");
10722 if (val == NULL)
10723 return -1;
10724 if (strcasecmp(val, "Correct-key") == 0 ||
10725 strcasecmp(val, "CorrectKey") == 0)
10726 protected = CORRECT_KEY;
10727 else if (strcasecmp(val, "IncorrectKey") == 0)
10728 protected = INCORRECT_KEY;
10729 else if (strcasecmp(val, "Unprotected") == 0)
10730 protected = UNPROTECTED;
10731 else {
10732 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10733 "PMFProtected");
10734 return 0;
10735 }
10736
10737 if (protected != UNPROTECTED &&
10738 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10739 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10740 "PMFProtected for auth/assocreq/reassocreq");
10741 return 0;
10742 }
10743
10744 if (if_nametoindex("sigmadut") == 0) {
10745 snprintf(buf, sizeof(buf),
10746 "iw dev %s interface add sigmadut type monitor",
10747 get_station_ifname());
10748 if (system(buf) != 0 ||
10749 if_nametoindex("sigmadut") == 0) {
10750 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10751 "monitor interface with '%s'", buf);
10752 return -2;
10753 }
10754 }
10755
10756 if (system("ifconfig sigmadut up") != 0) {
10757 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10758 "monitor interface up");
10759 return -2;
10760 }
10761
10762 return sta_inject_frame(dut, conn, frame, protected, NULL);
10763}
10764
10765
10766static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10767 struct sigma_conn *conn,
10768 struct sigma_cmd *cmd,
10769 const char *ifname)
10770{
10771 char buf[200];
10772 const char *val;
10773
10774 val = get_param(cmd, "ClearARP");
10775 if (val && atoi(val) == 1) {
10776 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10777 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10778 if (system(buf) != 0) {
10779 send_resp(dut, conn, SIGMA_ERROR,
10780 "errorCode,Failed to clear ARP cache");
10781 return 0;
10782 }
10783 }
10784
10785 return 1;
10786}
10787
10788
10789int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10790 struct sigma_cmd *cmd)
10791{
10792 const char *intf = get_param(cmd, "Interface");
10793 const char *val;
10794
10795 if (intf == NULL)
10796 return -1;
10797
10798 val = get_param(cmd, "program");
10799 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010800 strcasecmp(val, "HS2-R2") == 0 ||
10801 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010802 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10803
10804 return -1;
10805}
10806
10807
Jouni Malinenf7222712019-06-13 01:50:21 +030010808static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
10809 struct sigma_conn *conn,
10810 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010811{
10812 const char *intf = get_param(cmd, "Interface");
10813 const char *mac = get_param(cmd, "MAC");
10814
10815 if (intf == NULL || mac == NULL)
10816 return -1;
10817
10818 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10819 "interface %s to %s", intf, mac);
10820
10821 if (dut->set_macaddr) {
10822 char buf[128];
10823 int res;
10824 if (strcasecmp(mac, "default") == 0) {
10825 res = snprintf(buf, sizeof(buf), "%s",
10826 dut->set_macaddr);
10827 dut->tmp_mac_addr = 0;
10828 } else {
10829 res = snprintf(buf, sizeof(buf), "%s %s",
10830 dut->set_macaddr, mac);
10831 dut->tmp_mac_addr = 1;
10832 }
10833 if (res < 0 || res >= (int) sizeof(buf))
10834 return -1;
10835 if (system(buf) != 0) {
10836 send_resp(dut, conn, SIGMA_ERROR,
10837 "errorCode,Failed to set MAC "
10838 "address");
10839 return 0;
10840 }
10841 return 1;
10842 }
10843
10844 if (strcasecmp(mac, "default") == 0)
10845 return 1;
10846
10847 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10848 "command");
10849 return 0;
10850}
10851
10852
10853static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
10854 struct sigma_conn *conn, const char *intf,
10855 int val)
10856{
10857 char buf[200];
10858 int res;
10859
10860 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
10861 intf, val);
10862 if (res < 0 || res >= (int) sizeof(buf))
10863 return -1;
10864 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10865 if (system(buf) != 0) {
10866 send_resp(dut, conn, SIGMA_ERROR,
10867 "errorCode,Failed to configure offchannel mode");
10868 return 0;
10869 }
10870
10871 return 1;
10872}
10873
10874
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010875static int off_chan_val(enum sec_ch_offset off)
10876{
10877 switch (off) {
10878 case SEC_CH_NO:
10879 return 0;
10880 case SEC_CH_40ABOVE:
10881 return 40;
10882 case SEC_CH_40BELOW:
10883 return -40;
10884 }
10885
10886 return 0;
10887}
10888
10889
10890static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
10891 const char *intf, int off_ch_num,
10892 enum sec_ch_offset sec)
10893{
10894 char buf[200];
10895 int res;
10896
10897 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
10898 intf, off_ch_num);
10899 if (res < 0 || res >= (int) sizeof(buf))
10900 return -1;
10901 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10902 if (system(buf) != 0) {
10903 send_resp(dut, conn, SIGMA_ERROR,
10904 "errorCode,Failed to set offchan");
10905 return 0;
10906 }
10907
10908 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
10909 intf, off_chan_val(sec));
10910 if (res < 0 || res >= (int) sizeof(buf))
10911 return -1;
10912 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10913 if (system(buf) != 0) {
10914 send_resp(dut, conn, SIGMA_ERROR,
10915 "errorCode,Failed to set sec chan offset");
10916 return 0;
10917 }
10918
10919 return 1;
10920}
10921
10922
10923static int tdls_set_offchannel_offset(struct sigma_dut *dut,
10924 struct sigma_conn *conn,
10925 const char *intf, int off_ch_num,
10926 enum sec_ch_offset sec)
10927{
10928 char buf[200];
10929 int res;
10930
10931 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
10932 off_ch_num);
10933 if (res < 0 || res >= (int) sizeof(buf))
10934 return -1;
10935 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10936
10937 if (wpa_command(intf, buf) < 0) {
10938 send_resp(dut, conn, SIGMA_ERROR,
10939 "ErrorCode,Failed to set offchan");
10940 return 0;
10941 }
10942 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
10943 off_chan_val(sec));
10944 if (res < 0 || res >= (int) sizeof(buf))
10945 return -1;
10946
10947 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10948
10949 if (wpa_command(intf, buf) < 0) {
10950 send_resp(dut, conn, SIGMA_ERROR,
10951 "ErrorCode,Failed to set sec chan offset");
10952 return 0;
10953 }
10954
10955 return 1;
10956}
10957
10958
10959static int tdls_set_offchannel_mode(struct sigma_dut *dut,
10960 struct sigma_conn *conn,
10961 const char *intf, int val)
10962{
10963 char buf[200];
10964 int res;
10965
10966 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
10967 val);
10968 if (res < 0 || res >= (int) sizeof(buf))
10969 return -1;
10970 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10971
10972 if (wpa_command(intf, buf) < 0) {
10973 send_resp(dut, conn, SIGMA_ERROR,
10974 "ErrorCode,Failed to configure offchannel mode");
10975 return 0;
10976 }
10977
10978 return 1;
10979}
10980
10981
10982static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
10983 struct sigma_conn *conn,
10984 struct sigma_cmd *cmd)
10985{
10986 const char *val;
10987 enum {
10988 CHSM_NOT_SET,
10989 CHSM_ENABLE,
10990 CHSM_DISABLE,
10991 CHSM_REJREQ,
10992 CHSM_UNSOLRESP
10993 } chsm = CHSM_NOT_SET;
10994 int off_ch_num = -1;
10995 enum sec_ch_offset sec_ch = SEC_CH_NO;
10996 int res;
10997
10998 val = get_param(cmd, "Uapsd");
10999 if (val) {
11000 char buf[100];
11001 if (strcasecmp(val, "Enable") == 0)
11002 snprintf(buf, sizeof(buf), "SET ps 99");
11003 else if (strcasecmp(val, "Disable") == 0)
11004 snprintf(buf, sizeof(buf), "SET ps 98");
11005 else {
11006 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11007 "Unsupported uapsd parameter value");
11008 return 0;
11009 }
11010 if (wpa_command(intf, buf)) {
11011 send_resp(dut, conn, SIGMA_ERROR,
11012 "ErrorCode,Failed to change U-APSD "
11013 "powersave mode");
11014 return 0;
11015 }
11016 }
11017
11018 val = get_param(cmd, "TPKTIMER");
11019 if (val && strcasecmp(val, "DISABLE") == 0) {
11020 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11021 send_resp(dut, conn, SIGMA_ERROR,
11022 "ErrorCode,Failed to enable no TPK "
11023 "expiration test mode");
11024 return 0;
11025 }
11026 dut->no_tpk_expiration = 1;
11027 }
11028
11029 val = get_param(cmd, "ChSwitchMode");
11030 if (val) {
11031 if (strcasecmp(val, "Enable") == 0 ||
11032 strcasecmp(val, "Initiate") == 0)
11033 chsm = CHSM_ENABLE;
11034 else if (strcasecmp(val, "Disable") == 0 ||
11035 strcasecmp(val, "passive") == 0)
11036 chsm = CHSM_DISABLE;
11037 else if (strcasecmp(val, "RejReq") == 0)
11038 chsm = CHSM_REJREQ;
11039 else if (strcasecmp(val, "UnSolResp") == 0)
11040 chsm = CHSM_UNSOLRESP;
11041 else {
11042 send_resp(dut, conn, SIGMA_ERROR,
11043 "ErrorCode,Unknown ChSwitchMode value");
11044 return 0;
11045 }
11046 }
11047
11048 val = get_param(cmd, "OffChNum");
11049 if (val) {
11050 off_ch_num = atoi(val);
11051 if (off_ch_num == 0) {
11052 send_resp(dut, conn, SIGMA_ERROR,
11053 "ErrorCode,Invalid OffChNum");
11054 return 0;
11055 }
11056 }
11057
11058 val = get_param(cmd, "SecChOffset");
11059 if (val) {
11060 if (strcmp(val, "20") == 0)
11061 sec_ch = SEC_CH_NO;
11062 else if (strcasecmp(val, "40above") == 0)
11063 sec_ch = SEC_CH_40ABOVE;
11064 else if (strcasecmp(val, "40below") == 0)
11065 sec_ch = SEC_CH_40BELOW;
11066 else {
11067 send_resp(dut, conn, SIGMA_ERROR,
11068 "ErrorCode,Unknown SecChOffset value");
11069 return 0;
11070 }
11071 }
11072
11073 if (chsm == CHSM_NOT_SET) {
11074 /* no offchannel changes requested */
11075 return 1;
11076 }
11077
11078 if (strcmp(intf, get_main_ifname()) != 0 &&
11079 strcmp(intf, get_station_ifname()) != 0) {
11080 send_resp(dut, conn, SIGMA_ERROR,
11081 "ErrorCode,Unknown interface");
11082 return 0;
11083 }
11084
11085 switch (chsm) {
11086 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011087 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011088 break;
11089 case CHSM_ENABLE:
11090 if (off_ch_num < 0) {
11091 send_resp(dut, conn, SIGMA_ERROR,
11092 "ErrorCode,Missing OffChNum argument");
11093 return 0;
11094 }
11095 if (wifi_chip_type == DRIVER_WCN) {
11096 res = tdls_set_offchannel_offset(dut, conn, intf,
11097 off_ch_num, sec_ch);
11098 } else {
11099 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11100 sec_ch);
11101 }
11102 if (res != 1)
11103 return res;
11104 if (wifi_chip_type == DRIVER_WCN)
11105 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11106 else
11107 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11108 break;
11109 case CHSM_DISABLE:
11110 if (wifi_chip_type == DRIVER_WCN)
11111 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11112 else
11113 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11114 break;
11115 case CHSM_REJREQ:
11116 if (wifi_chip_type == DRIVER_WCN)
11117 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11118 else
11119 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11120 break;
11121 case CHSM_UNSOLRESP:
11122 if (off_ch_num < 0) {
11123 send_resp(dut, conn, SIGMA_ERROR,
11124 "ErrorCode,Missing OffChNum argument");
11125 return 0;
11126 }
11127 if (wifi_chip_type == DRIVER_WCN) {
11128 res = tdls_set_offchannel_offset(dut, conn, intf,
11129 off_ch_num, sec_ch);
11130 } else {
11131 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11132 sec_ch);
11133 }
11134 if (res != 1)
11135 return res;
11136 if (wifi_chip_type == DRIVER_WCN)
11137 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11138 else
11139 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11140 break;
11141 }
11142
11143 return res;
11144}
11145
11146
11147static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11148 struct sigma_conn *conn,
11149 struct sigma_cmd *cmd)
11150{
11151 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011152 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011153
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011154 novap_reset(dut, intf);
11155
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011156 val = get_param(cmd, "nss_mcs_opt");
11157 if (val) {
11158 /* String (nss_operating_mode; mcs_operating_mode) */
11159 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011160 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011161
11162 token = strdup(val);
11163 if (!token)
11164 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011165 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011166 if (!result) {
11167 sigma_dut_print(dut, DUT_MSG_ERROR,
11168 "VHT NSS not specified");
11169 goto failed;
11170 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011171 if (strcasecmp(result, "def") != 0) {
11172 nss = atoi(result);
11173 if (nss == 4)
11174 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011175 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011176 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011177
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011178 }
11179
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011180 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011181 if (!result) {
11182 sigma_dut_print(dut, DUT_MSG_ERROR,
11183 "VHT MCS not specified");
11184 goto failed;
11185 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011186 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011187 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011188 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011189 } else {
11190 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011191 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011192 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011193 }
11194 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011195 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011196 }
11197
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011198 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011199 return 1;
11200failed:
11201 free(token);
11202 return 0;
11203}
11204
11205
11206static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11207 struct sigma_conn *conn,
11208 struct sigma_cmd *cmd)
11209{
11210 switch (get_driver_type()) {
11211 case DRIVER_ATHEROS:
11212 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11213 default:
11214 send_resp(dut, conn, SIGMA_ERROR,
11215 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11216 return 0;
11217 }
11218}
11219
11220
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011221static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11222 struct sigma_conn *conn,
11223 struct sigma_cmd *cmd)
11224{
11225 const char *val;
11226 char *token = NULL, *result;
11227 char buf[60];
11228
11229 val = get_param(cmd, "nss_mcs_opt");
11230 if (val) {
11231 /* String (nss_operating_mode; mcs_operating_mode) */
11232 int nss, mcs, ratecode;
11233 char *saveptr;
11234
11235 token = strdup(val);
11236 if (!token)
11237 return -2;
11238
11239 result = strtok_r(token, ";", &saveptr);
11240 if (!result) {
11241 sigma_dut_print(dut, DUT_MSG_ERROR,
11242 "HE NSS not specified");
11243 goto failed;
11244 }
11245 nss = 1;
11246 if (strcasecmp(result, "def") != 0)
11247 nss = atoi(result);
11248
11249 result = strtok_r(NULL, ";", &saveptr);
11250 if (!result) {
11251 sigma_dut_print(dut, DUT_MSG_ERROR,
11252 "HE MCS not specified");
11253 goto failed;
11254 }
11255 mcs = 7;
11256 if (strcasecmp(result, "def") != 0)
11257 mcs = atoi(result);
11258
Arif Hussain557bf412018-05-25 17:29:36 -070011259 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011260 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011261 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011262 } else if (nss > 2) {
11263 sigma_dut_print(dut, DUT_MSG_ERROR,
11264 "HE NSS %d not supported", nss);
11265 goto failed;
11266 }
11267
Arif Hussain557bf412018-05-25 17:29:36 -070011268 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11269 if (system(buf) != 0) {
11270 sigma_dut_print(dut, DUT_MSG_ERROR,
11271 "nss_mcs_opt: iwpriv %s nss %d failed",
11272 intf, nss);
11273 goto failed;
11274 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011275 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011276
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011277 /* Add the MCS to the ratecode */
11278 if (mcs >= 0 && mcs <= 11) {
11279 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011280#ifdef NL80211_SUPPORT
11281 if (dut->device_type == STA_testbed) {
11282 enum he_mcs_config mcs_config;
11283 int ret;
11284
11285 if (mcs <= 7)
11286 mcs_config = HE_80_MCS0_7;
11287 else if (mcs <= 9)
11288 mcs_config = HE_80_MCS0_9;
11289 else
11290 mcs_config = HE_80_MCS0_11;
11291 ret = sta_set_he_mcs(dut, intf, mcs_config);
11292 if (ret) {
11293 sigma_dut_print(dut, DUT_MSG_ERROR,
11294 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11295 mcs, mcs_config, ret);
11296 goto failed;
11297 }
11298 }
11299#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011300 } else {
11301 sigma_dut_print(dut, DUT_MSG_ERROR,
11302 "HE MCS %d not supported", mcs);
11303 goto failed;
11304 }
11305 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11306 intf, ratecode);
11307 if (system(buf) != 0) {
11308 sigma_dut_print(dut, DUT_MSG_ERROR,
11309 "iwpriv setting of 11ax rates failed");
11310 goto failed;
11311 }
11312 free(token);
11313 }
11314
11315 val = get_param(cmd, "GI");
11316 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011317 int fix_rate_sgi;
11318
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011319 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011320 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011321 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011322 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011323 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11324 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011325 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011326 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011327 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11328 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011329 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011330 } else {
11331 send_resp(dut, conn, SIGMA_ERROR,
11332 "errorCode,GI value not supported");
11333 return 0;
11334 }
11335 if (system(buf) != 0) {
11336 send_resp(dut, conn, SIGMA_ERROR,
11337 "errorCode,Failed to set shortgi");
11338 return 0;
11339 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011340 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11341 intf, fix_rate_sgi);
11342 if (system(buf) != 0) {
11343 send_resp(dut, conn, SIGMA_ERROR,
11344 "errorCode,Failed to set fix rate shortgi");
11345 return STATUS_SENT;
11346 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011347 }
11348
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011349 val = get_param(cmd, "LTF");
11350 if (val) {
11351#ifdef NL80211_SUPPORT
11352 if (strcmp(val, "3.2") == 0) {
11353 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11354 } if (strcmp(val, "6.4") == 0) {
11355 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11356 } else if (strcmp(val, "12.8") == 0) {
11357 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11358 } else {
11359 send_resp(dut, conn, SIGMA_ERROR,
11360 "errorCode, LTF value not supported");
11361 return 0;
11362 }
11363#else /* NL80211_SUPPORT */
11364 sigma_dut_print(dut, DUT_MSG_ERROR,
11365 "LTF cannot be set without NL80211_SUPPORT defined");
11366 return -2;
11367#endif /* NL80211_SUPPORT */
11368 }
11369
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011370 val = get_param(cmd, "TxSUPPDU");
11371 if (val) {
11372 int set_val = 1;
11373
11374 if (strcasecmp(val, "Enable") == 0)
11375 set_val = 1;
11376 else if (strcasecmp(val, "Disable") == 0)
11377 set_val = 0;
11378
11379 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11380 send_resp(dut, conn, SIGMA_ERROR,
11381 "ErrorCode,Failed to set Tx SU PPDU config");
11382 return 0;
11383 }
11384 }
11385
Arif Hussain480d5f42019-03-12 14:40:42 -070011386 val = get_param(cmd, "TWT_Setup");
11387 if (val) {
11388 if (strcasecmp(val, "Request") == 0) {
11389 if (sta_twt_request(dut, conn, cmd)) {
11390 send_resp(dut, conn, SIGMA_ERROR,
11391 "ErrorCode,sta_twt_request failed");
11392 return STATUS_SENT;
11393 }
11394 } else if (strcasecmp(val, "Teardown") == 0) {
11395 if (sta_twt_teardown(dut, conn, cmd)) {
11396 send_resp(dut, conn, SIGMA_ERROR,
11397 "ErrorCode,sta_twt_teardown failed");
11398 return STATUS_SENT;
11399 }
11400 }
11401 }
11402
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011403 val = get_param(cmd, "transmitOMI");
11404 if (val && sta_transmit_omi(dut, conn, cmd)) {
11405 send_resp(dut, conn, SIGMA_ERROR,
11406 "ErrorCode,sta_transmit_omi failed");
11407 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011408 }
11409
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011410 val = get_param(cmd, "Powersave");
11411 if (val) {
11412 char buf[60];
11413
11414 if (strcasecmp(val, "off") == 0) {
11415 snprintf(buf, sizeof(buf),
11416 "iwpriv %s setPower 2", intf);
11417 if (system(buf) != 0) {
11418 sigma_dut_print(dut, DUT_MSG_ERROR,
11419 "iwpriv setPower 2 failed");
11420 return 0;
11421 }
11422 } else if (strcasecmp(val, "on") == 0) {
11423 snprintf(buf, sizeof(buf),
11424 "iwpriv %s setPower 1", intf);
11425 if (system(buf) != 0) {
11426 sigma_dut_print(dut, DUT_MSG_ERROR,
11427 "iwpriv setPower 1 failed");
11428 return 0;
11429 }
11430 } else {
11431 sigma_dut_print(dut, DUT_MSG_ERROR,
11432 "Unsupported Powersave value '%s'",
11433 val);
11434 return -1;
11435 }
11436 }
11437
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011438 val = get_param(cmd, "MU_EDCA");
11439 if (val) {
11440 if (strcasecmp(val, "Override") == 0) {
11441 if (sta_set_mu_edca_override(dut, intf, 1)) {
11442 send_resp(dut, conn, SIGMA_ERROR,
11443 "errorCode,MU EDCA override set failed");
11444 return STATUS_SENT;
11445 }
11446 } else if (strcasecmp(val, "Disable") == 0) {
11447 if (sta_set_mu_edca_override(dut, intf, 0)) {
11448 send_resp(dut, conn, SIGMA_ERROR,
11449 "errorCode,MU EDCA override disable failed");
11450 return STATUS_SENT;
11451 }
11452 }
11453 }
11454
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011455 return 1;
11456
11457failed:
11458 free(token);
11459 return -2;
11460}
11461
11462
11463static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11464 struct sigma_conn *conn,
11465 struct sigma_cmd *cmd)
11466{
11467 switch (get_driver_type()) {
11468 case DRIVER_WCN:
11469 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11470 default:
11471 send_resp(dut, conn, SIGMA_ERROR,
11472 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11473 return 0;
11474 }
11475}
11476
11477
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011478static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11479 struct sigma_conn *conn,
11480 struct sigma_cmd *cmd)
11481{
11482 const char *val;
11483
11484 val = get_param(cmd, "powersave");
11485 if (val) {
11486 char buf[60];
11487
11488 if (strcasecmp(val, "off") == 0) {
11489 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11490 intf);
11491 if (system(buf) != 0) {
11492 sigma_dut_print(dut, DUT_MSG_ERROR,
11493 "iwpriv setPower 2 failed");
11494 return 0;
11495 }
11496 } else if (strcasecmp(val, "on") == 0) {
11497 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11498 intf);
11499 if (system(buf) != 0) {
11500 sigma_dut_print(dut, DUT_MSG_ERROR,
11501 "iwpriv setPower 1 failed");
11502 return 0;
11503 }
11504 } else {
11505 sigma_dut_print(dut, DUT_MSG_ERROR,
11506 "Unsupported power save config");
11507 return -1;
11508 }
11509 return 1;
11510 }
11511
11512 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11513
11514 return 0;
11515}
11516
11517
Ashwini Patil5acd7382017-04-13 15:55:04 +053011518static int btm_query_candidate_list(struct sigma_dut *dut,
11519 struct sigma_conn *conn,
11520 struct sigma_cmd *cmd)
11521{
11522 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11523 int len, ret;
11524 char buf[10];
11525
11526 /*
11527 * Neighbor Report elements format:
11528 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11529 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11530 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11531 */
11532
11533 bssid = get_param(cmd, "Nebor_BSSID");
11534 if (!bssid) {
11535 send_resp(dut, conn, SIGMA_INVALID,
11536 "errorCode,Nebor_BSSID is missing");
11537 return 0;
11538 }
11539
11540 info = get_param(cmd, "Nebor_Bssid_Info");
11541 if (!info) {
11542 sigma_dut_print(dut, DUT_MSG_INFO,
11543 "Using default value for Nebor_Bssid_Info: %s",
11544 DEFAULT_NEIGHBOR_BSSID_INFO);
11545 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11546 }
11547
11548 op_class = get_param(cmd, "Nebor_Op_Class");
11549 if (!op_class) {
11550 send_resp(dut, conn, SIGMA_INVALID,
11551 "errorCode,Nebor_Op_Class is missing");
11552 return 0;
11553 }
11554
11555 ch = get_param(cmd, "Nebor_Op_Ch");
11556 if (!ch) {
11557 send_resp(dut, conn, SIGMA_INVALID,
11558 "errorCode,Nebor_Op_Ch is missing");
11559 return 0;
11560 }
11561
11562 phy_type = get_param(cmd, "Nebor_Phy_Type");
11563 if (!phy_type) {
11564 sigma_dut_print(dut, DUT_MSG_INFO,
11565 "Using default value for Nebor_Phy_Type: %s",
11566 DEFAULT_NEIGHBOR_PHY_TYPE);
11567 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11568 }
11569
11570 /* Parse optional subelements */
11571 buf[0] = '\0';
11572 pref = get_param(cmd, "Nebor_Pref");
11573 if (pref) {
11574 /* hexdump for preferrence subelement */
11575 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11576 if (ret < 0 || ret >= (int) sizeof(buf)) {
11577 sigma_dut_print(dut, DUT_MSG_ERROR,
11578 "snprintf failed for optional subelement ret: %d",
11579 ret);
11580 send_resp(dut, conn, SIGMA_ERROR,
11581 "errorCode,snprintf failed for subelement");
11582 return 0;
11583 }
11584 }
11585
11586 if (!dut->btm_query_cand_list) {
11587 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11588 if (!dut->btm_query_cand_list) {
11589 send_resp(dut, conn, SIGMA_ERROR,
11590 "errorCode,Failed to allocate memory for btm_query_cand_list");
11591 return 0;
11592 }
11593 }
11594
11595 len = strlen(dut->btm_query_cand_list);
11596 ret = snprintf(dut->btm_query_cand_list + len,
11597 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11598 bssid, info, op_class, ch, phy_type, buf);
11599 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11600 sigma_dut_print(dut, DUT_MSG_ERROR,
11601 "snprintf failed for neighbor report list ret: %d",
11602 ret);
11603 send_resp(dut, conn, SIGMA_ERROR,
11604 "errorCode,snprintf failed for neighbor report");
11605 free(dut->btm_query_cand_list);
11606 dut->btm_query_cand_list = NULL;
11607 return 0;
11608 }
11609
11610 return 1;
11611}
11612
11613
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011614int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11615 struct sigma_ese_alloc *allocs, int *allocs_size)
11616{
11617 int max_count = *allocs_size;
11618 int count = 0, i;
11619 const char *val;
11620
11621 do {
11622 val = get_param_indexed(cmd, "AllocID", count);
11623 if (val)
11624 count++;
11625 } while (val);
11626
11627 if (count == 0 || count > max_count) {
11628 sigma_dut_print(dut, DUT_MSG_ERROR,
11629 "Invalid number of allocations(%d)", count);
11630 return -1;
11631 }
11632
11633 for (i = 0; i < count; i++) {
11634 val = get_param_indexed(cmd, "PercentBI", i);
11635 if (!val) {
11636 sigma_dut_print(dut, DUT_MSG_ERROR,
11637 "Missing PercentBI parameter at index %d",
11638 i);
11639 return -1;
11640 }
11641 allocs[i].percent_bi = atoi(val);
11642
11643 val = get_param_indexed(cmd, "SrcAID", i);
11644 if (val)
11645 allocs[i].src_aid = strtol(val, NULL, 0);
11646 else
11647 allocs[i].src_aid = ESE_BCAST_AID;
11648
11649 val = get_param_indexed(cmd, "DestAID", i);
11650 if (val)
11651 allocs[i].dst_aid = strtol(val, NULL, 0);
11652 else
11653 allocs[i].dst_aid = ESE_BCAST_AID;
11654
11655 allocs[i].type = ESE_CBAP;
11656 sigma_dut_print(dut, DUT_MSG_INFO,
11657 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11658 i, allocs[i].percent_bi, allocs[i].src_aid,
11659 allocs[i].dst_aid);
11660 }
11661
11662 *allocs_size = count;
11663 return 0;
11664}
11665
11666
11667static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11668 struct sigma_ese_alloc *allocs)
11669{
11670 switch (get_driver_type()) {
11671#ifdef __linux__
11672 case DRIVER_WIL6210:
11673 if (wil6210_set_ese(dut, count, allocs))
11674 return -1;
11675 return 1;
11676#endif /* __linux__ */
11677 default:
11678 sigma_dut_print(dut, DUT_MSG_ERROR,
11679 "Unsupported sta_set_60g_ese with the current driver");
11680 return -1;
11681 }
11682}
11683
11684
11685static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11686 struct sigma_conn *conn,
11687 struct sigma_cmd *cmd)
11688{
11689 const char *val;
11690
11691 val = get_param(cmd, "ExtSchIE");
11692 if (val && !strcasecmp(val, "Enable")) {
11693 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11694 int count = MAX_ESE_ALLOCS;
11695
11696 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11697 return -1;
11698 return sta_set_60g_ese(dut, count, allocs);
11699 }
11700
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011701 val = get_param(cmd, "MCS_FixedRate");
11702 if (val) {
11703 int sta_mcs = atoi(val);
11704
11705 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11706 sta_mcs);
11707 wil6210_set_force_mcs(dut, 1, sta_mcs);
11708
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011709 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011710 }
11711
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011712 send_resp(dut, conn, SIGMA_ERROR,
11713 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011714 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011715}
11716
11717
Jouni Malinenf7222712019-06-13 01:50:21 +030011718static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
11719 struct sigma_conn *conn,
11720 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011721{
11722 const char *intf = get_param(cmd, "Interface");
11723 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011724 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011725
11726 if (intf == NULL || prog == NULL)
11727 return -1;
11728
Ashwini Patil5acd7382017-04-13 15:55:04 +053011729 /* BSS Transition candidate list for BTM query */
11730 val = get_param(cmd, "Nebor_BSSID");
11731 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11732 return 0;
11733
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011734 if (strcasecmp(prog, "TDLS") == 0)
11735 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11736
11737 if (strcasecmp(prog, "VHT") == 0)
11738 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11739
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011740 if (strcasecmp(prog, "HE") == 0)
11741 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11742
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011743 if (strcasecmp(prog, "MBO") == 0) {
11744 val = get_param(cmd, "Cellular_Data_Cap");
11745 if (val &&
11746 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11747 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011748
11749 val = get_param(cmd, "Ch_Pref");
11750 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11751 return 0;
11752
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011753 return 1;
11754 }
11755
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011756 if (strcasecmp(prog, "60GHz") == 0)
11757 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11758
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011759 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11760 return 0;
11761}
11762
11763
Jouni Malinenf7222712019-06-13 01:50:21 +030011764static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
11765 struct sigma_conn *conn,
11766 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011767{
11768 const char *intf = get_param(cmd, "Interface");
11769 const char *mode = get_param(cmd, "Mode");
11770 int res;
11771
11772 if (intf == NULL || mode == NULL)
11773 return -1;
11774
11775 if (strcasecmp(mode, "On") == 0)
11776 res = wpa_command(intf, "SET radio_disabled 0");
11777 else if (strcasecmp(mode, "Off") == 0)
11778 res = wpa_command(intf, "SET radio_disabled 1");
11779 else
11780 return -1;
11781
11782 if (res) {
11783 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11784 "radio mode");
11785 return 0;
11786 }
11787
11788 return 1;
11789}
11790
11791
Jouni Malinenf7222712019-06-13 01:50:21 +030011792static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
11793 struct sigma_conn *conn,
11794 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011795{
11796 const char *intf = get_param(cmd, "Interface");
11797 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011798 const char *prog = get_param(cmd, "program");
11799 const char *powersave = get_param(cmd, "powersave");
11800 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011801
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011802 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011803 return -1;
11804
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011805 if (prog && strcasecmp(prog, "60GHz") == 0) {
11806 /*
11807 * The CAPI mode parameter does not exist in 60G
11808 * unscheduled PS.
11809 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080011810 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011811 res = set_ps(intf, dut, 1);
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011812 } else if (prog && get_driver_type() == DRIVER_WCN &&
11813 strcasecmp(prog, "HE") == 0) {
11814 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011815 } else {
11816 if (mode == NULL)
11817 return -1;
11818
11819 if (strcasecmp(mode, "On") == 0)
11820 res = set_ps(intf, dut, 1);
11821 else if (strcasecmp(mode, "Off") == 0)
11822 res = set_ps(intf, dut, 0);
11823 else
11824 return -1;
11825 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011826
11827 if (res) {
11828 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11829 "power save mode");
11830 return 0;
11831 }
11832
11833 return 1;
11834}
11835
11836
Jouni Malinenf7222712019-06-13 01:50:21 +030011837static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
11838 struct sigma_conn *conn,
11839 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011840{
11841 const char *intf = get_param(cmd, "Interface");
11842 const char *val, *bssid;
11843 int res;
11844 char *buf;
11845 size_t buf_len;
11846
11847 val = get_param(cmd, "BSSID_FILTER");
11848 if (val == NULL)
11849 return -1;
11850
11851 bssid = get_param(cmd, "BSSID_List");
11852 if (atoi(val) == 0 || bssid == NULL) {
11853 /* Disable BSSID filter */
11854 if (wpa_command(intf, "SET bssid_filter ")) {
11855 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
11856 "to disable BSSID filter");
11857 return 0;
11858 }
11859
11860 return 1;
11861 }
11862
11863 buf_len = 100 + strlen(bssid);
11864 buf = malloc(buf_len);
11865 if (buf == NULL)
11866 return -1;
11867
11868 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
11869 res = wpa_command(intf, buf);
11870 free(buf);
11871 if (res) {
11872 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
11873 "BSSID filter");
11874 return 0;
11875 }
11876
11877 return 1;
11878}
11879
11880
Jouni Malinenf7222712019-06-13 01:50:21 +030011881static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
11882 struct sigma_conn *conn,
11883 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011884{
11885 const char *intf = get_param(cmd, "Interface");
11886 const char *val;
11887
11888 /* TODO: ARP */
11889
11890 val = get_param(cmd, "HS2_CACHE_PROFILE");
11891 if (val && strcasecmp(val, "All") == 0)
11892 hs2_clear_credentials(intf);
11893
11894 return 1;
11895}
11896
11897
Jouni Malinenf7222712019-06-13 01:50:21 +030011898static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
11899 struct sigma_conn *conn,
11900 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011901{
11902 const char *intf = get_param(cmd, "Interface");
11903 const char *key_type = get_param(cmd, "KeyType");
11904 char buf[100], resp[200];
11905
11906 if (key_type == NULL)
11907 return -1;
11908
11909 if (strcasecmp(key_type, "GTK") == 0) {
11910 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
11911 strncmp(buf, "FAIL", 4) == 0) {
11912 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11913 "not fetch current GTK");
11914 return 0;
11915 }
11916 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
11917 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11918 return 0;
11919 } else {
11920 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11921 "KeyType");
11922 return 0;
11923 }
11924
11925 return 1;
11926}
11927
11928
11929static int hs2_set_policy(struct sigma_dut *dut)
11930{
11931#ifdef ANDROID
11932 system("ip rule del prio 23000");
11933 if (system("ip rule add from all lookup main prio 23000") != 0) {
11934 sigma_dut_print(dut, DUT_MSG_ERROR,
11935 "Failed to run:ip rule add from all lookup main prio");
11936 return -1;
11937 }
11938 if (system("ip route flush cache") != 0) {
11939 sigma_dut_print(dut, DUT_MSG_ERROR,
11940 "Failed to run ip route flush cache");
11941 return -1;
11942 }
11943 return 1;
11944#else /* ANDROID */
11945 return 0;
11946#endif /* ANDROID */
11947}
11948
11949
Jouni Malinenf7222712019-06-13 01:50:21 +030011950static enum sigma_cmd_result cmd_sta_hs2_associate(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 *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030011956 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011957 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030011958 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011959 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
11960 int tries = 0;
11961 int ignore_blacklist = 0;
11962 const char *events[] = {
11963 "CTRL-EVENT-CONNECTED",
11964 "INTERWORKING-BLACKLISTED",
11965 "INTERWORKING-NO-MATCH",
11966 NULL
11967 };
11968
11969 start_sta_mode(dut);
11970
Jouni Malinen439352d2018-09-13 03:42:23 +030011971 if (band) {
11972 if (strcmp(band, "2.4") == 0) {
11973 wpa_command(intf, "SET setband 2G");
11974 } else if (strcmp(band, "5") == 0) {
11975 wpa_command(intf, "SET setband 5G");
11976 } else {
11977 send_resp(dut, conn, SIGMA_ERROR,
11978 "errorCode,Unsupported band");
11979 return 0;
11980 }
11981 }
11982
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011983 blacklisted[0] = '\0';
11984 if (val && atoi(val))
11985 ignore_blacklist = 1;
11986
11987try_again:
11988 ctrl = open_wpa_mon(intf);
11989 if (ctrl == NULL) {
11990 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11991 "wpa_supplicant monitor connection");
11992 return -2;
11993 }
11994
11995 tries++;
11996 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
11997 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
11998 "Interworking connection");
11999 wpa_ctrl_detach(ctrl);
12000 wpa_ctrl_close(ctrl);
12001 return 0;
12002 }
12003
12004 buf[0] = '\0';
12005 while (1) {
12006 char *pos;
12007 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12008 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12009 if (!pos)
12010 break;
12011 pos += 25;
12012 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12013 pos);
12014 if (!blacklisted[0])
12015 memcpy(blacklisted, pos, strlen(pos) + 1);
12016 }
12017
12018 if (ignore_blacklist && blacklisted[0]) {
12019 char *end;
12020 end = strchr(blacklisted, ' ');
12021 if (end)
12022 *end = '\0';
12023 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12024 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012025 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12026 blacklisted);
12027 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012028 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12029 wpa_ctrl_detach(ctrl);
12030 wpa_ctrl_close(ctrl);
12031 return 0;
12032 }
12033 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12034 buf, sizeof(buf));
12035 }
12036
12037 wpa_ctrl_detach(ctrl);
12038 wpa_ctrl_close(ctrl);
12039
12040 if (res < 0) {
12041 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12042 "connect");
12043 return 0;
12044 }
12045
12046 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12047 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12048 if (tries < 2) {
12049 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12050 goto try_again;
12051 }
12052 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12053 "matching credentials found");
12054 return 0;
12055 }
12056
12057 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12058 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12059 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12060 "get current BSSID/SSID");
12061 return 0;
12062 }
12063
12064 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12065 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12066 hs2_set_policy(dut);
12067 return 0;
12068}
12069
12070
Jouni Malinenf7222712019-06-13 01:50:21 +030012071static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12072 struct sigma_conn *conn,
12073 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012074{
12075 const char *intf = get_param(cmd, "Interface");
12076 const char *display = get_param(cmd, "Display");
12077 struct wpa_ctrl *ctrl;
12078 char buf[300], params[400], *pos;
12079 char bssid[20];
12080 int info_avail = 0;
12081 unsigned int old_timeout;
12082 int res;
12083
12084 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12085 send_resp(dut, conn, SIGMA_ERROR,
12086 "ErrorCode,Could not get current BSSID");
12087 return 0;
12088 }
12089 ctrl = open_wpa_mon(intf);
12090 if (!ctrl) {
12091 sigma_dut_print(dut, DUT_MSG_ERROR,
12092 "Failed to open wpa_supplicant monitor connection");
12093 return -2;
12094 }
12095
12096 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12097 wpa_command(intf, buf);
12098
12099 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12100 if (res < 0) {
12101 send_resp(dut, conn, SIGMA_ERROR,
12102 "ErrorCode,Could not complete GAS query");
12103 goto fail;
12104 }
12105
12106 old_timeout = dut->default_timeout;
12107 dut->default_timeout = 2;
12108 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12109 dut->default_timeout = old_timeout;
12110 if (res < 0)
12111 goto done;
12112 pos = strchr(buf, ' ');
12113 if (!pos)
12114 goto done;
12115 pos++;
12116 pos = strchr(pos, ' ');
12117 if (!pos)
12118 goto done;
12119 pos++;
12120 info_avail = 1;
12121 snprintf(params, sizeof(params), "browser %s", pos);
12122
12123 if (display && strcasecmp(display, "Yes") == 0) {
12124 pid_t pid;
12125
12126 pid = fork();
12127 if (pid < 0) {
12128 perror("fork");
12129 return -1;
12130 }
12131
12132 if (pid == 0) {
12133 run_hs20_osu(dut, params);
12134 exit(0);
12135 }
12136 }
12137
12138done:
12139 snprintf(buf, sizeof(buf), "Info_available,%s",
12140 info_avail ? "Yes" : "No");
12141 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12142fail:
12143 wpa_ctrl_detach(ctrl);
12144 wpa_ctrl_close(ctrl);
12145 return 0;
12146}
12147
12148
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012149static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12150 struct sigma_conn *conn,
12151 const char *ifname,
12152 struct sigma_cmd *cmd)
12153{
12154 const char *val;
12155 int id;
12156
12157 id = add_cred(ifname);
12158 if (id < 0)
12159 return -2;
12160 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12161
12162 val = get_param(cmd, "prefer");
12163 if (val && atoi(val) > 0)
12164 set_cred(ifname, id, "priority", "1");
12165
12166 val = get_param(cmd, "REALM");
12167 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12168 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12169 "realm");
12170 return 0;
12171 }
12172
12173 val = get_param(cmd, "HOME_FQDN");
12174 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12175 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12176 "home_fqdn");
12177 return 0;
12178 }
12179
12180 val = get_param(cmd, "Username");
12181 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12182 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12183 "username");
12184 return 0;
12185 }
12186
12187 val = get_param(cmd, "Password");
12188 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12189 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12190 "password");
12191 return 0;
12192 }
12193
12194 val = get_param(cmd, "ROOT_CA");
12195 if (val) {
12196 char fname[200];
12197 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12198#ifdef __linux__
12199 if (!file_exists(fname)) {
12200 char msg[300];
12201 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12202 "file (%s) not found", fname);
12203 send_resp(dut, conn, SIGMA_ERROR, msg);
12204 return 0;
12205 }
12206#endif /* __linux__ */
12207 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12208 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12209 "not set root CA");
12210 return 0;
12211 }
12212 }
12213
12214 return 1;
12215}
12216
12217
12218static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12219{
12220 FILE *in, *out;
12221 char buf[500];
12222 int found = 0;
12223
12224 in = fopen("devdetail.xml", "r");
12225 if (in == NULL)
12226 return -1;
12227 out = fopen("devdetail.xml.tmp", "w");
12228 if (out == NULL) {
12229 fclose(in);
12230 return -1;
12231 }
12232
12233 while (fgets(buf, sizeof(buf), in)) {
12234 char *pos = strstr(buf, "<IMSI>");
12235 if (pos) {
12236 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12237 imsi);
12238 pos += 6;
12239 *pos = '\0';
12240 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12241 found++;
12242 } else {
12243 fprintf(out, "%s", buf);
12244 }
12245 }
12246
12247 fclose(out);
12248 fclose(in);
12249 if (found)
12250 rename("devdetail.xml.tmp", "devdetail.xml");
12251 else
12252 unlink("devdetail.xml.tmp");
12253
12254 return 0;
12255}
12256
12257
12258static int sta_add_credential_sim(struct sigma_dut *dut,
12259 struct sigma_conn *conn,
12260 const char *ifname, struct sigma_cmd *cmd)
12261{
12262 const char *val, *imsi = NULL;
12263 int id;
12264 char buf[200];
12265 int res;
12266 const char *pos;
12267 size_t mnc_len;
12268 char plmn_mcc[4];
12269 char plmn_mnc[4];
12270
12271 id = add_cred(ifname);
12272 if (id < 0)
12273 return -2;
12274 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12275
12276 val = get_param(cmd, "prefer");
12277 if (val && atoi(val) > 0)
12278 set_cred(ifname, id, "priority", "1");
12279
12280 val = get_param(cmd, "PLMN_MCC");
12281 if (val == NULL) {
12282 send_resp(dut, conn, SIGMA_ERROR,
12283 "errorCode,Missing PLMN_MCC");
12284 return 0;
12285 }
12286 if (strlen(val) != 3) {
12287 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12288 return 0;
12289 }
12290 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12291
12292 val = get_param(cmd, "PLMN_MNC");
12293 if (val == NULL) {
12294 send_resp(dut, conn, SIGMA_ERROR,
12295 "errorCode,Missing PLMN_MNC");
12296 return 0;
12297 }
12298 if (strlen(val) != 2 && strlen(val) != 3) {
12299 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12300 return 0;
12301 }
12302 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12303
12304 val = get_param(cmd, "IMSI");
12305 if (val == NULL) {
12306 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12307 "IMSI");
12308 return 0;
12309 }
12310
12311 imsi = pos = val;
12312
12313 if (strncmp(plmn_mcc, pos, 3) != 0) {
12314 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12315 return 0;
12316 }
12317 pos += 3;
12318
12319 mnc_len = strlen(plmn_mnc);
12320 if (mnc_len < 2) {
12321 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12322 return 0;
12323 }
12324
12325 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12326 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12327 return 0;
12328 }
12329 pos += mnc_len;
12330
12331 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12332 if (res < 0 || res >= (int) sizeof(buf))
12333 return -1;
12334 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12335 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12336 "not set IMSI");
12337 return 0;
12338 }
12339
12340 val = get_param(cmd, "Password");
12341 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12342 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12343 "not set password");
12344 return 0;
12345 }
12346
Jouni Malinenba630452018-06-22 11:49:59 +030012347 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012348 /*
12349 * Set provisioning_sp for the test cases where SIM/USIM
12350 * provisioning is used.
12351 */
12352 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12353 "wi-fi.org") < 0) {
12354 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12355 "not set provisioning_sp");
12356 return 0;
12357 }
12358
12359 update_devdetail_imsi(dut, imsi);
12360 }
12361
12362 return 1;
12363}
12364
12365
12366static int sta_add_credential_cert(struct sigma_dut *dut,
12367 struct sigma_conn *conn,
12368 const char *ifname,
12369 struct sigma_cmd *cmd)
12370{
12371 const char *val;
12372 int id;
12373
12374 id = add_cred(ifname);
12375 if (id < 0)
12376 return -2;
12377 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12378
12379 val = get_param(cmd, "prefer");
12380 if (val && atoi(val) > 0)
12381 set_cred(ifname, id, "priority", "1");
12382
12383 val = get_param(cmd, "REALM");
12384 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12386 "realm");
12387 return 0;
12388 }
12389
12390 val = get_param(cmd, "HOME_FQDN");
12391 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12392 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12393 "home_fqdn");
12394 return 0;
12395 }
12396
12397 val = get_param(cmd, "Username");
12398 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12399 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12400 "username");
12401 return 0;
12402 }
12403
12404 val = get_param(cmd, "clientCertificate");
12405 if (val) {
12406 char fname[200];
12407 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12408#ifdef __linux__
12409 if (!file_exists(fname)) {
12410 char msg[300];
12411 snprintf(msg, sizeof(msg),
12412 "ErrorCode,clientCertificate "
12413 "file (%s) not found", fname);
12414 send_resp(dut, conn, SIGMA_ERROR, msg);
12415 return 0;
12416 }
12417#endif /* __linux__ */
12418 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12419 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12420 "not set client_cert");
12421 return 0;
12422 }
12423 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12424 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12425 "not set private_key");
12426 return 0;
12427 }
12428 }
12429
12430 val = get_param(cmd, "ROOT_CA");
12431 if (val) {
12432 char fname[200];
12433 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12434#ifdef __linux__
12435 if (!file_exists(fname)) {
12436 char msg[300];
12437 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12438 "file (%s) not found", fname);
12439 send_resp(dut, conn, SIGMA_ERROR, msg);
12440 return 0;
12441 }
12442#endif /* __linux__ */
12443 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12444 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12445 "not set root CA");
12446 return 0;
12447 }
12448 }
12449
12450 return 1;
12451}
12452
12453
Jouni Malinenf7222712019-06-13 01:50:21 +030012454static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12455 struct sigma_conn *conn,
12456 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012457{
12458 const char *intf = get_param(cmd, "Interface");
12459 const char *type;
12460
12461 start_sta_mode(dut);
12462
12463 type = get_param(cmd, "Type");
12464 if (!type)
12465 return -1;
12466
12467 if (strcasecmp(type, "uname_pwd") == 0)
12468 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12469
12470 if (strcasecmp(type, "sim") == 0)
12471 return sta_add_credential_sim(dut, conn, intf, cmd);
12472
12473 if (strcasecmp(type, "cert") == 0)
12474 return sta_add_credential_cert(dut, conn, intf, cmd);
12475
12476 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12477 "type");
12478 return 0;
12479}
12480
12481
Jouni Malinenf7222712019-06-13 01:50:21 +030012482static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12483 struct sigma_conn *conn,
12484 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012485{
12486 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012487 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012488 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012489 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012490 int res;
12491
Arif Hussain66a4af02019-02-07 15:04:51 -080012492 val = get_param(cmd, "GetParameter");
12493 if (val && strcmp(val, "SSID_BSSID") == 0) {
12494 if (get_wpa_ssid_bssid(dut, get_station_ifname(),
12495 buf, sizeof(buf)) < 0) {
12496 sigma_dut_print(dut, DUT_MSG_ERROR,
12497 "Could not get ssid bssid");
12498 return ERROR_SEND_STATUS;
12499 }
12500
12501 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12502 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12503 return STATUS_SENT;
12504 }
12505
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012506 val = get_param(cmd, "HESSID");
12507 if (val) {
12508 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12509 if (res < 0 || res >= (int) sizeof(buf))
12510 return -1;
12511 wpa_command(intf, buf);
12512 }
12513
12514 val = get_param(cmd, "ACCS_NET_TYPE");
12515 if (val) {
12516 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12517 val);
12518 if (res < 0 || res >= (int) sizeof(buf))
12519 return -1;
12520 wpa_command(intf, buf);
12521 }
12522
vamsi krishna89ad8c62017-09-19 12:51:18 +053012523 bssid = get_param(cmd, "Bssid");
12524 ssid = get_param(cmd, "Ssid");
12525
12526 if (ssid) {
12527 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12528 send_resp(dut, conn, SIGMA_ERROR,
12529 "ErrorCode,Too long SSID");
12530 return 0;
12531 }
12532 ascii2hexstr(ssid, ssid_hex);
12533 }
12534
12535 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12536 bssid ? " bssid=": "",
12537 bssid ? bssid : "",
12538 ssid ? " ssid " : "",
12539 ssid ? ssid_hex : "");
12540 if (res < 0 || res >= (int) sizeof(buf))
12541 return -1;
12542
12543 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012544 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12545 "scan");
12546 return 0;
12547 }
12548
12549 return 1;
12550}
12551
12552
Jouni Malinenf7222712019-06-13 01:50:21 +030012553static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12554 struct sigma_conn *conn,
12555 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012556{
12557 const char *intf = get_param(cmd, "Interface");
12558 const char *bssid;
12559 char buf[4096], *pos;
12560 int freq, chan;
12561 char *ssid;
12562 char resp[100];
12563 int res;
12564 struct wpa_ctrl *ctrl;
12565
12566 bssid = get_param(cmd, "BSSID");
12567 if (!bssid) {
12568 send_resp(dut, conn, SIGMA_INVALID,
12569 "errorCode,BSSID argument is missing");
12570 return 0;
12571 }
12572
12573 ctrl = open_wpa_mon(intf);
12574 if (!ctrl) {
12575 sigma_dut_print(dut, DUT_MSG_ERROR,
12576 "Failed to open wpa_supplicant monitor connection");
12577 return -1;
12578 }
12579
12580 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12581 send_resp(dut, conn, SIGMA_ERROR,
12582 "errorCode,Could not start scan");
12583 wpa_ctrl_detach(ctrl);
12584 wpa_ctrl_close(ctrl);
12585 return 0;
12586 }
12587
12588 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12589 buf, sizeof(buf));
12590
12591 wpa_ctrl_detach(ctrl);
12592 wpa_ctrl_close(ctrl);
12593
12594 if (res < 0) {
12595 send_resp(dut, conn, SIGMA_ERROR,
12596 "errorCode,Scan did not complete");
12597 return 0;
12598 }
12599
12600 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12601 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12602 strncmp(buf, "id=", 3) != 0) {
12603 send_resp(dut, conn, SIGMA_ERROR,
12604 "errorCode,Specified BSSID not found");
12605 return 0;
12606 }
12607
12608 pos = strstr(buf, "\nfreq=");
12609 if (!pos) {
12610 send_resp(dut, conn, SIGMA_ERROR,
12611 "errorCode,Channel not found");
12612 return 0;
12613 }
12614 freq = atoi(pos + 6);
12615 chan = freq_to_channel(freq);
12616
12617 pos = strstr(buf, "\nssid=");
12618 if (!pos) {
12619 send_resp(dut, conn, SIGMA_ERROR,
12620 "errorCode,SSID not found");
12621 return 0;
12622 }
12623 ssid = pos + 6;
12624 pos = strchr(ssid, '\n');
12625 if (pos)
12626 *pos = '\0';
12627 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12628 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12629 return 0;
12630}
12631
12632
Jouni Malinenf7222712019-06-13 01:50:21 +030012633static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
12634 struct sigma_conn *conn,
12635 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012636{
12637#ifdef __linux__
12638 struct timeval tv;
12639 struct tm tm;
12640 time_t t;
12641 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012642 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012643
12644 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
12645
12646 memset(&tm, 0, sizeof(tm));
12647 val = get_param(cmd, "seconds");
12648 if (val)
12649 tm.tm_sec = atoi(val);
12650 val = get_param(cmd, "minutes");
12651 if (val)
12652 tm.tm_min = atoi(val);
12653 val = get_param(cmd, "hours");
12654 if (val)
12655 tm.tm_hour = atoi(val);
12656 val = get_param(cmd, "date");
12657 if (val)
12658 tm.tm_mday = atoi(val);
12659 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012660 if (val) {
12661 v = atoi(val);
12662 if (v < 1 || v > 12) {
12663 send_resp(dut, conn, SIGMA_INVALID,
12664 "errorCode,Invalid month");
12665 return 0;
12666 }
12667 tm.tm_mon = v - 1;
12668 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012669 val = get_param(cmd, "year");
12670 if (val) {
12671 int year = atoi(val);
12672#ifdef ANDROID
12673 if (year > 2035)
12674 year = 2035; /* years beyond 2035 not supported */
12675#endif /* ANDROID */
12676 tm.tm_year = year - 1900;
12677 }
12678 t = mktime(&tm);
12679 if (t == (time_t) -1) {
12680 send_resp(dut, conn, SIGMA_ERROR,
12681 "errorCode,Invalid date or time");
12682 return 0;
12683 }
12684
12685 memset(&tv, 0, sizeof(tv));
12686 tv.tv_sec = t;
12687
12688 if (settimeofday(&tv, NULL) < 0) {
12689 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12690 strerror(errno));
12691 send_resp(dut, conn, SIGMA_ERROR,
12692 "errorCode,Failed to set time");
12693 return 0;
12694 }
12695
12696 return 1;
12697#endif /* __linux__ */
12698
12699 return -1;
12700}
12701
12702
Jouni Malinenf7222712019-06-13 01:50:21 +030012703static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
12704 struct sigma_conn *conn,
12705 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012706{
12707 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012708 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012709 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012710 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012711 int res;
12712 struct wpa_ctrl *ctrl;
12713
12714 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012715 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012716
12717 val = get_param(cmd, "ProdESSAssoc");
12718 if (val)
12719 prod_ess_assoc = atoi(val);
12720
12721 kill_dhcp_client(dut, intf);
12722 if (start_dhcp_client(dut, intf) < 0)
12723 return -2;
12724
12725 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12726 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12727 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012728 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012729 prod_ess_assoc ? "" : "-N",
12730 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012731 name ? "'" : "",
12732 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12733 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012734
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012735 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012736 if (run_hs20_osu(dut, buf) < 0) {
12737 FILE *f;
12738
12739 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12740
12741 f = fopen("hs20-osu-client.res", "r");
12742 if (f) {
12743 char resp[400], res[300], *pos;
12744 if (!fgets(res, sizeof(res), f))
12745 res[0] = '\0';
12746 pos = strchr(res, '\n');
12747 if (pos)
12748 *pos = '\0';
12749 fclose(f);
12750 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12751 res);
12752 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12753 if (system(resp) != 0) {
12754 }
12755 snprintf(resp, sizeof(resp),
12756 "SSID,,BSSID,,failureReason,%s", res);
12757 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12758 return 0;
12759 }
12760
12761 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12762 return 0;
12763 }
12764
12765 if (!prod_ess_assoc)
12766 goto report;
12767
12768 ctrl = open_wpa_mon(intf);
12769 if (ctrl == NULL) {
12770 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12771 "wpa_supplicant monitor connection");
12772 return -1;
12773 }
12774
12775 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12776 buf, sizeof(buf));
12777
12778 wpa_ctrl_detach(ctrl);
12779 wpa_ctrl_close(ctrl);
12780
12781 if (res < 0) {
12782 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12783 "network after OSU");
12784 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12785 return 0;
12786 }
12787
12788report:
12789 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12790 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12791 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12792 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12793 return 0;
12794 }
12795
12796 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12797 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012798 return 0;
12799}
12800
12801
Jouni Malinenf7222712019-06-13 01:50:21 +030012802static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
12803 struct sigma_conn *conn,
12804 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012805{
12806 const char *val;
12807 int timeout = 120;
12808
12809 val = get_param(cmd, "PolicyUpdate");
12810 if (val == NULL || atoi(val) == 0)
12811 return 1; /* No operation requested */
12812
12813 val = get_param(cmd, "Timeout");
12814 if (val)
12815 timeout = atoi(val);
12816
12817 if (timeout) {
12818 /* TODO: time out the command and return
12819 * PolicyUpdateStatus,TIMEOUT if needed. */
12820 }
12821
12822 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12823 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12824 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12825 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12826 return 0;
12827 }
12828
12829 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12830 return 0;
12831}
12832
12833
Jouni Malinenf7222712019-06-13 01:50:21 +030012834static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
12835 struct sigma_conn *conn,
12836 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012837{
12838 struct wpa_ctrl *ctrl;
12839 const char *intf = get_param(cmd, "Interface");
12840 const char *bssid = get_param(cmd, "Bssid");
12841 const char *ssid = get_param(cmd, "SSID");
12842 const char *security = get_param(cmd, "Security");
12843 const char *passphrase = get_param(cmd, "Passphrase");
12844 const char *pin = get_param(cmd, "PIN");
12845 char buf[1000];
12846 char ssid_hex[200], passphrase_hex[200];
12847 const char *keymgmt, *cipher;
12848
12849 if (intf == NULL)
12850 intf = get_main_ifname();
12851
12852 if (!bssid) {
12853 send_resp(dut, conn, SIGMA_ERROR,
12854 "ErrorCode,Missing Bssid argument");
12855 return 0;
12856 }
12857
12858 if (!ssid) {
12859 send_resp(dut, conn, SIGMA_ERROR,
12860 "ErrorCode,Missing SSID argument");
12861 return 0;
12862 }
12863
12864 if (!security) {
12865 send_resp(dut, conn, SIGMA_ERROR,
12866 "ErrorCode,Missing Security argument");
12867 return 0;
12868 }
12869
12870 if (!passphrase) {
12871 send_resp(dut, conn, SIGMA_ERROR,
12872 "ErrorCode,Missing Passphrase argument");
12873 return 0;
12874 }
12875
12876 if (!pin) {
12877 send_resp(dut, conn, SIGMA_ERROR,
12878 "ErrorCode,Missing PIN argument");
12879 return 0;
12880 }
12881
vamsi krishna8c9c1562017-05-12 15:51:46 +053012882 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
12883 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012884 send_resp(dut, conn, SIGMA_ERROR,
12885 "ErrorCode,Too long SSID/passphrase");
12886 return 0;
12887 }
12888
12889 ctrl = open_wpa_mon(intf);
12890 if (ctrl == NULL) {
12891 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12892 "wpa_supplicant monitor connection");
12893 return -2;
12894 }
12895
12896 if (strcasecmp(security, "wpa2-psk") == 0) {
12897 keymgmt = "WPA2PSK";
12898 cipher = "CCMP";
12899 } else {
12900 wpa_ctrl_detach(ctrl);
12901 wpa_ctrl_close(ctrl);
12902 send_resp(dut, conn, SIGMA_ERROR,
12903 "ErrorCode,Unsupported Security value");
12904 return 0;
12905 }
12906
12907 ascii2hexstr(ssid, ssid_hex);
12908 ascii2hexstr(passphrase, passphrase_hex);
12909 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
12910 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
12911
12912 if (wpa_command(intf, buf) < 0) {
12913 wpa_ctrl_detach(ctrl);
12914 wpa_ctrl_close(ctrl);
12915 send_resp(dut, conn, SIGMA_ERROR,
12916 "ErrorCode,Failed to start registrar");
12917 return 0;
12918 }
12919
12920 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
12921 dut->er_oper_performed = 1;
12922
12923 return wps_connection_event(dut, conn, ctrl, intf, 0);
12924}
12925
12926
Jouni Malinenf7222712019-06-13 01:50:21 +030012927static enum sigma_cmd_result
12928cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
12929 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012930{
12931 struct wpa_ctrl *ctrl;
12932 const char *intf = get_param(cmd, "Interface");
12933 const char *bssid = get_param(cmd, "Bssid");
12934 char buf[100];
12935
12936 if (!bssid) {
12937 send_resp(dut, conn, SIGMA_ERROR,
12938 "ErrorCode,Missing Bssid argument");
12939 return 0;
12940 }
12941
12942 ctrl = open_wpa_mon(intf);
12943 if (ctrl == NULL) {
12944 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12945 "wpa_supplicant monitor connection");
12946 return -2;
12947 }
12948
12949 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
12950
12951 if (wpa_command(intf, buf) < 0) {
12952 wpa_ctrl_detach(ctrl);
12953 wpa_ctrl_close(ctrl);
12954 send_resp(dut, conn, SIGMA_ERROR,
12955 "ErrorCode,Failed to start registrar");
12956 return 0;
12957 }
12958
12959 return wps_connection_event(dut, conn, ctrl, intf, 0);
12960}
12961
12962
Jouni Malinenf7222712019-06-13 01:50:21 +030012963static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
12964 struct sigma_conn *conn,
12965 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053012966{
12967 struct wpa_ctrl *ctrl;
12968 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012969 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012970 const char *config_method = get_param(cmd, "WPSConfigMethod");
12971 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053012972 int res;
12973 char buf[256];
12974 const char *events[] = {
12975 "CTRL-EVENT-CONNECTED",
12976 "WPS-OVERLAP-DETECTED",
12977 "WPS-TIMEOUT",
12978 "WPS-FAIL",
12979 NULL
12980 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012981 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053012982
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012983 /* 60G WPS tests do not pass Interface parameter */
12984 if (!intf)
12985 intf = get_main_ifname();
12986
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012987 if (dut->mode == SIGMA_MODE_AP)
12988 return ap_wps_registration(dut, conn, cmd);
12989
12990 if (config_method) {
12991 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
12992 * sta_wps_enter_pin before calling start_wps_registration. */
12993 if (strcasecmp(config_method, "PBC") == 0)
12994 dut->wps_method = WFA_CS_WPS_PBC;
12995 }
12996 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
12997 send_resp(dut, conn, SIGMA_ERROR,
12998 "ErrorCode,WPS parameters not yet set");
12999 return STATUS_SENT;
13000 }
13001
13002 /* Make sure WPS is enabled (also for STA mode) */
13003 dut->wps_disable = 0;
13004
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013005 if (dut->band == WPS_BAND_60G && network_mode &&
13006 strcasecmp(network_mode, "PBSS") == 0) {
13007 sigma_dut_print(dut, DUT_MSG_DEBUG,
13008 "Set PBSS network mode, network id %d", id);
13009 if (set_network(get_station_ifname(), id, "pbss", "1") < 0)
13010 return -2;
13011 }
13012
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013013 if (dut->force_rsn_ie) {
13014 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13015 dut->force_rsn_ie);
13016 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13017 sigma_dut_print(dut, DUT_MSG_INFO,
13018 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013019 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013020 }
13021 }
13022
vamsi krishna9b144002017-09-20 13:28:13 +053013023 ctrl = open_wpa_mon(intf);
13024 if (!ctrl) {
13025 sigma_dut_print(dut, DUT_MSG_ERROR,
13026 "Failed to open wpa_supplicant monitor connection");
13027 return -2;
13028 }
13029
13030 role = get_param(cmd, "WpsRole");
13031 if (!role) {
13032 send_resp(dut, conn, SIGMA_INVALID,
13033 "ErrorCode,WpsRole not provided");
13034 goto fail;
13035 }
13036
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013037 if (strcasecmp(role, "Enrollee") != 0) {
13038 /* Registrar role for STA not supported */
13039 send_resp(dut, conn, SIGMA_ERROR,
13040 "ErrorCode,Unsupported WpsRole value");
13041 goto fail;
13042 }
13043
13044 if (is_60g_sigma_dut(dut)) {
13045 if (dut->wps_method == WFA_CS_WPS_PBC)
13046 snprintf(buf, sizeof(buf), "WPS_PBC");
13047 else /* WFA_CS_WPS_PIN_KEYPAD */
13048 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13049 dut->wps_pin);
13050 if (wpa_command(intf, buf) < 0) {
13051 send_resp(dut, conn, SIGMA_ERROR,
13052 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013053 goto fail;
13054 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013055 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13056 if (res < 0) {
13057 send_resp(dut, conn, SIGMA_ERROR,
13058 "ErrorCode,WPS connection did not complete");
13059 goto fail;
13060 }
13061 if (strstr(buf, "WPS-TIMEOUT")) {
13062 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13063 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13064 send_resp(dut, conn, SIGMA_COMPLETE,
13065 "WpsState,OverlapSession");
13066 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13067 send_resp(dut, conn, SIGMA_COMPLETE,
13068 "WpsState,Successful");
13069 } else {
13070 send_resp(dut, conn, SIGMA_COMPLETE,
13071 "WpsState,Failure");
13072 }
13073 } else {
13074 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013075 if (wpa_command(intf, "WPS_PBC") < 0) {
13076 send_resp(dut, conn, SIGMA_ERROR,
13077 "ErrorCode,Failed to enable PBC");
13078 goto fail;
13079 }
13080 } else {
13081 /* TODO: PIN method */
13082 send_resp(dut, conn, SIGMA_ERROR,
13083 "ErrorCode,Unsupported WpsConfigMethod value");
13084 goto fail;
13085 }
13086 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13087 if (res < 0) {
13088 send_resp(dut, conn, SIGMA_ERROR,
13089 "ErrorCode,WPS connection did not complete");
13090 goto fail;
13091 }
13092 if (strstr(buf, "WPS-TIMEOUT")) {
13093 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13094 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13095 send_resp(dut, conn, SIGMA_ERROR,
13096 "ErrorCode,OverlapSession");
13097 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13098 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13099 } else {
13100 send_resp(dut, conn, SIGMA_ERROR,
13101 "ErrorCode,WPS operation failed");
13102 }
vamsi krishna9b144002017-09-20 13:28:13 +053013103 }
13104
13105fail:
13106 wpa_ctrl_detach(ctrl);
13107 wpa_ctrl_close(ctrl);
13108 return 0;
13109}
13110
13111
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013112static int req_intf(struct sigma_cmd *cmd)
13113{
13114 return get_param(cmd, "interface") == NULL ? -1 : 0;
13115}
13116
13117
13118void sta_register_cmds(void)
13119{
13120 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13121 cmd_sta_get_ip_config);
13122 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13123 cmd_sta_set_ip_config);
13124 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13125 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13126 cmd_sta_get_mac_address);
13127 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13128 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13129 cmd_sta_verify_ip_connection);
13130 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13131 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13132 cmd_sta_set_encryption);
13133 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13134 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13135 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13136 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13137 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13138 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13139 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13140 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13141 cmd_sta_set_eapakaprime);
13142 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13143 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13144 /* TODO: sta_set_ibss */
13145 /* TODO: sta_set_mode */
13146 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13147 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13148 /* TODO: sta_up_load */
13149 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13150 cmd_sta_preset_testparameters);
13151 /* TODO: sta_set_system */
13152 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13153 /* TODO: sta_set_rifs_test */
13154 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13155 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13156 /* TODO: sta_send_coexist_mgmt */
13157 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13158 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13159 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13160 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13161 cmd_sta_reset_default);
13162 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13163 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13164 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13165 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13166 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013167 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013168 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13169 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13170 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13171 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13172 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013173 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13174 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013175 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13176 cmd_sta_add_credential);
13177 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013178 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013179 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13180 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13181 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13182 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13183 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13184 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013185 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013186 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13187 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013188 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013189 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013190}