blob: 3284d71438d18d75c63c2d4dc1d50faa39f24f7a [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;
325
326 if (length > WIL_WMI_MAX_PAYLOAD) {
327 sigma_dut_print(dut, DUT_MSG_ERROR,
328 "payload too large(%u, max %u)",
329 length, WIL_WMI_MAX_PAYLOAD);
330 return -1;
331 }
332
333 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
334 cmd.hdr.cmd = command;
335 memcpy(cmd.payload, payload, length);
336
337 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
338 sigma_dut_print(dut, DUT_MSG_ERROR,
339 "failed to get wil6210 debugfs dir");
340 return -1;
341 }
342
343 snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
344 f = fopen(fname, "wb");
345 if (!f) {
346 sigma_dut_print(dut, DUT_MSG_ERROR,
347 "failed to open: %s", fname);
348 return -1;
349 }
350
351 towrite = sizeof(cmd.hdr) + length;
352 written = fwrite(&cmd, 1, towrite, f);
353 fclose(f);
354 if (written != towrite) {
355 sigma_dut_print(dut, DUT_MSG_ERROR,
356 "failed to send wmi %u", command);
357 return -1;
358 }
359
360 return 0;
361}
362
363
364static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
365 const char *pattern, unsigned int *field)
366{
367 char buf[128], fname[128];
368 FILE *f;
369 regex_t re;
370 regmatch_t m[2];
371 int rc, ret = -1;
372
373 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
374 sigma_dut_print(dut, DUT_MSG_ERROR,
375 "failed to get wil6210 debugfs dir");
376 return -1;
377 }
378
379 snprintf(fname, sizeof(fname), "%s/stations", buf);
380 f = fopen(fname, "r");
381 if (!f) {
382 sigma_dut_print(dut, DUT_MSG_ERROR,
383 "failed to open: %s", fname);
384 return -1;
385 }
386
387 if (regcomp(&re, pattern, REG_EXTENDED)) {
388 sigma_dut_print(dut, DUT_MSG_ERROR,
389 "regcomp failed: %s", pattern);
390 goto out;
391 }
392
393 /*
394 * find the entry for the mac address
395 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
396 */
397 while (fgets(buf, sizeof(buf), f)) {
398 if (strcasestr(buf, bssid)) {
399 /* extract the field (CID/AID/state) */
400 rc = regexec(&re, buf, 2, m, 0);
401 if (!rc && (m[1].rm_so >= 0)) {
402 buf[m[1].rm_eo] = 0;
403 *field = atoi(&buf[m[1].rm_so]);
404 ret = 0;
405 break;
406 }
407 }
408 }
409
410 regfree(&re);
411 if (ret)
412 sigma_dut_print(dut, DUT_MSG_ERROR,
413 "could not extract field");
414
415out:
416 fclose(f);
417
418 return ret;
419}
420
421
422static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
423 unsigned int *cid)
424{
425 const char *pattern = "\\[([0-9]+)\\]";
426
427 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
428}
429
430
431static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
432 int l_rx)
433{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700434 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200435 unsigned int cid;
436
Rakesh Sunki556237d2017-03-30 14:49:31 -0700437 memset(&cmd, 0, sizeof(cmd));
438
Lior David0fe101e2017-03-09 16:09:50 +0200439 if (wil6210_get_cid(dut, mac, &cid))
440 return -1;
441
442 cmd.bf_type = WIL_WMI_BRP_RX;
443 cmd.sta_id = cid;
444 /* training length (l_rx) is ignored, FW always uses length 16 */
445 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
446 &cmd, sizeof(cmd));
447}
448
449
450static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
451{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700452 struct wil_wmi_bf_trig_cmd cmd;
453
454 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200455
456 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
457 return -1;
458
459 cmd.bf_type = WIL_WMI_SLS;
460 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
461 &cmd, sizeof(cmd));
462}
463
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200464
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200465int wil6210_set_ese(struct sigma_dut *dut, int count,
466 struct sigma_ese_alloc *allocs)
467{
468 struct wil_wmi_ese_cfg cmd = { };
469 int i;
470
471 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
472 return -1;
473
474 if (dut->ap_bcnint <= 0) {
475 sigma_dut_print(dut, DUT_MSG_ERROR,
476 "invalid beacon interval(%d), check test",
477 dut->ap_bcnint);
478 return -1;
479 }
480
481 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
482 cmd.flags = 0x1d;
483 cmd.num_allocs = count;
484 for (i = 0; i < count; i++) {
485 /*
486 * Convert percent from BI (BI specified in milliseconds)
487 * to absolute duration in microseconds.
488 */
489 cmd.slots[i].duration =
490 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
491 switch (allocs[i].type) {
492 case ESE_CBAP:
493 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
494 break;
495 case ESE_SP:
496 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
497 break;
498 default:
499 sigma_dut_print(dut, DUT_MSG_ERROR,
500 "invalid slot type(%d) at index %d",
501 allocs[i].type, i);
502 return -1;
503 }
504 cmd.slots[i].src_aid = allocs[i].src_aid;
505 cmd.slots[i].dst_aid = allocs[i].dst_aid;
506 sigma_dut_print(dut, DUT_MSG_INFO,
507 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
508 i, cmd.slots[i].duration,
509 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
510 cmd.slots[i].dst_aid);
511 }
512
513 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
514}
515
516
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200517int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
518{
519 struct wil_wmi_force_mcs cmd = { };
520
521 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
522 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
523 cmd.force_enable = (uint32_t) force;
524 cmd.mcs = (uint32_t) mcs;
525
526 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
527 &cmd, sizeof(cmd));
528}
529
530
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200531static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
532{
533 struct wil_wmi_force_rsn_ie cmd = { };
534
535 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
536 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
537 cmd.state = (uint32_t) state;
538
539 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
540 &cmd, sizeof(cmd));
541}
542
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300543
544/*
545 * this function is also used to configure generic remain-on-channel
546 */
547static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
548{
549 struct wil_wmi_p2p_cfg_cmd cmd = { };
550 int channel = freq_to_channel(freq);
551
552 if (channel < 0)
553 return -1;
554 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
555 cmd.channel = channel - 1;
556 cmd.bcon_interval = WIL_DEFAULT_BI;
557 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
558
559 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
560 &cmd, sizeof(cmd));
561}
562
563
564static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
565{
566 int ret = wil6210_p2p_cfg(dut, freq);
567
568 if (ret)
569 return ret;
570
571 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
572 if (!ret) {
573 /*
574 * wait a bit to allow FW to setup the radio
575 * especially important if we switch channels
576 */
577 usleep(500000);
578 }
579
580 return ret;
581}
582
583
584static int wil6210_stop_discovery(struct sigma_dut *dut)
585{
586 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
587}
588
589
590static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
591 int wait_duration,
592 const char *frame, size_t frame_len)
593{
594 char buf[128], fname[128];
595 FILE *f;
596 int res = 0;
597 size_t written;
598
599 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
600 sigma_dut_print(dut, DUT_MSG_ERROR,
601 "failed to get wil6210 debugfs dir");
602 return -1;
603 }
604 snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
605
606 if (wil6210_remain_on_channel(dut, freq)) {
607 sigma_dut_print(dut, DUT_MSG_ERROR,
608 "failed to listen on channel");
609 return -1;
610 }
611
612 f = fopen(fname, "wb");
613 if (!f) {
614 sigma_dut_print(dut, DUT_MSG_ERROR,
615 "failed to open: %s", fname);
616 res = -1;
617 goto out_stop;
618 }
619 written = fwrite(frame, 1, frame_len, f);
620 fclose(f);
621
622 if (written != frame_len) {
623 sigma_dut_print(dut, DUT_MSG_ERROR,
624 "failed to transmit frame (got %zd, expected %zd)",
625 written, frame_len);
626 res = -1;
627 goto out_stop;
628 }
629
630 usleep(wait_duration * 1000);
631
632out_stop:
633 wil6210_stop_discovery(dut);
634 return res;
635}
636
637
638static int find_template_frame_tag(struct template_frame_tag *tags,
639 int total_tags, int tag_num)
640{
641 int i;
642
643 for (i = 0; i < total_tags; i++) {
644 if (tag_num == tags[i].num)
645 return i;
646 }
647
648 return -1;
649}
650
651
652static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
653 int id, const char *value, size_t val_len)
654{
655 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
656
657 if (len < 3 + val_len) {
658 sigma_dut_print(dut, DUT_MSG_ERROR,
659 "not enough space to replace P2P attribute");
660 return -1;
661 }
662
663 if (attr->len != val_len) {
664 sigma_dut_print(dut, DUT_MSG_ERROR,
665 "attribute length mismatch (need %zu have %hu)",
666 val_len, attr->len);
667 return -1;
668 }
669
670 if (attr->id != id) {
671 sigma_dut_print(dut, DUT_MSG_ERROR,
672 "incorrect attribute id (expected %d actual %d)",
673 id, attr->id);
674 return -1;
675 }
676
677 memcpy(attr->variable, value, val_len);
678
679 return 0;
680}
681
682
683static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
684 char *buf, size_t *length,
685 struct template_frame_tag *tags,
686 size_t *num_tags)
687{
688 char line[512];
689 FILE *f;
690 size_t offset = 0, tag_index = 0;
691 int num, index;
692 int in_tag = 0, tag_num = 0, tag_offset = 0;
693
694 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
695 sigma_dut_print(dut, DUT_MSG_ERROR,
696 "supplied buffer is too small");
697 return -1;
698 }
699
700 f = fopen(fname, "r");
701 if (!f) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "failed to open template file %s", fname);
704 return -1;
705 }
706
707 /*
708 * template file format: lines beginning with # are comments and
709 * ignored.
710 * It is possible to tag bytes in the frame to make it easy
711 * to replace fields in the template, espcially if they appear
712 * in variable-sized sections (such as IEs)
713 * This is done by a line beginning with $NUM where NUM is an integer
714 * tag number. It can be followed by space(s) and comment.
715 * The next line is considered the tagged bytes. The parser will fill
716 * the tag number, offset and length of the tagged bytes.
717 * rest of the lines contain frame bytes as sequence of hex digits,
718 * 2 digits for each byte. Spaces are allowed between bytes.
719 * On bytes lines only hex digits and spaces are allowed
720 */
721 while (!feof(f)) {
722 if (!fgets(line, sizeof(line), f))
723 break;
724 index = 0;
725 while (isspace((unsigned char) line[index]))
726 index++;
727 if (!line[index] || line[index] == '#')
728 continue;
729 if (line[index] == '$') {
730 if (tags) {
731 index++;
732 tag_num = strtol(&line[index], NULL, 0);
733 tag_offset = offset;
734 in_tag = 1;
735 }
736 continue;
737 }
738 while (line[index]) {
739 if (isspace((unsigned char) line[index])) {
740 index++;
741 continue;
742 }
743 num = hex_byte(&line[index]);
744 if (num < 0)
745 break;
746 buf[offset++] = num;
747 if (offset == *length)
748 goto out;
749 index += 2;
750 }
751
752 if (in_tag) {
753 if (tag_index < *num_tags) {
754 tags[tag_index].num = tag_num;
755 tags[tag_index].offset = tag_offset;
756 tags[tag_index].len = offset - tag_offset;
757 tag_index++;
758 } else {
759 sigma_dut_print(dut, DUT_MSG_INFO,
760 "too many tags, tag ignored");
761 }
762 in_tag = 0;
763 }
764 }
765
766 if (num_tags)
767 *num_tags = tag_index;
768out:
769 fclose(f);
770 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
771 sigma_dut_print(dut, DUT_MSG_ERROR,
772 "template frame is too small");
773 return -1;
774 }
775
776 *length = offset;
777 return 0;
778}
779
Lior Davidcc88b562017-01-03 18:52:09 +0200780#endif /* __linux__ */
781
782
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200783static void static_ip_file(int proto, const char *addr, const char *mask,
784 const char *gw)
785{
786 if (proto) {
787 FILE *f = fopen("static-ip", "w");
788 if (f) {
789 fprintf(f, "%d %s %s %s\n", proto, addr,
790 mask ? mask : "N/A",
791 gw ? gw : "N/A");
792 fclose(f);
793 }
794 } else {
795 unlink("static-ip");
796 }
797}
798
799
800static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
801 const char *ssid)
802{
803#ifdef __linux__
804 char buf[100];
805
806 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
807 intf, ssid);
808 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
809
810 if (system(buf) != 0) {
811 sigma_dut_print(dut, DUT_MSG_ERROR,
812 "iwpriv neighbor request failed");
813 return -1;
814 }
815
816 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
817
818 return 0;
819#else /* __linux__ */
820 return -1;
821#endif /* __linux__ */
822}
823
824
825static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530826 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200827{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530828 const char *val;
829 int reason_code = 0;
830 char buf[1024];
831
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200832 /*
833 * In the earlier builds we used WNM_QUERY and in later
834 * builds used WNM_BSS_QUERY.
835 */
836
Ashwini Patil5acd7382017-04-13 15:55:04 +0530837 val = get_param(cmd, "BTMQuery_Reason_Code");
838 if (val)
839 reason_code = atoi(val);
840
841 val = get_param(cmd, "Cand_List");
842 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
843 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
844 dut->btm_query_cand_list);
845 free(dut->btm_query_cand_list);
846 dut->btm_query_cand_list = NULL;
847 } else {
848 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
849 }
850
851 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200852 sigma_dut_print(dut, DUT_MSG_ERROR,
853 "transition management query failed");
854 return -1;
855 }
856
857 sigma_dut_print(dut, DUT_MSG_DEBUG,
858 "transition management query sent");
859
860 return 0;
861}
862
863
864int is_ip_addr(const char *str)
865{
866 const char *pos = str;
867 struct in_addr addr;
868
869 while (*pos) {
870 if (*pos != '.' && (*pos < '0' || *pos > '9'))
871 return 0;
872 pos++;
873 }
874
875 return inet_aton(str, &addr);
876}
877
878
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200879int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
880 size_t buf_len)
881{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530882 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200883 char ip[16], mask[15], dns[16], sec_dns[16];
884 int is_dhcp = 0;
885 int s;
886#ifdef ANDROID
887 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530888#else /* ANDROID */
889 FILE *f;
890#ifdef __linux__
891 const char *str_ps;
892#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200893#endif /* ANDROID */
894
895 ip[0] = '\0';
896 mask[0] = '\0';
897 dns[0] = '\0';
898 sec_dns[0] = '\0';
899
900 s = socket(PF_INET, SOCK_DGRAM, 0);
901 if (s >= 0) {
902 struct ifreq ifr;
903 struct sockaddr_in saddr;
904
905 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700906 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200907 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
908 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
909 "%s IP address: %s",
910 ifname, strerror(errno));
911 } else {
912 memcpy(&saddr, &ifr.ifr_addr,
913 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700914 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200915 }
916
917 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
918 memcpy(&saddr, &ifr.ifr_addr,
919 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700920 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200921 }
922 close(s);
923 }
924
925#ifdef ANDROID
926 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
927 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
928 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
929 if (property_get(tmp, prop, NULL) != 0 &&
930 strcmp(prop, "ok") == 0) {
931 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
932 ifname);
933 if (property_get(tmp, prop, NULL) != 0 &&
934 strcmp(ip, prop) == 0)
935 is_dhcp = 1;
936 }
937 }
938
939 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700940 if (property_get(tmp, prop, NULL) != 0)
941 strlcpy(dns, prop, sizeof(dns));
942 else if (property_get("net.dns1", prop, NULL) != 0)
943 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200944
945 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700946 if (property_get(tmp, prop, NULL) != 0)
947 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200948#else /* ANDROID */
949#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530950 if (get_driver_type() == DRIVER_OPENWRT)
951 str_ps = "ps -w";
952 else
953 str_ps = "ps ax";
954 snprintf(tmp, sizeof(tmp),
955 "%s | grep dhclient | grep -v grep | grep -q %s",
956 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200957 if (system(tmp) == 0)
958 is_dhcp = 1;
959 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530960 snprintf(tmp, sizeof(tmp),
961 "%s | grep udhcpc | grep -v grep | grep -q %s",
962 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200963 if (system(tmp) == 0)
964 is_dhcp = 1;
965 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530966 snprintf(tmp, sizeof(tmp),
967 "%s | grep dhcpcd | grep -v grep | grep -q %s",
968 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200969 if (system(tmp) == 0)
970 is_dhcp = 1;
971 }
972 }
973#endif /* __linux__ */
974
975 f = fopen("/etc/resolv.conf", "r");
976 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530977 char *pos, *pos2;
978
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200979 while (fgets(tmp, sizeof(tmp), f)) {
980 if (strncmp(tmp, "nameserver", 10) != 0)
981 continue;
982 pos = tmp + 10;
983 while (*pos == ' ' || *pos == '\t')
984 pos++;
985 pos2 = pos;
986 while (*pos2) {
987 if (*pos2 == '\n' || *pos2 == '\r') {
988 *pos2 = '\0';
989 break;
990 }
991 pos2++;
992 }
Peng Xub8fc5cc2017-05-10 17:27:28 -0700993 if (!dns[0])
994 strlcpy(dns, pos, sizeof(dns));
995 else if (!sec_dns[0])
996 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200997 }
998 fclose(f);
999 }
1000#endif /* ANDROID */
1001
1002 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1003 is_dhcp, ip, mask, dns);
1004 buf[buf_len - 1] = '\0';
1005
1006 return 0;
1007}
1008
1009
1010
1011
1012int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1013 size_t buf_len)
1014{
1015#ifdef __linux__
1016#ifdef ANDROID
1017 char cmd[200], result[1000], *pos, *end;
1018 FILE *f;
1019 size_t len;
1020
1021 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1022 f = popen(cmd, "r");
1023 if (f == NULL)
1024 return -1;
1025 len = fread(result, 1, sizeof(result) - 1, f);
1026 pclose(f);
1027 if (len == 0)
1028 return -1;
1029 result[len] = '\0';
1030 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1031
1032 pos = strstr(result, "inet6 ");
1033 if (pos == NULL)
1034 return -1;
1035 pos += 6;
1036 end = strchr(pos, ' ');
1037 if (end)
1038 *end = '\0';
1039 end = strchr(pos, '/');
1040 if (end)
1041 *end = '\0';
1042 snprintf(buf, buf_len, "ip,%s", pos);
1043 buf[buf_len - 1] = '\0';
1044 return 0;
1045#else /* ANDROID */
1046 struct ifaddrs *ifaddr, *ifa;
1047 int res, found = 0;
1048 char host[NI_MAXHOST];
1049
1050 if (getifaddrs(&ifaddr) < 0) {
1051 perror("getifaddrs");
1052 return -1;
1053 }
1054
1055 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1056 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1057 continue;
1058 if (ifa->ifa_addr == NULL ||
1059 ifa->ifa_addr->sa_family != AF_INET6)
1060 continue;
1061
1062 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1063 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1064 if (res != 0) {
1065 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1066 gai_strerror(res));
1067 continue;
1068 }
1069 if (strncmp(host, "fe80::", 6) == 0)
1070 continue; /* skip link-local */
1071
1072 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1073 found = 1;
1074 break;
1075 }
1076
1077 freeifaddrs(ifaddr);
1078
1079 if (found) {
1080 char *pos;
1081 pos = strchr(host, '%');
1082 if (pos)
1083 *pos = '\0';
1084 snprintf(buf, buf_len, "ip,%s", host);
1085 buf[buf_len - 1] = '\0';
1086 return 0;
1087 }
1088
1089#endif /* ANDROID */
1090#endif /* __linux__ */
1091 return -1;
1092}
1093
1094
1095static int cmd_sta_get_ip_config(struct sigma_dut *dut,
1096 struct sigma_conn *conn,
1097 struct sigma_cmd *cmd)
1098{
1099 const char *intf = get_param(cmd, "Interface");
1100 const char *ifname;
1101 char buf[200];
1102 const char *val;
1103 int type = 1;
1104
1105 if (intf == NULL)
1106 return -1;
1107
1108 if (strcmp(intf, get_main_ifname()) == 0)
1109 ifname = get_station_ifname();
1110 else
1111 ifname = intf;
1112
1113 /*
1114 * UCC may assume the IP address to be available immediately after
1115 * association without trying to run sta_get_ip_config multiple times.
1116 * Sigma CAPI does not specify this command as a block command that
1117 * would wait for the address to become available, but to pass tests
1118 * more reliably, it looks like such a wait may be needed here.
1119 */
1120 if (wait_ip_addr(dut, ifname, 15) < 0) {
1121 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1122 "for sta_get_ip_config");
1123 /*
1124 * Try to continue anyway since many UCC tests do not really
1125 * care about the return value from here..
1126 */
1127 }
1128
1129 val = get_param(cmd, "Type");
1130 if (val)
1131 type = atoi(val);
1132 if (type == 2 || dut->last_set_ip_config_ipv6) {
1133 int i;
1134
1135 /*
1136 * Since we do not have proper wait for IPv6 addresses, use a
1137 * fixed two second delay here as a workaround for UCC script
1138 * assuming IPv6 address is available when this command returns.
1139 * Some scripts did not use Type,2 properly for IPv6, so include
1140 * also the cases where the previous sta_set_ip_config indicated
1141 * use of IPv6.
1142 */
1143 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1144 for (i = 0; i < 10; i++) {
1145 sleep(1);
1146 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1147 {
1148 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1149 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1150#ifdef ANDROID
1151 sigma_dut_print(dut, DUT_MSG_INFO,
1152 "Adding IPv6 rule on Android");
1153 add_ipv6_rule(dut, intf);
1154#endif /* ANDROID */
1155
1156 return 0;
1157 }
1158 }
1159 }
1160 if (type == 1) {
1161 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1162 return -2;
1163 } else if (type == 2) {
1164 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1165 return -2;
1166 } else {
1167 send_resp(dut, conn, SIGMA_ERROR,
1168 "errorCode,Unsupported address type");
1169 return 0;
1170 }
1171
1172 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1173 return 0;
1174}
1175
1176
1177static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1178{
1179#ifdef __linux__
1180 char buf[200];
1181 char path[128];
1182 struct stat s;
1183
1184#ifdef ANDROID
1185 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1186#else /* ANDROID */
1187 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1188#endif /* ANDROID */
1189 if (stat(path, &s) == 0) {
1190 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1191 sigma_dut_print(dut, DUT_MSG_INFO,
1192 "Kill previous DHCP client: %s", buf);
1193 if (system(buf) != 0)
1194 sigma_dut_print(dut, DUT_MSG_INFO,
1195 "Failed to kill DHCP client");
1196 unlink(path);
1197 sleep(1);
1198 } else {
1199 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1200
1201 if (stat(path, &s) == 0) {
1202 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1203 sigma_dut_print(dut, DUT_MSG_INFO,
1204 "Kill previous DHCP client: %s", buf);
1205 if (system(buf) != 0)
1206 sigma_dut_print(dut, DUT_MSG_INFO,
1207 "Failed to kill DHCP client");
1208 unlink(path);
1209 sleep(1);
1210 }
1211 }
1212#endif /* __linux__ */
1213}
1214
1215
1216static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1217{
1218#ifdef __linux__
1219 char buf[200];
1220
1221#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301222 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1223 snprintf(buf, sizeof(buf),
1224 "/system/bin/dhcpcd -b %s", ifname);
1225 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1226 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301227 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1228 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1229 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1230 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301231 } else {
1232 sigma_dut_print(dut, DUT_MSG_ERROR,
1233 "DHCP client program missing");
1234 return 0;
1235 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001236#else /* ANDROID */
1237 snprintf(buf, sizeof(buf),
1238 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1239 ifname, ifname);
1240#endif /* ANDROID */
1241 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1242 if (system(buf) != 0) {
1243 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1244 if (system(buf) != 0) {
1245 sigma_dut_print(dut, DUT_MSG_INFO,
1246 "Failed to start DHCP client");
1247#ifndef ANDROID
1248 return -1;
1249#endif /* ANDROID */
1250 }
1251 }
1252#endif /* __linux__ */
1253
1254 return 0;
1255}
1256
1257
1258static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1259{
1260#ifdef __linux__
1261 char buf[200];
1262
1263 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1264 if (system(buf) != 0) {
1265 sigma_dut_print(dut, DUT_MSG_INFO,
1266 "Failed to clear IP addresses");
1267 return -1;
1268 }
1269#endif /* __linux__ */
1270
1271 return 0;
1272}
1273
1274
1275#ifdef ANDROID
1276static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1277{
1278 char cmd[200], *result, *pos;
1279 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301280 int tableid;
1281 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001282
1283 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1284 ifname);
1285 fp = popen(cmd, "r");
1286 if (fp == NULL)
1287 return -1;
1288
1289 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301290 if (result == NULL) {
1291 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001292 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301293 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001294
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301295 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001296 fclose(fp);
1297
1298 if (len == 0) {
1299 free(result);
1300 return -1;
1301 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301302 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001303
1304 pos = strstr(result, "table ");
1305 if (pos == NULL) {
1306 free(result);
1307 return -1;
1308 }
1309
1310 pos += strlen("table ");
1311 tableid = atoi(pos);
1312 if (tableid != 0) {
1313 if (system("ip -6 rule del prio 22000") != 0) {
1314 /* ignore any error */
1315 }
1316 snprintf(cmd, sizeof(cmd),
1317 "ip -6 rule add from all lookup %d prio 22000",
1318 tableid);
1319 if (system(cmd) != 0) {
1320 sigma_dut_print(dut, DUT_MSG_INFO,
1321 "Failed to run %s", cmd);
1322 free(result);
1323 return -1;
1324 }
1325 } else {
1326 sigma_dut_print(dut, DUT_MSG_INFO,
1327 "No Valid Table Id found %s", pos);
1328 free(result);
1329 return -1;
1330 }
1331 free(result);
1332
1333 return 0;
1334}
1335#endif /* ANDROID */
1336
1337
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301338int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1339 const char *ip, const char *mask)
1340{
1341 char buf[200];
1342
1343 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1344 ifname, ip, mask);
1345 return system(buf) == 0;
1346}
1347
1348
1349int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1350{
1351 char buf[200];
1352
1353 if (!is_ip_addr(gw)) {
1354 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1355 return -1;
1356 }
1357
1358 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1359 if (!dut->no_ip_addr_set && system(buf) != 0) {
1360 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1361 gw);
1362 if (system(buf) != 0)
1363 return 0;
1364 }
1365
1366 return 1;
1367}
1368
1369
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001370static int cmd_sta_set_ip_config(struct sigma_dut *dut,
1371 struct sigma_conn *conn,
1372 struct sigma_cmd *cmd)
1373{
1374 const char *intf = get_param(cmd, "Interface");
1375 const char *ifname;
1376 char buf[200];
1377 const char *val, *ip, *mask, *gw;
1378 int type = 1;
1379
1380 if (intf == NULL)
1381 return -1;
1382
1383 if (strcmp(intf, get_main_ifname()) == 0)
1384 ifname = get_station_ifname();
1385 else
1386 ifname = intf;
1387
1388 if (if_nametoindex(ifname) == 0) {
1389 send_resp(dut, conn, SIGMA_ERROR,
1390 "ErrorCode,Unknown interface");
1391 return 0;
1392 }
1393
1394 val = get_param(cmd, "Type");
1395 if (val) {
1396 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301397 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001398 send_resp(dut, conn, SIGMA_ERROR,
1399 "ErrorCode,Unsupported address type");
1400 return 0;
1401 }
1402 }
1403
1404 dut->last_set_ip_config_ipv6 = 0;
1405
1406 val = get_param(cmd, "dhcp");
1407 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1408 static_ip_file(0, NULL, NULL, NULL);
1409#ifdef __linux__
1410 if (type == 2) {
1411 dut->last_set_ip_config_ipv6 = 1;
1412 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1413 "stateless address autoconfiguration");
1414#ifdef ANDROID
1415 /*
1416 * This sleep is required as the assignment in case of
1417 * Android is taking time and is done by the kernel.
1418 * The subsequent ping for IPv6 is impacting HS20 test
1419 * case.
1420 */
1421 sleep(2);
1422 add_ipv6_rule(dut, intf);
1423#endif /* ANDROID */
1424 /* Assume this happens by default */
1425 return 1;
1426 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301427 if (type != 3) {
1428 kill_dhcp_client(dut, ifname);
1429 if (start_dhcp_client(dut, ifname) < 0)
1430 return -2;
1431 } else {
1432 sigma_dut_print(dut, DUT_MSG_DEBUG,
1433 "Using FILS HLP DHCPv4 Rapid Commit");
1434 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001435
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001436 return 1;
1437#endif /* __linux__ */
1438 return -2;
1439 }
1440
1441 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301442 if (!ip) {
1443 send_resp(dut, conn, SIGMA_INVALID,
1444 "ErrorCode,Missing IP address");
1445 return 0;
1446 }
1447
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001448 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301449 if (!mask) {
1450 send_resp(dut, conn, SIGMA_INVALID,
1451 "ErrorCode,Missing subnet mask");
1452 return 0;
1453 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001454
1455 if (type == 2) {
1456 int net = atoi(mask);
1457
1458 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1459 return -1;
1460
1461 if (dut->no_ip_addr_set) {
1462 snprintf(buf, sizeof(buf),
1463 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1464 ifname);
1465 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1466 if (system(buf) != 0) {
1467 sigma_dut_print(dut, DUT_MSG_DEBUG,
1468 "Failed to disable IPv6 address before association");
1469 }
1470 } else {
1471 snprintf(buf, sizeof(buf),
1472 "ip -6 addr del %s/%s dev %s",
1473 ip, mask, ifname);
1474 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1475 if (system(buf) != 0) {
1476 /*
1477 * This command may fail if the address being
1478 * deleted does not exist. Inaction here is
1479 * intentional.
1480 */
1481 }
1482
1483 snprintf(buf, sizeof(buf),
1484 "ip -6 addr add %s/%s dev %s",
1485 ip, mask, ifname);
1486 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1487 if (system(buf) != 0) {
1488 send_resp(dut, conn, SIGMA_ERROR,
1489 "ErrorCode,Failed to set IPv6 address");
1490 return 0;
1491 }
1492 }
1493
1494 dut->last_set_ip_config_ipv6 = 1;
1495 static_ip_file(6, ip, mask, NULL);
1496 return 1;
1497 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301498 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001499 return -1;
1500 }
1501
1502 kill_dhcp_client(dut, ifname);
1503
1504 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301505 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001506 send_resp(dut, conn, SIGMA_ERROR,
1507 "ErrorCode,Failed to set IP address");
1508 return 0;
1509 }
1510 }
1511
1512 gw = get_param(cmd, "defaultGateway");
1513 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301514 if (set_ipv4_gw(dut, gw) < 1) {
1515 send_resp(dut, conn, SIGMA_ERROR,
1516 "ErrorCode,Failed to set default gateway");
1517 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001518 }
1519 }
1520
1521 val = get_param(cmd, "primary-dns");
1522 if (val) {
1523 /* TODO */
1524 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1525 "setting", val);
1526 }
1527
1528 val = get_param(cmd, "secondary-dns");
1529 if (val) {
1530 /* TODO */
1531 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1532 "setting", val);
1533 }
1534
1535 static_ip_file(4, ip, mask, gw);
1536
1537 return 1;
1538}
1539
1540
1541static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1542 struct sigma_cmd *cmd)
1543{
1544 /* const char *intf = get_param(cmd, "Interface"); */
1545 /* TODO: could report more details here */
1546 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1547 return 0;
1548}
1549
1550
1551static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1552 struct sigma_conn *conn,
1553 struct sigma_cmd *cmd)
1554{
1555 /* const char *intf = get_param(cmd, "Interface"); */
1556 char addr[20], resp[50];
1557
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301558 if (dut->dev_role == DEVROLE_STA_CFON)
1559 return sta_cfon_get_mac_address(dut, conn, cmd);
1560
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001561 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1562 < 0)
1563 return -2;
1564
1565 snprintf(resp, sizeof(resp), "mac,%s", addr);
1566 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1567 return 0;
1568}
1569
1570
1571static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1572 struct sigma_cmd *cmd)
1573{
1574 /* const char *intf = get_param(cmd, "Interface"); */
1575 int connected = 0;
1576 char result[32];
1577 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1578 sizeof(result)) < 0) {
1579 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1580 "%s status", get_station_ifname());
1581 return -2;
1582 }
1583
1584 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1585 if (strncmp(result, "COMPLETED", 9) == 0)
1586 connected = 1;
1587
1588 if (connected)
1589 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1590 else
1591 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1592
1593 return 0;
1594}
1595
1596
1597static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1598 struct sigma_conn *conn,
1599 struct sigma_cmd *cmd)
1600{
1601 /* const char *intf = get_param(cmd, "Interface"); */
1602 const char *dst, *timeout;
1603 int wait_time = 90;
1604 char buf[100];
1605 int res;
1606
1607 dst = get_param(cmd, "destination");
1608 if (dst == NULL || !is_ip_addr(dst))
1609 return -1;
1610
1611 timeout = get_param(cmd, "timeout");
1612 if (timeout) {
1613 wait_time = atoi(timeout);
1614 if (wait_time < 1)
1615 wait_time = 1;
1616 }
1617
1618 /* TODO: force renewal of IP lease if DHCP is enabled */
1619
1620 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1621 res = system(buf);
1622 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1623 if (res == 0)
1624 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1625 else if (res == 256)
1626 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1627 else
1628 return -2;
1629
1630 return 0;
1631}
1632
1633
1634static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1635 struct sigma_cmd *cmd)
1636{
1637 /* const char *intf = get_param(cmd, "Interface"); */
1638 char bssid[20], resp[50];
1639
1640 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1641 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001642 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001643
1644 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1645 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1646 return 0;
1647}
1648
1649
1650#ifdef __SAMSUNG__
1651static int add_use_network(const char *ifname)
1652{
1653 char buf[100];
1654
1655 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1656 wpa_command(ifname, buf);
1657 return 0;
1658}
1659#endif /* __SAMSUNG__ */
1660
1661
1662static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1663 const char *ifname, struct sigma_cmd *cmd)
1664{
1665 const char *ssid = get_param(cmd, "ssid");
1666 int id;
1667 const char *val;
1668
1669 if (ssid == NULL)
1670 return -1;
1671
1672 start_sta_mode(dut);
1673
1674#ifdef __SAMSUNG__
1675 add_use_network(ifname);
1676#endif /* __SAMSUNG__ */
1677
1678 id = add_network(ifname);
1679 if (id < 0)
1680 return -2;
1681 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1682
1683 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1684 return -2;
1685
1686 dut->infra_network_id = id;
1687 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1688
1689 val = get_param(cmd, "program");
1690 if (!val)
1691 val = get_param(cmd, "prog");
1692 if (val && strcasecmp(val, "hs2") == 0) {
1693 char buf[100];
1694 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1695 wpa_command(ifname, buf);
1696
1697 val = get_param(cmd, "prefer");
1698 if (val && atoi(val) > 0)
1699 set_network(ifname, id, "priority", "1");
1700 }
1701
1702 return id;
1703}
1704
1705
1706static int cmd_sta_set_encryption(struct sigma_dut *dut,
1707 struct sigma_conn *conn,
1708 struct sigma_cmd *cmd)
1709{
1710 const char *intf = get_param(cmd, "Interface");
1711 const char *ssid = get_param(cmd, "ssid");
1712 const char *type = get_param(cmd, "encpType");
1713 const char *ifname;
1714 char buf[200];
1715 int id;
1716
1717 if (intf == NULL || ssid == NULL)
1718 return -1;
1719
1720 if (strcmp(intf, get_main_ifname()) == 0)
1721 ifname = get_station_ifname();
1722 else
1723 ifname = intf;
1724
1725 id = add_network_common(dut, conn, ifname, cmd);
1726 if (id < 0)
1727 return id;
1728
1729 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1730 return -2;
1731
1732 if (type && strcasecmp(type, "wep") == 0) {
1733 const char *val;
1734 int i;
1735
1736 val = get_param(cmd, "activeKey");
1737 if (val) {
1738 int keyid;
1739 keyid = atoi(val);
1740 if (keyid < 1 || keyid > 4)
1741 return -1;
1742 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1743 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1744 return -2;
1745 }
1746
1747 for (i = 0; i < 4; i++) {
1748 snprintf(buf, sizeof(buf), "key%d", i + 1);
1749 val = get_param(cmd, buf);
1750 if (val == NULL)
1751 continue;
1752 snprintf(buf, sizeof(buf), "wep_key%d", i);
1753 if (set_network(ifname, id, buf, val) < 0)
1754 return -2;
1755 }
1756 }
1757
1758 return 1;
1759}
1760
1761
Jouni Malinene4fde732019-03-25 22:29:37 +02001762static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1763 int id, const char *val)
1764{
1765 char key_mgmt[200], *end, *pos;
1766 const char *in_pos = val;
1767
Jouni Malinen8179fee2019-03-28 03:19:47 +02001768 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001769 pos = key_mgmt;
1770 end = pos + sizeof(key_mgmt);
1771 while (*in_pos) {
1772 int res, akm = atoi(in_pos);
1773 const char *str;
1774
Jouni Malinen8179fee2019-03-28 03:19:47 +02001775 if (akm >= 0 && akm < 32)
1776 dut->akm_values |= 1 << akm;
1777
Jouni Malinene4fde732019-03-25 22:29:37 +02001778 switch (akm) {
1779 case AKM_WPA_EAP:
1780 str = "WPA-EAP";
1781 break;
1782 case AKM_WPA_PSK:
1783 str = "WPA-PSK";
1784 break;
1785 case AKM_FT_EAP:
1786 str = "FT-EAP";
1787 break;
1788 case AKM_FT_PSK:
1789 str = "FT-PSK";
1790 break;
1791 case AKM_EAP_SHA256:
1792 str = "WPA-EAP-SHA256";
1793 break;
1794 case AKM_PSK_SHA256:
1795 str = "WPA-PSK-SHA256";
1796 break;
1797 case AKM_SAE:
1798 str = "SAE";
1799 break;
1800 case AKM_FT_SAE:
1801 str = "FT-SAE";
1802 break;
1803 case AKM_SUITE_B:
1804 str = "WPA-EAP-SUITE-B-192";
1805 break;
1806 case AKM_FT_SUITE_B:
1807 str = "FT-EAP-SHA384";
1808 break;
1809 case AKM_FILS_SHA256:
1810 str = "FILS-SHA256";
1811 break;
1812 case AKM_FILS_SHA384:
1813 str = "FILS-SHA384";
1814 break;
1815 case AKM_FT_FILS_SHA256:
1816 str = "FT-FILS-SHA256";
1817 break;
1818 case AKM_FT_FILS_SHA384:
1819 str = "FT-FILS-SHA384";
1820 break;
1821 default:
1822 sigma_dut_print(dut, DUT_MSG_ERROR,
1823 "Unsupported AKMSuitetype %d", akm);
1824 return -1;
1825 }
1826
1827 res = snprintf(pos, end - pos, "%s%s",
1828 pos == key_mgmt ? "" : " ", str);
1829 if (res < 0 || res >= end - pos)
1830 return -1;
1831 pos += res;
1832
1833 in_pos = strchr(in_pos, ';');
1834 if (!in_pos)
1835 break;
1836 while (*in_pos == ';')
1837 in_pos++;
1838 }
1839 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1840 val, key_mgmt);
1841 return set_network(ifname, id, "key_mgmt", key_mgmt);
1842}
1843
1844
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001845static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1846 const char *ifname, struct sigma_cmd *cmd)
1847{
1848 const char *val;
1849 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001850 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001851 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301852 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001853
1854 id = add_network_common(dut, conn, ifname, cmd);
1855 if (id < 0)
1856 return id;
1857
Jouni Malinen47dcc952017-10-09 16:43:24 +03001858 val = get_param(cmd, "Type");
1859 owe = val && strcasecmp(val, "OWE") == 0;
1860
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001861 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001862 if (!val && owe)
1863 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001864 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001865 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1866 * this missing parameter and assume proto=WPA2. */
1867 if (set_network(ifname, id, "proto", "WPA2") < 0)
1868 return ERROR_SEND_STATUS;
1869 } else if (strcasecmp(val, "wpa") == 0 ||
1870 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001871 if (set_network(ifname, id, "proto", "WPA") < 0)
1872 return -2;
1873 } else if (strcasecmp(val, "wpa2") == 0 ||
1874 strcasecmp(val, "wpa2-psk") == 0 ||
1875 strcasecmp(val, "wpa2-ft") == 0 ||
1876 strcasecmp(val, "wpa2-sha256") == 0) {
1877 if (set_network(ifname, id, "proto", "WPA2") < 0)
1878 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301879 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1880 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001881 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1882 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001883 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301884 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001885 if (set_network(ifname, id, "proto", "WPA2") < 0)
1886 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001887 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001888 } else {
1889 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1890 return 0;
1891 }
1892
1893 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001894 if (val) {
1895 cipher_set = 1;
1896 if (strcasecmp(val, "tkip") == 0) {
1897 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1898 return -2;
1899 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1900 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1901 return -2;
1902 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1903 if (set_network(ifname, id, "pairwise",
1904 "CCMP TKIP") < 0)
1905 return -2;
1906 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1907 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1908 return -2;
1909 if (set_network(ifname, id, "group", "GCMP") < 0)
1910 return -2;
1911 } else {
1912 send_resp(dut, conn, SIGMA_ERROR,
1913 "errorCode,Unrecognized encpType value");
1914 return 0;
1915 }
1916 }
1917
1918 val = get_param(cmd, "PairwiseCipher");
1919 if (val) {
1920 cipher_set = 1;
1921 /* TODO: Support space separated list */
1922 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1923 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1924 return -2;
1925 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1926 if (set_network(ifname, id, "pairwise",
1927 "CCMP-256") < 0)
1928 return -2;
1929 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1930 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1931 return -2;
1932 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1933 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1934 return -2;
1935 } else {
1936 send_resp(dut, conn, SIGMA_ERROR,
1937 "errorCode,Unrecognized PairwiseCipher value");
1938 return 0;
1939 }
1940 }
1941
Jouni Malinen47dcc952017-10-09 16:43:24 +03001942 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001943 send_resp(dut, conn, SIGMA_ERROR,
1944 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001945 return 0;
1946 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001947
1948 val = get_param(cmd, "GroupCipher");
1949 if (val) {
1950 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1951 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1952 return -2;
1953 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1954 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1955 return -2;
1956 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1957 if (set_network(ifname, id, "group", "GCMP") < 0)
1958 return -2;
1959 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1960 if (set_network(ifname, id, "group", "CCMP") < 0)
1961 return -2;
1962 } else {
1963 send_resp(dut, conn, SIGMA_ERROR,
1964 "errorCode,Unrecognized GroupCipher value");
1965 return 0;
1966 }
1967 }
1968
Jouni Malinen7b239522017-09-14 21:37:18 +03001969 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001970 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001971 const char *cipher;
1972
1973 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1974 cipher = "BIP-GMAC-256";
1975 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1976 cipher = "BIP-CMAC-256";
1977 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1978 cipher = "BIP-GMAC-128";
1979 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1980 cipher = "AES-128-CMAC";
1981 } else {
1982 send_resp(dut, conn, SIGMA_INVALID,
1983 "errorCode,Unsupported GroupMgntCipher");
1984 return 0;
1985 }
1986 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1987 send_resp(dut, conn, SIGMA_INVALID,
1988 "errorCode,Failed to set GroupMgntCipher");
1989 return 0;
1990 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001991 }
1992
Jouni Malinene4fde732019-03-25 22:29:37 +02001993 val = get_param(cmd, "AKMSuiteType");
1994 if (val && set_akm_suites(dut, ifname, id, val) < 0)
1995 return ERROR_SEND_STATUS;
1996
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001997 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301998
1999 if (dut->program == PROGRAM_OCE) {
2000 dut->sta_pmf = STA_PMF_OPTIONAL;
2001 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2002 return -2;
2003 }
2004
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002005 val = get_param(cmd, "PMF");
2006 if (val) {
2007 if (strcasecmp(val, "Required") == 0 ||
2008 strcasecmp(val, "Forced_Required") == 0) {
2009 dut->sta_pmf = STA_PMF_REQUIRED;
2010 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2011 return -2;
2012 } else if (strcasecmp(val, "Optional") == 0) {
2013 dut->sta_pmf = STA_PMF_OPTIONAL;
2014 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2015 return -2;
2016 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002017 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002018 strcasecmp(val, "Forced_Disabled") == 0) {
2019 dut->sta_pmf = STA_PMF_DISABLED;
2020 } else {
2021 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2022 return 0;
2023 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302024 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002025 dut->sta_pmf = STA_PMF_REQUIRED;
2026 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2027 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002028 }
2029
2030 return id;
2031}
2032
2033
2034static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
2035 struct sigma_cmd *cmd)
2036{
2037 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002038 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002039 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002040 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002041 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002042 const char *ifname, *val, *alg;
2043 int id;
2044
2045 if (intf == NULL)
2046 return -1;
2047
2048 if (strcmp(intf, get_main_ifname()) == 0)
2049 ifname = get_station_ifname();
2050 else
2051 ifname = intf;
2052
2053 id = set_wpa_common(dut, conn, ifname, cmd);
2054 if (id < 0)
2055 return id;
2056
2057 val = get_param(cmd, "keyMgmtType");
2058 alg = get_param(cmd, "micAlg");
2059
Jouni Malinen992a81e2017-08-22 13:57:47 +03002060 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002061 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002062 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2063 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002064 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002065 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2066 return -2;
2067 }
2068 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2069 sigma_dut_print(dut, DUT_MSG_ERROR,
2070 "Failed to clear sae_groups to default");
2071 return -2;
2072 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002073 if (!pmf) {
2074 dut->sta_pmf = STA_PMF_REQUIRED;
2075 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2076 return -2;
2077 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002078 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2079 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2080 if (set_network(ifname, id, "key_mgmt",
2081 "FT-SAE FT-PSK") < 0)
2082 return -2;
2083 } else {
2084 if (set_network(ifname, id, "key_mgmt",
2085 "SAE WPA-PSK") < 0)
2086 return -2;
2087 }
2088 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2089 sigma_dut_print(dut, DUT_MSG_ERROR,
2090 "Failed to clear sae_groups to default");
2091 return -2;
2092 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002093 if (!pmf) {
2094 dut->sta_pmf = STA_PMF_OPTIONAL;
2095 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2096 return -2;
2097 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002098 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002099 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2100 return -2;
2101 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2102 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2103 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302104 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2105 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2106 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002107 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2108 dut->sta_pmf == STA_PMF_REQUIRED) {
2109 if (set_network(ifname, id, "key_mgmt",
2110 "WPA-PSK WPA-PSK-SHA256") < 0)
2111 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002112 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002113 if (set_network(ifname, id, "key_mgmt",
2114 "WPA-PSK WPA-PSK-SHA256") < 0)
2115 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002116 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002117 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2118 return -2;
2119 }
2120
2121 val = get_param(cmd, "passPhrase");
2122 if (val == NULL)
2123 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002124 if (type && strcasecmp(type, "SAE") == 0) {
2125 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2126 return -2;
2127 } else {
2128 if (set_network_quoted(ifname, id, "psk", val) < 0)
2129 return -2;
2130 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002131
Jouni Malinen78d10c42019-03-25 22:34:32 +02002132 val = get_param(cmd, "PasswordId");
2133 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2134 return ERROR_SEND_STATUS;
2135
Jouni Malinen992a81e2017-08-22 13:57:47 +03002136 val = get_param(cmd, "ECGroupID");
2137 if (val) {
2138 char buf[50];
2139
2140 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
2141 if (wpa_command(ifname, buf) != 0) {
2142 sigma_dut_print(dut, DUT_MSG_ERROR,
2143 "Failed to clear sae_groups");
2144 return -2;
2145 }
2146 }
2147
Jouni Malinen68143132017-09-02 02:34:08 +03002148 val = get_param(cmd, "InvalidSAEElement");
2149 if (val) {
2150 free(dut->sae_commit_override);
2151 dut->sae_commit_override = strdup(val);
2152 }
2153
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002154 if (dut->program == PROGRAM_60GHZ && network_mode &&
2155 strcasecmp(network_mode, "PBSS") == 0 &&
2156 set_network(ifname, id, "pbss", "1") < 0)
2157 return -2;
2158
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002159 return 1;
2160}
2161
2162
2163static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302164 const char *ifname, int username_identity,
2165 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002166{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302167 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002168 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002169 char buf[200], buf2[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002170#ifdef ANDROID
2171 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2172 int length;
2173#endif /* ANDROID */
Jouni Malinen8179fee2019-03-28 03:19:47 +02002174 int erp = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002175
2176 id = set_wpa_common(dut, conn, ifname, cmd);
2177 if (id < 0)
2178 return id;
2179
2180 val = get_param(cmd, "keyMgmtType");
2181 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302182 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002183
Jouni Malinenad395a22017-09-01 21:13:46 +03002184 if (val && strcasecmp(val, "SuiteB") == 0) {
2185 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2186 0)
2187 return -2;
2188 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002189 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2190 return -2;
2191 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2192 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2193 return -2;
2194 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2195 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2196 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002197 } else if (!akm &&
2198 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2199 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002200 if (set_network(ifname, id, "key_mgmt",
2201 "WPA-EAP WPA-EAP-SHA256") < 0)
2202 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302203 } else if (akm && atoi(akm) == 14) {
2204 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2205 dut->sta_pmf == STA_PMF_REQUIRED) {
2206 if (set_network(ifname, id, "key_mgmt",
2207 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2208 return -2;
2209 } else {
2210 if (set_network(ifname, id, "key_mgmt",
2211 "WPA-EAP FILS-SHA256") < 0)
2212 return -2;
2213 }
2214
Jouni Malinen8179fee2019-03-28 03:19:47 +02002215 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302216 } else if (akm && atoi(akm) == 15) {
2217 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2218 dut->sta_pmf == STA_PMF_REQUIRED) {
2219 if (set_network(ifname, id, "key_mgmt",
2220 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2221 return -2;
2222 } else {
2223 if (set_network(ifname, id, "key_mgmt",
2224 "WPA-EAP FILS-SHA384") < 0)
2225 return -2;
2226 }
2227
Jouni Malinen8179fee2019-03-28 03:19:47 +02002228 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002229 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002230 if (set_network(ifname, id, "key_mgmt",
2231 "WPA-EAP WPA-EAP-SHA256") < 0)
2232 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002233 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002234 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2235 return -2;
2236 }
2237
2238 val = get_param(cmd, "trustedRootCA");
2239 if (val) {
2240#ifdef ANDROID
2241 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2242 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
2243 kvalue);
2244 if (length > 0) {
2245 sigma_dut_print(dut, DUT_MSG_INFO,
2246 "Use Android keystore [%s]", buf);
2247 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
2248 val);
2249 goto ca_cert_selected;
2250 }
2251#endif /* ANDROID */
2252
2253 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2254#ifdef __linux__
2255 if (!file_exists(buf)) {
2256 char msg[300];
2257 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
2258 "file (%s) not found", buf);
2259 send_resp(dut, conn, SIGMA_ERROR, msg);
2260 return -3;
2261 }
2262#endif /* __linux__ */
2263#ifdef ANDROID
2264ca_cert_selected:
2265#endif /* ANDROID */
2266 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2267 return -2;
2268 }
2269
Jouni Malinen53264f62019-05-03 13:04:40 +03002270 val = get_param(cmd, "ServerCert");
2271 if (val) {
2272 FILE *f;
2273 char *result = NULL, *pos;
2274
2275 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2276 val);
2277 f = fopen(buf, "r");
2278 if (f) {
2279 result = fgets(buf, sizeof(buf), f);
2280 fclose(f);
2281 }
2282 if (!result) {
2283 snprintf(buf2, sizeof(buf2),
2284 "ErrorCode,ServerCert hash could not be read from %s",
2285 buf);
2286 send_resp(dut, conn, SIGMA_ERROR, buf2);
2287 return STATUS_SENT_ERROR;
2288 }
2289 pos = strchr(buf, '\n');
2290 if (pos)
2291 *pos = '\0';
2292 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2293 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2294 return ERROR_SEND_STATUS;
2295 }
2296
Jouni Malinen96f84b02019-05-03 12:32:56 +03002297 val = get_param(cmd, "Domain");
2298 if (val && set_network_quoted(ifname, id, "domain_match", val) < 0)
2299 return ERROR_SEND_STATUS;
2300
2301 val = get_param(cmd, "DomainSuffix");
2302 if (val &&
2303 set_network_quoted(ifname, id, "domain_suffix_match", val) < 0)
2304 return ERROR_SEND_STATUS;
2305
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302306 if (username_identity) {
2307 val = get_param(cmd, "username");
2308 if (val) {
2309 if (set_network_quoted(ifname, id, "identity", val) < 0)
2310 return -2;
2311 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002312
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302313 val = get_param(cmd, "password");
2314 if (val) {
2315 if (set_network_quoted(ifname, id, "password", val) < 0)
2316 return -2;
2317 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002318 }
2319
Jouni Malinen8179fee2019-03-28 03:19:47 +02002320 if (dut->akm_values &
2321 ((1 << AKM_FILS_SHA256) |
2322 (1 << AKM_FILS_SHA384) |
2323 (1 << AKM_FT_FILS_SHA256) |
2324 (1 << AKM_FT_FILS_SHA384)))
2325 erp = 1;
2326 if (erp && set_network(ifname, id, "erp", "1") < 0)
2327 return ERROR_SEND_STATUS;
2328
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002329 return id;
2330}
2331
2332
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002333static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2334{
2335 const char *val;
2336
2337 if (!cipher)
2338 return 0;
2339
2340 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2341 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2342 else if (strcasecmp(cipher,
2343 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2344 val = "ECDHE-RSA-AES256-GCM-SHA384";
2345 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2346 val = "DHE-RSA-AES256-GCM-SHA384";
2347 else if (strcasecmp(cipher,
2348 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2349 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2350 else
2351 return -1;
2352
2353 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2354 set_network_quoted(ifname, id, "phase1", "");
2355
2356 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2357}
2358
2359
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002360static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
2361 struct sigma_cmd *cmd)
2362{
2363 const char *intf = get_param(cmd, "Interface");
2364 const char *ifname, *val;
2365 int id;
2366 char buf[200];
2367#ifdef ANDROID
2368 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2369 int length;
2370 int jb_or_newer = 0;
2371 char prop[PROPERTY_VALUE_MAX];
2372#endif /* ANDROID */
2373
2374 if (intf == NULL)
2375 return -1;
2376
2377 if (strcmp(intf, get_main_ifname()) == 0)
2378 ifname = get_station_ifname();
2379 else
2380 ifname = intf;
2381
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302382 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002383 if (id < 0)
2384 return id;
2385
2386 if (set_network(ifname, id, "eap", "TLS") < 0)
2387 return -2;
2388
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302389 if (!get_param(cmd, "username") &&
2390 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002391 "wifi-user@wifilabs.local") < 0)
2392 return -2;
2393
2394 val = get_param(cmd, "clientCertificate");
2395 if (val == NULL)
2396 return -1;
2397#ifdef ANDROID
2398 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2399 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2400 if (length < 0) {
2401 /*
2402 * JB started reporting keystore type mismatches, so retry with
2403 * the GET_PUBKEY command if the generic GET fails.
2404 */
2405 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2406 buf, kvalue);
2407 }
2408
2409 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2410 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2411 if (strncmp(prop, "4.0", 3) != 0)
2412 jb_or_newer = 1;
2413 } else
2414 jb_or_newer = 1; /* assume newer */
2415
2416 if (jb_or_newer && length > 0) {
2417 sigma_dut_print(dut, DUT_MSG_INFO,
2418 "Use Android keystore [%s]", buf);
2419 if (set_network(ifname, id, "engine", "1") < 0)
2420 return -2;
2421 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2422 return -2;
2423 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2424 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2425 return -2;
2426 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2427 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2428 return -2;
2429 return 1;
2430 } else if (length > 0) {
2431 sigma_dut_print(dut, DUT_MSG_INFO,
2432 "Use Android keystore [%s]", buf);
2433 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2434 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2435 return -2;
2436 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2437 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2438 return -2;
2439 return 1;
2440 }
2441#endif /* ANDROID */
2442
2443 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2444#ifdef __linux__
2445 if (!file_exists(buf)) {
2446 char msg[300];
2447 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2448 "(%s) not found", buf);
2449 send_resp(dut, conn, SIGMA_ERROR, msg);
2450 return -3;
2451 }
2452#endif /* __linux__ */
2453 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2454 return -2;
2455 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2456 return -2;
2457
2458 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2459 return -2;
2460
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002461 val = get_param(cmd, "keyMgmtType");
2462 if (val && strcasecmp(val, "SuiteB") == 0) {
2463 val = get_param(cmd, "CertType");
2464 if (val && strcasecmp(val, "RSA") == 0) {
2465 if (set_network_quoted(ifname, id, "phase1",
2466 "tls_suiteb=1") < 0)
2467 return -2;
2468 } else {
2469 if (set_network_quoted(ifname, id, "openssl_ciphers",
2470 "SUITEB192") < 0)
2471 return -2;
2472 }
2473
2474 val = get_param(cmd, "TLSCipher");
2475 if (set_tls_cipher(ifname, id, val) < 0) {
2476 send_resp(dut, conn, SIGMA_ERROR,
2477 "ErrorCode,Unsupported TLSCipher value");
2478 return -3;
2479 }
2480 }
2481
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002482 return 1;
2483}
2484
2485
2486static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
2487 struct sigma_cmd *cmd)
2488{
2489 const char *intf = get_param(cmd, "Interface");
2490 const char *ifname;
2491 int id;
2492
2493 if (intf == NULL)
2494 return -1;
2495
2496 if (strcmp(intf, get_main_ifname()) == 0)
2497 ifname = get_station_ifname();
2498 else
2499 ifname = intf;
2500
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302501 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002502 if (id < 0)
2503 return id;
2504
2505 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2506 send_resp(dut, conn, SIGMA_ERROR,
2507 "errorCode,Failed to set TTLS method");
2508 return 0;
2509 }
2510
2511 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2512 send_resp(dut, conn, SIGMA_ERROR,
2513 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2514 return 0;
2515 }
2516
2517 return 1;
2518}
2519
2520
2521static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
2522 struct sigma_cmd *cmd)
2523{
2524 const char *intf = get_param(cmd, "Interface");
2525 const char *ifname;
2526 int id;
2527
2528 if (intf == NULL)
2529 return -1;
2530
2531 if (strcmp(intf, get_main_ifname()) == 0)
2532 ifname = get_station_ifname();
2533 else
2534 ifname = intf;
2535
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302536 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002537 if (id < 0)
2538 return id;
2539
2540 if (set_network(ifname, id, "eap", "SIM") < 0)
2541 return -2;
2542
2543 return 1;
2544}
2545
2546
2547static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
2548 struct sigma_cmd *cmd)
2549{
2550 const char *intf = get_param(cmd, "Interface");
2551 const char *ifname, *val;
2552 int id;
2553 char buf[100];
2554
2555 if (intf == NULL)
2556 return -1;
2557
2558 if (strcmp(intf, get_main_ifname()) == 0)
2559 ifname = get_station_ifname();
2560 else
2561 ifname = intf;
2562
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302563 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002564 if (id < 0)
2565 return id;
2566
2567 if (set_network(ifname, id, "eap", "PEAP") < 0)
2568 return -2;
2569
2570 val = get_param(cmd, "innerEAP");
2571 if (val) {
2572 if (strcasecmp(val, "MSCHAPv2") == 0) {
2573 if (set_network_quoted(ifname, id, "phase2",
2574 "auth=MSCHAPV2") < 0)
2575 return -2;
2576 } else if (strcasecmp(val, "GTC") == 0) {
2577 if (set_network_quoted(ifname, id, "phase2",
2578 "auth=GTC") < 0)
2579 return -2;
2580 } else
2581 return -1;
2582 }
2583
2584 val = get_param(cmd, "peapVersion");
2585 if (val) {
2586 int ver = atoi(val);
2587 if (ver < 0 || ver > 1)
2588 return -1;
2589 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2590 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2591 return -2;
2592 }
2593
2594 return 1;
2595}
2596
2597
2598static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2599 struct sigma_cmd *cmd)
2600{
2601 const char *intf = get_param(cmd, "Interface");
2602 const char *ifname, *val;
2603 int id;
2604 char buf[100];
2605
2606 if (intf == NULL)
2607 return -1;
2608
2609 if (strcmp(intf, get_main_ifname()) == 0)
2610 ifname = get_station_ifname();
2611 else
2612 ifname = intf;
2613
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302614 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002615 if (id < 0)
2616 return id;
2617
2618 if (set_network(ifname, id, "eap", "FAST") < 0)
2619 return -2;
2620
2621 val = get_param(cmd, "innerEAP");
2622 if (val) {
2623 if (strcasecmp(val, "MSCHAPV2") == 0) {
2624 if (set_network_quoted(ifname, id, "phase2",
2625 "auth=MSCHAPV2") < 0)
2626 return -2;
2627 } else if (strcasecmp(val, "GTC") == 0) {
2628 if (set_network_quoted(ifname, id, "phase2",
2629 "auth=GTC") < 0)
2630 return -2;
2631 } else
2632 return -1;
2633 }
2634
2635 val = get_param(cmd, "validateServer");
2636 if (val) {
2637 /* TODO */
2638 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2639 "validateServer=%s", val);
2640 }
2641
2642 val = get_param(cmd, "pacFile");
2643 if (val) {
2644 snprintf(buf, sizeof(buf), "blob://%s", val);
2645 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2646 return -2;
2647 }
2648
2649 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2650 0)
2651 return -2;
2652
2653 return 1;
2654}
2655
2656
2657static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2658 struct sigma_cmd *cmd)
2659{
2660 const char *intf = get_param(cmd, "Interface");
2661 const char *ifname;
2662 int id;
2663
2664 if (intf == NULL)
2665 return -1;
2666
2667 if (strcmp(intf, get_main_ifname()) == 0)
2668 ifname = get_station_ifname();
2669 else
2670 ifname = intf;
2671
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302672 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002673 if (id < 0)
2674 return id;
2675
2676 if (set_network(ifname, id, "eap", "AKA") < 0)
2677 return -2;
2678
2679 return 1;
2680}
2681
2682
2683static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2684 struct sigma_conn *conn,
2685 struct sigma_cmd *cmd)
2686{
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
2710static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2711 struct sigma_cmd *cmd)
2712{
2713 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002714 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002715 const char *ifname;
2716 int id;
2717
2718 if (strcmp(intf, get_main_ifname()) == 0)
2719 ifname = get_station_ifname();
2720 else
2721 ifname = intf;
2722
2723 id = add_network_common(dut, conn, ifname, cmd);
2724 if (id < 0)
2725 return id;
2726
2727 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2728 return -2;
2729
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002730 if (dut->program == PROGRAM_60GHZ && network_mode &&
2731 strcasecmp(network_mode, "PBSS") == 0 &&
2732 set_network(ifname, id, "pbss", "1") < 0)
2733 return -2;
2734
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002735 return 1;
2736}
2737
2738
Jouni Malinen47dcc952017-10-09 16:43:24 +03002739static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2740 struct sigma_cmd *cmd)
2741{
2742 const char *intf = get_param(cmd, "Interface");
2743 const char *ifname, *val;
2744 int id;
2745
2746 if (intf == NULL)
2747 return -1;
2748
2749 if (strcmp(intf, get_main_ifname()) == 0)
2750 ifname = get_station_ifname();
2751 else
2752 ifname = intf;
2753
2754 id = set_wpa_common(dut, conn, ifname, cmd);
2755 if (id < 0)
2756 return id;
2757
2758 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2759 return -2;
2760
2761 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002762 if (val && strcmp(val, "0") == 0) {
2763 if (wpa_command(ifname,
2764 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2765 sigma_dut_print(dut, DUT_MSG_ERROR,
2766 "Failed to set OWE DH Param element override");
2767 return -2;
2768 }
2769 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002770 sigma_dut_print(dut, DUT_MSG_ERROR,
2771 "Failed to clear owe_group");
2772 return -2;
2773 }
2774
2775 return 1;
2776}
2777
2778
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002779static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2780 struct sigma_cmd *cmd)
2781{
2782 const char *type = get_param(cmd, "Type");
2783
2784 if (type == NULL) {
2785 send_resp(dut, conn, SIGMA_ERROR,
2786 "ErrorCode,Missing Type argument");
2787 return 0;
2788 }
2789
2790 if (strcasecmp(type, "OPEN") == 0)
2791 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002792 if (strcasecmp(type, "OWE") == 0)
2793 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002794 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002795 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002796 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002797 return cmd_sta_set_psk(dut, conn, cmd);
2798 if (strcasecmp(type, "EAPTLS") == 0)
2799 return cmd_sta_set_eaptls(dut, conn, cmd);
2800 if (strcasecmp(type, "EAPTTLS") == 0)
2801 return cmd_sta_set_eapttls(dut, conn, cmd);
2802 if (strcasecmp(type, "EAPPEAP") == 0)
2803 return cmd_sta_set_peap(dut, conn, cmd);
2804 if (strcasecmp(type, "EAPSIM") == 0)
2805 return cmd_sta_set_eapsim(dut, conn, cmd);
2806 if (strcasecmp(type, "EAPFAST") == 0)
2807 return cmd_sta_set_eapfast(dut, conn, cmd);
2808 if (strcasecmp(type, "EAPAKA") == 0)
2809 return cmd_sta_set_eapaka(dut, conn, cmd);
2810 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2811 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002812 if (strcasecmp(type, "wep") == 0)
2813 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002814
2815 send_resp(dut, conn, SIGMA_ERROR,
2816 "ErrorCode,Unsupported Type value");
2817 return 0;
2818}
2819
2820
2821int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2822{
2823#ifdef __linux__
2824 /* special handling for ath6kl */
2825 char path[128], fname[128], *pos;
2826 ssize_t res;
2827 FILE *f;
2828
2829 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
2830 res = readlink(path, path, sizeof(path));
2831 if (res < 0)
2832 return 0; /* not ath6kl */
2833
2834 if (res >= (int) sizeof(path))
2835 res = sizeof(path) - 1;
2836 path[res] = '\0';
2837 pos = strrchr(path, '/');
2838 if (pos == NULL)
2839 pos = path;
2840 else
2841 pos++;
2842 snprintf(fname, sizeof(fname),
2843 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2844 "create_qos", pos);
2845 if (!file_exists(fname))
2846 return 0; /* not ath6kl */
2847
2848 if (uapsd) {
2849 f = fopen(fname, "w");
2850 if (f == NULL)
2851 return -1;
2852
2853 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2854 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2855 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2856 "20000 0\n");
2857 fclose(f);
2858 } else {
2859 snprintf(fname, sizeof(fname),
2860 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2861 "delete_qos", pos);
2862
2863 f = fopen(fname, "w");
2864 if (f == NULL)
2865 return -1;
2866
2867 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2868 fprintf(f, "2 4\n");
2869 fclose(f);
2870 }
2871#endif /* __linux__ */
2872
2873 return 0;
2874}
2875
2876
2877static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2878 struct sigma_cmd *cmd)
2879{
2880 const char *intf = get_param(cmd, "Interface");
2881 /* const char *ssid = get_param(cmd, "ssid"); */
2882 const char *val;
2883 int max_sp_len = 4;
2884 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2885 char buf[100];
2886 int ret1, ret2;
2887
2888 val = get_param(cmd, "maxSPLength");
2889 if (val) {
2890 max_sp_len = atoi(val);
2891 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2892 max_sp_len != 4)
2893 return -1;
2894 }
2895
2896 val = get_param(cmd, "acBE");
2897 if (val)
2898 ac_be = atoi(val);
2899
2900 val = get_param(cmd, "acBK");
2901 if (val)
2902 ac_bk = atoi(val);
2903
2904 val = get_param(cmd, "acVI");
2905 if (val)
2906 ac_vi = atoi(val);
2907
2908 val = get_param(cmd, "acVO");
2909 if (val)
2910 ac_vo = atoi(val);
2911
2912 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2913
2914 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2915 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2916 ret1 = wpa_command(intf, buf);
2917
2918 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2919 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2920 ret2 = wpa_command(intf, buf);
2921
2922 if (ret1 && ret2) {
2923 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2924 "UAPSD parameters.");
2925 return -2;
2926 }
2927
2928 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2929 send_resp(dut, conn, SIGMA_ERROR,
2930 "ErrorCode,Failed to set ath6kl QoS parameters");
2931 return 0;
2932 }
2933
2934 return 1;
2935}
2936
2937
2938static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2939 struct sigma_cmd *cmd)
2940{
2941 char buf[1000];
2942 const char *intf = get_param(cmd, "Interface");
2943 const char *grp = get_param(cmd, "Group");
2944 const char *act = get_param(cmd, "Action");
2945 const char *tid = get_param(cmd, "Tid");
2946 const char *dir = get_param(cmd, "Direction");
2947 const char *psb = get_param(cmd, "Psb");
2948 const char *up = get_param(cmd, "Up");
2949 const char *fixed = get_param(cmd, "Fixed");
2950 const char *size = get_param(cmd, "Size");
2951 const char *msize = get_param(cmd, "Maxsize");
2952 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2953 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2954 const char *inact = get_param(cmd, "Inactivity");
2955 const char *sus = get_param(cmd, "Suspension");
2956 const char *mindr = get_param(cmd, "Mindatarate");
2957 const char *meandr = get_param(cmd, "Meandatarate");
2958 const char *peakdr = get_param(cmd, "Peakdatarate");
2959 const char *phyrate = get_param(cmd, "Phyrate");
2960 const char *burstsize = get_param(cmd, "Burstsize");
2961 const char *sba = get_param(cmd, "Sba");
2962 int direction;
2963 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002964 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002965 int fixed_int;
2966 int psb_ts;
2967
2968 if (intf == NULL || grp == NULL || act == NULL )
2969 return -1;
2970
2971 if (strcasecmp(act, "addts") == 0) {
2972 if (tid == NULL || dir == NULL || psb == NULL ||
2973 up == NULL || fixed == NULL || size == NULL)
2974 return -1;
2975
2976 /*
2977 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2978 * possible values, but WMM-AC and V-E test scripts use "UP,
2979 * "DOWN", and "BIDI".
2980 */
2981 if (strcasecmp(dir, "uplink") == 0 ||
2982 strcasecmp(dir, "up") == 0) {
2983 direction = 0;
2984 } else if (strcasecmp(dir, "downlink") == 0 ||
2985 strcasecmp(dir, "down") == 0) {
2986 direction = 1;
2987 } else if (strcasecmp(dir, "bidi") == 0) {
2988 direction = 2;
2989 } else {
2990 sigma_dut_print(dut, DUT_MSG_ERROR,
2991 "Direction %s not supported", dir);
2992 return -1;
2993 }
2994
2995 if (strcasecmp(psb, "legacy") == 0) {
2996 psb_ts = 0;
2997 } else if (strcasecmp(psb, "uapsd") == 0) {
2998 psb_ts = 1;
2999 } else {
3000 sigma_dut_print(dut, DUT_MSG_ERROR,
3001 "PSB %s not supported", psb);
3002 return -1;
3003 }
3004
3005 if (atoi(tid) < 0 || atoi(tid) > 7) {
3006 sigma_dut_print(dut, DUT_MSG_ERROR,
3007 "TID %s not supported", tid);
3008 return -1;
3009 }
3010
3011 if (strcasecmp(fixed, "true") == 0) {
3012 fixed_int = 1;
3013 } else {
3014 fixed_int = 0;
3015 }
3016
Peng Xu93319622017-10-04 17:58:16 -07003017 if (sba)
3018 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003019
3020 dut->dialog_token++;
3021 handle = 7000 + dut->dialog_token;
3022
3023 /*
3024 * size: convert to hex
3025 * maxsi: convert to hex
3026 * mindr: convert to hex
3027 * meandr: convert to hex
3028 * peakdr: convert to hex
3029 * burstsize: convert to hex
3030 * phyrate: convert to hex
3031 * sba: convert to hex with modification
3032 * minsi: convert to integer
3033 * sus: convert to integer
3034 * inact: convert to integer
3035 * maxsi: convert to integer
3036 */
3037
3038 /*
3039 * The Nominal MSDU Size field is 2 octets long and contains an
3040 * unsigned integer that specifies the nominal size, in octets,
3041 * of MSDUs belonging to the traffic under this traffic
3042 * specification and is defined in Figure 16. If the Fixed
3043 * subfield is set to 1, then the size of the MSDU is fixed and
3044 * is indicated by the Size Subfield. If the Fixed subfield is
3045 * set to 0, then the size of the MSDU might not be fixed and
3046 * the Size indicates the nominal MSDU size.
3047 *
3048 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3049 * and specifies the excess allocation of time (and bandwidth)
3050 * over and above the stated rates required to transport an MSDU
3051 * belonging to the traffic in this TSPEC. This field is
3052 * represented as an unsigned binary number with an implicit
3053 * binary point after the leftmost 3 bits. For example, an SBA
3054 * of 1.75 is represented as 0x3800. This field is included to
3055 * account for retransmissions. As such, the value of this field
3056 * must be greater than unity.
3057 */
3058
3059 snprintf(buf, sizeof(buf),
3060 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3061 " 0x%X 0x%X 0x%X"
3062 " 0x%X 0x%X 0x%X"
3063 " 0x%X %d %d %d %d"
3064 " %d %d",
3065 intf, handle, tid, direction, psb_ts, up,
3066 (unsigned int) ((fixed_int << 15) | atoi(size)),
3067 msize ? atoi(msize) : 0,
3068 mindr ? atoi(mindr) : 0,
3069 meandr ? atoi(meandr) : 0,
3070 peakdr ? atoi(peakdr) : 0,
3071 burstsize ? atoi(burstsize) : 0,
3072 phyrate ? atoi(phyrate) : 0,
3073 sba ? ((unsigned int) (((int) sba_fv << 13) |
3074 (int)((sba_fv - (int) sba_fv) *
3075 8192))) : 0,
3076 minsi ? atoi(minsi) : 0,
3077 sus ? atoi(sus) : 0,
3078 0, 0,
3079 inact ? atoi(inact) : 0,
3080 maxsi ? atoi(maxsi) : 0);
3081
3082 if (system(buf) != 0) {
3083 sigma_dut_print(dut, DUT_MSG_ERROR,
3084 "iwpriv addtspec request failed");
3085 send_resp(dut, conn, SIGMA_ERROR,
3086 "errorCode,Failed to execute addTspec command");
3087 return 0;
3088 }
3089
3090 sigma_dut_print(dut, DUT_MSG_INFO,
3091 "iwpriv addtspec request send");
3092
3093 /* Mapping handle to a TID */
3094 dut->tid_to_handle[atoi(tid)] = handle;
3095 } else if (strcasecmp(act, "delts") == 0) {
3096 if (tid == NULL)
3097 return -1;
3098
3099 if (atoi(tid) < 0 || atoi(tid) > 7) {
3100 sigma_dut_print(dut, DUT_MSG_ERROR,
3101 "TID %s not supported", tid);
3102 send_resp(dut, conn, SIGMA_ERROR,
3103 "errorCode,Unsupported TID");
3104 return 0;
3105 }
3106
3107 handle = dut->tid_to_handle[atoi(tid)];
3108
3109 if (handle < 7000 || handle > 7255) {
3110 /* Invalid handle ie no mapping for that TID */
3111 sigma_dut_print(dut, DUT_MSG_ERROR,
3112 "handle-> %d not found", handle);
3113 }
3114
3115 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3116 intf, handle);
3117
3118 if (system(buf) != 0) {
3119 sigma_dut_print(dut, DUT_MSG_ERROR,
3120 "iwpriv deltspec request failed");
3121 send_resp(dut, conn, SIGMA_ERROR,
3122 "errorCode,Failed to execute delTspec command");
3123 return 0;
3124 }
3125
3126 sigma_dut_print(dut, DUT_MSG_INFO,
3127 "iwpriv deltspec request send");
3128
3129 dut->tid_to_handle[atoi(tid)] = 0;
3130 } else {
3131 sigma_dut_print(dut, DUT_MSG_ERROR,
3132 "Action type %s not supported", act);
3133 send_resp(dut, conn, SIGMA_ERROR,
3134 "errorCode,Unsupported Action");
3135 return 0;
3136 }
3137
3138 return 1;
3139}
3140
3141
vamsi krishna52e16f92017-08-29 12:37:34 +05303142static int find_network(struct sigma_dut *dut, const char *ssid)
3143{
3144 char list[4096];
3145 char *pos;
3146
3147 sigma_dut_print(dut, DUT_MSG_DEBUG,
3148 "Search for profile based on SSID: '%s'", ssid);
3149 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
3150 list, sizeof(list)) < 0)
3151 return -1;
3152 pos = strstr(list, ssid);
3153 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3154 return -1;
3155
3156 while (pos > list && pos[-1] != '\n')
3157 pos--;
3158 dut->infra_network_id = atoi(pos);
3159 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3160 return 0;
3161}
3162
3163
Sunil Dutt44595082018-02-12 19:41:45 +05303164#ifdef NL80211_SUPPORT
3165static int sta_config_rsnie(struct sigma_dut *dut, int val)
3166{
3167 struct nl_msg *msg;
3168 int ret;
3169 struct nlattr *params;
3170 int ifindex;
3171
3172 ifindex = if_nametoindex("wlan0");
3173 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3174 NL80211_CMD_VENDOR)) ||
3175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3176 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3177 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3178 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3179 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3180 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3181 sigma_dut_print(dut, DUT_MSG_ERROR,
3182 "%s: err in adding vendor_cmd and vendor_data",
3183 __func__);
3184 nlmsg_free(msg);
3185 return -1;
3186 }
3187 nla_nest_end(msg, params);
3188
3189 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3190 if (ret) {
3191 sigma_dut_print(dut, DUT_MSG_ERROR,
3192 "%s: err in send_and_recv_msgs, ret=%d",
3193 __func__, ret);
3194 return ret;
3195 }
3196
3197 return 0;
3198}
3199#endif /* NL80211_SUPPORT */
3200
3201
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003202static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
3203 struct sigma_cmd *cmd)
3204{
3205 /* const char *intf = get_param(cmd, "Interface"); */
3206 const char *ssid = get_param(cmd, "ssid");
3207 const char *wps_param = get_param(cmd, "WPS");
3208 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003209 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003210 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003211 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003212 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003213
3214 if (ssid == NULL)
3215 return -1;
3216
Jouni Malinen3c367e82017-06-23 17:01:47 +03003217 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303218#ifdef NL80211_SUPPORT
3219 if (get_driver_type() == DRIVER_WCN) {
3220 sta_config_rsnie(dut, 1);
3221 dut->config_rsnie = 1;
3222 }
3223#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003224 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3225 dut->rsne_override);
3226 if (wpa_command(get_station_ifname(), buf) < 0) {
3227 send_resp(dut, conn, SIGMA_ERROR,
3228 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3229 return 0;
3230 }
3231 }
3232
Jouni Malinen68143132017-09-02 02:34:08 +03003233 if (dut->sae_commit_override) {
3234 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3235 dut->sae_commit_override);
3236 if (wpa_command(get_station_ifname(), buf) < 0) {
3237 send_resp(dut, conn, SIGMA_ERROR,
3238 "ErrorCode,Failed to set SAE commit override");
3239 return 0;
3240 }
3241 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303242#ifdef ANDROID
3243 if (dut->fils_hlp)
3244 process_fils_hlp(dut);
3245#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003246
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003247 if (wps_param &&
3248 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3249 wps = 1;
3250
3251 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003252 if (dut->program == PROGRAM_60GHZ && network_mode &&
3253 strcasecmp(network_mode, "PBSS") == 0 &&
3254 set_network(get_station_ifname(), dut->infra_network_id,
3255 "pbss", "1") < 0)
3256 return -2;
3257
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003258 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3259 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3260 "parameters not yet set");
3261 return 0;
3262 }
3263 if (dut->wps_method == WFA_CS_WPS_PBC) {
3264 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
3265 return -2;
3266 } else {
3267 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3268 dut->wps_pin);
3269 if (wpa_command(get_station_ifname(), buf) < 0)
3270 return -2;
3271 }
3272 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303273 if (strcmp(ssid, dut->infra_ssid) == 0) {
3274 sigma_dut_print(dut, DUT_MSG_DEBUG,
3275 "sta_associate for the most recently added network");
3276 } else if (find_network(dut, ssid) < 0) {
3277 sigma_dut_print(dut, DUT_MSG_DEBUG,
3278 "sta_associate for a previously stored network profile");
3279 send_resp(dut, conn, SIGMA_ERROR,
3280 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003281 return 0;
3282 }
3283
3284 if (bssid &&
3285 set_network(get_station_ifname(), dut->infra_network_id,
3286 "bssid", bssid) < 0) {
3287 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3288 "Invalid bssid argument");
3289 return 0;
3290 }
3291
Jouni Malinen46a19b62017-06-23 14:31:27 +03003292 extra[0] = '\0';
3293 if (chan)
3294 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003295 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003296 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3297 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003298 if (wpa_command(get_station_ifname(), buf) < 0) {
3299 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3300 "network id %d on %s",
3301 dut->infra_network_id,
3302 get_station_ifname());
3303 return -2;
3304 }
3305 }
3306
3307 return 1;
3308}
3309
3310
3311static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3312{
3313 char buf[500], cmd[200];
3314 int res;
3315
3316 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3317 * default path */
3318 res = snprintf(cmd, sizeof(cmd),
3319 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3320 file_exists("./hs20-osu-client") ?
3321 "./hs20-osu-client" : "hs20-osu-client",
3322 sigma_wpas_ctrl,
3323 dut->summary_log ? "-s " : "",
3324 dut->summary_log ? dut->summary_log : "");
3325 if (res < 0 || res >= (int) sizeof(cmd))
3326 return -1;
3327
3328 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3329 if (res < 0 || res >= (int) sizeof(buf))
3330 return -1;
3331 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3332
3333 if (system(buf) != 0) {
3334 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3335 return -1;
3336 }
3337 sigma_dut_print(dut, DUT_MSG_DEBUG,
3338 "Completed hs20-osu-client operation");
3339
3340 return 0;
3341}
3342
3343
3344static int download_ppsmo(struct sigma_dut *dut,
3345 struct sigma_conn *conn,
3346 const char *intf,
3347 struct sigma_cmd *cmd)
3348{
3349 const char *name, *path, *val;
3350 char url[500], buf[600], fbuf[100];
3351 char *fqdn = NULL;
3352
3353 name = get_param(cmd, "FileName");
3354 path = get_param(cmd, "FilePath");
3355 if (name == NULL || path == NULL)
3356 return -1;
3357
3358 if (strcasecmp(path, "VendorSpecific") == 0) {
3359 snprintf(url, sizeof(url), "PPS/%s", name);
3360 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3361 "from the device (%s)", url);
3362 if (!file_exists(url)) {
3363 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3364 "PPS MO file does not exist");
3365 return 0;
3366 }
3367 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3368 if (system(buf) != 0) {
3369 send_resp(dut, conn, SIGMA_ERROR,
3370 "errorCode,Failed to copy PPS MO");
3371 return 0;
3372 }
3373 } else if (strncasecmp(path, "http:", 5) != 0 &&
3374 strncasecmp(path, "https:", 6) != 0) {
3375 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3376 "Unsupported FilePath value");
3377 return 0;
3378 } else {
3379 snprintf(url, sizeof(url), "%s/%s", path, name);
3380 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3381 url);
3382 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3383 remove("pps-tnds.xml");
3384 if (system(buf) != 0) {
3385 send_resp(dut, conn, SIGMA_ERROR,
3386 "errorCode,Failed to download PPS MO");
3387 return 0;
3388 }
3389 }
3390
3391 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3392 send_resp(dut, conn, SIGMA_ERROR,
3393 "errorCode,Failed to parse downloaded PPSMO");
3394 return 0;
3395 }
3396 unlink("pps-tnds.xml");
3397
3398 val = get_param(cmd, "managementTreeURI");
3399 if (val) {
3400 const char *pos, *end;
3401 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3402 val);
3403 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3404 send_resp(dut, conn, SIGMA_ERROR,
3405 "errorCode,Invalid managementTreeURI prefix");
3406 return 0;
3407 }
3408 pos = val + 8;
3409 end = strchr(pos, '/');
3410 if (end == NULL ||
3411 strcmp(end, "/PerProviderSubscription") != 0) {
3412 send_resp(dut, conn, SIGMA_ERROR,
3413 "errorCode,Invalid managementTreeURI postfix");
3414 return 0;
3415 }
3416 if (end - pos >= (int) sizeof(fbuf)) {
3417 send_resp(dut, conn, SIGMA_ERROR,
3418 "errorCode,Too long FQDN in managementTreeURI");
3419 return 0;
3420 }
3421 memcpy(fbuf, pos, end - pos);
3422 fbuf[end - pos] = '\0';
3423 fqdn = fbuf;
3424 sigma_dut_print(dut, DUT_MSG_INFO,
3425 "FQDN from managementTreeURI: %s", fqdn);
3426 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3427 FILE *f = fopen("pps-fqdn", "r");
3428 if (f) {
3429 if (fgets(fbuf, sizeof(fbuf), f)) {
3430 fbuf[sizeof(fbuf) - 1] = '\0';
3431 fqdn = fbuf;
3432 sigma_dut_print(dut, DUT_MSG_DEBUG,
3433 "Use FQDN %s", fqdn);
3434 }
3435 fclose(f);
3436 }
3437 }
3438
3439 if (fqdn == NULL) {
3440 send_resp(dut, conn, SIGMA_ERROR,
3441 "errorCode,No FQDN specified");
3442 return 0;
3443 }
3444
3445 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3446 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3447 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3448
3449 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3450 if (rename("pps.xml", buf) < 0) {
3451 send_resp(dut, conn, SIGMA_ERROR,
3452 "errorCode,Could not move PPS MO");
3453 return 0;
3454 }
3455
3456 if (strcasecmp(path, "VendorSpecific") == 0) {
3457 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3458 fqdn);
3459 if (system(buf)) {
3460 send_resp(dut, conn, SIGMA_ERROR,
3461 "errorCode,Failed to copy OSU CA cert");
3462 return 0;
3463 }
3464
3465 snprintf(buf, sizeof(buf),
3466 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3467 fqdn);
3468 if (system(buf)) {
3469 send_resp(dut, conn, SIGMA_ERROR,
3470 "errorCode,Failed to copy AAA CA cert");
3471 return 0;
3472 }
3473 } else {
3474 snprintf(buf, sizeof(buf),
3475 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3476 fqdn, fqdn);
3477 if (run_hs20_osu(dut, buf) < 0) {
3478 send_resp(dut, conn, SIGMA_ERROR,
3479 "errorCode,Failed to download OSU CA cert");
3480 return 0;
3481 }
3482
3483 snprintf(buf, sizeof(buf),
3484 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3485 fqdn, fqdn);
3486 if (run_hs20_osu(dut, buf) < 0) {
3487 sigma_dut_print(dut, DUT_MSG_INFO,
3488 "Failed to download AAA CA cert");
3489 }
3490 }
3491
3492 if (file_exists("next-client-cert.pem")) {
3493 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3494 if (rename("next-client-cert.pem", buf) < 0) {
3495 send_resp(dut, conn, SIGMA_ERROR,
3496 "errorCode,Could not move client certificate");
3497 return 0;
3498 }
3499 }
3500
3501 if (file_exists("next-client-key.pem")) {
3502 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3503 if (rename("next-client-key.pem", buf) < 0) {
3504 send_resp(dut, conn, SIGMA_ERROR,
3505 "errorCode,Could not move client key");
3506 return 0;
3507 }
3508 }
3509
3510 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3511 if (run_hs20_osu(dut, buf) < 0) {
3512 send_resp(dut, conn, SIGMA_ERROR,
3513 "errorCode,Failed to configure credential from "
3514 "PPSMO");
3515 return 0;
3516 }
3517
3518 return 1;
3519}
3520
3521
3522static int download_cert(struct sigma_dut *dut,
3523 struct sigma_conn *conn,
3524 const char *intf,
3525 struct sigma_cmd *cmd)
3526{
3527 const char *name, *path;
3528 char url[500], buf[600];
3529
3530 name = get_param(cmd, "FileName");
3531 path = get_param(cmd, "FilePath");
3532 if (name == NULL || path == NULL)
3533 return -1;
3534
3535 if (strcasecmp(path, "VendorSpecific") == 0) {
3536 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3537 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3538 "certificate from the device (%s)", url);
3539 if (!file_exists(url)) {
3540 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3541 "certificate file does not exist");
3542 return 0;
3543 }
3544 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3545 if (system(buf) != 0) {
3546 send_resp(dut, conn, SIGMA_ERROR,
3547 "errorCode,Failed to copy client "
3548 "certificate");
3549 return 0;
3550 }
3551
3552 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3553 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3554 "private key from the device (%s)", url);
3555 if (!file_exists(url)) {
3556 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3557 "private key file does not exist");
3558 return 0;
3559 }
3560 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3561 if (system(buf) != 0) {
3562 send_resp(dut, conn, SIGMA_ERROR,
3563 "errorCode,Failed to copy client key");
3564 return 0;
3565 }
3566 } else if (strncasecmp(path, "http:", 5) != 0 &&
3567 strncasecmp(path, "https:", 6) != 0) {
3568 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3569 "Unsupported FilePath value");
3570 return 0;
3571 } else {
3572 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3573 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3574 "certificate/key from %s", url);
3575 snprintf(buf, sizeof(buf),
3576 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3577 if (system(buf) != 0) {
3578 send_resp(dut, conn, SIGMA_ERROR,
3579 "errorCode,Failed to download client "
3580 "certificate");
3581 return 0;
3582 }
3583
3584 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3585 {
3586 send_resp(dut, conn, SIGMA_ERROR,
3587 "errorCode,Failed to copy client key");
3588 return 0;
3589 }
3590 }
3591
3592 return 1;
3593}
3594
3595
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003596static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3597 struct sigma_conn *conn,
3598 struct sigma_cmd *cmd)
3599{
3600 const char *val;
3601 const char *intf = get_param(cmd, "interface");
3602
3603 if (!intf)
3604 return -1;
3605
3606 val = get_param(cmd, "WscIEFragment");
3607 if (val && strcasecmp(val, "enable") == 0) {
3608 sigma_dut_print(dut, DUT_MSG_DEBUG,
3609 "Enable WSC IE fragmentation");
3610
3611 dut->wsc_fragment = 1;
3612 /* set long attributes to force fragmentation */
3613 if (wpa_command(intf, "SET device_name "
3614 WPS_LONG_DEVICE_NAME) < 0)
3615 return -2;
3616 if (wpa_command(intf, "SET manufacturer "
3617 WPS_LONG_MANUFACTURER) < 0)
3618 return -2;
3619 if (wpa_command(intf, "SET model_name "
3620 WPS_LONG_MODEL_NAME) < 0)
3621 return -2;
3622 if (wpa_command(intf, "SET model_number "
3623 WPS_LONG_MODEL_NUMBER) < 0)
3624 return -2;
3625 if (wpa_command(intf, "SET serial_number "
3626 WPS_LONG_SERIAL_NUMBER) < 0)
3627 return -2;
3628 }
3629
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003630 val = get_param(cmd, "RSN_IE");
3631 if (val) {
3632 if (strcasecmp(val, "disable") == 0)
3633 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3634 else if (strcasecmp(val, "enable") == 0)
3635 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3636 }
3637
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003638 val = get_param(cmd, "WpsVersion");
3639 if (val)
3640 dut->wps_forced_version = get_wps_forced_version(dut, val);
3641
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003642 val = get_param(cmd, "WscEAPFragment");
3643 if (val && strcasecmp(val, "enable") == 0)
3644 dut->eap_fragment = 1;
3645
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003646 return 1;
3647}
3648
3649
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003650static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3651 struct sigma_conn *conn,
3652 const char *intf,
3653 struct sigma_cmd *cmd)
3654{
3655 const char *val;
3656
3657 val = get_param(cmd, "FileType");
3658 if (val && strcasecmp(val, "PPSMO") == 0)
3659 return download_ppsmo(dut, conn, intf, cmd);
3660 if (val && strcasecmp(val, "CERT") == 0)
3661 return download_cert(dut, conn, intf, cmd);
3662 if (val) {
3663 send_resp(dut, conn, SIGMA_ERROR,
3664 "ErrorCode,Unsupported FileType");
3665 return 0;
3666 }
3667
3668 return 1;
3669}
3670
3671
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303672static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3673 struct sigma_conn *conn,
3674 const char *intf,
3675 struct sigma_cmd *cmd)
3676{
3677 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303678 char buf[1000];
3679 char text[20];
3680 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303681
3682 val = get_param(cmd, "OCESupport");
3683 if (val && strcasecmp(val, "Disable") == 0) {
3684 if (wpa_command(intf, "SET oce 0") < 0) {
3685 send_resp(dut, conn, SIGMA_ERROR,
3686 "ErrorCode,Failed to disable OCE");
3687 return 0;
3688 }
3689 } else if (val && strcasecmp(val, "Enable") == 0) {
3690 if (wpa_command(intf, "SET oce 1") < 0) {
3691 send_resp(dut, conn, SIGMA_ERROR,
3692 "ErrorCode,Failed to enable OCE");
3693 return 0;
3694 }
3695 }
3696
vamsi krishnaa2799492017-12-05 14:28:01 +05303697 val = get_param(cmd, "FILScap");
3698 if (val && (atoi(val) == 1)) {
3699 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3700 send_resp(dut, conn, SIGMA_ERROR,
3701 "ErrorCode,Failed to enable FILS");
3702 return 0;
3703 }
3704 } else if (val && (atoi(val) == 0)) {
3705 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3706 send_resp(dut, conn, SIGMA_ERROR,
3707 "ErrorCode,Failed to disable FILS");
3708 return 0;
3709 }
3710 }
3711
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303712 val = get_param(cmd, "FILSHLP");
3713 if (val && strcasecmp(val, "Enable") == 0) {
3714 if (get_wpa_status(get_station_ifname(), "address", text,
3715 sizeof(text)) < 0)
3716 return -2;
3717 hwaddr_aton(text, addr);
3718 snprintf(buf, sizeof(buf),
3719 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3720 "080045100140000040004011399e00000000ffffffff00440043"
3721 "012cb30001010600fd4f46410000000000000000000000000000"
3722 "000000000000"
3723 "%02x%02x%02x%02x%02x%02x"
3724 "0000000000000000000000000000000000000000000000000000"
3725 "0000000000000000000000000000000000000000000000000000"
3726 "0000000000000000000000000000000000000000000000000000"
3727 "0000000000000000000000000000000000000000000000000000"
3728 "0000000000000000000000000000000000000000000000000000"
3729 "0000000000000000000000000000000000000000000000000000"
3730 "0000000000000000000000000000000000000000000000000000"
3731 "0000000000000000000000000000000000000000638253633501"
3732 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3733 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3734 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3735 if (wpa_command(intf, buf)) {
3736 send_resp(dut, conn, SIGMA_ERROR,
3737 "ErrorCode,Failed to add HLP");
3738 return 0;
3739 }
3740 dut->fils_hlp = 1;
3741 }
3742
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303743 return 1;
3744}
3745
3746
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003747static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3748 const char *val)
3749{
3750 int counter = 0;
3751 char token[50];
3752 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303753 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003754
Peng Xub8fc5cc2017-05-10 17:27:28 -07003755 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003756 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303757 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003758 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003759 if (strcmp(result, "disable") == 0)
3760 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
3761 else
3762 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303763 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003764 counter++;
3765 }
3766}
3767
3768
3769static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3770 const char *val)
3771{
3772 char buf[100];
3773
3774 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3775 if (system(buf) != 0) {
3776 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3777 }
3778}
3779
3780
3781static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3782 const char *val)
3783{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003784 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003785 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003786 }
3787}
3788
3789
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003790static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3791 const char *val)
3792{
3793#ifdef NL80211_SUPPORT
3794 struct nl_msg *msg;
3795 int ret = 0;
3796 struct nlattr *params;
3797 int ifindex;
3798 int wmmenable = 1;
3799
3800 if (val &&
3801 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3802 wmmenable = 0;
3803
3804 ifindex = if_nametoindex(intf);
3805 if (ifindex == 0) {
3806 sigma_dut_print(dut, DUT_MSG_ERROR,
3807 "%s: Index for interface %s failed",
3808 __func__, intf);
3809 return -1;
3810 }
3811
3812 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3813 NL80211_CMD_VENDOR)) ||
3814 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3815 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3816 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3817 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3818 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3819 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3820 wmmenable)) {
3821 sigma_dut_print(dut, DUT_MSG_ERROR,
3822 "%s: err in adding vendor_cmd and vendor_data",
3823 __func__);
3824 nlmsg_free(msg);
3825 return -1;
3826 }
3827 nla_nest_end(msg, params);
3828
3829 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3830 if (ret) {
3831 sigma_dut_print(dut, DUT_MSG_ERROR,
3832 "%s: err in send_and_recv_msgs, ret=%d",
3833 __func__, ret);
3834 }
3835 return ret;
3836#else /* NL80211_SUPPORT */
3837 sigma_dut_print(dut, DUT_MSG_ERROR,
3838 "WMM cannot be changed without NL80211_SUPPORT defined");
3839 return -1;
3840#endif /* NL80211_SUPPORT */
3841}
3842
3843
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003844static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3845 const char *val)
3846{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003847 int sgi20;
3848
3849 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3850
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003851 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003852}
3853
3854
3855static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3856 const char *val)
3857{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303858 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003859
3860 /* Disable Tx Beam forming when using a fixed rate */
3861 ath_disable_txbf(dut, intf);
3862
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303863 v = atoi(val);
3864 if (v < 0 || v > 32) {
3865 sigma_dut_print(dut, DUT_MSG_ERROR,
3866 "Invalid Fixed MCS rate: %d", v);
3867 return;
3868 }
3869 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003870
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003871 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003872
3873 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003874 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003875}
3876
3877
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08003878static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3879 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003880{
3881 char buf[60];
3882
3883 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3884 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3885 else
3886 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3887
3888 if (system(buf) != 0)
3889 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3890}
3891
3892
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003893static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3894 int ampdu)
3895{
3896 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003897 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003898
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003899 if (ampdu)
3900 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003901 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3902 if (system(buf) != 0) {
3903 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3904 return -1;
3905 }
3906
3907 return 0;
3908}
3909
3910
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003911static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3912 const char *val)
3913{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003914 run_iwpriv(dut, intf, "tx_stbc %s", val);
3915 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003916}
3917
3918
3919static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3920 const char *val)
3921{
3922 char buf[60];
3923
Peng Xucc317ed2017-05-18 16:44:37 -07003924 if (strcmp(val, "160") == 0) {
3925 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3926 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003927 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3928 } else if (strcmp(val, "40") == 0) {
3929 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3930 } else if (strcmp(val, "20") == 0) {
3931 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3932 } else if (strcasecmp(val, "Auto") == 0) {
3933 buf[0] = '\0';
3934 } else {
3935 sigma_dut_print(dut, DUT_MSG_ERROR,
3936 "WIDTH/CTS_WIDTH value not supported");
3937 return -1;
3938 }
3939
3940 if (buf[0] != '\0' && system(buf) != 0) {
3941 sigma_dut_print(dut, DUT_MSG_ERROR,
3942 "Failed to set WIDTH/CTS_WIDTH");
3943 return -1;
3944 }
3945
3946 return 0;
3947}
3948
3949
3950int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3951 const char *intf, const char *val)
3952{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003953 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003954 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003955 dut->chwidth = 0;
3956 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003957 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003958 dut->chwidth = 0;
3959 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003960 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003961 dut->chwidth = 1;
3962 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003963 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003964 dut->chwidth = 2;
3965 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003966 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003967 dut->chwidth = 3;
3968 } else {
3969 send_resp(dut, conn, SIGMA_ERROR,
3970 "ErrorCode,WIDTH not supported");
3971 return -1;
3972 }
3973
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003974 return 0;
3975}
3976
3977
3978static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3979 const char *val)
3980{
3981 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07003982 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003983
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003984 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003985 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003986 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003987 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003988 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003989 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003990 } else {
3991 sigma_dut_print(dut, DUT_MSG_ERROR,
3992 "SP_STREAM value not supported");
3993 return -1;
3994 }
3995
3996 if (system(buf) != 0) {
3997 sigma_dut_print(dut, DUT_MSG_ERROR,
3998 "Failed to set SP_STREAM");
3999 return -1;
4000 }
4001
Arif Hussainac6c5112018-05-25 17:34:00 -07004002 dut->sta_nss = sta_nss;
4003
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004004 return 0;
4005}
4006
4007
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304008static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4009 const char *val)
4010{
4011 char buf[60];
4012
4013 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4014 if (system(buf) != 0)
4015 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4016
4017 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4018 if (system(buf) != 0)
4019 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4020}
4021
4022
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304023static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4024 struct sigma_conn *conn,
4025 const char *intf, int capa)
4026{
4027 char buf[32];
4028
4029 if (capa > 0 && capa < 4) {
4030 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4031 if (wpa_command(intf, buf) < 0) {
4032 send_resp(dut, conn, SIGMA_ERROR,
4033 "ErrorCode, Failed to set cellular data capability");
4034 return 0;
4035 }
4036 return 1;
4037 }
4038
4039 sigma_dut_print(dut, DUT_MSG_ERROR,
4040 "Invalid Cellular data capability: %d", capa);
4041 send_resp(dut, conn, SIGMA_INVALID,
4042 "ErrorCode,Invalid cellular data capability");
4043 return 0;
4044}
4045
4046
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304047static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4048 const char *intf, const char *val)
4049{
4050 if (strcasecmp(val, "Disable") == 0) {
4051 if (wpa_command(intf, "SET roaming 0") < 0) {
4052 send_resp(dut, conn, SIGMA_ERROR,
4053 "ErrorCode,Failed to disable roaming");
4054 return 0;
4055 }
4056 return 1;
4057 }
4058
4059 if (strcasecmp(val, "Enable") == 0) {
4060 if (wpa_command(intf, "SET roaming 1") < 0) {
4061 send_resp(dut, conn, SIGMA_ERROR,
4062 "ErrorCode,Failed to enable roaming");
4063 return 0;
4064 }
4065 return 1;
4066 }
4067
4068 sigma_dut_print(dut, DUT_MSG_ERROR,
4069 "Invalid value provided for roaming: %s", val);
4070 send_resp(dut, conn, SIGMA_INVALID,
4071 "ErrorCode,Unknown value provided for Roaming");
4072 return 0;
4073}
4074
4075
Ashwini Patila75de5a2017-04-13 16:35:05 +05304076static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4077 struct sigma_conn *conn,
4078 const char *intf, const char *val)
4079{
4080 if (strcasecmp(val, "Disable") == 0) {
4081 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4082 send_resp(dut, conn, SIGMA_ERROR,
4083 "ErrorCode,Failed to disable Assoc_disallow");
4084 return 0;
4085 }
4086 return 1;
4087 }
4088
4089 if (strcasecmp(val, "Enable") == 0) {
4090 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4091 send_resp(dut, conn, SIGMA_ERROR,
4092 "ErrorCode,Failed to enable Assoc_disallow");
4093 return 0;
4094 }
4095 return 1;
4096 }
4097
4098 sigma_dut_print(dut, DUT_MSG_ERROR,
4099 "Invalid value provided for Assoc_disallow: %s", val);
4100 send_resp(dut, conn, SIGMA_INVALID,
4101 "ErrorCode,Unknown value provided for Assoc_disallow");
4102 return 0;
4103}
4104
4105
Ashwini Patilc63161e2017-04-13 16:30:23 +05304106static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4107 const char *intf, const char *val)
4108{
4109 if (strcasecmp(val, "Reject") == 0) {
4110 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4111 send_resp(dut, conn, SIGMA_ERROR,
4112 "ErrorCode,Failed to Reject BTM Request");
4113 return 0;
4114 }
4115 return 1;
4116 }
4117
4118 if (strcasecmp(val, "Accept") == 0) {
4119 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4120 send_resp(dut, conn, SIGMA_ERROR,
4121 "ErrorCode,Failed to Accept BTM Request");
4122 return 0;
4123 }
4124 return 1;
4125 }
4126
4127 sigma_dut_print(dut, DUT_MSG_ERROR,
4128 "Invalid value provided for BSS_Transition: %s", val);
4129 send_resp(dut, conn, SIGMA_INVALID,
4130 "ErrorCode,Unknown value provided for BSS_Transition");
4131 return 0;
4132}
4133
4134
Ashwini Patil00402582017-04-13 12:29:39 +05304135static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4136 struct sigma_conn *conn,
4137 const char *intf,
4138 struct sigma_cmd *cmd)
4139{
4140 const char *ch, *pref, *op_class, *reason;
4141 char buf[120];
4142 int len, ret;
4143
4144 pref = get_param(cmd, "Ch_Pref");
4145 if (!pref)
4146 return 1;
4147
4148 if (strcasecmp(pref, "clear") == 0) {
4149 free(dut->non_pref_ch_list);
4150 dut->non_pref_ch_list = NULL;
4151 } else {
4152 op_class = get_param(cmd, "Ch_Op_Class");
4153 if (!op_class) {
4154 send_resp(dut, conn, SIGMA_INVALID,
4155 "ErrorCode,Ch_Op_Class not provided");
4156 return 0;
4157 }
4158
4159 ch = get_param(cmd, "Ch_Pref_Num");
4160 if (!ch) {
4161 send_resp(dut, conn, SIGMA_INVALID,
4162 "ErrorCode,Ch_Pref_Num not provided");
4163 return 0;
4164 }
4165
4166 reason = get_param(cmd, "Ch_Reason_Code");
4167 if (!reason) {
4168 send_resp(dut, conn, SIGMA_INVALID,
4169 "ErrorCode,Ch_Reason_Code not provided");
4170 return 0;
4171 }
4172
4173 if (!dut->non_pref_ch_list) {
4174 dut->non_pref_ch_list =
4175 calloc(1, NON_PREF_CH_LIST_SIZE);
4176 if (!dut->non_pref_ch_list) {
4177 send_resp(dut, conn, SIGMA_ERROR,
4178 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4179 return 0;
4180 }
4181 }
4182 len = strlen(dut->non_pref_ch_list);
4183 ret = snprintf(dut->non_pref_ch_list + len,
4184 NON_PREF_CH_LIST_SIZE - len,
4185 " %s:%s:%s:%s", op_class, ch, pref, reason);
4186 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4187 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4188 dut->non_pref_ch_list);
4189 } else {
4190 sigma_dut_print(dut, DUT_MSG_ERROR,
4191 "snprintf failed for non_pref_list, ret = %d",
4192 ret);
4193 send_resp(dut, conn, SIGMA_ERROR,
4194 "ErrorCode,snprintf failed");
4195 free(dut->non_pref_ch_list);
4196 dut->non_pref_ch_list = NULL;
4197 return 0;
4198 }
4199 }
4200
4201 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4202 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4203 if (ret < 0 || ret >= (int) sizeof(buf)) {
4204 sigma_dut_print(dut, DUT_MSG_DEBUG,
4205 "snprintf failed for set non_pref_chan, ret: %d",
4206 ret);
4207 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4208 return 0;
4209 }
4210
4211 if (wpa_command(intf, buf) < 0) {
4212 send_resp(dut, conn, SIGMA_ERROR,
4213 "ErrorCode,Failed to set non-preferred channel list");
4214 return 0;
4215 }
4216
4217 return 1;
4218}
4219
4220
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004221#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004222
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004223static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4224 uint8_t cfg)
4225{
4226 struct nl_msg *msg;
4227 int ret = 0;
4228 struct nlattr *params;
4229 int ifindex;
4230
4231 ifindex = if_nametoindex(intf);
4232 if (ifindex == 0) {
4233 sigma_dut_print(dut, DUT_MSG_ERROR,
4234 "%s: Index for interface %s failed",
4235 __func__, intf);
4236 return -1;
4237 }
4238
4239 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4240 NL80211_CMD_VENDOR)) ||
4241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4242 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4243 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4244 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4245 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4246 nla_put_u8(msg,
4247 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4248 cfg)) {
4249 sigma_dut_print(dut, DUT_MSG_ERROR,
4250 "%s: err in adding vendor_cmd and vendor_data",
4251 __func__);
4252 nlmsg_free(msg);
4253 return -1;
4254 }
4255 nla_nest_end(msg, params);
4256
4257 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4258 if (ret) {
4259 sigma_dut_print(dut, DUT_MSG_ERROR,
4260 "%s: err in send_and_recv_msgs, ret=%d",
4261 __func__, ret);
4262 }
4263 return ret;
4264}
4265
4266
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004267static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4268 enum he_fragmentation_val frag)
4269{
4270 struct nl_msg *msg;
4271 int ret = 0;
4272 struct nlattr *params;
4273 int ifindex;
4274
4275 ifindex = if_nametoindex(intf);
4276 if (ifindex == 0) {
4277 sigma_dut_print(dut, DUT_MSG_ERROR,
4278 "%s: Index for interface %s failed",
4279 __func__, intf);
4280 return -1;
4281 }
4282
4283 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4284 NL80211_CMD_VENDOR)) ||
4285 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4286 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4287 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4288 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4289 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4290 nla_put_u8(msg,
4291 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4292 frag)) {
4293 sigma_dut_print(dut, DUT_MSG_ERROR,
4294 "%s: err in adding vendor_cmd and vendor_data",
4295 __func__);
4296 nlmsg_free(msg);
4297 return -1;
4298 }
4299 nla_nest_end(msg, params);
4300
4301 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4302 if (ret) {
4303 sigma_dut_print(dut, DUT_MSG_ERROR,
4304 "%s: err in send_and_recv_msgs, ret=%d",
4305 __func__, ret);
4306 }
4307 return ret;
4308}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004309
4310
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004311static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
4312 enum qca_wlan_he_ltf_cfg ltf)
4313{
4314 struct nl_msg *msg;
4315 int ret = 0;
4316 struct nlattr *params;
4317 int ifindex;
4318
4319 ifindex = if_nametoindex(intf);
4320 if (ifindex == 0) {
4321 sigma_dut_print(dut, DUT_MSG_ERROR,
4322 "%s: Index for interface %s failed",
4323 __func__, intf);
4324 return -1;
4325 }
4326
4327 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4328 NL80211_CMD_VENDOR)) ||
4329 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4330 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4331 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4332 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4333 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4334 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4335 ltf)) {
4336 sigma_dut_print(dut, DUT_MSG_ERROR,
4337 "%s: err in adding vendor_cmd and vendor_data",
4338 __func__);
4339 nlmsg_free(msg);
4340 return -1;
4341 }
4342 nla_nest_end(msg, params);
4343
4344 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4345 if (ret) {
4346 sigma_dut_print(dut, DUT_MSG_ERROR,
4347 "%s: err in send_and_recv_msgs, ret=%d",
4348 __func__, ret);
4349 }
4350 return ret;
4351}
4352
4353
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004354static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4355 int noack, enum qca_wlan_ac_type ac)
4356{
4357 struct nl_msg *msg;
4358 int ret = 0;
4359 struct nlattr *params;
4360 int ifindex;
4361
4362 ifindex = if_nametoindex(intf);
4363 if (ifindex == 0) {
4364 sigma_dut_print(dut, DUT_MSG_ERROR,
4365 "%s: Index for interface %s failed",
4366 __func__, intf);
4367 return -1;
4368 }
4369
4370 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4371 NL80211_CMD_VENDOR)) ||
4372 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4373 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4374 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4375 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4376 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4377 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4378 noack) ||
4379 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4380 ac)) {
4381 sigma_dut_print(dut, DUT_MSG_ERROR,
4382 "%s: err in adding vendor_cmd and vendor_data",
4383 __func__);
4384 nlmsg_free(msg);
4385 return -1;
4386 }
4387 nla_nest_end(msg, params);
4388
4389 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4390 if (ret) {
4391 sigma_dut_print(dut, DUT_MSG_ERROR,
4392 "%s: err in send_and_recv_msgs, ret=%d",
4393 __func__, ret);
4394 }
4395 return ret;
4396}
4397
4398
4399static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4400 const char *val)
4401{
4402 int noack, ret;
4403 char token[100];
4404 char *result;
4405 char *saveptr;
4406 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4407
4408 strlcpy(token, val, sizeof(token));
4409 token[sizeof(token) - 1] = '\0';
4410 result = strtok_r(token, ":", &saveptr);
4411 while (result) {
4412 noack = strcasecmp(result, "Disable") != 0;
4413 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4414 if (ret) {
4415 sigma_dut_print(dut, DUT_MSG_ERROR,
4416 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4417 ac, ret);
4418 }
4419 result = strtok_r(NULL, ":", &saveptr);
4420 ac++;
4421 }
4422}
4423
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004424#endif /* NL80211_SUPPORT */
4425
4426
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004427static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
4428 struct sigma_conn *conn,
4429 struct sigma_cmd *cmd)
4430{
4431 const char *intf = get_param(cmd, "Interface");
4432 const char *val;
4433
4434 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004435 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4436 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004437 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4438 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004439
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004440 if (val && strcasecmp(val, "LOC") == 0)
4441 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004442 if (val && strcasecmp(val, "60GHZ") == 0) {
4443 val = get_param(cmd, "WPS");
4444 if (val && strcasecmp(val, "disable") == 0) {
4445 dut->wps_disable = 1;
4446 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4447 } else {
4448 /* wps_disable can have other value from the previous
4449 * test, so make sure it has the correct value.
4450 */
4451 dut->wps_disable = 0;
4452 }
4453
4454 val = get_param(cmd, "P2P");
4455 if (val && strcasecmp(val, "disable") == 0)
4456 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4457 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004458
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004459 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4460 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4461
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004462#ifdef ANDROID_NAN
4463 if (val && strcasecmp(val, "NAN") == 0)
4464 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4465#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004466#ifdef MIRACAST
4467 if (val && (strcasecmp(val, "WFD") == 0 ||
4468 strcasecmp(val, "DisplayR2") == 0))
4469 return miracast_preset_testparameters(dut, conn, cmd);
4470#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004471
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304472 if (val && strcasecmp(val, "MBO") == 0) {
4473 val = get_param(cmd, "Cellular_Data_Cap");
4474 if (val &&
4475 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4476 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304477
4478 val = get_param(cmd, "Ch_Pref");
4479 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4480 return 0;
4481
Ashwini Patilc63161e2017-04-13 16:30:23 +05304482 val = get_param(cmd, "BSS_Transition");
4483 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4484 return 0;
4485
Ashwini Patila75de5a2017-04-13 16:35:05 +05304486 val = get_param(cmd, "Assoc_Disallow");
4487 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4488 return 0;
4489
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304490 val = get_param(cmd, "Roaming");
4491 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4492 return 0;
4493
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304494 return 1;
4495 }
4496
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304497 if (val && strcasecmp(val, "OCE") == 0)
4498 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4499
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004500#if 0
4501 val = get_param(cmd, "Supplicant");
4502 if (val && strcasecmp(val, "Default") != 0) {
4503 send_resp(dut, conn, SIGMA_ERROR,
4504 "ErrorCode,Only default(Vendor) supplicant "
4505 "supported");
4506 return 0;
4507 }
4508#endif
4509
4510 val = get_param(cmd, "RTS");
4511 if (val) {
4512 switch (get_driver_type()) {
4513 case DRIVER_ATHEROS:
4514 ath_sta_set_rts(dut, intf, val);
4515 break;
4516 default:
4517#if 0
4518 send_resp(dut, conn, SIGMA_ERROR,
4519 "ErrorCode,Setting RTS not supported");
4520 return 0;
4521#else
4522 sigma_dut_print(dut, DUT_MSG_DEBUG,
4523 "Setting RTS not supported");
4524 break;
4525#endif
4526 }
4527 }
4528
4529#if 0
4530 val = get_param(cmd, "FRGMNT");
4531 if (val) {
4532 /* TODO */
4533 send_resp(dut, conn, SIGMA_ERROR,
4534 "ErrorCode,Setting FRGMNT not supported");
4535 return 0;
4536 }
4537#endif
4538
4539#if 0
4540 val = get_param(cmd, "Preamble");
4541 if (val) {
4542 /* TODO: Long/Short */
4543 send_resp(dut, conn, SIGMA_ERROR,
4544 "ErrorCode,Setting Preamble not supported");
4545 return 0;
4546 }
4547#endif
4548
4549 val = get_param(cmd, "Mode");
4550 if (val) {
4551 if (strcmp(val, "11b") == 0 ||
4552 strcmp(val, "11g") == 0 ||
4553 strcmp(val, "11a") == 0 ||
4554 strcmp(val, "11n") == 0 ||
4555 strcmp(val, "11ng") == 0 ||
4556 strcmp(val, "11nl") == 0 ||
4557 strcmp(val, "11nl(nabg)") == 0 ||
4558 strcmp(val, "AC") == 0 ||
4559 strcmp(val, "11AC") == 0 ||
4560 strcmp(val, "11ac") == 0 ||
4561 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004562 strcmp(val, "11an") == 0 ||
4563 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004564 /* STA supports all modes by default */
4565 } else {
4566 send_resp(dut, conn, SIGMA_ERROR,
4567 "ErrorCode,Setting Mode not supported");
4568 return 0;
4569 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004570
4571 /* Change the mode only in case of testbed for HE program
4572 * and for 11a and 11g modes only. */
4573 if (dut->program == PROGRAM_HE &&
4574 dut->device_type == STA_testbed) {
4575 int phymode;
4576 char buf[60];
4577
4578 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004579 phymode = 1; /* IEEE80211_MODE_11A */
4580 } else if (strcmp(val, "11g") == 0) {
4581 phymode = 3; /* IEEE80211_MODE_11G */
4582 } else if (strcmp(val, "11b") == 0) {
4583 phymode = 2; /* IEEE80211_MODE_11B */
4584 } else if (strcmp(val, "11n") == 0 ||
4585 strcmp(val, "11nl") == 0 ||
4586 strcmp(val, "11nl(nabg)") == 0) {
4587 phymode = 22; /* IEEE80211_MODE_11AGN */
4588 } else if (strcmp(val, "11ng") == 0) {
4589 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4590 } else if (strcmp(val, "AC") == 0 ||
4591 strcasecmp(val, "11AC") == 0) {
4592 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4593 } else if (strcmp(val, "11na") == 0 ||
4594 strcasecmp(val, "11an") == 0) {
4595 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4596 } else if (strcmp(val, "11ax") == 0) {
4597 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004598 } else {
4599 sigma_dut_print(dut, DUT_MSG_DEBUG,
4600 "Ignoring mode change for mode: %s",
4601 val);
4602 phymode = -1;
4603 }
4604 if (phymode != -1) {
4605 snprintf(buf, sizeof(buf),
4606 "iwpriv %s setphymode %d",
4607 intf, phymode);
4608 if (system(buf) != 0) {
4609 sigma_dut_print(dut, DUT_MSG_ERROR,
4610 "iwpriv setting of phymode failed");
4611 }
4612 }
4613 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004614 }
4615
4616 val = get_param(cmd, "wmm");
4617 if (val) {
4618 switch (get_driver_type()) {
4619 case DRIVER_ATHEROS:
4620 ath_sta_set_wmm(dut, intf, val);
4621 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004622 case DRIVER_WCN:
4623 wcn_sta_set_wmm(dut, intf, val);
4624 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004625 default:
4626 sigma_dut_print(dut, DUT_MSG_DEBUG,
4627 "Setting wmm not supported");
4628 break;
4629 }
4630 }
4631
4632 val = get_param(cmd, "Powersave");
4633 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004634 char buf[60];
4635
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004636 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004637 if (get_driver_type() == DRIVER_WCN) {
4638 snprintf(buf, sizeof(buf),
4639 "iwpriv %s setPower 2", intf);
4640 if (system(buf) != 0) {
4641 sigma_dut_print(dut, DUT_MSG_ERROR,
4642 "iwpriv setPower 2 failed");
4643 return 0;
4644 }
4645 }
4646
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004647 if (wpa_command(get_station_ifname(),
4648 "P2P_SET ps 0") < 0)
4649 return -2;
4650 /* Make sure test modes are disabled */
4651 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4652 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4653 } else if (strcmp(val, "1") == 0 ||
4654 strcasecmp(val, "PSPoll") == 0 ||
4655 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004656 if (get_driver_type() == DRIVER_WCN) {
4657 snprintf(buf, sizeof(buf),
4658 "iwpriv %s setPower 1", intf);
4659 if (system(buf) != 0) {
4660 sigma_dut_print(dut, DUT_MSG_ERROR,
4661 "iwpriv setPower 1 failed");
4662 return 0;
4663 }
4664 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004665 /* Disable default power save mode */
4666 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4667 /* Enable PS-Poll test mode */
4668 if (wpa_command(get_station_ifname(),
4669 "P2P_SET ps 97") < 0 ||
4670 wpa_command(get_station_ifname(),
4671 "P2P_SET ps 99") < 0)
4672 return -2;
4673 } else if (strcmp(val, "2") == 0 ||
4674 strcasecmp(val, "Fast") == 0) {
4675 /* TODO */
4676 send_resp(dut, conn, SIGMA_ERROR,
4677 "ErrorCode,Powersave=Fast not supported");
4678 return 0;
4679 } else if (strcmp(val, "3") == 0 ||
4680 strcasecmp(val, "PSNonPoll") == 0) {
4681 /* Make sure test modes are disabled */
4682 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4683 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4684
4685 /* Enable default power save mode */
4686 if (wpa_command(get_station_ifname(),
4687 "P2P_SET ps 1") < 0)
4688 return -2;
4689 } else
4690 return -1;
4691 }
4692
4693 val = get_param(cmd, "NoAck");
4694 if (val) {
4695 switch (get_driver_type()) {
4696 case DRIVER_ATHEROS:
4697 ath_sta_set_noack(dut, intf, val);
4698 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004699#ifdef NL80211_SUPPORT
4700 case DRIVER_WCN:
4701 wcn_sta_set_noack(dut, intf, val);
4702 break;
4703#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004704 default:
4705 send_resp(dut, conn, SIGMA_ERROR,
4706 "ErrorCode,Setting NoAck not supported");
4707 return 0;
4708 }
4709 }
4710
4711 val = get_param(cmd, "IgnoreChswitchProhibit");
4712 if (val) {
4713 /* TODO: Enabled/disabled */
4714 if (strcasecmp(val, "Enabled") == 0) {
4715 send_resp(dut, conn, SIGMA_ERROR,
4716 "ErrorCode,Enabling IgnoreChswitchProhibit "
4717 "not supported");
4718 return 0;
4719 }
4720 }
4721
4722 val = get_param(cmd, "TDLS");
4723 if (val) {
4724 if (strcasecmp(val, "Disabled") == 0) {
4725 if (wpa_command(intf, "SET tdls_disabled 1")) {
4726 send_resp(dut, conn, SIGMA_ERROR,
4727 "ErrorCode,Failed to disable TDLS");
4728 return 0;
4729 }
4730 } else if (strcasecmp(val, "Enabled") == 0) {
4731 if (wpa_command(intf, "SET tdls_disabled 0")) {
4732 send_resp(dut, conn, SIGMA_ERROR,
4733 "ErrorCode,Failed to enable TDLS");
4734 return 0;
4735 }
4736 } else {
4737 send_resp(dut, conn, SIGMA_ERROR,
4738 "ErrorCode,Unsupported TDLS value");
4739 return 0;
4740 }
4741 }
4742
4743 val = get_param(cmd, "TDLSmode");
4744 if (val) {
4745 if (strcasecmp(val, "Default") == 0) {
4746 wpa_command(intf, "SET tdls_testing 0");
4747 } else if (strcasecmp(val, "APProhibit") == 0) {
4748 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4749 send_resp(dut, conn, SIGMA_ERROR,
4750 "ErrorCode,Failed to enable ignore "
4751 "APProhibit TDLS mode");
4752 return 0;
4753 }
4754 } else if (strcasecmp(val, "HiLoMac") == 0) {
4755 /* STA should respond with TDLS setup req for a TDLS
4756 * setup req */
4757 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4758 send_resp(dut, conn, SIGMA_ERROR,
4759 "ErrorCode,Failed to enable HiLoMac "
4760 "TDLS mode");
4761 return 0;
4762 }
4763 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4764 /*
4765 * Since all security modes are enabled by default when
4766 * Sigma control is used, there is no need to do
4767 * anything here.
4768 */
4769 } else if (strcasecmp(val, "ExistLink") == 0) {
4770 /*
4771 * Since we allow new TDLS Setup Request even if there
4772 * is an existing link, nothing needs to be done for
4773 * this.
4774 */
4775 } else {
4776 /* TODO:
4777 * ExistLink: STA should send TDLS setup req even if
4778 * direct link already exists
4779 */
4780 send_resp(dut, conn, SIGMA_ERROR,
4781 "ErrorCode,Unsupported TDLSmode value");
4782 return 0;
4783 }
4784 }
4785
4786 val = get_param(cmd, "FakePubKey");
4787 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4788 send_resp(dut, conn, SIGMA_ERROR,
4789 "ErrorCode,Failed to enable FakePubKey");
4790 return 0;
4791 }
4792
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004793#ifdef NL80211_SUPPORT
4794 val = get_param(cmd, "FrgmntSupport");
4795 if (val) {
4796 if (strcasecmp(val, "Enable") == 0) {
4797 if (sta_set_he_fragmentation(dut, intf,
4798 HE_FRAG_LEVEL1)) {
4799 send_resp(dut, conn, SIGMA_ERROR,
4800 "ErrorCode,Failed to enable HE Fragmentation");
4801 return 0;
4802 }
4803 } else if (strcasecmp(val, "Disable") == 0) {
4804 if (sta_set_he_fragmentation(dut, intf,
4805 HE_FRAG_DISABLE)) {
4806 send_resp(dut, conn, SIGMA_ERROR,
4807 "ErrorCode,Failed to disable HE Fragmentation");
4808 return 0;
4809 }
4810 }
4811 }
4812#endif /* NL80211_SUPPORT */
4813
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004814 return 1;
4815}
4816
4817
4818static const char * ath_get_radio_name(const char *radio_name)
4819{
4820 if (radio_name == NULL)
4821 return "wifi0";
4822 if (strcmp(radio_name, "wifi1") == 0)
4823 return "wifi1";
4824 if (strcmp(radio_name, "wifi2") == 0)
4825 return "wifi2";
4826 return "wifi0";
4827}
4828
4829
4830static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4831 const char *val)
4832{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004833 unsigned int vht_mcsmap = 0;
4834 int txchainmask = 0;
4835 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4836
4837 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4838 if (dut->testbed_flag_txsp == 1) {
4839 vht_mcsmap = 0xfffc;
4840 dut->testbed_flag_txsp = 0;
4841 } else {
4842 vht_mcsmap = 0xfffe;
4843 }
4844 txchainmask = 1;
4845 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4846 if (dut->testbed_flag_txsp == 1) {
4847 vht_mcsmap = 0xfff0;
4848 dut->testbed_flag_txsp = 0;
4849 } else {
4850 vht_mcsmap = 0xfffa;
4851 }
4852 txchainmask = 3;
4853 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4854 if (dut->testbed_flag_txsp == 1) {
4855 vht_mcsmap = 0xffc0;
4856 dut->testbed_flag_txsp = 0;
4857 } else {
4858 vht_mcsmap = 0xffea;
4859 }
4860 txchainmask = 7;
4861 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4862 if (dut->testbed_flag_txsp == 1) {
4863 vht_mcsmap = 0xff00;
4864 dut->testbed_flag_txsp = 0;
4865 } else {
4866 vht_mcsmap = 0xffaa;
4867 }
4868 txchainmask = 15;
4869 } else {
4870 if (dut->testbed_flag_txsp == 1) {
4871 vht_mcsmap = 0xffc0;
4872 dut->testbed_flag_txsp = 0;
4873 } else {
4874 vht_mcsmap = 0xffea;
4875 }
4876 }
4877
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004878 if (txchainmask)
4879 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004880
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004881 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004882}
4883
4884
4885static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4886 const char *val)
4887{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004888 unsigned int vht_mcsmap = 0;
4889 int rxchainmask = 0;
4890 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4891
4892 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4893 if (dut->testbed_flag_rxsp == 1) {
4894 vht_mcsmap = 0xfffc;
4895 dut->testbed_flag_rxsp = 0;
4896 } else {
4897 vht_mcsmap = 0xfffe;
4898 }
4899 rxchainmask = 1;
4900 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4901 if (dut->testbed_flag_rxsp == 1) {
4902 vht_mcsmap = 0xfff0;
4903 dut->testbed_flag_rxsp = 0;
4904 } else {
4905 vht_mcsmap = 0xfffa;
4906 }
4907 rxchainmask = 3;
4908 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4909 if (dut->testbed_flag_rxsp == 1) {
4910 vht_mcsmap = 0xffc0;
4911 dut->testbed_flag_rxsp = 0;
4912 } else {
4913 vht_mcsmap = 0xffea;
4914 }
4915 rxchainmask = 7;
4916 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4917 if (dut->testbed_flag_rxsp == 1) {
4918 vht_mcsmap = 0xff00;
4919 dut->testbed_flag_rxsp = 0;
4920 } else {
4921 vht_mcsmap = 0xffaa;
4922 }
4923 rxchainmask = 15;
4924 } else {
4925 if (dut->testbed_flag_rxsp == 1) {
4926 vht_mcsmap = 0xffc0;
4927 dut->testbed_flag_rxsp = 0;
4928 } else {
4929 vht_mcsmap = 0xffea;
4930 }
4931 }
4932
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004933 if (rxchainmask)
4934 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004935
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004936 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004937}
4938
4939
4940void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4941{
4942 if (strcasecmp(val, "enable") == 0) {
4943 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4944 != 0) {
4945 sigma_dut_print(dut, DUT_MSG_ERROR,
4946 "Disable BB_VHTSIGB_CRC_CALC failed");
4947 }
4948
4949 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4950 != 0) {
4951 sigma_dut_print(dut, DUT_MSG_ERROR,
4952 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4953 }
4954 } else {
4955 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4956 != 0) {
4957 sigma_dut_print(dut, DUT_MSG_ERROR,
4958 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4959 }
4960
4961 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4962 != 0) {
4963 sigma_dut_print(dut, DUT_MSG_ERROR,
4964 "Enable BB_VHTSIGB_CRC_CALC failed");
4965 }
4966 }
4967}
4968
4969
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004970static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4971 const char *val)
4972{
4973 char buf[60];
4974
4975 if (strcmp(val, "20") == 0) {
4976 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4977 dut->chwidth = 0;
4978 } else if (strcmp(val, "40") == 0) {
4979 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4980 dut->chwidth = 1;
4981 } else if (strcmp(val, "80") == 0) {
4982 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4983 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05304984 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004985 buf[0] = '\0';
4986 } else {
4987 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4988 val);
4989 return -1;
4990 }
4991
4992 if (buf[0] != '\0' && system(buf) != 0) {
4993 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4994 return -1;
4995 }
4996
4997 return 0;
4998}
4999
5000
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005001static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5002 const char *intf, int addbareject)
5003{
5004#ifdef NL80211_SUPPORT
5005 struct nl_msg *msg;
5006 int ret = 0;
5007 struct nlattr *params;
5008 int ifindex;
5009
5010 ifindex = if_nametoindex(intf);
5011 if (ifindex == 0) {
5012 sigma_dut_print(dut, DUT_MSG_ERROR,
5013 "%s: Index for interface %s failed",
5014 __func__, intf);
5015 return -1;
5016 }
5017
5018 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5019 NL80211_CMD_VENDOR)) ||
5020 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5021 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5022 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5023 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5024 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5025 nla_put_u8(msg,
5026 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5027 !addbareject)) {
5028 sigma_dut_print(dut, DUT_MSG_ERROR,
5029 "%s: err in adding vendor_cmd and vendor_data",
5030 __func__);
5031 nlmsg_free(msg);
5032 return -1;
5033 }
5034 nla_nest_end(msg, params);
5035
5036 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5037 if (ret) {
5038 sigma_dut_print(dut, DUT_MSG_ERROR,
5039 "%s: err in send_and_recv_msgs, ret=%d",
5040 __func__, ret);
5041 }
5042 return ret;
5043#else /* NL80211_SUPPORT */
5044 sigma_dut_print(dut, DUT_MSG_ERROR,
5045 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5046 return -1;
5047#endif /* NL80211_SUPPORT */
5048}
5049
5050
5051static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5052 int addbareject)
5053{
5054 int ret;
5055
5056 switch (get_driver_type()) {
5057 case DRIVER_WCN:
5058 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5059 if (ret) {
5060 sigma_dut_print(dut, DUT_MSG_ERROR,
5061 "nlvendor_sta_set_addba_reject failed, ret:%d",
5062 ret);
5063 return ret;
5064 }
5065 break;
5066 default:
5067 sigma_dut_print(dut, DUT_MSG_ERROR,
5068 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5069 ret = -1;
5070 break;
5071 }
5072
5073 return ret;
5074}
5075
5076
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005077static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5078 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005079{
5080#ifdef NL80211_SUPPORT
5081 struct nl_msg *msg;
5082 int ret = 0;
5083 struct nlattr *params;
5084 int ifindex;
5085
5086 ifindex = if_nametoindex(intf);
5087 if (ifindex == 0) {
5088 sigma_dut_print(dut, DUT_MSG_ERROR,
5089 "%s: Index for interface %s failed",
5090 __func__, intf);
5091 return -1;
5092 }
5093
5094 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5095 NL80211_CMD_VENDOR)) ||
5096 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5097 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5098 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5099 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5100 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5101 nla_put_u8(msg,
5102 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005103 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005104 sigma_dut_print(dut, DUT_MSG_ERROR,
5105 "%s: err in adding vendor_cmd and vendor_data",
5106 __func__);
5107 nlmsg_free(msg);
5108 return -1;
5109 }
5110 nla_nest_end(msg, params);
5111
5112 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5113 if (ret) {
5114 sigma_dut_print(dut, DUT_MSG_ERROR,
5115 "%s: err in send_and_recv_msgs, ret=%d",
5116 __func__, ret);
5117 }
5118 return ret;
5119#else /* NL80211_SUPPORT */
5120 sigma_dut_print(dut, DUT_MSG_ERROR,
5121 "Disable addba not possible without NL80211_SUPPORT defined");
5122 return -1;
5123#endif /* NL80211_SUPPORT */
5124}
5125
5126
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305127#ifdef NL80211_SUPPORT
5128static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5129{
5130 struct nl_msg *msg;
5131 int ret = 0;
5132 int ifindex;
5133
5134 ifindex = if_nametoindex(intf);
5135 if (ifindex == 0) {
5136 sigma_dut_print(dut, DUT_MSG_ERROR,
5137 "%s: Index for interface %s failed",
5138 __func__, intf);
5139 return -1;
5140 }
5141
5142 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5143 NL80211_CMD_SET_WIPHY)) ||
5144 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5145 sigma_dut_print(dut, DUT_MSG_ERROR,
5146 "%s: err in adding RTS threshold",
5147 __func__);
5148 nlmsg_free(msg);
5149 return -1;
5150 }
5151
5152 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5153 if (ret) {
5154 sigma_dut_print(dut, DUT_MSG_ERROR,
5155 "%s: err in send_and_recv_msgs, ret=%d",
5156 __func__, ret);
5157 }
5158 return ret;
5159}
5160#endif /* NL80211_SUPPORT */
5161
5162
5163static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5164{
5165 char buf[100];
5166
5167#ifdef NL80211_SUPPORT
5168 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5169 return 0;
5170 sigma_dut_print(dut, DUT_MSG_DEBUG,
5171 "Fall back to using iwconfig for setting RTS threshold");
5172#endif /* NL80211_SUPPORT */
5173
5174 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5175 if (system(buf) != 0) {
5176 sigma_dut_print(dut, DUT_MSG_ERROR,
5177 "Failed to set RTS threshold %d", val);
5178 return -1;
5179 }
5180 return 0;
5181}
5182
5183
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005184static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5185 struct sigma_conn *conn,
5186 struct sigma_cmd *cmd)
5187{
5188 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005189 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005190 char buf[30];
5191
5192 val = get_param(cmd, "40_INTOLERANT");
5193 if (val) {
5194 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5195 /* TODO: iwpriv ht40intol through wpa_supplicant */
5196 send_resp(dut, conn, SIGMA_ERROR,
5197 "ErrorCode,40_INTOLERANT not supported");
5198 return 0;
5199 }
5200 }
5201
5202 val = get_param(cmd, "ADDBA_REJECT");
5203 if (val) {
5204 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5205 /* reject any ADDBA with status "decline" */
5206 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005207 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005208 } else {
5209 /* accept ADDBA */
5210 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005211 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005212 }
5213 }
5214
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005215 if (addbareject >= 0 &&
5216 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5217 send_resp(dut, conn, SIGMA_ERROR,
5218 "ErrorCode,set addba_reject failed");
5219 return 0;
5220 }
5221
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005222 val = get_param(cmd, "AMPDU");
5223 if (val) {
5224 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5225 /* enable AMPDU Aggregation */
5226 if (ampdu == 0) {
5227 send_resp(dut, conn, SIGMA_ERROR,
5228 "ErrorCode,Mismatch in "
5229 "addba_reject/ampdu - "
5230 "not supported");
5231 return 0;
5232 }
5233 ampdu = 1;
5234 } else {
5235 /* disable AMPDU Aggregation */
5236 if (ampdu == 1) {
5237 send_resp(dut, conn, SIGMA_ERROR,
5238 "ErrorCode,Mismatch in "
5239 "addba_reject/ampdu - "
5240 "not supported");
5241 return 0;
5242 }
5243 ampdu = 0;
5244 }
5245 }
5246
5247 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005248 int ret;
5249
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005250 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5251 ampdu ? "Enabling" : "Disabling");
5252 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005253 if (wpa_command(intf, buf) < 0 &&
5254 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005255 send_resp(dut, conn, SIGMA_ERROR,
5256 "ErrorCode,set aggr failed");
5257 return 0;
5258 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005259
5260 if (ampdu == 0) {
5261 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005262 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005263 if (ret) {
5264 sigma_dut_print(dut, DUT_MSG_ERROR,
5265 "Failed to disable addba, ret:%d",
5266 ret);
5267 }
5268 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005269 }
5270
5271 val = get_param(cmd, "AMSDU");
5272 if (val) {
5273 switch (get_driver_type()) {
5274 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005275 case DRIVER_WCN:
5276 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005277 break;
5278 default:
5279 if (strcmp(val, "1") == 0 ||
5280 strcasecmp(val, "Enable") == 0) {
5281 /* Enable AMSDU Aggregation */
5282 send_resp(dut, conn, SIGMA_ERROR,
5283 "ErrorCode,AMSDU aggregation not supported");
5284 return 0;
5285 }
5286 break;
5287 }
5288 }
5289
5290 val = get_param(cmd, "STBC_RX");
5291 if (val) {
5292 switch (get_driver_type()) {
5293 case DRIVER_ATHEROS:
5294 ath_sta_set_stbc(dut, intf, val);
5295 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305296 case DRIVER_WCN:
5297 wcn_sta_set_stbc(dut, intf, val);
5298 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005299 default:
5300 send_resp(dut, conn, SIGMA_ERROR,
5301 "ErrorCode,STBC_RX not supported");
5302 return 0;
5303 }
5304 }
5305
5306 val = get_param(cmd, "WIDTH");
5307 if (val) {
5308 switch (get_driver_type()) {
5309 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005310 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005311 send_resp(dut, conn, SIGMA_ERROR,
5312 "ErrorCode,Failed to set WIDTH");
5313 return 0;
5314 }
5315 break;
5316 case DRIVER_ATHEROS:
5317 if (ath_set_width(dut, conn, intf, val) < 0)
5318 return 0;
5319 break;
5320 default:
5321 sigma_dut_print(dut, DUT_MSG_ERROR,
5322 "Setting WIDTH not supported");
5323 break;
5324 }
5325 }
5326
5327 val = get_param(cmd, "SMPS");
5328 if (val) {
5329 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5330 send_resp(dut, conn, SIGMA_ERROR,
5331 "ErrorCode,SMPS not supported");
5332 return 0;
5333 }
5334
5335 val = get_param(cmd, "TXSP_STREAM");
5336 if (val) {
5337 switch (get_driver_type()) {
5338 case DRIVER_WCN:
5339 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5340 send_resp(dut, conn, SIGMA_ERROR,
5341 "ErrorCode,Failed to set TXSP_STREAM");
5342 return 0;
5343 }
5344 break;
5345 case DRIVER_ATHEROS:
5346 ath_sta_set_txsp_stream(dut, intf, val);
5347 break;
5348 default:
5349 sigma_dut_print(dut, DUT_MSG_ERROR,
5350 "Setting TXSP_STREAM not supported");
5351 break;
5352 }
5353 }
5354
5355 val = get_param(cmd, "RXSP_STREAM");
5356 if (val) {
5357 switch (get_driver_type()) {
5358 case DRIVER_WCN:
5359 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5360 send_resp(dut, conn, SIGMA_ERROR,
5361 "ErrorCode,Failed to set RXSP_STREAM");
5362 return 0;
5363 }
5364 break;
5365 case DRIVER_ATHEROS:
5366 ath_sta_set_rxsp_stream(dut, intf, val);
5367 break;
5368 default:
5369 sigma_dut_print(dut, DUT_MSG_ERROR,
5370 "Setting RXSP_STREAM not supported");
5371 break;
5372 }
5373 }
5374
5375 val = get_param(cmd, "DYN_BW_SGNL");
5376 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005377 switch (get_driver_type()) {
5378 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005379 if (strcasecmp(val, "enable") == 0) {
5380 snprintf(buf, sizeof(buf),
5381 "iwpriv %s cwmenable 1", intf);
5382 if (system(buf) != 0) {
5383 sigma_dut_print(dut, DUT_MSG_ERROR,
5384 "iwpriv cwmenable 1 failed");
5385 return 0;
5386 }
5387 } else if (strcasecmp(val, "disable") == 0) {
5388 snprintf(buf, sizeof(buf),
5389 "iwpriv %s cwmenable 0", intf);
5390 if (system(buf) != 0) {
5391 sigma_dut_print(dut, DUT_MSG_ERROR,
5392 "iwpriv cwmenable 0 failed");
5393 return 0;
5394 }
5395 } else {
5396 sigma_dut_print(dut, DUT_MSG_ERROR,
5397 "Unsupported DYN_BW_SGL");
5398 }
5399
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005400 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5401 if (system(buf) != 0) {
5402 sigma_dut_print(dut, DUT_MSG_ERROR,
5403 "Failed to set cts_cbw in DYN_BW_SGNL");
5404 return 0;
5405 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005406 break;
5407 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005408 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005409 ath_config_dyn_bw_sig(dut, intf, val);
5410 break;
5411 default:
5412 sigma_dut_print(dut, DUT_MSG_ERROR,
5413 "Failed to set DYN_BW_SGNL");
5414 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005415 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005416 }
5417
5418 val = get_param(cmd, "RTS_FORCE");
5419 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005420 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005421 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305422 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005423 sigma_dut_print(dut, DUT_MSG_ERROR,
5424 "Failed to set RTS_FORCE 64");
5425 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005426 snprintf(buf, sizeof(buf),
5427 "wifitool %s beeliner_fw_test 100 1", intf);
5428 if (system(buf) != 0) {
5429 sigma_dut_print(dut, DUT_MSG_ERROR,
5430 "wifitool beeliner_fw_test 100 1 failed");
5431 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005432 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305433 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005434 sigma_dut_print(dut, DUT_MSG_ERROR,
5435 "Failed to set RTS_FORCE 2347");
5436 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005437 } else {
5438 send_resp(dut, conn, SIGMA_ERROR,
5439 "ErrorCode,RTS_FORCE value not supported");
5440 return 0;
5441 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005442 }
5443
5444 val = get_param(cmd, "CTS_WIDTH");
5445 if (val) {
5446 switch (get_driver_type()) {
5447 case DRIVER_WCN:
5448 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5449 send_resp(dut, conn, SIGMA_ERROR,
5450 "ErrorCode,Failed to set CTS_WIDTH");
5451 return 0;
5452 }
5453 break;
5454 case DRIVER_ATHEROS:
5455 ath_set_cts_width(dut, intf, val);
5456 break;
5457 default:
5458 sigma_dut_print(dut, DUT_MSG_ERROR,
5459 "Setting CTS_WIDTH not supported");
5460 break;
5461 }
5462 }
5463
5464 val = get_param(cmd, "BW_SGNL");
5465 if (val) {
5466 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005467 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005468 } else if (strcasecmp(val, "Disable") == 0) {
5469 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005470 } else {
5471 send_resp(dut, conn, SIGMA_ERROR,
5472 "ErrorCode,BW_SGNL value not supported");
5473 return 0;
5474 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005475 }
5476
5477 val = get_param(cmd, "Band");
5478 if (val) {
5479 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5480 /* STA supports all bands by default */
5481 } else {
5482 send_resp(dut, conn, SIGMA_ERROR,
5483 "ErrorCode,Unsupported Band");
5484 return 0;
5485 }
5486 }
5487
5488 val = get_param(cmd, "zero_crc");
5489 if (val) {
5490 switch (get_driver_type()) {
5491 case DRIVER_ATHEROS:
5492 ath_set_zero_crc(dut, val);
5493 break;
5494 default:
5495 break;
5496 }
5497 }
5498
5499 return 1;
5500}
5501
5502
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005503static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5504{
5505 switch (get_driver_type()) {
5506#ifdef __linux__
5507 case DRIVER_WIL6210:
5508 return wil6210_set_force_mcs(dut, force, mcs);
5509#endif /* __linux__ */
5510 default:
5511 sigma_dut_print(dut, DUT_MSG_ERROR,
5512 "Unsupported sta_set_force_mcs with the current driver");
5513 return -1;
5514 }
5515}
5516
5517
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005518static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5519{
5520 switch (get_driver_type()) {
5521#ifdef __linux__
5522 case DRIVER_WIL6210:
5523 return wil6210_force_rsn_ie(dut, state);
5524#endif /* __linux__ */
5525 default:
5526 sigma_dut_print(dut, DUT_MSG_ERROR,
5527 "Unsupported sta_60g_force_rsn_ie with the current driver");
5528 return -1;
5529 }
5530}
5531
5532
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005533static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5534 struct sigma_cmd *cmd)
5535{
5536 const char *val;
5537 char buf[100];
5538
5539 val = get_param(cmd, "MSDUSize");
5540 if (val) {
5541 int mtu;
5542
5543 dut->amsdu_size = atoi(val);
5544 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5545 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5546 sigma_dut_print(dut, DUT_MSG_ERROR,
5547 "MSDUSize %d is above max %d or below min %d",
5548 dut->amsdu_size,
5549 IEEE80211_MAX_DATA_LEN_DMG,
5550 IEEE80211_SNAP_LEN_DMG);
5551 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005552 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005553 }
5554
5555 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5556 sigma_dut_print(dut, DUT_MSG_DEBUG,
5557 "Setting amsdu_size to %d", mtu);
5558 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
5559 get_station_ifname(), mtu);
5560
5561 if (system(buf) != 0) {
5562 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5563 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005564 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005565 }
5566 }
5567
5568 val = get_param(cmd, "BAckRcvBuf");
5569 if (val) {
5570 dut->back_rcv_buf = atoi(val);
5571 if (dut->back_rcv_buf == 0) {
5572 sigma_dut_print(dut, DUT_MSG_ERROR,
5573 "Failed to convert %s or value is 0",
5574 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005575 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005576 }
5577
5578 sigma_dut_print(dut, DUT_MSG_DEBUG,
5579 "Setting BAckRcvBuf to %s", val);
5580 }
5581
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005582 val = get_param(cmd, "MCS_FixedRate");
5583 if (val) {
5584 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5585 sigma_dut_print(dut, DUT_MSG_ERROR,
5586 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005587 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005588 }
5589 }
5590
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005591 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005592}
5593
5594
5595static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5596 struct sigma_cmd *cmd)
5597{
5598 int net_id;
5599 char *ifname;
5600 const char *val;
5601 char buf[100];
5602
5603 dut->mode = SIGMA_MODE_STATION;
5604 ifname = get_main_ifname();
5605 if (wpa_command(ifname, "PING") != 0) {
5606 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005607 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005608 }
5609
5610 wpa_command(ifname, "FLUSH");
5611 net_id = add_network_common(dut, conn, ifname, cmd);
5612 if (net_id < 0) {
5613 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5614 return net_id;
5615 }
5616
5617 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5618 if (set_network(ifname, net_id, "mode", "2") < 0) {
5619 sigma_dut_print(dut, DUT_MSG_ERROR,
5620 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005621 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005622 }
5623
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005624 if (set_network(ifname, net_id, "pbss", "1") < 0)
5625 return -2;
5626
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005627 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005628 "Supplicant set network with mode 2. network_id %d",
5629 net_id);
5630
5631 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5632 sigma_dut_print(dut, DUT_MSG_INFO,
5633 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005634 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005635 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636
5637 val = get_param(cmd, "Security");
5638 if (val && strcasecmp(val, "OPEN") == 0) {
5639 dut->ap_key_mgmt = AP_OPEN;
5640 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5641 sigma_dut_print(dut, DUT_MSG_ERROR,
5642 "Failed to set supplicant to %s security",
5643 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005644 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005645 }
5646 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5647 dut->ap_key_mgmt = AP_WPA2_PSK;
5648 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5649 sigma_dut_print(dut, DUT_MSG_ERROR,
5650 "Failed to set supplicant to %s security",
5651 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005652 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005653 }
5654
5655 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5656 sigma_dut_print(dut, DUT_MSG_ERROR,
5657 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005658 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005659 }
5660 } else if (val) {
5661 sigma_dut_print(dut, DUT_MSG_ERROR,
5662 "Requested Security %s is not supported on 60GHz",
5663 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005664 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005665 }
5666
5667 val = get_param(cmd, "Encrypt");
5668 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5669 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5670 sigma_dut_print(dut, DUT_MSG_ERROR,
5671 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005672 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005673 }
5674 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5675 sigma_dut_print(dut, DUT_MSG_ERROR,
5676 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005677 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005678 }
5679 } else if (val) {
5680 sigma_dut_print(dut, DUT_MSG_ERROR,
5681 "Requested Encrypt %s is not supported on 60 GHz",
5682 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005683 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005684 }
5685
5686 val = get_param(cmd, "PSK");
5687 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5688 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5689 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005690 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005691 }
5692
5693 /* Convert 60G channel to freq */
5694 switch (dut->ap_channel) {
5695 case 1:
5696 val = "58320";
5697 break;
5698 case 2:
5699 val = "60480";
5700 break;
5701 case 3:
5702 val = "62640";
5703 break;
5704 default:
5705 sigma_dut_print(dut, DUT_MSG_ERROR,
5706 "Failed to configure channel %d. Not supported",
5707 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005708 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005709 }
5710
5711 if (set_network(ifname, net_id, "frequency", val) < 0) {
5712 sigma_dut_print(dut, DUT_MSG_ERROR,
5713 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005714 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005715 }
5716
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005717 if (dut->eap_fragment) {
5718 sigma_dut_print(dut, DUT_MSG_DEBUG,
5719 "Set EAP fragment size to 128 bytes.");
5720 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
5721 return ERROR_SEND_STATUS;
5722 }
5723
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005724 sigma_dut_print(dut, DUT_MSG_DEBUG,
5725 "Supplicant set network with frequency");
5726
5727 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5728 if (wpa_command(ifname, buf) < 0) {
5729 sigma_dut_print(dut, DUT_MSG_INFO,
5730 "Failed to select network id %d on %s",
5731 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005732 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005733 }
5734
5735 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5736
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005737 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005738}
5739
5740
Lior David67543f52017-01-03 19:04:22 +02005741static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5742{
5743 char buf[128], fname[128];
5744 FILE *f;
5745
5746 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5747 sigma_dut_print(dut, DUT_MSG_ERROR,
5748 "failed to get wil6210 debugfs dir");
5749 return -1;
5750 }
5751
5752 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5753 f = fopen(fname, "w");
5754 if (!f) {
5755 sigma_dut_print(dut, DUT_MSG_ERROR,
5756 "failed to open: %s", fname);
5757 return -1;
5758 }
5759
5760 fprintf(f, "%d\n", abft_len);
5761 fclose(f);
5762
5763 return 0;
5764}
5765
5766
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02005767int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5768 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02005769{
5770 switch (get_driver_type()) {
5771 case DRIVER_WIL6210:
5772 return wil6210_set_abft_len(dut, abft_len);
5773 default:
5774 sigma_dut_print(dut, DUT_MSG_ERROR,
5775 "set abft_len not supported");
5776 return -1;
5777 }
5778}
5779
5780
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005781static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5782 struct sigma_cmd *cmd)
5783{
5784 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005785 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005786
5787 if (dut->dev_role != DEVROLE_PCP) {
5788 send_resp(dut, conn, SIGMA_INVALID,
5789 "ErrorCode,Invalid DevRole");
5790 return 0;
5791 }
5792
5793 val = get_param(cmd, "SSID");
5794 if (val) {
5795 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5796 send_resp(dut, conn, SIGMA_INVALID,
5797 "ErrorCode,Invalid SSID");
5798 return -1;
5799 }
5800
Peng Xub8fc5cc2017-05-10 17:27:28 -07005801 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005802 }
5803
5804 val = get_param(cmd, "CHANNEL");
5805 if (val) {
5806 const char *pos;
5807
5808 dut->ap_channel = atoi(val);
5809 pos = strchr(val, ';');
5810 if (pos) {
5811 pos++;
5812 dut->ap_channel_1 = atoi(pos);
5813 }
5814 }
5815
5816 switch (dut->ap_channel) {
5817 case 1:
5818 case 2:
5819 case 3:
5820 break;
5821 default:
5822 sigma_dut_print(dut, DUT_MSG_ERROR,
5823 "Channel %d is not supported", dut->ap_channel);
5824 send_resp(dut, conn, SIGMA_ERROR,
5825 "Requested channel is not supported");
5826 return -1;
5827 }
5828
5829 val = get_param(cmd, "BCNINT");
5830 if (val)
5831 dut->ap_bcnint = atoi(val);
5832
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005833 val = get_param(cmd, "AllocType");
5834 if (val) {
5835 send_resp(dut, conn, SIGMA_ERROR,
5836 "ErrorCode,AllocType is not supported yet");
5837 return -1;
5838 }
5839
5840 val = get_param(cmd, "PercentBI");
5841 if (val) {
5842 send_resp(dut, conn, SIGMA_ERROR,
5843 "ErrorCode,PercentBI is not supported yet");
5844 return -1;
5845 }
5846
5847 val = get_param(cmd, "CBAPOnly");
5848 if (val) {
5849 send_resp(dut, conn, SIGMA_ERROR,
5850 "ErrorCode,CBAPOnly is not supported yet");
5851 return -1;
5852 }
5853
5854 val = get_param(cmd, "AMPDU");
5855 if (val) {
5856 if (strcasecmp(val, "Enable") == 0)
5857 dut->ap_ampdu = 1;
5858 else if (strcasecmp(val, "Disable") == 0)
5859 dut->ap_ampdu = 2;
5860 else {
5861 send_resp(dut, conn, SIGMA_ERROR,
5862 "ErrorCode,AMPDU value is not Enable nor Disabled");
5863 return -1;
5864 }
5865 }
5866
5867 val = get_param(cmd, "AMSDU");
5868 if (val) {
5869 if (strcasecmp(val, "Enable") == 0)
5870 dut->ap_amsdu = 1;
5871 else if (strcasecmp(val, "Disable") == 0)
5872 dut->ap_amsdu = 2;
5873 }
5874
5875 val = get_param(cmd, "NumMSDU");
5876 if (val) {
5877 send_resp(dut, conn, SIGMA_ERROR,
5878 "ErrorCode, NumMSDU is not supported yet");
5879 return -1;
5880 }
5881
5882 val = get_param(cmd, "ABFTLRang");
5883 if (val) {
5884 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005885 "ABFTLRang parameter %s", val);
5886 if (strcmp(val, "Gt1") == 0)
5887 abft_len = 2; /* 2 slots in this case */
5888 }
5889
5890 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5891 send_resp(dut, conn, SIGMA_ERROR,
5892 "ErrorCode, Can't set ABFT length");
5893 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005894 }
5895
5896 if (sta_pcp_start(dut, conn, cmd) < 0) {
5897 send_resp(dut, conn, SIGMA_ERROR,
5898 "ErrorCode, Can't start PCP role");
5899 return -1;
5900 }
5901
5902 return sta_set_60g_common(dut, conn, cmd);
5903}
5904
5905
5906static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5907 struct sigma_cmd *cmd)
5908{
5909 const char *val = get_param(cmd, "DiscoveryMode");
5910
5911 if (dut->dev_role != DEVROLE_STA) {
5912 send_resp(dut, conn, SIGMA_INVALID,
5913 "ErrorCode,Invalid DevRole");
5914 return 0;
5915 }
5916
5917 if (val) {
5918 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5919 /* Ignore Discovery mode till Driver expose API. */
5920#if 0
5921 if (strcasecmp(val, "1") == 0) {
5922 send_resp(dut, conn, SIGMA_INVALID,
5923 "ErrorCode,DiscoveryMode 1 not supported");
5924 return 0;
5925 }
5926
5927 if (strcasecmp(val, "0") == 0) {
5928 /* OK */
5929 } else {
5930 send_resp(dut, conn, SIGMA_INVALID,
5931 "ErrorCode,DiscoveryMode not supported");
5932 return 0;
5933 }
5934#endif
5935 }
5936
5937 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005938 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005939 return sta_set_60g_common(dut, conn, cmd);
5940}
5941
5942
5943static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5944 struct sigma_cmd *cmd)
5945{
5946 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005947 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305948
Jouni Malinened77e672018-01-10 16:45:13 +02005949 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005950 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005951 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305952 wpa_command(intf, "DISCONNECT");
5953 return 1;
5954 }
5955
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005956 disconnect_station(dut);
5957 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5958 * due to cached results. */
5959 wpa_command(intf, "SET ignore_old_scan_res 1");
5960 wpa_command(intf, "BSS_FLUSH");
5961 return 1;
5962}
5963
5964
5965static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5966 struct sigma_cmd *cmd)
5967{
5968 const char *intf = get_param(cmd, "Interface");
5969 const char *bssid = get_param(cmd, "bssid");
5970 const char *val = get_param(cmd, "CHANNEL");
5971 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305972 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305973 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005974 int res;
5975 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305976 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305977 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005978
5979 if (bssid == NULL) {
5980 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5981 "argument");
5982 return 0;
5983 }
5984
5985 if (val)
5986 chan = atoi(val);
5987
5988 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5989 /* The current network may be from sta_associate or
5990 * sta_hs2_associate
5991 */
5992 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5993 0 ||
5994 set_network(intf, 0, "bssid", bssid) < 0)
5995 return -2;
5996 }
5997
5998 ctrl = open_wpa_mon(intf);
5999 if (ctrl == NULL) {
6000 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6001 "wpa_supplicant monitor connection");
6002 return -1;
6003 }
6004
Sunil Duttd30ce092018-01-11 23:56:29 +05306005 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6006 sizeof(result)) < 0 ||
6007 strncmp(result, "COMPLETED", 9) != 0) {
6008 sigma_dut_print(dut, DUT_MSG_DEBUG,
6009 "sta_reassoc: Not connected");
6010 fastreassoc = 0;
6011 }
6012
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306013 if (dut->rsne_override) {
6014#ifdef NL80211_SUPPORT
6015 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
6016 sta_config_rsnie(dut, 1);
6017 dut->config_rsnie = 1;
6018 }
6019#endif /* NL80211_SUPPORT */
6020 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6021 dut->rsne_override);
6022 if (wpa_command(intf, buf) < 0) {
6023 send_resp(dut, conn, SIGMA_ERROR,
6024 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6025 return 0;
6026 }
6027 }
6028
Sunil Duttd30ce092018-01-11 23:56:29 +05306029 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006030#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306031 if (chan) {
6032 unsigned int freq;
6033
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006034 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306035 if (!freq) {
6036 sigma_dut_print(dut, DUT_MSG_ERROR,
6037 "Invalid channel number provided: %d",
6038 chan);
6039 send_resp(dut, conn, SIGMA_INVALID,
6040 "ErrorCode,Invalid channel number");
6041 goto close_mon_conn;
6042 }
6043 res = snprintf(buf, sizeof(buf),
6044 "SCAN TYPE=ONLY freq=%d", freq);
6045 } else {
6046 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6047 }
6048 if (res < 0 || res >= (int) sizeof(buf)) {
6049 send_resp(dut, conn, SIGMA_ERROR,
6050 "ErrorCode,snprintf failed");
6051 goto close_mon_conn;
6052 }
6053 if (wpa_command(intf, buf) < 0) {
6054 sigma_dut_print(dut, DUT_MSG_INFO,
6055 "Failed to start scan");
6056 send_resp(dut, conn, SIGMA_ERROR,
6057 "ErrorCode,scan failed");
6058 goto close_mon_conn;
6059 }
6060
6061 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6062 buf, sizeof(buf));
6063 if (res < 0) {
6064 sigma_dut_print(dut, DUT_MSG_INFO,
6065 "Scan did not complete");
6066 send_resp(dut, conn, SIGMA_ERROR,
6067 "ErrorCode,scan did not complete");
6068 goto close_mon_conn;
6069 }
6070
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006071 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6072 < 0) {
6073 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6074 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306075 status = -2;
6076 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006077 }
6078 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6079 bssid, chan);
6080 if (res > 0 && res < (int) sizeof(buf))
6081 res = wpa_command(intf, buf);
6082
6083 if (res < 0 || res >= (int) sizeof(buf)) {
6084 send_resp(dut, conn, SIGMA_ERROR,
6085 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306086 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006087 }
6088#else /* ANDROID */
6089 sigma_dut_print(dut, DUT_MSG_DEBUG,
6090 "Reassoc using iwpriv - skip chan=%d info",
6091 chan);
6092 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
6093 if (system(buf) != 0) {
6094 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05306095 status = -2;
6096 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006097 }
6098#endif /* ANDROID */
6099 sigma_dut_print(dut, DUT_MSG_INFO,
6100 "sta_reassoc: Run %s successful", buf);
6101 } else if (wpa_command(intf, "REASSOCIATE")) {
6102 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6103 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306104 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006105 }
6106
6107 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6108 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306109 if (res < 0) {
6110 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
6111 status = -1;
6112 goto close_mon_conn;
6113 }
6114 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006115
Ashwini Patil467efef2017-05-25 12:18:27 +05306116close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006117 wpa_ctrl_detach(ctrl);
6118 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306119 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006120}
6121
6122
6123static void hs2_clear_credentials(const char *intf)
6124{
6125 wpa_command(intf, "REMOVE_CRED all");
6126}
6127
6128
Lior Davidcc88b562017-01-03 18:52:09 +02006129#ifdef __linux__
6130static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6131 unsigned int *aid)
6132{
Lior David0fe101e2017-03-09 16:09:50 +02006133 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006134
Lior David0fe101e2017-03-09 16:09:50 +02006135 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006136}
6137#endif /* __linux__ */
6138
6139
6140static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6141 unsigned int *aid)
6142{
6143 switch (get_driver_type()) {
6144#ifdef __linux__
6145 case DRIVER_WIL6210:
6146 return wil6210_get_aid(dut, bssid, aid);
6147#endif /* __linux__ */
6148 default:
6149 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6150 return -1;
6151 }
6152}
6153
6154
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006155static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6156 struct sigma_cmd *cmd)
6157{
6158 char buf[MAX_CMD_LEN];
6159 char bss_list[MAX_CMD_LEN];
6160 const char *parameter = get_param(cmd, "Parameter");
6161
6162 if (parameter == NULL)
6163 return -1;
6164
Lior Davidcc88b562017-01-03 18:52:09 +02006165 if (strcasecmp(parameter, "AID") == 0) {
6166 unsigned int aid = 0;
6167 char bssid[20];
6168
6169 if (get_wpa_status(get_station_ifname(), "bssid",
6170 bssid, sizeof(bssid)) < 0) {
6171 sigma_dut_print(dut, DUT_MSG_ERROR,
6172 "could not get bssid");
6173 return -2;
6174 }
6175
6176 if (sta_get_aid_60g(dut, bssid, &aid))
6177 return -2;
6178
6179 snprintf(buf, sizeof(buf), "aid,%d", aid);
6180 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6181 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6182 return 0;
6183 }
6184
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006185 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6186 char *bss_line;
6187 char *bss_id = NULL;
6188 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306189 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006190
6191 if (ifname == NULL) {
6192 sigma_dut_print(dut, DUT_MSG_INFO,
6193 "For get DiscoveredDevList need Interface name.");
6194 return -1;
6195 }
6196
6197 /*
6198 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6199 * of BSSIDs in "bssid=<BSSID>\n"
6200 */
6201 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6202 bss_list,
6203 sizeof(bss_list)) < 0) {
6204 sigma_dut_print(dut, DUT_MSG_ERROR,
6205 "Failed to get bss list");
6206 return -1;
6207 }
6208
6209 sigma_dut_print(dut, DUT_MSG_DEBUG,
6210 "bss list for ifname:%s is:%s",
6211 ifname, bss_list);
6212
6213 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306214 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006215 while (bss_line) {
6216 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6217 bss_id) {
6218 int len;
6219
6220 len = snprintf(buf + strlen(buf),
6221 sizeof(buf) - strlen(buf),
6222 ",%s", bss_id);
6223 free(bss_id);
6224 bss_id = NULL;
6225 if (len < 0) {
6226 sigma_dut_print(dut,
6227 DUT_MSG_ERROR,
6228 "Failed to read BSSID");
6229 send_resp(dut, conn, SIGMA_ERROR,
6230 "ErrorCode,Failed to read BSS ID");
6231 return 0;
6232 }
6233
6234 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6235 sigma_dut_print(dut,
6236 DUT_MSG_ERROR,
6237 "Response buf too small for list");
6238 send_resp(dut, conn,
6239 SIGMA_ERROR,
6240 "ErrorCode,Response buf too small for list");
6241 return 0;
6242 }
6243 }
6244
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306245 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006246 }
6247
6248 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6249 buf);
6250 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6251 return 0;
6252 }
6253
6254 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6255 return 0;
6256}
6257
6258
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006259static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6260 struct sigma_cmd *cmd)
6261{
6262 char buf[MAX_CMD_LEN];
6263 const char *parameter = get_param(cmd, "Parameter");
6264
6265 if (!parameter)
6266 return -1;
6267
6268 if (strcasecmp(parameter, "RSSI") == 0) {
6269 char rssi[10];
6270
6271 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
6272 rssi, sizeof(rssi)) < 0) {
6273 sigma_dut_print(dut, DUT_MSG_ERROR,
6274 "Could not get RSSI");
6275 return -2;
6276 }
6277
6278 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6279 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6280 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6281 return 0;
6282 }
6283
6284 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6285 return 0;
6286}
6287
6288
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006289static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
6290 struct sigma_cmd *cmd)
6291{
6292 const char *program = get_param(cmd, "Program");
6293
6294 if (program == NULL)
6295 return -1;
6296
6297 if (strcasecmp(program, "P2PNFC") == 0)
6298 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6299
6300 if (strcasecmp(program, "60ghz") == 0)
6301 return sta_get_parameter_60g(dut, conn, cmd);
6302
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006303 if (strcasecmp(program, "he") == 0)
6304 return sta_get_parameter_he(dut, conn, cmd);
6305
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006306#ifdef ANDROID_NAN
6307 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006308 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006309#endif /* ANDROID_NAN */
6310
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006311#ifdef MIRACAST
6312 if (strcasecmp(program, "WFD") == 0 ||
6313 strcasecmp(program, "DisplayR2") == 0)
6314 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6315#endif /* MIRACAST */
6316
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006317 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6318 return 0;
6319}
6320
6321
6322static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6323 const char *type)
6324{
6325 char buf[100];
6326
6327 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006328 run_iwpriv(dut, intf, "chwidth 2");
6329 run_iwpriv(dut, intf, "mode 11ACVHT80");
6330 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006331 }
6332
6333 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006334 run_iwpriv(dut, intf, "chwidth 0");
6335 run_iwpriv(dut, intf, "mode 11naht40");
6336 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006337 }
6338
6339 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006340 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006341
6342 /* Reset CTS width */
6343 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6344 intf);
6345 if (system(buf) != 0) {
6346 sigma_dut_print(dut, DUT_MSG_ERROR,
6347 "wifitool %s beeliner_fw_test 54 0 failed",
6348 intf);
6349 }
6350
6351 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006352 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006353
6354 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6355 if (system(buf) != 0) {
6356 sigma_dut_print(dut, DUT_MSG_ERROR,
6357 "iwpriv rts failed");
6358 }
6359 }
6360
6361 if (type && strcasecmp(type, "Testbed") == 0) {
6362 dut->testbed_flag_txsp = 1;
6363 dut->testbed_flag_rxsp = 1;
6364 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006365 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006366
6367 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006368 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006369
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006370 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006371
6372 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006373 run_iwpriv(dut, intf, "tx_stbc 0");
6374 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006375
6376 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006377 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006378 }
6379
6380 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006381 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006382 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006383
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006384 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006385 }
6386}
6387
6388
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006389#ifdef NL80211_SUPPORT
6390static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6391 enum he_mcs_config mcs)
6392{
6393 struct nl_msg *msg;
6394 int ret = 0;
6395 struct nlattr *params;
6396 int ifindex;
6397
6398 ifindex = if_nametoindex(intf);
6399 if (ifindex == 0) {
6400 sigma_dut_print(dut, DUT_MSG_ERROR,
6401 "%s: Index for interface %s failed",
6402 __func__, intf);
6403 return -1;
6404 }
6405
6406 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6407 NL80211_CMD_VENDOR)) ||
6408 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6409 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6410 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6411 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6412 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6413 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6414 mcs)) {
6415 sigma_dut_print(dut, DUT_MSG_ERROR,
6416 "%s: err in adding vendor_cmd and vendor_data",
6417 __func__);
6418 nlmsg_free(msg);
6419 return -1;
6420 }
6421 nla_nest_end(msg, params);
6422
6423 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6424 if (ret) {
6425 sigma_dut_print(dut, DUT_MSG_ERROR,
6426 "%s: err in send_and_recv_msgs, ret=%d",
6427 __func__, ret);
6428 }
6429 return ret;
6430}
6431#endif /* NL80211_SUPPORT */
6432
6433
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006434static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6435 const char *intf, int enable)
6436{
6437#ifdef NL80211_SUPPORT
6438 struct nl_msg *msg;
6439 int ret = 0;
6440 struct nlattr *params;
6441 int ifindex;
6442
6443 ifindex = if_nametoindex(intf);
6444 if (ifindex == 0) {
6445 sigma_dut_print(dut, DUT_MSG_ERROR,
6446 "%s: Index for interface %s failed",
6447 __func__, intf);
6448 return -1;
6449 }
6450
6451 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6452 NL80211_CMD_VENDOR)) ||
6453 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6454 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6455 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6456 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6457 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6458 nla_put_u8(msg,
6459 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6460 enable)) {
6461 sigma_dut_print(dut, DUT_MSG_ERROR,
6462 "%s: err in adding vendor_cmd and vendor_data",
6463 __func__);
6464 nlmsg_free(msg);
6465 return -1;
6466 }
6467 nla_nest_end(msg, params);
6468
6469 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6470 if (ret) {
6471 sigma_dut_print(dut, DUT_MSG_ERROR,
6472 "%s: err in send_and_recv_msgs, ret=%d",
6473 __func__, ret);
6474 }
6475 return ret;
6476#else /* NL80211_SUPPORT */
6477 sigma_dut_print(dut, DUT_MSG_ERROR,
6478 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6479 return -1;
6480#endif /* NL80211_SUPPORT */
6481}
6482
6483
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006484static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6485 const char *intf, int enable)
6486{
6487#ifdef NL80211_SUPPORT
6488 struct nl_msg *msg;
6489 int ret = 0;
6490 struct nlattr *params;
6491 int ifindex;
6492
6493 ifindex = if_nametoindex(intf);
6494 if (ifindex == 0) {
6495 sigma_dut_print(dut, DUT_MSG_ERROR,
6496 "%s: Index for interface %s failed",
6497 __func__, intf);
6498 return -1;
6499 }
6500
6501 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6502 NL80211_CMD_VENDOR)) ||
6503 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6504 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6505 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6506 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6507 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6508 nla_put_u8(msg,
6509 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6510 enable)) {
6511 sigma_dut_print(dut, DUT_MSG_ERROR,
6512 "%s: err in adding vendor_cmd and vendor_data",
6513 __func__);
6514 nlmsg_free(msg);
6515 return -1;
6516 }
6517 nla_nest_end(msg, params);
6518
6519 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6520 if (ret) {
6521 sigma_dut_print(dut, DUT_MSG_ERROR,
6522 "%s: err in send_and_recv_msgs, ret=%d",
6523 __func__, ret);
6524 }
6525 return ret;
6526#else /* NL80211_SUPPORT */
6527 sigma_dut_print(dut, DUT_MSG_ERROR,
6528 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6529 return -1;
6530#endif /* NL80211_SUPPORT */
6531}
6532
6533
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006534#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006535
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006536static int sta_set_he_testbed_def(struct sigma_dut *dut,
6537 const char *intf, int cfg)
6538{
6539 struct nl_msg *msg;
6540 int ret = 0;
6541 struct nlattr *params;
6542 int ifindex;
6543
6544 ifindex = if_nametoindex(intf);
6545 if (ifindex == 0) {
6546 sigma_dut_print(dut, DUT_MSG_ERROR,
6547 "%s: Index for interface %s failed",
6548 __func__, intf);
6549 return -1;
6550 }
6551
6552 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6553 NL80211_CMD_VENDOR)) ||
6554 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6555 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6556 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6557 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6558 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6559 nla_put_u8(msg,
6560 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6561 cfg)) {
6562 sigma_dut_print(dut, DUT_MSG_ERROR,
6563 "%s: err in adding vendor_cmd and vendor_data",
6564 __func__);
6565 nlmsg_free(msg);
6566 return -1;
6567 }
6568 nla_nest_end(msg, params);
6569
6570 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6571 if (ret) {
6572 sigma_dut_print(dut, DUT_MSG_ERROR,
6573 "%s: err in send_and_recv_msgs, ret=%d",
6574 __func__, ret);
6575 }
6576 return ret;
6577}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006578
6579
6580static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
6581{
6582 struct nl_msg *msg;
6583 int ret = 0;
6584 struct nlattr *params;
6585 int ifindex;
6586
6587 ifindex = if_nametoindex(intf);
6588 if (ifindex == 0) {
6589 sigma_dut_print(dut, DUT_MSG_ERROR,
6590 "%s: Index for interface %s failed",
6591 __func__, intf);
6592 return -1;
6593 }
6594
6595 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6596 NL80211_CMD_VENDOR)) ||
6597 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6598 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6599 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6600 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6601 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6602 nla_put_u8(msg,
6603 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
6604 cfg)) {
6605 sigma_dut_print(dut, DUT_MSG_ERROR,
6606 "%s: err in adding vendor_cmd and vendor_data",
6607 __func__);
6608 nlmsg_free(msg);
6609 return -1;
6610 }
6611 nla_nest_end(msg, params);
6612
6613 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6614 if (ret) {
6615 sigma_dut_print(dut, DUT_MSG_ERROR,
6616 "%s: err in send_and_recv_msgs, ret=%d",
6617 __func__, ret);
6618 }
6619 return ret;
6620}
6621
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006622#endif /* NL80211_SUPPORT */
6623
6624
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006625static int sta_set_addba_buf_size(struct sigma_dut *dut,
6626 const char *intf, int bufsize)
6627{
6628#ifdef NL80211_SUPPORT
6629 struct nl_msg *msg;
6630 int ret = 0;
6631 struct nlattr *params;
6632 int ifindex;
6633
6634 ifindex = if_nametoindex(intf);
6635 if (ifindex == 0) {
6636 sigma_dut_print(dut, DUT_MSG_ERROR,
6637 "%s: Index for interface %s failed",
6638 __func__, intf);
6639 return -1;
6640 }
6641
6642 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6643 NL80211_CMD_VENDOR)) ||
6644 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6645 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6646 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6647 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6648 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006649 nla_put_u16(msg,
6650 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6651 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006652 sigma_dut_print(dut, DUT_MSG_ERROR,
6653 "%s: err in adding vendor_cmd and vendor_data",
6654 __func__);
6655 nlmsg_free(msg);
6656 return -1;
6657 }
6658 nla_nest_end(msg, params);
6659
6660 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6661 if (ret) {
6662 sigma_dut_print(dut, DUT_MSG_ERROR,
6663 "%s: err in send_and_recv_msgs, ret=%d",
6664 __func__, ret);
6665 }
6666 return ret;
6667#else /* NL80211_SUPPORT */
6668 sigma_dut_print(dut, DUT_MSG_ERROR,
6669 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6670 return -1;
6671#endif /* NL80211_SUPPORT */
6672}
6673
6674
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006675static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6676 int enable)
6677{
6678#ifdef NL80211_SUPPORT
6679 struct nl_msg *msg;
6680 int ret = 0;
6681 struct nlattr *params;
6682 int ifindex;
6683
6684 ifindex = if_nametoindex(intf);
6685 if (ifindex == 0) {
6686 sigma_dut_print(dut, DUT_MSG_ERROR,
6687 "%s: Index for interface %s failed",
6688 __func__, intf);
6689 return -1;
6690 }
6691
6692 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6693 NL80211_CMD_VENDOR)) ||
6694 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6695 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6696 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6697 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6698 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6699 nla_put_u8(msg,
6700 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
6701 enable)) {
6702 sigma_dut_print(dut, DUT_MSG_ERROR,
6703 "%s: err in adding vendor_cmd and vendor_data",
6704 __func__);
6705 nlmsg_free(msg);
6706 return -1;
6707 }
6708 nla_nest_end(msg, params);
6709
6710 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6711 if (ret) {
6712 sigma_dut_print(dut, DUT_MSG_ERROR,
6713 "%s: err in send_and_recv_msgs, ret=%d",
6714 __func__, ret);
6715 }
6716 return ret;
6717#else /* NL80211_SUPPORT */
6718 sigma_dut_print(dut, DUT_MSG_ERROR,
6719 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
6720 return -1;
6721#endif /* NL80211_SUPPORT */
6722}
6723
6724
Arif Hussain9765f7d2018-07-03 08:28:26 -07006725static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
6726 int val)
6727{
6728#ifdef NL80211_SUPPORT
6729 struct nl_msg *msg;
6730 int ret = 0;
6731 struct nlattr *params;
6732 int ifindex;
6733
6734 ifindex = if_nametoindex(intf);
6735 if (ifindex == 0) {
6736 sigma_dut_print(dut, DUT_MSG_ERROR,
6737 "%s: Index for interface %s failed, val:%d",
6738 __func__, intf, val);
6739 return -1;
6740 }
6741
6742 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6743 NL80211_CMD_VENDOR)) ||
6744 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6745 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6746 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6747 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6748 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6749 nla_put_u8(msg,
6750 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
6751 val)) {
6752 sigma_dut_print(dut, DUT_MSG_ERROR,
6753 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6754 __func__, val);
6755 nlmsg_free(msg);
6756 return -1;
6757 }
6758 nla_nest_end(msg, params);
6759
6760 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6761 if (ret) {
6762 sigma_dut_print(dut, DUT_MSG_ERROR,
6763 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6764 __func__, ret, val);
6765 }
6766 return ret;
6767#else /* NL80211_SUPPORT */
6768 sigma_dut_print(dut, DUT_MSG_ERROR,
6769 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
6770 return -1;
6771#endif /* NL80211_SUPPORT */
6772}
6773
6774
Arif Hussain68d23f52018-07-11 13:39:08 -07006775#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006776static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
6777 enum qca_wlan_he_mac_padding_dur val)
6778{
Arif Hussain68d23f52018-07-11 13:39:08 -07006779 struct nl_msg *msg;
6780 int ret = 0;
6781 struct nlattr *params;
6782 int ifindex;
6783
6784 ifindex = if_nametoindex(intf);
6785 if (ifindex == 0) {
6786 sigma_dut_print(dut, DUT_MSG_ERROR,
6787 "%s: Index for interface %s failed, val:%d",
6788 __func__, intf, val);
6789 return -1;
6790 }
6791
6792 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6793 NL80211_CMD_VENDOR)) ||
6794 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6795 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6796 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6797 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6798 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6799 nla_put_u8(msg,
6800 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
6801 val)) {
6802 sigma_dut_print(dut, DUT_MSG_ERROR,
6803 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6804 __func__, val);
6805 nlmsg_free(msg);
6806 return -1;
6807 }
6808 nla_nest_end(msg, params);
6809
6810 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6811 if (ret) {
6812 sigma_dut_print(dut, DUT_MSG_ERROR,
6813 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6814 __func__, ret, val);
6815 }
6816 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07006817}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006818#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07006819
6820
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006821static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
6822 int val)
6823{
6824#ifdef NL80211_SUPPORT
6825 struct nl_msg *msg;
6826 int ret = 0;
6827 struct nlattr *params;
6828 int ifindex;
6829
6830 ifindex = if_nametoindex(intf);
6831 if (ifindex == 0) {
6832 sigma_dut_print(dut, DUT_MSG_ERROR,
6833 "%s: Index for interface %s failed, val:%d",
6834 __func__, intf, val);
6835 return -1;
6836 }
6837
6838 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6839 NL80211_CMD_VENDOR)) ||
6840 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6841 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6842 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6843 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6844 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6845 nla_put_u8(msg,
6846 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
6847 val)) {
6848 sigma_dut_print(dut, DUT_MSG_ERROR,
6849 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6850 __func__, val);
6851 nlmsg_free(msg);
6852 return -1;
6853 }
6854 nla_nest_end(msg, params);
6855
6856 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6857 if (ret) {
6858 sigma_dut_print(dut, DUT_MSG_ERROR,
6859 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6860 __func__, ret, val);
6861 }
6862 return ret;
6863#else /* NL80211_SUPPORT */
6864 sigma_dut_print(dut, DUT_MSG_ERROR,
6865 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
6866 return -1;
6867#endif /* NL80211_SUPPORT */
6868}
6869
6870
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006871#ifdef NL80211_SUPPORT
6872static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
6873{
6874 struct nl_msg *msg;
6875 int ret = 0;
6876 struct nlattr *params;
6877 int ifindex;
6878
6879 ifindex = if_nametoindex(intf);
6880 if (ifindex == 0) {
6881 sigma_dut_print(dut, DUT_MSG_ERROR,
6882 "%s: Index for interface %s failed",
6883 __func__, intf);
6884 return -1;
6885 }
6886
6887 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6888 NL80211_CMD_VENDOR)) ||
6889 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6890 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6891 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6892 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6893 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6894 nla_put_flag(msg,
6895 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
6896 sigma_dut_print(dut, DUT_MSG_ERROR,
6897 "%s: err in adding vendor_cmd and vendor_data",
6898 __func__);
6899 nlmsg_free(msg);
6900 return -1;
6901 }
6902 nla_nest_end(msg, params);
6903
6904 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6905 if (ret) {
6906 sigma_dut_print(dut, DUT_MSG_ERROR,
6907 "%s: err in send_and_recv_msgs, ret=%d",
6908 __func__, ret);
6909 }
6910 return ret;
6911}
6912#endif /* NL80211_SUPPORT */
6913
6914
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006915static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
6916 int val)
6917{
6918#ifdef NL80211_SUPPORT
6919 struct nl_msg *msg;
6920 int ret = 0;
6921 struct nlattr *params;
6922 int ifindex;
6923
6924 ifindex = if_nametoindex(intf);
6925 if (ifindex == 0) {
6926 sigma_dut_print(dut, DUT_MSG_ERROR,
6927 "%s: Index for interface %s failed, val:%d",
6928 __func__, intf, val);
6929 return -1;
6930 }
6931
6932 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6933 NL80211_CMD_VENDOR)) ||
6934 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6935 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6936 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6937 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6938 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6939 nla_put_u8(msg,
6940 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
6941 val)) {
6942 sigma_dut_print(dut, DUT_MSG_ERROR,
6943 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6944 __func__, val);
6945 nlmsg_free(msg);
6946 return -1;
6947 }
6948 nla_nest_end(msg, params);
6949
6950 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6951 if (ret) {
6952 sigma_dut_print(dut, DUT_MSG_ERROR,
6953 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6954 __func__, ret, val);
6955 }
6956 return ret;
6957#else /* NL80211_SUPPORT */
6958 sigma_dut_print(dut, DUT_MSG_ERROR,
6959 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
6960 return -1;
6961#endif /* NL80211_SUPPORT */
6962}
6963
6964
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006965static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
6966 int val)
6967{
6968#ifdef NL80211_SUPPORT
6969 struct nl_msg *msg;
6970 int ret = 0;
6971 struct nlattr *params;
6972 int ifindex;
6973
6974 ifindex = if_nametoindex(intf);
6975 if (ifindex == 0) {
6976 sigma_dut_print(dut, DUT_MSG_ERROR,
6977 "%s: Index for interface %s failed, val:%d",
6978 __func__, intf, val);
6979 return -1;
6980 }
6981
6982 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6983 NL80211_CMD_VENDOR)) ||
6984 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6985 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6986 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6987 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6988 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6989 nla_put_u8(msg,
6990 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
6991 val)) {
6992 sigma_dut_print(dut, DUT_MSG_ERROR,
6993 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6994 __func__, val);
6995 nlmsg_free(msg);
6996 return -1;
6997 }
6998 nla_nest_end(msg, params);
6999
7000 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7001 if (ret) {
7002 sigma_dut_print(dut, DUT_MSG_ERROR,
7003 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7004 __func__, ret, val);
7005 }
7006 return ret;
7007#else /* NL80211_SUPPORT */
7008 sigma_dut_print(dut, DUT_MSG_ERROR,
7009 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7010 return -1;
7011#endif /* NL80211_SUPPORT */
7012}
7013
7014
Arif Hussain480d5f42019-03-12 14:40:42 -07007015static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7016 int val)
7017{
7018#ifdef NL80211_SUPPORT
7019 struct nl_msg *msg;
7020 int ret;
7021 struct nlattr *params;
7022 int ifindex;
7023
7024 ifindex = if_nametoindex(intf);
7025 if (ifindex == 0) {
7026 sigma_dut_print(dut, DUT_MSG_ERROR,
7027 "%s: Index for interface %s failed, val:%d",
7028 __func__, intf, val);
7029 return -1;
7030 }
7031
7032 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7033 NL80211_CMD_VENDOR)) ||
7034 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7035 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7036 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7037 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7038 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7039 nla_put_u8(msg,
7040 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7041 val)) {
7042 sigma_dut_print(dut, DUT_MSG_ERROR,
7043 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7044 __func__, val);
7045 nlmsg_free(msg);
7046 return -1;
7047 }
7048 nla_nest_end(msg, params);
7049
7050 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7051 if (ret) {
7052 sigma_dut_print(dut, DUT_MSG_ERROR,
7053 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7054 __func__, ret, val);
7055 }
7056 return ret;
7057#else /* NL80211_SUPPORT */
7058 sigma_dut_print(dut, DUT_MSG_ERROR,
7059 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7060 return -1;
7061#endif /* NL80211_SUPPORT */
7062}
7063
7064
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007065static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7066 const char *type)
7067{
7068 char buf[60];
7069
7070 if (dut->program == PROGRAM_HE) {
7071 /* resetting phymode to auto in case of HE program */
7072 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7073 if (system(buf) != 0) {
7074 sigma_dut_print(dut, DUT_MSG_ERROR,
7075 "iwpriv %s setphymode failed", intf);
7076 }
7077
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007078 /* reset the rate to Auto rate */
7079 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7080 intf);
7081 if (system(buf) != 0) {
7082 sigma_dut_print(dut, DUT_MSG_ERROR,
7083 "iwpriv %s set_11ax_rate 0xff failed",
7084 intf);
7085 }
7086
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007087 /* reset the LDPC setting */
7088 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7089 if (system(buf) != 0) {
7090 sigma_dut_print(dut, DUT_MSG_ERROR,
7091 "iwpriv %s ldpc 1 failed", intf);
7092 }
7093
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007094 /* reset the power save setting */
7095 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7096 if (system(buf) != 0) {
7097 sigma_dut_print(dut, DUT_MSG_ERROR,
7098 "iwpriv %s setPower 2 failed", intf);
7099 }
7100
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007101 /* remove all network profiles */
7102 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007103
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007104 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7105 sta_set_addba_buf_size(dut, intf, 64);
7106
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007107#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007108 /* Reset the device HE capabilities to its default supported
7109 * configuration. */
7110 sta_set_he_testbed_def(dut, intf, 0);
7111
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007112 /* Disable noackpolicy for all AC */
7113 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7114 sigma_dut_print(dut, DUT_MSG_ERROR,
7115 "Disable of noackpolicy for all AC failed");
7116 }
7117#endif /* NL80211_SUPPORT */
7118
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007119 /* Enable WMM by default */
7120 if (wcn_sta_set_wmm(dut, intf, "on")) {
7121 sigma_dut_print(dut, DUT_MSG_ERROR,
7122 "Enable of WMM in sta_reset_default_wcn failed");
7123 }
7124
7125 /* Disable ADDBA_REJECT by default */
7126 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7127 sigma_dut_print(dut, DUT_MSG_ERROR,
7128 "Disable of addba_reject in sta_reset_default_wcn failed");
7129 }
7130
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007131 /* Enable sending of ADDBA by default */
7132 if (nlvendor_config_send_addba(dut, intf, 1)) {
7133 sigma_dut_print(dut, DUT_MSG_ERROR,
7134 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7135 }
7136
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007137 /* Enable AMPDU by default */
7138 iwpriv_sta_set_ampdu(dut, intf, 1);
7139
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007140#ifdef NL80211_SUPPORT
7141 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
7142 sigma_dut_print(dut, DUT_MSG_ERROR,
7143 "Set LTF config to default in sta_reset_default_wcn failed");
7144 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007145
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007146 /* set the beamformee NSTS(maximum number of
7147 * space-time streams) to default DUT config
7148 */
7149 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007150 sigma_dut_print(dut, DUT_MSG_ERROR,
7151 "Failed to set BeamformeeSTS");
7152 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007153
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007154 if (sta_set_mac_padding_duration(
7155 dut, intf,
7156 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007157 sigma_dut_print(dut, DUT_MSG_ERROR,
7158 "Failed to set MAC padding duration");
7159 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007160
7161 if (sta_set_mu_edca_override(dut, intf, 0)) {
7162 sigma_dut_print(dut, DUT_MSG_ERROR,
7163 "ErrorCode,Failed to set MU EDCA override disable");
7164 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007165
7166 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7167 sigma_dut_print(dut, DUT_MSG_ERROR,
7168 "Failed to set OM ctrl supp");
7169 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007170
7171 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7172 sigma_dut_print(dut, DUT_MSG_ERROR,
7173 "Failed to set Tx SU PPDU enable");
7174 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007175
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007176 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7177 sigma_dut_print(dut, DUT_MSG_ERROR,
7178 "failed to send TB PPDU Tx cfg");
7179 }
7180
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007181 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7182 sigma_dut_print(dut, DUT_MSG_ERROR,
7183 "Failed to set OM ctrl reset");
7184 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007185
7186 /* +HTC-HE support default on */
7187 if (sta_set_he_htc_supp(dut, intf, 1)) {
7188 sigma_dut_print(dut, DUT_MSG_ERROR,
7189 "Setting of +HTC-HE support failed");
7190 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007191#endif /* NL80211_SUPPORT */
7192
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007193 if (sta_set_tx_beamformee(dut, intf, 1)) {
7194 sigma_dut_print(dut, DUT_MSG_ERROR,
7195 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7196 }
7197
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007198 /* Set nss to 1 and MCS 0-7 in case of testbed */
7199 if (type && strcasecmp(type, "Testbed") == 0) {
7200#ifdef NL80211_SUPPORT
7201 int ret;
7202#endif /* NL80211_SUPPORT */
7203
7204 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7205 if (system(buf) != 0) {
7206 sigma_dut_print(dut, DUT_MSG_ERROR,
7207 "iwpriv %s nss failed", intf);
7208 }
7209
7210#ifdef NL80211_SUPPORT
7211 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7212 if (ret) {
7213 sigma_dut_print(dut, DUT_MSG_ERROR,
7214 "Setting of MCS failed, ret:%d",
7215 ret);
7216 }
7217#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007218
7219 /* Disable STBC as default */
7220 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007221
7222 /* Disable AMSDU as default */
7223 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007224
7225#ifdef NL80211_SUPPORT
7226 /* HE fragmentation default off */
7227 if (sta_set_he_fragmentation(dut, intf,
7228 HE_FRAG_DISABLE)) {
7229 sigma_dut_print(dut, DUT_MSG_ERROR,
7230 "Setting of HE fragmentation failed");
7231 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007232
7233 /* set the beamformee NSTS(maximum number of
7234 * space-time streams) to default testbed config
7235 */
7236 if (sta_set_beamformee_sts(dut, intf, 3)) {
7237 sigma_dut_print(dut, DUT_MSG_ERROR,
7238 "Failed to set BeamformeeSTS");
7239 }
7240
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007241 /* +HTC-HE support default off */
7242 if (sta_set_he_htc_supp(dut, intf, 0)) {
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "Setting of +HTC-HE support failed");
7245 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007246
7247 /* Set device HE capabilities to testbed default
7248 * configuration. */
7249 if (sta_set_he_testbed_def(dut, intf, 1)) {
7250 sigma_dut_print(dut, DUT_MSG_DEBUG,
7251 "Failed to set HE defaults");
7252 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007253
7254 /* Disable VHT support in 2.4 GHz for testbed */
7255 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007256#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007257
7258 /* Enable WEP/TKIP with HE capability in testbed */
7259 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7260 sigma_dut_print(dut, DUT_MSG_ERROR,
7261 "Enabling HE config with WEP/TKIP failed");
7262 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007263 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007264
7265 /* Defaults in case of DUT */
7266 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007267 /* Enable STBC by default */
7268 wcn_sta_set_stbc(dut, intf, "1");
7269
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007270 /* set nss to 2 */
7271 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7272 if (system(buf) != 0) {
7273 sigma_dut_print(dut, DUT_MSG_ERROR,
7274 "iwpriv %s nss 2 failed", intf);
7275 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007276 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007277
7278#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007279 /* Set HE_MCS to 0-11 */
7280 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007281 sigma_dut_print(dut, DUT_MSG_ERROR,
7282 "Setting of MCS failed");
7283 }
7284#endif /* NL80211_SUPPORT */
7285
7286 /* Disable WEP/TKIP with HE capability in DUT */
7287 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7288 sigma_dut_print(dut, DUT_MSG_ERROR,
7289 "Enabling HE config with WEP/TKIP failed");
7290 }
7291 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007292 }
7293}
7294
7295
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007296static int cmd_sta_reset_default(struct sigma_dut *dut,
7297 struct sigma_conn *conn,
7298 struct sigma_cmd *cmd)
7299{
7300 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
7301 struct sigma_cmd *cmd);
7302 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007303 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007304 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007305 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307306 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007307
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007308 if (!program)
7309 program = get_param(cmd, "prog");
7310 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007311 dut->device_type = STA_unknown;
7312 type = get_param(cmd, "type");
7313 if (type && strcasecmp(type, "Testbed") == 0)
7314 dut->device_type = STA_testbed;
7315 if (type && strcasecmp(type, "DUT") == 0)
7316 dut->device_type = STA_dut;
7317
7318 if (dut->program == PROGRAM_TDLS) {
7319 /* Clear TDLS testing mode */
7320 wpa_command(intf, "SET tdls_disabled 0");
7321 wpa_command(intf, "SET tdls_testing 0");
7322 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307323 if (get_driver_type() == DRIVER_WCN) {
7324 /* Enable the WCN driver in TDLS Explicit trigger mode
7325 */
7326 wpa_command(intf, "SET tdls_external_control 0");
7327 wpa_command(intf, "SET tdls_trigger_control 0");
7328 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007329 }
7330
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007331#ifdef MIRACAST
7332 if (dut->program == PROGRAM_WFD ||
7333 dut->program == PROGRAM_DISPLAYR2)
7334 miracast_sta_reset_default(dut, conn, cmd);
7335#endif /* MIRACAST */
7336
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007337 switch (get_driver_type()) {
7338 case DRIVER_ATHEROS:
7339 sta_reset_default_ath(dut, intf, type);
7340 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007341 case DRIVER_WCN:
7342 sta_reset_default_wcn(dut, intf, type);
7343 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007344 default:
7345 break;
7346 }
7347
7348#ifdef ANDROID_NAN
7349 if (dut->program == PROGRAM_NAN)
7350 nan_cmd_sta_reset_default(dut, conn, cmd);
7351#endif /* ANDROID_NAN */
7352
Jouni Malinenba630452018-06-22 11:49:59 +03007353 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007354 unlink("SP/wi-fi.org/pps.xml");
7355 if (system("rm -r SP/*") != 0) {
7356 }
7357 unlink("next-client-cert.pem");
7358 unlink("next-client-key.pem");
7359 }
7360
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007361 /* For WPS program of the 60 GHz band the band type needs to be saved */
7362 if (dut->program == PROGRAM_WPS) {
7363 if (band && strcasecmp(band, "60GHz") == 0) {
7364 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007365 /* For 60 GHz enable WPS for WPS TCs */
7366 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007367 } else {
7368 dut->band = WPS_BAND_NON_60G;
7369 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007370 } else if (dut->program == PROGRAM_60GHZ) {
7371 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7372 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007373 }
7374
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007375 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007376 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007377 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007378
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007379 sigma_dut_print(dut, DUT_MSG_INFO,
7380 "WPS 60 GHz program, wps_disable = %d",
7381 dut->wps_disable);
7382
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007383 if (!dev_role) {
7384 send_resp(dut, conn, SIGMA_ERROR,
7385 "errorCode,Missing DevRole argument");
7386 return 0;
7387 }
7388
7389 if (strcasecmp(dev_role, "STA") == 0)
7390 dut->dev_role = DEVROLE_STA;
7391 else if (strcasecmp(dev_role, "PCP") == 0)
7392 dut->dev_role = DEVROLE_PCP;
7393 else {
7394 send_resp(dut, conn, SIGMA_ERROR,
7395 "errorCode,Unknown DevRole");
7396 return 0;
7397 }
7398
7399 if (dut->device_type == STA_unknown) {
7400 sigma_dut_print(dut, DUT_MSG_ERROR,
7401 "Device type is not STA testbed or DUT");
7402 send_resp(dut, conn, SIGMA_ERROR,
7403 "errorCode,Unknown device type");
7404 return 0;
7405 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007406
7407 sigma_dut_print(dut, DUT_MSG_DEBUG,
7408 "Setting msdu_size to MAX: 7912");
7409 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
7410 get_station_ifname());
7411
7412 if (system(buf) != 0) {
7413 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7414 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007415 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007416 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007417
7418 if (sta_set_force_mcs(dut, 0, 1)) {
7419 sigma_dut_print(dut, DUT_MSG_ERROR,
7420 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007421 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007422 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007423 }
7424
7425 wpa_command(intf, "WPS_ER_STOP");
7426 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307427 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007428 wpa_command(intf, "SET radio_disabled 0");
7429
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007430 dut->wps_forced_version = 0;
7431
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007432 if (dut->wsc_fragment) {
7433 dut->wsc_fragment = 0;
7434 wpa_command(intf, "SET device_name Test client");
7435 wpa_command(intf, "SET manufacturer ");
7436 wpa_command(intf, "SET model_name ");
7437 wpa_command(intf, "SET model_number ");
7438 wpa_command(intf, "SET serial_number ");
7439 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007440 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7441 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7442 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7443 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007444
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007445 if (dut->tmp_mac_addr && dut->set_macaddr) {
7446 dut->tmp_mac_addr = 0;
7447 if (system(dut->set_macaddr) != 0) {
7448 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7449 "temporary MAC address");
7450 }
7451 }
7452
7453 set_ps(intf, dut, 0);
7454
Jouni Malinenba630452018-06-22 11:49:59 +03007455 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7456 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007457 wpa_command(intf, "SET interworking 1");
7458 wpa_command(intf, "SET hs20 1");
7459 }
7460
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007461 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007462 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007463 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007464 wpa_command(intf, "SET pmf 1");
7465 } else {
7466 wpa_command(intf, "SET pmf 0");
7467 }
7468
7469 hs2_clear_credentials(intf);
7470 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7471 wpa_command(intf, "SET access_network_type 15");
7472
7473 static_ip_file(0, NULL, NULL, NULL);
7474 kill_dhcp_client(dut, intf);
7475 clear_ip_addr(dut, intf);
7476
7477 dut->er_oper_performed = 0;
7478 dut->er_oper_bssid[0] = '\0';
7479
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007480 if (dut->program == PROGRAM_LOC) {
7481 /* Disable Interworking by default */
7482 wpa_command(get_station_ifname(), "SET interworking 0");
7483 }
7484
Ashwini Patil00402582017-04-13 12:29:39 +05307485 if (dut->program == PROGRAM_MBO) {
7486 free(dut->non_pref_ch_list);
7487 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307488 free(dut->btm_query_cand_list);
7489 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307490 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307491 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307492 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307493 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307494 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307495 }
7496
Jouni Malinen3c367e82017-06-23 17:01:47 +03007497 free(dut->rsne_override);
7498 dut->rsne_override = NULL;
7499
Jouni Malinen68143132017-09-02 02:34:08 +03007500 free(dut->sae_commit_override);
7501 dut->sae_commit_override = NULL;
7502
Jouni Malinend86e5822017-08-29 03:55:32 +03007503 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007504 free(dut->dpp_peer_uri);
7505 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007506 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007507 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007508
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007509 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7510
vamsi krishnaa2799492017-12-05 14:28:01 +05307511 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307512 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307513 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307514 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7515 dut->fils_hlp = 0;
7516#ifdef ANDROID
7517 hlp_thread_cleanup(dut);
7518#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307519 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307520
Jouni Malinen8179fee2019-03-28 03:19:47 +02007521 dut->akm_values = 0;
7522
Sunil Dutt076081f2018-02-05 19:45:50 +05307523#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05307524 if (get_driver_type() == DRIVER_WCN &&
7525 dut->config_rsnie == 1) {
7526 dut->config_rsnie = 0;
7527 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307528 }
7529#endif /* NL80211_SUPPORT */
7530
Sunil Duttfebf8a82018-02-09 18:50:13 +05307531 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7532 dut->dev_role = DEVROLE_STA_CFON;
7533 return sta_cfon_reset_default(dut, conn, cmd);
7534 }
7535
Jouni Malinen439352d2018-09-13 03:42:23 +03007536 wpa_command(intf, "SET setband AUTO");
7537
Sunil Duttfebf8a82018-02-09 18:50:13 +05307538 if (dut->program != PROGRAM_VHT)
7539 return cmd_sta_p2p_reset(dut, conn, cmd);
7540
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007541 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007542}
7543
7544
7545static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
7546 struct sigma_cmd *cmd)
7547{
7548 const char *program = get_param(cmd, "Program");
7549
7550 if (program == NULL)
7551 return -1;
7552#ifdef ANDROID_NAN
7553 if (strcasecmp(program, "NAN") == 0)
7554 return nan_cmd_sta_get_events(dut, conn, cmd);
7555#endif /* ANDROID_NAN */
7556 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7557 return 0;
7558}
7559
7560
Jouni Malinen82905202018-04-29 17:20:10 +03007561static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7562 struct sigma_cmd *cmd)
7563{
7564 const char *url = get_param(cmd, "url");
7565 const char *method = get_param(cmd, "method");
7566 pid_t pid;
7567 int status;
7568
7569 if (!url || !method)
7570 return -1;
7571
7572 /* TODO: Add support for method,post */
7573 if (strcasecmp(method, "get") != 0) {
7574 send_resp(dut, conn, SIGMA_ERROR,
7575 "ErrorCode,Unsupported method");
7576 return 0;
7577 }
7578
7579 pid = fork();
7580 if (pid < 0) {
7581 perror("fork");
7582 return -1;
7583 }
7584
7585 if (pid == 0) {
7586 char * argv[5] = { "wget", "-O", "/dev/null",
7587 (char *) url, NULL };
7588
7589 execv("/usr/bin/wget", argv);
7590 perror("execv");
7591 exit(0);
7592 return -1;
7593 }
7594
7595 if (waitpid(pid, &status, 0) < 0) {
7596 perror("waitpid");
7597 return -1;
7598 }
7599
7600 if (WIFEXITED(status)) {
7601 const char *errmsg;
7602
7603 if (WEXITSTATUS(status) == 0)
7604 return 1;
7605 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7606 WEXITSTATUS(status));
7607 switch (WEXITSTATUS(status)) {
7608 case 4:
7609 errmsg = "errmsg,Network failure";
7610 break;
7611 case 8:
7612 errmsg = "errmsg,Server issued an error response";
7613 break;
7614 default:
7615 errmsg = "errmsg,Unknown failure from wget";
7616 break;
7617 }
7618 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7619 return 0;
7620 }
7621
7622 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7623 return 0;
7624}
7625
7626
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007627static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
7628 struct sigma_cmd *cmd)
7629{
7630 const char *program = get_param(cmd, "Prog");
7631
Jouni Malinen82905202018-04-29 17:20:10 +03007632 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007633 return -1;
7634#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007635 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007636 return nan_cmd_sta_exec_action(dut, conn, cmd);
7637#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007638
7639 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007640 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007641
7642 if (get_param(cmd, "url"))
7643 return sta_exec_action_url(dut, conn, cmd);
7644
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007645 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7646 return 0;
7647}
7648
7649
7650static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
7651 struct sigma_cmd *cmd)
7652{
7653 const char *intf = get_param(cmd, "Interface");
7654 const char *val, *mcs32, *rate;
7655
7656 val = get_param(cmd, "GREENFIELD");
7657 if (val) {
7658 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7659 /* Enable GD */
7660 send_resp(dut, conn, SIGMA_ERROR,
7661 "ErrorCode,GF not supported");
7662 return 0;
7663 }
7664 }
7665
7666 val = get_param(cmd, "SGI20");
7667 if (val) {
7668 switch (get_driver_type()) {
7669 case DRIVER_ATHEROS:
7670 ath_sta_set_sgi(dut, intf, val);
7671 break;
7672 default:
7673 send_resp(dut, conn, SIGMA_ERROR,
7674 "ErrorCode,SGI20 not supported");
7675 return 0;
7676 }
7677 }
7678
7679 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7680 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7681 if (mcs32 && rate) {
7682 /* TODO */
7683 send_resp(dut, conn, SIGMA_ERROR,
7684 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7685 return 0;
7686 } else if (mcs32 && !rate) {
7687 /* TODO */
7688 send_resp(dut, conn, SIGMA_ERROR,
7689 "ErrorCode,MCS32 not supported");
7690 return 0;
7691 } else if (!mcs32 && rate) {
7692 switch (get_driver_type()) {
7693 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08007694 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007695 ath_sta_set_11nrates(dut, intf, rate);
7696 break;
7697 default:
7698 send_resp(dut, conn, SIGMA_ERROR,
7699 "ErrorCode,MCS32_FIXEDRATE not supported");
7700 return 0;
7701 }
7702 }
7703
7704 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7705}
7706
7707
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007708static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
7709 int mcs_config)
7710{
7711#ifdef NL80211_SUPPORT
7712 int ret;
7713
7714 switch (mcs_config) {
7715 case HE_80_MCS0_7:
7716 case HE_80_MCS0_9:
7717 case HE_80_MCS0_11:
7718 ret = sta_set_he_mcs(dut, intf, mcs_config);
7719 if (ret) {
7720 sigma_dut_print(dut, DUT_MSG_ERROR,
7721 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
7722 mcs_config, ret);
7723 }
7724 break;
7725 default:
7726 sigma_dut_print(dut, DUT_MSG_ERROR,
7727 "cmd_set_max_he_mcs: Invalid mcs %d",
7728 mcs_config);
7729 break;
7730 }
7731#else /* NL80211_SUPPORT */
7732 sigma_dut_print(dut, DUT_MSG_ERROR,
7733 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
7734#endif /* NL80211_SUPPORT */
7735}
7736
7737
Arif Hussain480d5f42019-03-12 14:40:42 -07007738static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
7739 struct sigma_cmd *cmd)
7740{
7741#ifdef NL80211_SUPPORT
7742 struct nlattr *params;
7743 struct nlattr *attr;
7744 struct nlattr *attr1;
7745 struct nl_msg *msg;
7746 int ifindex, ret;
7747 const char *val;
7748 const char *intf = get_param(cmd, "Interface");
7749 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
7750 wake_interval_mantissa = 512;
7751 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
7752 protection = 0;
7753
7754 ifindex = if_nametoindex(intf);
7755 if (ifindex == 0) {
7756 sigma_dut_print(dut, DUT_MSG_ERROR,
7757 "%s: Index for interface %s failed",
7758 __func__, intf);
7759 return -1;
7760 }
7761
7762 val = get_param(cmd, "FlowType");
7763 if (val) {
7764 flow_type = atoi(val);
7765 if (flow_type != 0 && flow_type != 1) {
7766 sigma_dut_print(dut, DUT_MSG_ERROR,
7767 "TWT: Invalid FlowType %d", flow_type);
7768 return -1;
7769 }
7770 }
7771
7772 val = get_param(cmd, "TWT_Trigger");
7773 if (val) {
7774 twt_trigger = atoi(val);
7775 if (twt_trigger != 0 && twt_trigger != 1) {
7776 sigma_dut_print(dut, DUT_MSG_ERROR,
7777 "TWT: Invalid TWT_Trigger %d",
7778 twt_trigger);
7779 return -1;
7780 }
7781 }
7782
7783 val = get_param(cmd, "Protection");
7784 if (val) {
7785 protection = atoi(val);
7786 if (protection != 0 && protection != 1) {
7787 sigma_dut_print(dut, DUT_MSG_ERROR,
7788 "TWT: Invalid Protection %d",
7789 protection);
7790 return -1;
7791 }
7792 }
7793
7794 val = get_param(cmd, "TargetWakeTime");
7795 if (val)
7796 target_wake_time = atoi(val);
7797
7798 val = get_param(cmd, "WakeIntervalMantissa");
7799 if (val)
7800 wake_interval_mantissa = atoi(val);
7801
7802 val = get_param(cmd, "WakeIntervalExp");
7803 if (val)
7804 wake_interval_exp = atoi(val);
7805
7806 val = get_param(cmd, "NominalMinWakeDur");
7807 if (val)
7808 nominal_min_wake_dur = atoi(val);
7809
7810 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7811 NL80211_CMD_VENDOR)) ||
7812 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7813 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7814 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7815 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7816 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7817 !(params = nla_nest_start(
7818 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
7819 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7820 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
7821 wake_interval_exp) ||
7822 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST, 0) ||
7823 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
7824 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER,
7825 twt_trigger) ||
7826 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
7827 flow_type) ||
7828 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION,
7829 protection) ||
7830 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
7831 target_wake_time) ||
7832 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
7833 nominal_min_wake_dur) ||
7834 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
7835 wake_interval_mantissa)) {
7836 sigma_dut_print(dut, DUT_MSG_ERROR,
7837 "%s: err in adding vendor_cmd and vendor_data",
7838 __func__);
7839 nlmsg_free(msg);
7840 return -1;
7841 }
7842 nla_nest_end(msg, attr1);
7843 nla_nest_end(msg, params);
7844 nla_nest_end(msg, attr);
7845
7846 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7847 if (ret) {
7848 sigma_dut_print(dut, DUT_MSG_ERROR,
7849 "%s: err in send_and_recv_msgs, ret=%d",
7850 __func__, ret);
7851 }
7852
7853 return ret;
7854#else /* NL80211_SUPPORT */
7855 sigma_dut_print(dut, DUT_MSG_ERROR,
7856 "TWT request cannot be done without NL80211_SUPPORT defined");
7857 return -1;
7858#endif /* NL80211_SUPPORT */
7859}
7860
7861
7862static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
7863 struct sigma_cmd *cmd)
7864{
7865 #ifdef NL80211_SUPPORT
7866 struct nlattr *params;
7867 struct nlattr *attr;
7868 struct nlattr *attr1;
7869 int ifindex, ret;
7870 struct nl_msg *msg;
7871 const char *intf = get_param(cmd, "Interface");
7872
7873 ifindex = if_nametoindex(intf);
7874 if (ifindex == 0) {
7875 sigma_dut_print(dut, DUT_MSG_ERROR,
7876 "%s: Index for interface %s failed",
7877 __func__, intf);
7878 return -1;
7879 }
7880
7881 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7882 NL80211_CMD_VENDOR)) ||
7883 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7884 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7885 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7886 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7887 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7888 !(params = nla_nest_start(
7889 msg,
7890 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
7891 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7892 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
7893 sigma_dut_print(dut, DUT_MSG_ERROR,
7894 "%s: err in adding vendor_cmd and vendor_data",
7895 __func__);
7896 nlmsg_free(msg);
7897 return -1;
7898 }
7899 nla_nest_end(msg, attr1);
7900 nla_nest_end(msg, params);
7901 nla_nest_end(msg, attr);
7902
7903 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7904 if (ret) {
7905 sigma_dut_print(dut, DUT_MSG_ERROR,
7906 "%s: err in send_and_recv_msgs, ret=%d",
7907 __func__, ret);
7908 }
7909
7910 return ret;
7911#else /* NL80211_SUPPORT */
7912 sigma_dut_print(dut, DUT_MSG_ERROR,
7913 "TWT teardown cannot be done without NL80211_SUPPORT defined");
7914 return -1;
7915#endif /* NL80211_SUPPORT */
7916}
7917
7918
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08007919static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
7920 struct sigma_cmd *cmd)
7921{
7922#ifdef NL80211_SUPPORT
7923 struct nlattr *params;
7924 struct nlattr *attr;
7925 struct nlattr *attr1;
7926 struct nl_msg *msg;
7927 int ifindex, ret;
7928 const char *val;
7929 const char *intf = get_param(cmd, "Interface");
7930 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
7931 ulmu_data_dis = 0;
7932
7933 ifindex = if_nametoindex(intf);
7934 if (ifindex == 0) {
7935 sigma_dut_print(dut, DUT_MSG_ERROR,
7936 "%s: Index for interface %s failed",
7937 __func__, intf);
7938 return -1;
7939 }
7940 val = get_param(cmd, "OMCtrl_RxNSS");
7941 if (val)
7942 rx_nss = atoi(val);
7943
7944 val = get_param(cmd, "OMCtrl_ChnlWidth");
7945 if (val)
7946 ch_bw = atoi(val);
7947
7948 val = get_param(cmd, "OMCtrl_ULMUDisable");
7949 if (val)
7950 ulmu_dis = atoi(val);
7951
7952 val = get_param(cmd, "OMCtrl_TxNSTS");
7953 if (val)
7954 tx_nsts = atoi(val);
7955
7956 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
7957 if (val)
7958 ulmu_data_dis = atoi(val);
7959
7960 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7961 NL80211_CMD_VENDOR)) ||
7962 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7963 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7964 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7965 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7966 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7967 !(params = nla_nest_start(
7968 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
7969 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7970 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
7971 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
7972 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
7973 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
7974 ulmu_data_dis) ||
7975 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
7976 ulmu_dis)) {
7977 sigma_dut_print(dut, DUT_MSG_ERROR,
7978 "%s: err in adding vendor_cmd and vendor_data",
7979 __func__);
7980 nlmsg_free(msg);
7981 return -1;
7982 }
7983 nla_nest_end(msg, attr1);
7984 nla_nest_end(msg, params);
7985 nla_nest_end(msg, attr);
7986
7987 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7988 if (ret) {
7989 sigma_dut_print(dut, DUT_MSG_ERROR,
7990 "%s: err in send_and_recv_msgs, ret=%d",
7991 __func__, ret);
7992 }
7993
7994 return ret;
7995#else /* NL80211_SUPPORT */
7996 sigma_dut_print(dut, DUT_MSG_ERROR,
7997 "OMI TX cannot be processed without NL80211_SUPPORT defined");
7998 return -1;
7999#endif /* NL80211_SUPPORT */
8000}
8001
8002
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008003static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8004 struct sigma_conn *conn,
8005 struct sigma_cmd *cmd)
8006{
8007 const char *intf = get_param(cmd, "Interface");
8008 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008009 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008010 int tkip = -1;
8011 int wep = -1;
8012
Arif Hussaina37e9552018-06-20 17:05:59 -07008013 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008014 val = get_param(cmd, "SGI80");
8015 if (val) {
8016 int sgi80;
8017
8018 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008019 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008020 }
8021
8022 val = get_param(cmd, "TxBF");
8023 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008024 switch (get_driver_type()) {
8025 case DRIVER_WCN:
8026 if (sta_set_tx_beamformee(dut, intf, 1)) {
8027 send_resp(dut, conn, SIGMA_ERROR,
8028 "ErrorCode,Failed to set TX beamformee enable");
8029 return 0;
8030 }
8031 break;
8032 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008033 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008034 send_resp(dut, conn, SIGMA_ERROR,
8035 "ErrorCode,Setting vhtsubfee failed");
8036 return 0;
8037 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008038 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008039 send_resp(dut, conn, SIGMA_ERROR,
8040 "ErrorCode,Setting vhtsubfer failed");
8041 return 0;
8042 }
8043 break;
8044 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008045 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008046 "Unsupported driver type");
8047 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008048 }
8049 }
8050
8051 val = get_param(cmd, "MU_TxBF");
8052 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
8053 switch (get_driver_type()) {
8054 case DRIVER_ATHEROS:
8055 ath_sta_set_txsp_stream(dut, intf, "1SS");
8056 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008057 run_iwpriv(dut, intf, "vhtmubfee 1");
8058 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308059 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008060 case DRIVER_WCN:
8061 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8062 send_resp(dut, conn, SIGMA_ERROR,
8063 "ErrorCode,Failed to set RX/TXSP_STREAM");
8064 return 0;
8065 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308066 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008067 default:
8068 sigma_dut_print(dut, DUT_MSG_ERROR,
8069 "Setting SP_STREAM not supported");
8070 break;
8071 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008072 }
8073
8074 val = get_param(cmd, "LDPC");
8075 if (val) {
8076 int ldpc;
8077
8078 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008079 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008080 }
8081
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008082 val = get_param(cmd, "BCC");
8083 if (val) {
8084 int bcc;
8085
8086 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8087 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8088 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008089 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008090 }
8091
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008092 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8093 if (val && dut->sta_nss == 1)
8094 cmd_set_max_he_mcs(dut, intf, atoi(val));
8095
8096 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8097 if (val && dut->sta_nss == 2)
8098 cmd_set_max_he_mcs(dut, intf, atoi(val));
8099
Arif Hussainac6c5112018-05-25 17:34:00 -07008100 val = get_param(cmd, "MCS_FixedRate");
8101 if (val) {
8102#ifdef NL80211_SUPPORT
8103 int mcs, ratecode = 0;
8104 enum he_mcs_config mcs_config;
8105 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008106 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008107
8108 ratecode = (0x07 & dut->sta_nss) << 5;
8109 mcs = atoi(val);
8110 /* Add the MCS to the ratecode */
8111 if (mcs >= 0 && mcs <= 11) {
8112 ratecode += mcs;
8113 if (dut->device_type == STA_testbed &&
8114 mcs > 7 && mcs <= 11) {
8115 if (mcs <= 9)
8116 mcs_config = HE_80_MCS0_9;
8117 else
8118 mcs_config = HE_80_MCS0_11;
8119 ret = sta_set_he_mcs(dut, intf, mcs_config);
8120 if (ret) {
8121 sigma_dut_print(dut, DUT_MSG_ERROR,
8122 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8123 mcs, mcs_config, ret);
8124 }
8125 }
8126 snprintf(buf, sizeof(buf),
8127 "iwpriv %s set_11ax_rate 0x%03x",
8128 intf, ratecode);
8129 if (system(buf) != 0) {
8130 sigma_dut_print(dut, DUT_MSG_ERROR,
8131 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8132 ratecode);
8133 }
8134 } else {
8135 sigma_dut_print(dut, DUT_MSG_ERROR,
8136 "MCS_FixedRate: HE MCS %d not supported",
8137 mcs);
8138 }
8139#else /* NL80211_SUPPORT */
8140 sigma_dut_print(dut, DUT_MSG_ERROR,
8141 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8142#endif /* NL80211_SUPPORT */
8143 }
8144
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008145 val = get_param(cmd, "opt_md_notif_ie");
8146 if (val) {
8147 char *result = NULL;
8148 char delim[] = ";";
8149 char token[30];
8150 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308151 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008152
Peng Xub8fc5cc2017-05-10 17:27:28 -07008153 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308154 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008155
8156 /* Extract the NSS information */
8157 if (result) {
8158 value = atoi(result);
8159 switch (value) {
8160 case 1:
8161 config_val = 1;
8162 break;
8163 case 2:
8164 config_val = 3;
8165 break;
8166 case 3:
8167 config_val = 7;
8168 break;
8169 case 4:
8170 config_val = 15;
8171 break;
8172 default:
8173 config_val = 3;
8174 break;
8175 }
8176
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008177 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8178 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008179
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008180 }
8181
8182 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308183 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008184 if (result) {
8185 value = atoi(result);
8186 switch (value) {
8187 case 20:
8188 config_val = 0;
8189 break;
8190 case 40:
8191 config_val = 1;
8192 break;
8193 case 80:
8194 config_val = 2;
8195 break;
8196 case 160:
8197 config_val = 3;
8198 break;
8199 default:
8200 config_val = 2;
8201 break;
8202 }
8203
8204 dut->chwidth = config_val;
8205
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008206 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008207 }
8208
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008209 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008210 }
8211
8212 val = get_param(cmd, "nss_mcs_cap");
8213 if (val) {
8214 int nss, mcs;
8215 char token[20];
8216 char *result = NULL;
8217 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308218 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008219
Peng Xub8fc5cc2017-05-10 17:27:28 -07008220 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308221 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308222 if (!result) {
8223 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008224 "NSS not specified");
8225 send_resp(dut, conn, SIGMA_ERROR,
8226 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308227 return 0;
8228 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008229 nss = atoi(result);
8230
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008231 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008232 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008233
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308234 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008235 if (result == NULL) {
8236 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008237 "MCS not specified");
8238 send_resp(dut, conn, SIGMA_ERROR,
8239 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008240 return 0;
8241 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308242 result = strtok_r(result, "-", &saveptr);
8243 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308244 if (!result) {
8245 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008246 "MCS not specified");
8247 send_resp(dut, conn, SIGMA_ERROR,
8248 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308249 return 0;
8250 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008251 mcs = atoi(result);
8252
Arif Hussaina37e9552018-06-20 17:05:59 -07008253 if (program && strcasecmp(program, "HE") == 0) {
8254#ifdef NL80211_SUPPORT
8255 enum he_mcs_config mcs_config;
8256 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008257
Arif Hussaina37e9552018-06-20 17:05:59 -07008258 if (mcs >= 0 && mcs <= 7) {
8259 mcs_config = HE_80_MCS0_7;
8260 } else if (mcs > 7 && mcs <= 9) {
8261 mcs_config = HE_80_MCS0_9;
8262 } else if (mcs > 9 && mcs <= 11) {
8263 mcs_config = HE_80_MCS0_11;
8264 } else {
8265 sigma_dut_print(dut, DUT_MSG_ERROR,
8266 "nss_mcs_cap: HE: Invalid mcs: %d",
8267 mcs);
8268 send_resp(dut, conn, SIGMA_ERROR,
8269 "errorCode,Invalid MCS");
8270 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008271 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008272
8273 ret = sta_set_he_mcs(dut, intf, mcs_config);
8274 if (ret) {
8275 sigma_dut_print(dut, DUT_MSG_ERROR,
8276 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8277 mcs_config, ret);
8278 send_resp(dut, conn, SIGMA_ERROR,
8279 "errorCode,Failed to set MCS");
8280 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008281 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008282#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008283 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008284 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8285#endif /* NL80211_SUPPORT */
8286 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008287 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008288
8289 switch (nss) {
8290 case 1:
8291 switch (mcs) {
8292 case 7:
8293 vht_mcsmap = 0xfffc;
8294 break;
8295 case 8:
8296 vht_mcsmap = 0xfffd;
8297 break;
8298 case 9:
8299 vht_mcsmap = 0xfffe;
8300 break;
8301 default:
8302 vht_mcsmap = 0xfffe;
8303 break;
8304 }
8305 break;
8306 case 2:
8307 switch (mcs) {
8308 case 7:
8309 vht_mcsmap = 0xfff0;
8310 break;
8311 case 8:
8312 vht_mcsmap = 0xfff5;
8313 break;
8314 case 9:
8315 vht_mcsmap = 0xfffa;
8316 break;
8317 default:
8318 vht_mcsmap = 0xfffa;
8319 break;
8320 }
8321 break;
8322 case 3:
8323 switch (mcs) {
8324 case 7:
8325 vht_mcsmap = 0xffc0;
8326 break;
8327 case 8:
8328 vht_mcsmap = 0xffd5;
8329 break;
8330 case 9:
8331 vht_mcsmap = 0xffea;
8332 break;
8333 default:
8334 vht_mcsmap = 0xffea;
8335 break;
8336 }
8337 break;
8338 default:
8339 vht_mcsmap = 0xffea;
8340 break;
8341 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008342 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008343 }
8344 }
8345
8346 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8347
8348 val = get_param(cmd, "Vht_tkip");
8349 if (val)
8350 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8351
8352 val = get_param(cmd, "Vht_wep");
8353 if (val)
8354 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8355
8356 if (tkip != -1 || wep != -1) {
8357 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008358 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008359 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008360 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008361 } else {
8362 sigma_dut_print(dut, DUT_MSG_ERROR,
8363 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8364 return 0;
8365 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008366 }
8367
Arif Hussain55f00da2018-07-03 08:28:26 -07008368 val = get_param(cmd, "txBandwidth");
8369 if (val) {
8370 switch (get_driver_type()) {
8371 case DRIVER_WCN:
8372 if (wcn_sta_set_width(dut, intf, val) < 0) {
8373 send_resp(dut, conn, SIGMA_ERROR,
8374 "ErrorCode,Failed to set txBandwidth");
8375 return 0;
8376 }
8377 break;
8378 case DRIVER_ATHEROS:
8379 if (ath_set_width(dut, conn, intf, val) < 0) {
8380 send_resp(dut, conn, SIGMA_ERROR,
8381 "ErrorCode,Failed to set txBandwidth");
8382 return 0;
8383 }
8384 break;
8385 default:
8386 sigma_dut_print(dut, DUT_MSG_ERROR,
8387 "Setting txBandwidth not supported");
8388 break;
8389 }
8390 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008391
Arif Hussain9765f7d2018-07-03 08:28:26 -07008392 val = get_param(cmd, "BeamformeeSTS");
8393 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008394 if (sta_set_tx_beamformee(dut, intf, 1)) {
8395 send_resp(dut, conn, SIGMA_ERROR,
8396 "ErrorCode,Failed to set TX beamformee enable");
8397 return 0;
8398 }
8399
Arif Hussain9765f7d2018-07-03 08:28:26 -07008400 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8401 send_resp(dut, conn, SIGMA_ERROR,
8402 "ErrorCode,Failed to set BeamformeeSTS");
8403 return 0;
8404 }
8405 }
8406
Arif Hussain68d23f52018-07-11 13:39:08 -07008407 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8408 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008409#ifdef NL80211_SUPPORT
8410 enum qca_wlan_he_mac_padding_dur set_val;
8411
8412 switch (atoi(val)) {
8413 case 16:
8414 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8415 break;
8416 case 8:
8417 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8418 break;
8419 default:
8420 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8421 break;
8422 }
8423 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008424 send_resp(dut, conn, SIGMA_ERROR,
8425 "ErrorCode,Failed to set MAC padding duration");
8426 return 0;
8427 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008428#else /* NL80211_SUPPORT */
8429 sigma_dut_print(dut, DUT_MSG_ERROR,
8430 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8431#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008432 }
8433
Arif Hussain480d5f42019-03-12 14:40:42 -07008434 val = get_param(cmd, "TWT_ReqSupport");
8435 if (val) {
8436 int set_val;
8437
8438 if (strcasecmp(val, "Enable") == 0) {
8439 set_val = 1;
8440 } else if (strcasecmp(val, "Disable") == 0) {
8441 set_val = 0;
8442 } else {
8443 send_resp(dut, conn, SIGMA_ERROR,
8444 "ErrorCode,Invalid TWT_ReqSupport");
8445 return STATUS_SENT;
8446 }
8447
8448 if (sta_set_twt_req_support(dut, intf, set_val)) {
8449 sigma_dut_print(dut, DUT_MSG_ERROR,
8450 "Failed to set TWT req support %d",
8451 set_val);
8452 send_resp(dut, conn, SIGMA_ERROR,
8453 "ErrorCode,Failed to set TWT_ReqSupport");
8454 return STATUS_SENT;
8455 }
8456 }
8457
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008458 val = get_param(cmd, "MU_EDCA");
8459 if (val && (strcasecmp(val, "Override") == 0)) {
8460 if (sta_set_mu_edca_override(dut, intf, 1)) {
8461 send_resp(dut, conn, SIGMA_ERROR,
8462 "ErrorCode,Failed to set MU EDCA override");
8463 return 0;
8464 }
8465 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008466
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008467 val = get_param(cmd, "OMControl");
8468 if (val) {
8469 int set_val = 1;
8470
8471 if (strcasecmp(val, "Enable") == 0)
8472 set_val = 1;
8473 else if (strcasecmp(val, "Disable") == 0)
8474 set_val = 0;
8475
8476 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8477 send_resp(dut, conn, SIGMA_ERROR,
8478 "ErrorCode,Failed to set OM ctrl supp");
8479 return 0;
8480 }
8481 }
8482
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008483 val = get_param(cmd, "ADDBAResp_BufSize");
8484 if (val) {
8485 int buf_size;
8486
8487 if (strcasecmp(val, "gt64") == 0)
8488 buf_size = 256;
8489 else
8490 buf_size = 64;
8491 if (get_driver_type() == DRIVER_WCN &&
8492 sta_set_addba_buf_size(dut, intf, buf_size)) {
8493 send_resp(dut, conn, SIGMA_ERROR,
8494 "ErrorCode,set addbaresp_buff_size failed");
8495 return 0;
8496 }
8497 }
8498
8499 val = get_param(cmd, "ADDBAReq_BufSize");
8500 if (val) {
8501 int buf_size;
8502
8503 if (strcasecmp(val, "gt64") == 0)
8504 buf_size = 256;
8505 else
8506 buf_size = 64;
8507 if (get_driver_type() == DRIVER_WCN &&
8508 sta_set_addba_buf_size(dut, intf, buf_size)) {
8509 send_resp(dut, conn, SIGMA_ERROR,
8510 "ErrorCode,set addbareq_buff_size failed");
8511 return 0;
8512 }
8513 }
8514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008515 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8516}
8517
8518
8519static int sta_set_wireless_60g(struct sigma_dut *dut,
8520 struct sigma_conn *conn,
8521 struct sigma_cmd *cmd)
8522{
8523 const char *dev_role = get_param(cmd, "DevRole");
8524
8525 if (!dev_role) {
8526 send_resp(dut, conn, SIGMA_INVALID,
8527 "ErrorCode,DevRole not specified");
8528 return 0;
8529 }
8530
8531 if (strcasecmp(dev_role, "PCP") == 0)
8532 return sta_set_60g_pcp(dut, conn, cmd);
8533 if (strcasecmp(dev_role, "STA") == 0)
8534 return sta_set_60g_sta(dut, conn, cmd);
8535 send_resp(dut, conn, SIGMA_INVALID,
8536 "ErrorCode,DevRole not supported");
8537 return 0;
8538}
8539
8540
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308541static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8542 struct sigma_cmd *cmd)
8543{
8544 int status;
8545 const char *intf = get_param(cmd, "Interface");
8546 const char *val = get_param(cmd, "DevRole");
8547
8548 if (val && strcasecmp(val, "STA-CFON") == 0) {
8549 status = sta_cfon_set_wireless(dut, conn, cmd);
8550 if (status)
8551 return status;
8552 }
8553 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8554}
8555
8556
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008557static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
8558 struct sigma_cmd *cmd)
8559{
8560 const char *val;
8561
8562 val = get_param(cmd, "Program");
8563 if (val) {
8564 if (strcasecmp(val, "11n") == 0)
8565 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008566 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008567 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8568 if (strcasecmp(val, "60ghz") == 0)
8569 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308570 if (strcasecmp(val, "OCE") == 0)
8571 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008572 /* sta_set_wireless in WPS program is only used for 60G */
8573 if (is_60g_sigma_dut(dut))
8574 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008575 send_resp(dut, conn, SIGMA_ERROR,
8576 "ErrorCode,Program value not supported");
8577 } else {
8578 send_resp(dut, conn, SIGMA_ERROR,
8579 "ErrorCode,Program argument not available");
8580 }
8581
8582 return 0;
8583}
8584
8585
8586static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8587 int tid)
8588{
8589 char buf[100];
8590 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8591
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308592 if (tid < 0 ||
8593 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8594 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8595 return;
8596 }
8597
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008598 /*
8599 * Two ways to ensure that addba request with a
8600 * non zero TID could be sent out. EV 117296
8601 */
8602 snprintf(buf, sizeof(buf),
8603 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8604 tid);
8605 if (system(buf) != 0) {
8606 sigma_dut_print(dut, DUT_MSG_ERROR,
8607 "Ping did not send out");
8608 }
8609
8610 snprintf(buf, sizeof(buf),
8611 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8612 intf, VI_QOS_TMP_FILE);
8613 if (system(buf) != 0)
8614 return;
8615
8616 snprintf(buf, sizeof(buf),
8617 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8618 intf, VI_QOS_TMP_FILE);
8619 if (system(buf) != 0)
8620 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8621
8622 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8623 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8624 if (system(buf) != 0) {
8625 sigma_dut_print(dut, DUT_MSG_ERROR,
8626 "VI_QOS_TEMP_FILE generation error failed");
8627 }
8628 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8629 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8630 if (system(buf) != 0) {
8631 sigma_dut_print(dut, DUT_MSG_ERROR,
8632 "VI_QOS_FILE generation failed");
8633 }
8634
8635 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8636 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8637 if (system(buf) != 0) {
8638 sigma_dut_print(dut, DUT_MSG_ERROR,
8639 "VI_QOS_FILE generation failed");
8640 }
8641
8642 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8643 if (system(buf) != 0) {
8644 }
8645}
8646
8647
8648static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8649 struct sigma_cmd *cmd)
8650{
8651 const char *intf = get_param(cmd, "Interface");
8652 const char *val;
8653 int tid = 0;
8654 char buf[100];
8655
8656 val = get_param(cmd, "TID");
8657 if (val) {
8658 tid = atoi(val);
8659 if (tid)
8660 ath_sta_inject_frame(dut, intf, tid);
8661 }
8662
8663 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008664 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008665
8666 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8667 if (system(buf) != 0) {
8668 sigma_dut_print(dut, DUT_MSG_ERROR,
8669 "wifitool senddelba failed");
8670 }
8671
8672 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8673 if (system(buf) != 0) {
8674 sigma_dut_print(dut, DUT_MSG_ERROR,
8675 "wifitool sendaddba failed");
8676 }
8677
8678 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8679
8680 return 1;
8681}
8682
8683
Lior David9981b512017-01-20 13:16:40 +02008684#ifdef __linux__
8685
8686static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
8687 int agg_size)
8688{
8689 char dir[128], buf[128];
8690 FILE *f;
8691 regex_t re;
8692 regmatch_t m[2];
8693 int rc, ret = -1, vring_id, found;
8694
8695 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
8696 sigma_dut_print(dut, DUT_MSG_ERROR,
8697 "failed to get wil6210 debugfs dir");
8698 return -1;
8699 }
8700
8701 snprintf(buf, sizeof(buf), "%s/vrings", dir);
8702 f = fopen(buf, "r");
8703 if (!f) {
8704 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008705 /* newer wil6210 driver renamed file to "rings" */
8706 snprintf(buf, sizeof(buf), "%s/rings", dir);
8707 f = fopen(buf, "r");
8708 if (!f) {
8709 sigma_dut_print(dut, DUT_MSG_ERROR,
8710 "failed to open: %s", buf);
8711 return -1;
8712 }
Lior David9981b512017-01-20 13:16:40 +02008713 }
8714
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008715 /* can be either VRING tx... or RING... */
8716 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02008717 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
8718 goto out;
8719 }
8720
8721 /* find TX VRING for the mac address */
8722 found = 0;
8723 while (fgets(buf, sizeof(buf), f)) {
8724 if (strcasestr(buf, dest_mac)) {
8725 found = 1;
8726 break;
8727 }
8728 }
8729
8730 if (!found) {
8731 sigma_dut_print(dut, DUT_MSG_ERROR,
8732 "no TX VRING for %s", dest_mac);
8733 goto out;
8734 }
8735
8736 /* extract VRING ID, "VRING tx_<id> = {" */
8737 if (!fgets(buf, sizeof(buf), f)) {
8738 sigma_dut_print(dut, DUT_MSG_ERROR,
8739 "no VRING start line for %s", dest_mac);
8740 goto out;
8741 }
8742
8743 rc = regexec(&re, buf, 2, m, 0);
8744 regfree(&re);
8745 if (rc || m[1].rm_so < 0) {
8746 sigma_dut_print(dut, DUT_MSG_ERROR,
8747 "no VRING TX ID for %s", dest_mac);
8748 goto out;
8749 }
8750 buf[m[1].rm_eo] = 0;
8751 vring_id = atoi(&buf[m[1].rm_so]);
8752
8753 /* send the addba command */
8754 fclose(f);
8755 snprintf(buf, sizeof(buf), "%s/back", dir);
8756 f = fopen(buf, "w");
8757 if (!f) {
8758 sigma_dut_print(dut, DUT_MSG_ERROR,
8759 "failed to open: %s", buf);
8760 return -1;
8761 }
8762
8763 fprintf(f, "add %d %d\n", vring_id, agg_size);
8764
8765 ret = 0;
8766
8767out:
8768 fclose(f);
8769
8770 return ret;
8771}
8772
8773
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008774int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8775 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008776{
8777 const char *val;
8778 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008779
8780 val = get_param(cmd, "TID");
8781 if (val) {
8782 tid = atoi(val);
8783 if (tid != 0) {
8784 sigma_dut_print(dut, DUT_MSG_ERROR,
8785 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
8786 tid);
8787 }
8788 }
8789
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008790 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008791 if (!val) {
8792 sigma_dut_print(dut, DUT_MSG_ERROR,
8793 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008794 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008795 }
8796
Lior David9981b512017-01-20 13:16:40 +02008797 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008799
8800 return 1;
8801}
8802
Lior David9981b512017-01-20 13:16:40 +02008803#endif /* __linux__ */
8804
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008805
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008806static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8807 struct sigma_cmd *cmd)
8808{
8809#ifdef NL80211_SUPPORT
8810 const char *intf = get_param(cmd, "Interface");
8811 const char *val;
8812 int tid = -1;
8813 int bufsize = 64;
8814 struct nl_msg *msg;
8815 int ret = 0;
8816 struct nlattr *params;
8817 int ifindex;
8818
8819 val = get_param(cmd, "TID");
8820 if (val)
8821 tid = atoi(val);
8822
8823 if (tid == -1) {
8824 send_resp(dut, conn, SIGMA_ERROR,
8825 "ErrorCode,sta_send_addba tid invalid");
8826 return 0;
8827 }
8828
8829 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8830
8831 ifindex = if_nametoindex(intf);
8832 if (ifindex == 0) {
8833 sigma_dut_print(dut, DUT_MSG_ERROR,
8834 "%s: Index for interface %s failed",
8835 __func__, intf);
8836 send_resp(dut, conn, SIGMA_ERROR,
8837 "ErrorCode,sta_send_addba interface invalid");
8838 return 0;
8839 }
8840
8841 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8842 NL80211_CMD_VENDOR)) ||
8843 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8844 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8845 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8846 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8847 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8848 nla_put_u8(msg,
8849 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
8850 QCA_WLAN_ADD_BA) ||
8851 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
8852 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07008853 nla_put_u16(msg,
8854 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
8855 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008856 sigma_dut_print(dut, DUT_MSG_ERROR,
8857 "%s: err in adding vendor_cmd and vendor_data",
8858 __func__);
8859 nlmsg_free(msg);
8860 send_resp(dut, conn, SIGMA_ERROR,
8861 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
8862 return 0;
8863 }
8864 nla_nest_end(msg, params);
8865
8866 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8867 if (ret) {
8868 sigma_dut_print(dut, DUT_MSG_ERROR,
8869 "%s: err in send_and_recv_msgs, ret=%d",
8870 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05308871 if (ret == -EOPNOTSUPP)
8872 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008873 send_resp(dut, conn, SIGMA_ERROR,
8874 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
8875 return 0;
8876 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008877#else /* NL80211_SUPPORT */
8878 sigma_dut_print(dut, DUT_MSG_ERROR,
8879 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008880#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05308881
8882 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008883}
8884
8885
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008886static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8887 struct sigma_cmd *cmd)
8888{
8889 switch (get_driver_type()) {
8890 case DRIVER_ATHEROS:
8891 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008892 case DRIVER_WCN:
8893 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02008894#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008895 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008896 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02008897#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008898 default:
8899 /*
8900 * There is no driver specific implementation for other drivers.
8901 * Ignore the command and report COMPLETE since the following
8902 * throughput test operation will end up sending ADDBA anyway.
8903 */
8904 return 1;
8905 }
8906}
8907
8908
8909int inject_eth_frame(int s, const void *data, size_t len,
8910 unsigned short ethtype, char *dst, char *src)
8911{
8912 struct iovec iov[4] = {
8913 {
8914 .iov_base = dst,
8915 .iov_len = ETH_ALEN,
8916 },
8917 {
8918 .iov_base = src,
8919 .iov_len = ETH_ALEN,
8920 },
8921 {
8922 .iov_base = &ethtype,
8923 .iov_len = sizeof(unsigned short),
8924 },
8925 {
8926 .iov_base = (void *) data,
8927 .iov_len = len,
8928 }
8929 };
8930 struct msghdr msg = {
8931 .msg_name = NULL,
8932 .msg_namelen = 0,
8933 .msg_iov = iov,
8934 .msg_iovlen = 4,
8935 .msg_control = NULL,
8936 .msg_controllen = 0,
8937 .msg_flags = 0,
8938 };
8939
8940 return sendmsg(s, &msg, 0);
8941}
8942
8943#if defined(__linux__) || defined(__QNXNTO__)
8944
8945int inject_frame(int s, const void *data, size_t len, int encrypt)
8946{
8947#define IEEE80211_RADIOTAP_F_WEP 0x04
8948#define IEEE80211_RADIOTAP_F_FRAG 0x08
8949 unsigned char rtap_hdr[] = {
8950 0x00, 0x00, /* radiotap version */
8951 0x0e, 0x00, /* radiotap length */
8952 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
8953 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
8954 0x00, /* padding */
8955 0x00, 0x00, /* RX and TX flags to indicate that */
8956 0x00, 0x00, /* this is the injected frame directly */
8957 };
8958 struct iovec iov[2] = {
8959 {
8960 .iov_base = &rtap_hdr,
8961 .iov_len = sizeof(rtap_hdr),
8962 },
8963 {
8964 .iov_base = (void *) data,
8965 .iov_len = len,
8966 }
8967 };
8968 struct msghdr msg = {
8969 .msg_name = NULL,
8970 .msg_namelen = 0,
8971 .msg_iov = iov,
8972 .msg_iovlen = 2,
8973 .msg_control = NULL,
8974 .msg_controllen = 0,
8975 .msg_flags = 0,
8976 };
8977
8978 if (encrypt)
8979 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
8980
8981 return sendmsg(s, &msg, 0);
8982}
8983
8984
8985int open_monitor(const char *ifname)
8986{
8987#ifdef __QNXNTO__
8988 struct sockaddr_dl ll;
8989 int s;
8990
8991 memset(&ll, 0, sizeof(ll));
8992 ll.sdl_family = AF_LINK;
8993 ll.sdl_index = if_nametoindex(ifname);
8994 if (ll.sdl_index == 0) {
8995 perror("if_nametoindex");
8996 return -1;
8997 }
8998 s = socket(PF_INET, SOCK_RAW, 0);
8999#else /* __QNXNTO__ */
9000 struct sockaddr_ll ll;
9001 int s;
9002
9003 memset(&ll, 0, sizeof(ll));
9004 ll.sll_family = AF_PACKET;
9005 ll.sll_ifindex = if_nametoindex(ifname);
9006 if (ll.sll_ifindex == 0) {
9007 perror("if_nametoindex");
9008 return -1;
9009 }
9010 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9011#endif /* __QNXNTO__ */
9012 if (s < 0) {
9013 perror("socket[PF_PACKET,SOCK_RAW]");
9014 return -1;
9015 }
9016
9017 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9018 perror("monitor socket bind");
9019 close(s);
9020 return -1;
9021 }
9022
9023 return s;
9024}
9025
9026
9027static int hex2num(char c)
9028{
9029 if (c >= '0' && c <= '9')
9030 return c - '0';
9031 if (c >= 'a' && c <= 'f')
9032 return c - 'a' + 10;
9033 if (c >= 'A' && c <= 'F')
9034 return c - 'A' + 10;
9035 return -1;
9036}
9037
9038
9039int hwaddr_aton(const char *txt, unsigned char *addr)
9040{
9041 int i;
9042
9043 for (i = 0; i < 6; i++) {
9044 int a, b;
9045
9046 a = hex2num(*txt++);
9047 if (a < 0)
9048 return -1;
9049 b = hex2num(*txt++);
9050 if (b < 0)
9051 return -1;
9052 *addr++ = (a << 4) | b;
9053 if (i < 5 && *txt++ != ':')
9054 return -1;
9055 }
9056
9057 return 0;
9058}
9059
9060#endif /* defined(__linux__) || defined(__QNXNTO__) */
9061
9062enum send_frame_type {
9063 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9064};
9065enum send_frame_protection {
9066 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9067};
9068
9069
9070static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9071 enum send_frame_type frame,
9072 enum send_frame_protection protected,
9073 const char *dest)
9074{
9075#ifdef __linux__
9076 unsigned char buf[1000], *pos;
9077 int s, res;
9078 char bssid[20], addr[20];
9079 char result[32], ssid[100];
9080 size_t ssid_len;
9081
9082 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
9083 sizeof(result)) < 0 ||
9084 strncmp(result, "COMPLETED", 9) != 0) {
9085 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9086 return 0;
9087 }
9088
9089 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
9090 < 0) {
9091 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9092 "current BSSID");
9093 return 0;
9094 }
9095
9096 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
9097 < 0) {
9098 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9099 "own MAC address");
9100 return 0;
9101 }
9102
9103 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
9104 < 0) {
9105 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9106 "current SSID");
9107 return 0;
9108 }
9109 ssid_len = strlen(ssid);
9110
9111 pos = buf;
9112
9113 /* Frame Control */
9114 switch (frame) {
9115 case DISASSOC:
9116 *pos++ = 0xa0;
9117 break;
9118 case DEAUTH:
9119 *pos++ = 0xc0;
9120 break;
9121 case SAQUERY:
9122 *pos++ = 0xd0;
9123 break;
9124 case AUTH:
9125 *pos++ = 0xb0;
9126 break;
9127 case ASSOCREQ:
9128 *pos++ = 0x00;
9129 break;
9130 case REASSOCREQ:
9131 *pos++ = 0x20;
9132 break;
9133 case DLS_REQ:
9134 *pos++ = 0xd0;
9135 break;
9136 }
9137
9138 if (protected == INCORRECT_KEY)
9139 *pos++ = 0x40; /* Set Protected field to 1 */
9140 else
9141 *pos++ = 0x00;
9142
9143 /* Duration */
9144 *pos++ = 0x00;
9145 *pos++ = 0x00;
9146
9147 /* addr1 = DA (current AP) */
9148 hwaddr_aton(bssid, pos);
9149 pos += 6;
9150 /* addr2 = SA (own address) */
9151 hwaddr_aton(addr, pos);
9152 pos += 6;
9153 /* addr3 = BSSID (current AP) */
9154 hwaddr_aton(bssid, pos);
9155 pos += 6;
9156
9157 /* Seq# (to be filled by driver/mac80211) */
9158 *pos++ = 0x00;
9159 *pos++ = 0x00;
9160
9161 if (protected == INCORRECT_KEY) {
9162 /* CCMP parameters */
9163 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9164 pos += 8;
9165 }
9166
9167 if (protected == INCORRECT_KEY) {
9168 switch (frame) {
9169 case DEAUTH:
9170 /* Reason code (encrypted) */
9171 memcpy(pos, "\xa7\x39", 2);
9172 pos += 2;
9173 break;
9174 case DISASSOC:
9175 /* Reason code (encrypted) */
9176 memcpy(pos, "\xa7\x39", 2);
9177 pos += 2;
9178 break;
9179 case SAQUERY:
9180 /* Category|Action|TransID (encrypted) */
9181 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9182 pos += 4;
9183 break;
9184 default:
9185 return -1;
9186 }
9187
9188 /* CCMP MIC */
9189 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9190 pos += 8;
9191 } else {
9192 switch (frame) {
9193 case DEAUTH:
9194 /* reason code = 8 */
9195 *pos++ = 0x08;
9196 *pos++ = 0x00;
9197 break;
9198 case DISASSOC:
9199 /* reason code = 8 */
9200 *pos++ = 0x08;
9201 *pos++ = 0x00;
9202 break;
9203 case SAQUERY:
9204 /* Category - SA Query */
9205 *pos++ = 0x08;
9206 /* SA query Action - Request */
9207 *pos++ = 0x00;
9208 /* Transaction ID */
9209 *pos++ = 0x12;
9210 *pos++ = 0x34;
9211 break;
9212 case AUTH:
9213 /* Auth Alg (Open) */
9214 *pos++ = 0x00;
9215 *pos++ = 0x00;
9216 /* Seq# */
9217 *pos++ = 0x01;
9218 *pos++ = 0x00;
9219 /* Status code */
9220 *pos++ = 0x00;
9221 *pos++ = 0x00;
9222 break;
9223 case ASSOCREQ:
9224 /* Capability Information */
9225 *pos++ = 0x31;
9226 *pos++ = 0x04;
9227 /* Listen Interval */
9228 *pos++ = 0x0a;
9229 *pos++ = 0x00;
9230 /* SSID */
9231 *pos++ = 0x00;
9232 *pos++ = ssid_len;
9233 memcpy(pos, ssid, ssid_len);
9234 pos += ssid_len;
9235 /* Supported Rates */
9236 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9237 10);
9238 pos += 10;
9239 /* Extended Supported Rates */
9240 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9241 pos += 6;
9242 /* RSN */
9243 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9244 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9245 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9246 pos += 28;
9247 break;
9248 case REASSOCREQ:
9249 /* Capability Information */
9250 *pos++ = 0x31;
9251 *pos++ = 0x04;
9252 /* Listen Interval */
9253 *pos++ = 0x0a;
9254 *pos++ = 0x00;
9255 /* Current AP */
9256 hwaddr_aton(bssid, pos);
9257 pos += 6;
9258 /* SSID */
9259 *pos++ = 0x00;
9260 *pos++ = ssid_len;
9261 memcpy(pos, ssid, ssid_len);
9262 pos += ssid_len;
9263 /* Supported Rates */
9264 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9265 10);
9266 pos += 10;
9267 /* Extended Supported Rates */
9268 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9269 pos += 6;
9270 /* RSN */
9271 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9272 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9273 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9274 pos += 28;
9275 break;
9276 case DLS_REQ:
9277 /* Category - DLS */
9278 *pos++ = 0x02;
9279 /* DLS Action - Request */
9280 *pos++ = 0x00;
9281 /* Destination MACAddress */
9282 if (dest)
9283 hwaddr_aton(dest, pos);
9284 else
9285 memset(pos, 0, 6);
9286 pos += 6;
9287 /* Source MACAddress */
9288 hwaddr_aton(addr, pos);
9289 pos += 6;
9290 /* Capability Information */
9291 *pos++ = 0x10; /* Privacy */
9292 *pos++ = 0x06; /* QoS */
9293 /* DLS Timeout Value */
9294 *pos++ = 0x00;
9295 *pos++ = 0x01;
9296 /* Supported rates */
9297 *pos++ = 0x01;
9298 *pos++ = 0x08;
9299 *pos++ = 0x0c; /* 6 Mbps */
9300 *pos++ = 0x12; /* 9 Mbps */
9301 *pos++ = 0x18; /* 12 Mbps */
9302 *pos++ = 0x24; /* 18 Mbps */
9303 *pos++ = 0x30; /* 24 Mbps */
9304 *pos++ = 0x48; /* 36 Mbps */
9305 *pos++ = 0x60; /* 48 Mbps */
9306 *pos++ = 0x6c; /* 54 Mbps */
9307 /* TODO: Extended Supported Rates */
9308 /* TODO: HT Capabilities */
9309 break;
9310 }
9311 }
9312
9313 s = open_monitor("sigmadut");
9314 if (s < 0) {
9315 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9316 "monitor socket");
9317 return 0;
9318 }
9319
9320 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9321 if (res < 0) {
9322 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9323 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309324 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009325 return 0;
9326 }
9327 if (res < pos - buf) {
9328 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9329 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309330 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009331 return 0;
9332 }
9333
9334 close(s);
9335
9336 return 1;
9337#else /* __linux__ */
9338 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9339 "yet supported");
9340 return 0;
9341#endif /* __linux__ */
9342}
9343
9344
9345static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9346 struct sigma_conn *conn,
9347 struct sigma_cmd *cmd)
9348{
9349 const char *intf = get_param(cmd, "Interface");
9350 const char *sta, *val;
9351 unsigned char addr[ETH_ALEN];
9352 char buf[100];
9353
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009354 if (!intf)
9355 return -1;
9356
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009357 sta = get_param(cmd, "peer");
9358 if (sta == NULL)
9359 sta = get_param(cmd, "station");
9360 if (sta == NULL) {
9361 send_resp(dut, conn, SIGMA_ERROR,
9362 "ErrorCode,Missing peer address");
9363 return 0;
9364 }
9365 if (hwaddr_aton(sta, addr) < 0) {
9366 send_resp(dut, conn, SIGMA_ERROR,
9367 "ErrorCode,Invalid peer address");
9368 return 0;
9369 }
9370
9371 val = get_param(cmd, "type");
9372 if (val == NULL)
9373 return -1;
9374
9375 if (strcasecmp(val, "DISCOVERY") == 0) {
9376 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9377 if (wpa_command(intf, buf) < 0) {
9378 send_resp(dut, conn, SIGMA_ERROR,
9379 "ErrorCode,Failed to send TDLS discovery");
9380 return 0;
9381 }
9382 return 1;
9383 }
9384
9385 if (strcasecmp(val, "SETUP") == 0) {
9386 int status = 0, timeout = 0;
9387
9388 val = get_param(cmd, "Status");
9389 if (val)
9390 status = atoi(val);
9391
9392 val = get_param(cmd, "Timeout");
9393 if (val)
9394 timeout = atoi(val);
9395
9396 if (status != 0 && status != 37) {
9397 send_resp(dut, conn, SIGMA_ERROR,
9398 "ErrorCode,Unsupported status value");
9399 return 0;
9400 }
9401
9402 if (timeout != 0 && timeout != 301) {
9403 send_resp(dut, conn, SIGMA_ERROR,
9404 "ErrorCode,Unsupported timeout value");
9405 return 0;
9406 }
9407
9408 if (status && timeout) {
9409 send_resp(dut, conn, SIGMA_ERROR,
9410 "ErrorCode,Unsupported timeout+status "
9411 "combination");
9412 return 0;
9413 }
9414
9415 if (status == 37 &&
9416 wpa_command(intf, "SET tdls_testing 0x200")) {
9417 send_resp(dut, conn, SIGMA_ERROR,
9418 "ErrorCode,Failed to enable "
9419 "decline setup response test mode");
9420 return 0;
9421 }
9422
9423 if (timeout == 301) {
9424 int res;
9425 if (dut->no_tpk_expiration)
9426 res = wpa_command(intf,
9427 "SET tdls_testing 0x108");
9428 else
9429 res = wpa_command(intf,
9430 "SET tdls_testing 0x8");
9431 if (res) {
9432 send_resp(dut, conn, SIGMA_ERROR,
9433 "ErrorCode,Failed to set short TPK "
9434 "lifetime");
9435 return 0;
9436 }
9437 }
9438
9439 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9440 if (wpa_command(intf, buf) < 0) {
9441 send_resp(dut, conn, SIGMA_ERROR,
9442 "ErrorCode,Failed to send TDLS setup");
9443 return 0;
9444 }
9445 return 1;
9446 }
9447
9448 if (strcasecmp(val, "TEARDOWN") == 0) {
9449 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9450 if (wpa_command(intf, buf) < 0) {
9451 send_resp(dut, conn, SIGMA_ERROR,
9452 "ErrorCode,Failed to send TDLS teardown");
9453 return 0;
9454 }
9455 return 1;
9456 }
9457
9458 send_resp(dut, conn, SIGMA_ERROR,
9459 "ErrorCode,Unsupported TDLS frame");
9460 return 0;
9461}
9462
9463
9464static int sta_ap_known(const char *ifname, const char *bssid)
9465{
9466 char buf[4096];
9467
Jouni Malinendd32f192018-09-15 02:55:19 +03009468 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009469 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9470 return 0;
9471 if (strncmp(buf, "id=", 3) != 0)
9472 return 0;
9473 return 1;
9474}
9475
9476
9477static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9478 const char *bssid)
9479{
9480 int res;
9481 struct wpa_ctrl *ctrl;
9482 char buf[256];
9483
9484 if (sta_ap_known(ifname, bssid))
9485 return 0;
9486 sigma_dut_print(dut, DUT_MSG_DEBUG,
9487 "AP not in BSS table - start scan");
9488
9489 ctrl = open_wpa_mon(ifname);
9490 if (ctrl == NULL) {
9491 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9492 "wpa_supplicant monitor connection");
9493 return -1;
9494 }
9495
9496 if (wpa_command(ifname, "SCAN") < 0) {
9497 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9498 wpa_ctrl_detach(ctrl);
9499 wpa_ctrl_close(ctrl);
9500 return -1;
9501 }
9502
9503 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9504 buf, sizeof(buf));
9505
9506 wpa_ctrl_detach(ctrl);
9507 wpa_ctrl_close(ctrl);
9508
9509 if (res < 0) {
9510 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9511 return -1;
9512 }
9513
9514 if (sta_ap_known(ifname, bssid))
9515 return 0;
9516 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9517 return -1;
9518}
9519
9520
9521static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9522 struct sigma_conn *conn,
9523 struct sigma_cmd *cmd,
9524 const char *intf)
9525{
9526 char buf[200];
9527
9528 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9529 if (system(buf) != 0) {
9530 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9531 "ndsend");
9532 return 0;
9533 }
9534
9535 return 1;
9536}
9537
9538
9539static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9540 struct sigma_conn *conn,
9541 struct sigma_cmd *cmd,
9542 const char *intf)
9543{
9544 char buf[200];
9545 const char *ip = get_param(cmd, "SenderIP");
9546
Peng Xu26b356d2017-10-04 17:58:16 -07009547 if (!ip)
9548 return 0;
9549
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009550 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9551 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9552 if (system(buf) == 0) {
9553 sigma_dut_print(dut, DUT_MSG_INFO,
9554 "Neighbor Solicitation got a response "
9555 "for %s@%s", ip, intf);
9556 }
9557
9558 return 1;
9559}
9560
9561
9562static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9563 struct sigma_conn *conn,
9564 struct sigma_cmd *cmd,
9565 const char *ifname)
9566{
9567 char buf[200];
9568 const char *ip = get_param(cmd, "SenderIP");
9569
9570 if (ip == NULL) {
9571 send_resp(dut, conn, SIGMA_ERROR,
9572 "ErrorCode,Missing SenderIP parameter");
9573 return 0;
9574 }
9575 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9576 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9577 if (system(buf) != 0) {
9578 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9579 "for %s@%s", ip, ifname);
9580 }
9581
9582 return 1;
9583}
9584
9585
9586static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9587 struct sigma_conn *conn,
9588 struct sigma_cmd *cmd,
9589 const char *ifname)
9590{
9591 char buf[200];
9592 char ip[16];
9593 int s;
Peng Xub3756882017-10-04 14:39:09 -07009594 struct ifreq ifr;
9595 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009596
9597 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009598 if (s < 0) {
9599 perror("socket");
9600 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009601 }
9602
Peng Xub3756882017-10-04 14:39:09 -07009603 memset(&ifr, 0, sizeof(ifr));
9604 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9605 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9606 sigma_dut_print(dut, DUT_MSG_INFO,
9607 "Failed to get %s IP address: %s",
9608 ifname, strerror(errno));
9609 close(s);
9610 return -1;
9611 }
9612 close(s);
9613
9614 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9615 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9616
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009617 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9618 ip);
9619 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9620 if (system(buf) != 0) {
9621 }
9622
9623 return 1;
9624}
9625
9626
9627static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9628 struct sigma_conn *conn,
9629 struct sigma_cmd *cmd,
9630 const char *ifname)
9631{
9632 char buf[200], addr[20];
9633 char dst[ETH_ALEN], src[ETH_ALEN];
9634 short ethtype = htons(ETH_P_ARP);
9635 char *pos;
9636 int s, res;
9637 const char *val;
9638 struct sockaddr_in taddr;
9639
9640 val = get_param(cmd, "dest");
9641 if (val)
9642 hwaddr_aton(val, (unsigned char *) dst);
9643
9644 val = get_param(cmd, "DestIP");
9645 if (val)
9646 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009647 else
9648 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009649
9650 if (get_wpa_status(get_station_ifname(), "address", addr,
9651 sizeof(addr)) < 0)
9652 return -2;
9653 hwaddr_aton(addr, (unsigned char *) src);
9654
9655 pos = buf;
9656 *pos++ = 0x00;
9657 *pos++ = 0x01;
9658 *pos++ = 0x08;
9659 *pos++ = 0x00;
9660 *pos++ = 0x06;
9661 *pos++ = 0x04;
9662 *pos++ = 0x00;
9663 *pos++ = 0x02;
9664 memcpy(pos, src, ETH_ALEN);
9665 pos += ETH_ALEN;
9666 memcpy(pos, &taddr.sin_addr, 4);
9667 pos += 4;
9668 memcpy(pos, dst, ETH_ALEN);
9669 pos += ETH_ALEN;
9670 memcpy(pos, &taddr.sin_addr, 4);
9671 pos += 4;
9672
9673 s = open_monitor(get_station_ifname());
9674 if (s < 0) {
9675 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9676 "monitor socket");
9677 return 0;
9678 }
9679
9680 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
9681 if (res < 0) {
9682 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9683 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309684 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009685 return 0;
9686 }
9687
9688 close(s);
9689
9690 return 1;
9691}
9692
9693
9694static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
9695 struct sigma_conn *conn,
9696 struct sigma_cmd *cmd,
9697 const char *intf, const char *dest)
9698{
9699 char buf[100];
9700
9701 if (if_nametoindex("sigmadut") == 0) {
9702 snprintf(buf, sizeof(buf),
9703 "iw dev %s interface add sigmadut type monitor",
9704 get_station_ifname());
9705 if (system(buf) != 0 ||
9706 if_nametoindex("sigmadut") == 0) {
9707 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9708 "monitor interface with '%s'", buf);
9709 return -2;
9710 }
9711 }
9712
9713 if (system("ifconfig sigmadut up") != 0) {
9714 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9715 "monitor interface up");
9716 return -2;
9717 }
9718
9719 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
9720}
9721
9722
9723static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
9724 struct sigma_conn *conn,
9725 struct sigma_cmd *cmd)
9726{
9727 const char *intf = get_param(cmd, "Interface");
9728 const char *dest = get_param(cmd, "Dest");
9729 const char *type = get_param(cmd, "FrameName");
9730 const char *val;
9731 char buf[200], *pos, *end;
9732 int count, count2;
9733
9734 if (type == NULL)
9735 type = get_param(cmd, "Type");
9736
9737 if (intf == NULL || dest == NULL || type == NULL)
9738 return -1;
9739
9740 if (strcasecmp(type, "NeighAdv") == 0)
9741 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
9742
9743 if (strcasecmp(type, "NeighSolicitReq") == 0)
9744 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
9745
9746 if (strcasecmp(type, "ARPProbe") == 0)
9747 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
9748
9749 if (strcasecmp(type, "ARPAnnounce") == 0)
9750 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
9751
9752 if (strcasecmp(type, "ARPReply") == 0)
9753 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
9754
9755 if (strcasecmp(type, "DLS-request") == 0 ||
9756 strcasecmp(type, "DLSrequest") == 0)
9757 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
9758 dest);
9759
9760 if (strcasecmp(type, "ANQPQuery") != 0 &&
9761 strcasecmp(type, "Query") != 0) {
9762 send_resp(dut, conn, SIGMA_ERROR,
9763 "ErrorCode,Unsupported HS 2.0 send frame type");
9764 return 0;
9765 }
9766
9767 if (sta_scan_ap(dut, intf, dest) < 0) {
9768 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
9769 "the requested AP");
9770 return 0;
9771 }
9772
9773 pos = buf;
9774 end = buf + sizeof(buf);
9775 count = 0;
9776 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
9777
9778 val = get_param(cmd, "ANQP_CAP_LIST");
9779 if (val && atoi(val)) {
9780 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
9781 count++;
9782 }
9783
9784 val = get_param(cmd, "VENUE_NAME");
9785 if (val && atoi(val)) {
9786 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
9787 count++;
9788 }
9789
9790 val = get_param(cmd, "NETWORK_AUTH_TYPE");
9791 if (val && atoi(val)) {
9792 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
9793 count++;
9794 }
9795
9796 val = get_param(cmd, "ROAMING_CONS");
9797 if (val && atoi(val)) {
9798 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
9799 count++;
9800 }
9801
9802 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
9803 if (val && atoi(val)) {
9804 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
9805 count++;
9806 }
9807
9808 val = get_param(cmd, "NAI_REALM_LIST");
9809 if (val && atoi(val)) {
9810 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
9811 count++;
9812 }
9813
9814 val = get_param(cmd, "3GPP_INFO");
9815 if (val && atoi(val)) {
9816 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
9817 count++;
9818 }
9819
9820 val = get_param(cmd, "DOMAIN_LIST");
9821 if (val && atoi(val)) {
9822 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
9823 count++;
9824 }
9825
Jouni Malinen34cf9532018-04-29 19:26:33 +03009826 val = get_param(cmd, "Venue_URL");
9827 if (val && atoi(val)) {
9828 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
9829 count++;
9830 }
9831
Jouni Malinend3bca5d2018-04-29 17:25:23 +03009832 val = get_param(cmd, "Advice_Of_Charge");
9833 if (val && atoi(val)) {
9834 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
9835 count++;
9836 }
9837
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009838 if (count && wpa_command(intf, buf)) {
9839 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
9840 return 0;
9841 }
9842
9843 pos = buf;
9844 end = buf + sizeof(buf);
9845 count2 = 0;
9846 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
9847
9848 val = get_param(cmd, "HS_CAP_LIST");
9849 if (val && atoi(val)) {
9850 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
9851 count2++;
9852 }
9853
9854 val = get_param(cmd, "OPER_NAME");
9855 if (val && atoi(val)) {
9856 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
9857 count2++;
9858 }
9859
9860 val = get_param(cmd, "WAN_METRICS");
9861 if (!val)
9862 val = get_param(cmd, "WAN_MAT");
9863 if (!val)
9864 val = get_param(cmd, "WAN_MET");
9865 if (val && atoi(val)) {
9866 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
9867 count2++;
9868 }
9869
9870 val = get_param(cmd, "CONNECTION_CAPABILITY");
9871 if (val && atoi(val)) {
9872 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
9873 count2++;
9874 }
9875
9876 val = get_param(cmd, "OP_CLASS");
9877 if (val && atoi(val)) {
9878 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
9879 count2++;
9880 }
9881
9882 val = get_param(cmd, "OSU_PROVIDER_LIST");
9883 if (val && atoi(val)) {
9884 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
9885 count2++;
9886 }
9887
Jouni Malinenf67afec2018-04-29 19:24:58 +03009888 val = get_param(cmd, "OPER_ICON_METADATA");
9889 if (!val)
9890 val = get_param(cmd, "OPERATOR_ICON_METADATA");
9891 if (val && atoi(val)) {
9892 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
9893 count2++;
9894 }
9895
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009896 if (count && count2) {
9897 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
9898 "second query");
9899 sleep(1);
9900 }
9901
9902 if (count2 && wpa_command(intf, buf)) {
9903 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
9904 "failed");
9905 return 0;
9906 }
9907
9908 val = get_param(cmd, "NAI_HOME_REALM_LIST");
9909 if (val) {
9910 if (count || count2) {
9911 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9912 "sending out second query");
9913 sleep(1);
9914 }
9915
9916 if (strcmp(val, "1") == 0)
9917 val = "mail.example.com";
9918 snprintf(buf, end - pos,
9919 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
9920 dest, val);
9921 if (wpa_command(intf, buf)) {
9922 send_resp(dut, conn, SIGMA_ERROR,
9923 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
9924 "failed");
9925 return 0;
9926 }
9927 }
9928
9929 val = get_param(cmd, "ICON_REQUEST");
9930 if (val) {
9931 if (count || count2) {
9932 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9933 "sending out second query");
9934 sleep(1);
9935 }
9936
9937 snprintf(buf, end - pos,
9938 "HS20_ICON_REQUEST %s %s", dest, val);
9939 if (wpa_command(intf, buf)) {
9940 send_resp(dut, conn, SIGMA_ERROR,
9941 "ErrorCode,HS20_ICON_REQUEST failed");
9942 return 0;
9943 }
9944 }
9945
9946 return 1;
9947}
9948
9949
9950static int ath_sta_send_frame_vht(struct sigma_dut *dut,
9951 struct sigma_conn *conn,
9952 struct sigma_cmd *cmd)
9953{
9954 const char *val;
9955 char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009956 int chwidth, nss;
9957
9958 val = get_param(cmd, "framename");
9959 if (!val)
9960 return -1;
9961 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9962
9963 /* Command sequence to generate Op mode notification */
9964 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
9965 ifname = get_station_ifname();
9966
9967 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009968 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009969
9970 /* Extract Channel width */
9971 val = get_param(cmd, "Channel_width");
9972 if (val) {
9973 switch (atoi(val)) {
9974 case 20:
9975 chwidth = 0;
9976 break;
9977 case 40:
9978 chwidth = 1;
9979 break;
9980 case 80:
9981 chwidth = 2;
9982 break;
9983 case 160:
9984 chwidth = 3;
9985 break;
9986 default:
9987 chwidth = 2;
9988 break;
9989 }
9990
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009991 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009992 }
9993
9994 /* Extract NSS */
9995 val = get_param(cmd, "NSS");
9996 if (val) {
9997 switch (atoi(val)) {
9998 case 1:
9999 nss = 1;
10000 break;
10001 case 2:
10002 nss = 3;
10003 break;
10004 case 3:
10005 nss = 7;
10006 break;
10007 default:
10008 /* We do not support NSS > 3 */
10009 nss = 3;
10010 break;
10011 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010012 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010013 }
10014
10015 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010016 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010017 }
10018
10019 return 1;
10020}
10021
10022
10023static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10024 struct sigma_conn *conn,
10025 struct sigma_cmd *cmd)
10026{
10027 switch (get_driver_type()) {
10028 case DRIVER_ATHEROS:
10029 return ath_sta_send_frame_vht(dut, conn, cmd);
10030 default:
10031 send_resp(dut, conn, SIGMA_ERROR,
10032 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10033 return 0;
10034 }
10035}
10036
10037
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010038static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10039 struct sigma_cmd *cmd)
10040{
10041 const char *val;
10042 const char *intf = get_param(cmd, "Interface");
10043
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010044 if (!intf)
10045 return -1;
10046
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010047 val = get_param(cmd, "framename");
10048 if (!val)
10049 return -1;
10050 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10051
10052 /* Command sequence to generate Op mode notification */
10053 if (val && strcasecmp(val, "action") == 0) {
10054 val = get_param(cmd, "PPDUTxType");
10055 if (val && strcasecmp(val, "TB") == 0) {
10056 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10057 sigma_dut_print(dut, DUT_MSG_ERROR,
10058 "failed to send TB PPDU Tx cfg");
10059 send_resp(dut, conn, SIGMA_ERROR,
10060 "ErrorCode,set TB PPDU Tx cfg failed");
10061 return 0;
10062 }
10063 return 1;
10064 }
10065
10066 sigma_dut_print(dut, DUT_MSG_ERROR,
10067 "Action Tx type is not defined");
10068 }
10069
10070 return 1;
10071}
10072
10073
10074static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10075 struct sigma_conn *conn,
10076 struct sigma_cmd *cmd)
10077{
10078 switch (get_driver_type()) {
10079 case DRIVER_WCN:
10080 return wcn_sta_send_frame_he(dut, conn, cmd);
10081 default:
10082 send_resp(dut, conn, SIGMA_ERROR,
10083 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10084 return 0;
10085 }
10086}
10087
10088
Lior David0fe101e2017-03-09 16:09:50 +020010089#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010090
10091static int
10092wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10093 const char *frame_name, const char *dest_mac)
10094{
10095 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10096 const char *ssid = get_param(cmd, "ssid");
10097 const char *countstr = get_param(cmd, "count");
10098 const char *channelstr = get_param(cmd, "channel");
10099 const char *group_id = get_param(cmd, "groupid");
10100 const char *client_id = get_param(cmd, "clientmac");
10101 int count, channel, freq, i;
10102 const char *fname;
10103 char frame[1024], src_mac[20], group_id_attr[25],
10104 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10105 const char *group_ssid;
10106 const int group_ssid_prefix_len = 9;
10107 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10108 size_t framelen = sizeof(frame);
10109 struct template_frame_tag tags[2];
10110 size_t tags_total = ARRAY_SIZE(tags);
10111 int tag_index, len, dst_len;
10112
10113 if (!countstr || !channelstr) {
10114 sigma_dut_print(dut, DUT_MSG_ERROR,
10115 "Missing argument: count, channel");
10116 return -1;
10117 }
10118 if (isprobereq && !ssid) {
10119 sigma_dut_print(dut, DUT_MSG_ERROR,
10120 "Missing argument: ssid");
10121 return -1;
10122 }
10123 if (!isprobereq && (!group_id || !client_id)) {
10124 sigma_dut_print(dut, DUT_MSG_ERROR,
10125 "Missing argument: group_id, client_id");
10126 return -1;
10127 }
10128
10129 count = atoi(countstr);
10130 channel = atoi(channelstr);
10131 freq = channel_to_freq(dut, channel);
10132
10133 if (!freq) {
10134 sigma_dut_print(dut, DUT_MSG_ERROR,
10135 "invalid channel: %s", channelstr);
10136 return -1;
10137 }
10138
10139 if (isprobereq) {
10140 if (strcasecmp(ssid, "wildcard") == 0) {
10141 fname = "probe_req_wildcard.txt";
10142 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10143 fname = "probe_req_P2P_Wildcard.txt";
10144 } else {
10145 sigma_dut_print(dut, DUT_MSG_ERROR,
10146 "invalid probe request type");
10147 return -1;
10148 }
10149 } else {
10150 fname = "P2P_device_discovery_req.txt";
10151 }
10152
10153 if (parse_template_frame_file(dut, fname, frame, &framelen,
10154 tags, &tags_total)) {
10155 sigma_dut_print(dut, DUT_MSG_ERROR,
10156 "invalid frame template: %s", fname);
10157 return -1;
10158 }
10159
10160 if (get_wpa_status(get_station_ifname(), "address",
10161 src_mac, sizeof(src_mac)) < 0 ||
10162 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10163 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10164 return -1;
10165 /* Use wildcard BSSID, since we are in PBSS */
10166 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10167
10168 if (!isprobereq) {
10169 tag_index = find_template_frame_tag(tags, tags_total, 1);
10170 if (tag_index < 0) {
10171 sigma_dut_print(dut, DUT_MSG_ERROR,
10172 "can't find device id attribute");
10173 return -1;
10174 }
10175 if (parse_mac_address(dut, client_id,
10176 (unsigned char *) client_mac)) {
10177 sigma_dut_print(dut, DUT_MSG_ERROR,
10178 "invalid client_id: %s", client_id);
10179 return -1;
10180 }
10181 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10182 framelen - tags[tag_index].offset,
10183 IEEE80211_P2P_ATTR_DEVICE_ID,
10184 client_mac, ETH_ALEN)) {
10185 sigma_dut_print(dut, DUT_MSG_ERROR,
10186 "fail to replace device id attribute");
10187 return -1;
10188 }
10189
10190 /*
10191 * group_id arg contains device MAC address followed by
10192 * space and SSID (DIRECT-somessid).
10193 * group id attribute contains device address (6 bytes)
10194 * followed by SSID prefix DIRECT-XX (9 bytes)
10195 */
10196 if (strlen(group_id) < sizeof(device_macstr)) {
10197 sigma_dut_print(dut, DUT_MSG_ERROR,
10198 "group_id arg too short");
10199 return -1;
10200 }
10201 memcpy(device_macstr, group_id, sizeof(device_macstr));
10202 device_macstr[sizeof(device_macstr) - 1] = '\0';
10203 if (parse_mac_address(dut, device_macstr,
10204 (unsigned char *) group_id_attr)) {
10205 sigma_dut_print(dut, DUT_MSG_ERROR,
10206 "fail to parse device address from group_id");
10207 return -1;
10208 }
10209 group_ssid = strchr(group_id, ' ');
10210 if (!group_ssid) {
10211 sigma_dut_print(dut, DUT_MSG_ERROR,
10212 "invalid group_id arg, no ssid");
10213 return -1;
10214 }
10215 group_ssid++;
10216 len = strlen(group_ssid);
10217 if (len < group_ssid_prefix_len) {
10218 sigma_dut_print(dut, DUT_MSG_ERROR,
10219 "group_id SSID too short");
10220 return -1;
10221 }
10222 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10223 if (len > dst_len) {
10224 sigma_dut_print(dut, DUT_MSG_ERROR,
10225 "group_id SSID (%s) too long",
10226 group_ssid);
10227 return -1;
10228 }
10229
10230 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10231 tag_index = find_template_frame_tag(tags, tags_total, 2);
10232 if (tag_index < 0) {
10233 sigma_dut_print(dut, DUT_MSG_ERROR,
10234 "can't find group id attribute");
10235 return -1;
10236 }
10237 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10238 framelen - tags[tag_index].offset,
10239 IEEE80211_P2P_ATTR_GROUP_ID,
10240 group_id_attr,
10241 sizeof(group_id_attr))) {
10242 sigma_dut_print(dut, DUT_MSG_ERROR,
10243 "fail to replace group id attribute");
10244 return -1;
10245 }
10246 }
10247
10248 for (i = 0; i < count; i++) {
10249 if (wil6210_transmit_frame(dut, freq,
10250 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10251 frame, framelen)) {
10252 sigma_dut_print(dut, DUT_MSG_ERROR,
10253 "fail to transmit probe request frame");
10254 return -1;
10255 }
10256 }
10257
10258 return 0;
10259}
10260
10261
Lior David0fe101e2017-03-09 16:09:50 +020010262int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10263 struct sigma_cmd *cmd)
10264{
10265 const char *frame_name = get_param(cmd, "framename");
10266 const char *mac = get_param(cmd, "dest_mac");
10267
10268 if (!frame_name || !mac) {
10269 sigma_dut_print(dut, DUT_MSG_ERROR,
10270 "framename and dest_mac must be provided");
10271 return -1;
10272 }
10273
10274 if (strcasecmp(frame_name, "brp") == 0) {
10275 const char *l_rx = get_param(cmd, "L-RX");
10276 int l_rx_i;
10277
10278 if (!l_rx) {
10279 sigma_dut_print(dut, DUT_MSG_ERROR,
10280 "L-RX must be provided");
10281 return -1;
10282 }
10283 l_rx_i = atoi(l_rx);
10284
10285 sigma_dut_print(dut, DUT_MSG_INFO,
10286 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10287 mac, l_rx);
10288 if (l_rx_i != 16) {
10289 sigma_dut_print(dut, DUT_MSG_ERROR,
10290 "unsupported L-RX: %s", l_rx);
10291 return -1;
10292 }
10293
10294 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10295 return -1;
10296 } else if (strcasecmp(frame_name, "ssw") == 0) {
10297 sigma_dut_print(dut, DUT_MSG_INFO,
10298 "dev_send_frame: SLS, dest_mac %s", mac);
10299 if (wil6210_send_sls(dut, mac))
10300 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010301 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10302 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10303 sigma_dut_print(dut, DUT_MSG_INFO,
10304 "dev_send_frame: %s, dest_mac %s", frame_name,
10305 mac);
10306 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10307 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010308 } else {
10309 sigma_dut_print(dut, DUT_MSG_ERROR,
10310 "unsupported frame type: %s", frame_name);
10311 return -1;
10312 }
10313
10314 return 1;
10315}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010316
Lior David0fe101e2017-03-09 16:09:50 +020010317#endif /* __linux__ */
10318
10319
10320static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10321 struct sigma_conn *conn,
10322 struct sigma_cmd *cmd)
10323{
10324 switch (get_driver_type()) {
10325#ifdef __linux__
10326 case DRIVER_WIL6210:
10327 return wil6210_send_frame_60g(dut, conn, cmd);
10328#endif /* __linux__ */
10329 default:
10330 send_resp(dut, conn, SIGMA_ERROR,
10331 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10332 return 0;
10333 }
10334}
10335
10336
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010337static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10338 const char *intf, struct sigma_cmd *cmd)
10339{
10340 const char *val, *addr;
10341 char buf[100];
10342
10343 addr = get_param(cmd, "DestMac");
10344 if (!addr) {
10345 send_resp(dut, conn, SIGMA_INVALID,
10346 "ErrorCode,AP MAC address is missing");
10347 return 0;
10348 }
10349
10350 val = get_param(cmd, "ANQPQuery_ID");
10351 if (!val) {
10352 send_resp(dut, conn, SIGMA_INVALID,
10353 "ErrorCode,Missing ANQPQuery_ID");
10354 return 0;
10355 }
10356
10357 if (strcasecmp(val, "NeighborReportReq") == 0) {
10358 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10359 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10360 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10361 } else {
10362 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10363 val);
10364 send_resp(dut, conn, SIGMA_INVALID,
10365 "ErrorCode,Invalid ANQPQuery_ID");
10366 return 0;
10367 }
10368
Ashwini Patild174f2c2017-04-13 16:49:46 +053010369 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10370 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10371 * if associated, AP BSSID).
10372 */
10373 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10374 send_resp(dut, conn, SIGMA_ERROR,
10375 "ErrorCode,Failed to set gas_address3");
10376 return 0;
10377 }
10378
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010379 if (wpa_command(intf, buf) < 0) {
10380 send_resp(dut, conn, SIGMA_ERROR,
10381 "ErrorCode,Failed to send ANQP query");
10382 return 0;
10383 }
10384
10385 return 1;
10386}
10387
10388
10389static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10390 struct sigma_conn *conn,
10391 const char *intf,
10392 struct sigma_cmd *cmd)
10393{
10394 const char *val = get_param(cmd, "FrameName");
10395
10396 if (val && strcasecmp(val, "ANQPQuery") == 0)
10397 return mbo_send_anqp_query(dut, conn, intf, cmd);
10398
10399 return 2;
10400}
10401
10402
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010403int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
10404 struct sigma_cmd *cmd)
10405{
10406 const char *intf = get_param(cmd, "Interface");
10407 const char *val;
10408 enum send_frame_type frame;
10409 enum send_frame_protection protected;
10410 char buf[100];
10411 unsigned char addr[ETH_ALEN];
10412 int res;
10413
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010414 if (!intf)
10415 return -1;
10416
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010417 val = get_param(cmd, "program");
10418 if (val == NULL)
10419 val = get_param(cmd, "frame");
10420 if (val && strcasecmp(val, "TDLS") == 0)
10421 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10422 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010423 strcasecmp(val, "HS2-R2") == 0 ||
10424 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010425 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10426 if (val && strcasecmp(val, "VHT") == 0)
10427 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010428 if (val && strcasecmp(val, "HE") == 0)
10429 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010430 if (val && strcasecmp(val, "LOC") == 0)
10431 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010432 if (val && strcasecmp(val, "60GHz") == 0)
10433 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010434 if (val && strcasecmp(val, "MBO") == 0) {
10435 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10436 if (res != 2)
10437 return res;
10438 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010439
10440 val = get_param(cmd, "TD_DISC");
10441 if (val) {
10442 if (hwaddr_aton(val, addr) < 0)
10443 return -1;
10444 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10445 if (wpa_command(intf, buf) < 0) {
10446 send_resp(dut, conn, SIGMA_ERROR,
10447 "ErrorCode,Failed to send TDLS discovery");
10448 return 0;
10449 }
10450 return 1;
10451 }
10452
10453 val = get_param(cmd, "TD_Setup");
10454 if (val) {
10455 if (hwaddr_aton(val, addr) < 0)
10456 return -1;
10457 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10458 if (wpa_command(intf, buf) < 0) {
10459 send_resp(dut, conn, SIGMA_ERROR,
10460 "ErrorCode,Failed to start TDLS setup");
10461 return 0;
10462 }
10463 return 1;
10464 }
10465
10466 val = get_param(cmd, "TD_TearDown");
10467 if (val) {
10468 if (hwaddr_aton(val, addr) < 0)
10469 return -1;
10470 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10471 if (wpa_command(intf, buf) < 0) {
10472 send_resp(dut, conn, SIGMA_ERROR,
10473 "ErrorCode,Failed to tear down TDLS link");
10474 return 0;
10475 }
10476 return 1;
10477 }
10478
10479 val = get_param(cmd, "TD_ChannelSwitch");
10480 if (val) {
10481 /* TODO */
10482 send_resp(dut, conn, SIGMA_ERROR,
10483 "ErrorCode,TD_ChannelSwitch not yet supported");
10484 return 0;
10485 }
10486
10487 val = get_param(cmd, "TD_NF");
10488 if (val) {
10489 /* TODO */
10490 send_resp(dut, conn, SIGMA_ERROR,
10491 "ErrorCode,TD_NF not yet supported");
10492 return 0;
10493 }
10494
10495 val = get_param(cmd, "PMFFrameType");
10496 if (val == NULL)
10497 val = get_param(cmd, "FrameName");
10498 if (val == NULL)
10499 val = get_param(cmd, "Type");
10500 if (val == NULL)
10501 return -1;
10502 if (strcasecmp(val, "disassoc") == 0)
10503 frame = DISASSOC;
10504 else if (strcasecmp(val, "deauth") == 0)
10505 frame = DEAUTH;
10506 else if (strcasecmp(val, "saquery") == 0)
10507 frame = SAQUERY;
10508 else if (strcasecmp(val, "auth") == 0)
10509 frame = AUTH;
10510 else if (strcasecmp(val, "assocreq") == 0)
10511 frame = ASSOCREQ;
10512 else if (strcasecmp(val, "reassocreq") == 0)
10513 frame = REASSOCREQ;
10514 else if (strcasecmp(val, "neigreq") == 0) {
10515 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10516
10517 val = get_param(cmd, "ssid");
10518 if (val == NULL)
10519 return -1;
10520
10521 res = send_neighbor_request(dut, intf, val);
10522 if (res) {
10523 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10524 "Failed to send neighbor report request");
10525 return 0;
10526 }
10527
10528 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010529 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10530 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010531 sigma_dut_print(dut, DUT_MSG_DEBUG,
10532 "Got Transition Management Query");
10533
Ashwini Patil5acd7382017-04-13 15:55:04 +053010534 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010535 if (res) {
10536 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10537 "Failed to send Transition Management Query");
10538 return 0;
10539 }
10540
10541 return 1;
10542 } else {
10543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10544 "PMFFrameType");
10545 return 0;
10546 }
10547
10548 val = get_param(cmd, "PMFProtected");
10549 if (val == NULL)
10550 val = get_param(cmd, "Protected");
10551 if (val == NULL)
10552 return -1;
10553 if (strcasecmp(val, "Correct-key") == 0 ||
10554 strcasecmp(val, "CorrectKey") == 0)
10555 protected = CORRECT_KEY;
10556 else if (strcasecmp(val, "IncorrectKey") == 0)
10557 protected = INCORRECT_KEY;
10558 else if (strcasecmp(val, "Unprotected") == 0)
10559 protected = UNPROTECTED;
10560 else {
10561 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10562 "PMFProtected");
10563 return 0;
10564 }
10565
10566 if (protected != UNPROTECTED &&
10567 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10568 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10569 "PMFProtected for auth/assocreq/reassocreq");
10570 return 0;
10571 }
10572
10573 if (if_nametoindex("sigmadut") == 0) {
10574 snprintf(buf, sizeof(buf),
10575 "iw dev %s interface add sigmadut type monitor",
10576 get_station_ifname());
10577 if (system(buf) != 0 ||
10578 if_nametoindex("sigmadut") == 0) {
10579 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10580 "monitor interface with '%s'", buf);
10581 return -2;
10582 }
10583 }
10584
10585 if (system("ifconfig sigmadut up") != 0) {
10586 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10587 "monitor interface up");
10588 return -2;
10589 }
10590
10591 return sta_inject_frame(dut, conn, frame, protected, NULL);
10592}
10593
10594
10595static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10596 struct sigma_conn *conn,
10597 struct sigma_cmd *cmd,
10598 const char *ifname)
10599{
10600 char buf[200];
10601 const char *val;
10602
10603 val = get_param(cmd, "ClearARP");
10604 if (val && atoi(val) == 1) {
10605 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10606 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10607 if (system(buf) != 0) {
10608 send_resp(dut, conn, SIGMA_ERROR,
10609 "errorCode,Failed to clear ARP cache");
10610 return 0;
10611 }
10612 }
10613
10614 return 1;
10615}
10616
10617
10618int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10619 struct sigma_cmd *cmd)
10620{
10621 const char *intf = get_param(cmd, "Interface");
10622 const char *val;
10623
10624 if (intf == NULL)
10625 return -1;
10626
10627 val = get_param(cmd, "program");
10628 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010629 strcasecmp(val, "HS2-R2") == 0 ||
10630 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010631 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10632
10633 return -1;
10634}
10635
10636
10637static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
10638 struct sigma_cmd *cmd)
10639{
10640 const char *intf = get_param(cmd, "Interface");
10641 const char *mac = get_param(cmd, "MAC");
10642
10643 if (intf == NULL || mac == NULL)
10644 return -1;
10645
10646 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10647 "interface %s to %s", intf, mac);
10648
10649 if (dut->set_macaddr) {
10650 char buf[128];
10651 int res;
10652 if (strcasecmp(mac, "default") == 0) {
10653 res = snprintf(buf, sizeof(buf), "%s",
10654 dut->set_macaddr);
10655 dut->tmp_mac_addr = 0;
10656 } else {
10657 res = snprintf(buf, sizeof(buf), "%s %s",
10658 dut->set_macaddr, mac);
10659 dut->tmp_mac_addr = 1;
10660 }
10661 if (res < 0 || res >= (int) sizeof(buf))
10662 return -1;
10663 if (system(buf) != 0) {
10664 send_resp(dut, conn, SIGMA_ERROR,
10665 "errorCode,Failed to set MAC "
10666 "address");
10667 return 0;
10668 }
10669 return 1;
10670 }
10671
10672 if (strcasecmp(mac, "default") == 0)
10673 return 1;
10674
10675 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10676 "command");
10677 return 0;
10678}
10679
10680
10681static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
10682 struct sigma_conn *conn, const char *intf,
10683 int val)
10684{
10685 char buf[200];
10686 int res;
10687
10688 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
10689 intf, val);
10690 if (res < 0 || res >= (int) sizeof(buf))
10691 return -1;
10692 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10693 if (system(buf) != 0) {
10694 send_resp(dut, conn, SIGMA_ERROR,
10695 "errorCode,Failed to configure offchannel mode");
10696 return 0;
10697 }
10698
10699 return 1;
10700}
10701
10702
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010703static int off_chan_val(enum sec_ch_offset off)
10704{
10705 switch (off) {
10706 case SEC_CH_NO:
10707 return 0;
10708 case SEC_CH_40ABOVE:
10709 return 40;
10710 case SEC_CH_40BELOW:
10711 return -40;
10712 }
10713
10714 return 0;
10715}
10716
10717
10718static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
10719 const char *intf, int off_ch_num,
10720 enum sec_ch_offset sec)
10721{
10722 char buf[200];
10723 int res;
10724
10725 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
10726 intf, off_ch_num);
10727 if (res < 0 || res >= (int) sizeof(buf))
10728 return -1;
10729 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10730 if (system(buf) != 0) {
10731 send_resp(dut, conn, SIGMA_ERROR,
10732 "errorCode,Failed to set offchan");
10733 return 0;
10734 }
10735
10736 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
10737 intf, off_chan_val(sec));
10738 if (res < 0 || res >= (int) sizeof(buf))
10739 return -1;
10740 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10741 if (system(buf) != 0) {
10742 send_resp(dut, conn, SIGMA_ERROR,
10743 "errorCode,Failed to set sec chan offset");
10744 return 0;
10745 }
10746
10747 return 1;
10748}
10749
10750
10751static int tdls_set_offchannel_offset(struct sigma_dut *dut,
10752 struct sigma_conn *conn,
10753 const char *intf, int off_ch_num,
10754 enum sec_ch_offset sec)
10755{
10756 char buf[200];
10757 int res;
10758
10759 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
10760 off_ch_num);
10761 if (res < 0 || res >= (int) sizeof(buf))
10762 return -1;
10763 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10764
10765 if (wpa_command(intf, buf) < 0) {
10766 send_resp(dut, conn, SIGMA_ERROR,
10767 "ErrorCode,Failed to set offchan");
10768 return 0;
10769 }
10770 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
10771 off_chan_val(sec));
10772 if (res < 0 || res >= (int) sizeof(buf))
10773 return -1;
10774
10775 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10776
10777 if (wpa_command(intf, buf) < 0) {
10778 send_resp(dut, conn, SIGMA_ERROR,
10779 "ErrorCode,Failed to set sec chan offset");
10780 return 0;
10781 }
10782
10783 return 1;
10784}
10785
10786
10787static int tdls_set_offchannel_mode(struct sigma_dut *dut,
10788 struct sigma_conn *conn,
10789 const char *intf, int val)
10790{
10791 char buf[200];
10792 int res;
10793
10794 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
10795 val);
10796 if (res < 0 || res >= (int) sizeof(buf))
10797 return -1;
10798 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10799
10800 if (wpa_command(intf, buf) < 0) {
10801 send_resp(dut, conn, SIGMA_ERROR,
10802 "ErrorCode,Failed to configure offchannel mode");
10803 return 0;
10804 }
10805
10806 return 1;
10807}
10808
10809
10810static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
10811 struct sigma_conn *conn,
10812 struct sigma_cmd *cmd)
10813{
10814 const char *val;
10815 enum {
10816 CHSM_NOT_SET,
10817 CHSM_ENABLE,
10818 CHSM_DISABLE,
10819 CHSM_REJREQ,
10820 CHSM_UNSOLRESP
10821 } chsm = CHSM_NOT_SET;
10822 int off_ch_num = -1;
10823 enum sec_ch_offset sec_ch = SEC_CH_NO;
10824 int res;
10825
10826 val = get_param(cmd, "Uapsd");
10827 if (val) {
10828 char buf[100];
10829 if (strcasecmp(val, "Enable") == 0)
10830 snprintf(buf, sizeof(buf), "SET ps 99");
10831 else if (strcasecmp(val, "Disable") == 0)
10832 snprintf(buf, sizeof(buf), "SET ps 98");
10833 else {
10834 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10835 "Unsupported uapsd parameter value");
10836 return 0;
10837 }
10838 if (wpa_command(intf, buf)) {
10839 send_resp(dut, conn, SIGMA_ERROR,
10840 "ErrorCode,Failed to change U-APSD "
10841 "powersave mode");
10842 return 0;
10843 }
10844 }
10845
10846 val = get_param(cmd, "TPKTIMER");
10847 if (val && strcasecmp(val, "DISABLE") == 0) {
10848 if (wpa_command(intf, "SET tdls_testing 0x100")) {
10849 send_resp(dut, conn, SIGMA_ERROR,
10850 "ErrorCode,Failed to enable no TPK "
10851 "expiration test mode");
10852 return 0;
10853 }
10854 dut->no_tpk_expiration = 1;
10855 }
10856
10857 val = get_param(cmd, "ChSwitchMode");
10858 if (val) {
10859 if (strcasecmp(val, "Enable") == 0 ||
10860 strcasecmp(val, "Initiate") == 0)
10861 chsm = CHSM_ENABLE;
10862 else if (strcasecmp(val, "Disable") == 0 ||
10863 strcasecmp(val, "passive") == 0)
10864 chsm = CHSM_DISABLE;
10865 else if (strcasecmp(val, "RejReq") == 0)
10866 chsm = CHSM_REJREQ;
10867 else if (strcasecmp(val, "UnSolResp") == 0)
10868 chsm = CHSM_UNSOLRESP;
10869 else {
10870 send_resp(dut, conn, SIGMA_ERROR,
10871 "ErrorCode,Unknown ChSwitchMode value");
10872 return 0;
10873 }
10874 }
10875
10876 val = get_param(cmd, "OffChNum");
10877 if (val) {
10878 off_ch_num = atoi(val);
10879 if (off_ch_num == 0) {
10880 send_resp(dut, conn, SIGMA_ERROR,
10881 "ErrorCode,Invalid OffChNum");
10882 return 0;
10883 }
10884 }
10885
10886 val = get_param(cmd, "SecChOffset");
10887 if (val) {
10888 if (strcmp(val, "20") == 0)
10889 sec_ch = SEC_CH_NO;
10890 else if (strcasecmp(val, "40above") == 0)
10891 sec_ch = SEC_CH_40ABOVE;
10892 else if (strcasecmp(val, "40below") == 0)
10893 sec_ch = SEC_CH_40BELOW;
10894 else {
10895 send_resp(dut, conn, SIGMA_ERROR,
10896 "ErrorCode,Unknown SecChOffset value");
10897 return 0;
10898 }
10899 }
10900
10901 if (chsm == CHSM_NOT_SET) {
10902 /* no offchannel changes requested */
10903 return 1;
10904 }
10905
10906 if (strcmp(intf, get_main_ifname()) != 0 &&
10907 strcmp(intf, get_station_ifname()) != 0) {
10908 send_resp(dut, conn, SIGMA_ERROR,
10909 "ErrorCode,Unknown interface");
10910 return 0;
10911 }
10912
10913 switch (chsm) {
10914 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030010915 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010916 break;
10917 case CHSM_ENABLE:
10918 if (off_ch_num < 0) {
10919 send_resp(dut, conn, SIGMA_ERROR,
10920 "ErrorCode,Missing OffChNum argument");
10921 return 0;
10922 }
10923 if (wifi_chip_type == DRIVER_WCN) {
10924 res = tdls_set_offchannel_offset(dut, conn, intf,
10925 off_ch_num, sec_ch);
10926 } else {
10927 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10928 sec_ch);
10929 }
10930 if (res != 1)
10931 return res;
10932 if (wifi_chip_type == DRIVER_WCN)
10933 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
10934 else
10935 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
10936 break;
10937 case CHSM_DISABLE:
10938 if (wifi_chip_type == DRIVER_WCN)
10939 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
10940 else
10941 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
10942 break;
10943 case CHSM_REJREQ:
10944 if (wifi_chip_type == DRIVER_WCN)
10945 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
10946 else
10947 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
10948 break;
10949 case CHSM_UNSOLRESP:
10950 if (off_ch_num < 0) {
10951 send_resp(dut, conn, SIGMA_ERROR,
10952 "ErrorCode,Missing OffChNum argument");
10953 return 0;
10954 }
10955 if (wifi_chip_type == DRIVER_WCN) {
10956 res = tdls_set_offchannel_offset(dut, conn, intf,
10957 off_ch_num, sec_ch);
10958 } else {
10959 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10960 sec_ch);
10961 }
10962 if (res != 1)
10963 return res;
10964 if (wifi_chip_type == DRIVER_WCN)
10965 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
10966 else
10967 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
10968 break;
10969 }
10970
10971 return res;
10972}
10973
10974
10975static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
10976 struct sigma_conn *conn,
10977 struct sigma_cmd *cmd)
10978{
10979 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053010980 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010981
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080010982 novap_reset(dut, intf);
10983
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010984 val = get_param(cmd, "nss_mcs_opt");
10985 if (val) {
10986 /* String (nss_operating_mode; mcs_operating_mode) */
10987 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010988 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010989
10990 token = strdup(val);
10991 if (!token)
10992 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010993 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010994 if (!result) {
10995 sigma_dut_print(dut, DUT_MSG_ERROR,
10996 "VHT NSS not specified");
10997 goto failed;
10998 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010999 if (strcasecmp(result, "def") != 0) {
11000 nss = atoi(result);
11001 if (nss == 4)
11002 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011003 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011004 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011005
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011006 }
11007
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011008 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011009 if (!result) {
11010 sigma_dut_print(dut, DUT_MSG_ERROR,
11011 "VHT MCS not specified");
11012 goto failed;
11013 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011014 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011015 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011016 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011017 } else {
11018 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011019 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011020 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011021 }
11022 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011023 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011024 }
11025
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011026 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011027 return 1;
11028failed:
11029 free(token);
11030 return 0;
11031}
11032
11033
11034static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11035 struct sigma_conn *conn,
11036 struct sigma_cmd *cmd)
11037{
11038 switch (get_driver_type()) {
11039 case DRIVER_ATHEROS:
11040 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11041 default:
11042 send_resp(dut, conn, SIGMA_ERROR,
11043 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11044 return 0;
11045 }
11046}
11047
11048
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011049static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11050 struct sigma_conn *conn,
11051 struct sigma_cmd *cmd)
11052{
11053 const char *val;
11054 char *token = NULL, *result;
11055 char buf[60];
11056
11057 val = get_param(cmd, "nss_mcs_opt");
11058 if (val) {
11059 /* String (nss_operating_mode; mcs_operating_mode) */
11060 int nss, mcs, ratecode;
11061 char *saveptr;
11062
11063 token = strdup(val);
11064 if (!token)
11065 return -2;
11066
11067 result = strtok_r(token, ";", &saveptr);
11068 if (!result) {
11069 sigma_dut_print(dut, DUT_MSG_ERROR,
11070 "HE NSS not specified");
11071 goto failed;
11072 }
11073 nss = 1;
11074 if (strcasecmp(result, "def") != 0)
11075 nss = atoi(result);
11076
11077 result = strtok_r(NULL, ";", &saveptr);
11078 if (!result) {
11079 sigma_dut_print(dut, DUT_MSG_ERROR,
11080 "HE MCS not specified");
11081 goto failed;
11082 }
11083 mcs = 7;
11084 if (strcasecmp(result, "def") != 0)
11085 mcs = atoi(result);
11086
Arif Hussain557bf412018-05-25 17:29:36 -070011087 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011088 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011089 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011090 } else if (nss > 2) {
11091 sigma_dut_print(dut, DUT_MSG_ERROR,
11092 "HE NSS %d not supported", nss);
11093 goto failed;
11094 }
11095
Arif Hussain557bf412018-05-25 17:29:36 -070011096 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11097 if (system(buf) != 0) {
11098 sigma_dut_print(dut, DUT_MSG_ERROR,
11099 "nss_mcs_opt: iwpriv %s nss %d failed",
11100 intf, nss);
11101 goto failed;
11102 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011103 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011104
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011105 /* Add the MCS to the ratecode */
11106 if (mcs >= 0 && mcs <= 11) {
11107 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011108#ifdef NL80211_SUPPORT
11109 if (dut->device_type == STA_testbed) {
11110 enum he_mcs_config mcs_config;
11111 int ret;
11112
11113 if (mcs <= 7)
11114 mcs_config = HE_80_MCS0_7;
11115 else if (mcs <= 9)
11116 mcs_config = HE_80_MCS0_9;
11117 else
11118 mcs_config = HE_80_MCS0_11;
11119 ret = sta_set_he_mcs(dut, intf, mcs_config);
11120 if (ret) {
11121 sigma_dut_print(dut, DUT_MSG_ERROR,
11122 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11123 mcs, mcs_config, ret);
11124 goto failed;
11125 }
11126 }
11127#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011128 } else {
11129 sigma_dut_print(dut, DUT_MSG_ERROR,
11130 "HE MCS %d not supported", mcs);
11131 goto failed;
11132 }
11133 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11134 intf, ratecode);
11135 if (system(buf) != 0) {
11136 sigma_dut_print(dut, DUT_MSG_ERROR,
11137 "iwpriv setting of 11ax rates failed");
11138 goto failed;
11139 }
11140 free(token);
11141 }
11142
11143 val = get_param(cmd, "GI");
11144 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011145 int fix_rate_sgi;
11146
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011147 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011148 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011149 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011150 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011151 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11152 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011153 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011154 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011155 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11156 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011157 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011158 } else {
11159 send_resp(dut, conn, SIGMA_ERROR,
11160 "errorCode,GI value not supported");
11161 return 0;
11162 }
11163 if (system(buf) != 0) {
11164 send_resp(dut, conn, SIGMA_ERROR,
11165 "errorCode,Failed to set shortgi");
11166 return 0;
11167 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011168 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11169 intf, fix_rate_sgi);
11170 if (system(buf) != 0) {
11171 send_resp(dut, conn, SIGMA_ERROR,
11172 "errorCode,Failed to set fix rate shortgi");
11173 return STATUS_SENT;
11174 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011175 }
11176
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011177 val = get_param(cmd, "LTF");
11178 if (val) {
11179#ifdef NL80211_SUPPORT
11180 if (strcmp(val, "3.2") == 0) {
11181 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11182 } if (strcmp(val, "6.4") == 0) {
11183 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11184 } else if (strcmp(val, "12.8") == 0) {
11185 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11186 } else {
11187 send_resp(dut, conn, SIGMA_ERROR,
11188 "errorCode, LTF value not supported");
11189 return 0;
11190 }
11191#else /* NL80211_SUPPORT */
11192 sigma_dut_print(dut, DUT_MSG_ERROR,
11193 "LTF cannot be set without NL80211_SUPPORT defined");
11194 return -2;
11195#endif /* NL80211_SUPPORT */
11196 }
11197
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011198 val = get_param(cmd, "TxSUPPDU");
11199 if (val) {
11200 int set_val = 1;
11201
11202 if (strcasecmp(val, "Enable") == 0)
11203 set_val = 1;
11204 else if (strcasecmp(val, "Disable") == 0)
11205 set_val = 0;
11206
11207 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11208 send_resp(dut, conn, SIGMA_ERROR,
11209 "ErrorCode,Failed to set Tx SU PPDU config");
11210 return 0;
11211 }
11212 }
11213
Arif Hussain480d5f42019-03-12 14:40:42 -070011214 val = get_param(cmd, "TWT_Setup");
11215 if (val) {
11216 if (strcasecmp(val, "Request") == 0) {
11217 if (sta_twt_request(dut, conn, cmd)) {
11218 send_resp(dut, conn, SIGMA_ERROR,
11219 "ErrorCode,sta_twt_request failed");
11220 return STATUS_SENT;
11221 }
11222 } else if (strcasecmp(val, "Teardown") == 0) {
11223 if (sta_twt_teardown(dut, conn, cmd)) {
11224 send_resp(dut, conn, SIGMA_ERROR,
11225 "ErrorCode,sta_twt_teardown failed");
11226 return STATUS_SENT;
11227 }
11228 }
11229 }
11230
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011231 val = get_param(cmd, "transmitOMI");
11232 if (val && sta_transmit_omi(dut, conn, cmd)) {
11233 send_resp(dut, conn, SIGMA_ERROR,
11234 "ErrorCode,sta_transmit_omi failed");
11235 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011236 }
11237
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011238 val = get_param(cmd, "Powersave");
11239 if (val) {
11240 char buf[60];
11241
11242 if (strcasecmp(val, "off") == 0) {
11243 snprintf(buf, sizeof(buf),
11244 "iwpriv %s setPower 2", intf);
11245 if (system(buf) != 0) {
11246 sigma_dut_print(dut, DUT_MSG_ERROR,
11247 "iwpriv setPower 2 failed");
11248 return 0;
11249 }
11250 } else if (strcasecmp(val, "on") == 0) {
11251 snprintf(buf, sizeof(buf),
11252 "iwpriv %s setPower 1", intf);
11253 if (system(buf) != 0) {
11254 sigma_dut_print(dut, DUT_MSG_ERROR,
11255 "iwpriv setPower 1 failed");
11256 return 0;
11257 }
11258 } else {
11259 sigma_dut_print(dut, DUT_MSG_ERROR,
11260 "Unsupported Powersave value '%s'",
11261 val);
11262 return -1;
11263 }
11264 }
11265
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011266 val = get_param(cmd, "MU_EDCA");
11267 if (val) {
11268 if (strcasecmp(val, "Override") == 0) {
11269 if (sta_set_mu_edca_override(dut, intf, 1)) {
11270 send_resp(dut, conn, SIGMA_ERROR,
11271 "errorCode,MU EDCA override set failed");
11272 return STATUS_SENT;
11273 }
11274 } else if (strcasecmp(val, "Disable") == 0) {
11275 if (sta_set_mu_edca_override(dut, intf, 0)) {
11276 send_resp(dut, conn, SIGMA_ERROR,
11277 "errorCode,MU EDCA override disable failed");
11278 return STATUS_SENT;
11279 }
11280 }
11281 }
11282
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011283 return 1;
11284
11285failed:
11286 free(token);
11287 return -2;
11288}
11289
11290
11291static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11292 struct sigma_conn *conn,
11293 struct sigma_cmd *cmd)
11294{
11295 switch (get_driver_type()) {
11296 case DRIVER_WCN:
11297 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11298 default:
11299 send_resp(dut, conn, SIGMA_ERROR,
11300 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11301 return 0;
11302 }
11303}
11304
11305
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011306static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11307 struct sigma_conn *conn,
11308 struct sigma_cmd *cmd)
11309{
11310 const char *val;
11311
11312 val = get_param(cmd, "powersave");
11313 if (val) {
11314 char buf[60];
11315
11316 if (strcasecmp(val, "off") == 0) {
11317 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11318 intf);
11319 if (system(buf) != 0) {
11320 sigma_dut_print(dut, DUT_MSG_ERROR,
11321 "iwpriv setPower 2 failed");
11322 return 0;
11323 }
11324 } else if (strcasecmp(val, "on") == 0) {
11325 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11326 intf);
11327 if (system(buf) != 0) {
11328 sigma_dut_print(dut, DUT_MSG_ERROR,
11329 "iwpriv setPower 1 failed");
11330 return 0;
11331 }
11332 } else {
11333 sigma_dut_print(dut, DUT_MSG_ERROR,
11334 "Unsupported power save config");
11335 return -1;
11336 }
11337 return 1;
11338 }
11339
11340 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11341
11342 return 0;
11343}
11344
11345
Ashwini Patil5acd7382017-04-13 15:55:04 +053011346static int btm_query_candidate_list(struct sigma_dut *dut,
11347 struct sigma_conn *conn,
11348 struct sigma_cmd *cmd)
11349{
11350 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11351 int len, ret;
11352 char buf[10];
11353
11354 /*
11355 * Neighbor Report elements format:
11356 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11357 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11358 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11359 */
11360
11361 bssid = get_param(cmd, "Nebor_BSSID");
11362 if (!bssid) {
11363 send_resp(dut, conn, SIGMA_INVALID,
11364 "errorCode,Nebor_BSSID is missing");
11365 return 0;
11366 }
11367
11368 info = get_param(cmd, "Nebor_Bssid_Info");
11369 if (!info) {
11370 sigma_dut_print(dut, DUT_MSG_INFO,
11371 "Using default value for Nebor_Bssid_Info: %s",
11372 DEFAULT_NEIGHBOR_BSSID_INFO);
11373 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11374 }
11375
11376 op_class = get_param(cmd, "Nebor_Op_Class");
11377 if (!op_class) {
11378 send_resp(dut, conn, SIGMA_INVALID,
11379 "errorCode,Nebor_Op_Class is missing");
11380 return 0;
11381 }
11382
11383 ch = get_param(cmd, "Nebor_Op_Ch");
11384 if (!ch) {
11385 send_resp(dut, conn, SIGMA_INVALID,
11386 "errorCode,Nebor_Op_Ch is missing");
11387 return 0;
11388 }
11389
11390 phy_type = get_param(cmd, "Nebor_Phy_Type");
11391 if (!phy_type) {
11392 sigma_dut_print(dut, DUT_MSG_INFO,
11393 "Using default value for Nebor_Phy_Type: %s",
11394 DEFAULT_NEIGHBOR_PHY_TYPE);
11395 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11396 }
11397
11398 /* Parse optional subelements */
11399 buf[0] = '\0';
11400 pref = get_param(cmd, "Nebor_Pref");
11401 if (pref) {
11402 /* hexdump for preferrence subelement */
11403 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11404 if (ret < 0 || ret >= (int) sizeof(buf)) {
11405 sigma_dut_print(dut, DUT_MSG_ERROR,
11406 "snprintf failed for optional subelement ret: %d",
11407 ret);
11408 send_resp(dut, conn, SIGMA_ERROR,
11409 "errorCode,snprintf failed for subelement");
11410 return 0;
11411 }
11412 }
11413
11414 if (!dut->btm_query_cand_list) {
11415 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11416 if (!dut->btm_query_cand_list) {
11417 send_resp(dut, conn, SIGMA_ERROR,
11418 "errorCode,Failed to allocate memory for btm_query_cand_list");
11419 return 0;
11420 }
11421 }
11422
11423 len = strlen(dut->btm_query_cand_list);
11424 ret = snprintf(dut->btm_query_cand_list + len,
11425 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11426 bssid, info, op_class, ch, phy_type, buf);
11427 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11428 sigma_dut_print(dut, DUT_MSG_ERROR,
11429 "snprintf failed for neighbor report list ret: %d",
11430 ret);
11431 send_resp(dut, conn, SIGMA_ERROR,
11432 "errorCode,snprintf failed for neighbor report");
11433 free(dut->btm_query_cand_list);
11434 dut->btm_query_cand_list = NULL;
11435 return 0;
11436 }
11437
11438 return 1;
11439}
11440
11441
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011442int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11443 struct sigma_ese_alloc *allocs, int *allocs_size)
11444{
11445 int max_count = *allocs_size;
11446 int count = 0, i;
11447 const char *val;
11448
11449 do {
11450 val = get_param_indexed(cmd, "AllocID", count);
11451 if (val)
11452 count++;
11453 } while (val);
11454
11455 if (count == 0 || count > max_count) {
11456 sigma_dut_print(dut, DUT_MSG_ERROR,
11457 "Invalid number of allocations(%d)", count);
11458 return -1;
11459 }
11460
11461 for (i = 0; i < count; i++) {
11462 val = get_param_indexed(cmd, "PercentBI", i);
11463 if (!val) {
11464 sigma_dut_print(dut, DUT_MSG_ERROR,
11465 "Missing PercentBI parameter at index %d",
11466 i);
11467 return -1;
11468 }
11469 allocs[i].percent_bi = atoi(val);
11470
11471 val = get_param_indexed(cmd, "SrcAID", i);
11472 if (val)
11473 allocs[i].src_aid = strtol(val, NULL, 0);
11474 else
11475 allocs[i].src_aid = ESE_BCAST_AID;
11476
11477 val = get_param_indexed(cmd, "DestAID", i);
11478 if (val)
11479 allocs[i].dst_aid = strtol(val, NULL, 0);
11480 else
11481 allocs[i].dst_aid = ESE_BCAST_AID;
11482
11483 allocs[i].type = ESE_CBAP;
11484 sigma_dut_print(dut, DUT_MSG_INFO,
11485 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11486 i, allocs[i].percent_bi, allocs[i].src_aid,
11487 allocs[i].dst_aid);
11488 }
11489
11490 *allocs_size = count;
11491 return 0;
11492}
11493
11494
11495static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11496 struct sigma_ese_alloc *allocs)
11497{
11498 switch (get_driver_type()) {
11499#ifdef __linux__
11500 case DRIVER_WIL6210:
11501 if (wil6210_set_ese(dut, count, allocs))
11502 return -1;
11503 return 1;
11504#endif /* __linux__ */
11505 default:
11506 sigma_dut_print(dut, DUT_MSG_ERROR,
11507 "Unsupported sta_set_60g_ese with the current driver");
11508 return -1;
11509 }
11510}
11511
11512
11513static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11514 struct sigma_conn *conn,
11515 struct sigma_cmd *cmd)
11516{
11517 const char *val;
11518
11519 val = get_param(cmd, "ExtSchIE");
11520 if (val && !strcasecmp(val, "Enable")) {
11521 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11522 int count = MAX_ESE_ALLOCS;
11523
11524 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11525 return -1;
11526 return sta_set_60g_ese(dut, count, allocs);
11527 }
11528
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011529 val = get_param(cmd, "MCS_FixedRate");
11530 if (val) {
11531 int sta_mcs = atoi(val);
11532
11533 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11534 sta_mcs);
11535 wil6210_set_force_mcs(dut, 1, sta_mcs);
11536
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011537 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011538 }
11539
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011540 send_resp(dut, conn, SIGMA_ERROR,
11541 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011542 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011543}
11544
11545
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011546static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
11547 struct sigma_cmd *cmd)
11548{
11549 const char *intf = get_param(cmd, "Interface");
11550 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011551 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011552
11553 if (intf == NULL || prog == NULL)
11554 return -1;
11555
Ashwini Patil5acd7382017-04-13 15:55:04 +053011556 /* BSS Transition candidate list for BTM query */
11557 val = get_param(cmd, "Nebor_BSSID");
11558 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11559 return 0;
11560
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011561 if (strcasecmp(prog, "TDLS") == 0)
11562 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11563
11564 if (strcasecmp(prog, "VHT") == 0)
11565 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11566
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011567 if (strcasecmp(prog, "HE") == 0)
11568 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11569
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011570 if (strcasecmp(prog, "MBO") == 0) {
11571 val = get_param(cmd, "Cellular_Data_Cap");
11572 if (val &&
11573 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11574 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011575
11576 val = get_param(cmd, "Ch_Pref");
11577 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11578 return 0;
11579
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011580 return 1;
11581 }
11582
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011583 if (strcasecmp(prog, "60GHz") == 0)
11584 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11585
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011586 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11587 return 0;
11588}
11589
11590
11591static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
11592 struct sigma_cmd *cmd)
11593{
11594 const char *intf = get_param(cmd, "Interface");
11595 const char *mode = get_param(cmd, "Mode");
11596 int res;
11597
11598 if (intf == NULL || mode == NULL)
11599 return -1;
11600
11601 if (strcasecmp(mode, "On") == 0)
11602 res = wpa_command(intf, "SET radio_disabled 0");
11603 else if (strcasecmp(mode, "Off") == 0)
11604 res = wpa_command(intf, "SET radio_disabled 1");
11605 else
11606 return -1;
11607
11608 if (res) {
11609 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11610 "radio mode");
11611 return 0;
11612 }
11613
11614 return 1;
11615}
11616
11617
11618static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
11619 struct sigma_cmd *cmd)
11620{
11621 const char *intf = get_param(cmd, "Interface");
11622 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011623 const char *prog = get_param(cmd, "program");
11624 const char *powersave = get_param(cmd, "powersave");
11625 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011626
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011627 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011628 return -1;
11629
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011630 if (prog && strcasecmp(prog, "60GHz") == 0) {
11631 /*
11632 * The CAPI mode parameter does not exist in 60G
11633 * unscheduled PS.
11634 */
11635 if (strcasecmp(powersave, "unscheduled") == 0)
11636 res = set_ps(intf, dut, 1);
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011637 } else if (prog && get_driver_type() == DRIVER_WCN &&
11638 strcasecmp(prog, "HE") == 0) {
11639 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011640 } else {
11641 if (mode == NULL)
11642 return -1;
11643
11644 if (strcasecmp(mode, "On") == 0)
11645 res = set_ps(intf, dut, 1);
11646 else if (strcasecmp(mode, "Off") == 0)
11647 res = set_ps(intf, dut, 0);
11648 else
11649 return -1;
11650 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011651
11652 if (res) {
11653 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11654 "power save mode");
11655 return 0;
11656 }
11657
11658 return 1;
11659}
11660
11661
11662static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
11663 struct sigma_cmd *cmd)
11664{
11665 const char *intf = get_param(cmd, "Interface");
11666 const char *val, *bssid;
11667 int res;
11668 char *buf;
11669 size_t buf_len;
11670
11671 val = get_param(cmd, "BSSID_FILTER");
11672 if (val == NULL)
11673 return -1;
11674
11675 bssid = get_param(cmd, "BSSID_List");
11676 if (atoi(val) == 0 || bssid == NULL) {
11677 /* Disable BSSID filter */
11678 if (wpa_command(intf, "SET bssid_filter ")) {
11679 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
11680 "to disable BSSID filter");
11681 return 0;
11682 }
11683
11684 return 1;
11685 }
11686
11687 buf_len = 100 + strlen(bssid);
11688 buf = malloc(buf_len);
11689 if (buf == NULL)
11690 return -1;
11691
11692 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
11693 res = wpa_command(intf, buf);
11694 free(buf);
11695 if (res) {
11696 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
11697 "BSSID filter");
11698 return 0;
11699 }
11700
11701 return 1;
11702}
11703
11704
11705static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
11706 struct sigma_cmd *cmd)
11707{
11708 const char *intf = get_param(cmd, "Interface");
11709 const char *val;
11710
11711 /* TODO: ARP */
11712
11713 val = get_param(cmd, "HS2_CACHE_PROFILE");
11714 if (val && strcasecmp(val, "All") == 0)
11715 hs2_clear_credentials(intf);
11716
11717 return 1;
11718}
11719
11720
11721static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
11722 struct sigma_cmd *cmd)
11723{
11724 const char *intf = get_param(cmd, "Interface");
11725 const char *key_type = get_param(cmd, "KeyType");
11726 char buf[100], resp[200];
11727
11728 if (key_type == NULL)
11729 return -1;
11730
11731 if (strcasecmp(key_type, "GTK") == 0) {
11732 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
11733 strncmp(buf, "FAIL", 4) == 0) {
11734 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11735 "not fetch current GTK");
11736 return 0;
11737 }
11738 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
11739 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11740 return 0;
11741 } else {
11742 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11743 "KeyType");
11744 return 0;
11745 }
11746
11747 return 1;
11748}
11749
11750
11751static int hs2_set_policy(struct sigma_dut *dut)
11752{
11753#ifdef ANDROID
11754 system("ip rule del prio 23000");
11755 if (system("ip rule add from all lookup main prio 23000") != 0) {
11756 sigma_dut_print(dut, DUT_MSG_ERROR,
11757 "Failed to run:ip rule add from all lookup main prio");
11758 return -1;
11759 }
11760 if (system("ip route flush cache") != 0) {
11761 sigma_dut_print(dut, DUT_MSG_ERROR,
11762 "Failed to run ip route flush cache");
11763 return -1;
11764 }
11765 return 1;
11766#else /* ANDROID */
11767 return 0;
11768#endif /* ANDROID */
11769}
11770
11771
11772static int cmd_sta_hs2_associate(struct sigma_dut *dut,
11773 struct sigma_conn *conn,
11774 struct sigma_cmd *cmd)
11775{
11776 const char *intf = get_param(cmd, "Interface");
11777 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030011778 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011779 struct wpa_ctrl *ctrl;
11780 int res;
11781 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
11782 int tries = 0;
11783 int ignore_blacklist = 0;
11784 const char *events[] = {
11785 "CTRL-EVENT-CONNECTED",
11786 "INTERWORKING-BLACKLISTED",
11787 "INTERWORKING-NO-MATCH",
11788 NULL
11789 };
11790
11791 start_sta_mode(dut);
11792
Jouni Malinen439352d2018-09-13 03:42:23 +030011793 if (band) {
11794 if (strcmp(band, "2.4") == 0) {
11795 wpa_command(intf, "SET setband 2G");
11796 } else if (strcmp(band, "5") == 0) {
11797 wpa_command(intf, "SET setband 5G");
11798 } else {
11799 send_resp(dut, conn, SIGMA_ERROR,
11800 "errorCode,Unsupported band");
11801 return 0;
11802 }
11803 }
11804
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011805 blacklisted[0] = '\0';
11806 if (val && atoi(val))
11807 ignore_blacklist = 1;
11808
11809try_again:
11810 ctrl = open_wpa_mon(intf);
11811 if (ctrl == NULL) {
11812 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11813 "wpa_supplicant monitor connection");
11814 return -2;
11815 }
11816
11817 tries++;
11818 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
11819 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
11820 "Interworking connection");
11821 wpa_ctrl_detach(ctrl);
11822 wpa_ctrl_close(ctrl);
11823 return 0;
11824 }
11825
11826 buf[0] = '\0';
11827 while (1) {
11828 char *pos;
11829 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11830 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
11831 if (!pos)
11832 break;
11833 pos += 25;
11834 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
11835 pos);
11836 if (!blacklisted[0])
11837 memcpy(blacklisted, pos, strlen(pos) + 1);
11838 }
11839
11840 if (ignore_blacklist && blacklisted[0]) {
11841 char *end;
11842 end = strchr(blacklisted, ' ');
11843 if (end)
11844 *end = '\0';
11845 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
11846 blacklisted);
11847 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
11848 blacklisted);
11849 if (wpa_command(intf, buf)) {
11850 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
11851 wpa_ctrl_detach(ctrl);
11852 wpa_ctrl_close(ctrl);
11853 return 0;
11854 }
11855 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11856 buf, sizeof(buf));
11857 }
11858
11859 wpa_ctrl_detach(ctrl);
11860 wpa_ctrl_close(ctrl);
11861
11862 if (res < 0) {
11863 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11864 "connect");
11865 return 0;
11866 }
11867
11868 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
11869 strstr(buf, "INTERWORKING-BLACKLISTED")) {
11870 if (tries < 2) {
11871 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
11872 goto try_again;
11873 }
11874 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
11875 "matching credentials found");
11876 return 0;
11877 }
11878
11879 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11880 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11881 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11882 "get current BSSID/SSID");
11883 return 0;
11884 }
11885
11886 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
11887 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11888 hs2_set_policy(dut);
11889 return 0;
11890}
11891
11892
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011893static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
11894 struct sigma_conn *conn,
11895 struct sigma_cmd *cmd)
11896{
11897 const char *intf = get_param(cmd, "Interface");
11898 const char *display = get_param(cmd, "Display");
11899 struct wpa_ctrl *ctrl;
11900 char buf[300], params[400], *pos;
11901 char bssid[20];
11902 int info_avail = 0;
11903 unsigned int old_timeout;
11904 int res;
11905
11906 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
11907 send_resp(dut, conn, SIGMA_ERROR,
11908 "ErrorCode,Could not get current BSSID");
11909 return 0;
11910 }
11911 ctrl = open_wpa_mon(intf);
11912 if (!ctrl) {
11913 sigma_dut_print(dut, DUT_MSG_ERROR,
11914 "Failed to open wpa_supplicant monitor connection");
11915 return -2;
11916 }
11917
11918 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
11919 wpa_command(intf, buf);
11920
11921 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
11922 if (res < 0) {
11923 send_resp(dut, conn, SIGMA_ERROR,
11924 "ErrorCode,Could not complete GAS query");
11925 goto fail;
11926 }
11927
11928 old_timeout = dut->default_timeout;
11929 dut->default_timeout = 2;
11930 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
11931 dut->default_timeout = old_timeout;
11932 if (res < 0)
11933 goto done;
11934 pos = strchr(buf, ' ');
11935 if (!pos)
11936 goto done;
11937 pos++;
11938 pos = strchr(pos, ' ');
11939 if (!pos)
11940 goto done;
11941 pos++;
11942 info_avail = 1;
11943 snprintf(params, sizeof(params), "browser %s", pos);
11944
11945 if (display && strcasecmp(display, "Yes") == 0) {
11946 pid_t pid;
11947
11948 pid = fork();
11949 if (pid < 0) {
11950 perror("fork");
11951 return -1;
11952 }
11953
11954 if (pid == 0) {
11955 run_hs20_osu(dut, params);
11956 exit(0);
11957 }
11958 }
11959
11960done:
11961 snprintf(buf, sizeof(buf), "Info_available,%s",
11962 info_avail ? "Yes" : "No");
11963 send_resp(dut, conn, SIGMA_COMPLETE, buf);
11964fail:
11965 wpa_ctrl_detach(ctrl);
11966 wpa_ctrl_close(ctrl);
11967 return 0;
11968}
11969
11970
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011971static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
11972 struct sigma_conn *conn,
11973 const char *ifname,
11974 struct sigma_cmd *cmd)
11975{
11976 const char *val;
11977 int id;
11978
11979 id = add_cred(ifname);
11980 if (id < 0)
11981 return -2;
11982 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11983
11984 val = get_param(cmd, "prefer");
11985 if (val && atoi(val) > 0)
11986 set_cred(ifname, id, "priority", "1");
11987
11988 val = get_param(cmd, "REALM");
11989 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
11990 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11991 "realm");
11992 return 0;
11993 }
11994
11995 val = get_param(cmd, "HOME_FQDN");
11996 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
11997 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11998 "home_fqdn");
11999 return 0;
12000 }
12001
12002 val = get_param(cmd, "Username");
12003 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12004 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12005 "username");
12006 return 0;
12007 }
12008
12009 val = get_param(cmd, "Password");
12010 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12011 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12012 "password");
12013 return 0;
12014 }
12015
12016 val = get_param(cmd, "ROOT_CA");
12017 if (val) {
12018 char fname[200];
12019 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12020#ifdef __linux__
12021 if (!file_exists(fname)) {
12022 char msg[300];
12023 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12024 "file (%s) not found", fname);
12025 send_resp(dut, conn, SIGMA_ERROR, msg);
12026 return 0;
12027 }
12028#endif /* __linux__ */
12029 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12030 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12031 "not set root CA");
12032 return 0;
12033 }
12034 }
12035
12036 return 1;
12037}
12038
12039
12040static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12041{
12042 FILE *in, *out;
12043 char buf[500];
12044 int found = 0;
12045
12046 in = fopen("devdetail.xml", "r");
12047 if (in == NULL)
12048 return -1;
12049 out = fopen("devdetail.xml.tmp", "w");
12050 if (out == NULL) {
12051 fclose(in);
12052 return -1;
12053 }
12054
12055 while (fgets(buf, sizeof(buf), in)) {
12056 char *pos = strstr(buf, "<IMSI>");
12057 if (pos) {
12058 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12059 imsi);
12060 pos += 6;
12061 *pos = '\0';
12062 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12063 found++;
12064 } else {
12065 fprintf(out, "%s", buf);
12066 }
12067 }
12068
12069 fclose(out);
12070 fclose(in);
12071 if (found)
12072 rename("devdetail.xml.tmp", "devdetail.xml");
12073 else
12074 unlink("devdetail.xml.tmp");
12075
12076 return 0;
12077}
12078
12079
12080static int sta_add_credential_sim(struct sigma_dut *dut,
12081 struct sigma_conn *conn,
12082 const char *ifname, struct sigma_cmd *cmd)
12083{
12084 const char *val, *imsi = NULL;
12085 int id;
12086 char buf[200];
12087 int res;
12088 const char *pos;
12089 size_t mnc_len;
12090 char plmn_mcc[4];
12091 char plmn_mnc[4];
12092
12093 id = add_cred(ifname);
12094 if (id < 0)
12095 return -2;
12096 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12097
12098 val = get_param(cmd, "prefer");
12099 if (val && atoi(val) > 0)
12100 set_cred(ifname, id, "priority", "1");
12101
12102 val = get_param(cmd, "PLMN_MCC");
12103 if (val == NULL) {
12104 send_resp(dut, conn, SIGMA_ERROR,
12105 "errorCode,Missing PLMN_MCC");
12106 return 0;
12107 }
12108 if (strlen(val) != 3) {
12109 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12110 return 0;
12111 }
12112 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12113
12114 val = get_param(cmd, "PLMN_MNC");
12115 if (val == NULL) {
12116 send_resp(dut, conn, SIGMA_ERROR,
12117 "errorCode,Missing PLMN_MNC");
12118 return 0;
12119 }
12120 if (strlen(val) != 2 && strlen(val) != 3) {
12121 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12122 return 0;
12123 }
12124 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12125
12126 val = get_param(cmd, "IMSI");
12127 if (val == NULL) {
12128 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12129 "IMSI");
12130 return 0;
12131 }
12132
12133 imsi = pos = val;
12134
12135 if (strncmp(plmn_mcc, pos, 3) != 0) {
12136 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12137 return 0;
12138 }
12139 pos += 3;
12140
12141 mnc_len = strlen(plmn_mnc);
12142 if (mnc_len < 2) {
12143 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12144 return 0;
12145 }
12146
12147 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12148 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12149 return 0;
12150 }
12151 pos += mnc_len;
12152
12153 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12154 if (res < 0 || res >= (int) sizeof(buf))
12155 return -1;
12156 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12157 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12158 "not set IMSI");
12159 return 0;
12160 }
12161
12162 val = get_param(cmd, "Password");
12163 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12164 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12165 "not set password");
12166 return 0;
12167 }
12168
Jouni Malinenba630452018-06-22 11:49:59 +030012169 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012170 /*
12171 * Set provisioning_sp for the test cases where SIM/USIM
12172 * provisioning is used.
12173 */
12174 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12175 "wi-fi.org") < 0) {
12176 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12177 "not set provisioning_sp");
12178 return 0;
12179 }
12180
12181 update_devdetail_imsi(dut, imsi);
12182 }
12183
12184 return 1;
12185}
12186
12187
12188static int sta_add_credential_cert(struct sigma_dut *dut,
12189 struct sigma_conn *conn,
12190 const char *ifname,
12191 struct sigma_cmd *cmd)
12192{
12193 const char *val;
12194 int id;
12195
12196 id = add_cred(ifname);
12197 if (id < 0)
12198 return -2;
12199 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12200
12201 val = get_param(cmd, "prefer");
12202 if (val && atoi(val) > 0)
12203 set_cred(ifname, id, "priority", "1");
12204
12205 val = get_param(cmd, "REALM");
12206 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12207 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12208 "realm");
12209 return 0;
12210 }
12211
12212 val = get_param(cmd, "HOME_FQDN");
12213 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12214 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12215 "home_fqdn");
12216 return 0;
12217 }
12218
12219 val = get_param(cmd, "Username");
12220 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12221 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12222 "username");
12223 return 0;
12224 }
12225
12226 val = get_param(cmd, "clientCertificate");
12227 if (val) {
12228 char fname[200];
12229 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12230#ifdef __linux__
12231 if (!file_exists(fname)) {
12232 char msg[300];
12233 snprintf(msg, sizeof(msg),
12234 "ErrorCode,clientCertificate "
12235 "file (%s) not found", fname);
12236 send_resp(dut, conn, SIGMA_ERROR, msg);
12237 return 0;
12238 }
12239#endif /* __linux__ */
12240 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12241 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12242 "not set client_cert");
12243 return 0;
12244 }
12245 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12246 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12247 "not set private_key");
12248 return 0;
12249 }
12250 }
12251
12252 val = get_param(cmd, "ROOT_CA");
12253 if (val) {
12254 char fname[200];
12255 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12256#ifdef __linux__
12257 if (!file_exists(fname)) {
12258 char msg[300];
12259 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12260 "file (%s) not found", fname);
12261 send_resp(dut, conn, SIGMA_ERROR, msg);
12262 return 0;
12263 }
12264#endif /* __linux__ */
12265 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12266 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12267 "not set root CA");
12268 return 0;
12269 }
12270 }
12271
12272 return 1;
12273}
12274
12275
12276static int cmd_sta_add_credential(struct sigma_dut *dut,
12277 struct sigma_conn *conn,
12278 struct sigma_cmd *cmd)
12279{
12280 const char *intf = get_param(cmd, "Interface");
12281 const char *type;
12282
12283 start_sta_mode(dut);
12284
12285 type = get_param(cmd, "Type");
12286 if (!type)
12287 return -1;
12288
12289 if (strcasecmp(type, "uname_pwd") == 0)
12290 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12291
12292 if (strcasecmp(type, "sim") == 0)
12293 return sta_add_credential_sim(dut, conn, intf, cmd);
12294
12295 if (strcasecmp(type, "cert") == 0)
12296 return sta_add_credential_cert(dut, conn, intf, cmd);
12297
12298 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12299 "type");
12300 return 0;
12301}
12302
12303
12304static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
12305 struct sigma_cmd *cmd)
12306{
12307 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012308 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012309 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012310 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012311 int res;
12312
Arif Hussain66a4af02019-02-07 15:04:51 -080012313 val = get_param(cmd, "GetParameter");
12314 if (val && strcmp(val, "SSID_BSSID") == 0) {
12315 if (get_wpa_ssid_bssid(dut, get_station_ifname(),
12316 buf, sizeof(buf)) < 0) {
12317 sigma_dut_print(dut, DUT_MSG_ERROR,
12318 "Could not get ssid bssid");
12319 return ERROR_SEND_STATUS;
12320 }
12321
12322 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12323 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12324 return STATUS_SENT;
12325 }
12326
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012327 val = get_param(cmd, "HESSID");
12328 if (val) {
12329 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12330 if (res < 0 || res >= (int) sizeof(buf))
12331 return -1;
12332 wpa_command(intf, buf);
12333 }
12334
12335 val = get_param(cmd, "ACCS_NET_TYPE");
12336 if (val) {
12337 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12338 val);
12339 if (res < 0 || res >= (int) sizeof(buf))
12340 return -1;
12341 wpa_command(intf, buf);
12342 }
12343
vamsi krishna89ad8c62017-09-19 12:51:18 +053012344 bssid = get_param(cmd, "Bssid");
12345 ssid = get_param(cmd, "Ssid");
12346
12347 if (ssid) {
12348 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12349 send_resp(dut, conn, SIGMA_ERROR,
12350 "ErrorCode,Too long SSID");
12351 return 0;
12352 }
12353 ascii2hexstr(ssid, ssid_hex);
12354 }
12355
12356 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12357 bssid ? " bssid=": "",
12358 bssid ? bssid : "",
12359 ssid ? " ssid " : "",
12360 ssid ? ssid_hex : "");
12361 if (res < 0 || res >= (int) sizeof(buf))
12362 return -1;
12363
12364 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012365 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12366 "scan");
12367 return 0;
12368 }
12369
12370 return 1;
12371}
12372
12373
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012374static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
12375 struct sigma_cmd *cmd)
12376{
12377 const char *intf = get_param(cmd, "Interface");
12378 const char *bssid;
12379 char buf[4096], *pos;
12380 int freq, chan;
12381 char *ssid;
12382 char resp[100];
12383 int res;
12384 struct wpa_ctrl *ctrl;
12385
12386 bssid = get_param(cmd, "BSSID");
12387 if (!bssid) {
12388 send_resp(dut, conn, SIGMA_INVALID,
12389 "errorCode,BSSID argument is missing");
12390 return 0;
12391 }
12392
12393 ctrl = open_wpa_mon(intf);
12394 if (!ctrl) {
12395 sigma_dut_print(dut, DUT_MSG_ERROR,
12396 "Failed to open wpa_supplicant monitor connection");
12397 return -1;
12398 }
12399
12400 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12401 send_resp(dut, conn, SIGMA_ERROR,
12402 "errorCode,Could not start scan");
12403 wpa_ctrl_detach(ctrl);
12404 wpa_ctrl_close(ctrl);
12405 return 0;
12406 }
12407
12408 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12409 buf, sizeof(buf));
12410
12411 wpa_ctrl_detach(ctrl);
12412 wpa_ctrl_close(ctrl);
12413
12414 if (res < 0) {
12415 send_resp(dut, conn, SIGMA_ERROR,
12416 "errorCode,Scan did not complete");
12417 return 0;
12418 }
12419
12420 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12421 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12422 strncmp(buf, "id=", 3) != 0) {
12423 send_resp(dut, conn, SIGMA_ERROR,
12424 "errorCode,Specified BSSID not found");
12425 return 0;
12426 }
12427
12428 pos = strstr(buf, "\nfreq=");
12429 if (!pos) {
12430 send_resp(dut, conn, SIGMA_ERROR,
12431 "errorCode,Channel not found");
12432 return 0;
12433 }
12434 freq = atoi(pos + 6);
12435 chan = freq_to_channel(freq);
12436
12437 pos = strstr(buf, "\nssid=");
12438 if (!pos) {
12439 send_resp(dut, conn, SIGMA_ERROR,
12440 "errorCode,SSID not found");
12441 return 0;
12442 }
12443 ssid = pos + 6;
12444 pos = strchr(ssid, '\n');
12445 if (pos)
12446 *pos = '\0';
12447 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12448 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12449 return 0;
12450}
12451
12452
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012453static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
12454 struct sigma_cmd *cmd)
12455{
12456#ifdef __linux__
12457 struct timeval tv;
12458 struct tm tm;
12459 time_t t;
12460 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012461 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012462
12463 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
12464
12465 memset(&tm, 0, sizeof(tm));
12466 val = get_param(cmd, "seconds");
12467 if (val)
12468 tm.tm_sec = atoi(val);
12469 val = get_param(cmd, "minutes");
12470 if (val)
12471 tm.tm_min = atoi(val);
12472 val = get_param(cmd, "hours");
12473 if (val)
12474 tm.tm_hour = atoi(val);
12475 val = get_param(cmd, "date");
12476 if (val)
12477 tm.tm_mday = atoi(val);
12478 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012479 if (val) {
12480 v = atoi(val);
12481 if (v < 1 || v > 12) {
12482 send_resp(dut, conn, SIGMA_INVALID,
12483 "errorCode,Invalid month");
12484 return 0;
12485 }
12486 tm.tm_mon = v - 1;
12487 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012488 val = get_param(cmd, "year");
12489 if (val) {
12490 int year = atoi(val);
12491#ifdef ANDROID
12492 if (year > 2035)
12493 year = 2035; /* years beyond 2035 not supported */
12494#endif /* ANDROID */
12495 tm.tm_year = year - 1900;
12496 }
12497 t = mktime(&tm);
12498 if (t == (time_t) -1) {
12499 send_resp(dut, conn, SIGMA_ERROR,
12500 "errorCode,Invalid date or time");
12501 return 0;
12502 }
12503
12504 memset(&tv, 0, sizeof(tv));
12505 tv.tv_sec = t;
12506
12507 if (settimeofday(&tv, NULL) < 0) {
12508 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12509 strerror(errno));
12510 send_resp(dut, conn, SIGMA_ERROR,
12511 "errorCode,Failed to set time");
12512 return 0;
12513 }
12514
12515 return 1;
12516#endif /* __linux__ */
12517
12518 return -1;
12519}
12520
12521
12522static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
12523 struct sigma_cmd *cmd)
12524{
12525 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012526 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012527 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012528 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012529 int res;
12530 struct wpa_ctrl *ctrl;
12531
12532 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012533 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012534
12535 val = get_param(cmd, "ProdESSAssoc");
12536 if (val)
12537 prod_ess_assoc = atoi(val);
12538
12539 kill_dhcp_client(dut, intf);
12540 if (start_dhcp_client(dut, intf) < 0)
12541 return -2;
12542
12543 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12544 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12545 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012546 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012547 prod_ess_assoc ? "" : "-N",
12548 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012549 name ? "'" : "",
12550 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12551 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012552
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012553 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012554 if (run_hs20_osu(dut, buf) < 0) {
12555 FILE *f;
12556
12557 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12558
12559 f = fopen("hs20-osu-client.res", "r");
12560 if (f) {
12561 char resp[400], res[300], *pos;
12562 if (!fgets(res, sizeof(res), f))
12563 res[0] = '\0';
12564 pos = strchr(res, '\n');
12565 if (pos)
12566 *pos = '\0';
12567 fclose(f);
12568 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12569 res);
12570 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12571 if (system(resp) != 0) {
12572 }
12573 snprintf(resp, sizeof(resp),
12574 "SSID,,BSSID,,failureReason,%s", res);
12575 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12576 return 0;
12577 }
12578
12579 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12580 return 0;
12581 }
12582
12583 if (!prod_ess_assoc)
12584 goto report;
12585
12586 ctrl = open_wpa_mon(intf);
12587 if (ctrl == NULL) {
12588 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12589 "wpa_supplicant monitor connection");
12590 return -1;
12591 }
12592
12593 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12594 buf, sizeof(buf));
12595
12596 wpa_ctrl_detach(ctrl);
12597 wpa_ctrl_close(ctrl);
12598
12599 if (res < 0) {
12600 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12601 "network after OSU");
12602 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12603 return 0;
12604 }
12605
12606report:
12607 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12608 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12609 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12610 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12611 return 0;
12612 }
12613
12614 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12615 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012616 return 0;
12617}
12618
12619
12620static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
12621 struct sigma_cmd *cmd)
12622{
12623 const char *val;
12624 int timeout = 120;
12625
12626 val = get_param(cmd, "PolicyUpdate");
12627 if (val == NULL || atoi(val) == 0)
12628 return 1; /* No operation requested */
12629
12630 val = get_param(cmd, "Timeout");
12631 if (val)
12632 timeout = atoi(val);
12633
12634 if (timeout) {
12635 /* TODO: time out the command and return
12636 * PolicyUpdateStatus,TIMEOUT if needed. */
12637 }
12638
12639 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12640 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12641 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12642 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12643 return 0;
12644 }
12645
12646 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12647 return 0;
12648}
12649
12650
12651static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
12652 struct sigma_cmd *cmd)
12653{
12654 struct wpa_ctrl *ctrl;
12655 const char *intf = get_param(cmd, "Interface");
12656 const char *bssid = get_param(cmd, "Bssid");
12657 const char *ssid = get_param(cmd, "SSID");
12658 const char *security = get_param(cmd, "Security");
12659 const char *passphrase = get_param(cmd, "Passphrase");
12660 const char *pin = get_param(cmd, "PIN");
12661 char buf[1000];
12662 char ssid_hex[200], passphrase_hex[200];
12663 const char *keymgmt, *cipher;
12664
12665 if (intf == NULL)
12666 intf = get_main_ifname();
12667
12668 if (!bssid) {
12669 send_resp(dut, conn, SIGMA_ERROR,
12670 "ErrorCode,Missing Bssid argument");
12671 return 0;
12672 }
12673
12674 if (!ssid) {
12675 send_resp(dut, conn, SIGMA_ERROR,
12676 "ErrorCode,Missing SSID argument");
12677 return 0;
12678 }
12679
12680 if (!security) {
12681 send_resp(dut, conn, SIGMA_ERROR,
12682 "ErrorCode,Missing Security argument");
12683 return 0;
12684 }
12685
12686 if (!passphrase) {
12687 send_resp(dut, conn, SIGMA_ERROR,
12688 "ErrorCode,Missing Passphrase argument");
12689 return 0;
12690 }
12691
12692 if (!pin) {
12693 send_resp(dut, conn, SIGMA_ERROR,
12694 "ErrorCode,Missing PIN argument");
12695 return 0;
12696 }
12697
vamsi krishna8c9c1562017-05-12 15:51:46 +053012698 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
12699 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012700 send_resp(dut, conn, SIGMA_ERROR,
12701 "ErrorCode,Too long SSID/passphrase");
12702 return 0;
12703 }
12704
12705 ctrl = open_wpa_mon(intf);
12706 if (ctrl == NULL) {
12707 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12708 "wpa_supplicant monitor connection");
12709 return -2;
12710 }
12711
12712 if (strcasecmp(security, "wpa2-psk") == 0) {
12713 keymgmt = "WPA2PSK";
12714 cipher = "CCMP";
12715 } else {
12716 wpa_ctrl_detach(ctrl);
12717 wpa_ctrl_close(ctrl);
12718 send_resp(dut, conn, SIGMA_ERROR,
12719 "ErrorCode,Unsupported Security value");
12720 return 0;
12721 }
12722
12723 ascii2hexstr(ssid, ssid_hex);
12724 ascii2hexstr(passphrase, passphrase_hex);
12725 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
12726 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
12727
12728 if (wpa_command(intf, buf) < 0) {
12729 wpa_ctrl_detach(ctrl);
12730 wpa_ctrl_close(ctrl);
12731 send_resp(dut, conn, SIGMA_ERROR,
12732 "ErrorCode,Failed to start registrar");
12733 return 0;
12734 }
12735
12736 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
12737 dut->er_oper_performed = 1;
12738
12739 return wps_connection_event(dut, conn, ctrl, intf, 0);
12740}
12741
12742
12743static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
12744 struct sigma_conn *conn,
12745 struct sigma_cmd *cmd)
12746{
12747 struct wpa_ctrl *ctrl;
12748 const char *intf = get_param(cmd, "Interface");
12749 const char *bssid = get_param(cmd, "Bssid");
12750 char buf[100];
12751
12752 if (!bssid) {
12753 send_resp(dut, conn, SIGMA_ERROR,
12754 "ErrorCode,Missing Bssid argument");
12755 return 0;
12756 }
12757
12758 ctrl = open_wpa_mon(intf);
12759 if (ctrl == NULL) {
12760 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12761 "wpa_supplicant monitor connection");
12762 return -2;
12763 }
12764
12765 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
12766
12767 if (wpa_command(intf, buf) < 0) {
12768 wpa_ctrl_detach(ctrl);
12769 wpa_ctrl_close(ctrl);
12770 send_resp(dut, conn, SIGMA_ERROR,
12771 "ErrorCode,Failed to start registrar");
12772 return 0;
12773 }
12774
12775 return wps_connection_event(dut, conn, ctrl, intf, 0);
12776}
12777
12778
vamsi krishna9b144002017-09-20 13:28:13 +053012779static int cmd_start_wps_registration(struct sigma_dut *dut,
12780 struct sigma_conn *conn,
12781 struct sigma_cmd *cmd)
12782{
12783 struct wpa_ctrl *ctrl;
12784 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012785 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012786 const char *config_method = get_param(cmd, "WPSConfigMethod");
12787 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053012788 int res;
12789 char buf[256];
12790 const char *events[] = {
12791 "CTRL-EVENT-CONNECTED",
12792 "WPS-OVERLAP-DETECTED",
12793 "WPS-TIMEOUT",
12794 "WPS-FAIL",
12795 NULL
12796 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012797 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053012798
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012799 /* 60G WPS tests do not pass Interface parameter */
12800 if (!intf)
12801 intf = get_main_ifname();
12802
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012803 if (dut->mode == SIGMA_MODE_AP)
12804 return ap_wps_registration(dut, conn, cmd);
12805
12806 if (config_method) {
12807 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
12808 * sta_wps_enter_pin before calling start_wps_registration. */
12809 if (strcasecmp(config_method, "PBC") == 0)
12810 dut->wps_method = WFA_CS_WPS_PBC;
12811 }
12812 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
12813 send_resp(dut, conn, SIGMA_ERROR,
12814 "ErrorCode,WPS parameters not yet set");
12815 return STATUS_SENT;
12816 }
12817
12818 /* Make sure WPS is enabled (also for STA mode) */
12819 dut->wps_disable = 0;
12820
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012821 if (dut->band == WPS_BAND_60G && network_mode &&
12822 strcasecmp(network_mode, "PBSS") == 0) {
12823 sigma_dut_print(dut, DUT_MSG_DEBUG,
12824 "Set PBSS network mode, network id %d", id);
12825 if (set_network(get_station_ifname(), id, "pbss", "1") < 0)
12826 return -2;
12827 }
12828
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012829 if (dut->force_rsn_ie) {
12830 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
12831 dut->force_rsn_ie);
12832 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
12833 sigma_dut_print(dut, DUT_MSG_INFO,
12834 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012835 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012836 }
12837 }
12838
vamsi krishna9b144002017-09-20 13:28:13 +053012839 ctrl = open_wpa_mon(intf);
12840 if (!ctrl) {
12841 sigma_dut_print(dut, DUT_MSG_ERROR,
12842 "Failed to open wpa_supplicant monitor connection");
12843 return -2;
12844 }
12845
12846 role = get_param(cmd, "WpsRole");
12847 if (!role) {
12848 send_resp(dut, conn, SIGMA_INVALID,
12849 "ErrorCode,WpsRole not provided");
12850 goto fail;
12851 }
12852
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012853 if (strcasecmp(role, "Enrollee") != 0) {
12854 /* Registrar role for STA not supported */
12855 send_resp(dut, conn, SIGMA_ERROR,
12856 "ErrorCode,Unsupported WpsRole value");
12857 goto fail;
12858 }
12859
12860 if (is_60g_sigma_dut(dut)) {
12861 if (dut->wps_method == WFA_CS_WPS_PBC)
12862 snprintf(buf, sizeof(buf), "WPS_PBC");
12863 else /* WFA_CS_WPS_PIN_KEYPAD */
12864 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
12865 dut->wps_pin);
12866 if (wpa_command(intf, buf) < 0) {
12867 send_resp(dut, conn, SIGMA_ERROR,
12868 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053012869 goto fail;
12870 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012871 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12872 if (res < 0) {
12873 send_resp(dut, conn, SIGMA_ERROR,
12874 "ErrorCode,WPS connection did not complete");
12875 goto fail;
12876 }
12877 if (strstr(buf, "WPS-TIMEOUT")) {
12878 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
12879 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
12880 send_resp(dut, conn, SIGMA_COMPLETE,
12881 "WpsState,OverlapSession");
12882 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
12883 send_resp(dut, conn, SIGMA_COMPLETE,
12884 "WpsState,Successful");
12885 } else {
12886 send_resp(dut, conn, SIGMA_COMPLETE,
12887 "WpsState,Failure");
12888 }
12889 } else {
12890 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053012891 if (wpa_command(intf, "WPS_PBC") < 0) {
12892 send_resp(dut, conn, SIGMA_ERROR,
12893 "ErrorCode,Failed to enable PBC");
12894 goto fail;
12895 }
12896 } else {
12897 /* TODO: PIN method */
12898 send_resp(dut, conn, SIGMA_ERROR,
12899 "ErrorCode,Unsupported WpsConfigMethod value");
12900 goto fail;
12901 }
12902 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12903 if (res < 0) {
12904 send_resp(dut, conn, SIGMA_ERROR,
12905 "ErrorCode,WPS connection did not complete");
12906 goto fail;
12907 }
12908 if (strstr(buf, "WPS-TIMEOUT")) {
12909 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
12910 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
12911 send_resp(dut, conn, SIGMA_ERROR,
12912 "ErrorCode,OverlapSession");
12913 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
12914 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
12915 } else {
12916 send_resp(dut, conn, SIGMA_ERROR,
12917 "ErrorCode,WPS operation failed");
12918 }
vamsi krishna9b144002017-09-20 13:28:13 +053012919 }
12920
12921fail:
12922 wpa_ctrl_detach(ctrl);
12923 wpa_ctrl_close(ctrl);
12924 return 0;
12925}
12926
12927
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012928static int req_intf(struct sigma_cmd *cmd)
12929{
12930 return get_param(cmd, "interface") == NULL ? -1 : 0;
12931}
12932
12933
12934void sta_register_cmds(void)
12935{
12936 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
12937 cmd_sta_get_ip_config);
12938 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
12939 cmd_sta_set_ip_config);
12940 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
12941 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
12942 cmd_sta_get_mac_address);
12943 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
12944 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
12945 cmd_sta_verify_ip_connection);
12946 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
12947 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
12948 cmd_sta_set_encryption);
12949 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
12950 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
12951 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
12952 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
12953 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
12954 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
12955 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
12956 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
12957 cmd_sta_set_eapakaprime);
12958 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
12959 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
12960 /* TODO: sta_set_ibss */
12961 /* TODO: sta_set_mode */
12962 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
12963 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
12964 /* TODO: sta_up_load */
12965 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
12966 cmd_sta_preset_testparameters);
12967 /* TODO: sta_set_system */
12968 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
12969 /* TODO: sta_set_rifs_test */
12970 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
12971 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
12972 /* TODO: sta_send_coexist_mgmt */
12973 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
12974 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
12975 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
12976 sigma_dut_reg_cmd("sta_reset_default", req_intf,
12977 cmd_sta_reset_default);
12978 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
12979 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
12980 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
12981 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
12982 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012983 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012984 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
12985 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
12986 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
12987 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
12988 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012989 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
12990 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012991 sigma_dut_reg_cmd("sta_add_credential", req_intf,
12992 cmd_sta_add_credential);
12993 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012994 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012995 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
12996 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
12997 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
12998 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
12999 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13000 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013001 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013002 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13003 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013004 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013005 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013006}