blob: 35f3d7cd7c29ebda4de314a12c13270130fe10dc [file] [log] [blame]
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001/*
2 * Sigma Control API DUT (station/AP)
3 * Copyright (c) 2010-2011, Atheros Communications, Inc.
Jouni Malinen9d7e31d2017-12-22 18:55:04 +02004 * Copyright (c) 2011-2017, Qualcomm Atheros, Inc.
Jouni Malinenc12ea4a2018-01-05 21:07:10 +02005 * Copyright (c) 2018, The Linux Foundation
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006 * All Rights Reserved.
7 * Licensed under the Clear BSD license. See README for more details.
8 */
9
10#include "sigma_dut.h"
11#include <sys/ioctl.h>
12#include <sys/stat.h>
Jouni Malinen82905202018-04-29 17:20:10 +030013#include <sys/wait.h>
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030014#include <ctype.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020016#include <regex.h>
17#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020018#include <sys/time.h>
19#include <netpacket/packet.h>
20#include <linux/if_ether.h>
21#ifdef ANDROID
22#include <cutils/properties.h>
23#include <android/log.h>
24#include "keystore_get.h"
25#else /* ANDROID */
26#include <ifaddrs.h>
27#endif /* ANDROID */
28#include <netdb.h>
29#endif /* __linux__ */
30#ifdef __QNXNTO__
31#include <net/if_dl.h>
32#endif /* __QNXNTO__ */
33#include "wpa_ctrl.h"
34#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070035#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070036#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020037
38/* Temporary files for sta_send_addba */
39#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
40#define VI_QOS_FILE "/tmp/vi-qos.txt"
41#define VI_QOS_REFFILE "/etc/vi-qos.txt"
42
43/*
44 * MTU for Ethernet need to take into account 8-byte SNAP header
45 * to be added when encapsulating Ethernet frame into 802.11
46 */
47#ifndef IEEE80211_MAX_DATA_LEN_DMG
48#define IEEE80211_MAX_DATA_LEN_DMG 7920
49#endif
50#ifndef IEEE80211_SNAP_LEN_DMG
51#define IEEE80211_SNAP_LEN_DMG 8
52#endif
53
Ashwini Patil00402582017-04-13 12:29:39 +053054#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053055#define NEIGHBOR_REPORT_SIZE 1000
56#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
57#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053058
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030059#define WIL_DEFAULT_BI 100
60
61/* default remain on channel time for transmitting frames (milliseconds) */
62#define WIL_TRANSMIT_FRAME_DEFAULT_ROC 500
63#define IEEE80211_P2P_ATTR_DEVICE_ID 3
64#define IEEE80211_P2P_ATTR_GROUP_ID 15
65
66/* describes tagged bytes in template frame file */
67struct template_frame_tag {
68 int num;
69 int offset;
70 size_t len;
71};
72
Jouni Malinencd4e3c32015-10-29 12:39:56 +020073extern char *sigma_wpas_ctrl;
74extern char *sigma_cert_path;
75extern enum driver_type wifi_chip_type;
76extern char *sigma_radio_ifname[];
77
Lior David0fe101e2017-03-09 16:09:50 +020078#ifdef __linux__
79#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020080#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020081#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020082#define WIL_WMI_UNIT_TEST_CMDID 0x900
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030083#define WIL_WMI_P2P_CFG_CMDID 0x910
84#define WIL_WMI_START_LISTEN_CMDID 0x914
85#define WIL_WMI_DISCOVERY_STOP_CMDID 0x917
Lior David0fe101e2017-03-09 16:09:50 +020086
87struct wil_wmi_header {
88 uint8_t mid;
89 uint8_t reserved;
90 uint16_t cmd;
91 uint32_t ts;
92} __attribute__((packed));
93
94enum wil_wmi_bf_trig_type {
95 WIL_WMI_SLS,
96 WIL_WMI_BRP_RX,
97 WIL_WMI_BRP_TX,
98};
99
100struct wil_wmi_bf_trig_cmd {
101 /* enum wil_wmi_bf_trig_type */
102 uint32_t bf_type;
103 /* cid when type == WMI_BRP_RX */
104 uint32_t sta_id;
105 uint32_t reserved;
106 /* mac address when type = WIL_WMI_SLS */
107 uint8_t dest_mac[6];
108} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200109
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200110enum wil_wmi_sched_scheme_advertisment {
111 WIL_WMI_ADVERTISE_ESE_DISABLED,
112 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
113 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
114};
115
116enum wil_wmi_ese_slot_type {
117 WIL_WMI_ESE_SP,
118 WIL_WMI_ESE_CBAP,
119 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
120};
121
122struct wil_wmi_ese_slot {
123 /* offset from start of BI in microseconds */
124 uint32_t tbtt_offset;
125 uint8_t flags;
126 /* enum wil_wmi_ese_slot_type */
127 uint8_t slot_type;
128 /* duration in microseconds */
129 uint16_t duration;
130 /* frame exchange sequence duration, microseconds */
131 uint16_t tx_op;
132 /* time between 2 blocks for periodic allocation(microseconds) */
133 uint16_t period;
134 /* number of blocks in periodic allocation */
135 uint8_t num_blocks;
136 /* for semi-active allocations */
137 uint8_t idle_period;
138 uint8_t src_aid;
139 uint8_t dst_aid;
140 uint32_t reserved;
141} __attribute__((packed));
142
143#define WIL_WMI_MAX_ESE_SLOTS 4
144struct wil_wmi_ese_cfg {
145 uint8_t serial_num;
146 /* wil_wmi_sched_scheme_advertisment */
147 uint8_t ese_advertisment;
148 uint16_t flags;
149 uint8_t num_allocs;
150 uint8_t reserved[3];
151 uint64_t start_tbtt;
152 /* allocations list */
153 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
154} __attribute__((packed));
155
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200156#define WIL_WMI_UT_FORCE_MCS 6
157struct wil_wmi_force_mcs {
158 /* WIL_WMI_UT_HW_SYSAPI */
159 uint16_t module_id;
160 /* WIL_WMI_UT_FORCE_MCS */
161 uint16_t subtype_id;
162 /* cid (ignored in oob_mode, affects all stations) */
163 uint32_t cid;
164 /* 1 to force MCS, 0 to restore default behavior */
165 uint32_t force_enable;
166 /* MCS index, 0-12 */
167 uint32_t mcs;
168} __attribute__((packed));
169
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200170#define WIL_WMI_UT_HW_SYSAPI 10
171#define WIL_WMI_UT_FORCE_RSN_IE 0x29
172struct wil_wmi_force_rsn_ie {
173 /* WIL_WMI_UT_HW_SYSAPI */
174 uint16_t module_id;
175 /* WIL_WMI_UT_FORCE_RSN_IE */
176 uint16_t subtype_id;
177 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
178 uint32_t state;
179} __attribute__((packed));
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300180
181enum wil_wmi_discovery_mode {
182 WMI_DISCOVERY_MODE_NON_OFFLOAD,
183 WMI_DISCOVERY_MODE_OFFLOAD,
184 WMI_DISCOVERY_MODE_PEER2PEER,
185};
186
187struct wil_wmi_p2p_cfg_cmd {
188 /* enum wil_wmi_discovery_mode */
189 uint8_t discovery_mode;
190 /* 0-based (wireless channel - 1) */
191 uint8_t channel;
192 /* set to WIL_DEFAULT_BI */
193 uint16_t bcon_interval;
194} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200195#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200196
197#ifdef ANDROID
198
199static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
200
201#define ANDROID_KEYSTORE_GET 'g'
202#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
203
204static int android_keystore_get(char cmd, const char *key, unsigned char *val)
205{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200206 /* Android 4.3 changed keystore design, so need to use keystore_get() */
207#ifndef KEYSTORE_MESSAGE_SIZE
208#define KEYSTORE_MESSAGE_SIZE 65535
209#endif /* KEYSTORE_MESSAGE_SIZE */
210
211 ssize_t len;
212 uint8_t *value = NULL;
213
214 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
215 "keystore command '%c' key '%s' --> keystore_get",
216 cmd, key);
217
218 len = keystore_get(key, strlen(key), &value);
219 if (len < 0) {
220 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
221 "keystore_get() failed");
222 return -1;
223 }
224
225 if (len > KEYSTORE_MESSAGE_SIZE)
226 len = KEYSTORE_MESSAGE_SIZE;
227 memcpy(val, value, len);
228 free(value);
229 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200230}
231#endif /* ANDROID */
232
233
234int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
235{
236#ifdef __linux__
237 char buf[100];
238
239 if (wifi_chip_type == DRIVER_WCN) {
240 if (enabled) {
241 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530242 if (system(buf) != 0)
243 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200244 } else {
245 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530246 if (system(buf) != 0)
247 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200248 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530249 if (system(buf) != 0)
250 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200251 }
252
253 return 0;
254 }
255
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530256set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200257 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
258 intf, enabled ? "on" : "off");
259 if (system(buf) != 0) {
260 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
261 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530262 if (system(buf) != 0) {
263 sigma_dut_print(dut, DUT_MSG_ERROR,
264 "Failed to set power save %s",
265 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200266 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530267 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200268 }
269
270 return 0;
271#else /* __linux__ */
272 return -1;
273#endif /* __linux__ */
274}
275
276
Lior Davidcc88b562017-01-03 18:52:09 +0200277#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200278
Lior Davidcc88b562017-01-03 18:52:09 +0200279static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
280 size_t len)
281{
282 DIR *dir, *wil_dir;
283 struct dirent *entry;
284 int ret = -1;
285 const char *root_path = "/sys/kernel/debug/ieee80211";
286
287 dir = opendir(root_path);
288 if (!dir)
289 return -2;
290
291 while ((entry = readdir(dir))) {
292 if (strcmp(entry->d_name, ".") == 0 ||
293 strcmp(entry->d_name, "..") == 0)
294 continue;
295
296 if (snprintf(path, len, "%s/%s/wil6210",
297 root_path, entry->d_name) >= (int) len) {
298 ret = -3;
299 break;
300 }
301
302 wil_dir = opendir(path);
303 if (wil_dir) {
304 closedir(wil_dir);
305 ret = 0;
306 break;
307 }
308 }
309
310 closedir(dir);
311 return ret;
312}
Lior David0fe101e2017-03-09 16:09:50 +0200313
314
315static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
316 void *payload, uint16_t length)
317{
318 struct {
319 struct wil_wmi_header hdr;
320 char payload[WIL_WMI_MAX_PAYLOAD];
321 } __attribute__((packed)) cmd;
322 char buf[128], fname[128];
323 size_t towrite, written;
324 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300325 int res;
Lior David0fe101e2017-03-09 16:09:50 +0200326
327 if (length > WIL_WMI_MAX_PAYLOAD) {
328 sigma_dut_print(dut, DUT_MSG_ERROR,
329 "payload too large(%u, max %u)",
330 length, WIL_WMI_MAX_PAYLOAD);
331 return -1;
332 }
333
334 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
335 cmd.hdr.cmd = command;
336 memcpy(cmd.payload, payload, length);
337
338 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
339 sigma_dut_print(dut, DUT_MSG_ERROR,
340 "failed to get wil6210 debugfs dir");
341 return -1;
342 }
343
Jouni Malinen3aa72862019-05-29 23:14:51 +0300344 res = snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
345 if (res < 0 || res >= sizeof(fname))
346 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200347 f = fopen(fname, "wb");
348 if (!f) {
349 sigma_dut_print(dut, DUT_MSG_ERROR,
350 "failed to open: %s", fname);
351 return -1;
352 }
353
354 towrite = sizeof(cmd.hdr) + length;
355 written = fwrite(&cmd, 1, towrite, f);
356 fclose(f);
357 if (written != towrite) {
358 sigma_dut_print(dut, DUT_MSG_ERROR,
359 "failed to send wmi %u", command);
360 return -1;
361 }
362
363 return 0;
364}
365
366
367static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
368 const char *pattern, unsigned int *field)
369{
370 char buf[128], fname[128];
371 FILE *f;
372 regex_t re;
373 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +0300374 int rc, ret = -1, res;
Lior David0fe101e2017-03-09 16:09:50 +0200375
376 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
377 sigma_dut_print(dut, DUT_MSG_ERROR,
378 "failed to get wil6210 debugfs dir");
379 return -1;
380 }
381
Jouni Malinen3aa72862019-05-29 23:14:51 +0300382 res = snprintf(fname, sizeof(fname), "%s/stations", buf);
383 if (res < 0 || res >= sizeof(fname))
384 return -1;
Lior David0fe101e2017-03-09 16:09:50 +0200385 f = fopen(fname, "r");
386 if (!f) {
387 sigma_dut_print(dut, DUT_MSG_ERROR,
388 "failed to open: %s", fname);
389 return -1;
390 }
391
392 if (regcomp(&re, pattern, REG_EXTENDED)) {
393 sigma_dut_print(dut, DUT_MSG_ERROR,
394 "regcomp failed: %s", pattern);
395 goto out;
396 }
397
398 /*
399 * find the entry for the mac address
400 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
401 */
402 while (fgets(buf, sizeof(buf), f)) {
403 if (strcasestr(buf, bssid)) {
404 /* extract the field (CID/AID/state) */
405 rc = regexec(&re, buf, 2, m, 0);
406 if (!rc && (m[1].rm_so >= 0)) {
407 buf[m[1].rm_eo] = 0;
408 *field = atoi(&buf[m[1].rm_so]);
409 ret = 0;
410 break;
411 }
412 }
413 }
414
415 regfree(&re);
416 if (ret)
417 sigma_dut_print(dut, DUT_MSG_ERROR,
418 "could not extract field");
419
420out:
421 fclose(f);
422
423 return ret;
424}
425
426
427static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
428 unsigned int *cid)
429{
430 const char *pattern = "\\[([0-9]+)\\]";
431
432 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
433}
434
435
436static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
437 int l_rx)
438{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700439 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200440 unsigned int cid;
441
Rakesh Sunki556237d2017-03-30 14:49:31 -0700442 memset(&cmd, 0, sizeof(cmd));
443
Lior David0fe101e2017-03-09 16:09:50 +0200444 if (wil6210_get_cid(dut, mac, &cid))
445 return -1;
446
447 cmd.bf_type = WIL_WMI_BRP_RX;
448 cmd.sta_id = cid;
449 /* training length (l_rx) is ignored, FW always uses length 16 */
450 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
451 &cmd, sizeof(cmd));
452}
453
454
455static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
456{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700457 struct wil_wmi_bf_trig_cmd cmd;
458
459 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200460
461 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
462 return -1;
463
464 cmd.bf_type = WIL_WMI_SLS;
465 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
466 &cmd, sizeof(cmd));
467}
468
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200469
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200470int wil6210_set_ese(struct sigma_dut *dut, int count,
471 struct sigma_ese_alloc *allocs)
472{
473 struct wil_wmi_ese_cfg cmd = { };
474 int i;
475
476 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
477 return -1;
478
479 if (dut->ap_bcnint <= 0) {
480 sigma_dut_print(dut, DUT_MSG_ERROR,
481 "invalid beacon interval(%d), check test",
482 dut->ap_bcnint);
483 return -1;
484 }
485
486 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
487 cmd.flags = 0x1d;
488 cmd.num_allocs = count;
489 for (i = 0; i < count; i++) {
490 /*
491 * Convert percent from BI (BI specified in milliseconds)
492 * to absolute duration in microseconds.
493 */
494 cmd.slots[i].duration =
495 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
496 switch (allocs[i].type) {
497 case ESE_CBAP:
498 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
499 break;
500 case ESE_SP:
501 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
502 break;
503 default:
504 sigma_dut_print(dut, DUT_MSG_ERROR,
505 "invalid slot type(%d) at index %d",
506 allocs[i].type, i);
507 return -1;
508 }
509 cmd.slots[i].src_aid = allocs[i].src_aid;
510 cmd.slots[i].dst_aid = allocs[i].dst_aid;
511 sigma_dut_print(dut, DUT_MSG_INFO,
512 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
513 i, cmd.slots[i].duration,
514 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
515 cmd.slots[i].dst_aid);
516 }
517
518 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
519}
520
521
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200522int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
523{
524 struct wil_wmi_force_mcs cmd = { };
525
526 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
527 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
528 cmd.force_enable = (uint32_t) force;
529 cmd.mcs = (uint32_t) mcs;
530
531 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
532 &cmd, sizeof(cmd));
533}
534
535
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200536static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
537{
538 struct wil_wmi_force_rsn_ie cmd = { };
539
540 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
541 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
542 cmd.state = (uint32_t) state;
543
544 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
545 &cmd, sizeof(cmd));
546}
547
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300548
549/*
550 * this function is also used to configure generic remain-on-channel
551 */
552static int wil6210_p2p_cfg(struct sigma_dut *dut, int freq)
553{
554 struct wil_wmi_p2p_cfg_cmd cmd = { };
555 int channel = freq_to_channel(freq);
556
557 if (channel < 0)
558 return -1;
559 cmd.discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD;
560 cmd.channel = channel - 1;
561 cmd.bcon_interval = WIL_DEFAULT_BI;
562 cmd.discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER;
563
564 return wil6210_wmi_send(dut, WIL_WMI_P2P_CFG_CMDID,
565 &cmd, sizeof(cmd));
566}
567
568
569static int wil6210_remain_on_channel(struct sigma_dut *dut, int freq)
570{
571 int ret = wil6210_p2p_cfg(dut, freq);
572
573 if (ret)
574 return ret;
575
576 ret = wil6210_wmi_send(dut, WIL_WMI_START_LISTEN_CMDID, NULL, 0);
577 if (!ret) {
578 /*
579 * wait a bit to allow FW to setup the radio
580 * especially important if we switch channels
581 */
582 usleep(500000);
583 }
584
585 return ret;
586}
587
588
589static int wil6210_stop_discovery(struct sigma_dut *dut)
590{
591 return wil6210_wmi_send(dut, WIL_WMI_DISCOVERY_STOP_CMDID, NULL, 0);
592}
593
594
595static int wil6210_transmit_frame(struct sigma_dut *dut, int freq,
596 int wait_duration,
597 const char *frame, size_t frame_len)
598{
599 char buf[128], fname[128];
600 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +0300601 int res = 0, r;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300602 size_t written;
603
604 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
605 sigma_dut_print(dut, DUT_MSG_ERROR,
606 "failed to get wil6210 debugfs dir");
607 return -1;
608 }
Jouni Malinen3aa72862019-05-29 23:14:51 +0300609 r = snprintf(fname, sizeof(fname), "%s/tx_mgmt", buf);
610 if (r < 0 || r >= sizeof(fname))
611 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +0300612
613 if (wil6210_remain_on_channel(dut, freq)) {
614 sigma_dut_print(dut, DUT_MSG_ERROR,
615 "failed to listen on channel");
616 return -1;
617 }
618
619 f = fopen(fname, "wb");
620 if (!f) {
621 sigma_dut_print(dut, DUT_MSG_ERROR,
622 "failed to open: %s", fname);
623 res = -1;
624 goto out_stop;
625 }
626 written = fwrite(frame, 1, frame_len, f);
627 fclose(f);
628
629 if (written != frame_len) {
630 sigma_dut_print(dut, DUT_MSG_ERROR,
631 "failed to transmit frame (got %zd, expected %zd)",
632 written, frame_len);
633 res = -1;
634 goto out_stop;
635 }
636
637 usleep(wait_duration * 1000);
638
639out_stop:
640 wil6210_stop_discovery(dut);
641 return res;
642}
643
644
645static int find_template_frame_tag(struct template_frame_tag *tags,
646 int total_tags, int tag_num)
647{
648 int i;
649
650 for (i = 0; i < total_tags; i++) {
651 if (tag_num == tags[i].num)
652 return i;
653 }
654
655 return -1;
656}
657
658
659static int replace_p2p_attribute(struct sigma_dut *dut, char *buf, size_t len,
660 int id, const char *value, size_t val_len)
661{
662 struct wfa_p2p_attribute *attr = (struct wfa_p2p_attribute *) buf;
663
664 if (len < 3 + val_len) {
665 sigma_dut_print(dut, DUT_MSG_ERROR,
666 "not enough space to replace P2P attribute");
667 return -1;
668 }
669
670 if (attr->len != val_len) {
671 sigma_dut_print(dut, DUT_MSG_ERROR,
672 "attribute length mismatch (need %zu have %hu)",
673 val_len, attr->len);
674 return -1;
675 }
676
677 if (attr->id != id) {
678 sigma_dut_print(dut, DUT_MSG_ERROR,
679 "incorrect attribute id (expected %d actual %d)",
680 id, attr->id);
681 return -1;
682 }
683
684 memcpy(attr->variable, value, val_len);
685
686 return 0;
687}
688
689
690static int parse_template_frame_file(struct sigma_dut *dut, const char *fname,
691 char *buf, size_t *length,
692 struct template_frame_tag *tags,
693 size_t *num_tags)
694{
695 char line[512];
696 FILE *f;
697 size_t offset = 0, tag_index = 0;
698 int num, index;
699 int in_tag = 0, tag_num = 0, tag_offset = 0;
700
701 if (*length < sizeof(struct ieee80211_hdr_3addr)) {
702 sigma_dut_print(dut, DUT_MSG_ERROR,
703 "supplied buffer is too small");
704 return -1;
705 }
706
707 f = fopen(fname, "r");
708 if (!f) {
709 sigma_dut_print(dut, DUT_MSG_ERROR,
710 "failed to open template file %s", fname);
711 return -1;
712 }
713
714 /*
715 * template file format: lines beginning with # are comments and
716 * ignored.
717 * It is possible to tag bytes in the frame to make it easy
718 * to replace fields in the template, espcially if they appear
719 * in variable-sized sections (such as IEs)
720 * This is done by a line beginning with $NUM where NUM is an integer
721 * tag number. It can be followed by space(s) and comment.
722 * The next line is considered the tagged bytes. The parser will fill
723 * the tag number, offset and length of the tagged bytes.
724 * rest of the lines contain frame bytes as sequence of hex digits,
725 * 2 digits for each byte. Spaces are allowed between bytes.
726 * On bytes lines only hex digits and spaces are allowed
727 */
728 while (!feof(f)) {
729 if (!fgets(line, sizeof(line), f))
730 break;
731 index = 0;
732 while (isspace((unsigned char) line[index]))
733 index++;
734 if (!line[index] || line[index] == '#')
735 continue;
736 if (line[index] == '$') {
737 if (tags) {
738 index++;
739 tag_num = strtol(&line[index], NULL, 0);
740 tag_offset = offset;
741 in_tag = 1;
742 }
743 continue;
744 }
745 while (line[index]) {
746 if (isspace((unsigned char) line[index])) {
747 index++;
748 continue;
749 }
750 num = hex_byte(&line[index]);
751 if (num < 0)
752 break;
753 buf[offset++] = num;
754 if (offset == *length)
755 goto out;
756 index += 2;
757 }
758
759 if (in_tag) {
760 if (tag_index < *num_tags) {
761 tags[tag_index].num = tag_num;
762 tags[tag_index].offset = tag_offset;
763 tags[tag_index].len = offset - tag_offset;
764 tag_index++;
765 } else {
766 sigma_dut_print(dut, DUT_MSG_INFO,
767 "too many tags, tag ignored");
768 }
769 in_tag = 0;
770 }
771 }
772
773 if (num_tags)
774 *num_tags = tag_index;
775out:
776 fclose(f);
777 if (offset < sizeof(struct ieee80211_hdr_3addr)) {
778 sigma_dut_print(dut, DUT_MSG_ERROR,
779 "template frame is too small");
780 return -1;
781 }
782
783 *length = offset;
784 return 0;
785}
786
Lior Davidcc88b562017-01-03 18:52:09 +0200787#endif /* __linux__ */
788
789
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200790static void static_ip_file(int proto, const char *addr, const char *mask,
791 const char *gw)
792{
793 if (proto) {
794 FILE *f = fopen("static-ip", "w");
795 if (f) {
796 fprintf(f, "%d %s %s %s\n", proto, addr,
797 mask ? mask : "N/A",
798 gw ? gw : "N/A");
799 fclose(f);
800 }
801 } else {
802 unlink("static-ip");
803 }
804}
805
806
807static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
808 const char *ssid)
809{
810#ifdef __linux__
811 char buf[100];
812
813 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
814 intf, ssid);
815 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
816
817 if (system(buf) != 0) {
818 sigma_dut_print(dut, DUT_MSG_ERROR,
819 "iwpriv neighbor request failed");
820 return -1;
821 }
822
823 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
824
825 return 0;
826#else /* __linux__ */
827 return -1;
828#endif /* __linux__ */
829}
830
831
832static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530833 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200834{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530835 const char *val;
836 int reason_code = 0;
837 char buf[1024];
838
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200839 /*
840 * In the earlier builds we used WNM_QUERY and in later
841 * builds used WNM_BSS_QUERY.
842 */
843
Ashwini Patil5acd7382017-04-13 15:55:04 +0530844 val = get_param(cmd, "BTMQuery_Reason_Code");
845 if (val)
846 reason_code = atoi(val);
847
848 val = get_param(cmd, "Cand_List");
849 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
850 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
851 dut->btm_query_cand_list);
852 free(dut->btm_query_cand_list);
853 dut->btm_query_cand_list = NULL;
854 } else {
855 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
856 }
857
858 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200859 sigma_dut_print(dut, DUT_MSG_ERROR,
860 "transition management query failed");
861 return -1;
862 }
863
864 sigma_dut_print(dut, DUT_MSG_DEBUG,
865 "transition management query sent");
866
867 return 0;
868}
869
870
871int is_ip_addr(const char *str)
872{
873 const char *pos = str;
874 struct in_addr addr;
875
876 while (*pos) {
877 if (*pos != '.' && (*pos < '0' || *pos > '9'))
878 return 0;
879 pos++;
880 }
881
882 return inet_aton(str, &addr);
883}
884
885
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200886int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
887 size_t buf_len)
888{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530889 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200890 char ip[16], mask[15], dns[16], sec_dns[16];
891 int is_dhcp = 0;
892 int s;
893#ifdef ANDROID
894 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530895#else /* ANDROID */
896 FILE *f;
897#ifdef __linux__
898 const char *str_ps;
899#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200900#endif /* ANDROID */
901
902 ip[0] = '\0';
903 mask[0] = '\0';
904 dns[0] = '\0';
905 sec_dns[0] = '\0';
906
907 s = socket(PF_INET, SOCK_DGRAM, 0);
908 if (s >= 0) {
909 struct ifreq ifr;
910 struct sockaddr_in saddr;
911
912 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700913 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200914 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
915 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
916 "%s IP address: %s",
917 ifname, strerror(errno));
918 } else {
919 memcpy(&saddr, &ifr.ifr_addr,
920 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700921 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200922 }
923
924 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
925 memcpy(&saddr, &ifr.ifr_addr,
926 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700927 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200928 }
929 close(s);
930 }
931
932#ifdef ANDROID
933 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
934 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
935 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
936 if (property_get(tmp, prop, NULL) != 0 &&
937 strcmp(prop, "ok") == 0) {
938 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
939 ifname);
940 if (property_get(tmp, prop, NULL) != 0 &&
941 strcmp(ip, prop) == 0)
942 is_dhcp = 1;
943 }
944 }
945
946 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700947 if (property_get(tmp, prop, NULL) != 0)
948 strlcpy(dns, prop, sizeof(dns));
949 else if (property_get("net.dns1", prop, NULL) != 0)
950 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200951
952 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700953 if (property_get(tmp, prop, NULL) != 0)
954 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200955#else /* ANDROID */
956#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530957 if (get_driver_type() == DRIVER_OPENWRT)
958 str_ps = "ps -w";
959 else
960 str_ps = "ps ax";
961 snprintf(tmp, sizeof(tmp),
962 "%s | grep dhclient | grep -v grep | grep -q %s",
963 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200964 if (system(tmp) == 0)
965 is_dhcp = 1;
966 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530967 snprintf(tmp, sizeof(tmp),
968 "%s | grep udhcpc | grep -v grep | grep -q %s",
969 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200970 if (system(tmp) == 0)
971 is_dhcp = 1;
972 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530973 snprintf(tmp, sizeof(tmp),
974 "%s | grep dhcpcd | grep -v grep | grep -q %s",
975 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200976 if (system(tmp) == 0)
977 is_dhcp = 1;
978 }
979 }
980#endif /* __linux__ */
981
982 f = fopen("/etc/resolv.conf", "r");
983 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530984 char *pos, *pos2;
985
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200986 while (fgets(tmp, sizeof(tmp), f)) {
987 if (strncmp(tmp, "nameserver", 10) != 0)
988 continue;
989 pos = tmp + 10;
990 while (*pos == ' ' || *pos == '\t')
991 pos++;
992 pos2 = pos;
993 while (*pos2) {
994 if (*pos2 == '\n' || *pos2 == '\r') {
995 *pos2 = '\0';
996 break;
997 }
998 pos2++;
999 }
Peng Xub8fc5cc2017-05-10 17:27:28 -07001000 if (!dns[0])
1001 strlcpy(dns, pos, sizeof(dns));
1002 else if (!sec_dns[0])
1003 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001004 }
1005 fclose(f);
1006 }
1007#endif /* ANDROID */
1008
1009 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
1010 is_dhcp, ip, mask, dns);
1011 buf[buf_len - 1] = '\0';
1012
1013 return 0;
1014}
1015
1016
1017
1018
1019int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
1020 size_t buf_len)
1021{
1022#ifdef __linux__
1023#ifdef ANDROID
1024 char cmd[200], result[1000], *pos, *end;
1025 FILE *f;
1026 size_t len;
1027
1028 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
1029 f = popen(cmd, "r");
1030 if (f == NULL)
1031 return -1;
1032 len = fread(result, 1, sizeof(result) - 1, f);
1033 pclose(f);
1034 if (len == 0)
1035 return -1;
1036 result[len] = '\0';
1037 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
1038
1039 pos = strstr(result, "inet6 ");
1040 if (pos == NULL)
1041 return -1;
1042 pos += 6;
1043 end = strchr(pos, ' ');
1044 if (end)
1045 *end = '\0';
1046 end = strchr(pos, '/');
1047 if (end)
1048 *end = '\0';
1049 snprintf(buf, buf_len, "ip,%s", pos);
1050 buf[buf_len - 1] = '\0';
1051 return 0;
1052#else /* ANDROID */
1053 struct ifaddrs *ifaddr, *ifa;
1054 int res, found = 0;
1055 char host[NI_MAXHOST];
1056
1057 if (getifaddrs(&ifaddr) < 0) {
1058 perror("getifaddrs");
1059 return -1;
1060 }
1061
1062 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
1063 if (strcasecmp(ifname, ifa->ifa_name) != 0)
1064 continue;
1065 if (ifa->ifa_addr == NULL ||
1066 ifa->ifa_addr->sa_family != AF_INET6)
1067 continue;
1068
1069 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
1070 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
1071 if (res != 0) {
1072 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
1073 gai_strerror(res));
1074 continue;
1075 }
1076 if (strncmp(host, "fe80::", 6) == 0)
1077 continue; /* skip link-local */
1078
1079 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
1080 found = 1;
1081 break;
1082 }
1083
1084 freeifaddrs(ifaddr);
1085
1086 if (found) {
1087 char *pos;
1088 pos = strchr(host, '%');
1089 if (pos)
1090 *pos = '\0';
1091 snprintf(buf, buf_len, "ip,%s", host);
1092 buf[buf_len - 1] = '\0';
1093 return 0;
1094 }
1095
1096#endif /* ANDROID */
1097#endif /* __linux__ */
1098 return -1;
1099}
1100
1101
Jouni Malinenf7222712019-06-13 01:50:21 +03001102static enum sigma_cmd_result cmd_sta_get_ip_config(struct sigma_dut *dut,
1103 struct sigma_conn *conn,
1104 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001105{
1106 const char *intf = get_param(cmd, "Interface");
1107 const char *ifname;
1108 char buf[200];
1109 const char *val;
1110 int type = 1;
1111
1112 if (intf == NULL)
1113 return -1;
1114
1115 if (strcmp(intf, get_main_ifname()) == 0)
1116 ifname = get_station_ifname();
1117 else
1118 ifname = intf;
1119
1120 /*
1121 * UCC may assume the IP address to be available immediately after
1122 * association without trying to run sta_get_ip_config multiple times.
1123 * Sigma CAPI does not specify this command as a block command that
1124 * would wait for the address to become available, but to pass tests
1125 * more reliably, it looks like such a wait may be needed here.
1126 */
1127 if (wait_ip_addr(dut, ifname, 15) < 0) {
1128 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
1129 "for sta_get_ip_config");
1130 /*
1131 * Try to continue anyway since many UCC tests do not really
1132 * care about the return value from here..
1133 */
1134 }
1135
1136 val = get_param(cmd, "Type");
1137 if (val)
1138 type = atoi(val);
1139 if (type == 2 || dut->last_set_ip_config_ipv6) {
1140 int i;
1141
1142 /*
1143 * Since we do not have proper wait for IPv6 addresses, use a
1144 * fixed two second delay here as a workaround for UCC script
1145 * assuming IPv6 address is available when this command returns.
1146 * Some scripts did not use Type,2 properly for IPv6, so include
1147 * also the cases where the previous sta_set_ip_config indicated
1148 * use of IPv6.
1149 */
1150 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
1151 for (i = 0; i < 10; i++) {
1152 sleep(1);
1153 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
1154 {
1155 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
1156 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1157#ifdef ANDROID
1158 sigma_dut_print(dut, DUT_MSG_INFO,
1159 "Adding IPv6 rule on Android");
1160 add_ipv6_rule(dut, intf);
1161#endif /* ANDROID */
1162
1163 return 0;
1164 }
1165 }
1166 }
1167 if (type == 1) {
1168 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
1169 return -2;
1170 } else if (type == 2) {
1171 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
1172 return -2;
1173 } else {
1174 send_resp(dut, conn, SIGMA_ERROR,
1175 "errorCode,Unsupported address type");
1176 return 0;
1177 }
1178
1179 send_resp(dut, conn, SIGMA_COMPLETE, buf);
1180 return 0;
1181}
1182
1183
1184static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
1185{
1186#ifdef __linux__
1187 char buf[200];
1188 char path[128];
1189 struct stat s;
1190
1191#ifdef ANDROID
1192 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
1193#else /* ANDROID */
1194 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
1195#endif /* ANDROID */
1196 if (stat(path, &s) == 0) {
1197 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1198 sigma_dut_print(dut, DUT_MSG_INFO,
1199 "Kill previous DHCP client: %s", buf);
1200 if (system(buf) != 0)
1201 sigma_dut_print(dut, DUT_MSG_INFO,
1202 "Failed to kill DHCP client");
1203 unlink(path);
1204 sleep(1);
1205 } else {
1206 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
1207
1208 if (stat(path, &s) == 0) {
1209 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
1210 sigma_dut_print(dut, DUT_MSG_INFO,
1211 "Kill previous DHCP client: %s", buf);
1212 if (system(buf) != 0)
1213 sigma_dut_print(dut, DUT_MSG_INFO,
1214 "Failed to kill DHCP client");
1215 unlink(path);
1216 sleep(1);
1217 }
1218 }
1219#endif /* __linux__ */
1220}
1221
1222
1223static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
1224{
1225#ifdef __linux__
1226 char buf[200];
1227
1228#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301229 if (access("/system/bin/dhcpcd", F_OK) != -1) {
1230 snprintf(buf, sizeof(buf),
1231 "/system/bin/dhcpcd -b %s", ifname);
1232 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
1233 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
Ankita Bajaj8454e5d2019-04-05 16:04:55 +05301234 } else if (access("/vendor/bin/dhcpcd", F_OK) != -1) {
1235 snprintf(buf, sizeof(buf), "/vendor/bin/dhcpcd -b %s", ifname);
1236 } else if (access("/vendor/bin/dhcptool", F_OK) != -1) {
1237 snprintf(buf, sizeof(buf), "/vendor/bin/dhcptool %s", ifname);
Purushottam Kushwaha46d64262016-08-23 17:57:53 +05301238 } else {
1239 sigma_dut_print(dut, DUT_MSG_ERROR,
1240 "DHCP client program missing");
1241 return 0;
1242 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001243#else /* ANDROID */
1244 snprintf(buf, sizeof(buf),
1245 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
1246 ifname, ifname);
1247#endif /* ANDROID */
1248 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
1249 if (system(buf) != 0) {
1250 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
1251 if (system(buf) != 0) {
1252 sigma_dut_print(dut, DUT_MSG_INFO,
1253 "Failed to start DHCP client");
1254#ifndef ANDROID
1255 return -1;
1256#endif /* ANDROID */
1257 }
1258 }
1259#endif /* __linux__ */
1260
1261 return 0;
1262}
1263
1264
1265static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
1266{
1267#ifdef __linux__
1268 char buf[200];
1269
1270 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
1271 if (system(buf) != 0) {
1272 sigma_dut_print(dut, DUT_MSG_INFO,
1273 "Failed to clear IP addresses");
1274 return -1;
1275 }
1276#endif /* __linux__ */
1277
1278 return 0;
1279}
1280
1281
1282#ifdef ANDROID
1283static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1284{
1285 char cmd[200], *result, *pos;
1286 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301287 int tableid;
1288 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001289
1290 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1291 ifname);
1292 fp = popen(cmd, "r");
1293 if (fp == NULL)
1294 return -1;
1295
1296 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301297 if (result == NULL) {
1298 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001299 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301300 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001301
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301302 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001303 fclose(fp);
1304
1305 if (len == 0) {
1306 free(result);
1307 return -1;
1308 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301309 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001310
1311 pos = strstr(result, "table ");
1312 if (pos == NULL) {
1313 free(result);
1314 return -1;
1315 }
1316
1317 pos += strlen("table ");
1318 tableid = atoi(pos);
1319 if (tableid != 0) {
1320 if (system("ip -6 rule del prio 22000") != 0) {
1321 /* ignore any error */
1322 }
1323 snprintf(cmd, sizeof(cmd),
1324 "ip -6 rule add from all lookup %d prio 22000",
1325 tableid);
1326 if (system(cmd) != 0) {
1327 sigma_dut_print(dut, DUT_MSG_INFO,
1328 "Failed to run %s", cmd);
1329 free(result);
1330 return -1;
1331 }
1332 } else {
1333 sigma_dut_print(dut, DUT_MSG_INFO,
1334 "No Valid Table Id found %s", pos);
1335 free(result);
1336 return -1;
1337 }
1338 free(result);
1339
1340 return 0;
1341}
1342#endif /* ANDROID */
1343
1344
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301345int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1346 const char *ip, const char *mask)
1347{
1348 char buf[200];
1349
1350 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1351 ifname, ip, mask);
1352 return system(buf) == 0;
1353}
1354
1355
1356int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1357{
1358 char buf[200];
1359
1360 if (!is_ip_addr(gw)) {
1361 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1362 return -1;
1363 }
1364
1365 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1366 if (!dut->no_ip_addr_set && system(buf) != 0) {
1367 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1368 gw);
1369 if (system(buf) != 0)
1370 return 0;
1371 }
1372
1373 return 1;
1374}
1375
1376
Jouni Malinenf7222712019-06-13 01:50:21 +03001377static enum sigma_cmd_result cmd_sta_set_ip_config(struct sigma_dut *dut,
1378 struct sigma_conn *conn,
1379 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001380{
1381 const char *intf = get_param(cmd, "Interface");
1382 const char *ifname;
1383 char buf[200];
1384 const char *val, *ip, *mask, *gw;
1385 int type = 1;
1386
1387 if (intf == NULL)
1388 return -1;
1389
1390 if (strcmp(intf, get_main_ifname()) == 0)
1391 ifname = get_station_ifname();
1392 else
1393 ifname = intf;
1394
1395 if (if_nametoindex(ifname) == 0) {
1396 send_resp(dut, conn, SIGMA_ERROR,
1397 "ErrorCode,Unknown interface");
1398 return 0;
1399 }
1400
1401 val = get_param(cmd, "Type");
1402 if (val) {
1403 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301404 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001405 send_resp(dut, conn, SIGMA_ERROR,
1406 "ErrorCode,Unsupported address type");
1407 return 0;
1408 }
1409 }
1410
1411 dut->last_set_ip_config_ipv6 = 0;
1412
1413 val = get_param(cmd, "dhcp");
1414 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1415 static_ip_file(0, NULL, NULL, NULL);
1416#ifdef __linux__
1417 if (type == 2) {
1418 dut->last_set_ip_config_ipv6 = 1;
1419 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1420 "stateless address autoconfiguration");
1421#ifdef ANDROID
1422 /*
1423 * This sleep is required as the assignment in case of
1424 * Android is taking time and is done by the kernel.
1425 * The subsequent ping for IPv6 is impacting HS20 test
1426 * case.
1427 */
1428 sleep(2);
1429 add_ipv6_rule(dut, intf);
1430#endif /* ANDROID */
1431 /* Assume this happens by default */
1432 return 1;
1433 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301434 if (type != 3) {
1435 kill_dhcp_client(dut, ifname);
1436 if (start_dhcp_client(dut, ifname) < 0)
1437 return -2;
1438 } else {
1439 sigma_dut_print(dut, DUT_MSG_DEBUG,
1440 "Using FILS HLP DHCPv4 Rapid Commit");
1441 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001442
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001443 return 1;
1444#endif /* __linux__ */
1445 return -2;
1446 }
1447
1448 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301449 if (!ip) {
1450 send_resp(dut, conn, SIGMA_INVALID,
1451 "ErrorCode,Missing IP address");
1452 return 0;
1453 }
1454
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001455 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301456 if (!mask) {
1457 send_resp(dut, conn, SIGMA_INVALID,
1458 "ErrorCode,Missing subnet mask");
1459 return 0;
1460 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001461
1462 if (type == 2) {
1463 int net = atoi(mask);
1464
1465 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1466 return -1;
1467
1468 if (dut->no_ip_addr_set) {
1469 snprintf(buf, sizeof(buf),
1470 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1471 ifname);
1472 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1473 if (system(buf) != 0) {
1474 sigma_dut_print(dut, DUT_MSG_DEBUG,
1475 "Failed to disable IPv6 address before association");
1476 }
1477 } else {
1478 snprintf(buf, sizeof(buf),
1479 "ip -6 addr del %s/%s dev %s",
1480 ip, mask, ifname);
1481 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1482 if (system(buf) != 0) {
1483 /*
1484 * This command may fail if the address being
1485 * deleted does not exist. Inaction here is
1486 * intentional.
1487 */
1488 }
1489
1490 snprintf(buf, sizeof(buf),
1491 "ip -6 addr add %s/%s dev %s",
1492 ip, mask, ifname);
1493 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1494 if (system(buf) != 0) {
1495 send_resp(dut, conn, SIGMA_ERROR,
1496 "ErrorCode,Failed to set IPv6 address");
1497 return 0;
1498 }
1499 }
1500
1501 dut->last_set_ip_config_ipv6 = 1;
1502 static_ip_file(6, ip, mask, NULL);
1503 return 1;
1504 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301505 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001506 return -1;
1507 }
1508
1509 kill_dhcp_client(dut, ifname);
1510
1511 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301512 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001513 send_resp(dut, conn, SIGMA_ERROR,
1514 "ErrorCode,Failed to set IP address");
1515 return 0;
1516 }
1517 }
1518
1519 gw = get_param(cmd, "defaultGateway");
1520 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301521 if (set_ipv4_gw(dut, gw) < 1) {
1522 send_resp(dut, conn, SIGMA_ERROR,
1523 "ErrorCode,Failed to set default gateway");
1524 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001525 }
1526 }
1527
1528 val = get_param(cmd, "primary-dns");
1529 if (val) {
1530 /* TODO */
1531 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1532 "setting", val);
1533 }
1534
1535 val = get_param(cmd, "secondary-dns");
1536 if (val) {
1537 /* TODO */
1538 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1539 "setting", val);
1540 }
1541
1542 static_ip_file(4, ip, mask, gw);
1543
1544 return 1;
1545}
1546
1547
Jouni Malinenf7222712019-06-13 01:50:21 +03001548static enum sigma_cmd_result cmd_sta_get_info(struct sigma_dut *dut,
1549 struct sigma_conn *conn,
1550 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001551{
1552 /* const char *intf = get_param(cmd, "Interface"); */
1553 /* TODO: could report more details here */
1554 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1555 return 0;
1556}
1557
1558
Jouni Malinenf7222712019-06-13 01:50:21 +03001559static enum sigma_cmd_result cmd_sta_get_mac_address(struct sigma_dut *dut,
1560 struct sigma_conn *conn,
1561 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001562{
1563 /* const char *intf = get_param(cmd, "Interface"); */
1564 char addr[20], resp[50];
1565
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301566 if (dut->dev_role == DEVROLE_STA_CFON)
1567 return sta_cfon_get_mac_address(dut, conn, cmd);
1568
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001569 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1570 < 0)
1571 return -2;
1572
1573 snprintf(resp, sizeof(resp), "mac,%s", addr);
1574 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1575 return 0;
1576}
1577
1578
Jouni Malinenf7222712019-06-13 01:50:21 +03001579static enum sigma_cmd_result cmd_sta_is_connected(struct sigma_dut *dut,
1580 struct sigma_conn *conn,
1581 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001582{
1583 /* const char *intf = get_param(cmd, "Interface"); */
1584 int connected = 0;
1585 char result[32];
1586 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1587 sizeof(result)) < 0) {
1588 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1589 "%s status", get_station_ifname());
1590 return -2;
1591 }
1592
1593 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1594 if (strncmp(result, "COMPLETED", 9) == 0)
1595 connected = 1;
1596
1597 if (connected)
1598 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1599 else
1600 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1601
1602 return 0;
1603}
1604
1605
Jouni Malinenf7222712019-06-13 01:50:21 +03001606static enum sigma_cmd_result
1607cmd_sta_verify_ip_connection(struct sigma_dut *dut, struct sigma_conn *conn,
1608 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001609{
1610 /* const char *intf = get_param(cmd, "Interface"); */
1611 const char *dst, *timeout;
1612 int wait_time = 90;
1613 char buf[100];
1614 int res;
1615
1616 dst = get_param(cmd, "destination");
1617 if (dst == NULL || !is_ip_addr(dst))
1618 return -1;
1619
1620 timeout = get_param(cmd, "timeout");
1621 if (timeout) {
1622 wait_time = atoi(timeout);
1623 if (wait_time < 1)
1624 wait_time = 1;
1625 }
1626
1627 /* TODO: force renewal of IP lease if DHCP is enabled */
1628
1629 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1630 res = system(buf);
1631 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1632 if (res == 0)
1633 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1634 else if (res == 256)
1635 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1636 else
1637 return -2;
1638
1639 return 0;
1640}
1641
1642
Jouni Malinenf7222712019-06-13 01:50:21 +03001643static enum sigma_cmd_result cmd_sta_get_bssid(struct sigma_dut *dut,
1644 struct sigma_conn *conn,
1645 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001646{
1647 /* const char *intf = get_param(cmd, "Interface"); */
1648 char bssid[20], resp[50];
1649
1650 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1651 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001652 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001653
1654 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1655 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1656 return 0;
1657}
1658
1659
1660#ifdef __SAMSUNG__
1661static int add_use_network(const char *ifname)
1662{
1663 char buf[100];
1664
1665 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1666 wpa_command(ifname, buf);
1667 return 0;
1668}
1669#endif /* __SAMSUNG__ */
1670
1671
1672static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1673 const char *ifname, struct sigma_cmd *cmd)
1674{
1675 const char *ssid = get_param(cmd, "ssid");
1676 int id;
1677 const char *val;
1678
1679 if (ssid == NULL)
1680 return -1;
1681
1682 start_sta_mode(dut);
1683
1684#ifdef __SAMSUNG__
1685 add_use_network(ifname);
1686#endif /* __SAMSUNG__ */
1687
1688 id = add_network(ifname);
1689 if (id < 0)
1690 return -2;
1691 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1692
1693 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1694 return -2;
1695
1696 dut->infra_network_id = id;
1697 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1698
1699 val = get_param(cmd, "program");
1700 if (!val)
1701 val = get_param(cmd, "prog");
1702 if (val && strcasecmp(val, "hs2") == 0) {
1703 char buf[100];
1704 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1705 wpa_command(ifname, buf);
1706
1707 val = get_param(cmd, "prefer");
1708 if (val && atoi(val) > 0)
1709 set_network(ifname, id, "priority", "1");
1710 }
1711
1712 return id;
1713}
1714
1715
Jouni Malinenf7222712019-06-13 01:50:21 +03001716static enum sigma_cmd_result cmd_sta_set_encryption(struct sigma_dut *dut,
1717 struct sigma_conn *conn,
1718 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001719{
1720 const char *intf = get_param(cmd, "Interface");
1721 const char *ssid = get_param(cmd, "ssid");
1722 const char *type = get_param(cmd, "encpType");
1723 const char *ifname;
1724 char buf[200];
1725 int id;
1726
1727 if (intf == NULL || ssid == NULL)
1728 return -1;
1729
1730 if (strcmp(intf, get_main_ifname()) == 0)
1731 ifname = get_station_ifname();
1732 else
1733 ifname = intf;
1734
1735 id = add_network_common(dut, conn, ifname, cmd);
1736 if (id < 0)
1737 return id;
1738
1739 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1740 return -2;
1741
1742 if (type && strcasecmp(type, "wep") == 0) {
1743 const char *val;
1744 int i;
1745
1746 val = get_param(cmd, "activeKey");
1747 if (val) {
1748 int keyid;
1749 keyid = atoi(val);
1750 if (keyid < 1 || keyid > 4)
1751 return -1;
1752 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1753 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1754 return -2;
1755 }
1756
1757 for (i = 0; i < 4; i++) {
1758 snprintf(buf, sizeof(buf), "key%d", i + 1);
1759 val = get_param(cmd, buf);
1760 if (val == NULL)
1761 continue;
1762 snprintf(buf, sizeof(buf), "wep_key%d", i);
1763 if (set_network(ifname, id, buf, val) < 0)
1764 return -2;
1765 }
1766 }
1767
1768 return 1;
1769}
1770
1771
Jouni Malinene4fde732019-03-25 22:29:37 +02001772static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1773 int id, const char *val)
1774{
1775 char key_mgmt[200], *end, *pos;
1776 const char *in_pos = val;
1777
Jouni Malinen8179fee2019-03-28 03:19:47 +02001778 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001779 pos = key_mgmt;
1780 end = pos + sizeof(key_mgmt);
1781 while (*in_pos) {
1782 int res, akm = atoi(in_pos);
1783 const char *str;
1784
Jouni Malinen8179fee2019-03-28 03:19:47 +02001785 if (akm >= 0 && akm < 32)
1786 dut->akm_values |= 1 << akm;
1787
Jouni Malinene4fde732019-03-25 22:29:37 +02001788 switch (akm) {
1789 case AKM_WPA_EAP:
1790 str = "WPA-EAP";
1791 break;
1792 case AKM_WPA_PSK:
1793 str = "WPA-PSK";
1794 break;
1795 case AKM_FT_EAP:
1796 str = "FT-EAP";
1797 break;
1798 case AKM_FT_PSK:
1799 str = "FT-PSK";
1800 break;
1801 case AKM_EAP_SHA256:
1802 str = "WPA-EAP-SHA256";
1803 break;
1804 case AKM_PSK_SHA256:
1805 str = "WPA-PSK-SHA256";
1806 break;
1807 case AKM_SAE:
1808 str = "SAE";
1809 break;
1810 case AKM_FT_SAE:
1811 str = "FT-SAE";
1812 break;
1813 case AKM_SUITE_B:
1814 str = "WPA-EAP-SUITE-B-192";
1815 break;
1816 case AKM_FT_SUITE_B:
1817 str = "FT-EAP-SHA384";
1818 break;
1819 case AKM_FILS_SHA256:
1820 str = "FILS-SHA256";
1821 break;
1822 case AKM_FILS_SHA384:
1823 str = "FILS-SHA384";
1824 break;
1825 case AKM_FT_FILS_SHA256:
1826 str = "FT-FILS-SHA256";
1827 break;
1828 case AKM_FT_FILS_SHA384:
1829 str = "FT-FILS-SHA384";
1830 break;
1831 default:
1832 sigma_dut_print(dut, DUT_MSG_ERROR,
1833 "Unsupported AKMSuitetype %d", akm);
1834 return -1;
1835 }
1836
1837 res = snprintf(pos, end - pos, "%s%s",
1838 pos == key_mgmt ? "" : " ", str);
1839 if (res < 0 || res >= end - pos)
1840 return -1;
1841 pos += res;
1842
1843 in_pos = strchr(in_pos, ';');
1844 if (!in_pos)
1845 break;
1846 while (*in_pos == ';')
1847 in_pos++;
1848 }
1849 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1850 val, key_mgmt);
1851 return set_network(ifname, id, "key_mgmt", key_mgmt);
1852}
1853
1854
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001855static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1856 const char *ifname, struct sigma_cmd *cmd)
1857{
1858 const char *val;
1859 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001860 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001861 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301862 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001863
1864 id = add_network_common(dut, conn, ifname, cmd);
1865 if (id < 0)
1866 return id;
1867
Jouni Malinen47dcc952017-10-09 16:43:24 +03001868 val = get_param(cmd, "Type");
1869 owe = val && strcasecmp(val, "OWE") == 0;
1870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001871 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001872 if (!val && owe)
1873 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001874 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001875 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1876 * this missing parameter and assume proto=WPA2. */
1877 if (set_network(ifname, id, "proto", "WPA2") < 0)
1878 return ERROR_SEND_STATUS;
1879 } else if (strcasecmp(val, "wpa") == 0 ||
1880 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001881 if (set_network(ifname, id, "proto", "WPA") < 0)
1882 return -2;
1883 } else if (strcasecmp(val, "wpa2") == 0 ||
1884 strcasecmp(val, "wpa2-psk") == 0 ||
1885 strcasecmp(val, "wpa2-ft") == 0 ||
1886 strcasecmp(val, "wpa2-sha256") == 0) {
1887 if (set_network(ifname, id, "proto", "WPA2") < 0)
1888 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301889 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1890 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001891 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1892 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001893 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301894 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001895 if (set_network(ifname, id, "proto", "WPA2") < 0)
1896 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001897 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001898 } else {
1899 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1900 return 0;
1901 }
1902
1903 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001904 if (val) {
1905 cipher_set = 1;
1906 if (strcasecmp(val, "tkip") == 0) {
1907 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1908 return -2;
1909 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1910 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1911 return -2;
1912 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1913 if (set_network(ifname, id, "pairwise",
1914 "CCMP TKIP") < 0)
1915 return -2;
1916 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1917 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1918 return -2;
1919 if (set_network(ifname, id, "group", "GCMP") < 0)
1920 return -2;
1921 } else {
1922 send_resp(dut, conn, SIGMA_ERROR,
1923 "errorCode,Unrecognized encpType value");
1924 return 0;
1925 }
1926 }
1927
1928 val = get_param(cmd, "PairwiseCipher");
1929 if (val) {
1930 cipher_set = 1;
1931 /* TODO: Support space separated list */
1932 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1933 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1934 return -2;
1935 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1936 if (set_network(ifname, id, "pairwise",
1937 "CCMP-256") < 0)
1938 return -2;
1939 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1940 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1941 return -2;
1942 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1943 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1944 return -2;
1945 } else {
1946 send_resp(dut, conn, SIGMA_ERROR,
1947 "errorCode,Unrecognized PairwiseCipher value");
1948 return 0;
1949 }
1950 }
1951
Jouni Malinen47dcc952017-10-09 16:43:24 +03001952 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001953 send_resp(dut, conn, SIGMA_ERROR,
1954 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001955 return 0;
1956 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001957
1958 val = get_param(cmd, "GroupCipher");
1959 if (val) {
1960 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1961 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1962 return -2;
1963 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1964 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1965 return -2;
1966 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1967 if (set_network(ifname, id, "group", "GCMP") < 0)
1968 return -2;
1969 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1970 if (set_network(ifname, id, "group", "CCMP") < 0)
1971 return -2;
1972 } else {
1973 send_resp(dut, conn, SIGMA_ERROR,
1974 "errorCode,Unrecognized GroupCipher value");
1975 return 0;
1976 }
1977 }
1978
Jouni Malinen7b239522017-09-14 21:37:18 +03001979 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001980 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001981 const char *cipher;
1982
1983 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1984 cipher = "BIP-GMAC-256";
1985 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1986 cipher = "BIP-CMAC-256";
1987 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1988 cipher = "BIP-GMAC-128";
1989 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1990 cipher = "AES-128-CMAC";
1991 } else {
1992 send_resp(dut, conn, SIGMA_INVALID,
1993 "errorCode,Unsupported GroupMgntCipher");
1994 return 0;
1995 }
1996 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1997 send_resp(dut, conn, SIGMA_INVALID,
1998 "errorCode,Failed to set GroupMgntCipher");
1999 return 0;
2000 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002001 }
2002
Jouni Malinene4fde732019-03-25 22:29:37 +02002003 val = get_param(cmd, "AKMSuiteType");
2004 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2005 return ERROR_SEND_STATUS;
2006
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002007 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302008
2009 if (dut->program == PROGRAM_OCE) {
2010 dut->sta_pmf = STA_PMF_OPTIONAL;
2011 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2012 return -2;
2013 }
2014
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002015 val = get_param(cmd, "PMF");
2016 if (val) {
2017 if (strcasecmp(val, "Required") == 0 ||
2018 strcasecmp(val, "Forced_Required") == 0) {
2019 dut->sta_pmf = STA_PMF_REQUIRED;
2020 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2021 return -2;
2022 } else if (strcasecmp(val, "Optional") == 0) {
2023 dut->sta_pmf = STA_PMF_OPTIONAL;
2024 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2025 return -2;
2026 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002027 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002028 strcasecmp(val, "Forced_Disabled") == 0) {
2029 dut->sta_pmf = STA_PMF_DISABLED;
2030 } else {
2031 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2032 return 0;
2033 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302034 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002035 dut->sta_pmf = STA_PMF_REQUIRED;
2036 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2037 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002038 }
2039
2040 return id;
2041}
2042
2043
Jouni Malinenf7222712019-06-13 01:50:21 +03002044static enum sigma_cmd_result cmd_sta_set_psk(struct sigma_dut *dut,
2045 struct sigma_conn *conn,
2046 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002047{
2048 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002049 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002050 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002051 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002052 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002053 const char *ifname, *val, *alg;
2054 int id;
2055
2056 if (intf == NULL)
2057 return -1;
2058
2059 if (strcmp(intf, get_main_ifname()) == 0)
2060 ifname = get_station_ifname();
2061 else
2062 ifname = intf;
2063
2064 id = set_wpa_common(dut, conn, ifname, cmd);
2065 if (id < 0)
2066 return id;
2067
2068 val = get_param(cmd, "keyMgmtType");
2069 alg = get_param(cmd, "micAlg");
2070
Jouni Malinen992a81e2017-08-22 13:57:47 +03002071 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002072 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002073 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2074 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002075 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002076 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2077 return -2;
2078 }
2079 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2080 sigma_dut_print(dut, DUT_MSG_ERROR,
2081 "Failed to clear sae_groups to default");
2082 return -2;
2083 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002084 if (!pmf) {
2085 dut->sta_pmf = STA_PMF_REQUIRED;
2086 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2087 return -2;
2088 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002089 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2090 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2091 if (set_network(ifname, id, "key_mgmt",
2092 "FT-SAE FT-PSK") < 0)
2093 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002094 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002095 if (set_network(ifname, id, "key_mgmt",
2096 "SAE WPA-PSK") < 0)
2097 return -2;
2098 }
2099 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2100 sigma_dut_print(dut, DUT_MSG_ERROR,
2101 "Failed to clear sae_groups to default");
2102 return -2;
2103 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002104 if (!pmf) {
2105 dut->sta_pmf = STA_PMF_OPTIONAL;
2106 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2107 return -2;
2108 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002109 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002110 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2111 return -2;
2112 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2113 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2114 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302115 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2116 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2117 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002118 } else if (!akm &&
2119 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2120 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002121 if (set_network(ifname, id, "key_mgmt",
2122 "WPA-PSK WPA-PSK-SHA256") < 0)
2123 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002124 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002125 if (set_network(ifname, id, "key_mgmt",
2126 "WPA-PSK WPA-PSK-SHA256") < 0)
2127 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002128 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002129 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2130 return -2;
2131 }
2132
2133 val = get_param(cmd, "passPhrase");
2134 if (val == NULL)
2135 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002136 if (type && strcasecmp(type, "SAE") == 0) {
2137 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2138 return -2;
2139 } else {
2140 if (set_network_quoted(ifname, id, "psk", val) < 0)
2141 return -2;
2142 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002143
Jouni Malinen78d10c42019-03-25 22:34:32 +02002144 val = get_param(cmd, "PasswordId");
2145 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2146 return ERROR_SEND_STATUS;
2147
Jouni Malinen992a81e2017-08-22 13:57:47 +03002148 val = get_param(cmd, "ECGroupID");
2149 if (val) {
2150 char buf[50];
2151
2152 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
2153 if (wpa_command(ifname, buf) != 0) {
2154 sigma_dut_print(dut, DUT_MSG_ERROR,
2155 "Failed to clear sae_groups");
2156 return -2;
2157 }
2158 }
2159
Jouni Malinen68143132017-09-02 02:34:08 +03002160 val = get_param(cmd, "InvalidSAEElement");
2161 if (val) {
2162 free(dut->sae_commit_override);
2163 dut->sae_commit_override = strdup(val);
2164 }
2165
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002166 if (dut->program == PROGRAM_60GHZ && network_mode &&
2167 strcasecmp(network_mode, "PBSS") == 0 &&
2168 set_network(ifname, id, "pbss", "1") < 0)
2169 return -2;
2170
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002171 return 1;
2172}
2173
2174
Jouni Malinen8ac93452019-08-14 15:19:13 +03002175static enum sigma_cmd_result set_trust_root_system(struct sigma_dut *dut,
2176 struct sigma_conn *conn,
2177 const char *ifname, int id)
2178{
2179 char buf[200];
2180
2181 snprintf(buf, sizeof(buf), "%s/certs", sigma_cert_path);
2182 if (!file_exists(buf))
2183 strlcpy(buf, "/system/etc/security/cacerts", sizeof(buf));
2184 if (!file_exists(buf))
2185 strlcpy(buf, "/etc/ssl/certs", sizeof(buf));
2186 if (!file_exists(buf)) {
2187 char msg[300];
2188
2189 snprintf(msg, sizeof(msg),
2190 "ErrorCode,trustedRootCA system store (%s) not found",
2191 buf);
2192 send_resp(dut, conn, SIGMA_ERROR, msg);
2193 return STATUS_SENT_ERROR;
2194 }
2195
2196 if (set_network_quoted(ifname, id, "ca_path", buf) < 0)
2197 return ERROR_SEND_STATUS;
2198
2199 return SUCCESS_SEND_STATUS;
2200}
2201
2202
2203static enum sigma_cmd_result set_trust_root(struct sigma_dut *dut,
2204 struct sigma_conn *conn,
2205 const char *ifname, int id,
2206 const char *val)
2207{
2208 char buf[200];
2209#ifdef ANDROID
2210 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2211 int length;
2212#endif /* ANDROID */
2213
2214 if (strcmp(val, "DEFAULT") == 0)
2215 return set_trust_root_system(dut, conn, ifname, id);
2216
2217#ifdef ANDROID
2218 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2219 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2220 if (length > 0) {
2221 sigma_dut_print(dut, DUT_MSG_INFO, "Use Android keystore [%s]",
2222 buf);
2223 snprintf(buf, sizeof(buf), "keystore://CACERT_%s", val);
2224 goto ca_cert_selected;
2225 }
2226#endif /* ANDROID */
2227
2228 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2229#ifdef __linux__
2230 if (!file_exists(buf)) {
2231 char msg[300];
2232
2233 snprintf(msg, sizeof(msg),
2234 "ErrorCode,trustedRootCA file (%s) not found", buf);
2235 send_resp(dut, conn, SIGMA_ERROR, msg);
2236 return STATUS_SENT_ERROR;
2237 }
2238#endif /* __linux__ */
2239#ifdef ANDROID
2240ca_cert_selected:
2241#endif /* ANDROID */
2242 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2243 return ERROR_SEND_STATUS;
2244
2245 return SUCCESS_SEND_STATUS;
2246}
2247
2248
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002249static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302250 const char *ifname, int username_identity,
2251 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002252{
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002253 const char *val, *alg, *akm, *trust_root, *domain, *domain_suffix;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002254 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002255 char buf[200], buf2[300];
Jouni Malinen8179fee2019-03-28 03:19:47 +02002256 int erp = 0;
Jouni Malinen8ac93452019-08-14 15:19:13 +03002257 enum sigma_cmd_result res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002258
2259 id = set_wpa_common(dut, conn, ifname, cmd);
2260 if (id < 0)
2261 return id;
2262
2263 val = get_param(cmd, "keyMgmtType");
2264 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302265 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002266 trust_root = get_param(cmd, "trustedRootCA");
2267 domain = get_param(cmd, "Domain");
2268 domain_suffix = get_param(cmd, "DomainSuffix");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002269
Jouni Malinenad395a22017-09-01 21:13:46 +03002270 if (val && strcasecmp(val, "SuiteB") == 0) {
2271 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2272 0)
2273 return -2;
2274 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002275 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2276 return -2;
2277 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2278 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2279 return -2;
2280 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2281 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2282 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002283 } else if (!akm &&
2284 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2285 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002286 if (set_network(ifname, id, "key_mgmt",
2287 "WPA-EAP WPA-EAP-SHA256") < 0)
2288 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302289 } else if (akm && atoi(akm) == 14) {
2290 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2291 dut->sta_pmf == STA_PMF_REQUIRED) {
2292 if (set_network(ifname, id, "key_mgmt",
2293 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2294 return -2;
2295 } else {
2296 if (set_network(ifname, id, "key_mgmt",
2297 "WPA-EAP FILS-SHA256") < 0)
2298 return -2;
2299 }
2300
Jouni Malinen8179fee2019-03-28 03:19:47 +02002301 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302302 } else if (akm && atoi(akm) == 15) {
2303 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2304 dut->sta_pmf == STA_PMF_REQUIRED) {
2305 if (set_network(ifname, id, "key_mgmt",
2306 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2307 return -2;
2308 } else {
2309 if (set_network(ifname, id, "key_mgmt",
2310 "WPA-EAP FILS-SHA384") < 0)
2311 return -2;
2312 }
2313
Jouni Malinen8179fee2019-03-28 03:19:47 +02002314 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002315 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002316 if (set_network(ifname, id, "key_mgmt",
2317 "WPA-EAP WPA-EAP-SHA256") < 0)
2318 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002319 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002320 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2321 return -2;
2322 }
2323
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002324 if (trust_root) {
2325 if (strcmp(trust_root, "DEFAULT") == 0 && !domain &&
2326 !domain_suffix) {
2327 send_resp(dut, conn, SIGMA_ERROR,
2328 "errorCode,trustRootCA DEFAULT used without specifying Domain or DomainSuffix");
2329 return STATUS_SENT_ERROR;
2330 }
2331 res = set_trust_root(dut, conn, ifname, id, trust_root);
Jouni Malinen8ac93452019-08-14 15:19:13 +03002332 if (res != SUCCESS_SEND_STATUS)
2333 return res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002334 }
2335
Jouni Malinen53264f62019-05-03 13:04:40 +03002336 val = get_param(cmd, "ServerCert");
2337 if (val) {
2338 FILE *f;
2339 char *result = NULL, *pos;
2340
2341 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2342 val);
2343 f = fopen(buf, "r");
2344 if (f) {
2345 result = fgets(buf, sizeof(buf), f);
2346 fclose(f);
2347 }
2348 if (!result) {
2349 snprintf(buf2, sizeof(buf2),
2350 "ErrorCode,ServerCert hash could not be read from %s",
2351 buf);
2352 send_resp(dut, conn, SIGMA_ERROR, buf2);
2353 return STATUS_SENT_ERROR;
2354 }
2355 pos = strchr(buf, '\n');
2356 if (pos)
2357 *pos = '\0';
2358 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2359 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2360 return ERROR_SEND_STATUS;
Jouni Malinen29108dc2019-06-13 23:42:11 +03002361
2362 snprintf(buf, sizeof(buf), "%s/%s.tod", sigma_cert_path, val);
2363 if (file_exists(buf)) {
2364 sigma_dut_print(dut, DUT_MSG_DEBUG,
2365 "TOD policy enabled for the configured ServerCert hash");
2366 dut->sta_tod_policy = 1;
2367 }
Jouni Malinen53264f62019-05-03 13:04:40 +03002368 }
2369
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002370 if (domain &&
2371 set_network_quoted(ifname, id, "domain_match", domain) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002372 return ERROR_SEND_STATUS;
2373
Jouni Malinenb4d56ba2019-08-23 18:17:44 +03002374 if (domain_suffix &&
2375 set_network_quoted(ifname, id, "domain_suffix_match",
2376 domain_suffix) < 0)
Jouni Malinen96f84b02019-05-03 12:32:56 +03002377 return ERROR_SEND_STATUS;
2378
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302379 if (username_identity) {
2380 val = get_param(cmd, "username");
2381 if (val) {
2382 if (set_network_quoted(ifname, id, "identity", val) < 0)
2383 return -2;
2384 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002385
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302386 val = get_param(cmd, "password");
2387 if (val) {
2388 if (set_network_quoted(ifname, id, "password", val) < 0)
2389 return -2;
2390 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002391 }
2392
Jouni Malinen8179fee2019-03-28 03:19:47 +02002393 if (dut->akm_values &
2394 ((1 << AKM_FILS_SHA256) |
2395 (1 << AKM_FILS_SHA384) |
2396 (1 << AKM_FT_FILS_SHA256) |
2397 (1 << AKM_FT_FILS_SHA384)))
2398 erp = 1;
2399 if (erp && set_network(ifname, id, "erp", "1") < 0)
2400 return ERROR_SEND_STATUS;
2401
Jouni Malinen134fe3c2019-06-12 04:16:49 +03002402 dut->sta_associate_wait_connect = 1;
2403
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002404 return id;
2405}
2406
2407
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002408static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2409{
2410 const char *val;
2411
2412 if (!cipher)
2413 return 0;
2414
2415 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2416 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2417 else if (strcasecmp(cipher,
2418 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2419 val = "ECDHE-RSA-AES256-GCM-SHA384";
2420 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2421 val = "DHE-RSA-AES256-GCM-SHA384";
2422 else if (strcasecmp(cipher,
2423 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2424 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2425 else
2426 return -1;
2427
2428 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2429 set_network_quoted(ifname, id, "phase1", "");
2430
2431 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2432}
2433
2434
Jouni Malinenf7222712019-06-13 01:50:21 +03002435static enum sigma_cmd_result cmd_sta_set_eaptls(struct sigma_dut *dut,
2436 struct sigma_conn *conn,
2437 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002438{
2439 const char *intf = get_param(cmd, "Interface");
2440 const char *ifname, *val;
2441 int id;
2442 char buf[200];
2443#ifdef ANDROID
2444 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2445 int length;
2446 int jb_or_newer = 0;
2447 char prop[PROPERTY_VALUE_MAX];
2448#endif /* ANDROID */
2449
2450 if (intf == NULL)
2451 return -1;
2452
2453 if (strcmp(intf, get_main_ifname()) == 0)
2454 ifname = get_station_ifname();
2455 else
2456 ifname = intf;
2457
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302458 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002459 if (id < 0)
2460 return id;
2461
2462 if (set_network(ifname, id, "eap", "TLS") < 0)
2463 return -2;
2464
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302465 if (!get_param(cmd, "username") &&
2466 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002467 "wifi-user@wifilabs.local") < 0)
2468 return -2;
2469
2470 val = get_param(cmd, "clientCertificate");
2471 if (val == NULL)
2472 return -1;
2473#ifdef ANDROID
2474 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2475 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2476 if (length < 0) {
2477 /*
2478 * JB started reporting keystore type mismatches, so retry with
2479 * the GET_PUBKEY command if the generic GET fails.
2480 */
2481 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2482 buf, kvalue);
2483 }
2484
2485 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2486 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2487 if (strncmp(prop, "4.0", 3) != 0)
2488 jb_or_newer = 1;
2489 } else
2490 jb_or_newer = 1; /* assume newer */
2491
2492 if (jb_or_newer && length > 0) {
2493 sigma_dut_print(dut, DUT_MSG_INFO,
2494 "Use Android keystore [%s]", buf);
2495 if (set_network(ifname, id, "engine", "1") < 0)
2496 return -2;
2497 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2498 return -2;
2499 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2500 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2501 return -2;
2502 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2503 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2504 return -2;
2505 return 1;
2506 } else if (length > 0) {
2507 sigma_dut_print(dut, DUT_MSG_INFO,
2508 "Use Android keystore [%s]", buf);
2509 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2510 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2511 return -2;
2512 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2513 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2514 return -2;
2515 return 1;
2516 }
2517#endif /* ANDROID */
2518
2519 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2520#ifdef __linux__
2521 if (!file_exists(buf)) {
2522 char msg[300];
2523 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2524 "(%s) not found", buf);
2525 send_resp(dut, conn, SIGMA_ERROR, msg);
2526 return -3;
2527 }
2528#endif /* __linux__ */
2529 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2530 return -2;
2531 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2532 return -2;
2533
2534 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2535 return -2;
2536
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002537 val = get_param(cmd, "keyMgmtType");
2538 if (val && strcasecmp(val, "SuiteB") == 0) {
2539 val = get_param(cmd, "CertType");
2540 if (val && strcasecmp(val, "RSA") == 0) {
2541 if (set_network_quoted(ifname, id, "phase1",
2542 "tls_suiteb=1") < 0)
2543 return -2;
2544 } else {
2545 if (set_network_quoted(ifname, id, "openssl_ciphers",
2546 "SUITEB192") < 0)
2547 return -2;
2548 }
2549
2550 val = get_param(cmd, "TLSCipher");
2551 if (set_tls_cipher(ifname, id, val) < 0) {
2552 send_resp(dut, conn, SIGMA_ERROR,
2553 "ErrorCode,Unsupported TLSCipher value");
2554 return -3;
2555 }
2556 }
2557
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002558 return 1;
2559}
2560
2561
Jouni Malinenf7222712019-06-13 01:50:21 +03002562static enum sigma_cmd_result cmd_sta_set_eapttls(struct sigma_dut *dut,
2563 struct sigma_conn *conn,
2564 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002565{
2566 const char *intf = get_param(cmd, "Interface");
2567 const char *ifname;
2568 int id;
2569
2570 if (intf == NULL)
2571 return -1;
2572
2573 if (strcmp(intf, get_main_ifname()) == 0)
2574 ifname = get_station_ifname();
2575 else
2576 ifname = intf;
2577
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302578 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002579 if (id < 0)
2580 return id;
2581
2582 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2583 send_resp(dut, conn, SIGMA_ERROR,
2584 "errorCode,Failed to set TTLS method");
2585 return 0;
2586 }
2587
2588 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2589 send_resp(dut, conn, SIGMA_ERROR,
2590 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2591 return 0;
2592 }
2593
2594 return 1;
2595}
2596
2597
Jouni Malinenf7222712019-06-13 01:50:21 +03002598static enum sigma_cmd_result cmd_sta_set_eapsim(struct sigma_dut *dut,
2599 struct sigma_conn *conn,
2600 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002601{
2602 const char *intf = get_param(cmd, "Interface");
2603 const char *ifname;
2604 int id;
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, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002615 if (id < 0)
2616 return id;
2617
2618 if (set_network(ifname, id, "eap", "SIM") < 0)
2619 return -2;
2620
2621 return 1;
2622}
2623
2624
Jouni Malinenf7222712019-06-13 01:50:21 +03002625static enum sigma_cmd_result cmd_sta_set_peap(struct sigma_dut *dut,
2626 struct sigma_conn *conn,
2627 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002628{
2629 const char *intf = get_param(cmd, "Interface");
2630 const char *ifname, *val;
2631 int id;
2632 char buf[100];
2633
2634 if (intf == NULL)
2635 return -1;
2636
2637 if (strcmp(intf, get_main_ifname()) == 0)
2638 ifname = get_station_ifname();
2639 else
2640 ifname = intf;
2641
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302642 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002643 if (id < 0)
2644 return id;
2645
2646 if (set_network(ifname, id, "eap", "PEAP") < 0)
2647 return -2;
2648
2649 val = get_param(cmd, "innerEAP");
2650 if (val) {
2651 if (strcasecmp(val, "MSCHAPv2") == 0) {
2652 if (set_network_quoted(ifname, id, "phase2",
2653 "auth=MSCHAPV2") < 0)
2654 return -2;
2655 } else if (strcasecmp(val, "GTC") == 0) {
2656 if (set_network_quoted(ifname, id, "phase2",
2657 "auth=GTC") < 0)
2658 return -2;
2659 } else
2660 return -1;
2661 }
2662
2663 val = get_param(cmd, "peapVersion");
2664 if (val) {
2665 int ver = atoi(val);
2666 if (ver < 0 || ver > 1)
2667 return -1;
2668 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2669 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2670 return -2;
2671 }
2672
2673 return 1;
2674}
2675
2676
Jouni Malinenf7222712019-06-13 01:50:21 +03002677static enum sigma_cmd_result cmd_sta_set_eapfast(struct sigma_dut *dut,
2678 struct sigma_conn *conn,
2679 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002680{
2681 const char *intf = get_param(cmd, "Interface");
2682 const char *ifname, *val;
2683 int id;
2684 char buf[100];
2685
2686 if (intf == NULL)
2687 return -1;
2688
2689 if (strcmp(intf, get_main_ifname()) == 0)
2690 ifname = get_station_ifname();
2691 else
2692 ifname = intf;
2693
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302694 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002695 if (id < 0)
2696 return id;
2697
2698 if (set_network(ifname, id, "eap", "FAST") < 0)
2699 return -2;
2700
2701 val = get_param(cmd, "innerEAP");
2702 if (val) {
2703 if (strcasecmp(val, "MSCHAPV2") == 0) {
2704 if (set_network_quoted(ifname, id, "phase2",
2705 "auth=MSCHAPV2") < 0)
2706 return -2;
2707 } else if (strcasecmp(val, "GTC") == 0) {
2708 if (set_network_quoted(ifname, id, "phase2",
2709 "auth=GTC") < 0)
2710 return -2;
2711 } else
2712 return -1;
2713 }
2714
2715 val = get_param(cmd, "validateServer");
2716 if (val) {
2717 /* TODO */
2718 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2719 "validateServer=%s", val);
2720 }
2721
2722 val = get_param(cmd, "pacFile");
2723 if (val) {
2724 snprintf(buf, sizeof(buf), "blob://%s", val);
2725 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2726 return -2;
2727 }
2728
2729 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2730 0)
2731 return -2;
2732
2733 return 1;
2734}
2735
2736
Jouni Malinenf7222712019-06-13 01:50:21 +03002737static enum sigma_cmd_result cmd_sta_set_eapaka(struct sigma_dut *dut,
2738 struct sigma_conn *conn,
2739 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002740{
2741 const char *intf = get_param(cmd, "Interface");
2742 const char *ifname;
2743 int id;
2744
2745 if (intf == NULL)
2746 return -1;
2747
2748 if (strcmp(intf, get_main_ifname()) == 0)
2749 ifname = get_station_ifname();
2750 else
2751 ifname = intf;
2752
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302753 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002754 if (id < 0)
2755 return id;
2756
2757 if (set_network(ifname, id, "eap", "AKA") < 0)
2758 return -2;
2759
2760 return 1;
2761}
2762
2763
Jouni Malinenf7222712019-06-13 01:50:21 +03002764static enum sigma_cmd_result cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2765 struct sigma_conn *conn,
2766 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002767{
2768 const char *intf = get_param(cmd, "Interface");
2769 const char *ifname;
2770 int id;
2771
2772 if (intf == NULL)
2773 return -1;
2774
2775 if (strcmp(intf, get_main_ifname()) == 0)
2776 ifname = get_station_ifname();
2777 else
2778 ifname = intf;
2779
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302780 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002781 if (id < 0)
2782 return id;
2783
2784 if (set_network(ifname, id, "eap", "AKA'") < 0)
2785 return -2;
2786
2787 return 1;
2788}
2789
2790
2791static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2792 struct sigma_cmd *cmd)
2793{
2794 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002795 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002796 const char *ifname;
2797 int id;
2798
2799 if (strcmp(intf, get_main_ifname()) == 0)
2800 ifname = get_station_ifname();
2801 else
2802 ifname = intf;
2803
2804 id = add_network_common(dut, conn, ifname, cmd);
2805 if (id < 0)
2806 return id;
2807
2808 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2809 return -2;
2810
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002811 if (dut->program == PROGRAM_60GHZ && network_mode &&
2812 strcasecmp(network_mode, "PBSS") == 0 &&
2813 set_network(ifname, id, "pbss", "1") < 0)
2814 return -2;
2815
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002816 return 1;
2817}
2818
2819
Jouni Malinen47dcc952017-10-09 16:43:24 +03002820static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2821 struct sigma_cmd *cmd)
2822{
2823 const char *intf = get_param(cmd, "Interface");
2824 const char *ifname, *val;
2825 int id;
2826
2827 if (intf == NULL)
2828 return -1;
2829
2830 if (strcmp(intf, get_main_ifname()) == 0)
2831 ifname = get_station_ifname();
2832 else
2833 ifname = intf;
2834
2835 id = set_wpa_common(dut, conn, ifname, cmd);
2836 if (id < 0)
2837 return id;
2838
2839 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2840 return -2;
2841
2842 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002843 if (val && strcmp(val, "0") == 0) {
2844 if (wpa_command(ifname,
2845 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2846 sigma_dut_print(dut, DUT_MSG_ERROR,
2847 "Failed to set OWE DH Param element override");
2848 return -2;
2849 }
2850 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002851 sigma_dut_print(dut, DUT_MSG_ERROR,
2852 "Failed to clear owe_group");
2853 return -2;
2854 }
2855
2856 return 1;
2857}
2858
2859
Jouni Malinenf7222712019-06-13 01:50:21 +03002860static enum sigma_cmd_result cmd_sta_set_security(struct sigma_dut *dut,
2861 struct sigma_conn *conn,
2862 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002863{
2864 const char *type = get_param(cmd, "Type");
2865
2866 if (type == NULL) {
2867 send_resp(dut, conn, SIGMA_ERROR,
2868 "ErrorCode,Missing Type argument");
2869 return 0;
2870 }
2871
2872 if (strcasecmp(type, "OPEN") == 0)
2873 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002874 if (strcasecmp(type, "OWE") == 0)
2875 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002876 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002877 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002878 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002879 return cmd_sta_set_psk(dut, conn, cmd);
2880 if (strcasecmp(type, "EAPTLS") == 0)
2881 return cmd_sta_set_eaptls(dut, conn, cmd);
2882 if (strcasecmp(type, "EAPTTLS") == 0)
2883 return cmd_sta_set_eapttls(dut, conn, cmd);
2884 if (strcasecmp(type, "EAPPEAP") == 0)
2885 return cmd_sta_set_peap(dut, conn, cmd);
2886 if (strcasecmp(type, "EAPSIM") == 0)
2887 return cmd_sta_set_eapsim(dut, conn, cmd);
2888 if (strcasecmp(type, "EAPFAST") == 0)
2889 return cmd_sta_set_eapfast(dut, conn, cmd);
2890 if (strcasecmp(type, "EAPAKA") == 0)
2891 return cmd_sta_set_eapaka(dut, conn, cmd);
2892 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2893 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002894 if (strcasecmp(type, "wep") == 0)
2895 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002896
2897 send_resp(dut, conn, SIGMA_ERROR,
2898 "ErrorCode,Unsupported Type value");
2899 return 0;
2900}
2901
2902
2903int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2904{
2905#ifdef __linux__
2906 /* special handling for ath6kl */
2907 char path[128], fname[128], *pos;
2908 ssize_t res;
2909 FILE *f;
2910
Jouni Malinene39cd562019-05-29 23:39:56 +03002911 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
2912 intf);
2913 if (res < 0 || res >= sizeof(fname))
2914 return 0;
2915 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002916 if (res < 0)
2917 return 0; /* not ath6kl */
2918
2919 if (res >= (int) sizeof(path))
2920 res = sizeof(path) - 1;
2921 path[res] = '\0';
2922 pos = strrchr(path, '/');
2923 if (pos == NULL)
2924 pos = path;
2925 else
2926 pos++;
2927 snprintf(fname, sizeof(fname),
2928 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2929 "create_qos", pos);
2930 if (!file_exists(fname))
2931 return 0; /* not ath6kl */
2932
2933 if (uapsd) {
2934 f = fopen(fname, "w");
2935 if (f == NULL)
2936 return -1;
2937
2938 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2939 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2940 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2941 "20000 0\n");
2942 fclose(f);
2943 } else {
2944 snprintf(fname, sizeof(fname),
2945 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2946 "delete_qos", pos);
2947
2948 f = fopen(fname, "w");
2949 if (f == NULL)
2950 return -1;
2951
2952 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2953 fprintf(f, "2 4\n");
2954 fclose(f);
2955 }
2956#endif /* __linux__ */
2957
2958 return 0;
2959}
2960
2961
Jouni Malinenf7222712019-06-13 01:50:21 +03002962static enum sigma_cmd_result cmd_sta_set_uapsd(struct sigma_dut *dut,
2963 struct sigma_conn *conn,
2964 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002965{
2966 const char *intf = get_param(cmd, "Interface");
2967 /* const char *ssid = get_param(cmd, "ssid"); */
2968 const char *val;
2969 int max_sp_len = 4;
2970 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2971 char buf[100];
2972 int ret1, ret2;
2973
2974 val = get_param(cmd, "maxSPLength");
2975 if (val) {
2976 max_sp_len = atoi(val);
2977 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2978 max_sp_len != 4)
2979 return -1;
2980 }
2981
2982 val = get_param(cmd, "acBE");
2983 if (val)
2984 ac_be = atoi(val);
2985
2986 val = get_param(cmd, "acBK");
2987 if (val)
2988 ac_bk = atoi(val);
2989
2990 val = get_param(cmd, "acVI");
2991 if (val)
2992 ac_vi = atoi(val);
2993
2994 val = get_param(cmd, "acVO");
2995 if (val)
2996 ac_vo = atoi(val);
2997
2998 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2999
3000 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
3001 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3002 ret1 = wpa_command(intf, buf);
3003
3004 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
3005 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
3006 ret2 = wpa_command(intf, buf);
3007
3008 if (ret1 && ret2) {
3009 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
3010 "UAPSD parameters.");
3011 return -2;
3012 }
3013
3014 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
3015 send_resp(dut, conn, SIGMA_ERROR,
3016 "ErrorCode,Failed to set ath6kl QoS parameters");
3017 return 0;
3018 }
3019
3020 return 1;
3021}
3022
3023
Jouni Malinenf7222712019-06-13 01:50:21 +03003024static enum sigma_cmd_result cmd_sta_set_wmm(struct sigma_dut *dut,
3025 struct sigma_conn *conn,
3026 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003027{
3028 char buf[1000];
3029 const char *intf = get_param(cmd, "Interface");
3030 const char *grp = get_param(cmd, "Group");
3031 const char *act = get_param(cmd, "Action");
3032 const char *tid = get_param(cmd, "Tid");
3033 const char *dir = get_param(cmd, "Direction");
3034 const char *psb = get_param(cmd, "Psb");
3035 const char *up = get_param(cmd, "Up");
3036 const char *fixed = get_param(cmd, "Fixed");
3037 const char *size = get_param(cmd, "Size");
3038 const char *msize = get_param(cmd, "Maxsize");
3039 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
3040 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
3041 const char *inact = get_param(cmd, "Inactivity");
3042 const char *sus = get_param(cmd, "Suspension");
3043 const char *mindr = get_param(cmd, "Mindatarate");
3044 const char *meandr = get_param(cmd, "Meandatarate");
3045 const char *peakdr = get_param(cmd, "Peakdatarate");
3046 const char *phyrate = get_param(cmd, "Phyrate");
3047 const char *burstsize = get_param(cmd, "Burstsize");
3048 const char *sba = get_param(cmd, "Sba");
3049 int direction;
3050 int handle;
Peng Xu93319622017-10-04 17:58:16 -07003051 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003052 int fixed_int;
3053 int psb_ts;
3054
3055 if (intf == NULL || grp == NULL || act == NULL )
3056 return -1;
3057
3058 if (strcasecmp(act, "addts") == 0) {
3059 if (tid == NULL || dir == NULL || psb == NULL ||
3060 up == NULL || fixed == NULL || size == NULL)
3061 return -1;
3062
3063 /*
3064 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
3065 * possible values, but WMM-AC and V-E test scripts use "UP,
3066 * "DOWN", and "BIDI".
3067 */
3068 if (strcasecmp(dir, "uplink") == 0 ||
3069 strcasecmp(dir, "up") == 0) {
3070 direction = 0;
3071 } else if (strcasecmp(dir, "downlink") == 0 ||
3072 strcasecmp(dir, "down") == 0) {
3073 direction = 1;
3074 } else if (strcasecmp(dir, "bidi") == 0) {
3075 direction = 2;
3076 } else {
3077 sigma_dut_print(dut, DUT_MSG_ERROR,
3078 "Direction %s not supported", dir);
3079 return -1;
3080 }
3081
3082 if (strcasecmp(psb, "legacy") == 0) {
3083 psb_ts = 0;
3084 } else if (strcasecmp(psb, "uapsd") == 0) {
3085 psb_ts = 1;
3086 } else {
3087 sigma_dut_print(dut, DUT_MSG_ERROR,
3088 "PSB %s not supported", psb);
3089 return -1;
3090 }
3091
3092 if (atoi(tid) < 0 || atoi(tid) > 7) {
3093 sigma_dut_print(dut, DUT_MSG_ERROR,
3094 "TID %s not supported", tid);
3095 return -1;
3096 }
3097
3098 if (strcasecmp(fixed, "true") == 0) {
3099 fixed_int = 1;
3100 } else {
3101 fixed_int = 0;
3102 }
3103
Peng Xu93319622017-10-04 17:58:16 -07003104 if (sba)
3105 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003106
3107 dut->dialog_token++;
3108 handle = 7000 + dut->dialog_token;
3109
3110 /*
3111 * size: convert to hex
3112 * maxsi: convert to hex
3113 * mindr: convert to hex
3114 * meandr: convert to hex
3115 * peakdr: convert to hex
3116 * burstsize: convert to hex
3117 * phyrate: convert to hex
3118 * sba: convert to hex with modification
3119 * minsi: convert to integer
3120 * sus: convert to integer
3121 * inact: convert to integer
3122 * maxsi: convert to integer
3123 */
3124
3125 /*
3126 * The Nominal MSDU Size field is 2 octets long and contains an
3127 * unsigned integer that specifies the nominal size, in octets,
3128 * of MSDUs belonging to the traffic under this traffic
3129 * specification and is defined in Figure 16. If the Fixed
3130 * subfield is set to 1, then the size of the MSDU is fixed and
3131 * is indicated by the Size Subfield. If the Fixed subfield is
3132 * set to 0, then the size of the MSDU might not be fixed and
3133 * the Size indicates the nominal MSDU size.
3134 *
3135 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3136 * and specifies the excess allocation of time (and bandwidth)
3137 * over and above the stated rates required to transport an MSDU
3138 * belonging to the traffic in this TSPEC. This field is
3139 * represented as an unsigned binary number with an implicit
3140 * binary point after the leftmost 3 bits. For example, an SBA
3141 * of 1.75 is represented as 0x3800. This field is included to
3142 * account for retransmissions. As such, the value of this field
3143 * must be greater than unity.
3144 */
3145
3146 snprintf(buf, sizeof(buf),
3147 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3148 " 0x%X 0x%X 0x%X"
3149 " 0x%X 0x%X 0x%X"
3150 " 0x%X %d %d %d %d"
3151 " %d %d",
3152 intf, handle, tid, direction, psb_ts, up,
3153 (unsigned int) ((fixed_int << 15) | atoi(size)),
3154 msize ? atoi(msize) : 0,
3155 mindr ? atoi(mindr) : 0,
3156 meandr ? atoi(meandr) : 0,
3157 peakdr ? atoi(peakdr) : 0,
3158 burstsize ? atoi(burstsize) : 0,
3159 phyrate ? atoi(phyrate) : 0,
3160 sba ? ((unsigned int) (((int) sba_fv << 13) |
3161 (int)((sba_fv - (int) sba_fv) *
3162 8192))) : 0,
3163 minsi ? atoi(minsi) : 0,
3164 sus ? atoi(sus) : 0,
3165 0, 0,
3166 inact ? atoi(inact) : 0,
3167 maxsi ? atoi(maxsi) : 0);
3168
3169 if (system(buf) != 0) {
3170 sigma_dut_print(dut, DUT_MSG_ERROR,
3171 "iwpriv addtspec request failed");
3172 send_resp(dut, conn, SIGMA_ERROR,
3173 "errorCode,Failed to execute addTspec command");
3174 return 0;
3175 }
3176
3177 sigma_dut_print(dut, DUT_MSG_INFO,
3178 "iwpriv addtspec request send");
3179
3180 /* Mapping handle to a TID */
3181 dut->tid_to_handle[atoi(tid)] = handle;
3182 } else if (strcasecmp(act, "delts") == 0) {
3183 if (tid == NULL)
3184 return -1;
3185
3186 if (atoi(tid) < 0 || atoi(tid) > 7) {
3187 sigma_dut_print(dut, DUT_MSG_ERROR,
3188 "TID %s not supported", tid);
3189 send_resp(dut, conn, SIGMA_ERROR,
3190 "errorCode,Unsupported TID");
3191 return 0;
3192 }
3193
3194 handle = dut->tid_to_handle[atoi(tid)];
3195
3196 if (handle < 7000 || handle > 7255) {
3197 /* Invalid handle ie no mapping for that TID */
3198 sigma_dut_print(dut, DUT_MSG_ERROR,
3199 "handle-> %d not found", handle);
3200 }
3201
3202 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3203 intf, handle);
3204
3205 if (system(buf) != 0) {
3206 sigma_dut_print(dut, DUT_MSG_ERROR,
3207 "iwpriv deltspec request failed");
3208 send_resp(dut, conn, SIGMA_ERROR,
3209 "errorCode,Failed to execute delTspec command");
3210 return 0;
3211 }
3212
3213 sigma_dut_print(dut, DUT_MSG_INFO,
3214 "iwpriv deltspec request send");
3215
3216 dut->tid_to_handle[atoi(tid)] = 0;
3217 } else {
3218 sigma_dut_print(dut, DUT_MSG_ERROR,
3219 "Action type %s not supported", act);
3220 send_resp(dut, conn, SIGMA_ERROR,
3221 "errorCode,Unsupported Action");
3222 return 0;
3223 }
3224
3225 return 1;
3226}
3227
3228
vamsi krishna52e16f92017-08-29 12:37:34 +05303229static int find_network(struct sigma_dut *dut, const char *ssid)
3230{
3231 char list[4096];
3232 char *pos;
3233
3234 sigma_dut_print(dut, DUT_MSG_DEBUG,
3235 "Search for profile based on SSID: '%s'", ssid);
3236 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
3237 list, sizeof(list)) < 0)
3238 return -1;
3239 pos = strstr(list, ssid);
3240 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3241 return -1;
3242
3243 while (pos > list && pos[-1] != '\n')
3244 pos--;
3245 dut->infra_network_id = atoi(pos);
3246 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3247 return 0;
3248}
3249
3250
Sunil Dutt44595082018-02-12 19:41:45 +05303251#ifdef NL80211_SUPPORT
3252static int sta_config_rsnie(struct sigma_dut *dut, int val)
3253{
3254 struct nl_msg *msg;
3255 int ret;
3256 struct nlattr *params;
3257 int ifindex;
3258
3259 ifindex = if_nametoindex("wlan0");
3260 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3261 NL80211_CMD_VENDOR)) ||
3262 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3263 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3264 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3265 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3266 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3267 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3268 sigma_dut_print(dut, DUT_MSG_ERROR,
3269 "%s: err in adding vendor_cmd and vendor_data",
3270 __func__);
3271 nlmsg_free(msg);
3272 return -1;
3273 }
3274 nla_nest_end(msg, params);
3275
3276 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3277 if (ret) {
3278 sigma_dut_print(dut, DUT_MSG_ERROR,
3279 "%s: err in send_and_recv_msgs, ret=%d",
3280 __func__, ret);
3281 return ret;
3282 }
3283
3284 return 0;
3285}
3286#endif /* NL80211_SUPPORT */
3287
3288
Jouni Malinenf7222712019-06-13 01:50:21 +03003289static enum sigma_cmd_result cmd_sta_associate(struct sigma_dut *dut,
3290 struct sigma_conn *conn,
3291 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003292{
3293 /* const char *intf = get_param(cmd, "Interface"); */
3294 const char *ssid = get_param(cmd, "ssid");
3295 const char *wps_param = get_param(cmd, "WPS");
3296 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003297 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003298 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003299 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003300 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003301 int e;
3302 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3303 struct wpa_ctrl *ctrl = NULL;
3304 int num_network_not_found = 0;
3305 int num_disconnected = 0;
3306 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003307
3308 if (ssid == NULL)
3309 return -1;
3310
Jouni Malinen37d5c692019-08-19 16:56:55 +03003311 dut->server_cert_tod = 0;
3312
Jouni Malinen3c367e82017-06-23 17:01:47 +03003313 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303314#ifdef NL80211_SUPPORT
3315 if (get_driver_type() == DRIVER_WCN) {
3316 sta_config_rsnie(dut, 1);
3317 dut->config_rsnie = 1;
3318 }
3319#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003320 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3321 dut->rsne_override);
3322 if (wpa_command(get_station_ifname(), buf) < 0) {
3323 send_resp(dut, conn, SIGMA_ERROR,
3324 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3325 return 0;
3326 }
3327 }
3328
Jouni Malinen68143132017-09-02 02:34:08 +03003329 if (dut->sae_commit_override) {
3330 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3331 dut->sae_commit_override);
3332 if (wpa_command(get_station_ifname(), buf) < 0) {
3333 send_resp(dut, conn, SIGMA_ERROR,
3334 "ErrorCode,Failed to set SAE commit override");
3335 return 0;
3336 }
3337 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303338#ifdef ANDROID
3339 if (dut->fils_hlp)
3340 process_fils_hlp(dut);
3341#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003342
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003343 if (wps_param &&
3344 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3345 wps = 1;
3346
3347 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003348 if (dut->program == PROGRAM_60GHZ && network_mode &&
3349 strcasecmp(network_mode, "PBSS") == 0 &&
3350 set_network(get_station_ifname(), dut->infra_network_id,
3351 "pbss", "1") < 0)
3352 return -2;
3353
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003354 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3355 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3356 "parameters not yet set");
3357 return 0;
3358 }
3359 if (dut->wps_method == WFA_CS_WPS_PBC) {
3360 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
3361 return -2;
3362 } else {
3363 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3364 dut->wps_pin);
3365 if (wpa_command(get_station_ifname(), buf) < 0)
3366 return -2;
3367 }
3368 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303369 if (strcmp(ssid, dut->infra_ssid) == 0) {
3370 sigma_dut_print(dut, DUT_MSG_DEBUG,
3371 "sta_associate for the most recently added network");
3372 } else if (find_network(dut, ssid) < 0) {
3373 sigma_dut_print(dut, DUT_MSG_DEBUG,
3374 "sta_associate for a previously stored network profile");
3375 send_resp(dut, conn, SIGMA_ERROR,
3376 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003377 return 0;
3378 }
3379
3380 if (bssid &&
3381 set_network(get_station_ifname(), dut->infra_network_id,
3382 "bssid", bssid) < 0) {
3383 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3384 "Invalid bssid argument");
3385 return 0;
3386 }
3387
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003388 if (dut->program == PROGRAM_WPA3 &&
3389 dut->sta_associate_wait_connect) {
3390 ctrl = open_wpa_mon(get_station_ifname());
3391 if (!ctrl)
3392 return ERROR_SEND_STATUS;
3393 }
3394
Jouni Malinen46a19b62017-06-23 14:31:27 +03003395 extra[0] = '\0';
3396 if (chan)
3397 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003398 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003399 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3400 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003401 if (wpa_command(get_station_ifname(), buf) < 0) {
3402 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3403 "network id %d on %s",
3404 dut->infra_network_id,
3405 get_station_ifname());
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003406 ret = ERROR_SEND_STATUS;
3407 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003408 }
3409 }
3410
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003411 if (!ctrl)
3412 return SUCCESS_SEND_STATUS;
3413
3414 /* Wait for connection result to be able to store server certificate
3415 * hash for trust root override testing
3416 * (dev_exec_action,ServerCertTrust). */
3417
3418 for (e = 0; e < 20; e++) {
3419 const char *events[] = {
3420 "CTRL-EVENT-EAP-PEER-CERT",
3421 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3422 "CTRL-EVENT-DISCONNECTED",
3423 "CTRL-EVENT-CONNECTED",
3424 "CTRL-EVENT-NETWORK-NOT-FOUND",
3425 NULL
3426 };
3427 char buf[1024];
3428 int res;
3429
3430 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3431 if (res < 0) {
3432 send_resp(dut, conn, SIGMA_ERROR,
3433 "ErrorCode,Association did not complete");
3434 ret = STATUS_SENT_ERROR;
3435 break;
3436 }
3437 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3438 buf);
3439
3440 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3441 strstr(buf, " depth=0")) {
3442 char *pos = strstr(buf, " hash=");
3443
3444 if (pos) {
3445 char *end;
3446
Jouni Malinen34b19cb2019-08-16 16:37:17 +03003447 if (strstr(buf, " tod=1"))
3448 tod = 1;
3449 else if (strstr(buf, " tod=2"))
3450 tod = 2;
3451 else
3452 tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003453 sigma_dut_print(dut, DUT_MSG_DEBUG,
3454 "Server certificate TOD policy: %d",
3455 tod);
Jouni Malinen37d5c692019-08-19 16:56:55 +03003456 dut->server_cert_tod = tod;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003457
3458 pos += 6;
3459 end = strchr(pos, ' ');
3460 if (end)
3461 *end = '\0';
3462 strlcpy(dut->server_cert_hash, pos,
3463 sizeof(dut->server_cert_hash));
3464 sigma_dut_print(dut, DUT_MSG_DEBUG,
3465 "Server certificate hash: %s",
3466 dut->server_cert_hash);
3467 }
3468 }
3469
3470 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3471 send_resp(dut, conn, SIGMA_COMPLETE,
3472 "Result,TLS server certificate validation failed");
3473 ret = STATUS_SENT_ERROR;
3474 break;
3475 }
3476
3477 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3478 num_network_not_found++;
3479
3480 if (num_network_not_found > 2) {
3481 send_resp(dut, conn, SIGMA_COMPLETE,
3482 "Result,Network not found");
3483 ret = STATUS_SENT_ERROR;
3484 break;
3485 }
3486 }
3487
3488 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3489 num_disconnected++;
3490
3491 if (num_disconnected > 2) {
3492 send_resp(dut, conn, SIGMA_COMPLETE,
3493 "Result,Connection failed");
3494 ret = STATUS_SENT_ERROR;
3495 break;
3496 }
3497 }
3498
3499 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3500 if (tod >= 0) {
3501 sigma_dut_print(dut, DUT_MSG_DEBUG,
3502 "Network profile TOD policy update: %d -> %d",
3503 dut->sta_tod_policy, tod);
3504 dut->sta_tod_policy = tod;
3505 }
3506 break;
3507 }
3508 }
3509done:
3510 if (ctrl) {
3511 wpa_ctrl_detach(ctrl);
3512 wpa_ctrl_close(ctrl);
3513 }
3514 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003515}
3516
3517
3518static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3519{
3520 char buf[500], cmd[200];
3521 int res;
3522
3523 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3524 * default path */
3525 res = snprintf(cmd, sizeof(cmd),
3526 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3527 file_exists("./hs20-osu-client") ?
3528 "./hs20-osu-client" : "hs20-osu-client",
3529 sigma_wpas_ctrl,
3530 dut->summary_log ? "-s " : "",
3531 dut->summary_log ? dut->summary_log : "");
3532 if (res < 0 || res >= (int) sizeof(cmd))
3533 return -1;
3534
3535 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3536 if (res < 0 || res >= (int) sizeof(buf))
3537 return -1;
3538 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3539
3540 if (system(buf) != 0) {
3541 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3542 return -1;
3543 }
3544 sigma_dut_print(dut, DUT_MSG_DEBUG,
3545 "Completed hs20-osu-client operation");
3546
3547 return 0;
3548}
3549
3550
3551static int download_ppsmo(struct sigma_dut *dut,
3552 struct sigma_conn *conn,
3553 const char *intf,
3554 struct sigma_cmd *cmd)
3555{
3556 const char *name, *path, *val;
3557 char url[500], buf[600], fbuf[100];
3558 char *fqdn = NULL;
3559
3560 name = get_param(cmd, "FileName");
3561 path = get_param(cmd, "FilePath");
3562 if (name == NULL || path == NULL)
3563 return -1;
3564
3565 if (strcasecmp(path, "VendorSpecific") == 0) {
3566 snprintf(url, sizeof(url), "PPS/%s", name);
3567 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3568 "from the device (%s)", url);
3569 if (!file_exists(url)) {
3570 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3571 "PPS MO file does not exist");
3572 return 0;
3573 }
3574 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3575 if (system(buf) != 0) {
3576 send_resp(dut, conn, SIGMA_ERROR,
3577 "errorCode,Failed to copy PPS MO");
3578 return 0;
3579 }
3580 } else if (strncasecmp(path, "http:", 5) != 0 &&
3581 strncasecmp(path, "https:", 6) != 0) {
3582 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3583 "Unsupported FilePath value");
3584 return 0;
3585 } else {
3586 snprintf(url, sizeof(url), "%s/%s", path, name);
3587 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3588 url);
3589 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3590 remove("pps-tnds.xml");
3591 if (system(buf) != 0) {
3592 send_resp(dut, conn, SIGMA_ERROR,
3593 "errorCode,Failed to download PPS MO");
3594 return 0;
3595 }
3596 }
3597
3598 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3599 send_resp(dut, conn, SIGMA_ERROR,
3600 "errorCode,Failed to parse downloaded PPSMO");
3601 return 0;
3602 }
3603 unlink("pps-tnds.xml");
3604
3605 val = get_param(cmd, "managementTreeURI");
3606 if (val) {
3607 const char *pos, *end;
3608 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3609 val);
3610 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3611 send_resp(dut, conn, SIGMA_ERROR,
3612 "errorCode,Invalid managementTreeURI prefix");
3613 return 0;
3614 }
3615 pos = val + 8;
3616 end = strchr(pos, '/');
3617 if (end == NULL ||
3618 strcmp(end, "/PerProviderSubscription") != 0) {
3619 send_resp(dut, conn, SIGMA_ERROR,
3620 "errorCode,Invalid managementTreeURI postfix");
3621 return 0;
3622 }
3623 if (end - pos >= (int) sizeof(fbuf)) {
3624 send_resp(dut, conn, SIGMA_ERROR,
3625 "errorCode,Too long FQDN in managementTreeURI");
3626 return 0;
3627 }
3628 memcpy(fbuf, pos, end - pos);
3629 fbuf[end - pos] = '\0';
3630 fqdn = fbuf;
3631 sigma_dut_print(dut, DUT_MSG_INFO,
3632 "FQDN from managementTreeURI: %s", fqdn);
3633 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3634 FILE *f = fopen("pps-fqdn", "r");
3635 if (f) {
3636 if (fgets(fbuf, sizeof(fbuf), f)) {
3637 fbuf[sizeof(fbuf) - 1] = '\0';
3638 fqdn = fbuf;
3639 sigma_dut_print(dut, DUT_MSG_DEBUG,
3640 "Use FQDN %s", fqdn);
3641 }
3642 fclose(f);
3643 }
3644 }
3645
3646 if (fqdn == NULL) {
3647 send_resp(dut, conn, SIGMA_ERROR,
3648 "errorCode,No FQDN specified");
3649 return 0;
3650 }
3651
3652 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3653 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3654 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3655
3656 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3657 if (rename("pps.xml", buf) < 0) {
3658 send_resp(dut, conn, SIGMA_ERROR,
3659 "errorCode,Could not move PPS MO");
3660 return 0;
3661 }
3662
3663 if (strcasecmp(path, "VendorSpecific") == 0) {
3664 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3665 fqdn);
3666 if (system(buf)) {
3667 send_resp(dut, conn, SIGMA_ERROR,
3668 "errorCode,Failed to copy OSU CA cert");
3669 return 0;
3670 }
3671
3672 snprintf(buf, sizeof(buf),
3673 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3674 fqdn);
3675 if (system(buf)) {
3676 send_resp(dut, conn, SIGMA_ERROR,
3677 "errorCode,Failed to copy AAA CA cert");
3678 return 0;
3679 }
3680 } else {
3681 snprintf(buf, sizeof(buf),
3682 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3683 fqdn, fqdn);
3684 if (run_hs20_osu(dut, buf) < 0) {
3685 send_resp(dut, conn, SIGMA_ERROR,
3686 "errorCode,Failed to download OSU CA cert");
3687 return 0;
3688 }
3689
3690 snprintf(buf, sizeof(buf),
3691 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3692 fqdn, fqdn);
3693 if (run_hs20_osu(dut, buf) < 0) {
3694 sigma_dut_print(dut, DUT_MSG_INFO,
3695 "Failed to download AAA CA cert");
3696 }
3697 }
3698
3699 if (file_exists("next-client-cert.pem")) {
3700 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3701 if (rename("next-client-cert.pem", buf) < 0) {
3702 send_resp(dut, conn, SIGMA_ERROR,
3703 "errorCode,Could not move client certificate");
3704 return 0;
3705 }
3706 }
3707
3708 if (file_exists("next-client-key.pem")) {
3709 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3710 if (rename("next-client-key.pem", buf) < 0) {
3711 send_resp(dut, conn, SIGMA_ERROR,
3712 "errorCode,Could not move client key");
3713 return 0;
3714 }
3715 }
3716
3717 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3718 if (run_hs20_osu(dut, buf) < 0) {
3719 send_resp(dut, conn, SIGMA_ERROR,
3720 "errorCode,Failed to configure credential from "
3721 "PPSMO");
3722 return 0;
3723 }
3724
3725 return 1;
3726}
3727
3728
3729static int download_cert(struct sigma_dut *dut,
3730 struct sigma_conn *conn,
3731 const char *intf,
3732 struct sigma_cmd *cmd)
3733{
3734 const char *name, *path;
3735 char url[500], buf[600];
3736
3737 name = get_param(cmd, "FileName");
3738 path = get_param(cmd, "FilePath");
3739 if (name == NULL || path == NULL)
3740 return -1;
3741
3742 if (strcasecmp(path, "VendorSpecific") == 0) {
3743 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3744 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3745 "certificate from the device (%s)", url);
3746 if (!file_exists(url)) {
3747 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3748 "certificate file does not exist");
3749 return 0;
3750 }
3751 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3752 if (system(buf) != 0) {
3753 send_resp(dut, conn, SIGMA_ERROR,
3754 "errorCode,Failed to copy client "
3755 "certificate");
3756 return 0;
3757 }
3758
3759 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3760 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3761 "private key from the device (%s)", url);
3762 if (!file_exists(url)) {
3763 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3764 "private key file does not exist");
3765 return 0;
3766 }
3767 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3768 if (system(buf) != 0) {
3769 send_resp(dut, conn, SIGMA_ERROR,
3770 "errorCode,Failed to copy client key");
3771 return 0;
3772 }
3773 } else if (strncasecmp(path, "http:", 5) != 0 &&
3774 strncasecmp(path, "https:", 6) != 0) {
3775 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3776 "Unsupported FilePath value");
3777 return 0;
3778 } else {
3779 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3780 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3781 "certificate/key from %s", url);
3782 snprintf(buf, sizeof(buf),
3783 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3784 if (system(buf) != 0) {
3785 send_resp(dut, conn, SIGMA_ERROR,
3786 "errorCode,Failed to download client "
3787 "certificate");
3788 return 0;
3789 }
3790
3791 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3792 {
3793 send_resp(dut, conn, SIGMA_ERROR,
3794 "errorCode,Failed to copy client key");
3795 return 0;
3796 }
3797 }
3798
3799 return 1;
3800}
3801
3802
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003803static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3804 struct sigma_conn *conn,
3805 struct sigma_cmd *cmd)
3806{
3807 const char *val;
3808 const char *intf = get_param(cmd, "interface");
3809
3810 if (!intf)
3811 return -1;
3812
3813 val = get_param(cmd, "WscIEFragment");
3814 if (val && strcasecmp(val, "enable") == 0) {
3815 sigma_dut_print(dut, DUT_MSG_DEBUG,
3816 "Enable WSC IE fragmentation");
3817
3818 dut->wsc_fragment = 1;
3819 /* set long attributes to force fragmentation */
3820 if (wpa_command(intf, "SET device_name "
3821 WPS_LONG_DEVICE_NAME) < 0)
3822 return -2;
3823 if (wpa_command(intf, "SET manufacturer "
3824 WPS_LONG_MANUFACTURER) < 0)
3825 return -2;
3826 if (wpa_command(intf, "SET model_name "
3827 WPS_LONG_MODEL_NAME) < 0)
3828 return -2;
3829 if (wpa_command(intf, "SET model_number "
3830 WPS_LONG_MODEL_NUMBER) < 0)
3831 return -2;
3832 if (wpa_command(intf, "SET serial_number "
3833 WPS_LONG_SERIAL_NUMBER) < 0)
3834 return -2;
3835 }
3836
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003837 val = get_param(cmd, "RSN_IE");
3838 if (val) {
3839 if (strcasecmp(val, "disable") == 0)
3840 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3841 else if (strcasecmp(val, "enable") == 0)
3842 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3843 }
3844
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003845 val = get_param(cmd, "WpsVersion");
3846 if (val)
3847 dut->wps_forced_version = get_wps_forced_version(dut, val);
3848
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003849 val = get_param(cmd, "WscEAPFragment");
3850 if (val && strcasecmp(val, "enable") == 0)
3851 dut->eap_fragment = 1;
3852
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003853 return 1;
3854}
3855
3856
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003857static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3858 struct sigma_conn *conn,
3859 const char *intf,
3860 struct sigma_cmd *cmd)
3861{
3862 const char *val;
3863
3864 val = get_param(cmd, "FileType");
3865 if (val && strcasecmp(val, "PPSMO") == 0)
3866 return download_ppsmo(dut, conn, intf, cmd);
3867 if (val && strcasecmp(val, "CERT") == 0)
3868 return download_cert(dut, conn, intf, cmd);
3869 if (val) {
3870 send_resp(dut, conn, SIGMA_ERROR,
3871 "ErrorCode,Unsupported FileType");
3872 return 0;
3873 }
3874
3875 return 1;
3876}
3877
3878
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303879static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3880 struct sigma_conn *conn,
3881 const char *intf,
3882 struct sigma_cmd *cmd)
3883{
3884 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303885 char buf[1000];
3886 char text[20];
3887 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303888
3889 val = get_param(cmd, "OCESupport");
3890 if (val && strcasecmp(val, "Disable") == 0) {
3891 if (wpa_command(intf, "SET oce 0") < 0) {
3892 send_resp(dut, conn, SIGMA_ERROR,
3893 "ErrorCode,Failed to disable OCE");
3894 return 0;
3895 }
3896 } else if (val && strcasecmp(val, "Enable") == 0) {
3897 if (wpa_command(intf, "SET oce 1") < 0) {
3898 send_resp(dut, conn, SIGMA_ERROR,
3899 "ErrorCode,Failed to enable OCE");
3900 return 0;
3901 }
3902 }
3903
vamsi krishnaa2799492017-12-05 14:28:01 +05303904 val = get_param(cmd, "FILScap");
3905 if (val && (atoi(val) == 1)) {
3906 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3907 send_resp(dut, conn, SIGMA_ERROR,
3908 "ErrorCode,Failed to enable FILS");
3909 return 0;
3910 }
3911 } else if (val && (atoi(val) == 0)) {
3912 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3913 send_resp(dut, conn, SIGMA_ERROR,
3914 "ErrorCode,Failed to disable FILS");
3915 return 0;
3916 }
3917 }
3918
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303919 val = get_param(cmd, "FILSHLP");
3920 if (val && strcasecmp(val, "Enable") == 0) {
3921 if (get_wpa_status(get_station_ifname(), "address", text,
3922 sizeof(text)) < 0)
3923 return -2;
3924 hwaddr_aton(text, addr);
3925 snprintf(buf, sizeof(buf),
3926 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3927 "080045100140000040004011399e00000000ffffffff00440043"
3928 "012cb30001010600fd4f46410000000000000000000000000000"
3929 "000000000000"
3930 "%02x%02x%02x%02x%02x%02x"
3931 "0000000000000000000000000000000000000000000000000000"
3932 "0000000000000000000000000000000000000000000000000000"
3933 "0000000000000000000000000000000000000000000000000000"
3934 "0000000000000000000000000000000000000000000000000000"
3935 "0000000000000000000000000000000000000000000000000000"
3936 "0000000000000000000000000000000000000000000000000000"
3937 "0000000000000000000000000000000000000000000000000000"
3938 "0000000000000000000000000000000000000000638253633501"
3939 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3940 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3941 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3942 if (wpa_command(intf, buf)) {
3943 send_resp(dut, conn, SIGMA_ERROR,
3944 "ErrorCode,Failed to add HLP");
3945 return 0;
3946 }
3947 dut->fils_hlp = 1;
3948 }
3949
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303950 return 1;
3951}
3952
3953
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003954static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3955 const char *val)
3956{
3957 int counter = 0;
3958 char token[50];
3959 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303960 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003961
Peng Xub8fc5cc2017-05-10 17:27:28 -07003962 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003963 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303964 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003965 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003966 if (strcmp(result, "disable") == 0)
3967 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
3968 else
3969 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303970 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003971 counter++;
3972 }
3973}
3974
3975
3976static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3977 const char *val)
3978{
3979 char buf[100];
3980
3981 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3982 if (system(buf) != 0) {
3983 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3984 }
3985}
3986
3987
3988static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3989 const char *val)
3990{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003991 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003992 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003993 }
3994}
3995
3996
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003997static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3998 const char *val)
3999{
4000#ifdef NL80211_SUPPORT
4001 struct nl_msg *msg;
4002 int ret = 0;
4003 struct nlattr *params;
4004 int ifindex;
4005 int wmmenable = 1;
4006
4007 if (val &&
4008 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
4009 wmmenable = 0;
4010
4011 ifindex = if_nametoindex(intf);
4012 if (ifindex == 0) {
4013 sigma_dut_print(dut, DUT_MSG_ERROR,
4014 "%s: Index for interface %s failed",
4015 __func__, intf);
4016 return -1;
4017 }
4018
4019 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4020 NL80211_CMD_VENDOR)) ||
4021 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4022 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4023 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4024 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4025 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4026 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
4027 wmmenable)) {
4028 sigma_dut_print(dut, DUT_MSG_ERROR,
4029 "%s: err in adding vendor_cmd and vendor_data",
4030 __func__);
4031 nlmsg_free(msg);
4032 return -1;
4033 }
4034 nla_nest_end(msg, params);
4035
4036 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4037 if (ret) {
4038 sigma_dut_print(dut, DUT_MSG_ERROR,
4039 "%s: err in send_and_recv_msgs, ret=%d",
4040 __func__, ret);
4041 }
4042 return ret;
4043#else /* NL80211_SUPPORT */
4044 sigma_dut_print(dut, DUT_MSG_ERROR,
4045 "WMM cannot be changed without NL80211_SUPPORT defined");
4046 return -1;
4047#endif /* NL80211_SUPPORT */
4048}
4049
4050
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004051static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
4052 const char *val)
4053{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004054 int sgi20;
4055
4056 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4057
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004058 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004059}
4060
4061
4062static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
4063 const char *val)
4064{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304065 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004066
4067 /* Disable Tx Beam forming when using a fixed rate */
4068 ath_disable_txbf(dut, intf);
4069
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05304070 v = atoi(val);
4071 if (v < 0 || v > 32) {
4072 sigma_dut_print(dut, DUT_MSG_ERROR,
4073 "Invalid Fixed MCS rate: %d", v);
4074 return;
4075 }
4076 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004077
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004078 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004079
4080 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004081 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004082}
4083
4084
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004085static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4086 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004087{
4088 char buf[60];
4089
4090 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4091 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4092 else
4093 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4094
4095 if (system(buf) != 0)
4096 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4097}
4098
4099
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004100static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4101 int ampdu)
4102{
4103 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004104 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004105
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004106 if (ampdu)
4107 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004108 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4109 if (system(buf) != 0) {
4110 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4111 return -1;
4112 }
4113
4114 return 0;
4115}
4116
4117
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004118static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4119 const char *val)
4120{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004121 run_iwpriv(dut, intf, "tx_stbc %s", val);
4122 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004123}
4124
4125
4126static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4127 const char *val)
4128{
4129 char buf[60];
4130
Peng Xucc317ed2017-05-18 16:44:37 -07004131 if (strcmp(val, "160") == 0) {
4132 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4133 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004134 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4135 } else if (strcmp(val, "40") == 0) {
4136 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4137 } else if (strcmp(val, "20") == 0) {
4138 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4139 } else if (strcasecmp(val, "Auto") == 0) {
4140 buf[0] = '\0';
4141 } else {
4142 sigma_dut_print(dut, DUT_MSG_ERROR,
4143 "WIDTH/CTS_WIDTH value not supported");
4144 return -1;
4145 }
4146
4147 if (buf[0] != '\0' && system(buf) != 0) {
4148 sigma_dut_print(dut, DUT_MSG_ERROR,
4149 "Failed to set WIDTH/CTS_WIDTH");
4150 return -1;
4151 }
4152
4153 return 0;
4154}
4155
4156
4157int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4158 const char *intf, const char *val)
4159{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004160 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004161 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004162 dut->chwidth = 0;
4163 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004164 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004165 dut->chwidth = 0;
4166 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004167 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004168 dut->chwidth = 1;
4169 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004170 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004171 dut->chwidth = 2;
4172 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004173 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004174 dut->chwidth = 3;
4175 } else {
4176 send_resp(dut, conn, SIGMA_ERROR,
4177 "ErrorCode,WIDTH not supported");
4178 return -1;
4179 }
4180
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004181 return 0;
4182}
4183
4184
4185static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4186 const char *val)
4187{
4188 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004189 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004190
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004191 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004192 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004193 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004194 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004195 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004196 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004197 } else {
4198 sigma_dut_print(dut, DUT_MSG_ERROR,
4199 "SP_STREAM value not supported");
4200 return -1;
4201 }
4202
4203 if (system(buf) != 0) {
4204 sigma_dut_print(dut, DUT_MSG_ERROR,
4205 "Failed to set SP_STREAM");
4206 return -1;
4207 }
4208
Arif Hussainac6c5112018-05-25 17:34:00 -07004209 dut->sta_nss = sta_nss;
4210
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004211 return 0;
4212}
4213
4214
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304215static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4216 const char *val)
4217{
4218 char buf[60];
4219
4220 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4221 if (system(buf) != 0)
4222 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4223
4224 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4225 if (system(buf) != 0)
4226 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4227}
4228
4229
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304230static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4231 struct sigma_conn *conn,
4232 const char *intf, int capa)
4233{
4234 char buf[32];
4235
4236 if (capa > 0 && capa < 4) {
4237 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4238 if (wpa_command(intf, buf) < 0) {
4239 send_resp(dut, conn, SIGMA_ERROR,
4240 "ErrorCode, Failed to set cellular data capability");
4241 return 0;
4242 }
4243 return 1;
4244 }
4245
4246 sigma_dut_print(dut, DUT_MSG_ERROR,
4247 "Invalid Cellular data capability: %d", capa);
4248 send_resp(dut, conn, SIGMA_INVALID,
4249 "ErrorCode,Invalid cellular data capability");
4250 return 0;
4251}
4252
4253
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304254static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4255 const char *intf, const char *val)
4256{
4257 if (strcasecmp(val, "Disable") == 0) {
4258 if (wpa_command(intf, "SET roaming 0") < 0) {
4259 send_resp(dut, conn, SIGMA_ERROR,
4260 "ErrorCode,Failed to disable roaming");
4261 return 0;
4262 }
4263 return 1;
4264 }
4265
4266 if (strcasecmp(val, "Enable") == 0) {
4267 if (wpa_command(intf, "SET roaming 1") < 0) {
4268 send_resp(dut, conn, SIGMA_ERROR,
4269 "ErrorCode,Failed to enable roaming");
4270 return 0;
4271 }
4272 return 1;
4273 }
4274
4275 sigma_dut_print(dut, DUT_MSG_ERROR,
4276 "Invalid value provided for roaming: %s", val);
4277 send_resp(dut, conn, SIGMA_INVALID,
4278 "ErrorCode,Unknown value provided for Roaming");
4279 return 0;
4280}
4281
4282
Ashwini Patila75de5a2017-04-13 16:35:05 +05304283static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4284 struct sigma_conn *conn,
4285 const char *intf, const char *val)
4286{
4287 if (strcasecmp(val, "Disable") == 0) {
4288 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4289 send_resp(dut, conn, SIGMA_ERROR,
4290 "ErrorCode,Failed to disable Assoc_disallow");
4291 return 0;
4292 }
4293 return 1;
4294 }
4295
4296 if (strcasecmp(val, "Enable") == 0) {
4297 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4298 send_resp(dut, conn, SIGMA_ERROR,
4299 "ErrorCode,Failed to enable Assoc_disallow");
4300 return 0;
4301 }
4302 return 1;
4303 }
4304
4305 sigma_dut_print(dut, DUT_MSG_ERROR,
4306 "Invalid value provided for Assoc_disallow: %s", val);
4307 send_resp(dut, conn, SIGMA_INVALID,
4308 "ErrorCode,Unknown value provided for Assoc_disallow");
4309 return 0;
4310}
4311
4312
Ashwini Patilc63161e2017-04-13 16:30:23 +05304313static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4314 const char *intf, const char *val)
4315{
4316 if (strcasecmp(val, "Reject") == 0) {
4317 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4318 send_resp(dut, conn, SIGMA_ERROR,
4319 "ErrorCode,Failed to Reject BTM Request");
4320 return 0;
4321 }
4322 return 1;
4323 }
4324
4325 if (strcasecmp(val, "Accept") == 0) {
4326 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4327 send_resp(dut, conn, SIGMA_ERROR,
4328 "ErrorCode,Failed to Accept BTM Request");
4329 return 0;
4330 }
4331 return 1;
4332 }
4333
4334 sigma_dut_print(dut, DUT_MSG_ERROR,
4335 "Invalid value provided for BSS_Transition: %s", val);
4336 send_resp(dut, conn, SIGMA_INVALID,
4337 "ErrorCode,Unknown value provided for BSS_Transition");
4338 return 0;
4339}
4340
4341
Ashwini Patil00402582017-04-13 12:29:39 +05304342static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4343 struct sigma_conn *conn,
4344 const char *intf,
4345 struct sigma_cmd *cmd)
4346{
4347 const char *ch, *pref, *op_class, *reason;
4348 char buf[120];
4349 int len, ret;
4350
4351 pref = get_param(cmd, "Ch_Pref");
4352 if (!pref)
4353 return 1;
4354
4355 if (strcasecmp(pref, "clear") == 0) {
4356 free(dut->non_pref_ch_list);
4357 dut->non_pref_ch_list = NULL;
4358 } else {
4359 op_class = get_param(cmd, "Ch_Op_Class");
4360 if (!op_class) {
4361 send_resp(dut, conn, SIGMA_INVALID,
4362 "ErrorCode,Ch_Op_Class not provided");
4363 return 0;
4364 }
4365
4366 ch = get_param(cmd, "Ch_Pref_Num");
4367 if (!ch) {
4368 send_resp(dut, conn, SIGMA_INVALID,
4369 "ErrorCode,Ch_Pref_Num not provided");
4370 return 0;
4371 }
4372
4373 reason = get_param(cmd, "Ch_Reason_Code");
4374 if (!reason) {
4375 send_resp(dut, conn, SIGMA_INVALID,
4376 "ErrorCode,Ch_Reason_Code not provided");
4377 return 0;
4378 }
4379
4380 if (!dut->non_pref_ch_list) {
4381 dut->non_pref_ch_list =
4382 calloc(1, NON_PREF_CH_LIST_SIZE);
4383 if (!dut->non_pref_ch_list) {
4384 send_resp(dut, conn, SIGMA_ERROR,
4385 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4386 return 0;
4387 }
4388 }
4389 len = strlen(dut->non_pref_ch_list);
4390 ret = snprintf(dut->non_pref_ch_list + len,
4391 NON_PREF_CH_LIST_SIZE - len,
4392 " %s:%s:%s:%s", op_class, ch, pref, reason);
4393 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4394 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4395 dut->non_pref_ch_list);
4396 } else {
4397 sigma_dut_print(dut, DUT_MSG_ERROR,
4398 "snprintf failed for non_pref_list, ret = %d",
4399 ret);
4400 send_resp(dut, conn, SIGMA_ERROR,
4401 "ErrorCode,snprintf failed");
4402 free(dut->non_pref_ch_list);
4403 dut->non_pref_ch_list = NULL;
4404 return 0;
4405 }
4406 }
4407
4408 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4409 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4410 if (ret < 0 || ret >= (int) sizeof(buf)) {
4411 sigma_dut_print(dut, DUT_MSG_DEBUG,
4412 "snprintf failed for set non_pref_chan, ret: %d",
4413 ret);
4414 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4415 return 0;
4416 }
4417
4418 if (wpa_command(intf, buf) < 0) {
4419 send_resp(dut, conn, SIGMA_ERROR,
4420 "ErrorCode,Failed to set non-preferred channel list");
4421 return 0;
4422 }
4423
4424 return 1;
4425}
4426
4427
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004428#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004429
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004430static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4431 uint8_t cfg)
4432{
4433 struct nl_msg *msg;
4434 int ret = 0;
4435 struct nlattr *params;
4436 int ifindex;
4437
4438 ifindex = if_nametoindex(intf);
4439 if (ifindex == 0) {
4440 sigma_dut_print(dut, DUT_MSG_ERROR,
4441 "%s: Index for interface %s failed",
4442 __func__, intf);
4443 return -1;
4444 }
4445
4446 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4447 NL80211_CMD_VENDOR)) ||
4448 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4449 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4450 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4451 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4452 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4453 nla_put_u8(msg,
4454 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4455 cfg)) {
4456 sigma_dut_print(dut, DUT_MSG_ERROR,
4457 "%s: err in adding vendor_cmd and vendor_data",
4458 __func__);
4459 nlmsg_free(msg);
4460 return -1;
4461 }
4462 nla_nest_end(msg, params);
4463
4464 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4465 if (ret) {
4466 sigma_dut_print(dut, DUT_MSG_ERROR,
4467 "%s: err in send_and_recv_msgs, ret=%d",
4468 __func__, ret);
4469 }
4470 return ret;
4471}
4472
4473
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004474static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4475 enum he_fragmentation_val frag)
4476{
4477 struct nl_msg *msg;
4478 int ret = 0;
4479 struct nlattr *params;
4480 int ifindex;
4481
4482 ifindex = if_nametoindex(intf);
4483 if (ifindex == 0) {
4484 sigma_dut_print(dut, DUT_MSG_ERROR,
4485 "%s: Index for interface %s failed",
4486 __func__, intf);
4487 return -1;
4488 }
4489
4490 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4491 NL80211_CMD_VENDOR)) ||
4492 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4493 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4494 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4495 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4496 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4497 nla_put_u8(msg,
4498 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4499 frag)) {
4500 sigma_dut_print(dut, DUT_MSG_ERROR,
4501 "%s: err in adding vendor_cmd and vendor_data",
4502 __func__);
4503 nlmsg_free(msg);
4504 return -1;
4505 }
4506 nla_nest_end(msg, params);
4507
4508 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4509 if (ret) {
4510 sigma_dut_print(dut, DUT_MSG_ERROR,
4511 "%s: err in send_and_recv_msgs, ret=%d",
4512 __func__, ret);
4513 }
4514 return ret;
4515}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004516
4517
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004518static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
4519 enum qca_wlan_he_ltf_cfg ltf)
4520{
4521 struct nl_msg *msg;
4522 int ret = 0;
4523 struct nlattr *params;
4524 int ifindex;
4525
4526 ifindex = if_nametoindex(intf);
4527 if (ifindex == 0) {
4528 sigma_dut_print(dut, DUT_MSG_ERROR,
4529 "%s: Index for interface %s failed",
4530 __func__, intf);
4531 return -1;
4532 }
4533
4534 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4535 NL80211_CMD_VENDOR)) ||
4536 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4537 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4538 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4539 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4540 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4541 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4542 ltf)) {
4543 sigma_dut_print(dut, DUT_MSG_ERROR,
4544 "%s: err in adding vendor_cmd and vendor_data",
4545 __func__);
4546 nlmsg_free(msg);
4547 return -1;
4548 }
4549 nla_nest_end(msg, params);
4550
4551 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4552 if (ret) {
4553 sigma_dut_print(dut, DUT_MSG_ERROR,
4554 "%s: err in send_and_recv_msgs, ret=%d",
4555 __func__, ret);
4556 }
4557 return ret;
4558}
4559
4560
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004561static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4562 int noack, enum qca_wlan_ac_type ac)
4563{
4564 struct nl_msg *msg;
4565 int ret = 0;
4566 struct nlattr *params;
4567 int ifindex;
4568
4569 ifindex = if_nametoindex(intf);
4570 if (ifindex == 0) {
4571 sigma_dut_print(dut, DUT_MSG_ERROR,
4572 "%s: Index for interface %s failed",
4573 __func__, intf);
4574 return -1;
4575 }
4576
4577 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4578 NL80211_CMD_VENDOR)) ||
4579 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4580 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4581 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4582 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4583 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4584 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4585 noack) ||
4586 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4587 ac)) {
4588 sigma_dut_print(dut, DUT_MSG_ERROR,
4589 "%s: err in adding vendor_cmd and vendor_data",
4590 __func__);
4591 nlmsg_free(msg);
4592 return -1;
4593 }
4594 nla_nest_end(msg, params);
4595
4596 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4597 if (ret) {
4598 sigma_dut_print(dut, DUT_MSG_ERROR,
4599 "%s: err in send_and_recv_msgs, ret=%d",
4600 __func__, ret);
4601 }
4602 return ret;
4603}
4604
4605
4606static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4607 const char *val)
4608{
4609 int noack, ret;
4610 char token[100];
4611 char *result;
4612 char *saveptr;
4613 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4614
4615 strlcpy(token, val, sizeof(token));
4616 token[sizeof(token) - 1] = '\0';
4617 result = strtok_r(token, ":", &saveptr);
4618 while (result) {
4619 noack = strcasecmp(result, "Disable") != 0;
4620 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4621 if (ret) {
4622 sigma_dut_print(dut, DUT_MSG_ERROR,
4623 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4624 ac, ret);
4625 }
4626 result = strtok_r(NULL, ":", &saveptr);
4627 ac++;
4628 }
4629}
4630
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004631#endif /* NL80211_SUPPORT */
4632
4633
Jouni Malinenf7222712019-06-13 01:50:21 +03004634static enum sigma_cmd_result
4635cmd_sta_preset_testparameters(struct sigma_dut *dut, struct sigma_conn *conn,
4636 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004637{
4638 const char *intf = get_param(cmd, "Interface");
4639 const char *val;
4640
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03004641 val = get_param(cmd, "FT_DS");
4642 if (val) {
4643 if (strcasecmp(val, "Enable") == 0) {
4644 dut->sta_ft_ds = 1;
4645 } else if (strcasecmp(val, "Disable") == 0) {
4646 dut->sta_ft_ds = 0;
4647 } else {
4648 send_resp(dut, conn, SIGMA_ERROR,
4649 "errorCode,Unsupported value for FT_DS");
4650 return STATUS_SENT_ERROR;
4651 }
4652 }
4653
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004654 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004655 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4656 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004657 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4658 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004659
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004660 if (val && strcasecmp(val, "LOC") == 0)
4661 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004662 if (val && strcasecmp(val, "60GHZ") == 0) {
4663 val = get_param(cmd, "WPS");
4664 if (val && strcasecmp(val, "disable") == 0) {
4665 dut->wps_disable = 1;
4666 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4667 } else {
4668 /* wps_disable can have other value from the previous
4669 * test, so make sure it has the correct value.
4670 */
4671 dut->wps_disable = 0;
4672 }
4673
4674 val = get_param(cmd, "P2P");
4675 if (val && strcasecmp(val, "disable") == 0)
4676 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4677 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004678
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004679 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4680 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4681
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004682#ifdef ANDROID_NAN
4683 if (val && strcasecmp(val, "NAN") == 0)
4684 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4685#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004686#ifdef MIRACAST
4687 if (val && (strcasecmp(val, "WFD") == 0 ||
4688 strcasecmp(val, "DisplayR2") == 0))
4689 return miracast_preset_testparameters(dut, conn, cmd);
4690#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004691
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304692 if (val && strcasecmp(val, "MBO") == 0) {
4693 val = get_param(cmd, "Cellular_Data_Cap");
4694 if (val &&
4695 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4696 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304697
4698 val = get_param(cmd, "Ch_Pref");
4699 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4700 return 0;
4701
Ashwini Patilc63161e2017-04-13 16:30:23 +05304702 val = get_param(cmd, "BSS_Transition");
4703 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4704 return 0;
4705
Ashwini Patila75de5a2017-04-13 16:35:05 +05304706 val = get_param(cmd, "Assoc_Disallow");
4707 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4708 return 0;
4709
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304710 val = get_param(cmd, "Roaming");
4711 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4712 return 0;
4713
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304714 return 1;
4715 }
4716
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304717 if (val && strcasecmp(val, "OCE") == 0)
4718 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4719
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004720#if 0
4721 val = get_param(cmd, "Supplicant");
4722 if (val && strcasecmp(val, "Default") != 0) {
4723 send_resp(dut, conn, SIGMA_ERROR,
4724 "ErrorCode,Only default(Vendor) supplicant "
4725 "supported");
4726 return 0;
4727 }
4728#endif
4729
4730 val = get_param(cmd, "RTS");
4731 if (val) {
4732 switch (get_driver_type()) {
4733 case DRIVER_ATHEROS:
4734 ath_sta_set_rts(dut, intf, val);
4735 break;
4736 default:
4737#if 0
4738 send_resp(dut, conn, SIGMA_ERROR,
4739 "ErrorCode,Setting RTS not supported");
4740 return 0;
4741#else
4742 sigma_dut_print(dut, DUT_MSG_DEBUG,
4743 "Setting RTS not supported");
4744 break;
4745#endif
4746 }
4747 }
4748
4749#if 0
4750 val = get_param(cmd, "FRGMNT");
4751 if (val) {
4752 /* TODO */
4753 send_resp(dut, conn, SIGMA_ERROR,
4754 "ErrorCode,Setting FRGMNT not supported");
4755 return 0;
4756 }
4757#endif
4758
4759#if 0
4760 val = get_param(cmd, "Preamble");
4761 if (val) {
4762 /* TODO: Long/Short */
4763 send_resp(dut, conn, SIGMA_ERROR,
4764 "ErrorCode,Setting Preamble not supported");
4765 return 0;
4766 }
4767#endif
4768
4769 val = get_param(cmd, "Mode");
4770 if (val) {
4771 if (strcmp(val, "11b") == 0 ||
4772 strcmp(val, "11g") == 0 ||
4773 strcmp(val, "11a") == 0 ||
4774 strcmp(val, "11n") == 0 ||
4775 strcmp(val, "11ng") == 0 ||
4776 strcmp(val, "11nl") == 0 ||
4777 strcmp(val, "11nl(nabg)") == 0 ||
4778 strcmp(val, "AC") == 0 ||
4779 strcmp(val, "11AC") == 0 ||
4780 strcmp(val, "11ac") == 0 ||
4781 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004782 strcmp(val, "11an") == 0 ||
4783 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004784 /* STA supports all modes by default */
4785 } else {
4786 send_resp(dut, conn, SIGMA_ERROR,
4787 "ErrorCode,Setting Mode not supported");
4788 return 0;
4789 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004790
4791 /* Change the mode only in case of testbed for HE program
4792 * and for 11a and 11g modes only. */
4793 if (dut->program == PROGRAM_HE &&
4794 dut->device_type == STA_testbed) {
4795 int phymode;
4796 char buf[60];
4797
4798 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004799 phymode = 1; /* IEEE80211_MODE_11A */
4800 } else if (strcmp(val, "11g") == 0) {
4801 phymode = 3; /* IEEE80211_MODE_11G */
4802 } else if (strcmp(val, "11b") == 0) {
4803 phymode = 2; /* IEEE80211_MODE_11B */
4804 } else if (strcmp(val, "11n") == 0 ||
4805 strcmp(val, "11nl") == 0 ||
4806 strcmp(val, "11nl(nabg)") == 0) {
4807 phymode = 22; /* IEEE80211_MODE_11AGN */
4808 } else if (strcmp(val, "11ng") == 0) {
4809 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4810 } else if (strcmp(val, "AC") == 0 ||
4811 strcasecmp(val, "11AC") == 0) {
4812 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4813 } else if (strcmp(val, "11na") == 0 ||
4814 strcasecmp(val, "11an") == 0) {
4815 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4816 } else if (strcmp(val, "11ax") == 0) {
4817 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004818 } else {
4819 sigma_dut_print(dut, DUT_MSG_DEBUG,
4820 "Ignoring mode change for mode: %s",
4821 val);
4822 phymode = -1;
4823 }
4824 if (phymode != -1) {
4825 snprintf(buf, sizeof(buf),
4826 "iwpriv %s setphymode %d",
4827 intf, phymode);
4828 if (system(buf) != 0) {
4829 sigma_dut_print(dut, DUT_MSG_ERROR,
4830 "iwpriv setting of phymode failed");
4831 }
4832 }
4833 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004834 }
4835
4836 val = get_param(cmd, "wmm");
4837 if (val) {
4838 switch (get_driver_type()) {
4839 case DRIVER_ATHEROS:
4840 ath_sta_set_wmm(dut, intf, val);
4841 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004842 case DRIVER_WCN:
4843 wcn_sta_set_wmm(dut, intf, val);
4844 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004845 default:
4846 sigma_dut_print(dut, DUT_MSG_DEBUG,
4847 "Setting wmm not supported");
4848 break;
4849 }
4850 }
4851
4852 val = get_param(cmd, "Powersave");
4853 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004854 char buf[60];
4855
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004856 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004857 if (get_driver_type() == DRIVER_WCN) {
4858 snprintf(buf, sizeof(buf),
4859 "iwpriv %s setPower 2", intf);
4860 if (system(buf) != 0) {
4861 sigma_dut_print(dut, DUT_MSG_ERROR,
4862 "iwpriv setPower 2 failed");
4863 return 0;
4864 }
4865 }
4866
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004867 if (wpa_command(get_station_ifname(),
4868 "P2P_SET ps 0") < 0)
4869 return -2;
4870 /* Make sure test modes are disabled */
4871 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4872 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4873 } else if (strcmp(val, "1") == 0 ||
4874 strcasecmp(val, "PSPoll") == 0 ||
4875 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004876 if (get_driver_type() == DRIVER_WCN) {
4877 snprintf(buf, sizeof(buf),
4878 "iwpriv %s setPower 1", intf);
4879 if (system(buf) != 0) {
4880 sigma_dut_print(dut, DUT_MSG_ERROR,
4881 "iwpriv setPower 1 failed");
4882 return 0;
4883 }
4884 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004885 /* Disable default power save mode */
4886 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4887 /* Enable PS-Poll test mode */
4888 if (wpa_command(get_station_ifname(),
4889 "P2P_SET ps 97") < 0 ||
4890 wpa_command(get_station_ifname(),
4891 "P2P_SET ps 99") < 0)
4892 return -2;
4893 } else if (strcmp(val, "2") == 0 ||
4894 strcasecmp(val, "Fast") == 0) {
4895 /* TODO */
4896 send_resp(dut, conn, SIGMA_ERROR,
4897 "ErrorCode,Powersave=Fast not supported");
4898 return 0;
4899 } else if (strcmp(val, "3") == 0 ||
4900 strcasecmp(val, "PSNonPoll") == 0) {
4901 /* Make sure test modes are disabled */
4902 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4903 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4904
4905 /* Enable default power save mode */
4906 if (wpa_command(get_station_ifname(),
4907 "P2P_SET ps 1") < 0)
4908 return -2;
4909 } else
4910 return -1;
4911 }
4912
4913 val = get_param(cmd, "NoAck");
4914 if (val) {
4915 switch (get_driver_type()) {
4916 case DRIVER_ATHEROS:
4917 ath_sta_set_noack(dut, intf, val);
4918 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004919#ifdef NL80211_SUPPORT
4920 case DRIVER_WCN:
4921 wcn_sta_set_noack(dut, intf, val);
4922 break;
4923#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004924 default:
4925 send_resp(dut, conn, SIGMA_ERROR,
4926 "ErrorCode,Setting NoAck not supported");
4927 return 0;
4928 }
4929 }
4930
4931 val = get_param(cmd, "IgnoreChswitchProhibit");
4932 if (val) {
4933 /* TODO: Enabled/disabled */
4934 if (strcasecmp(val, "Enabled") == 0) {
4935 send_resp(dut, conn, SIGMA_ERROR,
4936 "ErrorCode,Enabling IgnoreChswitchProhibit "
4937 "not supported");
4938 return 0;
4939 }
4940 }
4941
4942 val = get_param(cmd, "TDLS");
4943 if (val) {
4944 if (strcasecmp(val, "Disabled") == 0) {
4945 if (wpa_command(intf, "SET tdls_disabled 1")) {
4946 send_resp(dut, conn, SIGMA_ERROR,
4947 "ErrorCode,Failed to disable TDLS");
4948 return 0;
4949 }
4950 } else if (strcasecmp(val, "Enabled") == 0) {
4951 if (wpa_command(intf, "SET tdls_disabled 0")) {
4952 send_resp(dut, conn, SIGMA_ERROR,
4953 "ErrorCode,Failed to enable TDLS");
4954 return 0;
4955 }
4956 } else {
4957 send_resp(dut, conn, SIGMA_ERROR,
4958 "ErrorCode,Unsupported TDLS value");
4959 return 0;
4960 }
4961 }
4962
4963 val = get_param(cmd, "TDLSmode");
4964 if (val) {
4965 if (strcasecmp(val, "Default") == 0) {
4966 wpa_command(intf, "SET tdls_testing 0");
4967 } else if (strcasecmp(val, "APProhibit") == 0) {
4968 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4969 send_resp(dut, conn, SIGMA_ERROR,
4970 "ErrorCode,Failed to enable ignore "
4971 "APProhibit TDLS mode");
4972 return 0;
4973 }
4974 } else if (strcasecmp(val, "HiLoMac") == 0) {
4975 /* STA should respond with TDLS setup req for a TDLS
4976 * setup req */
4977 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4978 send_resp(dut, conn, SIGMA_ERROR,
4979 "ErrorCode,Failed to enable HiLoMac "
4980 "TDLS mode");
4981 return 0;
4982 }
4983 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4984 /*
4985 * Since all security modes are enabled by default when
4986 * Sigma control is used, there is no need to do
4987 * anything here.
4988 */
4989 } else if (strcasecmp(val, "ExistLink") == 0) {
4990 /*
4991 * Since we allow new TDLS Setup Request even if there
4992 * is an existing link, nothing needs to be done for
4993 * this.
4994 */
4995 } else {
4996 /* TODO:
4997 * ExistLink: STA should send TDLS setup req even if
4998 * direct link already exists
4999 */
5000 send_resp(dut, conn, SIGMA_ERROR,
5001 "ErrorCode,Unsupported TDLSmode value");
5002 return 0;
5003 }
5004 }
5005
5006 val = get_param(cmd, "FakePubKey");
5007 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
5008 send_resp(dut, conn, SIGMA_ERROR,
5009 "ErrorCode,Failed to enable FakePubKey");
5010 return 0;
5011 }
5012
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08005013#ifdef NL80211_SUPPORT
5014 val = get_param(cmd, "FrgmntSupport");
5015 if (val) {
5016 if (strcasecmp(val, "Enable") == 0) {
5017 if (sta_set_he_fragmentation(dut, intf,
5018 HE_FRAG_LEVEL1)) {
5019 send_resp(dut, conn, SIGMA_ERROR,
5020 "ErrorCode,Failed to enable HE Fragmentation");
5021 return 0;
5022 }
5023 } else if (strcasecmp(val, "Disable") == 0) {
5024 if (sta_set_he_fragmentation(dut, intf,
5025 HE_FRAG_DISABLE)) {
5026 send_resp(dut, conn, SIGMA_ERROR,
5027 "ErrorCode,Failed to disable HE Fragmentation");
5028 return 0;
5029 }
5030 }
5031 }
5032#endif /* NL80211_SUPPORT */
5033
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005034 return 1;
5035}
5036
5037
5038static const char * ath_get_radio_name(const char *radio_name)
5039{
5040 if (radio_name == NULL)
5041 return "wifi0";
5042 if (strcmp(radio_name, "wifi1") == 0)
5043 return "wifi1";
5044 if (strcmp(radio_name, "wifi2") == 0)
5045 return "wifi2";
5046 return "wifi0";
5047}
5048
5049
5050static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
5051 const char *val)
5052{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005053 unsigned int vht_mcsmap = 0;
5054 int txchainmask = 0;
5055 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5056
5057 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5058 if (dut->testbed_flag_txsp == 1) {
5059 vht_mcsmap = 0xfffc;
5060 dut->testbed_flag_txsp = 0;
5061 } else {
5062 vht_mcsmap = 0xfffe;
5063 }
5064 txchainmask = 1;
5065 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5066 if (dut->testbed_flag_txsp == 1) {
5067 vht_mcsmap = 0xfff0;
5068 dut->testbed_flag_txsp = 0;
5069 } else {
5070 vht_mcsmap = 0xfffa;
5071 }
5072 txchainmask = 3;
5073 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5074 if (dut->testbed_flag_txsp == 1) {
5075 vht_mcsmap = 0xffc0;
5076 dut->testbed_flag_txsp = 0;
5077 } else {
5078 vht_mcsmap = 0xffea;
5079 }
5080 txchainmask = 7;
5081 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5082 if (dut->testbed_flag_txsp == 1) {
5083 vht_mcsmap = 0xff00;
5084 dut->testbed_flag_txsp = 0;
5085 } else {
5086 vht_mcsmap = 0xffaa;
5087 }
5088 txchainmask = 15;
5089 } else {
5090 if (dut->testbed_flag_txsp == 1) {
5091 vht_mcsmap = 0xffc0;
5092 dut->testbed_flag_txsp = 0;
5093 } else {
5094 vht_mcsmap = 0xffea;
5095 }
5096 }
5097
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005098 if (txchainmask)
5099 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005100
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005101 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005102}
5103
5104
5105static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5106 const char *val)
5107{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005108 unsigned int vht_mcsmap = 0;
5109 int rxchainmask = 0;
5110 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5111
5112 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5113 if (dut->testbed_flag_rxsp == 1) {
5114 vht_mcsmap = 0xfffc;
5115 dut->testbed_flag_rxsp = 0;
5116 } else {
5117 vht_mcsmap = 0xfffe;
5118 }
5119 rxchainmask = 1;
5120 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5121 if (dut->testbed_flag_rxsp == 1) {
5122 vht_mcsmap = 0xfff0;
5123 dut->testbed_flag_rxsp = 0;
5124 } else {
5125 vht_mcsmap = 0xfffa;
5126 }
5127 rxchainmask = 3;
5128 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5129 if (dut->testbed_flag_rxsp == 1) {
5130 vht_mcsmap = 0xffc0;
5131 dut->testbed_flag_rxsp = 0;
5132 } else {
5133 vht_mcsmap = 0xffea;
5134 }
5135 rxchainmask = 7;
5136 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5137 if (dut->testbed_flag_rxsp == 1) {
5138 vht_mcsmap = 0xff00;
5139 dut->testbed_flag_rxsp = 0;
5140 } else {
5141 vht_mcsmap = 0xffaa;
5142 }
5143 rxchainmask = 15;
5144 } else {
5145 if (dut->testbed_flag_rxsp == 1) {
5146 vht_mcsmap = 0xffc0;
5147 dut->testbed_flag_rxsp = 0;
5148 } else {
5149 vht_mcsmap = 0xffea;
5150 }
5151 }
5152
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005153 if (rxchainmask)
5154 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005155
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005156 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005157}
5158
5159
5160void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5161{
5162 if (strcasecmp(val, "enable") == 0) {
5163 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5164 != 0) {
5165 sigma_dut_print(dut, DUT_MSG_ERROR,
5166 "Disable BB_VHTSIGB_CRC_CALC failed");
5167 }
5168
5169 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5170 != 0) {
5171 sigma_dut_print(dut, DUT_MSG_ERROR,
5172 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5173 }
5174 } else {
5175 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5176 != 0) {
5177 sigma_dut_print(dut, DUT_MSG_ERROR,
5178 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5179 }
5180
5181 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5182 != 0) {
5183 sigma_dut_print(dut, DUT_MSG_ERROR,
5184 "Enable BB_VHTSIGB_CRC_CALC failed");
5185 }
5186 }
5187}
5188
5189
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005190static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5191 const char *val)
5192{
5193 char buf[60];
5194
5195 if (strcmp(val, "20") == 0) {
5196 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5197 dut->chwidth = 0;
5198 } else if (strcmp(val, "40") == 0) {
5199 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5200 dut->chwidth = 1;
5201 } else if (strcmp(val, "80") == 0) {
5202 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5203 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305204 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005205 buf[0] = '\0';
5206 } else {
5207 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5208 val);
5209 return -1;
5210 }
5211
5212 if (buf[0] != '\0' && system(buf) != 0) {
5213 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5214 return -1;
5215 }
5216
5217 return 0;
5218}
5219
5220
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005221static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5222 const char *intf, int addbareject)
5223{
5224#ifdef NL80211_SUPPORT
5225 struct nl_msg *msg;
5226 int ret = 0;
5227 struct nlattr *params;
5228 int ifindex;
5229
5230 ifindex = if_nametoindex(intf);
5231 if (ifindex == 0) {
5232 sigma_dut_print(dut, DUT_MSG_ERROR,
5233 "%s: Index for interface %s failed",
5234 __func__, intf);
5235 return -1;
5236 }
5237
5238 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5239 NL80211_CMD_VENDOR)) ||
5240 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5241 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5242 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5243 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5244 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5245 nla_put_u8(msg,
5246 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5247 !addbareject)) {
5248 sigma_dut_print(dut, DUT_MSG_ERROR,
5249 "%s: err in adding vendor_cmd and vendor_data",
5250 __func__);
5251 nlmsg_free(msg);
5252 return -1;
5253 }
5254 nla_nest_end(msg, params);
5255
5256 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5257 if (ret) {
5258 sigma_dut_print(dut, DUT_MSG_ERROR,
5259 "%s: err in send_and_recv_msgs, ret=%d",
5260 __func__, ret);
5261 }
5262 return ret;
5263#else /* NL80211_SUPPORT */
5264 sigma_dut_print(dut, DUT_MSG_ERROR,
5265 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5266 return -1;
5267#endif /* NL80211_SUPPORT */
5268}
5269
5270
5271static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5272 int addbareject)
5273{
5274 int ret;
5275
5276 switch (get_driver_type()) {
5277 case DRIVER_WCN:
5278 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5279 if (ret) {
5280 sigma_dut_print(dut, DUT_MSG_ERROR,
5281 "nlvendor_sta_set_addba_reject failed, ret:%d",
5282 ret);
5283 return ret;
5284 }
5285 break;
5286 default:
5287 sigma_dut_print(dut, DUT_MSG_ERROR,
5288 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5289 ret = -1;
5290 break;
5291 }
5292
5293 return ret;
5294}
5295
5296
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005297static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5298 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005299{
5300#ifdef NL80211_SUPPORT
5301 struct nl_msg *msg;
5302 int ret = 0;
5303 struct nlattr *params;
5304 int ifindex;
5305
5306 ifindex = if_nametoindex(intf);
5307 if (ifindex == 0) {
5308 sigma_dut_print(dut, DUT_MSG_ERROR,
5309 "%s: Index for interface %s failed",
5310 __func__, intf);
5311 return -1;
5312 }
5313
5314 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5315 NL80211_CMD_VENDOR)) ||
5316 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5317 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5318 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5319 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5320 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5321 nla_put_u8(msg,
5322 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005323 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005324 sigma_dut_print(dut, DUT_MSG_ERROR,
5325 "%s: err in adding vendor_cmd and vendor_data",
5326 __func__);
5327 nlmsg_free(msg);
5328 return -1;
5329 }
5330 nla_nest_end(msg, params);
5331
5332 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5333 if (ret) {
5334 sigma_dut_print(dut, DUT_MSG_ERROR,
5335 "%s: err in send_and_recv_msgs, ret=%d",
5336 __func__, ret);
5337 }
5338 return ret;
5339#else /* NL80211_SUPPORT */
5340 sigma_dut_print(dut, DUT_MSG_ERROR,
5341 "Disable addba not possible without NL80211_SUPPORT defined");
5342 return -1;
5343#endif /* NL80211_SUPPORT */
5344}
5345
5346
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305347#ifdef NL80211_SUPPORT
5348static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5349{
5350 struct nl_msg *msg;
5351 int ret = 0;
5352 int ifindex;
5353
5354 ifindex = if_nametoindex(intf);
5355 if (ifindex == 0) {
5356 sigma_dut_print(dut, DUT_MSG_ERROR,
5357 "%s: Index for interface %s failed",
5358 __func__, intf);
5359 return -1;
5360 }
5361
5362 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5363 NL80211_CMD_SET_WIPHY)) ||
5364 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5365 sigma_dut_print(dut, DUT_MSG_ERROR,
5366 "%s: err in adding RTS threshold",
5367 __func__);
5368 nlmsg_free(msg);
5369 return -1;
5370 }
5371
5372 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5373 if (ret) {
5374 sigma_dut_print(dut, DUT_MSG_ERROR,
5375 "%s: err in send_and_recv_msgs, ret=%d",
5376 __func__, ret);
5377 }
5378 return ret;
5379}
5380#endif /* NL80211_SUPPORT */
5381
5382
5383static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5384{
5385 char buf[100];
5386
5387#ifdef NL80211_SUPPORT
5388 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5389 return 0;
5390 sigma_dut_print(dut, DUT_MSG_DEBUG,
5391 "Fall back to using iwconfig for setting RTS threshold");
5392#endif /* NL80211_SUPPORT */
5393
5394 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5395 if (system(buf) != 0) {
5396 sigma_dut_print(dut, DUT_MSG_ERROR,
5397 "Failed to set RTS threshold %d", val);
5398 return -1;
5399 }
5400 return 0;
5401}
5402
5403
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005404static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5405 struct sigma_conn *conn,
5406 struct sigma_cmd *cmd)
5407{
5408 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005409 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005410 char buf[128];
5411 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005412
5413 val = get_param(cmd, "40_INTOLERANT");
5414 if (val) {
5415 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5416 /* TODO: iwpriv ht40intol through wpa_supplicant */
5417 send_resp(dut, conn, SIGMA_ERROR,
5418 "ErrorCode,40_INTOLERANT not supported");
5419 return 0;
5420 }
5421 }
5422
5423 val = get_param(cmd, "ADDBA_REJECT");
5424 if (val) {
5425 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5426 /* reject any ADDBA with status "decline" */
5427 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005428 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005429 } else {
5430 /* accept ADDBA */
5431 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005432 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005433 }
5434 }
5435
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005436 if (addbareject >= 0 &&
5437 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5438 send_resp(dut, conn, SIGMA_ERROR,
5439 "ErrorCode,set addba_reject failed");
5440 return 0;
5441 }
5442
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005443 val = get_param(cmd, "AMPDU");
5444 if (val) {
5445 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5446 /* enable AMPDU Aggregation */
5447 if (ampdu == 0) {
5448 send_resp(dut, conn, SIGMA_ERROR,
5449 "ErrorCode,Mismatch in "
5450 "addba_reject/ampdu - "
5451 "not supported");
5452 return 0;
5453 }
5454 ampdu = 1;
5455 } else {
5456 /* disable AMPDU Aggregation */
5457 if (ampdu == 1) {
5458 send_resp(dut, conn, SIGMA_ERROR,
5459 "ErrorCode,Mismatch in "
5460 "addba_reject/ampdu - "
5461 "not supported");
5462 return 0;
5463 }
5464 ampdu = 0;
5465 }
5466 }
5467
5468 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005469 int ret;
5470
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005471 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5472 ampdu ? "Enabling" : "Disabling");
5473 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005474 if (wpa_command(intf, buf) < 0 &&
5475 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005476 send_resp(dut, conn, SIGMA_ERROR,
5477 "ErrorCode,set aggr failed");
5478 return 0;
5479 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005480
5481 if (ampdu == 0) {
5482 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005483 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005484 if (ret) {
5485 sigma_dut_print(dut, DUT_MSG_ERROR,
5486 "Failed to disable addba, ret:%d",
5487 ret);
5488 }
5489 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005490 }
5491
5492 val = get_param(cmd, "AMSDU");
5493 if (val) {
5494 switch (get_driver_type()) {
5495 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005496 case DRIVER_WCN:
5497 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005498 break;
5499 default:
5500 if (strcmp(val, "1") == 0 ||
5501 strcasecmp(val, "Enable") == 0) {
5502 /* Enable AMSDU Aggregation */
5503 send_resp(dut, conn, SIGMA_ERROR,
5504 "ErrorCode,AMSDU aggregation not supported");
5505 return 0;
5506 }
5507 break;
5508 }
5509 }
5510
5511 val = get_param(cmd, "STBC_RX");
5512 if (val) {
5513 switch (get_driver_type()) {
5514 case DRIVER_ATHEROS:
5515 ath_sta_set_stbc(dut, intf, val);
5516 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305517 case DRIVER_WCN:
5518 wcn_sta_set_stbc(dut, intf, val);
5519 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005520 default:
5521 send_resp(dut, conn, SIGMA_ERROR,
5522 "ErrorCode,STBC_RX not supported");
5523 return 0;
5524 }
5525 }
5526
5527 val = get_param(cmd, "WIDTH");
5528 if (val) {
5529 switch (get_driver_type()) {
5530 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005531 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005532 send_resp(dut, conn, SIGMA_ERROR,
5533 "ErrorCode,Failed to set WIDTH");
5534 return 0;
5535 }
5536 break;
5537 case DRIVER_ATHEROS:
5538 if (ath_set_width(dut, conn, intf, val) < 0)
5539 return 0;
5540 break;
5541 default:
5542 sigma_dut_print(dut, DUT_MSG_ERROR,
5543 "Setting WIDTH not supported");
5544 break;
5545 }
5546 }
5547
5548 val = get_param(cmd, "SMPS");
5549 if (val) {
5550 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5551 send_resp(dut, conn, SIGMA_ERROR,
5552 "ErrorCode,SMPS not supported");
5553 return 0;
5554 }
5555
5556 val = get_param(cmd, "TXSP_STREAM");
5557 if (val) {
5558 switch (get_driver_type()) {
5559 case DRIVER_WCN:
5560 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5561 send_resp(dut, conn, SIGMA_ERROR,
5562 "ErrorCode,Failed to set TXSP_STREAM");
5563 return 0;
5564 }
5565 break;
5566 case DRIVER_ATHEROS:
5567 ath_sta_set_txsp_stream(dut, intf, val);
5568 break;
5569 default:
5570 sigma_dut_print(dut, DUT_MSG_ERROR,
5571 "Setting TXSP_STREAM not supported");
5572 break;
5573 }
5574 }
5575
5576 val = get_param(cmd, "RXSP_STREAM");
5577 if (val) {
5578 switch (get_driver_type()) {
5579 case DRIVER_WCN:
5580 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5581 send_resp(dut, conn, SIGMA_ERROR,
5582 "ErrorCode,Failed to set RXSP_STREAM");
5583 return 0;
5584 }
5585 break;
5586 case DRIVER_ATHEROS:
5587 ath_sta_set_rxsp_stream(dut, intf, val);
5588 break;
5589 default:
5590 sigma_dut_print(dut, DUT_MSG_ERROR,
5591 "Setting RXSP_STREAM not supported");
5592 break;
5593 }
5594 }
5595
5596 val = get_param(cmd, "DYN_BW_SGNL");
5597 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005598 switch (get_driver_type()) {
5599 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005600 if (strcasecmp(val, "enable") == 0) {
5601 snprintf(buf, sizeof(buf),
5602 "iwpriv %s cwmenable 1", intf);
5603 if (system(buf) != 0) {
5604 sigma_dut_print(dut, DUT_MSG_ERROR,
5605 "iwpriv cwmenable 1 failed");
5606 return 0;
5607 }
5608 } else if (strcasecmp(val, "disable") == 0) {
5609 snprintf(buf, sizeof(buf),
5610 "iwpriv %s cwmenable 0", intf);
5611 if (system(buf) != 0) {
5612 sigma_dut_print(dut, DUT_MSG_ERROR,
5613 "iwpriv cwmenable 0 failed");
5614 return 0;
5615 }
5616 } else {
5617 sigma_dut_print(dut, DUT_MSG_ERROR,
5618 "Unsupported DYN_BW_SGL");
5619 }
5620
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005621 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5622 if (system(buf) != 0) {
5623 sigma_dut_print(dut, DUT_MSG_ERROR,
5624 "Failed to set cts_cbw in DYN_BW_SGNL");
5625 return 0;
5626 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005627 break;
5628 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005629 novap_reset(dut, intf, 1);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005630 ath_config_dyn_bw_sig(dut, intf, val);
5631 break;
5632 default:
5633 sigma_dut_print(dut, DUT_MSG_ERROR,
5634 "Failed to set DYN_BW_SGNL");
5635 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005636 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005637 }
5638
5639 val = get_param(cmd, "RTS_FORCE");
5640 if (val) {
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07005641 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005642 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305643 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005644 sigma_dut_print(dut, DUT_MSG_ERROR,
5645 "Failed to set RTS_FORCE 64");
5646 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005647 res = snprintf(buf, sizeof(buf),
5648 "wifitool %s beeliner_fw_test 100 1",
5649 intf);
5650 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005651 sigma_dut_print(dut, DUT_MSG_ERROR,
5652 "wifitool beeliner_fw_test 100 1 failed");
5653 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005654 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305655 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005656 sigma_dut_print(dut, DUT_MSG_ERROR,
5657 "Failed to set RTS_FORCE 2347");
5658 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005659 } else {
5660 send_resp(dut, conn, SIGMA_ERROR,
5661 "ErrorCode,RTS_FORCE value not supported");
5662 return 0;
5663 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005664 }
5665
5666 val = get_param(cmd, "CTS_WIDTH");
5667 if (val) {
5668 switch (get_driver_type()) {
5669 case DRIVER_WCN:
5670 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5671 send_resp(dut, conn, SIGMA_ERROR,
5672 "ErrorCode,Failed to set CTS_WIDTH");
5673 return 0;
5674 }
5675 break;
5676 case DRIVER_ATHEROS:
5677 ath_set_cts_width(dut, intf, val);
5678 break;
5679 default:
5680 sigma_dut_print(dut, DUT_MSG_ERROR,
5681 "Setting CTS_WIDTH not supported");
5682 break;
5683 }
5684 }
5685
5686 val = get_param(cmd, "BW_SGNL");
5687 if (val) {
5688 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005689 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005690 } else if (strcasecmp(val, "Disable") == 0) {
5691 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005692 } else {
5693 send_resp(dut, conn, SIGMA_ERROR,
5694 "ErrorCode,BW_SGNL value not supported");
5695 return 0;
5696 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005697 }
5698
5699 val = get_param(cmd, "Band");
5700 if (val) {
5701 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5702 /* STA supports all bands by default */
5703 } else {
5704 send_resp(dut, conn, SIGMA_ERROR,
5705 "ErrorCode,Unsupported Band");
5706 return 0;
5707 }
5708 }
5709
5710 val = get_param(cmd, "zero_crc");
5711 if (val) {
5712 switch (get_driver_type()) {
5713 case DRIVER_ATHEROS:
5714 ath_set_zero_crc(dut, val);
5715 break;
5716 default:
5717 break;
5718 }
5719 }
5720
5721 return 1;
5722}
5723
5724
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005725static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5726{
5727 switch (get_driver_type()) {
5728#ifdef __linux__
5729 case DRIVER_WIL6210:
5730 return wil6210_set_force_mcs(dut, force, mcs);
5731#endif /* __linux__ */
5732 default:
5733 sigma_dut_print(dut, DUT_MSG_ERROR,
5734 "Unsupported sta_set_force_mcs with the current driver");
5735 return -1;
5736 }
5737}
5738
5739
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005740static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5741{
5742 switch (get_driver_type()) {
5743#ifdef __linux__
5744 case DRIVER_WIL6210:
5745 return wil6210_force_rsn_ie(dut, state);
5746#endif /* __linux__ */
5747 default:
5748 sigma_dut_print(dut, DUT_MSG_ERROR,
5749 "Unsupported sta_60g_force_rsn_ie with the current driver");
5750 return -1;
5751 }
5752}
5753
5754
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005755static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5756 struct sigma_cmd *cmd)
5757{
5758 const char *val;
5759 char buf[100];
5760
5761 val = get_param(cmd, "MSDUSize");
5762 if (val) {
5763 int mtu;
5764
5765 dut->amsdu_size = atoi(val);
5766 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5767 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5768 sigma_dut_print(dut, DUT_MSG_ERROR,
5769 "MSDUSize %d is above max %d or below min %d",
5770 dut->amsdu_size,
5771 IEEE80211_MAX_DATA_LEN_DMG,
5772 IEEE80211_SNAP_LEN_DMG);
5773 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005774 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005775 }
5776
5777 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5778 sigma_dut_print(dut, DUT_MSG_DEBUG,
5779 "Setting amsdu_size to %d", mtu);
5780 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
5781 get_station_ifname(), mtu);
5782
5783 if (system(buf) != 0) {
5784 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5785 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005786 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005787 }
5788 }
5789
5790 val = get_param(cmd, "BAckRcvBuf");
5791 if (val) {
5792 dut->back_rcv_buf = atoi(val);
5793 if (dut->back_rcv_buf == 0) {
5794 sigma_dut_print(dut, DUT_MSG_ERROR,
5795 "Failed to convert %s or value is 0",
5796 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005797 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005798 }
5799
5800 sigma_dut_print(dut, DUT_MSG_DEBUG,
5801 "Setting BAckRcvBuf to %s", val);
5802 }
5803
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005804 val = get_param(cmd, "MCS_FixedRate");
5805 if (val) {
5806 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5807 sigma_dut_print(dut, DUT_MSG_ERROR,
5808 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005809 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005810 }
5811 }
5812
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005813 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005814}
5815
5816
5817static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5818 struct sigma_cmd *cmd)
5819{
5820 int net_id;
5821 char *ifname;
5822 const char *val;
5823 char buf[100];
5824
5825 dut->mode = SIGMA_MODE_STATION;
5826 ifname = get_main_ifname();
5827 if (wpa_command(ifname, "PING") != 0) {
5828 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005829 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005830 }
5831
5832 wpa_command(ifname, "FLUSH");
5833 net_id = add_network_common(dut, conn, ifname, cmd);
5834 if (net_id < 0) {
5835 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5836 return net_id;
5837 }
5838
5839 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5840 if (set_network(ifname, net_id, "mode", "2") < 0) {
5841 sigma_dut_print(dut, DUT_MSG_ERROR,
5842 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005843 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005844 }
5845
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005846 if (set_network(ifname, net_id, "pbss", "1") < 0)
5847 return -2;
5848
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005849 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005850 "Supplicant set network with mode 2. network_id %d",
5851 net_id);
5852
5853 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5854 sigma_dut_print(dut, DUT_MSG_INFO,
5855 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005856 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005857 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005858
5859 val = get_param(cmd, "Security");
5860 if (val && strcasecmp(val, "OPEN") == 0) {
5861 dut->ap_key_mgmt = AP_OPEN;
5862 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5863 sigma_dut_print(dut, DUT_MSG_ERROR,
5864 "Failed to set supplicant to %s security",
5865 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005866 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005867 }
5868 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5869 dut->ap_key_mgmt = AP_WPA2_PSK;
5870 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5871 sigma_dut_print(dut, DUT_MSG_ERROR,
5872 "Failed to set supplicant to %s security",
5873 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005874 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005875 }
5876
5877 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5878 sigma_dut_print(dut, DUT_MSG_ERROR,
5879 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005880 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005881 }
5882 } else if (val) {
5883 sigma_dut_print(dut, DUT_MSG_ERROR,
5884 "Requested Security %s is not supported on 60GHz",
5885 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005886 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005887 }
5888
5889 val = get_param(cmd, "Encrypt");
5890 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5891 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5892 sigma_dut_print(dut, DUT_MSG_ERROR,
5893 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005894 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005895 }
5896 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5897 sigma_dut_print(dut, DUT_MSG_ERROR,
5898 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005899 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005900 }
5901 } else if (val) {
5902 sigma_dut_print(dut, DUT_MSG_ERROR,
5903 "Requested Encrypt %s is not supported on 60 GHz",
5904 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005905 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005906 }
5907
5908 val = get_param(cmd, "PSK");
5909 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5910 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5911 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005912 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005913 }
5914
5915 /* Convert 60G channel to freq */
5916 switch (dut->ap_channel) {
5917 case 1:
5918 val = "58320";
5919 break;
5920 case 2:
5921 val = "60480";
5922 break;
5923 case 3:
5924 val = "62640";
5925 break;
5926 default:
5927 sigma_dut_print(dut, DUT_MSG_ERROR,
5928 "Failed to configure channel %d. Not supported",
5929 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005930 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005931 }
5932
5933 if (set_network(ifname, net_id, "frequency", val) < 0) {
5934 sigma_dut_print(dut, DUT_MSG_ERROR,
5935 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005936 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005937 }
5938
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005939 if (dut->eap_fragment) {
5940 sigma_dut_print(dut, DUT_MSG_DEBUG,
5941 "Set EAP fragment size to 128 bytes.");
5942 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
5943 return ERROR_SEND_STATUS;
5944 }
5945
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005946 sigma_dut_print(dut, DUT_MSG_DEBUG,
5947 "Supplicant set network with frequency");
5948
5949 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5950 if (wpa_command(ifname, buf) < 0) {
5951 sigma_dut_print(dut, DUT_MSG_INFO,
5952 "Failed to select network id %d on %s",
5953 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005954 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005955 }
5956
5957 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5958
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005959 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005960}
5961
5962
Lior David67543f52017-01-03 19:04:22 +02005963static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5964{
5965 char buf[128], fname[128];
5966 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005967 int res;
Lior David67543f52017-01-03 19:04:22 +02005968
5969 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5970 sigma_dut_print(dut, DUT_MSG_ERROR,
5971 "failed to get wil6210 debugfs dir");
5972 return -1;
5973 }
5974
Jouni Malinen3aa72862019-05-29 23:14:51 +03005975 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5976 if (res < 0 || res >= sizeof(fname))
5977 return -1;
Lior David67543f52017-01-03 19:04:22 +02005978 f = fopen(fname, "w");
5979 if (!f) {
5980 sigma_dut_print(dut, DUT_MSG_ERROR,
5981 "failed to open: %s", fname);
5982 return -1;
5983 }
5984
5985 fprintf(f, "%d\n", abft_len);
5986 fclose(f);
5987
5988 return 0;
5989}
5990
5991
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02005992int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5993 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02005994{
5995 switch (get_driver_type()) {
5996 case DRIVER_WIL6210:
5997 return wil6210_set_abft_len(dut, abft_len);
5998 default:
5999 sigma_dut_print(dut, DUT_MSG_ERROR,
6000 "set abft_len not supported");
6001 return -1;
6002 }
6003}
6004
6005
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006006static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
6007 struct sigma_cmd *cmd)
6008{
6009 const char *val;
Lior David67543f52017-01-03 19:04:22 +02006010 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006011
6012 if (dut->dev_role != DEVROLE_PCP) {
6013 send_resp(dut, conn, SIGMA_INVALID,
6014 "ErrorCode,Invalid DevRole");
6015 return 0;
6016 }
6017
6018 val = get_param(cmd, "SSID");
6019 if (val) {
6020 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
6021 send_resp(dut, conn, SIGMA_INVALID,
6022 "ErrorCode,Invalid SSID");
6023 return -1;
6024 }
6025
Peng Xub8fc5cc2017-05-10 17:27:28 -07006026 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006027 }
6028
6029 val = get_param(cmd, "CHANNEL");
6030 if (val) {
6031 const char *pos;
6032
6033 dut->ap_channel = atoi(val);
6034 pos = strchr(val, ';');
6035 if (pos) {
6036 pos++;
6037 dut->ap_channel_1 = atoi(pos);
6038 }
6039 }
6040
6041 switch (dut->ap_channel) {
6042 case 1:
6043 case 2:
6044 case 3:
6045 break;
6046 default:
6047 sigma_dut_print(dut, DUT_MSG_ERROR,
6048 "Channel %d is not supported", dut->ap_channel);
6049 send_resp(dut, conn, SIGMA_ERROR,
6050 "Requested channel is not supported");
6051 return -1;
6052 }
6053
6054 val = get_param(cmd, "BCNINT");
6055 if (val)
6056 dut->ap_bcnint = atoi(val);
6057
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006058 val = get_param(cmd, "AllocType");
6059 if (val) {
6060 send_resp(dut, conn, SIGMA_ERROR,
6061 "ErrorCode,AllocType is not supported yet");
6062 return -1;
6063 }
6064
6065 val = get_param(cmd, "PercentBI");
6066 if (val) {
6067 send_resp(dut, conn, SIGMA_ERROR,
6068 "ErrorCode,PercentBI is not supported yet");
6069 return -1;
6070 }
6071
6072 val = get_param(cmd, "CBAPOnly");
6073 if (val) {
6074 send_resp(dut, conn, SIGMA_ERROR,
6075 "ErrorCode,CBAPOnly is not supported yet");
6076 return -1;
6077 }
6078
6079 val = get_param(cmd, "AMPDU");
6080 if (val) {
6081 if (strcasecmp(val, "Enable") == 0)
6082 dut->ap_ampdu = 1;
6083 else if (strcasecmp(val, "Disable") == 0)
6084 dut->ap_ampdu = 2;
6085 else {
6086 send_resp(dut, conn, SIGMA_ERROR,
6087 "ErrorCode,AMPDU value is not Enable nor Disabled");
6088 return -1;
6089 }
6090 }
6091
6092 val = get_param(cmd, "AMSDU");
6093 if (val) {
6094 if (strcasecmp(val, "Enable") == 0)
6095 dut->ap_amsdu = 1;
6096 else if (strcasecmp(val, "Disable") == 0)
6097 dut->ap_amsdu = 2;
6098 }
6099
6100 val = get_param(cmd, "NumMSDU");
6101 if (val) {
6102 send_resp(dut, conn, SIGMA_ERROR,
6103 "ErrorCode, NumMSDU is not supported yet");
6104 return -1;
6105 }
6106
6107 val = get_param(cmd, "ABFTLRang");
6108 if (val) {
6109 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006110 "ABFTLRang parameter %s", val);
6111 if (strcmp(val, "Gt1") == 0)
6112 abft_len = 2; /* 2 slots in this case */
6113 }
6114
6115 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6116 send_resp(dut, conn, SIGMA_ERROR,
6117 "ErrorCode, Can't set ABFT length");
6118 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006119 }
6120
6121 if (sta_pcp_start(dut, conn, cmd) < 0) {
6122 send_resp(dut, conn, SIGMA_ERROR,
6123 "ErrorCode, Can't start PCP role");
6124 return -1;
6125 }
6126
6127 return sta_set_60g_common(dut, conn, cmd);
6128}
6129
6130
6131static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6132 struct sigma_cmd *cmd)
6133{
6134 const char *val = get_param(cmd, "DiscoveryMode");
6135
6136 if (dut->dev_role != DEVROLE_STA) {
6137 send_resp(dut, conn, SIGMA_INVALID,
6138 "ErrorCode,Invalid DevRole");
6139 return 0;
6140 }
6141
6142 if (val) {
6143 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6144 /* Ignore Discovery mode till Driver expose API. */
6145#if 0
6146 if (strcasecmp(val, "1") == 0) {
6147 send_resp(dut, conn, SIGMA_INVALID,
6148 "ErrorCode,DiscoveryMode 1 not supported");
6149 return 0;
6150 }
6151
6152 if (strcasecmp(val, "0") == 0) {
6153 /* OK */
6154 } else {
6155 send_resp(dut, conn, SIGMA_INVALID,
6156 "ErrorCode,DiscoveryMode not supported");
6157 return 0;
6158 }
6159#endif
6160 }
6161
6162 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006163 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006164 return sta_set_60g_common(dut, conn, cmd);
6165}
6166
6167
Jouni Malinenf7222712019-06-13 01:50:21 +03006168static enum sigma_cmd_result cmd_sta_disconnect(struct sigma_dut *dut,
6169 struct sigma_conn *conn,
6170 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006171{
6172 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006173 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306174
Jouni Malinened77e672018-01-10 16:45:13 +02006175 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006176 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006177 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306178 wpa_command(intf, "DISCONNECT");
6179 return 1;
6180 }
6181
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006182 disconnect_station(dut);
6183 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6184 * due to cached results. */
6185 wpa_command(intf, "SET ignore_old_scan_res 1");
6186 wpa_command(intf, "BSS_FLUSH");
6187 return 1;
6188}
6189
6190
Jouni Malinenf7222712019-06-13 01:50:21 +03006191static enum sigma_cmd_result cmd_sta_reassoc(struct sigma_dut *dut,
6192 struct sigma_conn *conn,
6193 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006194{
6195 const char *intf = get_param(cmd, "Interface");
6196 const char *bssid = get_param(cmd, "bssid");
6197 const char *val = get_param(cmd, "CHANNEL");
6198 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306199 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306200 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006201 int res;
6202 int chan = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006203 enum sigma_cmd_result status = STATUS_SENT;
Sunil Duttd30ce092018-01-11 23:56:29 +05306204 int fastreassoc = 1;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006205 int ft_ds = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006206
6207 if (bssid == NULL) {
6208 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6209 "argument");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006210 return STATUS_SENT_ERROR;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006211 }
6212
6213 if (val)
6214 chan = atoi(val);
6215
6216 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6217 /* The current network may be from sta_associate or
6218 * sta_hs2_associate
6219 */
6220 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6221 0 ||
6222 set_network(intf, 0, "bssid", bssid) < 0)
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006223 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006224 }
6225
6226 ctrl = open_wpa_mon(intf);
6227 if (ctrl == NULL) {
6228 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6229 "wpa_supplicant monitor connection");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006230 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006231 }
6232
Sunil Duttd30ce092018-01-11 23:56:29 +05306233 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6234 sizeof(result)) < 0 ||
6235 strncmp(result, "COMPLETED", 9) != 0) {
6236 sigma_dut_print(dut, DUT_MSG_DEBUG,
6237 "sta_reassoc: Not connected");
6238 fastreassoc = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006239 } else if (dut->sta_ft_ds) {
6240 sigma_dut_print(dut, DUT_MSG_DEBUG,
6241 "sta_reassoc: Use FT-over-DS");
6242 ft_ds = 1;
Sunil Duttd30ce092018-01-11 23:56:29 +05306243 }
6244
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306245 if (dut->rsne_override) {
6246#ifdef NL80211_SUPPORT
6247 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
6248 sta_config_rsnie(dut, 1);
6249 dut->config_rsnie = 1;
6250 }
6251#endif /* NL80211_SUPPORT */
6252 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6253 dut->rsne_override);
6254 if (wpa_command(intf, buf) < 0) {
6255 send_resp(dut, conn, SIGMA_ERROR,
6256 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6257 return 0;
6258 }
6259 }
6260
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006261 if (ft_ds) {
6262 if (chan) {
6263 unsigned int freq;
6264
6265 freq = channel_to_freq(dut, chan);
6266 if (!freq) {
6267 sigma_dut_print(dut, DUT_MSG_ERROR,
6268 "Invalid channel number provided: %d",
6269 chan);
6270 send_resp(dut, conn, SIGMA_INVALID,
6271 "ErrorCode,Invalid channel number");
6272 goto close_mon_conn;
6273 }
6274 res = snprintf(buf, sizeof(buf),
6275 "SCAN TYPE=ONLY freq=%d", freq);
6276 } else {
6277 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6278 }
6279 if (res < 0 || res >= (int) sizeof(buf)) {
6280 send_resp(dut, conn, SIGMA_ERROR,
6281 "ErrorCode,snprintf failed");
6282 goto close_mon_conn;
6283 }
6284 if (wpa_command(intf, buf) < 0) {
6285 sigma_dut_print(dut, DUT_MSG_INFO,
6286 "Failed to start scan");
6287 send_resp(dut, conn, SIGMA_ERROR,
6288 "ErrorCode,scan failed");
6289 goto close_mon_conn;
6290 }
6291
6292 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6293 buf, sizeof(buf));
6294 if (res < 0) {
6295 sigma_dut_print(dut, DUT_MSG_INFO,
6296 "Scan did not complete");
6297 send_resp(dut, conn, SIGMA_ERROR,
6298 "ErrorCode,scan did not complete");
6299 goto close_mon_conn;
6300 }
6301
6302 res = snprintf(buf, sizeof(buf), "FT_DS %s", bssid);
6303 if (res > 0 && res < (int) sizeof(buf))
6304 res = wpa_command(intf, buf);
6305
6306 if (res < 0 || res >= (int) sizeof(buf)) {
6307 send_resp(dut, conn, SIGMA_ERROR,
6308 "errorCode,FT_DS command failed");
6309 status = STATUS_SENT_ERROR;
6310 goto close_mon_conn;
6311 }
6312 } else if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006313#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306314 if (chan) {
6315 unsigned int freq;
6316
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006317 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306318 if (!freq) {
6319 sigma_dut_print(dut, DUT_MSG_ERROR,
6320 "Invalid channel number provided: %d",
6321 chan);
6322 send_resp(dut, conn, SIGMA_INVALID,
6323 "ErrorCode,Invalid channel number");
6324 goto close_mon_conn;
6325 }
6326 res = snprintf(buf, sizeof(buf),
6327 "SCAN TYPE=ONLY freq=%d", freq);
6328 } else {
6329 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6330 }
6331 if (res < 0 || res >= (int) sizeof(buf)) {
6332 send_resp(dut, conn, SIGMA_ERROR,
6333 "ErrorCode,snprintf failed");
6334 goto close_mon_conn;
6335 }
6336 if (wpa_command(intf, buf) < 0) {
6337 sigma_dut_print(dut, DUT_MSG_INFO,
6338 "Failed to start scan");
6339 send_resp(dut, conn, SIGMA_ERROR,
6340 "ErrorCode,scan failed");
6341 goto close_mon_conn;
6342 }
6343
6344 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6345 buf, sizeof(buf));
6346 if (res < 0) {
6347 sigma_dut_print(dut, DUT_MSG_INFO,
6348 "Scan did not complete");
6349 send_resp(dut, conn, SIGMA_ERROR,
6350 "ErrorCode,scan did not complete");
6351 goto close_mon_conn;
6352 }
6353
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006354 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6355 < 0) {
6356 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6357 "bssid to any during FASTREASSOC");
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006358 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306359 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006360 }
6361 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6362 bssid, chan);
6363 if (res > 0 && res < (int) sizeof(buf))
6364 res = wpa_command(intf, buf);
6365
6366 if (res < 0 || res >= (int) sizeof(buf)) {
6367 send_resp(dut, conn, SIGMA_ERROR,
6368 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306369 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006370 }
6371#else /* ANDROID */
6372 sigma_dut_print(dut, DUT_MSG_DEBUG,
6373 "Reassoc using iwpriv - skip chan=%d info",
6374 chan);
6375 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
6376 if (system(buf) != 0) {
6377 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006378 status = ERROR_SEND_STATUS;
Ashwini Patil467efef2017-05-25 12:18:27 +05306379 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006380 }
6381#endif /* ANDROID */
6382 sigma_dut_print(dut, DUT_MSG_INFO,
6383 "sta_reassoc: Run %s successful", buf);
6384 } else if (wpa_command(intf, "REASSOCIATE")) {
6385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6386 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306387 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006388 }
6389
6390 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6391 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306392 if (res < 0) {
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006393 send_resp(dut, conn, SIGMA_ERROR,
6394 "errorCode,Connection did not complete");
6395 status = STATUS_SENT_ERROR;
Ashwini Patil467efef2017-05-25 12:18:27 +05306396 goto close_mon_conn;
6397 }
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03006398 status = SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006399
Ashwini Patil467efef2017-05-25 12:18:27 +05306400close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006401 wpa_ctrl_detach(ctrl);
6402 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306403 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006404}
6405
6406
6407static void hs2_clear_credentials(const char *intf)
6408{
6409 wpa_command(intf, "REMOVE_CRED all");
6410}
6411
6412
Lior Davidcc88b562017-01-03 18:52:09 +02006413#ifdef __linux__
6414static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6415 unsigned int *aid)
6416{
Lior David0fe101e2017-03-09 16:09:50 +02006417 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006418
Lior David0fe101e2017-03-09 16:09:50 +02006419 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006420}
6421#endif /* __linux__ */
6422
6423
6424static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6425 unsigned int *aid)
6426{
6427 switch (get_driver_type()) {
6428#ifdef __linux__
6429 case DRIVER_WIL6210:
6430 return wil6210_get_aid(dut, bssid, aid);
6431#endif /* __linux__ */
6432 default:
6433 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6434 return -1;
6435 }
6436}
6437
6438
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006439static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6440 struct sigma_cmd *cmd)
6441{
6442 char buf[MAX_CMD_LEN];
6443 char bss_list[MAX_CMD_LEN];
6444 const char *parameter = get_param(cmd, "Parameter");
6445
6446 if (parameter == NULL)
6447 return -1;
6448
Lior Davidcc88b562017-01-03 18:52:09 +02006449 if (strcasecmp(parameter, "AID") == 0) {
6450 unsigned int aid = 0;
6451 char bssid[20];
6452
6453 if (get_wpa_status(get_station_ifname(), "bssid",
6454 bssid, sizeof(bssid)) < 0) {
6455 sigma_dut_print(dut, DUT_MSG_ERROR,
6456 "could not get bssid");
6457 return -2;
6458 }
6459
6460 if (sta_get_aid_60g(dut, bssid, &aid))
6461 return -2;
6462
6463 snprintf(buf, sizeof(buf), "aid,%d", aid);
6464 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6465 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6466 return 0;
6467 }
6468
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006469 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6470 char *bss_line;
6471 char *bss_id = NULL;
6472 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306473 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006474
6475 if (ifname == NULL) {
6476 sigma_dut_print(dut, DUT_MSG_INFO,
6477 "For get DiscoveredDevList need Interface name.");
6478 return -1;
6479 }
6480
6481 /*
6482 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6483 * of BSSIDs in "bssid=<BSSID>\n"
6484 */
6485 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6486 bss_list,
6487 sizeof(bss_list)) < 0) {
6488 sigma_dut_print(dut, DUT_MSG_ERROR,
6489 "Failed to get bss list");
6490 return -1;
6491 }
6492
6493 sigma_dut_print(dut, DUT_MSG_DEBUG,
6494 "bss list for ifname:%s is:%s",
6495 ifname, bss_list);
6496
6497 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306498 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006499 while (bss_line) {
6500 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6501 bss_id) {
6502 int len;
6503
6504 len = snprintf(buf + strlen(buf),
6505 sizeof(buf) - strlen(buf),
6506 ",%s", bss_id);
6507 free(bss_id);
6508 bss_id = NULL;
6509 if (len < 0) {
6510 sigma_dut_print(dut,
6511 DUT_MSG_ERROR,
6512 "Failed to read BSSID");
6513 send_resp(dut, conn, SIGMA_ERROR,
6514 "ErrorCode,Failed to read BSS ID");
6515 return 0;
6516 }
6517
6518 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6519 sigma_dut_print(dut,
6520 DUT_MSG_ERROR,
6521 "Response buf too small for list");
6522 send_resp(dut, conn,
6523 SIGMA_ERROR,
6524 "ErrorCode,Response buf too small for list");
6525 return 0;
6526 }
6527 }
6528
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306529 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006530 }
6531
6532 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6533 buf);
6534 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6535 return 0;
6536 }
6537
6538 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6539 return 0;
6540}
6541
6542
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006543static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6544 struct sigma_cmd *cmd)
6545{
6546 char buf[MAX_CMD_LEN];
6547 const char *parameter = get_param(cmd, "Parameter");
6548
6549 if (!parameter)
6550 return -1;
6551
6552 if (strcasecmp(parameter, "RSSI") == 0) {
6553 char rssi[10];
6554
6555 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
6556 rssi, sizeof(rssi)) < 0) {
6557 sigma_dut_print(dut, DUT_MSG_ERROR,
6558 "Could not get RSSI");
6559 return -2;
6560 }
6561
6562 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6563 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6564 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6565 return 0;
6566 }
6567
6568 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6569 return 0;
6570}
6571
6572
Jouni Malinenf7222712019-06-13 01:50:21 +03006573static enum sigma_cmd_result cmd_sta_get_parameter(struct sigma_dut *dut,
6574 struct sigma_conn *conn,
6575 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006576{
6577 const char *program = get_param(cmd, "Program");
6578
6579 if (program == NULL)
6580 return -1;
6581
6582 if (strcasecmp(program, "P2PNFC") == 0)
6583 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6584
6585 if (strcasecmp(program, "60ghz") == 0)
6586 return sta_get_parameter_60g(dut, conn, cmd);
6587
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006588 if (strcasecmp(program, "he") == 0)
6589 return sta_get_parameter_he(dut, conn, cmd);
6590
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006591#ifdef ANDROID_NAN
6592 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006593 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006594#endif /* ANDROID_NAN */
6595
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006596#ifdef MIRACAST
6597 if (strcasecmp(program, "WFD") == 0 ||
6598 strcasecmp(program, "DisplayR2") == 0)
6599 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6600#endif /* MIRACAST */
6601
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006602 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6603 return 0;
6604}
6605
6606
6607static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6608 const char *type)
6609{
6610 char buf[100];
6611
6612 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006613 run_iwpriv(dut, intf, "chwidth 2");
6614 run_iwpriv(dut, intf, "mode 11ACVHT80");
6615 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006616 }
6617
6618 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006619 run_iwpriv(dut, intf, "chwidth 0");
6620 run_iwpriv(dut, intf, "mode 11naht40");
6621 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006622 }
6623
6624 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006625 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006626
6627 /* Reset CTS width */
6628 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6629 intf);
6630 if (system(buf) != 0) {
6631 sigma_dut_print(dut, DUT_MSG_ERROR,
6632 "wifitool %s beeliner_fw_test 54 0 failed",
6633 intf);
6634 }
6635
6636 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006637 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006638
6639 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6640 if (system(buf) != 0) {
6641 sigma_dut_print(dut, DUT_MSG_ERROR,
6642 "iwpriv rts failed");
6643 }
6644 }
6645
6646 if (type && strcasecmp(type, "Testbed") == 0) {
6647 dut->testbed_flag_txsp = 1;
6648 dut->testbed_flag_rxsp = 1;
6649 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006650 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006651
6652 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006653 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006654
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006655 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006656
6657 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006658 run_iwpriv(dut, intf, "tx_stbc 0");
6659 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006660
6661 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006662 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006663 }
6664
6665 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006666 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006667 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006668
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006669 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006670 }
6671}
6672
6673
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006674#ifdef NL80211_SUPPORT
6675static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6676 enum he_mcs_config mcs)
6677{
6678 struct nl_msg *msg;
6679 int ret = 0;
6680 struct nlattr *params;
6681 int ifindex;
6682
6683 ifindex = if_nametoindex(intf);
6684 if (ifindex == 0) {
6685 sigma_dut_print(dut, DUT_MSG_ERROR,
6686 "%s: Index for interface %s failed",
6687 __func__, intf);
6688 return -1;
6689 }
6690
6691 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6692 NL80211_CMD_VENDOR)) ||
6693 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6694 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6695 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6696 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6697 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6698 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6699 mcs)) {
6700 sigma_dut_print(dut, DUT_MSG_ERROR,
6701 "%s: err in adding vendor_cmd and vendor_data",
6702 __func__);
6703 nlmsg_free(msg);
6704 return -1;
6705 }
6706 nla_nest_end(msg, params);
6707
6708 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6709 if (ret) {
6710 sigma_dut_print(dut, DUT_MSG_ERROR,
6711 "%s: err in send_and_recv_msgs, ret=%d",
6712 __func__, ret);
6713 }
6714 return ret;
6715}
6716#endif /* NL80211_SUPPORT */
6717
6718
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006719static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6720 const char *intf, int enable)
6721{
6722#ifdef NL80211_SUPPORT
6723 struct nl_msg *msg;
6724 int ret = 0;
6725 struct nlattr *params;
6726 int ifindex;
6727
6728 ifindex = if_nametoindex(intf);
6729 if (ifindex == 0) {
6730 sigma_dut_print(dut, DUT_MSG_ERROR,
6731 "%s: Index for interface %s failed",
6732 __func__, intf);
6733 return -1;
6734 }
6735
6736 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6737 NL80211_CMD_VENDOR)) ||
6738 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6739 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6740 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6741 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6742 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6743 nla_put_u8(msg,
6744 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6745 enable)) {
6746 sigma_dut_print(dut, DUT_MSG_ERROR,
6747 "%s: err in adding vendor_cmd and vendor_data",
6748 __func__);
6749 nlmsg_free(msg);
6750 return -1;
6751 }
6752 nla_nest_end(msg, params);
6753
6754 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6755 if (ret) {
6756 sigma_dut_print(dut, DUT_MSG_ERROR,
6757 "%s: err in send_and_recv_msgs, ret=%d",
6758 __func__, ret);
6759 }
6760 return ret;
6761#else /* NL80211_SUPPORT */
6762 sigma_dut_print(dut, DUT_MSG_ERROR,
6763 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6764 return -1;
6765#endif /* NL80211_SUPPORT */
6766}
6767
6768
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006769static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6770 const char *intf, int enable)
6771{
6772#ifdef NL80211_SUPPORT
6773 struct nl_msg *msg;
6774 int ret = 0;
6775 struct nlattr *params;
6776 int ifindex;
6777
6778 ifindex = if_nametoindex(intf);
6779 if (ifindex == 0) {
6780 sigma_dut_print(dut, DUT_MSG_ERROR,
6781 "%s: Index for interface %s failed",
6782 __func__, intf);
6783 return -1;
6784 }
6785
6786 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6787 NL80211_CMD_VENDOR)) ||
6788 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6789 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6790 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6791 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6792 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6793 nla_put_u8(msg,
6794 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6795 enable)) {
6796 sigma_dut_print(dut, DUT_MSG_ERROR,
6797 "%s: err in adding vendor_cmd and vendor_data",
6798 __func__);
6799 nlmsg_free(msg);
6800 return -1;
6801 }
6802 nla_nest_end(msg, params);
6803
6804 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6805 if (ret) {
6806 sigma_dut_print(dut, DUT_MSG_ERROR,
6807 "%s: err in send_and_recv_msgs, ret=%d",
6808 __func__, ret);
6809 }
6810 return ret;
6811#else /* NL80211_SUPPORT */
6812 sigma_dut_print(dut, DUT_MSG_ERROR,
6813 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6814 return -1;
6815#endif /* NL80211_SUPPORT */
6816}
6817
6818
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006819#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006820
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006821static int sta_set_he_testbed_def(struct sigma_dut *dut,
6822 const char *intf, int cfg)
6823{
6824 struct nl_msg *msg;
6825 int ret = 0;
6826 struct nlattr *params;
6827 int ifindex;
6828
6829 ifindex = if_nametoindex(intf);
6830 if (ifindex == 0) {
6831 sigma_dut_print(dut, DUT_MSG_ERROR,
6832 "%s: Index for interface %s failed",
6833 __func__, intf);
6834 return -1;
6835 }
6836
6837 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6838 NL80211_CMD_VENDOR)) ||
6839 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6840 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6841 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6842 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6843 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6844 nla_put_u8(msg,
6845 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6846 cfg)) {
6847 sigma_dut_print(dut, DUT_MSG_ERROR,
6848 "%s: err in adding vendor_cmd and vendor_data",
6849 __func__);
6850 nlmsg_free(msg);
6851 return -1;
6852 }
6853 nla_nest_end(msg, params);
6854
6855 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6856 if (ret) {
6857 sigma_dut_print(dut, DUT_MSG_ERROR,
6858 "%s: err in send_and_recv_msgs, ret=%d",
6859 __func__, ret);
6860 }
6861 return ret;
6862}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006863
6864
6865static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
6866{
6867 struct nl_msg *msg;
6868 int ret = 0;
6869 struct nlattr *params;
6870 int ifindex;
6871
6872 ifindex = if_nametoindex(intf);
6873 if (ifindex == 0) {
6874 sigma_dut_print(dut, DUT_MSG_ERROR,
6875 "%s: Index for interface %s failed",
6876 __func__, intf);
6877 return -1;
6878 }
6879
6880 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6881 NL80211_CMD_VENDOR)) ||
6882 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6883 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6884 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6885 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6886 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6887 nla_put_u8(msg,
6888 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
6889 cfg)) {
6890 sigma_dut_print(dut, DUT_MSG_ERROR,
6891 "%s: err in adding vendor_cmd and vendor_data",
6892 __func__);
6893 nlmsg_free(msg);
6894 return -1;
6895 }
6896 nla_nest_end(msg, params);
6897
6898 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6899 if (ret) {
6900 sigma_dut_print(dut, DUT_MSG_ERROR,
6901 "%s: err in send_and_recv_msgs, ret=%d",
6902 __func__, ret);
6903 }
6904 return ret;
6905}
6906
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006907#endif /* NL80211_SUPPORT */
6908
6909
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006910static int sta_set_addba_buf_size(struct sigma_dut *dut,
6911 const char *intf, int bufsize)
6912{
6913#ifdef NL80211_SUPPORT
6914 struct nl_msg *msg;
6915 int ret = 0;
6916 struct nlattr *params;
6917 int ifindex;
6918
6919 ifindex = if_nametoindex(intf);
6920 if (ifindex == 0) {
6921 sigma_dut_print(dut, DUT_MSG_ERROR,
6922 "%s: Index for interface %s failed",
6923 __func__, intf);
6924 return -1;
6925 }
6926
6927 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6928 NL80211_CMD_VENDOR)) ||
6929 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6930 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6931 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6932 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6933 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006934 nla_put_u16(msg,
6935 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6936 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006937 sigma_dut_print(dut, DUT_MSG_ERROR,
6938 "%s: err in adding vendor_cmd and vendor_data",
6939 __func__);
6940 nlmsg_free(msg);
6941 return -1;
6942 }
6943 nla_nest_end(msg, params);
6944
6945 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6946 if (ret) {
6947 sigma_dut_print(dut, DUT_MSG_ERROR,
6948 "%s: err in send_and_recv_msgs, ret=%d",
6949 __func__, ret);
6950 }
6951 return ret;
6952#else /* NL80211_SUPPORT */
6953 sigma_dut_print(dut, DUT_MSG_ERROR,
6954 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6955 return -1;
6956#endif /* NL80211_SUPPORT */
6957}
6958
6959
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006960static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6961 int enable)
6962{
6963#ifdef NL80211_SUPPORT
6964 struct nl_msg *msg;
6965 int ret = 0;
6966 struct nlattr *params;
6967 int ifindex;
6968
6969 ifindex = if_nametoindex(intf);
6970 if (ifindex == 0) {
6971 sigma_dut_print(dut, DUT_MSG_ERROR,
6972 "%s: Index for interface %s failed",
6973 __func__, intf);
6974 return -1;
6975 }
6976
6977 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6978 NL80211_CMD_VENDOR)) ||
6979 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6980 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6981 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6982 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6983 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6984 nla_put_u8(msg,
6985 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
6986 enable)) {
6987 sigma_dut_print(dut, DUT_MSG_ERROR,
6988 "%s: err in adding vendor_cmd and vendor_data",
6989 __func__);
6990 nlmsg_free(msg);
6991 return -1;
6992 }
6993 nla_nest_end(msg, params);
6994
6995 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6996 if (ret) {
6997 sigma_dut_print(dut, DUT_MSG_ERROR,
6998 "%s: err in send_and_recv_msgs, ret=%d",
6999 __func__, ret);
7000 }
7001 return ret;
7002#else /* NL80211_SUPPORT */
7003 sigma_dut_print(dut, DUT_MSG_ERROR,
7004 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
7005 return -1;
7006#endif /* NL80211_SUPPORT */
7007}
7008
7009
Arif Hussain9765f7d2018-07-03 08:28:26 -07007010static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
7011 int val)
7012{
7013#ifdef NL80211_SUPPORT
7014 struct nl_msg *msg;
7015 int ret = 0;
7016 struct nlattr *params;
7017 int ifindex;
7018
7019 ifindex = if_nametoindex(intf);
7020 if (ifindex == 0) {
7021 sigma_dut_print(dut, DUT_MSG_ERROR,
7022 "%s: Index for interface %s failed, val:%d",
7023 __func__, intf, val);
7024 return -1;
7025 }
7026
7027 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7028 NL80211_CMD_VENDOR)) ||
7029 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7030 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7031 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7032 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7033 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7034 nla_put_u8(msg,
7035 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
7036 val)) {
7037 sigma_dut_print(dut, DUT_MSG_ERROR,
7038 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7039 __func__, val);
7040 nlmsg_free(msg);
7041 return -1;
7042 }
7043 nla_nest_end(msg, params);
7044
7045 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7046 if (ret) {
7047 sigma_dut_print(dut, DUT_MSG_ERROR,
7048 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7049 __func__, ret, val);
7050 }
7051 return ret;
7052#else /* NL80211_SUPPORT */
7053 sigma_dut_print(dut, DUT_MSG_ERROR,
7054 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
7055 return -1;
7056#endif /* NL80211_SUPPORT */
7057}
7058
7059
Arif Hussain68d23f52018-07-11 13:39:08 -07007060#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007061static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
7062 enum qca_wlan_he_mac_padding_dur val)
7063{
Arif Hussain68d23f52018-07-11 13:39:08 -07007064 struct nl_msg *msg;
7065 int ret = 0;
7066 struct nlattr *params;
7067 int ifindex;
7068
7069 ifindex = if_nametoindex(intf);
7070 if (ifindex == 0) {
7071 sigma_dut_print(dut, DUT_MSG_ERROR,
7072 "%s: Index for interface %s failed, val:%d",
7073 __func__, intf, val);
7074 return -1;
7075 }
7076
7077 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7078 NL80211_CMD_VENDOR)) ||
7079 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7080 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7081 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7082 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7083 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7084 nla_put_u8(msg,
7085 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
7086 val)) {
7087 sigma_dut_print(dut, DUT_MSG_ERROR,
7088 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7089 __func__, val);
7090 nlmsg_free(msg);
7091 return -1;
7092 }
7093 nla_nest_end(msg, params);
7094
7095 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7096 if (ret) {
7097 sigma_dut_print(dut, DUT_MSG_ERROR,
7098 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7099 __func__, ret, val);
7100 }
7101 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07007102}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007103#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007104
7105
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007106static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
7107 int val)
7108{
7109#ifdef NL80211_SUPPORT
7110 struct nl_msg *msg;
7111 int ret = 0;
7112 struct nlattr *params;
7113 int ifindex;
7114
7115 ifindex = if_nametoindex(intf);
7116 if (ifindex == 0) {
7117 sigma_dut_print(dut, DUT_MSG_ERROR,
7118 "%s: Index for interface %s failed, val:%d",
7119 __func__, intf, val);
7120 return -1;
7121 }
7122
7123 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7124 NL80211_CMD_VENDOR)) ||
7125 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7126 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7127 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7128 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7129 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7130 nla_put_u8(msg,
7131 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
7132 val)) {
7133 sigma_dut_print(dut, DUT_MSG_ERROR,
7134 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7135 __func__, val);
7136 nlmsg_free(msg);
7137 return -1;
7138 }
7139 nla_nest_end(msg, params);
7140
7141 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7142 if (ret) {
7143 sigma_dut_print(dut, DUT_MSG_ERROR,
7144 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7145 __func__, ret, val);
7146 }
7147 return ret;
7148#else /* NL80211_SUPPORT */
7149 sigma_dut_print(dut, DUT_MSG_ERROR,
7150 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
7151 return -1;
7152#endif /* NL80211_SUPPORT */
7153}
7154
7155
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007156#ifdef NL80211_SUPPORT
7157static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7158{
7159 struct nl_msg *msg;
7160 int ret = 0;
7161 struct nlattr *params;
7162 int ifindex;
7163
7164 ifindex = if_nametoindex(intf);
7165 if (ifindex == 0) {
7166 sigma_dut_print(dut, DUT_MSG_ERROR,
7167 "%s: Index for interface %s failed",
7168 __func__, intf);
7169 return -1;
7170 }
7171
7172 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7173 NL80211_CMD_VENDOR)) ||
7174 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7175 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7176 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7177 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7178 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7179 nla_put_flag(msg,
7180 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7181 sigma_dut_print(dut, DUT_MSG_ERROR,
7182 "%s: err in adding vendor_cmd and vendor_data",
7183 __func__);
7184 nlmsg_free(msg);
7185 return -1;
7186 }
7187 nla_nest_end(msg, params);
7188
7189 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7190 if (ret) {
7191 sigma_dut_print(dut, DUT_MSG_ERROR,
7192 "%s: err in send_and_recv_msgs, ret=%d",
7193 __func__, ret);
7194 }
7195 return ret;
7196}
7197#endif /* NL80211_SUPPORT */
7198
7199
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007200static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7201 int val)
7202{
7203#ifdef NL80211_SUPPORT
7204 struct nl_msg *msg;
7205 int ret = 0;
7206 struct nlattr *params;
7207 int ifindex;
7208
7209 ifindex = if_nametoindex(intf);
7210 if (ifindex == 0) {
7211 sigma_dut_print(dut, DUT_MSG_ERROR,
7212 "%s: Index for interface %s failed, val:%d",
7213 __func__, intf, val);
7214 return -1;
7215 }
7216
7217 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7218 NL80211_CMD_VENDOR)) ||
7219 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7220 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7221 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7222 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7223 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7224 nla_put_u8(msg,
7225 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7226 val)) {
7227 sigma_dut_print(dut, DUT_MSG_ERROR,
7228 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7229 __func__, val);
7230 nlmsg_free(msg);
7231 return -1;
7232 }
7233 nla_nest_end(msg, params);
7234
7235 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7236 if (ret) {
7237 sigma_dut_print(dut, DUT_MSG_ERROR,
7238 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7239 __func__, ret, val);
7240 }
7241 return ret;
7242#else /* NL80211_SUPPORT */
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7245 return -1;
7246#endif /* NL80211_SUPPORT */
7247}
7248
7249
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007250static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7251 int val)
7252{
7253#ifdef NL80211_SUPPORT
7254 struct nl_msg *msg;
7255 int ret = 0;
7256 struct nlattr *params;
7257 int ifindex;
7258
7259 ifindex = if_nametoindex(intf);
7260 if (ifindex == 0) {
7261 sigma_dut_print(dut, DUT_MSG_ERROR,
7262 "%s: Index for interface %s failed, val:%d",
7263 __func__, intf, val);
7264 return -1;
7265 }
7266
7267 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7268 NL80211_CMD_VENDOR)) ||
7269 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7270 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7271 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7272 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7273 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7274 nla_put_u8(msg,
7275 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7276 val)) {
7277 sigma_dut_print(dut, DUT_MSG_ERROR,
7278 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7279 __func__, val);
7280 nlmsg_free(msg);
7281 return -1;
7282 }
7283 nla_nest_end(msg, params);
7284
7285 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7286 if (ret) {
7287 sigma_dut_print(dut, DUT_MSG_ERROR,
7288 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7289 __func__, ret, val);
7290 }
7291 return ret;
7292#else /* NL80211_SUPPORT */
7293 sigma_dut_print(dut, DUT_MSG_ERROR,
7294 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7295 return -1;
7296#endif /* NL80211_SUPPORT */
7297}
7298
7299
Arif Hussain480d5f42019-03-12 14:40:42 -07007300static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7301 int val)
7302{
7303#ifdef NL80211_SUPPORT
7304 struct nl_msg *msg;
7305 int ret;
7306 struct nlattr *params;
7307 int ifindex;
7308
7309 ifindex = if_nametoindex(intf);
7310 if (ifindex == 0) {
7311 sigma_dut_print(dut, DUT_MSG_ERROR,
7312 "%s: Index for interface %s failed, val:%d",
7313 __func__, intf, val);
7314 return -1;
7315 }
7316
7317 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7318 NL80211_CMD_VENDOR)) ||
7319 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7320 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7321 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7322 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7323 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7324 nla_put_u8(msg,
7325 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7326 val)) {
7327 sigma_dut_print(dut, DUT_MSG_ERROR,
7328 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7329 __func__, val);
7330 nlmsg_free(msg);
7331 return -1;
7332 }
7333 nla_nest_end(msg, params);
7334
7335 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7336 if (ret) {
7337 sigma_dut_print(dut, DUT_MSG_ERROR,
7338 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7339 __func__, ret, val);
7340 }
7341 return ret;
7342#else /* NL80211_SUPPORT */
7343 sigma_dut_print(dut, DUT_MSG_ERROR,
7344 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7345 return -1;
7346#endif /* NL80211_SUPPORT */
7347}
7348
7349
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007350static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7351 const char *type)
7352{
7353 char buf[60];
7354
7355 if (dut->program == PROGRAM_HE) {
7356 /* resetting phymode to auto in case of HE program */
7357 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7358 if (system(buf) != 0) {
7359 sigma_dut_print(dut, DUT_MSG_ERROR,
7360 "iwpriv %s setphymode failed", intf);
7361 }
7362
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007363 /* reset the rate to Auto rate */
7364 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7365 intf);
7366 if (system(buf) != 0) {
7367 sigma_dut_print(dut, DUT_MSG_ERROR,
7368 "iwpriv %s set_11ax_rate 0xff failed",
7369 intf);
7370 }
7371
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007372 /* reset the LDPC setting */
7373 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7374 if (system(buf) != 0) {
7375 sigma_dut_print(dut, DUT_MSG_ERROR,
7376 "iwpriv %s ldpc 1 failed", intf);
7377 }
7378
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007379 /* reset the power save setting */
7380 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7381 if (system(buf) != 0) {
7382 sigma_dut_print(dut, DUT_MSG_ERROR,
7383 "iwpriv %s setPower 2 failed", intf);
7384 }
7385
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007386 /* remove all network profiles */
7387 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007388
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007389 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7390 sta_set_addba_buf_size(dut, intf, 64);
7391
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007392#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007393 /* Reset the device HE capabilities to its default supported
7394 * configuration. */
7395 sta_set_he_testbed_def(dut, intf, 0);
7396
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007397 /* Disable noackpolicy for all AC */
7398 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7399 sigma_dut_print(dut, DUT_MSG_ERROR,
7400 "Disable of noackpolicy for all AC failed");
7401 }
7402#endif /* NL80211_SUPPORT */
7403
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007404 /* Enable WMM by default */
7405 if (wcn_sta_set_wmm(dut, intf, "on")) {
7406 sigma_dut_print(dut, DUT_MSG_ERROR,
7407 "Enable of WMM in sta_reset_default_wcn failed");
7408 }
7409
7410 /* Disable ADDBA_REJECT by default */
7411 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7412 sigma_dut_print(dut, DUT_MSG_ERROR,
7413 "Disable of addba_reject in sta_reset_default_wcn failed");
7414 }
7415
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007416 /* Enable sending of ADDBA by default */
7417 if (nlvendor_config_send_addba(dut, intf, 1)) {
7418 sigma_dut_print(dut, DUT_MSG_ERROR,
7419 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7420 }
7421
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007422 /* Enable AMPDU by default */
7423 iwpriv_sta_set_ampdu(dut, intf, 1);
7424
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007425#ifdef NL80211_SUPPORT
7426 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
7427 sigma_dut_print(dut, DUT_MSG_ERROR,
7428 "Set LTF config to default in sta_reset_default_wcn failed");
7429 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007430
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007431 /* set the beamformee NSTS(maximum number of
7432 * space-time streams) to default DUT config
7433 */
7434 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007435 sigma_dut_print(dut, DUT_MSG_ERROR,
7436 "Failed to set BeamformeeSTS");
7437 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007438
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007439 if (sta_set_mac_padding_duration(
7440 dut, intf,
7441 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007442 sigma_dut_print(dut, DUT_MSG_ERROR,
7443 "Failed to set MAC padding duration");
7444 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007445
7446 if (sta_set_mu_edca_override(dut, intf, 0)) {
7447 sigma_dut_print(dut, DUT_MSG_ERROR,
7448 "ErrorCode,Failed to set MU EDCA override disable");
7449 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007450
7451 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7452 sigma_dut_print(dut, DUT_MSG_ERROR,
7453 "Failed to set OM ctrl supp");
7454 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007455
7456 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7457 sigma_dut_print(dut, DUT_MSG_ERROR,
7458 "Failed to set Tx SU PPDU enable");
7459 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007460
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007461 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7462 sigma_dut_print(dut, DUT_MSG_ERROR,
7463 "failed to send TB PPDU Tx cfg");
7464 }
7465
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007466 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7467 sigma_dut_print(dut, DUT_MSG_ERROR,
7468 "Failed to set OM ctrl reset");
7469 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007470
7471 /* +HTC-HE support default on */
7472 if (sta_set_he_htc_supp(dut, intf, 1)) {
7473 sigma_dut_print(dut, DUT_MSG_ERROR,
7474 "Setting of +HTC-HE support failed");
7475 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007476#endif /* NL80211_SUPPORT */
7477
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007478 if (sta_set_tx_beamformee(dut, intf, 1)) {
7479 sigma_dut_print(dut, DUT_MSG_ERROR,
7480 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7481 }
7482
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007483 /* Set nss to 1 and MCS 0-7 in case of testbed */
7484 if (type && strcasecmp(type, "Testbed") == 0) {
7485#ifdef NL80211_SUPPORT
7486 int ret;
7487#endif /* NL80211_SUPPORT */
7488
7489 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7490 if (system(buf) != 0) {
7491 sigma_dut_print(dut, DUT_MSG_ERROR,
7492 "iwpriv %s nss failed", intf);
7493 }
7494
7495#ifdef NL80211_SUPPORT
7496 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7497 if (ret) {
7498 sigma_dut_print(dut, DUT_MSG_ERROR,
7499 "Setting of MCS failed, ret:%d",
7500 ret);
7501 }
7502#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007503
7504 /* Disable STBC as default */
7505 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007506
7507 /* Disable AMSDU as default */
7508 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007509
7510#ifdef NL80211_SUPPORT
7511 /* HE fragmentation default off */
7512 if (sta_set_he_fragmentation(dut, intf,
7513 HE_FRAG_DISABLE)) {
7514 sigma_dut_print(dut, DUT_MSG_ERROR,
7515 "Setting of HE fragmentation failed");
7516 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007517
7518 /* set the beamformee NSTS(maximum number of
7519 * space-time streams) to default testbed config
7520 */
7521 if (sta_set_beamformee_sts(dut, intf, 3)) {
7522 sigma_dut_print(dut, DUT_MSG_ERROR,
7523 "Failed to set BeamformeeSTS");
7524 }
7525
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007526 /* +HTC-HE support default off */
7527 if (sta_set_he_htc_supp(dut, intf, 0)) {
7528 sigma_dut_print(dut, DUT_MSG_ERROR,
7529 "Setting of +HTC-HE support failed");
7530 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007531
7532 /* Set device HE capabilities to testbed default
7533 * configuration. */
7534 if (sta_set_he_testbed_def(dut, intf, 1)) {
7535 sigma_dut_print(dut, DUT_MSG_DEBUG,
7536 "Failed to set HE defaults");
7537 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007538
7539 /* Disable VHT support in 2.4 GHz for testbed */
7540 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007541#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007542
7543 /* Enable WEP/TKIP with HE capability in testbed */
7544 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7545 sigma_dut_print(dut, DUT_MSG_ERROR,
7546 "Enabling HE config with WEP/TKIP failed");
7547 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007548 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007549
7550 /* Defaults in case of DUT */
7551 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007552 /* Enable STBC by default */
7553 wcn_sta_set_stbc(dut, intf, "1");
7554
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007555 /* set nss to 2 */
7556 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7557 if (system(buf) != 0) {
7558 sigma_dut_print(dut, DUT_MSG_ERROR,
7559 "iwpriv %s nss 2 failed", intf);
7560 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007561 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007562
7563#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007564 /* Set HE_MCS to 0-11 */
7565 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007566 sigma_dut_print(dut, DUT_MSG_ERROR,
7567 "Setting of MCS failed");
7568 }
7569#endif /* NL80211_SUPPORT */
7570
7571 /* Disable WEP/TKIP with HE capability in DUT */
7572 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7573 sigma_dut_print(dut, DUT_MSG_ERROR,
7574 "Enabling HE config with WEP/TKIP failed");
7575 }
7576 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007577 }
7578}
7579
7580
Jouni Malinenf7222712019-06-13 01:50:21 +03007581static enum sigma_cmd_result cmd_sta_reset_default(struct sigma_dut *dut,
7582 struct sigma_conn *conn,
7583 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007584{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007585 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007586 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007587 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007588 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307589 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007590
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007591 if (!program)
7592 program = get_param(cmd, "prog");
7593 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007594 dut->device_type = STA_unknown;
7595 type = get_param(cmd, "type");
7596 if (type && strcasecmp(type, "Testbed") == 0)
7597 dut->device_type = STA_testbed;
7598 if (type && strcasecmp(type, "DUT") == 0)
7599 dut->device_type = STA_dut;
7600
7601 if (dut->program == PROGRAM_TDLS) {
7602 /* Clear TDLS testing mode */
7603 wpa_command(intf, "SET tdls_disabled 0");
7604 wpa_command(intf, "SET tdls_testing 0");
7605 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307606 if (get_driver_type() == DRIVER_WCN) {
7607 /* Enable the WCN driver in TDLS Explicit trigger mode
7608 */
7609 wpa_command(intf, "SET tdls_external_control 0");
7610 wpa_command(intf, "SET tdls_trigger_control 0");
7611 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007612 }
7613
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007614#ifdef MIRACAST
7615 if (dut->program == PROGRAM_WFD ||
7616 dut->program == PROGRAM_DISPLAYR2)
7617 miracast_sta_reset_default(dut, conn, cmd);
7618#endif /* MIRACAST */
7619
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007620 switch (get_driver_type()) {
7621 case DRIVER_ATHEROS:
7622 sta_reset_default_ath(dut, intf, type);
7623 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007624 case DRIVER_WCN:
7625 sta_reset_default_wcn(dut, intf, type);
7626 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007627 default:
7628 break;
7629 }
7630
7631#ifdef ANDROID_NAN
7632 if (dut->program == PROGRAM_NAN)
7633 nan_cmd_sta_reset_default(dut, conn, cmd);
7634#endif /* ANDROID_NAN */
7635
Vinay Gannevaram3b9fdd32019-06-14 17:55:44 +05307636 if (dut->program == PROGRAM_LOC &&
7637 lowi_cmd_sta_reset_default(dut, conn, cmd) < 0)
7638 return ERROR_SEND_STATUS;
7639
Jouni Malinenba630452018-06-22 11:49:59 +03007640 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007641 unlink("SP/wi-fi.org/pps.xml");
7642 if (system("rm -r SP/*") != 0) {
7643 }
7644 unlink("next-client-cert.pem");
7645 unlink("next-client-key.pem");
7646 }
7647
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007648 /* For WPS program of the 60 GHz band the band type needs to be saved */
7649 if (dut->program == PROGRAM_WPS) {
7650 if (band && strcasecmp(band, "60GHz") == 0) {
7651 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007652 /* For 60 GHz enable WPS for WPS TCs */
7653 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007654 } else {
7655 dut->band = WPS_BAND_NON_60G;
7656 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007657 } else if (dut->program == PROGRAM_60GHZ) {
7658 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7659 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007660 }
7661
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007662 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007663 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007664 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007665
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007666 sigma_dut_print(dut, DUT_MSG_INFO,
7667 "WPS 60 GHz program, wps_disable = %d",
7668 dut->wps_disable);
7669
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007670 if (!dev_role) {
7671 send_resp(dut, conn, SIGMA_ERROR,
7672 "errorCode,Missing DevRole argument");
7673 return 0;
7674 }
7675
7676 if (strcasecmp(dev_role, "STA") == 0)
7677 dut->dev_role = DEVROLE_STA;
7678 else if (strcasecmp(dev_role, "PCP") == 0)
7679 dut->dev_role = DEVROLE_PCP;
7680 else {
7681 send_resp(dut, conn, SIGMA_ERROR,
7682 "errorCode,Unknown DevRole");
7683 return 0;
7684 }
7685
7686 if (dut->device_type == STA_unknown) {
7687 sigma_dut_print(dut, DUT_MSG_ERROR,
7688 "Device type is not STA testbed or DUT");
7689 send_resp(dut, conn, SIGMA_ERROR,
7690 "errorCode,Unknown device type");
7691 return 0;
7692 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007693
7694 sigma_dut_print(dut, DUT_MSG_DEBUG,
7695 "Setting msdu_size to MAX: 7912");
7696 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
7697 get_station_ifname());
7698
7699 if (system(buf) != 0) {
7700 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7701 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007702 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007703 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007704
7705 if (sta_set_force_mcs(dut, 0, 1)) {
7706 sigma_dut_print(dut, DUT_MSG_ERROR,
7707 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007708 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007709 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007710 }
7711
7712 wpa_command(intf, "WPS_ER_STOP");
7713 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307714 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007715 wpa_command(intf, "SET radio_disabled 0");
7716
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007717 dut->wps_forced_version = 0;
7718
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007719 if (dut->wsc_fragment) {
7720 dut->wsc_fragment = 0;
7721 wpa_command(intf, "SET device_name Test client");
7722 wpa_command(intf, "SET manufacturer ");
7723 wpa_command(intf, "SET model_name ");
7724 wpa_command(intf, "SET model_number ");
7725 wpa_command(intf, "SET serial_number ");
7726 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007727 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7728 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7729 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7730 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007731
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007732 if (dut->tmp_mac_addr && dut->set_macaddr) {
7733 dut->tmp_mac_addr = 0;
7734 if (system(dut->set_macaddr) != 0) {
7735 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7736 "temporary MAC address");
7737 }
7738 }
7739
7740 set_ps(intf, dut, 0);
7741
Jouni Malinenba630452018-06-22 11:49:59 +03007742 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7743 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007744 wpa_command(intf, "SET interworking 1");
7745 wpa_command(intf, "SET hs20 1");
7746 }
7747
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007748 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007749 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007750 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007751 wpa_command(intf, "SET pmf 1");
7752 } else {
7753 wpa_command(intf, "SET pmf 0");
7754 }
7755
7756 hs2_clear_credentials(intf);
7757 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7758 wpa_command(intf, "SET access_network_type 15");
7759
7760 static_ip_file(0, NULL, NULL, NULL);
7761 kill_dhcp_client(dut, intf);
7762 clear_ip_addr(dut, intf);
7763
7764 dut->er_oper_performed = 0;
7765 dut->er_oper_bssid[0] = '\0';
7766
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007767 if (dut->program == PROGRAM_LOC) {
7768 /* Disable Interworking by default */
7769 wpa_command(get_station_ifname(), "SET interworking 0");
7770 }
7771
Ashwini Patil00402582017-04-13 12:29:39 +05307772 if (dut->program == PROGRAM_MBO) {
7773 free(dut->non_pref_ch_list);
7774 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307775 free(dut->btm_query_cand_list);
7776 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307777 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307778 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307779 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307780 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307781 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307782 }
7783
Jouni Malinen3c367e82017-06-23 17:01:47 +03007784 free(dut->rsne_override);
7785 dut->rsne_override = NULL;
7786
Jouni Malinen68143132017-09-02 02:34:08 +03007787 free(dut->sae_commit_override);
7788 dut->sae_commit_override = NULL;
7789
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007790 dut->sta_associate_wait_connect = 0;
7791 dut->server_cert_hash[0] = '\0';
Jouni Malinen37d5c692019-08-19 16:56:55 +03007792 dut->server_cert_tod = 0;
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007793 dut->sta_tod_policy = 0;
7794
Jouni Malinend86e5822017-08-29 03:55:32 +03007795 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007796 free(dut->dpp_peer_uri);
7797 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007798 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007799 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007800
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007801 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7802
vamsi krishnaa2799492017-12-05 14:28:01 +05307803 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307804 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307805 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307806 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7807 dut->fils_hlp = 0;
7808#ifdef ANDROID
7809 hlp_thread_cleanup(dut);
7810#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307811 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307812
Jouni Malinen8179fee2019-03-28 03:19:47 +02007813 dut->akm_values = 0;
Jouni Malinen6a7c9b42019-08-20 00:15:59 +03007814 dut->sta_ft_ds = 0;
Jouni Malinen8179fee2019-03-28 03:19:47 +02007815
Sunil Dutt076081f2018-02-05 19:45:50 +05307816#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05307817 if (get_driver_type() == DRIVER_WCN &&
7818 dut->config_rsnie == 1) {
7819 dut->config_rsnie = 0;
7820 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307821 }
7822#endif /* NL80211_SUPPORT */
7823
Sunil Duttfebf8a82018-02-09 18:50:13 +05307824 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7825 dut->dev_role = DEVROLE_STA_CFON;
7826 return sta_cfon_reset_default(dut, conn, cmd);
7827 }
7828
Jouni Malinen439352d2018-09-13 03:42:23 +03007829 wpa_command(intf, "SET setband AUTO");
7830
Sunil Duttfebf8a82018-02-09 18:50:13 +05307831 if (dut->program != PROGRAM_VHT)
7832 return cmd_sta_p2p_reset(dut, conn, cmd);
7833
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007834 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007835}
7836
7837
Jouni Malinenf7222712019-06-13 01:50:21 +03007838static enum sigma_cmd_result cmd_sta_get_events(struct sigma_dut *dut,
7839 struct sigma_conn *conn,
7840 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007841{
7842 const char *program = get_param(cmd, "Program");
7843
7844 if (program == NULL)
7845 return -1;
7846#ifdef ANDROID_NAN
7847 if (strcasecmp(program, "NAN") == 0)
7848 return nan_cmd_sta_get_events(dut, conn, cmd);
7849#endif /* ANDROID_NAN */
7850 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7851 return 0;
7852}
7853
7854
Jouni Malinen82905202018-04-29 17:20:10 +03007855static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7856 struct sigma_cmd *cmd)
7857{
7858 const char *url = get_param(cmd, "url");
7859 const char *method = get_param(cmd, "method");
7860 pid_t pid;
7861 int status;
7862
7863 if (!url || !method)
7864 return -1;
7865
7866 /* TODO: Add support for method,post */
7867 if (strcasecmp(method, "get") != 0) {
7868 send_resp(dut, conn, SIGMA_ERROR,
7869 "ErrorCode,Unsupported method");
7870 return 0;
7871 }
7872
7873 pid = fork();
7874 if (pid < 0) {
7875 perror("fork");
7876 return -1;
7877 }
7878
7879 if (pid == 0) {
7880 char * argv[5] = { "wget", "-O", "/dev/null",
7881 (char *) url, NULL };
7882
7883 execv("/usr/bin/wget", argv);
7884 perror("execv");
7885 exit(0);
7886 return -1;
7887 }
7888
7889 if (waitpid(pid, &status, 0) < 0) {
7890 perror("waitpid");
7891 return -1;
7892 }
7893
7894 if (WIFEXITED(status)) {
7895 const char *errmsg;
7896
7897 if (WEXITSTATUS(status) == 0)
7898 return 1;
7899 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7900 WEXITSTATUS(status));
7901 switch (WEXITSTATUS(status)) {
7902 case 4:
7903 errmsg = "errmsg,Network failure";
7904 break;
7905 case 8:
7906 errmsg = "errmsg,Server issued an error response";
7907 break;
7908 default:
7909 errmsg = "errmsg,Unknown failure from wget";
7910 break;
7911 }
7912 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7913 return 0;
7914 }
7915
7916 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7917 return 0;
7918}
7919
7920
Jouni Malinenf7222712019-06-13 01:50:21 +03007921static enum sigma_cmd_result cmd_sta_exec_action(struct sigma_dut *dut,
7922 struct sigma_conn *conn,
7923 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007924{
7925 const char *program = get_param(cmd, "Prog");
7926
Jouni Malinen82905202018-04-29 17:20:10 +03007927 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007928 return -1;
7929#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007930 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007931 return nan_cmd_sta_exec_action(dut, conn, cmd);
7932#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007933
7934 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007935 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007936
7937 if (get_param(cmd, "url"))
7938 return sta_exec_action_url(dut, conn, cmd);
7939
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007940 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7941 return 0;
7942}
7943
7944
Jouni Malinenf7222712019-06-13 01:50:21 +03007945static enum sigma_cmd_result cmd_sta_set_11n(struct sigma_dut *dut,
7946 struct sigma_conn *conn,
7947 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007948{
7949 const char *intf = get_param(cmd, "Interface");
7950 const char *val, *mcs32, *rate;
7951
7952 val = get_param(cmd, "GREENFIELD");
7953 if (val) {
7954 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7955 /* Enable GD */
7956 send_resp(dut, conn, SIGMA_ERROR,
7957 "ErrorCode,GF not supported");
7958 return 0;
7959 }
7960 }
7961
7962 val = get_param(cmd, "SGI20");
7963 if (val) {
7964 switch (get_driver_type()) {
7965 case DRIVER_ATHEROS:
7966 ath_sta_set_sgi(dut, intf, val);
7967 break;
7968 default:
7969 send_resp(dut, conn, SIGMA_ERROR,
7970 "ErrorCode,SGI20 not supported");
7971 return 0;
7972 }
7973 }
7974
7975 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7976 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7977 if (mcs32 && rate) {
7978 /* TODO */
7979 send_resp(dut, conn, SIGMA_ERROR,
7980 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7981 return 0;
7982 } else if (mcs32 && !rate) {
7983 /* TODO */
7984 send_resp(dut, conn, SIGMA_ERROR,
7985 "ErrorCode,MCS32 not supported");
7986 return 0;
7987 } else if (!mcs32 && rate) {
7988 switch (get_driver_type()) {
7989 case DRIVER_ATHEROS:
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -07007990 novap_reset(dut, intf, 1);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007991 ath_sta_set_11nrates(dut, intf, rate);
7992 break;
7993 default:
7994 send_resp(dut, conn, SIGMA_ERROR,
7995 "ErrorCode,MCS32_FIXEDRATE not supported");
7996 return 0;
7997 }
7998 }
7999
8000 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8001}
8002
8003
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008004static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
8005 int mcs_config)
8006{
8007#ifdef NL80211_SUPPORT
8008 int ret;
8009
8010 switch (mcs_config) {
8011 case HE_80_MCS0_7:
8012 case HE_80_MCS0_9:
8013 case HE_80_MCS0_11:
8014 ret = sta_set_he_mcs(dut, intf, mcs_config);
8015 if (ret) {
8016 sigma_dut_print(dut, DUT_MSG_ERROR,
8017 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
8018 mcs_config, ret);
8019 }
8020 break;
8021 default:
8022 sigma_dut_print(dut, DUT_MSG_ERROR,
8023 "cmd_set_max_he_mcs: Invalid mcs %d",
8024 mcs_config);
8025 break;
8026 }
8027#else /* NL80211_SUPPORT */
8028 sigma_dut_print(dut, DUT_MSG_ERROR,
8029 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
8030#endif /* NL80211_SUPPORT */
8031}
8032
8033
Arif Hussain480d5f42019-03-12 14:40:42 -07008034static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
8035 struct sigma_cmd *cmd)
8036{
8037#ifdef NL80211_SUPPORT
8038 struct nlattr *params;
8039 struct nlattr *attr;
8040 struct nlattr *attr1;
8041 struct nl_msg *msg;
8042 int ifindex, ret;
8043 const char *val;
8044 const char *intf = get_param(cmd, "Interface");
8045 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
8046 wake_interval_mantissa = 512;
8047 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
8048 protection = 0;
8049
8050 ifindex = if_nametoindex(intf);
8051 if (ifindex == 0) {
8052 sigma_dut_print(dut, DUT_MSG_ERROR,
8053 "%s: Index for interface %s failed",
8054 __func__, intf);
8055 return -1;
8056 }
8057
8058 val = get_param(cmd, "FlowType");
8059 if (val) {
8060 flow_type = atoi(val);
8061 if (flow_type != 0 && flow_type != 1) {
8062 sigma_dut_print(dut, DUT_MSG_ERROR,
8063 "TWT: Invalid FlowType %d", flow_type);
8064 return -1;
8065 }
8066 }
8067
8068 val = get_param(cmd, "TWT_Trigger");
8069 if (val) {
8070 twt_trigger = atoi(val);
8071 if (twt_trigger != 0 && twt_trigger != 1) {
8072 sigma_dut_print(dut, DUT_MSG_ERROR,
8073 "TWT: Invalid TWT_Trigger %d",
8074 twt_trigger);
8075 return -1;
8076 }
8077 }
8078
8079 val = get_param(cmd, "Protection");
8080 if (val) {
8081 protection = atoi(val);
8082 if (protection != 0 && protection != 1) {
8083 sigma_dut_print(dut, DUT_MSG_ERROR,
8084 "TWT: Invalid Protection %d",
8085 protection);
8086 return -1;
8087 }
8088 }
8089
8090 val = get_param(cmd, "TargetWakeTime");
8091 if (val)
8092 target_wake_time = atoi(val);
8093
8094 val = get_param(cmd, "WakeIntervalMantissa");
8095 if (val)
8096 wake_interval_mantissa = atoi(val);
8097
8098 val = get_param(cmd, "WakeIntervalExp");
8099 if (val)
8100 wake_interval_exp = atoi(val);
8101
8102 val = get_param(cmd, "NominalMinWakeDur");
8103 if (val)
8104 nominal_min_wake_dur = atoi(val);
8105
8106 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8107 NL80211_CMD_VENDOR)) ||
8108 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8109 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8110 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8111 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8112 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8113 !(params = nla_nest_start(
8114 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
8115 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8116 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
8117 wake_interval_exp) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008118 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008119 (twt_trigger &&
8120 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008121 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
8122 flow_type) ||
Kiran Kumar Lokere2cffae52019-09-26 18:44:15 -07008123 (protection &&
8124 nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION)) ||
Arif Hussain480d5f42019-03-12 14:40:42 -07008125 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
8126 target_wake_time) ||
8127 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
8128 nominal_min_wake_dur) ||
8129 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
8130 wake_interval_mantissa)) {
8131 sigma_dut_print(dut, DUT_MSG_ERROR,
8132 "%s: err in adding vendor_cmd and vendor_data",
8133 __func__);
8134 nlmsg_free(msg);
8135 return -1;
8136 }
8137 nla_nest_end(msg, attr1);
8138 nla_nest_end(msg, params);
8139 nla_nest_end(msg, attr);
8140
8141 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8142 if (ret) {
8143 sigma_dut_print(dut, DUT_MSG_ERROR,
8144 "%s: err in send_and_recv_msgs, ret=%d",
8145 __func__, ret);
8146 }
8147
8148 return ret;
8149#else /* NL80211_SUPPORT */
8150 sigma_dut_print(dut, DUT_MSG_ERROR,
8151 "TWT request cannot be done without NL80211_SUPPORT defined");
8152 return -1;
8153#endif /* NL80211_SUPPORT */
8154}
8155
8156
8157static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
8158 struct sigma_cmd *cmd)
8159{
8160 #ifdef NL80211_SUPPORT
8161 struct nlattr *params;
8162 struct nlattr *attr;
8163 struct nlattr *attr1;
8164 int ifindex, ret;
8165 struct nl_msg *msg;
8166 const char *intf = get_param(cmd, "Interface");
8167
8168 ifindex = if_nametoindex(intf);
8169 if (ifindex == 0) {
8170 sigma_dut_print(dut, DUT_MSG_ERROR,
8171 "%s: Index for interface %s failed",
8172 __func__, intf);
8173 return -1;
8174 }
8175
8176 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8177 NL80211_CMD_VENDOR)) ||
8178 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8179 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8180 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8181 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8182 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8183 !(params = nla_nest_start(
8184 msg,
8185 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8186 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8187 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8188 sigma_dut_print(dut, DUT_MSG_ERROR,
8189 "%s: err in adding vendor_cmd and vendor_data",
8190 __func__);
8191 nlmsg_free(msg);
8192 return -1;
8193 }
8194 nla_nest_end(msg, attr1);
8195 nla_nest_end(msg, params);
8196 nla_nest_end(msg, attr);
8197
8198 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8199 if (ret) {
8200 sigma_dut_print(dut, DUT_MSG_ERROR,
8201 "%s: err in send_and_recv_msgs, ret=%d",
8202 __func__, ret);
8203 }
8204
8205 return ret;
8206#else /* NL80211_SUPPORT */
8207 sigma_dut_print(dut, DUT_MSG_ERROR,
8208 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8209 return -1;
8210#endif /* NL80211_SUPPORT */
8211}
8212
8213
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008214static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8215 struct sigma_cmd *cmd)
8216{
8217#ifdef NL80211_SUPPORT
8218 struct nlattr *params;
8219 struct nlattr *attr;
8220 struct nlattr *attr1;
8221 struct nl_msg *msg;
8222 int ifindex, ret;
8223 const char *val;
8224 const char *intf = get_param(cmd, "Interface");
8225 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8226 ulmu_data_dis = 0;
8227
8228 ifindex = if_nametoindex(intf);
8229 if (ifindex == 0) {
8230 sigma_dut_print(dut, DUT_MSG_ERROR,
8231 "%s: Index for interface %s failed",
8232 __func__, intf);
8233 return -1;
8234 }
8235 val = get_param(cmd, "OMCtrl_RxNSS");
8236 if (val)
8237 rx_nss = atoi(val);
8238
8239 val = get_param(cmd, "OMCtrl_ChnlWidth");
8240 if (val)
8241 ch_bw = atoi(val);
8242
8243 val = get_param(cmd, "OMCtrl_ULMUDisable");
8244 if (val)
8245 ulmu_dis = atoi(val);
8246
8247 val = get_param(cmd, "OMCtrl_TxNSTS");
8248 if (val)
8249 tx_nsts = atoi(val);
8250
8251 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8252 if (val)
8253 ulmu_data_dis = atoi(val);
8254
8255 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8256 NL80211_CMD_VENDOR)) ||
8257 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8258 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8259 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8260 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8261 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8262 !(params = nla_nest_start(
8263 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8264 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8265 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8266 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8267 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8268 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8269 ulmu_data_dis) ||
8270 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8271 ulmu_dis)) {
8272 sigma_dut_print(dut, DUT_MSG_ERROR,
8273 "%s: err in adding vendor_cmd and vendor_data",
8274 __func__);
8275 nlmsg_free(msg);
8276 return -1;
8277 }
8278 nla_nest_end(msg, attr1);
8279 nla_nest_end(msg, params);
8280 nla_nest_end(msg, attr);
8281
8282 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8283 if (ret) {
8284 sigma_dut_print(dut, DUT_MSG_ERROR,
8285 "%s: err in send_and_recv_msgs, ret=%d",
8286 __func__, ret);
8287 }
8288
8289 return ret;
8290#else /* NL80211_SUPPORT */
8291 sigma_dut_print(dut, DUT_MSG_ERROR,
8292 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8293 return -1;
8294#endif /* NL80211_SUPPORT */
8295}
8296
8297
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008298static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8299 struct sigma_conn *conn,
8300 struct sigma_cmd *cmd)
8301{
8302 const char *intf = get_param(cmd, "Interface");
8303 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008304 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008305 int tkip = -1;
8306 int wep = -1;
8307
Arif Hussaina37e9552018-06-20 17:05:59 -07008308 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008309 val = get_param(cmd, "SGI80");
8310 if (val) {
8311 int sgi80;
8312
8313 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008314 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008315 }
8316
8317 val = get_param(cmd, "TxBF");
8318 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008319 switch (get_driver_type()) {
8320 case DRIVER_WCN:
8321 if (sta_set_tx_beamformee(dut, intf, 1)) {
8322 send_resp(dut, conn, SIGMA_ERROR,
8323 "ErrorCode,Failed to set TX beamformee enable");
8324 return 0;
8325 }
8326 break;
8327 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008328 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008329 send_resp(dut, conn, SIGMA_ERROR,
8330 "ErrorCode,Setting vhtsubfee failed");
8331 return 0;
8332 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008333 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008334 send_resp(dut, conn, SIGMA_ERROR,
8335 "ErrorCode,Setting vhtsubfer failed");
8336 return 0;
8337 }
8338 break;
8339 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008340 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008341 "Unsupported driver type");
8342 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008343 }
8344 }
8345
8346 val = get_param(cmd, "MU_TxBF");
8347 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
8348 switch (get_driver_type()) {
8349 case DRIVER_ATHEROS:
8350 ath_sta_set_txsp_stream(dut, intf, "1SS");
8351 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008352 run_iwpriv(dut, intf, "vhtmubfee 1");
8353 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308354 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008355 case DRIVER_WCN:
8356 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8357 send_resp(dut, conn, SIGMA_ERROR,
8358 "ErrorCode,Failed to set RX/TXSP_STREAM");
8359 return 0;
8360 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308361 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008362 default:
8363 sigma_dut_print(dut, DUT_MSG_ERROR,
8364 "Setting SP_STREAM not supported");
8365 break;
8366 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008367 }
8368
8369 val = get_param(cmd, "LDPC");
8370 if (val) {
8371 int ldpc;
8372
8373 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008374 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008375 }
8376
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008377 val = get_param(cmd, "BCC");
8378 if (val) {
8379 int bcc;
8380
8381 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8382 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8383 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008384 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008385 }
8386
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008387 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8388 if (val && dut->sta_nss == 1)
8389 cmd_set_max_he_mcs(dut, intf, atoi(val));
8390
8391 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8392 if (val && dut->sta_nss == 2)
8393 cmd_set_max_he_mcs(dut, intf, atoi(val));
8394
Arif Hussainac6c5112018-05-25 17:34:00 -07008395 val = get_param(cmd, "MCS_FixedRate");
8396 if (val) {
8397#ifdef NL80211_SUPPORT
8398 int mcs, ratecode = 0;
8399 enum he_mcs_config mcs_config;
8400 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008401 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008402
8403 ratecode = (0x07 & dut->sta_nss) << 5;
8404 mcs = atoi(val);
8405 /* Add the MCS to the ratecode */
8406 if (mcs >= 0 && mcs <= 11) {
8407 ratecode += mcs;
8408 if (dut->device_type == STA_testbed &&
8409 mcs > 7 && mcs <= 11) {
8410 if (mcs <= 9)
8411 mcs_config = HE_80_MCS0_9;
8412 else
8413 mcs_config = HE_80_MCS0_11;
8414 ret = sta_set_he_mcs(dut, intf, mcs_config);
8415 if (ret) {
8416 sigma_dut_print(dut, DUT_MSG_ERROR,
8417 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8418 mcs, mcs_config, ret);
8419 }
8420 }
8421 snprintf(buf, sizeof(buf),
8422 "iwpriv %s set_11ax_rate 0x%03x",
8423 intf, ratecode);
8424 if (system(buf) != 0) {
8425 sigma_dut_print(dut, DUT_MSG_ERROR,
8426 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8427 ratecode);
8428 }
8429 } else {
8430 sigma_dut_print(dut, DUT_MSG_ERROR,
8431 "MCS_FixedRate: HE MCS %d not supported",
8432 mcs);
8433 }
8434#else /* NL80211_SUPPORT */
8435 sigma_dut_print(dut, DUT_MSG_ERROR,
8436 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8437#endif /* NL80211_SUPPORT */
8438 }
8439
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008440 val = get_param(cmd, "opt_md_notif_ie");
8441 if (val) {
8442 char *result = NULL;
8443 char delim[] = ";";
8444 char token[30];
8445 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308446 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008447
Peng Xub8fc5cc2017-05-10 17:27:28 -07008448 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308449 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008450
8451 /* Extract the NSS information */
8452 if (result) {
8453 value = atoi(result);
8454 switch (value) {
8455 case 1:
8456 config_val = 1;
8457 break;
8458 case 2:
8459 config_val = 3;
8460 break;
8461 case 3:
8462 config_val = 7;
8463 break;
8464 case 4:
8465 config_val = 15;
8466 break;
8467 default:
8468 config_val = 3;
8469 break;
8470 }
8471
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008472 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8473 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008474
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008475 }
8476
8477 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308478 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008479 if (result) {
8480 value = atoi(result);
8481 switch (value) {
8482 case 20:
8483 config_val = 0;
8484 break;
8485 case 40:
8486 config_val = 1;
8487 break;
8488 case 80:
8489 config_val = 2;
8490 break;
8491 case 160:
8492 config_val = 3;
8493 break;
8494 default:
8495 config_val = 2;
8496 break;
8497 }
8498
8499 dut->chwidth = config_val;
8500
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008501 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008502 }
8503
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008504 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008505 }
8506
8507 val = get_param(cmd, "nss_mcs_cap");
8508 if (val) {
8509 int nss, mcs;
8510 char token[20];
8511 char *result = NULL;
8512 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308513 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008514
Peng Xub8fc5cc2017-05-10 17:27:28 -07008515 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308516 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308517 if (!result) {
8518 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008519 "NSS not specified");
8520 send_resp(dut, conn, SIGMA_ERROR,
8521 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308522 return 0;
8523 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008524 nss = atoi(result);
8525
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008526 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008527 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008528
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308529 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008530 if (result == NULL) {
8531 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008532 "MCS not specified");
8533 send_resp(dut, conn, SIGMA_ERROR,
8534 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008535 return 0;
8536 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308537 result = strtok_r(result, "-", &saveptr);
8538 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308539 if (!result) {
8540 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008541 "MCS not specified");
8542 send_resp(dut, conn, SIGMA_ERROR,
8543 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308544 return 0;
8545 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008546 mcs = atoi(result);
8547
Arif Hussaina37e9552018-06-20 17:05:59 -07008548 if (program && strcasecmp(program, "HE") == 0) {
8549#ifdef NL80211_SUPPORT
8550 enum he_mcs_config mcs_config;
8551 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008552
Arif Hussaina37e9552018-06-20 17:05:59 -07008553 if (mcs >= 0 && mcs <= 7) {
8554 mcs_config = HE_80_MCS0_7;
8555 } else if (mcs > 7 && mcs <= 9) {
8556 mcs_config = HE_80_MCS0_9;
8557 } else if (mcs > 9 && mcs <= 11) {
8558 mcs_config = HE_80_MCS0_11;
8559 } else {
8560 sigma_dut_print(dut, DUT_MSG_ERROR,
8561 "nss_mcs_cap: HE: Invalid mcs: %d",
8562 mcs);
8563 send_resp(dut, conn, SIGMA_ERROR,
8564 "errorCode,Invalid MCS");
8565 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008566 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008567
8568 ret = sta_set_he_mcs(dut, intf, mcs_config);
8569 if (ret) {
8570 sigma_dut_print(dut, DUT_MSG_ERROR,
8571 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8572 mcs_config, ret);
8573 send_resp(dut, conn, SIGMA_ERROR,
8574 "errorCode,Failed to set MCS");
8575 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008576 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008577#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008578 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008579 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8580#endif /* NL80211_SUPPORT */
8581 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008582 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008583
8584 switch (nss) {
8585 case 1:
8586 switch (mcs) {
8587 case 7:
8588 vht_mcsmap = 0xfffc;
8589 break;
8590 case 8:
8591 vht_mcsmap = 0xfffd;
8592 break;
8593 case 9:
8594 vht_mcsmap = 0xfffe;
8595 break;
8596 default:
8597 vht_mcsmap = 0xfffe;
8598 break;
8599 }
8600 break;
8601 case 2:
8602 switch (mcs) {
8603 case 7:
8604 vht_mcsmap = 0xfff0;
8605 break;
8606 case 8:
8607 vht_mcsmap = 0xfff5;
8608 break;
8609 case 9:
8610 vht_mcsmap = 0xfffa;
8611 break;
8612 default:
8613 vht_mcsmap = 0xfffa;
8614 break;
8615 }
8616 break;
8617 case 3:
8618 switch (mcs) {
8619 case 7:
8620 vht_mcsmap = 0xffc0;
8621 break;
8622 case 8:
8623 vht_mcsmap = 0xffd5;
8624 break;
8625 case 9:
8626 vht_mcsmap = 0xffea;
8627 break;
8628 default:
8629 vht_mcsmap = 0xffea;
8630 break;
8631 }
8632 break;
8633 default:
8634 vht_mcsmap = 0xffea;
8635 break;
8636 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008637 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008638 }
8639 }
8640
8641 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8642
8643 val = get_param(cmd, "Vht_tkip");
8644 if (val)
8645 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8646
8647 val = get_param(cmd, "Vht_wep");
8648 if (val)
8649 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8650
8651 if (tkip != -1 || wep != -1) {
8652 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008653 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008654 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008655 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008656 } else {
8657 sigma_dut_print(dut, DUT_MSG_ERROR,
8658 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8659 return 0;
8660 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008661 }
8662
Arif Hussain55f00da2018-07-03 08:28:26 -07008663 val = get_param(cmd, "txBandwidth");
8664 if (val) {
8665 switch (get_driver_type()) {
8666 case DRIVER_WCN:
8667 if (wcn_sta_set_width(dut, intf, val) < 0) {
8668 send_resp(dut, conn, SIGMA_ERROR,
8669 "ErrorCode,Failed to set txBandwidth");
8670 return 0;
8671 }
8672 break;
8673 case DRIVER_ATHEROS:
8674 if (ath_set_width(dut, conn, intf, val) < 0) {
8675 send_resp(dut, conn, SIGMA_ERROR,
8676 "ErrorCode,Failed to set txBandwidth");
8677 return 0;
8678 }
8679 break;
8680 default:
8681 sigma_dut_print(dut, DUT_MSG_ERROR,
8682 "Setting txBandwidth not supported");
8683 break;
8684 }
8685 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008686
Arif Hussain9765f7d2018-07-03 08:28:26 -07008687 val = get_param(cmd, "BeamformeeSTS");
8688 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008689 if (sta_set_tx_beamformee(dut, intf, 1)) {
8690 send_resp(dut, conn, SIGMA_ERROR,
8691 "ErrorCode,Failed to set TX beamformee enable");
8692 return 0;
8693 }
8694
Arif Hussain9765f7d2018-07-03 08:28:26 -07008695 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8696 send_resp(dut, conn, SIGMA_ERROR,
8697 "ErrorCode,Failed to set BeamformeeSTS");
8698 return 0;
8699 }
8700 }
8701
Arif Hussain68d23f52018-07-11 13:39:08 -07008702 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8703 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008704#ifdef NL80211_SUPPORT
8705 enum qca_wlan_he_mac_padding_dur set_val;
8706
8707 switch (atoi(val)) {
8708 case 16:
8709 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8710 break;
8711 case 8:
8712 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8713 break;
8714 default:
8715 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8716 break;
8717 }
8718 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008719 send_resp(dut, conn, SIGMA_ERROR,
8720 "ErrorCode,Failed to set MAC padding duration");
8721 return 0;
8722 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008723#else /* NL80211_SUPPORT */
8724 sigma_dut_print(dut, DUT_MSG_ERROR,
8725 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8726#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008727 }
8728
Arif Hussain480d5f42019-03-12 14:40:42 -07008729 val = get_param(cmd, "TWT_ReqSupport");
8730 if (val) {
8731 int set_val;
8732
8733 if (strcasecmp(val, "Enable") == 0) {
8734 set_val = 1;
8735 } else if (strcasecmp(val, "Disable") == 0) {
8736 set_val = 0;
8737 } else {
8738 send_resp(dut, conn, SIGMA_ERROR,
8739 "ErrorCode,Invalid TWT_ReqSupport");
8740 return STATUS_SENT;
8741 }
8742
8743 if (sta_set_twt_req_support(dut, intf, set_val)) {
8744 sigma_dut_print(dut, DUT_MSG_ERROR,
8745 "Failed to set TWT req support %d",
8746 set_val);
8747 send_resp(dut, conn, SIGMA_ERROR,
8748 "ErrorCode,Failed to set TWT_ReqSupport");
8749 return STATUS_SENT;
8750 }
8751 }
8752
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008753 val = get_param(cmd, "MU_EDCA");
8754 if (val && (strcasecmp(val, "Override") == 0)) {
8755 if (sta_set_mu_edca_override(dut, intf, 1)) {
8756 send_resp(dut, conn, SIGMA_ERROR,
8757 "ErrorCode,Failed to set MU EDCA override");
8758 return 0;
8759 }
8760 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008761
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008762 val = get_param(cmd, "OMControl");
8763 if (val) {
8764 int set_val = 1;
8765
8766 if (strcasecmp(val, "Enable") == 0)
8767 set_val = 1;
8768 else if (strcasecmp(val, "Disable") == 0)
8769 set_val = 0;
8770
8771 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8772 send_resp(dut, conn, SIGMA_ERROR,
8773 "ErrorCode,Failed to set OM ctrl supp");
8774 return 0;
8775 }
8776 }
8777
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008778 val = get_param(cmd, "ADDBAResp_BufSize");
8779 if (val) {
8780 int buf_size;
8781
8782 if (strcasecmp(val, "gt64") == 0)
8783 buf_size = 256;
8784 else
8785 buf_size = 64;
8786 if (get_driver_type() == DRIVER_WCN &&
8787 sta_set_addba_buf_size(dut, intf, buf_size)) {
8788 send_resp(dut, conn, SIGMA_ERROR,
8789 "ErrorCode,set addbaresp_buff_size failed");
8790 return 0;
8791 }
8792 }
8793
8794 val = get_param(cmd, "ADDBAReq_BufSize");
8795 if (val) {
8796 int buf_size;
8797
8798 if (strcasecmp(val, "gt64") == 0)
8799 buf_size = 256;
8800 else
8801 buf_size = 64;
8802 if (get_driver_type() == DRIVER_WCN &&
8803 sta_set_addba_buf_size(dut, intf, buf_size)) {
8804 send_resp(dut, conn, SIGMA_ERROR,
8805 "ErrorCode,set addbareq_buff_size failed");
8806 return 0;
8807 }
8808 }
8809
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008810 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8811}
8812
8813
8814static int sta_set_wireless_60g(struct sigma_dut *dut,
8815 struct sigma_conn *conn,
8816 struct sigma_cmd *cmd)
8817{
8818 const char *dev_role = get_param(cmd, "DevRole");
8819
8820 if (!dev_role) {
8821 send_resp(dut, conn, SIGMA_INVALID,
8822 "ErrorCode,DevRole not specified");
8823 return 0;
8824 }
8825
8826 if (strcasecmp(dev_role, "PCP") == 0)
8827 return sta_set_60g_pcp(dut, conn, cmd);
8828 if (strcasecmp(dev_role, "STA") == 0)
8829 return sta_set_60g_sta(dut, conn, cmd);
8830 send_resp(dut, conn, SIGMA_INVALID,
8831 "ErrorCode,DevRole not supported");
8832 return 0;
8833}
8834
8835
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308836static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8837 struct sigma_cmd *cmd)
8838{
8839 int status;
8840 const char *intf = get_param(cmd, "Interface");
8841 const char *val = get_param(cmd, "DevRole");
8842
8843 if (val && strcasecmp(val, "STA-CFON") == 0) {
8844 status = sta_cfon_set_wireless(dut, conn, cmd);
8845 if (status)
8846 return status;
8847 }
8848 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8849}
8850
8851
Jouni Malinenf7222712019-06-13 01:50:21 +03008852static enum sigma_cmd_result cmd_sta_set_wireless(struct sigma_dut *dut,
8853 struct sigma_conn *conn,
8854 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008855{
8856 const char *val;
8857
8858 val = get_param(cmd, "Program");
8859 if (val) {
8860 if (strcasecmp(val, "11n") == 0)
8861 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008862 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008863 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8864 if (strcasecmp(val, "60ghz") == 0)
8865 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308866 if (strcasecmp(val, "OCE") == 0)
8867 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008868 /* sta_set_wireless in WPS program is only used for 60G */
8869 if (is_60g_sigma_dut(dut))
8870 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008871 send_resp(dut, conn, SIGMA_ERROR,
8872 "ErrorCode,Program value not supported");
8873 } else {
8874 send_resp(dut, conn, SIGMA_ERROR,
8875 "ErrorCode,Program argument not available");
8876 }
8877
8878 return 0;
8879}
8880
8881
8882static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8883 int tid)
8884{
8885 char buf[100];
8886 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8887
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308888 if (tid < 0 ||
8889 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8890 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8891 return;
8892 }
8893
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008894 /*
8895 * Two ways to ensure that addba request with a
8896 * non zero TID could be sent out. EV 117296
8897 */
8898 snprintf(buf, sizeof(buf),
8899 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8900 tid);
8901 if (system(buf) != 0) {
8902 sigma_dut_print(dut, DUT_MSG_ERROR,
8903 "Ping did not send out");
8904 }
8905
8906 snprintf(buf, sizeof(buf),
8907 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8908 intf, VI_QOS_TMP_FILE);
8909 if (system(buf) != 0)
8910 return;
8911
8912 snprintf(buf, sizeof(buf),
8913 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8914 intf, VI_QOS_TMP_FILE);
8915 if (system(buf) != 0)
8916 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8917
8918 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8919 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8920 if (system(buf) != 0) {
8921 sigma_dut_print(dut, DUT_MSG_ERROR,
8922 "VI_QOS_TEMP_FILE generation error failed");
8923 }
8924 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8925 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8926 if (system(buf) != 0) {
8927 sigma_dut_print(dut, DUT_MSG_ERROR,
8928 "VI_QOS_FILE generation failed");
8929 }
8930
8931 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8932 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8933 if (system(buf) != 0) {
8934 sigma_dut_print(dut, DUT_MSG_ERROR,
8935 "VI_QOS_FILE generation failed");
8936 }
8937
8938 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8939 if (system(buf) != 0) {
8940 }
8941}
8942
8943
8944static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8945 struct sigma_cmd *cmd)
8946{
8947 const char *intf = get_param(cmd, "Interface");
8948 const char *val;
8949 int tid = 0;
8950 char buf[100];
8951
8952 val = get_param(cmd, "TID");
8953 if (val) {
8954 tid = atoi(val);
8955 if (tid)
8956 ath_sta_inject_frame(dut, intf, tid);
8957 }
8958
8959 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008960 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008961
8962 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8963 if (system(buf) != 0) {
8964 sigma_dut_print(dut, DUT_MSG_ERROR,
8965 "wifitool senddelba failed");
8966 }
8967
8968 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8969 if (system(buf) != 0) {
8970 sigma_dut_print(dut, DUT_MSG_ERROR,
8971 "wifitool sendaddba failed");
8972 }
8973
8974 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8975
8976 return 1;
8977}
8978
8979
Lior David9981b512017-01-20 13:16:40 +02008980#ifdef __linux__
8981
8982static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
8983 int agg_size)
8984{
8985 char dir[128], buf[128];
8986 FILE *f;
8987 regex_t re;
8988 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03008989 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02008990
8991 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
8992 sigma_dut_print(dut, DUT_MSG_ERROR,
8993 "failed to get wil6210 debugfs dir");
8994 return -1;
8995 }
8996
Jouni Malinen3aa72862019-05-29 23:14:51 +03008997 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
8998 if (res < 0 || res >= sizeof(buf))
8999 return -1;
Lior David9981b512017-01-20 13:16:40 +02009000 f = fopen(buf, "r");
9001 if (!f) {
9002 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009003 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03009004 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
9005 if (res < 0 || res >= sizeof(buf))
9006 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009007 f = fopen(buf, "r");
9008 if (!f) {
9009 sigma_dut_print(dut, DUT_MSG_ERROR,
9010 "failed to open: %s", buf);
9011 return -1;
9012 }
Lior David9981b512017-01-20 13:16:40 +02009013 }
9014
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02009015 /* can be either VRING tx... or RING... */
9016 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02009017 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
9018 goto out;
9019 }
9020
9021 /* find TX VRING for the mac address */
9022 found = 0;
9023 while (fgets(buf, sizeof(buf), f)) {
9024 if (strcasestr(buf, dest_mac)) {
9025 found = 1;
9026 break;
9027 }
9028 }
9029
9030 if (!found) {
9031 sigma_dut_print(dut, DUT_MSG_ERROR,
9032 "no TX VRING for %s", dest_mac);
9033 goto out;
9034 }
9035
9036 /* extract VRING ID, "VRING tx_<id> = {" */
9037 if (!fgets(buf, sizeof(buf), f)) {
9038 sigma_dut_print(dut, DUT_MSG_ERROR,
9039 "no VRING start line for %s", dest_mac);
9040 goto out;
9041 }
9042
9043 rc = regexec(&re, buf, 2, m, 0);
9044 regfree(&re);
9045 if (rc || m[1].rm_so < 0) {
9046 sigma_dut_print(dut, DUT_MSG_ERROR,
9047 "no VRING TX ID for %s", dest_mac);
9048 goto out;
9049 }
9050 buf[m[1].rm_eo] = 0;
9051 vring_id = atoi(&buf[m[1].rm_so]);
9052
9053 /* send the addba command */
9054 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03009055 res = snprintf(buf, sizeof(buf), "%s/back", dir);
9056 if (res < 0 || res >= sizeof(buf))
9057 return -1;
Lior David9981b512017-01-20 13:16:40 +02009058 f = fopen(buf, "w");
9059 if (!f) {
9060 sigma_dut_print(dut, DUT_MSG_ERROR,
9061 "failed to open: %s", buf);
9062 return -1;
9063 }
9064
9065 fprintf(f, "add %d %d\n", vring_id, agg_size);
9066
9067 ret = 0;
9068
9069out:
9070 fclose(f);
9071
9072 return ret;
9073}
9074
9075
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009076int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9077 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009078{
9079 const char *val;
9080 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009081
9082 val = get_param(cmd, "TID");
9083 if (val) {
9084 tid = atoi(val);
9085 if (tid != 0) {
9086 sigma_dut_print(dut, DUT_MSG_ERROR,
9087 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
9088 tid);
9089 }
9090 }
9091
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009092 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009093 if (!val) {
9094 sigma_dut_print(dut, DUT_MSG_ERROR,
9095 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02009096 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009097 }
9098
Lior David9981b512017-01-20 13:16:40 +02009099 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009100 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009101
9102 return 1;
9103}
9104
Lior David9981b512017-01-20 13:16:40 +02009105#endif /* __linux__ */
9106
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009107
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009108static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9109 struct sigma_cmd *cmd)
9110{
9111#ifdef NL80211_SUPPORT
9112 const char *intf = get_param(cmd, "Interface");
9113 const char *val;
9114 int tid = -1;
9115 int bufsize = 64;
9116 struct nl_msg *msg;
9117 int ret = 0;
9118 struct nlattr *params;
9119 int ifindex;
9120
9121 val = get_param(cmd, "TID");
9122 if (val)
9123 tid = atoi(val);
9124
9125 if (tid == -1) {
9126 send_resp(dut, conn, SIGMA_ERROR,
9127 "ErrorCode,sta_send_addba tid invalid");
9128 return 0;
9129 }
9130
9131 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
9132
9133 ifindex = if_nametoindex(intf);
9134 if (ifindex == 0) {
9135 sigma_dut_print(dut, DUT_MSG_ERROR,
9136 "%s: Index for interface %s failed",
9137 __func__, intf);
9138 send_resp(dut, conn, SIGMA_ERROR,
9139 "ErrorCode,sta_send_addba interface invalid");
9140 return 0;
9141 }
9142
9143 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
9144 NL80211_CMD_VENDOR)) ||
9145 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
9146 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
9147 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
9148 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
9149 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
9150 nla_put_u8(msg,
9151 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
9152 QCA_WLAN_ADD_BA) ||
9153 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
9154 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07009155 nla_put_u16(msg,
9156 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
9157 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009158 sigma_dut_print(dut, DUT_MSG_ERROR,
9159 "%s: err in adding vendor_cmd and vendor_data",
9160 __func__);
9161 nlmsg_free(msg);
9162 send_resp(dut, conn, SIGMA_ERROR,
9163 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9164 return 0;
9165 }
9166 nla_nest_end(msg, params);
9167
9168 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9169 if (ret) {
9170 sigma_dut_print(dut, DUT_MSG_ERROR,
9171 "%s: err in send_and_recv_msgs, ret=%d",
9172 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309173 if (ret == -EOPNOTSUPP)
9174 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009175 send_resp(dut, conn, SIGMA_ERROR,
9176 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9177 return 0;
9178 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009179#else /* NL80211_SUPPORT */
9180 sigma_dut_print(dut, DUT_MSG_ERROR,
9181 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009182#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309183
9184 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009185}
9186
9187
Jouni Malinenf7222712019-06-13 01:50:21 +03009188static enum sigma_cmd_result cmd_sta_send_addba(struct sigma_dut *dut,
9189 struct sigma_conn *conn,
9190 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009191{
9192 switch (get_driver_type()) {
9193 case DRIVER_ATHEROS:
9194 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009195 case DRIVER_WCN:
9196 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009197#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009198 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009199 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009200#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009201 default:
9202 /*
9203 * There is no driver specific implementation for other drivers.
9204 * Ignore the command and report COMPLETE since the following
9205 * throughput test operation will end up sending ADDBA anyway.
9206 */
9207 return 1;
9208 }
9209}
9210
9211
9212int inject_eth_frame(int s, const void *data, size_t len,
9213 unsigned short ethtype, char *dst, char *src)
9214{
9215 struct iovec iov[4] = {
9216 {
9217 .iov_base = dst,
9218 .iov_len = ETH_ALEN,
9219 },
9220 {
9221 .iov_base = src,
9222 .iov_len = ETH_ALEN,
9223 },
9224 {
9225 .iov_base = &ethtype,
9226 .iov_len = sizeof(unsigned short),
9227 },
9228 {
9229 .iov_base = (void *) data,
9230 .iov_len = len,
9231 }
9232 };
9233 struct msghdr msg = {
9234 .msg_name = NULL,
9235 .msg_namelen = 0,
9236 .msg_iov = iov,
9237 .msg_iovlen = 4,
9238 .msg_control = NULL,
9239 .msg_controllen = 0,
9240 .msg_flags = 0,
9241 };
9242
9243 return sendmsg(s, &msg, 0);
9244}
9245
9246#if defined(__linux__) || defined(__QNXNTO__)
9247
9248int inject_frame(int s, const void *data, size_t len, int encrypt)
9249{
9250#define IEEE80211_RADIOTAP_F_WEP 0x04
9251#define IEEE80211_RADIOTAP_F_FRAG 0x08
9252 unsigned char rtap_hdr[] = {
9253 0x00, 0x00, /* radiotap version */
9254 0x0e, 0x00, /* radiotap length */
9255 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9256 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9257 0x00, /* padding */
9258 0x00, 0x00, /* RX and TX flags to indicate that */
9259 0x00, 0x00, /* this is the injected frame directly */
9260 };
9261 struct iovec iov[2] = {
9262 {
9263 .iov_base = &rtap_hdr,
9264 .iov_len = sizeof(rtap_hdr),
9265 },
9266 {
9267 .iov_base = (void *) data,
9268 .iov_len = len,
9269 }
9270 };
9271 struct msghdr msg = {
9272 .msg_name = NULL,
9273 .msg_namelen = 0,
9274 .msg_iov = iov,
9275 .msg_iovlen = 2,
9276 .msg_control = NULL,
9277 .msg_controllen = 0,
9278 .msg_flags = 0,
9279 };
9280
9281 if (encrypt)
9282 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9283
9284 return sendmsg(s, &msg, 0);
9285}
9286
9287
9288int open_monitor(const char *ifname)
9289{
9290#ifdef __QNXNTO__
9291 struct sockaddr_dl ll;
9292 int s;
9293
9294 memset(&ll, 0, sizeof(ll));
9295 ll.sdl_family = AF_LINK;
9296 ll.sdl_index = if_nametoindex(ifname);
9297 if (ll.sdl_index == 0) {
9298 perror("if_nametoindex");
9299 return -1;
9300 }
9301 s = socket(PF_INET, SOCK_RAW, 0);
9302#else /* __QNXNTO__ */
9303 struct sockaddr_ll ll;
9304 int s;
9305
9306 memset(&ll, 0, sizeof(ll));
9307 ll.sll_family = AF_PACKET;
9308 ll.sll_ifindex = if_nametoindex(ifname);
9309 if (ll.sll_ifindex == 0) {
9310 perror("if_nametoindex");
9311 return -1;
9312 }
9313 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9314#endif /* __QNXNTO__ */
9315 if (s < 0) {
9316 perror("socket[PF_PACKET,SOCK_RAW]");
9317 return -1;
9318 }
9319
9320 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9321 perror("monitor socket bind");
9322 close(s);
9323 return -1;
9324 }
9325
9326 return s;
9327}
9328
9329
9330static int hex2num(char c)
9331{
9332 if (c >= '0' && c <= '9')
9333 return c - '0';
9334 if (c >= 'a' && c <= 'f')
9335 return c - 'a' + 10;
9336 if (c >= 'A' && c <= 'F')
9337 return c - 'A' + 10;
9338 return -1;
9339}
9340
9341
9342int hwaddr_aton(const char *txt, unsigned char *addr)
9343{
9344 int i;
9345
9346 for (i = 0; i < 6; i++) {
9347 int a, b;
9348
9349 a = hex2num(*txt++);
9350 if (a < 0)
9351 return -1;
9352 b = hex2num(*txt++);
9353 if (b < 0)
9354 return -1;
9355 *addr++ = (a << 4) | b;
9356 if (i < 5 && *txt++ != ':')
9357 return -1;
9358 }
9359
9360 return 0;
9361}
9362
9363#endif /* defined(__linux__) || defined(__QNXNTO__) */
9364
9365enum send_frame_type {
9366 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9367};
9368enum send_frame_protection {
9369 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9370};
9371
9372
9373static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9374 enum send_frame_type frame,
9375 enum send_frame_protection protected,
9376 const char *dest)
9377{
9378#ifdef __linux__
9379 unsigned char buf[1000], *pos;
9380 int s, res;
9381 char bssid[20], addr[20];
9382 char result[32], ssid[100];
9383 size_t ssid_len;
9384
9385 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
9386 sizeof(result)) < 0 ||
9387 strncmp(result, "COMPLETED", 9) != 0) {
9388 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9389 return 0;
9390 }
9391
9392 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
9393 < 0) {
9394 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9395 "current BSSID");
9396 return 0;
9397 }
9398
9399 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
9400 < 0) {
9401 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9402 "own MAC address");
9403 return 0;
9404 }
9405
9406 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
9407 < 0) {
9408 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9409 "current SSID");
9410 return 0;
9411 }
9412 ssid_len = strlen(ssid);
9413
9414 pos = buf;
9415
9416 /* Frame Control */
9417 switch (frame) {
9418 case DISASSOC:
9419 *pos++ = 0xa0;
9420 break;
9421 case DEAUTH:
9422 *pos++ = 0xc0;
9423 break;
9424 case SAQUERY:
9425 *pos++ = 0xd0;
9426 break;
9427 case AUTH:
9428 *pos++ = 0xb0;
9429 break;
9430 case ASSOCREQ:
9431 *pos++ = 0x00;
9432 break;
9433 case REASSOCREQ:
9434 *pos++ = 0x20;
9435 break;
9436 case DLS_REQ:
9437 *pos++ = 0xd0;
9438 break;
9439 }
9440
9441 if (protected == INCORRECT_KEY)
9442 *pos++ = 0x40; /* Set Protected field to 1 */
9443 else
9444 *pos++ = 0x00;
9445
9446 /* Duration */
9447 *pos++ = 0x00;
9448 *pos++ = 0x00;
9449
9450 /* addr1 = DA (current AP) */
9451 hwaddr_aton(bssid, pos);
9452 pos += 6;
9453 /* addr2 = SA (own address) */
9454 hwaddr_aton(addr, pos);
9455 pos += 6;
9456 /* addr3 = BSSID (current AP) */
9457 hwaddr_aton(bssid, pos);
9458 pos += 6;
9459
9460 /* Seq# (to be filled by driver/mac80211) */
9461 *pos++ = 0x00;
9462 *pos++ = 0x00;
9463
9464 if (protected == INCORRECT_KEY) {
9465 /* CCMP parameters */
9466 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9467 pos += 8;
9468 }
9469
9470 if (protected == INCORRECT_KEY) {
9471 switch (frame) {
9472 case DEAUTH:
9473 /* Reason code (encrypted) */
9474 memcpy(pos, "\xa7\x39", 2);
9475 pos += 2;
9476 break;
9477 case DISASSOC:
9478 /* Reason code (encrypted) */
9479 memcpy(pos, "\xa7\x39", 2);
9480 pos += 2;
9481 break;
9482 case SAQUERY:
9483 /* Category|Action|TransID (encrypted) */
9484 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9485 pos += 4;
9486 break;
9487 default:
9488 return -1;
9489 }
9490
9491 /* CCMP MIC */
9492 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9493 pos += 8;
9494 } else {
9495 switch (frame) {
9496 case DEAUTH:
9497 /* reason code = 8 */
9498 *pos++ = 0x08;
9499 *pos++ = 0x00;
9500 break;
9501 case DISASSOC:
9502 /* reason code = 8 */
9503 *pos++ = 0x08;
9504 *pos++ = 0x00;
9505 break;
9506 case SAQUERY:
9507 /* Category - SA Query */
9508 *pos++ = 0x08;
9509 /* SA query Action - Request */
9510 *pos++ = 0x00;
9511 /* Transaction ID */
9512 *pos++ = 0x12;
9513 *pos++ = 0x34;
9514 break;
9515 case AUTH:
9516 /* Auth Alg (Open) */
9517 *pos++ = 0x00;
9518 *pos++ = 0x00;
9519 /* Seq# */
9520 *pos++ = 0x01;
9521 *pos++ = 0x00;
9522 /* Status code */
9523 *pos++ = 0x00;
9524 *pos++ = 0x00;
9525 break;
9526 case ASSOCREQ:
9527 /* Capability Information */
9528 *pos++ = 0x31;
9529 *pos++ = 0x04;
9530 /* Listen Interval */
9531 *pos++ = 0x0a;
9532 *pos++ = 0x00;
9533 /* SSID */
9534 *pos++ = 0x00;
9535 *pos++ = ssid_len;
9536 memcpy(pos, ssid, ssid_len);
9537 pos += ssid_len;
9538 /* Supported Rates */
9539 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9540 10);
9541 pos += 10;
9542 /* Extended Supported Rates */
9543 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9544 pos += 6;
9545 /* RSN */
9546 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9547 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9548 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9549 pos += 28;
9550 break;
9551 case REASSOCREQ:
9552 /* Capability Information */
9553 *pos++ = 0x31;
9554 *pos++ = 0x04;
9555 /* Listen Interval */
9556 *pos++ = 0x0a;
9557 *pos++ = 0x00;
9558 /* Current AP */
9559 hwaddr_aton(bssid, pos);
9560 pos += 6;
9561 /* SSID */
9562 *pos++ = 0x00;
9563 *pos++ = ssid_len;
9564 memcpy(pos, ssid, ssid_len);
9565 pos += ssid_len;
9566 /* Supported Rates */
9567 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9568 10);
9569 pos += 10;
9570 /* Extended Supported Rates */
9571 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9572 pos += 6;
9573 /* RSN */
9574 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9575 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9576 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9577 pos += 28;
9578 break;
9579 case DLS_REQ:
9580 /* Category - DLS */
9581 *pos++ = 0x02;
9582 /* DLS Action - Request */
9583 *pos++ = 0x00;
9584 /* Destination MACAddress */
9585 if (dest)
9586 hwaddr_aton(dest, pos);
9587 else
9588 memset(pos, 0, 6);
9589 pos += 6;
9590 /* Source MACAddress */
9591 hwaddr_aton(addr, pos);
9592 pos += 6;
9593 /* Capability Information */
9594 *pos++ = 0x10; /* Privacy */
9595 *pos++ = 0x06; /* QoS */
9596 /* DLS Timeout Value */
9597 *pos++ = 0x00;
9598 *pos++ = 0x01;
9599 /* Supported rates */
9600 *pos++ = 0x01;
9601 *pos++ = 0x08;
9602 *pos++ = 0x0c; /* 6 Mbps */
9603 *pos++ = 0x12; /* 9 Mbps */
9604 *pos++ = 0x18; /* 12 Mbps */
9605 *pos++ = 0x24; /* 18 Mbps */
9606 *pos++ = 0x30; /* 24 Mbps */
9607 *pos++ = 0x48; /* 36 Mbps */
9608 *pos++ = 0x60; /* 48 Mbps */
9609 *pos++ = 0x6c; /* 54 Mbps */
9610 /* TODO: Extended Supported Rates */
9611 /* TODO: HT Capabilities */
9612 break;
9613 }
9614 }
9615
9616 s = open_monitor("sigmadut");
9617 if (s < 0) {
9618 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9619 "monitor socket");
9620 return 0;
9621 }
9622
9623 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9624 if (res < 0) {
9625 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9626 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309627 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009628 return 0;
9629 }
9630 if (res < pos - buf) {
9631 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9632 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309633 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009634 return 0;
9635 }
9636
9637 close(s);
9638
9639 return 1;
9640#else /* __linux__ */
9641 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9642 "yet supported");
9643 return 0;
9644#endif /* __linux__ */
9645}
9646
9647
9648static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9649 struct sigma_conn *conn,
9650 struct sigma_cmd *cmd)
9651{
9652 const char *intf = get_param(cmd, "Interface");
9653 const char *sta, *val;
9654 unsigned char addr[ETH_ALEN];
9655 char buf[100];
9656
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009657 if (!intf)
9658 return -1;
9659
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009660 sta = get_param(cmd, "peer");
9661 if (sta == NULL)
9662 sta = get_param(cmd, "station");
9663 if (sta == NULL) {
9664 send_resp(dut, conn, SIGMA_ERROR,
9665 "ErrorCode,Missing peer address");
9666 return 0;
9667 }
9668 if (hwaddr_aton(sta, addr) < 0) {
9669 send_resp(dut, conn, SIGMA_ERROR,
9670 "ErrorCode,Invalid peer address");
9671 return 0;
9672 }
9673
9674 val = get_param(cmd, "type");
9675 if (val == NULL)
9676 return -1;
9677
9678 if (strcasecmp(val, "DISCOVERY") == 0) {
9679 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9680 if (wpa_command(intf, buf) < 0) {
9681 send_resp(dut, conn, SIGMA_ERROR,
9682 "ErrorCode,Failed to send TDLS discovery");
9683 return 0;
9684 }
9685 return 1;
9686 }
9687
9688 if (strcasecmp(val, "SETUP") == 0) {
9689 int status = 0, timeout = 0;
9690
9691 val = get_param(cmd, "Status");
9692 if (val)
9693 status = atoi(val);
9694
9695 val = get_param(cmd, "Timeout");
9696 if (val)
9697 timeout = atoi(val);
9698
9699 if (status != 0 && status != 37) {
9700 send_resp(dut, conn, SIGMA_ERROR,
9701 "ErrorCode,Unsupported status value");
9702 return 0;
9703 }
9704
9705 if (timeout != 0 && timeout != 301) {
9706 send_resp(dut, conn, SIGMA_ERROR,
9707 "ErrorCode,Unsupported timeout value");
9708 return 0;
9709 }
9710
9711 if (status && timeout) {
9712 send_resp(dut, conn, SIGMA_ERROR,
9713 "ErrorCode,Unsupported timeout+status "
9714 "combination");
9715 return 0;
9716 }
9717
9718 if (status == 37 &&
9719 wpa_command(intf, "SET tdls_testing 0x200")) {
9720 send_resp(dut, conn, SIGMA_ERROR,
9721 "ErrorCode,Failed to enable "
9722 "decline setup response test mode");
9723 return 0;
9724 }
9725
9726 if (timeout == 301) {
9727 int res;
9728 if (dut->no_tpk_expiration)
9729 res = wpa_command(intf,
9730 "SET tdls_testing 0x108");
9731 else
9732 res = wpa_command(intf,
9733 "SET tdls_testing 0x8");
9734 if (res) {
9735 send_resp(dut, conn, SIGMA_ERROR,
9736 "ErrorCode,Failed to set short TPK "
9737 "lifetime");
9738 return 0;
9739 }
9740 }
9741
9742 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9743 if (wpa_command(intf, buf) < 0) {
9744 send_resp(dut, conn, SIGMA_ERROR,
9745 "ErrorCode,Failed to send TDLS setup");
9746 return 0;
9747 }
9748 return 1;
9749 }
9750
9751 if (strcasecmp(val, "TEARDOWN") == 0) {
9752 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9753 if (wpa_command(intf, buf) < 0) {
9754 send_resp(dut, conn, SIGMA_ERROR,
9755 "ErrorCode,Failed to send TDLS teardown");
9756 return 0;
9757 }
9758 return 1;
9759 }
9760
9761 send_resp(dut, conn, SIGMA_ERROR,
9762 "ErrorCode,Unsupported TDLS frame");
9763 return 0;
9764}
9765
9766
9767static int sta_ap_known(const char *ifname, const char *bssid)
9768{
9769 char buf[4096];
9770
Jouni Malinendd32f192018-09-15 02:55:19 +03009771 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009772 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9773 return 0;
9774 if (strncmp(buf, "id=", 3) != 0)
9775 return 0;
9776 return 1;
9777}
9778
9779
9780static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9781 const char *bssid)
9782{
9783 int res;
9784 struct wpa_ctrl *ctrl;
9785 char buf[256];
9786
9787 if (sta_ap_known(ifname, bssid))
9788 return 0;
9789 sigma_dut_print(dut, DUT_MSG_DEBUG,
9790 "AP not in BSS table - start scan");
9791
9792 ctrl = open_wpa_mon(ifname);
9793 if (ctrl == NULL) {
9794 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9795 "wpa_supplicant monitor connection");
9796 return -1;
9797 }
9798
9799 if (wpa_command(ifname, "SCAN") < 0) {
9800 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9801 wpa_ctrl_detach(ctrl);
9802 wpa_ctrl_close(ctrl);
9803 return -1;
9804 }
9805
9806 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9807 buf, sizeof(buf));
9808
9809 wpa_ctrl_detach(ctrl);
9810 wpa_ctrl_close(ctrl);
9811
9812 if (res < 0) {
9813 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9814 return -1;
9815 }
9816
9817 if (sta_ap_known(ifname, bssid))
9818 return 0;
9819 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9820 return -1;
9821}
9822
9823
9824static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9825 struct sigma_conn *conn,
9826 struct sigma_cmd *cmd,
9827 const char *intf)
9828{
9829 char buf[200];
9830
9831 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9832 if (system(buf) != 0) {
9833 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9834 "ndsend");
9835 return 0;
9836 }
9837
9838 return 1;
9839}
9840
9841
9842static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9843 struct sigma_conn *conn,
9844 struct sigma_cmd *cmd,
9845 const char *intf)
9846{
9847 char buf[200];
9848 const char *ip = get_param(cmd, "SenderIP");
9849
Peng Xu26b356d2017-10-04 17:58:16 -07009850 if (!ip)
9851 return 0;
9852
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009853 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9854 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9855 if (system(buf) == 0) {
9856 sigma_dut_print(dut, DUT_MSG_INFO,
9857 "Neighbor Solicitation got a response "
9858 "for %s@%s", ip, intf);
9859 }
9860
9861 return 1;
9862}
9863
9864
9865static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9866 struct sigma_conn *conn,
9867 struct sigma_cmd *cmd,
9868 const char *ifname)
9869{
9870 char buf[200];
9871 const char *ip = get_param(cmd, "SenderIP");
9872
9873 if (ip == NULL) {
9874 send_resp(dut, conn, SIGMA_ERROR,
9875 "ErrorCode,Missing SenderIP parameter");
9876 return 0;
9877 }
9878 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9879 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9880 if (system(buf) != 0) {
9881 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9882 "for %s@%s", ip, ifname);
9883 }
9884
9885 return 1;
9886}
9887
9888
9889static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9890 struct sigma_conn *conn,
9891 struct sigma_cmd *cmd,
9892 const char *ifname)
9893{
9894 char buf[200];
9895 char ip[16];
9896 int s;
Peng Xub3756882017-10-04 14:39:09 -07009897 struct ifreq ifr;
9898 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009899
9900 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009901 if (s < 0) {
9902 perror("socket");
9903 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009904 }
9905
Peng Xub3756882017-10-04 14:39:09 -07009906 memset(&ifr, 0, sizeof(ifr));
9907 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9908 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9909 sigma_dut_print(dut, DUT_MSG_INFO,
9910 "Failed to get %s IP address: %s",
9911 ifname, strerror(errno));
9912 close(s);
9913 return -1;
9914 }
9915 close(s);
9916
9917 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9918 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9919
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009920 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9921 ip);
9922 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9923 if (system(buf) != 0) {
9924 }
9925
9926 return 1;
9927}
9928
9929
9930static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9931 struct sigma_conn *conn,
9932 struct sigma_cmd *cmd,
9933 const char *ifname)
9934{
9935 char buf[200], addr[20];
9936 char dst[ETH_ALEN], src[ETH_ALEN];
9937 short ethtype = htons(ETH_P_ARP);
9938 char *pos;
9939 int s, res;
9940 const char *val;
9941 struct sockaddr_in taddr;
9942
9943 val = get_param(cmd, "dest");
9944 if (val)
9945 hwaddr_aton(val, (unsigned char *) dst);
9946
9947 val = get_param(cmd, "DestIP");
9948 if (val)
9949 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009950 else
9951 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009952
9953 if (get_wpa_status(get_station_ifname(), "address", addr,
9954 sizeof(addr)) < 0)
9955 return -2;
9956 hwaddr_aton(addr, (unsigned char *) src);
9957
9958 pos = buf;
9959 *pos++ = 0x00;
9960 *pos++ = 0x01;
9961 *pos++ = 0x08;
9962 *pos++ = 0x00;
9963 *pos++ = 0x06;
9964 *pos++ = 0x04;
9965 *pos++ = 0x00;
9966 *pos++ = 0x02;
9967 memcpy(pos, src, ETH_ALEN);
9968 pos += ETH_ALEN;
9969 memcpy(pos, &taddr.sin_addr, 4);
9970 pos += 4;
9971 memcpy(pos, dst, ETH_ALEN);
9972 pos += ETH_ALEN;
9973 memcpy(pos, &taddr.sin_addr, 4);
9974 pos += 4;
9975
9976 s = open_monitor(get_station_ifname());
9977 if (s < 0) {
9978 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9979 "monitor socket");
9980 return 0;
9981 }
9982
9983 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
9984 if (res < 0) {
9985 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9986 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309987 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009988 return 0;
9989 }
9990
9991 close(s);
9992
9993 return 1;
9994}
9995
9996
9997static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
9998 struct sigma_conn *conn,
9999 struct sigma_cmd *cmd,
10000 const char *intf, const char *dest)
10001{
10002 char buf[100];
10003
10004 if (if_nametoindex("sigmadut") == 0) {
10005 snprintf(buf, sizeof(buf),
10006 "iw dev %s interface add sigmadut type monitor",
10007 get_station_ifname());
10008 if (system(buf) != 0 ||
10009 if_nametoindex("sigmadut") == 0) {
10010 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10011 "monitor interface with '%s'", buf);
10012 return -2;
10013 }
10014 }
10015
10016 if (system("ifconfig sigmadut up") != 0) {
10017 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10018 "monitor interface up");
10019 return -2;
10020 }
10021
10022 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
10023}
10024
10025
10026static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
10027 struct sigma_conn *conn,
10028 struct sigma_cmd *cmd)
10029{
10030 const char *intf = get_param(cmd, "Interface");
10031 const char *dest = get_param(cmd, "Dest");
10032 const char *type = get_param(cmd, "FrameName");
10033 const char *val;
10034 char buf[200], *pos, *end;
10035 int count, count2;
10036
10037 if (type == NULL)
10038 type = get_param(cmd, "Type");
10039
10040 if (intf == NULL || dest == NULL || type == NULL)
10041 return -1;
10042
10043 if (strcasecmp(type, "NeighAdv") == 0)
10044 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
10045
10046 if (strcasecmp(type, "NeighSolicitReq") == 0)
10047 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
10048
10049 if (strcasecmp(type, "ARPProbe") == 0)
10050 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
10051
10052 if (strcasecmp(type, "ARPAnnounce") == 0)
10053 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
10054
10055 if (strcasecmp(type, "ARPReply") == 0)
10056 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
10057
10058 if (strcasecmp(type, "DLS-request") == 0 ||
10059 strcasecmp(type, "DLSrequest") == 0)
10060 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
10061 dest);
10062
10063 if (strcasecmp(type, "ANQPQuery") != 0 &&
10064 strcasecmp(type, "Query") != 0) {
10065 send_resp(dut, conn, SIGMA_ERROR,
10066 "ErrorCode,Unsupported HS 2.0 send frame type");
10067 return 0;
10068 }
10069
10070 if (sta_scan_ap(dut, intf, dest) < 0) {
10071 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
10072 "the requested AP");
10073 return 0;
10074 }
10075
10076 pos = buf;
10077 end = buf + sizeof(buf);
10078 count = 0;
10079 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
10080
10081 val = get_param(cmd, "ANQP_CAP_LIST");
10082 if (val && atoi(val)) {
10083 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
10084 count++;
10085 }
10086
10087 val = get_param(cmd, "VENUE_NAME");
10088 if (val && atoi(val)) {
10089 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
10090 count++;
10091 }
10092
10093 val = get_param(cmd, "NETWORK_AUTH_TYPE");
10094 if (val && atoi(val)) {
10095 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
10096 count++;
10097 }
10098
10099 val = get_param(cmd, "ROAMING_CONS");
10100 if (val && atoi(val)) {
10101 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
10102 count++;
10103 }
10104
10105 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
10106 if (val && atoi(val)) {
10107 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
10108 count++;
10109 }
10110
10111 val = get_param(cmd, "NAI_REALM_LIST");
10112 if (val && atoi(val)) {
10113 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
10114 count++;
10115 }
10116
10117 val = get_param(cmd, "3GPP_INFO");
10118 if (val && atoi(val)) {
10119 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
10120 count++;
10121 }
10122
10123 val = get_param(cmd, "DOMAIN_LIST");
10124 if (val && atoi(val)) {
10125 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
10126 count++;
10127 }
10128
Jouni Malinen34cf9532018-04-29 19:26:33 +030010129 val = get_param(cmd, "Venue_URL");
10130 if (val && atoi(val)) {
10131 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
10132 count++;
10133 }
10134
Jouni Malinend3bca5d2018-04-29 17:25:23 +030010135 val = get_param(cmd, "Advice_Of_Charge");
10136 if (val && atoi(val)) {
10137 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
10138 count++;
10139 }
10140
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010141 if (count && wpa_command(intf, buf)) {
10142 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
10143 return 0;
10144 }
10145
10146 pos = buf;
10147 end = buf + sizeof(buf);
10148 count2 = 0;
10149 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
10150
10151 val = get_param(cmd, "HS_CAP_LIST");
10152 if (val && atoi(val)) {
10153 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
10154 count2++;
10155 }
10156
10157 val = get_param(cmd, "OPER_NAME");
10158 if (val && atoi(val)) {
10159 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
10160 count2++;
10161 }
10162
10163 val = get_param(cmd, "WAN_METRICS");
10164 if (!val)
10165 val = get_param(cmd, "WAN_MAT");
10166 if (!val)
10167 val = get_param(cmd, "WAN_MET");
10168 if (val && atoi(val)) {
10169 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10170 count2++;
10171 }
10172
10173 val = get_param(cmd, "CONNECTION_CAPABILITY");
10174 if (val && atoi(val)) {
10175 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10176 count2++;
10177 }
10178
10179 val = get_param(cmd, "OP_CLASS");
10180 if (val && atoi(val)) {
10181 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10182 count2++;
10183 }
10184
10185 val = get_param(cmd, "OSU_PROVIDER_LIST");
10186 if (val && atoi(val)) {
10187 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10188 count2++;
10189 }
10190
Jouni Malinenf67afec2018-04-29 19:24:58 +030010191 val = get_param(cmd, "OPER_ICON_METADATA");
10192 if (!val)
10193 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10194 if (val && atoi(val)) {
10195 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10196 count2++;
10197 }
10198
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010199 if (count && count2) {
10200 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10201 "second query");
10202 sleep(1);
10203 }
10204
10205 if (count2 && wpa_command(intf, buf)) {
10206 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10207 "failed");
10208 return 0;
10209 }
10210
10211 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10212 if (val) {
10213 if (count || count2) {
10214 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10215 "sending out second query");
10216 sleep(1);
10217 }
10218
10219 if (strcmp(val, "1") == 0)
10220 val = "mail.example.com";
10221 snprintf(buf, end - pos,
10222 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10223 dest, val);
10224 if (wpa_command(intf, buf)) {
10225 send_resp(dut, conn, SIGMA_ERROR,
10226 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10227 "failed");
10228 return 0;
10229 }
10230 }
10231
10232 val = get_param(cmd, "ICON_REQUEST");
10233 if (val) {
10234 if (count || count2) {
10235 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10236 "sending out second query");
10237 sleep(1);
10238 }
10239
10240 snprintf(buf, end - pos,
10241 "HS20_ICON_REQUEST %s %s", dest, val);
10242 if (wpa_command(intf, buf)) {
10243 send_resp(dut, conn, SIGMA_ERROR,
10244 "ErrorCode,HS20_ICON_REQUEST failed");
10245 return 0;
10246 }
10247 }
10248
10249 return 1;
10250}
10251
10252
10253static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10254 struct sigma_conn *conn,
10255 struct sigma_cmd *cmd)
10256{
10257 const char *val;
10258 char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010259 int chwidth, nss;
10260
10261 val = get_param(cmd, "framename");
10262 if (!val)
10263 return -1;
10264 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10265
10266 /* Command sequence to generate Op mode notification */
10267 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
10268 ifname = get_station_ifname();
10269
10270 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010271 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010272
10273 /* Extract Channel width */
10274 val = get_param(cmd, "Channel_width");
10275 if (val) {
10276 switch (atoi(val)) {
10277 case 20:
10278 chwidth = 0;
10279 break;
10280 case 40:
10281 chwidth = 1;
10282 break;
10283 case 80:
10284 chwidth = 2;
10285 break;
10286 case 160:
10287 chwidth = 3;
10288 break;
10289 default:
10290 chwidth = 2;
10291 break;
10292 }
10293
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010294 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010295 }
10296
10297 /* Extract NSS */
10298 val = get_param(cmd, "NSS");
10299 if (val) {
10300 switch (atoi(val)) {
10301 case 1:
10302 nss = 1;
10303 break;
10304 case 2:
10305 nss = 3;
10306 break;
10307 case 3:
10308 nss = 7;
10309 break;
10310 default:
10311 /* We do not support NSS > 3 */
10312 nss = 3;
10313 break;
10314 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010315 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010316 }
10317
10318 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010319 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010320 }
10321
10322 return 1;
10323}
10324
10325
10326static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10327 struct sigma_conn *conn,
10328 struct sigma_cmd *cmd)
10329{
10330 switch (get_driver_type()) {
10331 case DRIVER_ATHEROS:
10332 return ath_sta_send_frame_vht(dut, conn, cmd);
10333 default:
10334 send_resp(dut, conn, SIGMA_ERROR,
10335 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10336 return 0;
10337 }
10338}
10339
10340
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010341static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10342 struct sigma_cmd *cmd)
10343{
10344 const char *val;
10345 const char *intf = get_param(cmd, "Interface");
10346
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010347 if (!intf)
10348 return -1;
10349
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010350 val = get_param(cmd, "framename");
10351 if (!val)
10352 return -1;
10353 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10354
10355 /* Command sequence to generate Op mode notification */
10356 if (val && strcasecmp(val, "action") == 0) {
10357 val = get_param(cmd, "PPDUTxType");
10358 if (val && strcasecmp(val, "TB") == 0) {
10359 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10360 sigma_dut_print(dut, DUT_MSG_ERROR,
10361 "failed to send TB PPDU Tx cfg");
10362 send_resp(dut, conn, SIGMA_ERROR,
10363 "ErrorCode,set TB PPDU Tx cfg failed");
10364 return 0;
10365 }
10366 return 1;
10367 }
10368
10369 sigma_dut_print(dut, DUT_MSG_ERROR,
10370 "Action Tx type is not defined");
10371 }
10372
10373 return 1;
10374}
10375
10376
10377static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10378 struct sigma_conn *conn,
10379 struct sigma_cmd *cmd)
10380{
10381 switch (get_driver_type()) {
10382 case DRIVER_WCN:
10383 return wcn_sta_send_frame_he(dut, conn, cmd);
10384 default:
10385 send_resp(dut, conn, SIGMA_ERROR,
10386 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10387 return 0;
10388 }
10389}
10390
10391
Lior David0fe101e2017-03-09 16:09:50 +020010392#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010393
10394static int
10395wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10396 const char *frame_name, const char *dest_mac)
10397{
10398 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10399 const char *ssid = get_param(cmd, "ssid");
10400 const char *countstr = get_param(cmd, "count");
10401 const char *channelstr = get_param(cmd, "channel");
10402 const char *group_id = get_param(cmd, "groupid");
10403 const char *client_id = get_param(cmd, "clientmac");
10404 int count, channel, freq, i;
10405 const char *fname;
10406 char frame[1024], src_mac[20], group_id_attr[25],
10407 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10408 const char *group_ssid;
10409 const int group_ssid_prefix_len = 9;
10410 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10411 size_t framelen = sizeof(frame);
10412 struct template_frame_tag tags[2];
10413 size_t tags_total = ARRAY_SIZE(tags);
10414 int tag_index, len, dst_len;
10415
10416 if (!countstr || !channelstr) {
10417 sigma_dut_print(dut, DUT_MSG_ERROR,
10418 "Missing argument: count, channel");
10419 return -1;
10420 }
10421 if (isprobereq && !ssid) {
10422 sigma_dut_print(dut, DUT_MSG_ERROR,
10423 "Missing argument: ssid");
10424 return -1;
10425 }
10426 if (!isprobereq && (!group_id || !client_id)) {
10427 sigma_dut_print(dut, DUT_MSG_ERROR,
10428 "Missing argument: group_id, client_id");
10429 return -1;
10430 }
10431
10432 count = atoi(countstr);
10433 channel = atoi(channelstr);
10434 freq = channel_to_freq(dut, channel);
10435
10436 if (!freq) {
10437 sigma_dut_print(dut, DUT_MSG_ERROR,
10438 "invalid channel: %s", channelstr);
10439 return -1;
10440 }
10441
10442 if (isprobereq) {
10443 if (strcasecmp(ssid, "wildcard") == 0) {
10444 fname = "probe_req_wildcard.txt";
10445 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10446 fname = "probe_req_P2P_Wildcard.txt";
10447 } else {
10448 sigma_dut_print(dut, DUT_MSG_ERROR,
10449 "invalid probe request type");
10450 return -1;
10451 }
10452 } else {
10453 fname = "P2P_device_discovery_req.txt";
10454 }
10455
10456 if (parse_template_frame_file(dut, fname, frame, &framelen,
10457 tags, &tags_total)) {
10458 sigma_dut_print(dut, DUT_MSG_ERROR,
10459 "invalid frame template: %s", fname);
10460 return -1;
10461 }
10462
10463 if (get_wpa_status(get_station_ifname(), "address",
10464 src_mac, sizeof(src_mac)) < 0 ||
10465 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10466 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10467 return -1;
10468 /* Use wildcard BSSID, since we are in PBSS */
10469 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10470
10471 if (!isprobereq) {
10472 tag_index = find_template_frame_tag(tags, tags_total, 1);
10473 if (tag_index < 0) {
10474 sigma_dut_print(dut, DUT_MSG_ERROR,
10475 "can't find device id attribute");
10476 return -1;
10477 }
10478 if (parse_mac_address(dut, client_id,
10479 (unsigned char *) client_mac)) {
10480 sigma_dut_print(dut, DUT_MSG_ERROR,
10481 "invalid client_id: %s", client_id);
10482 return -1;
10483 }
10484 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10485 framelen - tags[tag_index].offset,
10486 IEEE80211_P2P_ATTR_DEVICE_ID,
10487 client_mac, ETH_ALEN)) {
10488 sigma_dut_print(dut, DUT_MSG_ERROR,
10489 "fail to replace device id attribute");
10490 return -1;
10491 }
10492
10493 /*
10494 * group_id arg contains device MAC address followed by
10495 * space and SSID (DIRECT-somessid).
10496 * group id attribute contains device address (6 bytes)
10497 * followed by SSID prefix DIRECT-XX (9 bytes)
10498 */
10499 if (strlen(group_id) < sizeof(device_macstr)) {
10500 sigma_dut_print(dut, DUT_MSG_ERROR,
10501 "group_id arg too short");
10502 return -1;
10503 }
10504 memcpy(device_macstr, group_id, sizeof(device_macstr));
10505 device_macstr[sizeof(device_macstr) - 1] = '\0';
10506 if (parse_mac_address(dut, device_macstr,
10507 (unsigned char *) group_id_attr)) {
10508 sigma_dut_print(dut, DUT_MSG_ERROR,
10509 "fail to parse device address from group_id");
10510 return -1;
10511 }
10512 group_ssid = strchr(group_id, ' ');
10513 if (!group_ssid) {
10514 sigma_dut_print(dut, DUT_MSG_ERROR,
10515 "invalid group_id arg, no ssid");
10516 return -1;
10517 }
10518 group_ssid++;
10519 len = strlen(group_ssid);
10520 if (len < group_ssid_prefix_len) {
10521 sigma_dut_print(dut, DUT_MSG_ERROR,
10522 "group_id SSID too short");
10523 return -1;
10524 }
10525 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10526 if (len > dst_len) {
10527 sigma_dut_print(dut, DUT_MSG_ERROR,
10528 "group_id SSID (%s) too long",
10529 group_ssid);
10530 return -1;
10531 }
10532
10533 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10534 tag_index = find_template_frame_tag(tags, tags_total, 2);
10535 if (tag_index < 0) {
10536 sigma_dut_print(dut, DUT_MSG_ERROR,
10537 "can't find group id attribute");
10538 return -1;
10539 }
10540 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10541 framelen - tags[tag_index].offset,
10542 IEEE80211_P2P_ATTR_GROUP_ID,
10543 group_id_attr,
10544 sizeof(group_id_attr))) {
10545 sigma_dut_print(dut, DUT_MSG_ERROR,
10546 "fail to replace group id attribute");
10547 return -1;
10548 }
10549 }
10550
10551 for (i = 0; i < count; i++) {
10552 if (wil6210_transmit_frame(dut, freq,
10553 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10554 frame, framelen)) {
10555 sigma_dut_print(dut, DUT_MSG_ERROR,
10556 "fail to transmit probe request frame");
10557 return -1;
10558 }
10559 }
10560
10561 return 0;
10562}
10563
10564
Lior David0fe101e2017-03-09 16:09:50 +020010565int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10566 struct sigma_cmd *cmd)
10567{
10568 const char *frame_name = get_param(cmd, "framename");
10569 const char *mac = get_param(cmd, "dest_mac");
10570
10571 if (!frame_name || !mac) {
10572 sigma_dut_print(dut, DUT_MSG_ERROR,
10573 "framename and dest_mac must be provided");
10574 return -1;
10575 }
10576
10577 if (strcasecmp(frame_name, "brp") == 0) {
10578 const char *l_rx = get_param(cmd, "L-RX");
10579 int l_rx_i;
10580
10581 if (!l_rx) {
10582 sigma_dut_print(dut, DUT_MSG_ERROR,
10583 "L-RX must be provided");
10584 return -1;
10585 }
10586 l_rx_i = atoi(l_rx);
10587
10588 sigma_dut_print(dut, DUT_MSG_INFO,
10589 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10590 mac, l_rx);
10591 if (l_rx_i != 16) {
10592 sigma_dut_print(dut, DUT_MSG_ERROR,
10593 "unsupported L-RX: %s", l_rx);
10594 return -1;
10595 }
10596
10597 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10598 return -1;
10599 } else if (strcasecmp(frame_name, "ssw") == 0) {
10600 sigma_dut_print(dut, DUT_MSG_INFO,
10601 "dev_send_frame: SLS, dest_mac %s", mac);
10602 if (wil6210_send_sls(dut, mac))
10603 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010604 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10605 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10606 sigma_dut_print(dut, DUT_MSG_INFO,
10607 "dev_send_frame: %s, dest_mac %s", frame_name,
10608 mac);
10609 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10610 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010611 } else {
10612 sigma_dut_print(dut, DUT_MSG_ERROR,
10613 "unsupported frame type: %s", frame_name);
10614 return -1;
10615 }
10616
10617 return 1;
10618}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010619
Lior David0fe101e2017-03-09 16:09:50 +020010620#endif /* __linux__ */
10621
10622
10623static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10624 struct sigma_conn *conn,
10625 struct sigma_cmd *cmd)
10626{
10627 switch (get_driver_type()) {
10628#ifdef __linux__
10629 case DRIVER_WIL6210:
10630 return wil6210_send_frame_60g(dut, conn, cmd);
10631#endif /* __linux__ */
10632 default:
10633 send_resp(dut, conn, SIGMA_ERROR,
10634 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10635 return 0;
10636 }
10637}
10638
10639
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010640static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10641 const char *intf, struct sigma_cmd *cmd)
10642{
10643 const char *val, *addr;
10644 char buf[100];
10645
10646 addr = get_param(cmd, "DestMac");
10647 if (!addr) {
10648 send_resp(dut, conn, SIGMA_INVALID,
10649 "ErrorCode,AP MAC address is missing");
10650 return 0;
10651 }
10652
10653 val = get_param(cmd, "ANQPQuery_ID");
10654 if (!val) {
10655 send_resp(dut, conn, SIGMA_INVALID,
10656 "ErrorCode,Missing ANQPQuery_ID");
10657 return 0;
10658 }
10659
10660 if (strcasecmp(val, "NeighborReportReq") == 0) {
10661 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10662 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10663 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10664 } else {
10665 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10666 val);
10667 send_resp(dut, conn, SIGMA_INVALID,
10668 "ErrorCode,Invalid ANQPQuery_ID");
10669 return 0;
10670 }
10671
Ashwini Patild174f2c2017-04-13 16:49:46 +053010672 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10673 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10674 * if associated, AP BSSID).
10675 */
10676 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10677 send_resp(dut, conn, SIGMA_ERROR,
10678 "ErrorCode,Failed to set gas_address3");
10679 return 0;
10680 }
10681
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010682 if (wpa_command(intf, buf) < 0) {
10683 send_resp(dut, conn, SIGMA_ERROR,
10684 "ErrorCode,Failed to send ANQP query");
10685 return 0;
10686 }
10687
10688 return 1;
10689}
10690
10691
10692static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10693 struct sigma_conn *conn,
10694 const char *intf,
10695 struct sigma_cmd *cmd)
10696{
10697 const char *val = get_param(cmd, "FrameName");
10698
10699 if (val && strcasecmp(val, "ANQPQuery") == 0)
10700 return mbo_send_anqp_query(dut, conn, intf, cmd);
10701
10702 return 2;
10703}
10704
10705
Jouni Malinenf7222712019-06-13 01:50:21 +030010706enum sigma_cmd_result cmd_sta_send_frame(struct sigma_dut *dut,
10707 struct sigma_conn *conn,
10708 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010709{
10710 const char *intf = get_param(cmd, "Interface");
10711 const char *val;
10712 enum send_frame_type frame;
10713 enum send_frame_protection protected;
10714 char buf[100];
10715 unsigned char addr[ETH_ALEN];
10716 int res;
10717
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010718 if (!intf)
10719 return -1;
10720
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010721 val = get_param(cmd, "program");
10722 if (val == NULL)
10723 val = get_param(cmd, "frame");
10724 if (val && strcasecmp(val, "TDLS") == 0)
10725 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10726 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010727 strcasecmp(val, "HS2-R2") == 0 ||
10728 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010729 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10730 if (val && strcasecmp(val, "VHT") == 0)
10731 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010732 if (val && strcasecmp(val, "HE") == 0)
10733 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010734 if (val && strcasecmp(val, "LOC") == 0)
10735 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010736 if (val && strcasecmp(val, "60GHz") == 0)
10737 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010738 if (val && strcasecmp(val, "MBO") == 0) {
10739 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10740 if (res != 2)
10741 return res;
10742 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010743
10744 val = get_param(cmd, "TD_DISC");
10745 if (val) {
10746 if (hwaddr_aton(val, addr) < 0)
10747 return -1;
10748 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10749 if (wpa_command(intf, buf) < 0) {
10750 send_resp(dut, conn, SIGMA_ERROR,
10751 "ErrorCode,Failed to send TDLS discovery");
10752 return 0;
10753 }
10754 return 1;
10755 }
10756
10757 val = get_param(cmd, "TD_Setup");
10758 if (val) {
10759 if (hwaddr_aton(val, addr) < 0)
10760 return -1;
10761 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10762 if (wpa_command(intf, buf) < 0) {
10763 send_resp(dut, conn, SIGMA_ERROR,
10764 "ErrorCode,Failed to start TDLS setup");
10765 return 0;
10766 }
10767 return 1;
10768 }
10769
10770 val = get_param(cmd, "TD_TearDown");
10771 if (val) {
10772 if (hwaddr_aton(val, addr) < 0)
10773 return -1;
10774 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10775 if (wpa_command(intf, buf) < 0) {
10776 send_resp(dut, conn, SIGMA_ERROR,
10777 "ErrorCode,Failed to tear down TDLS link");
10778 return 0;
10779 }
10780 return 1;
10781 }
10782
10783 val = get_param(cmd, "TD_ChannelSwitch");
10784 if (val) {
10785 /* TODO */
10786 send_resp(dut, conn, SIGMA_ERROR,
10787 "ErrorCode,TD_ChannelSwitch not yet supported");
10788 return 0;
10789 }
10790
10791 val = get_param(cmd, "TD_NF");
10792 if (val) {
10793 /* TODO */
10794 send_resp(dut, conn, SIGMA_ERROR,
10795 "ErrorCode,TD_NF not yet supported");
10796 return 0;
10797 }
10798
10799 val = get_param(cmd, "PMFFrameType");
10800 if (val == NULL)
10801 val = get_param(cmd, "FrameName");
10802 if (val == NULL)
10803 val = get_param(cmd, "Type");
10804 if (val == NULL)
10805 return -1;
10806 if (strcasecmp(val, "disassoc") == 0)
10807 frame = DISASSOC;
10808 else if (strcasecmp(val, "deauth") == 0)
10809 frame = DEAUTH;
10810 else if (strcasecmp(val, "saquery") == 0)
10811 frame = SAQUERY;
10812 else if (strcasecmp(val, "auth") == 0)
10813 frame = AUTH;
10814 else if (strcasecmp(val, "assocreq") == 0)
10815 frame = ASSOCREQ;
10816 else if (strcasecmp(val, "reassocreq") == 0)
10817 frame = REASSOCREQ;
10818 else if (strcasecmp(val, "neigreq") == 0) {
10819 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10820
10821 val = get_param(cmd, "ssid");
10822 if (val == NULL)
10823 return -1;
10824
10825 res = send_neighbor_request(dut, intf, val);
10826 if (res) {
10827 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10828 "Failed to send neighbor report request");
10829 return 0;
10830 }
10831
10832 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010833 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10834 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010835 sigma_dut_print(dut, DUT_MSG_DEBUG,
10836 "Got Transition Management Query");
10837
Ashwini Patil5acd7382017-04-13 15:55:04 +053010838 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010839 if (res) {
10840 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10841 "Failed to send Transition Management Query");
10842 return 0;
10843 }
10844
10845 return 1;
10846 } else {
10847 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10848 "PMFFrameType");
10849 return 0;
10850 }
10851
10852 val = get_param(cmd, "PMFProtected");
10853 if (val == NULL)
10854 val = get_param(cmd, "Protected");
10855 if (val == NULL)
10856 return -1;
10857 if (strcasecmp(val, "Correct-key") == 0 ||
10858 strcasecmp(val, "CorrectKey") == 0)
10859 protected = CORRECT_KEY;
10860 else if (strcasecmp(val, "IncorrectKey") == 0)
10861 protected = INCORRECT_KEY;
10862 else if (strcasecmp(val, "Unprotected") == 0)
10863 protected = UNPROTECTED;
10864 else {
10865 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10866 "PMFProtected");
10867 return 0;
10868 }
10869
10870 if (protected != UNPROTECTED &&
10871 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10872 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10873 "PMFProtected for auth/assocreq/reassocreq");
10874 return 0;
10875 }
10876
10877 if (if_nametoindex("sigmadut") == 0) {
10878 snprintf(buf, sizeof(buf),
10879 "iw dev %s interface add sigmadut type monitor",
10880 get_station_ifname());
10881 if (system(buf) != 0 ||
10882 if_nametoindex("sigmadut") == 0) {
10883 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10884 "monitor interface with '%s'", buf);
10885 return -2;
10886 }
10887 }
10888
10889 if (system("ifconfig sigmadut up") != 0) {
10890 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10891 "monitor interface up");
10892 return -2;
10893 }
10894
10895 return sta_inject_frame(dut, conn, frame, protected, NULL);
10896}
10897
10898
10899static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10900 struct sigma_conn *conn,
10901 struct sigma_cmd *cmd,
10902 const char *ifname)
10903{
10904 char buf[200];
10905 const char *val;
10906
10907 val = get_param(cmd, "ClearARP");
10908 if (val && atoi(val) == 1) {
10909 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10910 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10911 if (system(buf) != 0) {
10912 send_resp(dut, conn, SIGMA_ERROR,
10913 "errorCode,Failed to clear ARP cache");
10914 return 0;
10915 }
10916 }
10917
10918 return 1;
10919}
10920
10921
10922int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10923 struct sigma_cmd *cmd)
10924{
10925 const char *intf = get_param(cmd, "Interface");
10926 const char *val;
10927
10928 if (intf == NULL)
10929 return -1;
10930
10931 val = get_param(cmd, "program");
10932 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010933 strcasecmp(val, "HS2-R2") == 0 ||
10934 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010935 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10936
10937 return -1;
10938}
10939
10940
Jouni Malinenf7222712019-06-13 01:50:21 +030010941static enum sigma_cmd_result cmd_sta_set_macaddr(struct sigma_dut *dut,
10942 struct sigma_conn *conn,
10943 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010944{
10945 const char *intf = get_param(cmd, "Interface");
10946 const char *mac = get_param(cmd, "MAC");
10947
10948 if (intf == NULL || mac == NULL)
10949 return -1;
10950
10951 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10952 "interface %s to %s", intf, mac);
10953
10954 if (dut->set_macaddr) {
10955 char buf[128];
10956 int res;
10957 if (strcasecmp(mac, "default") == 0) {
10958 res = snprintf(buf, sizeof(buf), "%s",
10959 dut->set_macaddr);
10960 dut->tmp_mac_addr = 0;
10961 } else {
10962 res = snprintf(buf, sizeof(buf), "%s %s",
10963 dut->set_macaddr, mac);
10964 dut->tmp_mac_addr = 1;
10965 }
10966 if (res < 0 || res >= (int) sizeof(buf))
10967 return -1;
10968 if (system(buf) != 0) {
10969 send_resp(dut, conn, SIGMA_ERROR,
10970 "errorCode,Failed to set MAC "
10971 "address");
10972 return 0;
10973 }
10974 return 1;
10975 }
10976
10977 if (strcasecmp(mac, "default") == 0)
10978 return 1;
10979
10980 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10981 "command");
10982 return 0;
10983}
10984
10985
10986static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
10987 struct sigma_conn *conn, const char *intf,
10988 int val)
10989{
10990 char buf[200];
10991 int res;
10992
10993 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
10994 intf, val);
10995 if (res < 0 || res >= (int) sizeof(buf))
10996 return -1;
10997 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10998 if (system(buf) != 0) {
10999 send_resp(dut, conn, SIGMA_ERROR,
11000 "errorCode,Failed to configure offchannel mode");
11001 return 0;
11002 }
11003
11004 return 1;
11005}
11006
11007
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011008static int off_chan_val(enum sec_ch_offset off)
11009{
11010 switch (off) {
11011 case SEC_CH_NO:
11012 return 0;
11013 case SEC_CH_40ABOVE:
11014 return 40;
11015 case SEC_CH_40BELOW:
11016 return -40;
11017 }
11018
11019 return 0;
11020}
11021
11022
11023static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
11024 const char *intf, int off_ch_num,
11025 enum sec_ch_offset sec)
11026{
11027 char buf[200];
11028 int res;
11029
11030 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
11031 intf, off_ch_num);
11032 if (res < 0 || res >= (int) sizeof(buf))
11033 return -1;
11034 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11035 if (system(buf) != 0) {
11036 send_resp(dut, conn, SIGMA_ERROR,
11037 "errorCode,Failed to set offchan");
11038 return 0;
11039 }
11040
11041 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
11042 intf, off_chan_val(sec));
11043 if (res < 0 || res >= (int) sizeof(buf))
11044 return -1;
11045 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11046 if (system(buf) != 0) {
11047 send_resp(dut, conn, SIGMA_ERROR,
11048 "errorCode,Failed to set sec chan offset");
11049 return 0;
11050 }
11051
11052 return 1;
11053}
11054
11055
11056static int tdls_set_offchannel_offset(struct sigma_dut *dut,
11057 struct sigma_conn *conn,
11058 const char *intf, int off_ch_num,
11059 enum sec_ch_offset sec)
11060{
11061 char buf[200];
11062 int res;
11063
11064 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
11065 off_ch_num);
11066 if (res < 0 || res >= (int) sizeof(buf))
11067 return -1;
11068 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11069
11070 if (wpa_command(intf, buf) < 0) {
11071 send_resp(dut, conn, SIGMA_ERROR,
11072 "ErrorCode,Failed to set offchan");
11073 return 0;
11074 }
11075 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
11076 off_chan_val(sec));
11077 if (res < 0 || res >= (int) sizeof(buf))
11078 return -1;
11079
11080 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11081
11082 if (wpa_command(intf, buf) < 0) {
11083 send_resp(dut, conn, SIGMA_ERROR,
11084 "ErrorCode,Failed to set sec chan offset");
11085 return 0;
11086 }
11087
11088 return 1;
11089}
11090
11091
11092static int tdls_set_offchannel_mode(struct sigma_dut *dut,
11093 struct sigma_conn *conn,
11094 const char *intf, int val)
11095{
11096 char buf[200];
11097 int res;
11098
11099 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
11100 val);
11101 if (res < 0 || res >= (int) sizeof(buf))
11102 return -1;
11103 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
11104
11105 if (wpa_command(intf, buf) < 0) {
11106 send_resp(dut, conn, SIGMA_ERROR,
11107 "ErrorCode,Failed to configure offchannel mode");
11108 return 0;
11109 }
11110
11111 return 1;
11112}
11113
11114
11115static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
11116 struct sigma_conn *conn,
11117 struct sigma_cmd *cmd)
11118{
11119 const char *val;
11120 enum {
11121 CHSM_NOT_SET,
11122 CHSM_ENABLE,
11123 CHSM_DISABLE,
11124 CHSM_REJREQ,
11125 CHSM_UNSOLRESP
11126 } chsm = CHSM_NOT_SET;
11127 int off_ch_num = -1;
11128 enum sec_ch_offset sec_ch = SEC_CH_NO;
11129 int res;
11130
11131 val = get_param(cmd, "Uapsd");
11132 if (val) {
11133 char buf[100];
11134 if (strcasecmp(val, "Enable") == 0)
11135 snprintf(buf, sizeof(buf), "SET ps 99");
11136 else if (strcasecmp(val, "Disable") == 0)
11137 snprintf(buf, sizeof(buf), "SET ps 98");
11138 else {
11139 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
11140 "Unsupported uapsd parameter value");
11141 return 0;
11142 }
11143 if (wpa_command(intf, buf)) {
11144 send_resp(dut, conn, SIGMA_ERROR,
11145 "ErrorCode,Failed to change U-APSD "
11146 "powersave mode");
11147 return 0;
11148 }
11149 }
11150
11151 val = get_param(cmd, "TPKTIMER");
11152 if (val && strcasecmp(val, "DISABLE") == 0) {
11153 if (wpa_command(intf, "SET tdls_testing 0x100")) {
11154 send_resp(dut, conn, SIGMA_ERROR,
11155 "ErrorCode,Failed to enable no TPK "
11156 "expiration test mode");
11157 return 0;
11158 }
11159 dut->no_tpk_expiration = 1;
11160 }
11161
11162 val = get_param(cmd, "ChSwitchMode");
11163 if (val) {
11164 if (strcasecmp(val, "Enable") == 0 ||
11165 strcasecmp(val, "Initiate") == 0)
11166 chsm = CHSM_ENABLE;
11167 else if (strcasecmp(val, "Disable") == 0 ||
11168 strcasecmp(val, "passive") == 0)
11169 chsm = CHSM_DISABLE;
11170 else if (strcasecmp(val, "RejReq") == 0)
11171 chsm = CHSM_REJREQ;
11172 else if (strcasecmp(val, "UnSolResp") == 0)
11173 chsm = CHSM_UNSOLRESP;
11174 else {
11175 send_resp(dut, conn, SIGMA_ERROR,
11176 "ErrorCode,Unknown ChSwitchMode value");
11177 return 0;
11178 }
11179 }
11180
11181 val = get_param(cmd, "OffChNum");
11182 if (val) {
11183 off_ch_num = atoi(val);
11184 if (off_ch_num == 0) {
11185 send_resp(dut, conn, SIGMA_ERROR,
11186 "ErrorCode,Invalid OffChNum");
11187 return 0;
11188 }
11189 }
11190
11191 val = get_param(cmd, "SecChOffset");
11192 if (val) {
11193 if (strcmp(val, "20") == 0)
11194 sec_ch = SEC_CH_NO;
11195 else if (strcasecmp(val, "40above") == 0)
11196 sec_ch = SEC_CH_40ABOVE;
11197 else if (strcasecmp(val, "40below") == 0)
11198 sec_ch = SEC_CH_40BELOW;
11199 else {
11200 send_resp(dut, conn, SIGMA_ERROR,
11201 "ErrorCode,Unknown SecChOffset value");
11202 return 0;
11203 }
11204 }
11205
11206 if (chsm == CHSM_NOT_SET) {
11207 /* no offchannel changes requested */
11208 return 1;
11209 }
11210
11211 if (strcmp(intf, get_main_ifname()) != 0 &&
11212 strcmp(intf, get_station_ifname()) != 0) {
11213 send_resp(dut, conn, SIGMA_ERROR,
11214 "ErrorCode,Unknown interface");
11215 return 0;
11216 }
11217
11218 switch (chsm) {
11219 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011220 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011221 break;
11222 case CHSM_ENABLE:
11223 if (off_ch_num < 0) {
11224 send_resp(dut, conn, SIGMA_ERROR,
11225 "ErrorCode,Missing OffChNum argument");
11226 return 0;
11227 }
11228 if (wifi_chip_type == DRIVER_WCN) {
11229 res = tdls_set_offchannel_offset(dut, conn, intf,
11230 off_ch_num, sec_ch);
11231 } else {
11232 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11233 sec_ch);
11234 }
11235 if (res != 1)
11236 return res;
11237 if (wifi_chip_type == DRIVER_WCN)
11238 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11239 else
11240 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11241 break;
11242 case CHSM_DISABLE:
11243 if (wifi_chip_type == DRIVER_WCN)
11244 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11245 else
11246 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11247 break;
11248 case CHSM_REJREQ:
11249 if (wifi_chip_type == DRIVER_WCN)
11250 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11251 else
11252 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11253 break;
11254 case CHSM_UNSOLRESP:
11255 if (off_ch_num < 0) {
11256 send_resp(dut, conn, SIGMA_ERROR,
11257 "ErrorCode,Missing OffChNum argument");
11258 return 0;
11259 }
11260 if (wifi_chip_type == DRIVER_WCN) {
11261 res = tdls_set_offchannel_offset(dut, conn, intf,
11262 off_ch_num, sec_ch);
11263 } else {
11264 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11265 sec_ch);
11266 }
11267 if (res != 1)
11268 return res;
11269 if (wifi_chip_type == DRIVER_WCN)
11270 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11271 else
11272 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11273 break;
11274 }
11275
11276 return res;
11277}
11278
11279
11280static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11281 struct sigma_conn *conn,
11282 struct sigma_cmd *cmd)
11283{
11284 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011285 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011286
Priyadharshini Gowthaman8c5b9a42019-07-31 14:38:48 -070011287 novap_reset(dut, intf, 1);
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011288
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011289 val = get_param(cmd, "nss_mcs_opt");
11290 if (val) {
11291 /* String (nss_operating_mode; mcs_operating_mode) */
11292 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011293 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011294
11295 token = strdup(val);
11296 if (!token)
11297 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011298 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011299 if (!result) {
11300 sigma_dut_print(dut, DUT_MSG_ERROR,
11301 "VHT NSS not specified");
11302 goto failed;
11303 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011304 if (strcasecmp(result, "def") != 0) {
11305 nss = atoi(result);
11306 if (nss == 4)
11307 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011308 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011309 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011310
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011311 }
11312
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011313 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011314 if (!result) {
11315 sigma_dut_print(dut, DUT_MSG_ERROR,
11316 "VHT MCS not specified");
11317 goto failed;
11318 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011319 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011320 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011321 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011322 } else {
11323 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011324 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011325 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011326 }
11327 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011328 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011329 }
11330
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011331 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011332 return 1;
11333failed:
11334 free(token);
11335 return 0;
11336}
11337
11338
11339static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11340 struct sigma_conn *conn,
11341 struct sigma_cmd *cmd)
11342{
11343 switch (get_driver_type()) {
11344 case DRIVER_ATHEROS:
11345 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11346 default:
11347 send_resp(dut, conn, SIGMA_ERROR,
11348 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11349 return 0;
11350 }
11351}
11352
11353
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011354static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11355 struct sigma_conn *conn,
11356 struct sigma_cmd *cmd)
11357{
11358 const char *val;
11359 char *token = NULL, *result;
11360 char buf[60];
11361
11362 val = get_param(cmd, "nss_mcs_opt");
11363 if (val) {
11364 /* String (nss_operating_mode; mcs_operating_mode) */
11365 int nss, mcs, ratecode;
11366 char *saveptr;
11367
11368 token = strdup(val);
11369 if (!token)
11370 return -2;
11371
11372 result = strtok_r(token, ";", &saveptr);
11373 if (!result) {
11374 sigma_dut_print(dut, DUT_MSG_ERROR,
11375 "HE NSS not specified");
11376 goto failed;
11377 }
11378 nss = 1;
11379 if (strcasecmp(result, "def") != 0)
11380 nss = atoi(result);
11381
11382 result = strtok_r(NULL, ";", &saveptr);
11383 if (!result) {
11384 sigma_dut_print(dut, DUT_MSG_ERROR,
11385 "HE MCS not specified");
11386 goto failed;
11387 }
11388 mcs = 7;
11389 if (strcasecmp(result, "def") != 0)
11390 mcs = atoi(result);
11391
Arif Hussain557bf412018-05-25 17:29:36 -070011392 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011393 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011394 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011395 } else if (nss > 2) {
11396 sigma_dut_print(dut, DUT_MSG_ERROR,
11397 "HE NSS %d not supported", nss);
11398 goto failed;
11399 }
11400
Arif Hussain557bf412018-05-25 17:29:36 -070011401 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11402 if (system(buf) != 0) {
11403 sigma_dut_print(dut, DUT_MSG_ERROR,
11404 "nss_mcs_opt: iwpriv %s nss %d failed",
11405 intf, nss);
11406 goto failed;
11407 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011408 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011409
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011410 /* Add the MCS to the ratecode */
11411 if (mcs >= 0 && mcs <= 11) {
11412 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011413#ifdef NL80211_SUPPORT
11414 if (dut->device_type == STA_testbed) {
11415 enum he_mcs_config mcs_config;
11416 int ret;
11417
11418 if (mcs <= 7)
11419 mcs_config = HE_80_MCS0_7;
11420 else if (mcs <= 9)
11421 mcs_config = HE_80_MCS0_9;
11422 else
11423 mcs_config = HE_80_MCS0_11;
11424 ret = sta_set_he_mcs(dut, intf, mcs_config);
11425 if (ret) {
11426 sigma_dut_print(dut, DUT_MSG_ERROR,
11427 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11428 mcs, mcs_config, ret);
11429 goto failed;
11430 }
11431 }
11432#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011433 } else {
11434 sigma_dut_print(dut, DUT_MSG_ERROR,
11435 "HE MCS %d not supported", mcs);
11436 goto failed;
11437 }
11438 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11439 intf, ratecode);
11440 if (system(buf) != 0) {
11441 sigma_dut_print(dut, DUT_MSG_ERROR,
11442 "iwpriv setting of 11ax rates failed");
11443 goto failed;
11444 }
11445 free(token);
11446 }
11447
11448 val = get_param(cmd, "GI");
11449 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011450 int fix_rate_sgi;
11451
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011452 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011453 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011454 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011455 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011456 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11457 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011458 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011459 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011460 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11461 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011462 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011463 } else {
11464 send_resp(dut, conn, SIGMA_ERROR,
11465 "errorCode,GI value not supported");
11466 return 0;
11467 }
11468 if (system(buf) != 0) {
11469 send_resp(dut, conn, SIGMA_ERROR,
11470 "errorCode,Failed to set shortgi");
11471 return 0;
11472 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011473 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11474 intf, fix_rate_sgi);
11475 if (system(buf) != 0) {
11476 send_resp(dut, conn, SIGMA_ERROR,
11477 "errorCode,Failed to set fix rate shortgi");
11478 return STATUS_SENT;
11479 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011480 }
11481
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011482 val = get_param(cmd, "LTF");
11483 if (val) {
11484#ifdef NL80211_SUPPORT
11485 if (strcmp(val, "3.2") == 0) {
11486 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11487 } if (strcmp(val, "6.4") == 0) {
11488 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11489 } else if (strcmp(val, "12.8") == 0) {
11490 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11491 } else {
11492 send_resp(dut, conn, SIGMA_ERROR,
11493 "errorCode, LTF value not supported");
11494 return 0;
11495 }
11496#else /* NL80211_SUPPORT */
11497 sigma_dut_print(dut, DUT_MSG_ERROR,
11498 "LTF cannot be set without NL80211_SUPPORT defined");
11499 return -2;
11500#endif /* NL80211_SUPPORT */
11501 }
11502
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011503 val = get_param(cmd, "TxSUPPDU");
11504 if (val) {
11505 int set_val = 1;
11506
11507 if (strcasecmp(val, "Enable") == 0)
11508 set_val = 1;
11509 else if (strcasecmp(val, "Disable") == 0)
11510 set_val = 0;
11511
11512 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11513 send_resp(dut, conn, SIGMA_ERROR,
11514 "ErrorCode,Failed to set Tx SU PPDU config");
11515 return 0;
11516 }
11517 }
11518
Arif Hussain480d5f42019-03-12 14:40:42 -070011519 val = get_param(cmd, "TWT_Setup");
11520 if (val) {
11521 if (strcasecmp(val, "Request") == 0) {
11522 if (sta_twt_request(dut, conn, cmd)) {
11523 send_resp(dut, conn, SIGMA_ERROR,
11524 "ErrorCode,sta_twt_request failed");
11525 return STATUS_SENT;
11526 }
11527 } else if (strcasecmp(val, "Teardown") == 0) {
11528 if (sta_twt_teardown(dut, conn, cmd)) {
11529 send_resp(dut, conn, SIGMA_ERROR,
11530 "ErrorCode,sta_twt_teardown failed");
11531 return STATUS_SENT;
11532 }
11533 }
11534 }
11535
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011536 val = get_param(cmd, "transmitOMI");
11537 if (val && sta_transmit_omi(dut, conn, cmd)) {
11538 send_resp(dut, conn, SIGMA_ERROR,
11539 "ErrorCode,sta_transmit_omi failed");
11540 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011541 }
11542
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011543 val = get_param(cmd, "Powersave");
11544 if (val) {
11545 char buf[60];
11546
11547 if (strcasecmp(val, "off") == 0) {
11548 snprintf(buf, sizeof(buf),
11549 "iwpriv %s setPower 2", intf);
11550 if (system(buf) != 0) {
11551 sigma_dut_print(dut, DUT_MSG_ERROR,
11552 "iwpriv setPower 2 failed");
11553 return 0;
11554 }
11555 } else if (strcasecmp(val, "on") == 0) {
11556 snprintf(buf, sizeof(buf),
11557 "iwpriv %s setPower 1", intf);
11558 if (system(buf) != 0) {
11559 sigma_dut_print(dut, DUT_MSG_ERROR,
11560 "iwpriv setPower 1 failed");
11561 return 0;
11562 }
11563 } else {
11564 sigma_dut_print(dut, DUT_MSG_ERROR,
11565 "Unsupported Powersave value '%s'",
11566 val);
11567 return -1;
11568 }
11569 }
11570
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011571 val = get_param(cmd, "MU_EDCA");
11572 if (val) {
11573 if (strcasecmp(val, "Override") == 0) {
11574 if (sta_set_mu_edca_override(dut, intf, 1)) {
11575 send_resp(dut, conn, SIGMA_ERROR,
11576 "errorCode,MU EDCA override set failed");
11577 return STATUS_SENT;
11578 }
11579 } else if (strcasecmp(val, "Disable") == 0) {
11580 if (sta_set_mu_edca_override(dut, intf, 0)) {
11581 send_resp(dut, conn, SIGMA_ERROR,
11582 "errorCode,MU EDCA override disable failed");
11583 return STATUS_SENT;
11584 }
11585 }
11586 }
11587
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011588 return 1;
11589
11590failed:
11591 free(token);
11592 return -2;
11593}
11594
11595
11596static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11597 struct sigma_conn *conn,
11598 struct sigma_cmd *cmd)
11599{
11600 switch (get_driver_type()) {
11601 case DRIVER_WCN:
11602 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11603 default:
11604 send_resp(dut, conn, SIGMA_ERROR,
11605 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11606 return 0;
11607 }
11608}
11609
11610
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011611static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11612 struct sigma_conn *conn,
11613 struct sigma_cmd *cmd)
11614{
11615 const char *val;
11616
11617 val = get_param(cmd, "powersave");
11618 if (val) {
11619 char buf[60];
11620
11621 if (strcasecmp(val, "off") == 0) {
11622 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11623 intf);
11624 if (system(buf) != 0) {
11625 sigma_dut_print(dut, DUT_MSG_ERROR,
11626 "iwpriv setPower 2 failed");
11627 return 0;
11628 }
11629 } else if (strcasecmp(val, "on") == 0) {
11630 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11631 intf);
11632 if (system(buf) != 0) {
11633 sigma_dut_print(dut, DUT_MSG_ERROR,
11634 "iwpriv setPower 1 failed");
11635 return 0;
11636 }
11637 } else {
11638 sigma_dut_print(dut, DUT_MSG_ERROR,
11639 "Unsupported power save config");
11640 return -1;
11641 }
11642 return 1;
11643 }
11644
11645 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11646
11647 return 0;
11648}
11649
11650
Ashwini Patil5acd7382017-04-13 15:55:04 +053011651static int btm_query_candidate_list(struct sigma_dut *dut,
11652 struct sigma_conn *conn,
11653 struct sigma_cmd *cmd)
11654{
11655 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11656 int len, ret;
11657 char buf[10];
11658
11659 /*
11660 * Neighbor Report elements format:
11661 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11662 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11663 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11664 */
11665
11666 bssid = get_param(cmd, "Nebor_BSSID");
11667 if (!bssid) {
11668 send_resp(dut, conn, SIGMA_INVALID,
11669 "errorCode,Nebor_BSSID is missing");
11670 return 0;
11671 }
11672
11673 info = get_param(cmd, "Nebor_Bssid_Info");
11674 if (!info) {
11675 sigma_dut_print(dut, DUT_MSG_INFO,
11676 "Using default value for Nebor_Bssid_Info: %s",
11677 DEFAULT_NEIGHBOR_BSSID_INFO);
11678 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11679 }
11680
11681 op_class = get_param(cmd, "Nebor_Op_Class");
11682 if (!op_class) {
11683 send_resp(dut, conn, SIGMA_INVALID,
11684 "errorCode,Nebor_Op_Class is missing");
11685 return 0;
11686 }
11687
11688 ch = get_param(cmd, "Nebor_Op_Ch");
11689 if (!ch) {
11690 send_resp(dut, conn, SIGMA_INVALID,
11691 "errorCode,Nebor_Op_Ch is missing");
11692 return 0;
11693 }
11694
11695 phy_type = get_param(cmd, "Nebor_Phy_Type");
11696 if (!phy_type) {
11697 sigma_dut_print(dut, DUT_MSG_INFO,
11698 "Using default value for Nebor_Phy_Type: %s",
11699 DEFAULT_NEIGHBOR_PHY_TYPE);
11700 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11701 }
11702
11703 /* Parse optional subelements */
11704 buf[0] = '\0';
11705 pref = get_param(cmd, "Nebor_Pref");
11706 if (pref) {
11707 /* hexdump for preferrence subelement */
11708 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11709 if (ret < 0 || ret >= (int) sizeof(buf)) {
11710 sigma_dut_print(dut, DUT_MSG_ERROR,
11711 "snprintf failed for optional subelement ret: %d",
11712 ret);
11713 send_resp(dut, conn, SIGMA_ERROR,
11714 "errorCode,snprintf failed for subelement");
11715 return 0;
11716 }
11717 }
11718
11719 if (!dut->btm_query_cand_list) {
11720 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11721 if (!dut->btm_query_cand_list) {
11722 send_resp(dut, conn, SIGMA_ERROR,
11723 "errorCode,Failed to allocate memory for btm_query_cand_list");
11724 return 0;
11725 }
11726 }
11727
11728 len = strlen(dut->btm_query_cand_list);
11729 ret = snprintf(dut->btm_query_cand_list + len,
11730 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11731 bssid, info, op_class, ch, phy_type, buf);
11732 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11733 sigma_dut_print(dut, DUT_MSG_ERROR,
11734 "snprintf failed for neighbor report list ret: %d",
11735 ret);
11736 send_resp(dut, conn, SIGMA_ERROR,
11737 "errorCode,snprintf failed for neighbor report");
11738 free(dut->btm_query_cand_list);
11739 dut->btm_query_cand_list = NULL;
11740 return 0;
11741 }
11742
11743 return 1;
11744}
11745
11746
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011747int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11748 struct sigma_ese_alloc *allocs, int *allocs_size)
11749{
11750 int max_count = *allocs_size;
11751 int count = 0, i;
11752 const char *val;
11753
11754 do {
11755 val = get_param_indexed(cmd, "AllocID", count);
11756 if (val)
11757 count++;
11758 } while (val);
11759
11760 if (count == 0 || count > max_count) {
11761 sigma_dut_print(dut, DUT_MSG_ERROR,
11762 "Invalid number of allocations(%d)", count);
11763 return -1;
11764 }
11765
11766 for (i = 0; i < count; i++) {
11767 val = get_param_indexed(cmd, "PercentBI", i);
11768 if (!val) {
11769 sigma_dut_print(dut, DUT_MSG_ERROR,
11770 "Missing PercentBI parameter at index %d",
11771 i);
11772 return -1;
11773 }
11774 allocs[i].percent_bi = atoi(val);
11775
11776 val = get_param_indexed(cmd, "SrcAID", i);
11777 if (val)
11778 allocs[i].src_aid = strtol(val, NULL, 0);
11779 else
11780 allocs[i].src_aid = ESE_BCAST_AID;
11781
11782 val = get_param_indexed(cmd, "DestAID", i);
11783 if (val)
11784 allocs[i].dst_aid = strtol(val, NULL, 0);
11785 else
11786 allocs[i].dst_aid = ESE_BCAST_AID;
11787
11788 allocs[i].type = ESE_CBAP;
11789 sigma_dut_print(dut, DUT_MSG_INFO,
11790 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11791 i, allocs[i].percent_bi, allocs[i].src_aid,
11792 allocs[i].dst_aid);
11793 }
11794
11795 *allocs_size = count;
11796 return 0;
11797}
11798
11799
11800static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11801 struct sigma_ese_alloc *allocs)
11802{
11803 switch (get_driver_type()) {
11804#ifdef __linux__
11805 case DRIVER_WIL6210:
11806 if (wil6210_set_ese(dut, count, allocs))
11807 return -1;
11808 return 1;
11809#endif /* __linux__ */
11810 default:
11811 sigma_dut_print(dut, DUT_MSG_ERROR,
11812 "Unsupported sta_set_60g_ese with the current driver");
11813 return -1;
11814 }
11815}
11816
11817
11818static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11819 struct sigma_conn *conn,
11820 struct sigma_cmd *cmd)
11821{
11822 const char *val;
11823
11824 val = get_param(cmd, "ExtSchIE");
11825 if (val && !strcasecmp(val, "Enable")) {
11826 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11827 int count = MAX_ESE_ALLOCS;
11828
11829 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11830 return -1;
11831 return sta_set_60g_ese(dut, count, allocs);
11832 }
11833
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011834 val = get_param(cmd, "MCS_FixedRate");
11835 if (val) {
11836 int sta_mcs = atoi(val);
11837
11838 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11839 sta_mcs);
11840 wil6210_set_force_mcs(dut, 1, sta_mcs);
11841
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011842 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011843 }
11844
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011845 send_resp(dut, conn, SIGMA_ERROR,
11846 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011847 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011848}
11849
11850
Jouni Malinenf7222712019-06-13 01:50:21 +030011851static enum sigma_cmd_result cmd_sta_set_rfeature(struct sigma_dut *dut,
11852 struct sigma_conn *conn,
11853 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011854{
11855 const char *intf = get_param(cmd, "Interface");
11856 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011857 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011858
11859 if (intf == NULL || prog == NULL)
11860 return -1;
11861
Ashwini Patil5acd7382017-04-13 15:55:04 +053011862 /* BSS Transition candidate list for BTM query */
11863 val = get_param(cmd, "Nebor_BSSID");
11864 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11865 return 0;
11866
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011867 if (strcasecmp(prog, "TDLS") == 0)
11868 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11869
11870 if (strcasecmp(prog, "VHT") == 0)
11871 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11872
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011873 if (strcasecmp(prog, "HE") == 0)
11874 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11875
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011876 if (strcasecmp(prog, "MBO") == 0) {
11877 val = get_param(cmd, "Cellular_Data_Cap");
11878 if (val &&
11879 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11880 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011881
11882 val = get_param(cmd, "Ch_Pref");
11883 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11884 return 0;
11885
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011886 return 1;
11887 }
11888
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011889 if (strcasecmp(prog, "60GHz") == 0)
11890 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11891
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011892 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11893 return 0;
11894}
11895
11896
Jouni Malinenf7222712019-06-13 01:50:21 +030011897static enum sigma_cmd_result cmd_sta_set_radio(struct sigma_dut *dut,
11898 struct sigma_conn *conn,
11899 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011900{
11901 const char *intf = get_param(cmd, "Interface");
11902 const char *mode = get_param(cmd, "Mode");
11903 int res;
11904
11905 if (intf == NULL || mode == NULL)
11906 return -1;
11907
11908 if (strcasecmp(mode, "On") == 0)
11909 res = wpa_command(intf, "SET radio_disabled 0");
11910 else if (strcasecmp(mode, "Off") == 0)
11911 res = wpa_command(intf, "SET radio_disabled 1");
11912 else
11913 return -1;
11914
11915 if (res) {
11916 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11917 "radio mode");
11918 return 0;
11919 }
11920
11921 return 1;
11922}
11923
11924
Jouni Malinenf7222712019-06-13 01:50:21 +030011925static enum sigma_cmd_result cmd_sta_set_pwrsave(struct sigma_dut *dut,
11926 struct sigma_conn *conn,
11927 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011928{
11929 const char *intf = get_param(cmd, "Interface");
11930 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011931 const char *prog = get_param(cmd, "program");
11932 const char *powersave = get_param(cmd, "powersave");
11933 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011934
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011935 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011936 return -1;
11937
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011938 if (prog && strcasecmp(prog, "60GHz") == 0) {
11939 /*
11940 * The CAPI mode parameter does not exist in 60G
11941 * unscheduled PS.
11942 */
Hu Wang5dc3ff12019-06-14 15:14:26 +080011943 if (powersave && strcasecmp(powersave, "unscheduled") == 0)
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011944 res = set_ps(intf, dut, 1);
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011945 } else if (prog && get_driver_type() == DRIVER_WCN &&
11946 strcasecmp(prog, "HE") == 0) {
11947 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011948 } else {
11949 if (mode == NULL)
11950 return -1;
11951
11952 if (strcasecmp(mode, "On") == 0)
11953 res = set_ps(intf, dut, 1);
11954 else if (strcasecmp(mode, "Off") == 0)
11955 res = set_ps(intf, dut, 0);
11956 else
11957 return -1;
11958 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011959
11960 if (res) {
11961 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11962 "power save mode");
11963 return 0;
11964 }
11965
11966 return 1;
11967}
11968
11969
Jouni Malinenf7222712019-06-13 01:50:21 +030011970static enum sigma_cmd_result cmd_sta_bssid_pool(struct sigma_dut *dut,
11971 struct sigma_conn *conn,
11972 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011973{
11974 const char *intf = get_param(cmd, "Interface");
11975 const char *val, *bssid;
11976 int res;
11977 char *buf;
11978 size_t buf_len;
11979
11980 val = get_param(cmd, "BSSID_FILTER");
11981 if (val == NULL)
11982 return -1;
11983
11984 bssid = get_param(cmd, "BSSID_List");
11985 if (atoi(val) == 0 || bssid == NULL) {
11986 /* Disable BSSID filter */
11987 if (wpa_command(intf, "SET bssid_filter ")) {
11988 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
11989 "to disable BSSID filter");
11990 return 0;
11991 }
11992
11993 return 1;
11994 }
11995
11996 buf_len = 100 + strlen(bssid);
11997 buf = malloc(buf_len);
11998 if (buf == NULL)
11999 return -1;
12000
12001 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
12002 res = wpa_command(intf, buf);
12003 free(buf);
12004 if (res) {
12005 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
12006 "BSSID filter");
12007 return 0;
12008 }
12009
12010 return 1;
12011}
12012
12013
Jouni Malinenf7222712019-06-13 01:50:21 +030012014static enum sigma_cmd_result cmd_sta_reset_parm(struct sigma_dut *dut,
12015 struct sigma_conn *conn,
12016 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012017{
12018 const char *intf = get_param(cmd, "Interface");
12019 const char *val;
12020
12021 /* TODO: ARP */
12022
12023 val = get_param(cmd, "HS2_CACHE_PROFILE");
12024 if (val && strcasecmp(val, "All") == 0)
12025 hs2_clear_credentials(intf);
12026
12027 return 1;
12028}
12029
12030
Jouni Malinenf7222712019-06-13 01:50:21 +030012031static enum sigma_cmd_result cmd_sta_get_key(struct sigma_dut *dut,
12032 struct sigma_conn *conn,
12033 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012034{
12035 const char *intf = get_param(cmd, "Interface");
12036 const char *key_type = get_param(cmd, "KeyType");
12037 char buf[100], resp[200];
12038
12039 if (key_type == NULL)
12040 return -1;
12041
12042 if (strcasecmp(key_type, "GTK") == 0) {
12043 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
12044 strncmp(buf, "FAIL", 4) == 0) {
12045 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12046 "not fetch current GTK");
12047 return 0;
12048 }
12049 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
12050 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12051 return 0;
12052 } else {
12053 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
12054 "KeyType");
12055 return 0;
12056 }
12057
12058 return 1;
12059}
12060
12061
12062static int hs2_set_policy(struct sigma_dut *dut)
12063{
12064#ifdef ANDROID
12065 system("ip rule del prio 23000");
12066 if (system("ip rule add from all lookup main prio 23000") != 0) {
12067 sigma_dut_print(dut, DUT_MSG_ERROR,
12068 "Failed to run:ip rule add from all lookup main prio");
12069 return -1;
12070 }
12071 if (system("ip route flush cache") != 0) {
12072 sigma_dut_print(dut, DUT_MSG_ERROR,
12073 "Failed to run ip route flush cache");
12074 return -1;
12075 }
12076 return 1;
12077#else /* ANDROID */
12078 return 0;
12079#endif /* ANDROID */
12080}
12081
12082
Jouni Malinenf7222712019-06-13 01:50:21 +030012083static enum sigma_cmd_result cmd_sta_hs2_associate(struct sigma_dut *dut,
12084 struct sigma_conn *conn,
12085 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012086{
12087 const char *intf = get_param(cmd, "Interface");
12088 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030012089 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012090 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030012091 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012092 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
12093 int tries = 0;
12094 int ignore_blacklist = 0;
12095 const char *events[] = {
12096 "CTRL-EVENT-CONNECTED",
12097 "INTERWORKING-BLACKLISTED",
12098 "INTERWORKING-NO-MATCH",
12099 NULL
12100 };
12101
12102 start_sta_mode(dut);
12103
Jouni Malinen439352d2018-09-13 03:42:23 +030012104 if (band) {
12105 if (strcmp(band, "2.4") == 0) {
12106 wpa_command(intf, "SET setband 2G");
12107 } else if (strcmp(band, "5") == 0) {
12108 wpa_command(intf, "SET setband 5G");
12109 } else {
12110 send_resp(dut, conn, SIGMA_ERROR,
12111 "errorCode,Unsupported band");
12112 return 0;
12113 }
12114 }
12115
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012116 blacklisted[0] = '\0';
12117 if (val && atoi(val))
12118 ignore_blacklist = 1;
12119
12120try_again:
12121 ctrl = open_wpa_mon(intf);
12122 if (ctrl == NULL) {
12123 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12124 "wpa_supplicant monitor connection");
12125 return -2;
12126 }
12127
12128 tries++;
12129 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
12130 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
12131 "Interworking connection");
12132 wpa_ctrl_detach(ctrl);
12133 wpa_ctrl_close(ctrl);
12134 return 0;
12135 }
12136
12137 buf[0] = '\0';
12138 while (1) {
12139 char *pos;
12140 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12141 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
12142 if (!pos)
12143 break;
12144 pos += 25;
12145 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
12146 pos);
12147 if (!blacklisted[0])
12148 memcpy(blacklisted, pos, strlen(pos) + 1);
12149 }
12150
12151 if (ignore_blacklist && blacklisted[0]) {
12152 char *end;
12153 end = strchr(blacklisted, ' ');
12154 if (end)
12155 *end = '\0';
12156 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
12157 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030012158 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
12159 blacklisted);
12160 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012161 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
12162 wpa_ctrl_detach(ctrl);
12163 wpa_ctrl_close(ctrl);
12164 return 0;
12165 }
12166 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12167 buf, sizeof(buf));
12168 }
12169
12170 wpa_ctrl_detach(ctrl);
12171 wpa_ctrl_close(ctrl);
12172
12173 if (res < 0) {
12174 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12175 "connect");
12176 return 0;
12177 }
12178
12179 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12180 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12181 if (tries < 2) {
12182 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12183 goto try_again;
12184 }
12185 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12186 "matching credentials found");
12187 return 0;
12188 }
12189
12190 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12191 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12192 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12193 "get current BSSID/SSID");
12194 return 0;
12195 }
12196
12197 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12198 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12199 hs2_set_policy(dut);
12200 return 0;
12201}
12202
12203
Jouni Malinenf7222712019-06-13 01:50:21 +030012204static enum sigma_cmd_result cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12205 struct sigma_conn *conn,
12206 struct sigma_cmd *cmd)
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012207{
12208 const char *intf = get_param(cmd, "Interface");
12209 const char *display = get_param(cmd, "Display");
12210 struct wpa_ctrl *ctrl;
12211 char buf[300], params[400], *pos;
12212 char bssid[20];
12213 int info_avail = 0;
12214 unsigned int old_timeout;
12215 int res;
12216
12217 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12218 send_resp(dut, conn, SIGMA_ERROR,
12219 "ErrorCode,Could not get current BSSID");
12220 return 0;
12221 }
12222 ctrl = open_wpa_mon(intf);
12223 if (!ctrl) {
12224 sigma_dut_print(dut, DUT_MSG_ERROR,
12225 "Failed to open wpa_supplicant monitor connection");
12226 return -2;
12227 }
12228
12229 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12230 wpa_command(intf, buf);
12231
12232 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12233 if (res < 0) {
12234 send_resp(dut, conn, SIGMA_ERROR,
12235 "ErrorCode,Could not complete GAS query");
12236 goto fail;
12237 }
12238
12239 old_timeout = dut->default_timeout;
12240 dut->default_timeout = 2;
12241 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12242 dut->default_timeout = old_timeout;
12243 if (res < 0)
12244 goto done;
12245 pos = strchr(buf, ' ');
12246 if (!pos)
12247 goto done;
12248 pos++;
12249 pos = strchr(pos, ' ');
12250 if (!pos)
12251 goto done;
12252 pos++;
12253 info_avail = 1;
12254 snprintf(params, sizeof(params), "browser %s", pos);
12255
12256 if (display && strcasecmp(display, "Yes") == 0) {
12257 pid_t pid;
12258
12259 pid = fork();
12260 if (pid < 0) {
12261 perror("fork");
12262 return -1;
12263 }
12264
12265 if (pid == 0) {
12266 run_hs20_osu(dut, params);
12267 exit(0);
12268 }
12269 }
12270
12271done:
12272 snprintf(buf, sizeof(buf), "Info_available,%s",
12273 info_avail ? "Yes" : "No");
12274 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12275fail:
12276 wpa_ctrl_detach(ctrl);
12277 wpa_ctrl_close(ctrl);
12278 return 0;
12279}
12280
12281
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012282static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12283 struct sigma_conn *conn,
12284 const char *ifname,
12285 struct sigma_cmd *cmd)
12286{
12287 const char *val;
12288 int id;
12289
12290 id = add_cred(ifname);
12291 if (id < 0)
12292 return -2;
12293 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12294
12295 val = get_param(cmd, "prefer");
12296 if (val && atoi(val) > 0)
12297 set_cred(ifname, id, "priority", "1");
12298
12299 val = get_param(cmd, "REALM");
12300 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12301 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12302 "realm");
12303 return 0;
12304 }
12305
12306 val = get_param(cmd, "HOME_FQDN");
12307 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12308 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12309 "home_fqdn");
12310 return 0;
12311 }
12312
12313 val = get_param(cmd, "Username");
12314 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12315 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12316 "username");
12317 return 0;
12318 }
12319
12320 val = get_param(cmd, "Password");
12321 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12322 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12323 "password");
12324 return 0;
12325 }
12326
12327 val = get_param(cmd, "ROOT_CA");
12328 if (val) {
12329 char fname[200];
12330 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12331#ifdef __linux__
12332 if (!file_exists(fname)) {
12333 char msg[300];
12334 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12335 "file (%s) not found", fname);
12336 send_resp(dut, conn, SIGMA_ERROR, msg);
12337 return 0;
12338 }
12339#endif /* __linux__ */
12340 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12341 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12342 "not set root CA");
12343 return 0;
12344 }
12345 }
12346
12347 return 1;
12348}
12349
12350
12351static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12352{
12353 FILE *in, *out;
12354 char buf[500];
12355 int found = 0;
12356
12357 in = fopen("devdetail.xml", "r");
12358 if (in == NULL)
12359 return -1;
12360 out = fopen("devdetail.xml.tmp", "w");
12361 if (out == NULL) {
12362 fclose(in);
12363 return -1;
12364 }
12365
12366 while (fgets(buf, sizeof(buf), in)) {
12367 char *pos = strstr(buf, "<IMSI>");
12368 if (pos) {
12369 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12370 imsi);
12371 pos += 6;
12372 *pos = '\0';
12373 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12374 found++;
12375 } else {
12376 fprintf(out, "%s", buf);
12377 }
12378 }
12379
12380 fclose(out);
12381 fclose(in);
12382 if (found)
12383 rename("devdetail.xml.tmp", "devdetail.xml");
12384 else
12385 unlink("devdetail.xml.tmp");
12386
12387 return 0;
12388}
12389
12390
12391static int sta_add_credential_sim(struct sigma_dut *dut,
12392 struct sigma_conn *conn,
12393 const char *ifname, struct sigma_cmd *cmd)
12394{
12395 const char *val, *imsi = NULL;
12396 int id;
12397 char buf[200];
12398 int res;
12399 const char *pos;
12400 size_t mnc_len;
12401 char plmn_mcc[4];
12402 char plmn_mnc[4];
12403
12404 id = add_cred(ifname);
12405 if (id < 0)
12406 return -2;
12407 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12408
12409 val = get_param(cmd, "prefer");
12410 if (val && atoi(val) > 0)
12411 set_cred(ifname, id, "priority", "1");
12412
12413 val = get_param(cmd, "PLMN_MCC");
12414 if (val == NULL) {
12415 send_resp(dut, conn, SIGMA_ERROR,
12416 "errorCode,Missing PLMN_MCC");
12417 return 0;
12418 }
12419 if (strlen(val) != 3) {
12420 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12421 return 0;
12422 }
12423 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12424
12425 val = get_param(cmd, "PLMN_MNC");
12426 if (val == NULL) {
12427 send_resp(dut, conn, SIGMA_ERROR,
12428 "errorCode,Missing PLMN_MNC");
12429 return 0;
12430 }
12431 if (strlen(val) != 2 && strlen(val) != 3) {
12432 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12433 return 0;
12434 }
12435 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12436
12437 val = get_param(cmd, "IMSI");
12438 if (val == NULL) {
12439 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12440 "IMSI");
12441 return 0;
12442 }
12443
12444 imsi = pos = val;
12445
12446 if (strncmp(plmn_mcc, pos, 3) != 0) {
12447 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12448 return 0;
12449 }
12450 pos += 3;
12451
12452 mnc_len = strlen(plmn_mnc);
12453 if (mnc_len < 2) {
12454 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12455 return 0;
12456 }
12457
12458 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12459 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12460 return 0;
12461 }
12462 pos += mnc_len;
12463
12464 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12465 if (res < 0 || res >= (int) sizeof(buf))
12466 return -1;
12467 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12468 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12469 "not set IMSI");
12470 return 0;
12471 }
12472
12473 val = get_param(cmd, "Password");
12474 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12475 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12476 "not set password");
12477 return 0;
12478 }
12479
Jouni Malinenba630452018-06-22 11:49:59 +030012480 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012481 /*
12482 * Set provisioning_sp for the test cases where SIM/USIM
12483 * provisioning is used.
12484 */
12485 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12486 "wi-fi.org") < 0) {
12487 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12488 "not set provisioning_sp");
12489 return 0;
12490 }
12491
12492 update_devdetail_imsi(dut, imsi);
12493 }
12494
12495 return 1;
12496}
12497
12498
12499static int sta_add_credential_cert(struct sigma_dut *dut,
12500 struct sigma_conn *conn,
12501 const char *ifname,
12502 struct sigma_cmd *cmd)
12503{
12504 const char *val;
12505 int id;
12506
12507 id = add_cred(ifname);
12508 if (id < 0)
12509 return -2;
12510 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12511
12512 val = get_param(cmd, "prefer");
12513 if (val && atoi(val) > 0)
12514 set_cred(ifname, id, "priority", "1");
12515
12516 val = get_param(cmd, "REALM");
12517 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12518 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12519 "realm");
12520 return 0;
12521 }
12522
12523 val = get_param(cmd, "HOME_FQDN");
12524 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12525 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12526 "home_fqdn");
12527 return 0;
12528 }
12529
12530 val = get_param(cmd, "Username");
12531 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12532 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12533 "username");
12534 return 0;
12535 }
12536
12537 val = get_param(cmd, "clientCertificate");
12538 if (val) {
12539 char fname[200];
12540 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12541#ifdef __linux__
12542 if (!file_exists(fname)) {
12543 char msg[300];
12544 snprintf(msg, sizeof(msg),
12545 "ErrorCode,clientCertificate "
12546 "file (%s) not found", fname);
12547 send_resp(dut, conn, SIGMA_ERROR, msg);
12548 return 0;
12549 }
12550#endif /* __linux__ */
12551 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12552 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12553 "not set client_cert");
12554 return 0;
12555 }
12556 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12557 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12558 "not set private_key");
12559 return 0;
12560 }
12561 }
12562
12563 val = get_param(cmd, "ROOT_CA");
12564 if (val) {
12565 char fname[200];
12566 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12567#ifdef __linux__
12568 if (!file_exists(fname)) {
12569 char msg[300];
12570 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12571 "file (%s) not found", fname);
12572 send_resp(dut, conn, SIGMA_ERROR, msg);
12573 return 0;
12574 }
12575#endif /* __linux__ */
12576 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12577 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12578 "not set root CA");
12579 return 0;
12580 }
12581 }
12582
12583 return 1;
12584}
12585
12586
Jouni Malinenf7222712019-06-13 01:50:21 +030012587static enum sigma_cmd_result cmd_sta_add_credential(struct sigma_dut *dut,
12588 struct sigma_conn *conn,
12589 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012590{
12591 const char *intf = get_param(cmd, "Interface");
12592 const char *type;
12593
12594 start_sta_mode(dut);
12595
12596 type = get_param(cmd, "Type");
12597 if (!type)
12598 return -1;
12599
12600 if (strcasecmp(type, "uname_pwd") == 0)
12601 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12602
12603 if (strcasecmp(type, "sim") == 0)
12604 return sta_add_credential_sim(dut, conn, intf, cmd);
12605
12606 if (strcasecmp(type, "cert") == 0)
12607 return sta_add_credential_cert(dut, conn, intf, cmd);
12608
12609 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12610 "type");
12611 return 0;
12612}
12613
12614
Jouni Malinenf7222712019-06-13 01:50:21 +030012615static enum sigma_cmd_result cmd_sta_scan(struct sigma_dut *dut,
12616 struct sigma_conn *conn,
12617 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012618{
12619 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012620 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012621 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012622 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012623 int res;
12624
Arif Hussain66a4af02019-02-07 15:04:51 -080012625 val = get_param(cmd, "GetParameter");
12626 if (val && strcmp(val, "SSID_BSSID") == 0) {
12627 if (get_wpa_ssid_bssid(dut, get_station_ifname(),
12628 buf, sizeof(buf)) < 0) {
12629 sigma_dut_print(dut, DUT_MSG_ERROR,
12630 "Could not get ssid bssid");
12631 return ERROR_SEND_STATUS;
12632 }
12633
12634 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12635 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12636 return STATUS_SENT;
12637 }
12638
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012639 val = get_param(cmd, "HESSID");
12640 if (val) {
12641 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12642 if (res < 0 || res >= (int) sizeof(buf))
12643 return -1;
12644 wpa_command(intf, buf);
12645 }
12646
12647 val = get_param(cmd, "ACCS_NET_TYPE");
12648 if (val) {
12649 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12650 val);
12651 if (res < 0 || res >= (int) sizeof(buf))
12652 return -1;
12653 wpa_command(intf, buf);
12654 }
12655
vamsi krishna89ad8c62017-09-19 12:51:18 +053012656 bssid = get_param(cmd, "Bssid");
12657 ssid = get_param(cmd, "Ssid");
12658
12659 if (ssid) {
12660 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12661 send_resp(dut, conn, SIGMA_ERROR,
12662 "ErrorCode,Too long SSID");
12663 return 0;
12664 }
12665 ascii2hexstr(ssid, ssid_hex);
12666 }
12667
12668 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12669 bssid ? " bssid=": "",
12670 bssid ? bssid : "",
12671 ssid ? " ssid " : "",
12672 ssid ? ssid_hex : "");
12673 if (res < 0 || res >= (int) sizeof(buf))
12674 return -1;
12675
12676 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012677 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12678 "scan");
12679 return 0;
12680 }
12681
12682 return 1;
12683}
12684
12685
Jouni Malinenf7222712019-06-13 01:50:21 +030012686static enum sigma_cmd_result cmd_sta_scan_bss(struct sigma_dut *dut,
12687 struct sigma_conn *conn,
12688 struct sigma_cmd *cmd)
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012689{
12690 const char *intf = get_param(cmd, "Interface");
12691 const char *bssid;
12692 char buf[4096], *pos;
12693 int freq, chan;
12694 char *ssid;
12695 char resp[100];
12696 int res;
12697 struct wpa_ctrl *ctrl;
12698
12699 bssid = get_param(cmd, "BSSID");
12700 if (!bssid) {
12701 send_resp(dut, conn, SIGMA_INVALID,
12702 "errorCode,BSSID argument is missing");
12703 return 0;
12704 }
12705
12706 ctrl = open_wpa_mon(intf);
12707 if (!ctrl) {
12708 sigma_dut_print(dut, DUT_MSG_ERROR,
12709 "Failed to open wpa_supplicant monitor connection");
12710 return -1;
12711 }
12712
12713 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12714 send_resp(dut, conn, SIGMA_ERROR,
12715 "errorCode,Could not start scan");
12716 wpa_ctrl_detach(ctrl);
12717 wpa_ctrl_close(ctrl);
12718 return 0;
12719 }
12720
12721 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12722 buf, sizeof(buf));
12723
12724 wpa_ctrl_detach(ctrl);
12725 wpa_ctrl_close(ctrl);
12726
12727 if (res < 0) {
12728 send_resp(dut, conn, SIGMA_ERROR,
12729 "errorCode,Scan did not complete");
12730 return 0;
12731 }
12732
12733 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12734 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12735 strncmp(buf, "id=", 3) != 0) {
12736 send_resp(dut, conn, SIGMA_ERROR,
12737 "errorCode,Specified BSSID not found");
12738 return 0;
12739 }
12740
12741 pos = strstr(buf, "\nfreq=");
12742 if (!pos) {
12743 send_resp(dut, conn, SIGMA_ERROR,
12744 "errorCode,Channel not found");
12745 return 0;
12746 }
12747 freq = atoi(pos + 6);
12748 chan = freq_to_channel(freq);
12749
12750 pos = strstr(buf, "\nssid=");
12751 if (!pos) {
12752 send_resp(dut, conn, SIGMA_ERROR,
12753 "errorCode,SSID not found");
12754 return 0;
12755 }
12756 ssid = pos + 6;
12757 pos = strchr(ssid, '\n');
12758 if (pos)
12759 *pos = '\0';
12760 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12761 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12762 return 0;
12763}
12764
12765
Jouni Malinenf7222712019-06-13 01:50:21 +030012766static enum sigma_cmd_result cmd_sta_set_systime(struct sigma_dut *dut,
12767 struct sigma_conn *conn,
12768 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012769{
12770#ifdef __linux__
12771 struct timeval tv;
12772 struct tm tm;
12773 time_t t;
12774 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012775 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012776
12777 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
12778
12779 memset(&tm, 0, sizeof(tm));
12780 val = get_param(cmd, "seconds");
12781 if (val)
12782 tm.tm_sec = atoi(val);
12783 val = get_param(cmd, "minutes");
12784 if (val)
12785 tm.tm_min = atoi(val);
12786 val = get_param(cmd, "hours");
12787 if (val)
12788 tm.tm_hour = atoi(val);
12789 val = get_param(cmd, "date");
12790 if (val)
12791 tm.tm_mday = atoi(val);
12792 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012793 if (val) {
12794 v = atoi(val);
12795 if (v < 1 || v > 12) {
12796 send_resp(dut, conn, SIGMA_INVALID,
12797 "errorCode,Invalid month");
12798 return 0;
12799 }
12800 tm.tm_mon = v - 1;
12801 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012802 val = get_param(cmd, "year");
12803 if (val) {
12804 int year = atoi(val);
12805#ifdef ANDROID
12806 if (year > 2035)
12807 year = 2035; /* years beyond 2035 not supported */
12808#endif /* ANDROID */
12809 tm.tm_year = year - 1900;
12810 }
12811 t = mktime(&tm);
12812 if (t == (time_t) -1) {
12813 send_resp(dut, conn, SIGMA_ERROR,
12814 "errorCode,Invalid date or time");
12815 return 0;
12816 }
12817
12818 memset(&tv, 0, sizeof(tv));
12819 tv.tv_sec = t;
12820
12821 if (settimeofday(&tv, NULL) < 0) {
12822 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12823 strerror(errno));
12824 send_resp(dut, conn, SIGMA_ERROR,
12825 "errorCode,Failed to set time");
12826 return 0;
12827 }
12828
12829 return 1;
12830#endif /* __linux__ */
12831
12832 return -1;
12833}
12834
12835
Jouni Malinenf7222712019-06-13 01:50:21 +030012836static enum sigma_cmd_result cmd_sta_osu(struct sigma_dut *dut,
12837 struct sigma_conn *conn,
12838 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012839{
12840 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012841 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012842 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012843 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012844 int res;
12845 struct wpa_ctrl *ctrl;
12846
12847 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012848 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012849
12850 val = get_param(cmd, "ProdESSAssoc");
12851 if (val)
12852 prod_ess_assoc = atoi(val);
12853
12854 kill_dhcp_client(dut, intf);
12855 if (start_dhcp_client(dut, intf) < 0)
12856 return -2;
12857
12858 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12859 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12860 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012861 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012862 prod_ess_assoc ? "" : "-N",
12863 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012864 name ? "'" : "",
12865 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12866 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012867
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012868 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012869 if (run_hs20_osu(dut, buf) < 0) {
12870 FILE *f;
12871
12872 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12873
12874 f = fopen("hs20-osu-client.res", "r");
12875 if (f) {
12876 char resp[400], res[300], *pos;
12877 if (!fgets(res, sizeof(res), f))
12878 res[0] = '\0';
12879 pos = strchr(res, '\n');
12880 if (pos)
12881 *pos = '\0';
12882 fclose(f);
12883 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12884 res);
12885 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12886 if (system(resp) != 0) {
12887 }
12888 snprintf(resp, sizeof(resp),
12889 "SSID,,BSSID,,failureReason,%s", res);
12890 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12891 return 0;
12892 }
12893
12894 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12895 return 0;
12896 }
12897
12898 if (!prod_ess_assoc)
12899 goto report;
12900
12901 ctrl = open_wpa_mon(intf);
12902 if (ctrl == NULL) {
12903 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12904 "wpa_supplicant monitor connection");
12905 return -1;
12906 }
12907
12908 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12909 buf, sizeof(buf));
12910
12911 wpa_ctrl_detach(ctrl);
12912 wpa_ctrl_close(ctrl);
12913
12914 if (res < 0) {
12915 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12916 "network after OSU");
12917 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12918 return 0;
12919 }
12920
12921report:
12922 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12923 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12924 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12925 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12926 return 0;
12927 }
12928
12929 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12930 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012931 return 0;
12932}
12933
12934
Jouni Malinenf7222712019-06-13 01:50:21 +030012935static enum sigma_cmd_result cmd_sta_policy_update(struct sigma_dut *dut,
12936 struct sigma_conn *conn,
12937 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012938{
12939 const char *val;
12940 int timeout = 120;
12941
12942 val = get_param(cmd, "PolicyUpdate");
12943 if (val == NULL || atoi(val) == 0)
12944 return 1; /* No operation requested */
12945
12946 val = get_param(cmd, "Timeout");
12947 if (val)
12948 timeout = atoi(val);
12949
12950 if (timeout) {
12951 /* TODO: time out the command and return
12952 * PolicyUpdateStatus,TIMEOUT if needed. */
12953 }
12954
12955 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12956 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12957 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12958 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12959 return 0;
12960 }
12961
12962 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12963 return 0;
12964}
12965
12966
Jouni Malinenf7222712019-06-13 01:50:21 +030012967static enum sigma_cmd_result cmd_sta_er_config(struct sigma_dut *dut,
12968 struct sigma_conn *conn,
12969 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012970{
12971 struct wpa_ctrl *ctrl;
12972 const char *intf = get_param(cmd, "Interface");
12973 const char *bssid = get_param(cmd, "Bssid");
12974 const char *ssid = get_param(cmd, "SSID");
12975 const char *security = get_param(cmd, "Security");
12976 const char *passphrase = get_param(cmd, "Passphrase");
12977 const char *pin = get_param(cmd, "PIN");
12978 char buf[1000];
12979 char ssid_hex[200], passphrase_hex[200];
12980 const char *keymgmt, *cipher;
12981
12982 if (intf == NULL)
12983 intf = get_main_ifname();
12984
12985 if (!bssid) {
12986 send_resp(dut, conn, SIGMA_ERROR,
12987 "ErrorCode,Missing Bssid argument");
12988 return 0;
12989 }
12990
12991 if (!ssid) {
12992 send_resp(dut, conn, SIGMA_ERROR,
12993 "ErrorCode,Missing SSID argument");
12994 return 0;
12995 }
12996
12997 if (!security) {
12998 send_resp(dut, conn, SIGMA_ERROR,
12999 "ErrorCode,Missing Security argument");
13000 return 0;
13001 }
13002
13003 if (!passphrase) {
13004 send_resp(dut, conn, SIGMA_ERROR,
13005 "ErrorCode,Missing Passphrase argument");
13006 return 0;
13007 }
13008
13009 if (!pin) {
13010 send_resp(dut, conn, SIGMA_ERROR,
13011 "ErrorCode,Missing PIN argument");
13012 return 0;
13013 }
13014
vamsi krishna8c9c1562017-05-12 15:51:46 +053013015 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
13016 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013017 send_resp(dut, conn, SIGMA_ERROR,
13018 "ErrorCode,Too long SSID/passphrase");
13019 return 0;
13020 }
13021
13022 ctrl = open_wpa_mon(intf);
13023 if (ctrl == NULL) {
13024 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13025 "wpa_supplicant monitor connection");
13026 return -2;
13027 }
13028
13029 if (strcasecmp(security, "wpa2-psk") == 0) {
13030 keymgmt = "WPA2PSK";
13031 cipher = "CCMP";
13032 } else {
13033 wpa_ctrl_detach(ctrl);
13034 wpa_ctrl_close(ctrl);
13035 send_resp(dut, conn, SIGMA_ERROR,
13036 "ErrorCode,Unsupported Security value");
13037 return 0;
13038 }
13039
13040 ascii2hexstr(ssid, ssid_hex);
13041 ascii2hexstr(passphrase, passphrase_hex);
13042 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
13043 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
13044
13045 if (wpa_command(intf, buf) < 0) {
13046 wpa_ctrl_detach(ctrl);
13047 wpa_ctrl_close(ctrl);
13048 send_resp(dut, conn, SIGMA_ERROR,
13049 "ErrorCode,Failed to start registrar");
13050 return 0;
13051 }
13052
13053 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
13054 dut->er_oper_performed = 1;
13055
13056 return wps_connection_event(dut, conn, ctrl, intf, 0);
13057}
13058
13059
Jouni Malinenf7222712019-06-13 01:50:21 +030013060static enum sigma_cmd_result
13061cmd_sta_wps_connect_pw_token(struct sigma_dut *dut, struct sigma_conn *conn,
13062 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013063{
13064 struct wpa_ctrl *ctrl;
13065 const char *intf = get_param(cmd, "Interface");
13066 const char *bssid = get_param(cmd, "Bssid");
13067 char buf[100];
13068
13069 if (!bssid) {
13070 send_resp(dut, conn, SIGMA_ERROR,
13071 "ErrorCode,Missing Bssid argument");
13072 return 0;
13073 }
13074
13075 ctrl = open_wpa_mon(intf);
13076 if (ctrl == NULL) {
13077 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
13078 "wpa_supplicant monitor connection");
13079 return -2;
13080 }
13081
13082 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
13083
13084 if (wpa_command(intf, buf) < 0) {
13085 wpa_ctrl_detach(ctrl);
13086 wpa_ctrl_close(ctrl);
13087 send_resp(dut, conn, SIGMA_ERROR,
13088 "ErrorCode,Failed to start registrar");
13089 return 0;
13090 }
13091
13092 return wps_connection_event(dut, conn, ctrl, intf, 0);
13093}
13094
13095
Jouni Malinenf7222712019-06-13 01:50:21 +030013096static enum sigma_cmd_result cmd_start_wps_registration(struct sigma_dut *dut,
13097 struct sigma_conn *conn,
13098 struct sigma_cmd *cmd)
vamsi krishna9b144002017-09-20 13:28:13 +053013099{
13100 struct wpa_ctrl *ctrl;
13101 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013102 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013103 const char *config_method = get_param(cmd, "WPSConfigMethod");
13104 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053013105 int res;
13106 char buf[256];
13107 const char *events[] = {
13108 "CTRL-EVENT-CONNECTED",
13109 "WPS-OVERLAP-DETECTED",
13110 "WPS-TIMEOUT",
13111 "WPS-FAIL",
13112 NULL
13113 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013114 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053013115
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013116 /* 60G WPS tests do not pass Interface parameter */
13117 if (!intf)
13118 intf = get_main_ifname();
13119
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013120 if (dut->mode == SIGMA_MODE_AP)
13121 return ap_wps_registration(dut, conn, cmd);
13122
13123 if (config_method) {
13124 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
13125 * sta_wps_enter_pin before calling start_wps_registration. */
13126 if (strcasecmp(config_method, "PBC") == 0)
13127 dut->wps_method = WFA_CS_WPS_PBC;
13128 }
13129 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
13130 send_resp(dut, conn, SIGMA_ERROR,
13131 "ErrorCode,WPS parameters not yet set");
13132 return STATUS_SENT;
13133 }
13134
13135 /* Make sure WPS is enabled (also for STA mode) */
13136 dut->wps_disable = 0;
13137
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020013138 if (dut->band == WPS_BAND_60G && network_mode &&
13139 strcasecmp(network_mode, "PBSS") == 0) {
13140 sigma_dut_print(dut, DUT_MSG_DEBUG,
13141 "Set PBSS network mode, network id %d", id);
13142 if (set_network(get_station_ifname(), id, "pbss", "1") < 0)
13143 return -2;
13144 }
13145
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013146 if (dut->force_rsn_ie) {
13147 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
13148 dut->force_rsn_ie);
13149 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
13150 sigma_dut_print(dut, DUT_MSG_INFO,
13151 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020013152 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020013153 }
13154 }
13155
vamsi krishna9b144002017-09-20 13:28:13 +053013156 ctrl = open_wpa_mon(intf);
13157 if (!ctrl) {
13158 sigma_dut_print(dut, DUT_MSG_ERROR,
13159 "Failed to open wpa_supplicant monitor connection");
13160 return -2;
13161 }
13162
13163 role = get_param(cmd, "WpsRole");
13164 if (!role) {
13165 send_resp(dut, conn, SIGMA_INVALID,
13166 "ErrorCode,WpsRole not provided");
13167 goto fail;
13168 }
13169
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013170 if (strcasecmp(role, "Enrollee") != 0) {
13171 /* Registrar role for STA not supported */
13172 send_resp(dut, conn, SIGMA_ERROR,
13173 "ErrorCode,Unsupported WpsRole value");
13174 goto fail;
13175 }
13176
13177 if (is_60g_sigma_dut(dut)) {
13178 if (dut->wps_method == WFA_CS_WPS_PBC)
13179 snprintf(buf, sizeof(buf), "WPS_PBC");
13180 else /* WFA_CS_WPS_PIN_KEYPAD */
13181 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13182 dut->wps_pin);
13183 if (wpa_command(intf, buf) < 0) {
13184 send_resp(dut, conn, SIGMA_ERROR,
13185 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013186 goto fail;
13187 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013188 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13189 if (res < 0) {
13190 send_resp(dut, conn, SIGMA_ERROR,
13191 "ErrorCode,WPS connection did not complete");
13192 goto fail;
13193 }
13194 if (strstr(buf, "WPS-TIMEOUT")) {
13195 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13196 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13197 send_resp(dut, conn, SIGMA_COMPLETE,
13198 "WpsState,OverlapSession");
13199 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13200 send_resp(dut, conn, SIGMA_COMPLETE,
13201 "WpsState,Successful");
13202 } else {
13203 send_resp(dut, conn, SIGMA_COMPLETE,
13204 "WpsState,Failure");
13205 }
13206 } else {
13207 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013208 if (wpa_command(intf, "WPS_PBC") < 0) {
13209 send_resp(dut, conn, SIGMA_ERROR,
13210 "ErrorCode,Failed to enable PBC");
13211 goto fail;
13212 }
13213 } else {
13214 /* TODO: PIN method */
13215 send_resp(dut, conn, SIGMA_ERROR,
13216 "ErrorCode,Unsupported WpsConfigMethod value");
13217 goto fail;
13218 }
13219 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13220 if (res < 0) {
13221 send_resp(dut, conn, SIGMA_ERROR,
13222 "ErrorCode,WPS connection did not complete");
13223 goto fail;
13224 }
13225 if (strstr(buf, "WPS-TIMEOUT")) {
13226 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13227 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13228 send_resp(dut, conn, SIGMA_ERROR,
13229 "ErrorCode,OverlapSession");
13230 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13231 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13232 } else {
13233 send_resp(dut, conn, SIGMA_ERROR,
13234 "ErrorCode,WPS operation failed");
13235 }
vamsi krishna9b144002017-09-20 13:28:13 +053013236 }
13237
13238fail:
13239 wpa_ctrl_detach(ctrl);
13240 wpa_ctrl_close(ctrl);
13241 return 0;
13242}
13243
13244
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013245static int req_intf(struct sigma_cmd *cmd)
13246{
13247 return get_param(cmd, "interface") == NULL ? -1 : 0;
13248}
13249
13250
13251void sta_register_cmds(void)
13252{
13253 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13254 cmd_sta_get_ip_config);
13255 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13256 cmd_sta_set_ip_config);
13257 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13258 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13259 cmd_sta_get_mac_address);
13260 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13261 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13262 cmd_sta_verify_ip_connection);
13263 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13264 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13265 cmd_sta_set_encryption);
13266 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13267 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13268 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13269 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13270 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13271 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13272 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13273 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13274 cmd_sta_set_eapakaprime);
13275 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13276 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13277 /* TODO: sta_set_ibss */
13278 /* TODO: sta_set_mode */
13279 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13280 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13281 /* TODO: sta_up_load */
13282 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13283 cmd_sta_preset_testparameters);
13284 /* TODO: sta_set_system */
13285 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13286 /* TODO: sta_set_rifs_test */
13287 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13288 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13289 /* TODO: sta_send_coexist_mgmt */
13290 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13291 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13292 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13293 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13294 cmd_sta_reset_default);
13295 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13296 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13297 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13298 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13299 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013300 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013301 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13302 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13303 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13304 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13305 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013306 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13307 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013308 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13309 cmd_sta_add_credential);
13310 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013311 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013312 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13313 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13314 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13315 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13316 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13317 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013318 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013319 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13320 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013321 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013322 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013323}