blob: 39371db58d0a6495a206d1dddd58b821aa7720b1 [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
1102static int cmd_sta_get_ip_config(struct sigma_dut *dut,
1103 struct sigma_conn *conn,
1104 struct sigma_cmd *cmd)
1105{
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 Malinencd4e3c32015-10-29 12:39:56 +02001377static int cmd_sta_set_ip_config(struct sigma_dut *dut,
1378 struct sigma_conn *conn,
1379 struct sigma_cmd *cmd)
1380{
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
1548static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1549 struct sigma_cmd *cmd)
1550{
1551 /* const char *intf = get_param(cmd, "Interface"); */
1552 /* TODO: could report more details here */
1553 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1554 return 0;
1555}
1556
1557
1558static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1559 struct sigma_conn *conn,
1560 struct sigma_cmd *cmd)
1561{
1562 /* const char *intf = get_param(cmd, "Interface"); */
1563 char addr[20], resp[50];
1564
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301565 if (dut->dev_role == DEVROLE_STA_CFON)
1566 return sta_cfon_get_mac_address(dut, conn, cmd);
1567
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001568 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1569 < 0)
1570 return -2;
1571
1572 snprintf(resp, sizeof(resp), "mac,%s", addr);
1573 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1574 return 0;
1575}
1576
1577
1578static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1579 struct sigma_cmd *cmd)
1580{
1581 /* const char *intf = get_param(cmd, "Interface"); */
1582 int connected = 0;
1583 char result[32];
1584 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1585 sizeof(result)) < 0) {
1586 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1587 "%s status", get_station_ifname());
1588 return -2;
1589 }
1590
1591 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1592 if (strncmp(result, "COMPLETED", 9) == 0)
1593 connected = 1;
1594
1595 if (connected)
1596 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1597 else
1598 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1599
1600 return 0;
1601}
1602
1603
1604static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1605 struct sigma_conn *conn,
1606 struct sigma_cmd *cmd)
1607{
1608 /* const char *intf = get_param(cmd, "Interface"); */
1609 const char *dst, *timeout;
1610 int wait_time = 90;
1611 char buf[100];
1612 int res;
1613
1614 dst = get_param(cmd, "destination");
1615 if (dst == NULL || !is_ip_addr(dst))
1616 return -1;
1617
1618 timeout = get_param(cmd, "timeout");
1619 if (timeout) {
1620 wait_time = atoi(timeout);
1621 if (wait_time < 1)
1622 wait_time = 1;
1623 }
1624
1625 /* TODO: force renewal of IP lease if DHCP is enabled */
1626
1627 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1628 res = system(buf);
1629 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1630 if (res == 0)
1631 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1632 else if (res == 256)
1633 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1634 else
1635 return -2;
1636
1637 return 0;
1638}
1639
1640
1641static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1642 struct sigma_cmd *cmd)
1643{
1644 /* const char *intf = get_param(cmd, "Interface"); */
1645 char bssid[20], resp[50];
1646
1647 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1648 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001649 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001650
1651 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1652 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1653 return 0;
1654}
1655
1656
1657#ifdef __SAMSUNG__
1658static int add_use_network(const char *ifname)
1659{
1660 char buf[100];
1661
1662 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1663 wpa_command(ifname, buf);
1664 return 0;
1665}
1666#endif /* __SAMSUNG__ */
1667
1668
1669static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1670 const char *ifname, struct sigma_cmd *cmd)
1671{
1672 const char *ssid = get_param(cmd, "ssid");
1673 int id;
1674 const char *val;
1675
1676 if (ssid == NULL)
1677 return -1;
1678
1679 start_sta_mode(dut);
1680
1681#ifdef __SAMSUNG__
1682 add_use_network(ifname);
1683#endif /* __SAMSUNG__ */
1684
1685 id = add_network(ifname);
1686 if (id < 0)
1687 return -2;
1688 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1689
1690 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1691 return -2;
1692
1693 dut->infra_network_id = id;
1694 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1695
1696 val = get_param(cmd, "program");
1697 if (!val)
1698 val = get_param(cmd, "prog");
1699 if (val && strcasecmp(val, "hs2") == 0) {
1700 char buf[100];
1701 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1702 wpa_command(ifname, buf);
1703
1704 val = get_param(cmd, "prefer");
1705 if (val && atoi(val) > 0)
1706 set_network(ifname, id, "priority", "1");
1707 }
1708
1709 return id;
1710}
1711
1712
1713static int cmd_sta_set_encryption(struct sigma_dut *dut,
1714 struct sigma_conn *conn,
1715 struct sigma_cmd *cmd)
1716{
1717 const char *intf = get_param(cmd, "Interface");
1718 const char *ssid = get_param(cmd, "ssid");
1719 const char *type = get_param(cmd, "encpType");
1720 const char *ifname;
1721 char buf[200];
1722 int id;
1723
1724 if (intf == NULL || ssid == NULL)
1725 return -1;
1726
1727 if (strcmp(intf, get_main_ifname()) == 0)
1728 ifname = get_station_ifname();
1729 else
1730 ifname = intf;
1731
1732 id = add_network_common(dut, conn, ifname, cmd);
1733 if (id < 0)
1734 return id;
1735
1736 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1737 return -2;
1738
1739 if (type && strcasecmp(type, "wep") == 0) {
1740 const char *val;
1741 int i;
1742
1743 val = get_param(cmd, "activeKey");
1744 if (val) {
1745 int keyid;
1746 keyid = atoi(val);
1747 if (keyid < 1 || keyid > 4)
1748 return -1;
1749 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1750 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1751 return -2;
1752 }
1753
1754 for (i = 0; i < 4; i++) {
1755 snprintf(buf, sizeof(buf), "key%d", i + 1);
1756 val = get_param(cmd, buf);
1757 if (val == NULL)
1758 continue;
1759 snprintf(buf, sizeof(buf), "wep_key%d", i);
1760 if (set_network(ifname, id, buf, val) < 0)
1761 return -2;
1762 }
1763 }
1764
1765 return 1;
1766}
1767
1768
Jouni Malinene4fde732019-03-25 22:29:37 +02001769static int set_akm_suites(struct sigma_dut *dut, const char *ifname,
1770 int id, const char *val)
1771{
1772 char key_mgmt[200], *end, *pos;
1773 const char *in_pos = val;
1774
Jouni Malinen8179fee2019-03-28 03:19:47 +02001775 dut->akm_values = 0;
Jouni Malinene4fde732019-03-25 22:29:37 +02001776 pos = key_mgmt;
1777 end = pos + sizeof(key_mgmt);
1778 while (*in_pos) {
1779 int res, akm = atoi(in_pos);
1780 const char *str;
1781
Jouni Malinen8179fee2019-03-28 03:19:47 +02001782 if (akm >= 0 && akm < 32)
1783 dut->akm_values |= 1 << akm;
1784
Jouni Malinene4fde732019-03-25 22:29:37 +02001785 switch (akm) {
1786 case AKM_WPA_EAP:
1787 str = "WPA-EAP";
1788 break;
1789 case AKM_WPA_PSK:
1790 str = "WPA-PSK";
1791 break;
1792 case AKM_FT_EAP:
1793 str = "FT-EAP";
1794 break;
1795 case AKM_FT_PSK:
1796 str = "FT-PSK";
1797 break;
1798 case AKM_EAP_SHA256:
1799 str = "WPA-EAP-SHA256";
1800 break;
1801 case AKM_PSK_SHA256:
1802 str = "WPA-PSK-SHA256";
1803 break;
1804 case AKM_SAE:
1805 str = "SAE";
1806 break;
1807 case AKM_FT_SAE:
1808 str = "FT-SAE";
1809 break;
1810 case AKM_SUITE_B:
1811 str = "WPA-EAP-SUITE-B-192";
1812 break;
1813 case AKM_FT_SUITE_B:
1814 str = "FT-EAP-SHA384";
1815 break;
1816 case AKM_FILS_SHA256:
1817 str = "FILS-SHA256";
1818 break;
1819 case AKM_FILS_SHA384:
1820 str = "FILS-SHA384";
1821 break;
1822 case AKM_FT_FILS_SHA256:
1823 str = "FT-FILS-SHA256";
1824 break;
1825 case AKM_FT_FILS_SHA384:
1826 str = "FT-FILS-SHA384";
1827 break;
1828 default:
1829 sigma_dut_print(dut, DUT_MSG_ERROR,
1830 "Unsupported AKMSuitetype %d", akm);
1831 return -1;
1832 }
1833
1834 res = snprintf(pos, end - pos, "%s%s",
1835 pos == key_mgmt ? "" : " ", str);
1836 if (res < 0 || res >= end - pos)
1837 return -1;
1838 pos += res;
1839
1840 in_pos = strchr(in_pos, ';');
1841 if (!in_pos)
1842 break;
1843 while (*in_pos == ';')
1844 in_pos++;
1845 }
1846 sigma_dut_print(dut, DUT_MSG_DEBUG, "AKMSuiteType %s --> %s",
1847 val, key_mgmt);
1848 return set_network(ifname, id, "key_mgmt", key_mgmt);
1849}
1850
1851
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001852static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1853 const char *ifname, struct sigma_cmd *cmd)
1854{
1855 const char *val;
1856 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001857 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001858 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301859 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001860
1861 id = add_network_common(dut, conn, ifname, cmd);
1862 if (id < 0)
1863 return id;
1864
Jouni Malinen47dcc952017-10-09 16:43:24 +03001865 val = get_param(cmd, "Type");
1866 owe = val && strcasecmp(val, "OWE") == 0;
1867
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001868 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001869 if (!val && owe)
1870 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001871 if (val == NULL) {
Jouni Malinene4fde732019-03-25 22:29:37 +02001872 /* keyMgmtType is being replaced with AKMSuiteType, so ignore
1873 * this missing parameter and assume proto=WPA2. */
1874 if (set_network(ifname, id, "proto", "WPA2") < 0)
1875 return ERROR_SEND_STATUS;
1876 } else if (strcasecmp(val, "wpa") == 0 ||
1877 strcasecmp(val, "wpa-psk") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001878 if (set_network(ifname, id, "proto", "WPA") < 0)
1879 return -2;
1880 } else if (strcasecmp(val, "wpa2") == 0 ||
1881 strcasecmp(val, "wpa2-psk") == 0 ||
1882 strcasecmp(val, "wpa2-ft") == 0 ||
1883 strcasecmp(val, "wpa2-sha256") == 0) {
1884 if (set_network(ifname, id, "proto", "WPA2") < 0)
1885 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301886 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1887 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001888 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1889 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001890 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301891 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001892 if (set_network(ifname, id, "proto", "WPA2") < 0)
1893 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001894 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001895 } else {
1896 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1897 return 0;
1898 }
1899
1900 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001901 if (val) {
1902 cipher_set = 1;
1903 if (strcasecmp(val, "tkip") == 0) {
1904 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1905 return -2;
1906 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1907 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1908 return -2;
1909 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1910 if (set_network(ifname, id, "pairwise",
1911 "CCMP TKIP") < 0)
1912 return -2;
1913 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1914 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1915 return -2;
1916 if (set_network(ifname, id, "group", "GCMP") < 0)
1917 return -2;
1918 } else {
1919 send_resp(dut, conn, SIGMA_ERROR,
1920 "errorCode,Unrecognized encpType value");
1921 return 0;
1922 }
1923 }
1924
1925 val = get_param(cmd, "PairwiseCipher");
1926 if (val) {
1927 cipher_set = 1;
1928 /* TODO: Support space separated list */
1929 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1930 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1931 return -2;
1932 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1933 if (set_network(ifname, id, "pairwise",
1934 "CCMP-256") < 0)
1935 return -2;
1936 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1937 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1938 return -2;
1939 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1940 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1941 return -2;
1942 } else {
1943 send_resp(dut, conn, SIGMA_ERROR,
1944 "errorCode,Unrecognized PairwiseCipher value");
1945 return 0;
1946 }
1947 }
1948
Jouni Malinen47dcc952017-10-09 16:43:24 +03001949 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001950 send_resp(dut, conn, SIGMA_ERROR,
1951 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001952 return 0;
1953 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001954
1955 val = get_param(cmd, "GroupCipher");
1956 if (val) {
1957 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1958 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1959 return -2;
1960 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1961 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1962 return -2;
1963 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1964 if (set_network(ifname, id, "group", "GCMP") < 0)
1965 return -2;
1966 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1967 if (set_network(ifname, id, "group", "CCMP") < 0)
1968 return -2;
1969 } else {
1970 send_resp(dut, conn, SIGMA_ERROR,
1971 "errorCode,Unrecognized GroupCipher value");
1972 return 0;
1973 }
1974 }
1975
Jouni Malinen7b239522017-09-14 21:37:18 +03001976 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001977 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001978 const char *cipher;
1979
1980 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1981 cipher = "BIP-GMAC-256";
1982 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1983 cipher = "BIP-CMAC-256";
1984 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1985 cipher = "BIP-GMAC-128";
1986 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1987 cipher = "AES-128-CMAC";
1988 } else {
1989 send_resp(dut, conn, SIGMA_INVALID,
1990 "errorCode,Unsupported GroupMgntCipher");
1991 return 0;
1992 }
1993 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1994 send_resp(dut, conn, SIGMA_INVALID,
1995 "errorCode,Failed to set GroupMgntCipher");
1996 return 0;
1997 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001998 }
1999
Jouni Malinene4fde732019-03-25 22:29:37 +02002000 val = get_param(cmd, "AKMSuiteType");
2001 if (val && set_akm_suites(dut, ifname, id, val) < 0)
2002 return ERROR_SEND_STATUS;
2003
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002004 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302005
2006 if (dut->program == PROGRAM_OCE) {
2007 dut->sta_pmf = STA_PMF_OPTIONAL;
2008 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2009 return -2;
2010 }
2011
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002012 val = get_param(cmd, "PMF");
2013 if (val) {
2014 if (strcasecmp(val, "Required") == 0 ||
2015 strcasecmp(val, "Forced_Required") == 0) {
2016 dut->sta_pmf = STA_PMF_REQUIRED;
2017 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2018 return -2;
2019 } else if (strcasecmp(val, "Optional") == 0) {
2020 dut->sta_pmf = STA_PMF_OPTIONAL;
2021 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2022 return -2;
2023 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08002024 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002025 strcasecmp(val, "Forced_Disabled") == 0) {
2026 dut->sta_pmf = STA_PMF_DISABLED;
2027 } else {
2028 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
2029 return 0;
2030 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05302031 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02002032 dut->sta_pmf = STA_PMF_REQUIRED;
2033 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2034 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002035 }
2036
2037 return id;
2038}
2039
2040
2041static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
2042 struct sigma_cmd *cmd)
2043{
2044 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03002045 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02002046 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002047 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinene4fde732019-03-25 22:29:37 +02002048 const char *akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002049 const char *ifname, *val, *alg;
2050 int id;
2051
2052 if (intf == NULL)
2053 return -1;
2054
2055 if (strcmp(intf, get_main_ifname()) == 0)
2056 ifname = get_station_ifname();
2057 else
2058 ifname = intf;
2059
2060 id = set_wpa_common(dut, conn, ifname, cmd);
2061 if (id < 0)
2062 return id;
2063
2064 val = get_param(cmd, "keyMgmtType");
2065 alg = get_param(cmd, "micAlg");
2066
Jouni Malinen992a81e2017-08-22 13:57:47 +03002067 if (type && strcasecmp(type, "SAE") == 0) {
Jouni Malinene4fde732019-03-25 22:29:37 +02002068 if (!akm && val && strcasecmp(val, "wpa2-ft") == 0) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002069 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
2070 return -2;
Jouni Malinene4fde732019-03-25 22:29:37 +02002071 } else if (!akm) {
Jouni Malinen992a81e2017-08-22 13:57:47 +03002072 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
2073 return -2;
2074 }
2075 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2076 sigma_dut_print(dut, DUT_MSG_ERROR,
2077 "Failed to clear sae_groups to default");
2078 return -2;
2079 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002080 if (!pmf) {
2081 dut->sta_pmf = STA_PMF_REQUIRED;
2082 if (set_network(ifname, id, "ieee80211w", "2") < 0)
2083 return -2;
2084 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002085 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
2086 if (val && strcasecmp(val, "wpa2-ft") == 0) {
2087 if (set_network(ifname, id, "key_mgmt",
2088 "FT-SAE FT-PSK") < 0)
2089 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002090 } else if (!akm) {
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002091 if (set_network(ifname, id, "key_mgmt",
2092 "SAE WPA-PSK") < 0)
2093 return -2;
2094 }
2095 if (wpa_command(ifname, "SET sae_groups ") != 0) {
2096 sigma_dut_print(dut, DUT_MSG_ERROR,
2097 "Failed to clear sae_groups to default");
2098 return -2;
2099 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02002100 if (!pmf) {
2101 dut->sta_pmf = STA_PMF_OPTIONAL;
2102 if (set_network(ifname, id, "ieee80211w", "1") < 0)
2103 return -2;
2104 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03002105 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002106 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
2107 return -2;
2108 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2109 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2110 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05302111 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2112 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
2113 return -2;
Jouni Malinen3b73d872019-06-12 03:13:25 +03002114 } else if (!akm &&
2115 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2116 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002117 if (set_network(ifname, id, "key_mgmt",
2118 "WPA-PSK WPA-PSK-SHA256") < 0)
2119 return -2;
Jouni Malinen77ff3f02019-03-28 03:45:40 +02002120 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
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) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002125 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
2126 return -2;
2127 }
2128
2129 val = get_param(cmd, "passPhrase");
2130 if (val == NULL)
2131 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03002132 if (type && strcasecmp(type, "SAE") == 0) {
2133 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
2134 return -2;
2135 } else {
2136 if (set_network_quoted(ifname, id, "psk", val) < 0)
2137 return -2;
2138 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002139
Jouni Malinen78d10c42019-03-25 22:34:32 +02002140 val = get_param(cmd, "PasswordId");
2141 if (val && set_network_quoted(ifname, id, "sae_password_id", val) < 0)
2142 return ERROR_SEND_STATUS;
2143
Jouni Malinen992a81e2017-08-22 13:57:47 +03002144 val = get_param(cmd, "ECGroupID");
2145 if (val) {
2146 char buf[50];
2147
2148 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
2149 if (wpa_command(ifname, buf) != 0) {
2150 sigma_dut_print(dut, DUT_MSG_ERROR,
2151 "Failed to clear sae_groups");
2152 return -2;
2153 }
2154 }
2155
Jouni Malinen68143132017-09-02 02:34:08 +03002156 val = get_param(cmd, "InvalidSAEElement");
2157 if (val) {
2158 free(dut->sae_commit_override);
2159 dut->sae_commit_override = strdup(val);
2160 }
2161
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002162 if (dut->program == PROGRAM_60GHZ && network_mode &&
2163 strcasecmp(network_mode, "PBSS") == 0 &&
2164 set_network(ifname, id, "pbss", "1") < 0)
2165 return -2;
2166
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002167 return 1;
2168}
2169
2170
2171static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302172 const char *ifname, int username_identity,
2173 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002174{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302175 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002176 int id;
Jouni Malinen53264f62019-05-03 13:04:40 +03002177 char buf[200], buf2[300];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002178#ifdef ANDROID
2179 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2180 int length;
2181#endif /* ANDROID */
Jouni Malinen8179fee2019-03-28 03:19:47 +02002182 int erp = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002183
2184 id = set_wpa_common(dut, conn, ifname, cmd);
2185 if (id < 0)
2186 return id;
2187
2188 val = get_param(cmd, "keyMgmtType");
2189 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302190 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002191
Jouni Malinenad395a22017-09-01 21:13:46 +03002192 if (val && strcasecmp(val, "SuiteB") == 0) {
2193 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
2194 0)
2195 return -2;
2196 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002197 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
2198 return -2;
2199 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
2200 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2201 return -2;
2202 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
2203 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
2204 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002205 } else if (!akm &&
2206 ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
2207 dut->sta_pmf == STA_PMF_REQUIRED)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002208 if (set_network(ifname, id, "key_mgmt",
2209 "WPA-EAP WPA-EAP-SHA256") < 0)
2210 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302211 } else if (akm && atoi(akm) == 14) {
2212 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2213 dut->sta_pmf == STA_PMF_REQUIRED) {
2214 if (set_network(ifname, id, "key_mgmt",
2215 "WPA-EAP-SHA256 FILS-SHA256") < 0)
2216 return -2;
2217 } else {
2218 if (set_network(ifname, id, "key_mgmt",
2219 "WPA-EAP FILS-SHA256") < 0)
2220 return -2;
2221 }
2222
Jouni Malinen8179fee2019-03-28 03:19:47 +02002223 erp = 1;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05302224 } else if (akm && atoi(akm) == 15) {
2225 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
2226 dut->sta_pmf == STA_PMF_REQUIRED) {
2227 if (set_network(ifname, id, "key_mgmt",
2228 "WPA-EAP-SHA256 FILS-SHA384") < 0)
2229 return -2;
2230 } else {
2231 if (set_network(ifname, id, "key_mgmt",
2232 "WPA-EAP FILS-SHA384") < 0)
2233 return -2;
2234 }
2235
Jouni Malinen8179fee2019-03-28 03:19:47 +02002236 erp = 1;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002237 } else if (!akm && dut->sta_pmf == STA_PMF_OPTIONAL) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002238 if (set_network(ifname, id, "key_mgmt",
2239 "WPA-EAP WPA-EAP-SHA256") < 0)
2240 return -2;
Jouni Malinend6a9d692019-03-28 03:01:24 +02002241 } else if (!akm) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002242 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
2243 return -2;
2244 }
2245
2246 val = get_param(cmd, "trustedRootCA");
2247 if (val) {
2248#ifdef ANDROID
2249 snprintf(buf, sizeof(buf), "CACERT_%s", val);
2250 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
2251 kvalue);
2252 if (length > 0) {
2253 sigma_dut_print(dut, DUT_MSG_INFO,
2254 "Use Android keystore [%s]", buf);
2255 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
2256 val);
2257 goto ca_cert_selected;
2258 }
2259#endif /* ANDROID */
2260
2261 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2262#ifdef __linux__
2263 if (!file_exists(buf)) {
2264 char msg[300];
2265 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
2266 "file (%s) not found", buf);
2267 send_resp(dut, conn, SIGMA_ERROR, msg);
2268 return -3;
2269 }
2270#endif /* __linux__ */
2271#ifdef ANDROID
2272ca_cert_selected:
2273#endif /* ANDROID */
2274 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
2275 return -2;
2276 }
2277
Jouni Malinen53264f62019-05-03 13:04:40 +03002278 val = get_param(cmd, "ServerCert");
2279 if (val) {
2280 FILE *f;
2281 char *result = NULL, *pos;
2282
2283 snprintf(buf, sizeof(buf), "%s/%s.sha256", sigma_cert_path,
2284 val);
2285 f = fopen(buf, "r");
2286 if (f) {
2287 result = fgets(buf, sizeof(buf), f);
2288 fclose(f);
2289 }
2290 if (!result) {
2291 snprintf(buf2, sizeof(buf2),
2292 "ErrorCode,ServerCert hash could not be read from %s",
2293 buf);
2294 send_resp(dut, conn, SIGMA_ERROR, buf2);
2295 return STATUS_SENT_ERROR;
2296 }
2297 pos = strchr(buf, '\n');
2298 if (pos)
2299 *pos = '\0';
2300 snprintf(buf2, sizeof(buf2), "hash://server/sha256/%s", buf);
2301 if (set_network_quoted(ifname, id, "ca_cert", buf2) < 0)
2302 return ERROR_SEND_STATUS;
2303 }
2304
Jouni Malinen96f84b02019-05-03 12:32:56 +03002305 val = get_param(cmd, "Domain");
2306 if (val && set_network_quoted(ifname, id, "domain_match", val) < 0)
2307 return ERROR_SEND_STATUS;
2308
2309 val = get_param(cmd, "DomainSuffix");
2310 if (val &&
2311 set_network_quoted(ifname, id, "domain_suffix_match", val) < 0)
2312 return ERROR_SEND_STATUS;
2313
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302314 if (username_identity) {
2315 val = get_param(cmd, "username");
2316 if (val) {
2317 if (set_network_quoted(ifname, id, "identity", val) < 0)
2318 return -2;
2319 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002320
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302321 val = get_param(cmd, "password");
2322 if (val) {
2323 if (set_network_quoted(ifname, id, "password", val) < 0)
2324 return -2;
2325 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002326 }
2327
Jouni Malinen8179fee2019-03-28 03:19:47 +02002328 if (dut->akm_values &
2329 ((1 << AKM_FILS_SHA256) |
2330 (1 << AKM_FILS_SHA384) |
2331 (1 << AKM_FT_FILS_SHA256) |
2332 (1 << AKM_FT_FILS_SHA384)))
2333 erp = 1;
2334 if (erp && set_network(ifname, id, "erp", "1") < 0)
2335 return ERROR_SEND_STATUS;
2336
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002337 return id;
2338}
2339
2340
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002341static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2342{
2343 const char *val;
2344
2345 if (!cipher)
2346 return 0;
2347
2348 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2349 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2350 else if (strcasecmp(cipher,
2351 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2352 val = "ECDHE-RSA-AES256-GCM-SHA384";
2353 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2354 val = "DHE-RSA-AES256-GCM-SHA384";
2355 else if (strcasecmp(cipher,
2356 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2357 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2358 else
2359 return -1;
2360
2361 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2362 set_network_quoted(ifname, id, "phase1", "");
2363
2364 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2365}
2366
2367
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002368static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
2369 struct sigma_cmd *cmd)
2370{
2371 const char *intf = get_param(cmd, "Interface");
2372 const char *ifname, *val;
2373 int id;
2374 char buf[200];
2375#ifdef ANDROID
2376 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2377 int length;
2378 int jb_or_newer = 0;
2379 char prop[PROPERTY_VALUE_MAX];
2380#endif /* ANDROID */
2381
2382 if (intf == NULL)
2383 return -1;
2384
2385 if (strcmp(intf, get_main_ifname()) == 0)
2386 ifname = get_station_ifname();
2387 else
2388 ifname = intf;
2389
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302390 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002391 if (id < 0)
2392 return id;
2393
2394 if (set_network(ifname, id, "eap", "TLS") < 0)
2395 return -2;
2396
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302397 if (!get_param(cmd, "username") &&
2398 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002399 "wifi-user@wifilabs.local") < 0)
2400 return -2;
2401
2402 val = get_param(cmd, "clientCertificate");
2403 if (val == NULL)
2404 return -1;
2405#ifdef ANDROID
2406 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2407 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2408 if (length < 0) {
2409 /*
2410 * JB started reporting keystore type mismatches, so retry with
2411 * the GET_PUBKEY command if the generic GET fails.
2412 */
2413 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2414 buf, kvalue);
2415 }
2416
2417 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2418 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2419 if (strncmp(prop, "4.0", 3) != 0)
2420 jb_or_newer = 1;
2421 } else
2422 jb_or_newer = 1; /* assume newer */
2423
2424 if (jb_or_newer && length > 0) {
2425 sigma_dut_print(dut, DUT_MSG_INFO,
2426 "Use Android keystore [%s]", buf);
2427 if (set_network(ifname, id, "engine", "1") < 0)
2428 return -2;
2429 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2430 return -2;
2431 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2432 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2433 return -2;
2434 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2435 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2436 return -2;
2437 return 1;
2438 } else if (length > 0) {
2439 sigma_dut_print(dut, DUT_MSG_INFO,
2440 "Use Android keystore [%s]", buf);
2441 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2442 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2443 return -2;
2444 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2445 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2446 return -2;
2447 return 1;
2448 }
2449#endif /* ANDROID */
2450
2451 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2452#ifdef __linux__
2453 if (!file_exists(buf)) {
2454 char msg[300];
2455 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2456 "(%s) not found", buf);
2457 send_resp(dut, conn, SIGMA_ERROR, msg);
2458 return -3;
2459 }
2460#endif /* __linux__ */
2461 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2462 return -2;
2463 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2464 return -2;
2465
2466 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2467 return -2;
2468
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002469 val = get_param(cmd, "keyMgmtType");
2470 if (val && strcasecmp(val, "SuiteB") == 0) {
2471 val = get_param(cmd, "CertType");
2472 if (val && strcasecmp(val, "RSA") == 0) {
2473 if (set_network_quoted(ifname, id, "phase1",
2474 "tls_suiteb=1") < 0)
2475 return -2;
2476 } else {
2477 if (set_network_quoted(ifname, id, "openssl_ciphers",
2478 "SUITEB192") < 0)
2479 return -2;
2480 }
2481
2482 val = get_param(cmd, "TLSCipher");
2483 if (set_tls_cipher(ifname, id, val) < 0) {
2484 send_resp(dut, conn, SIGMA_ERROR,
2485 "ErrorCode,Unsupported TLSCipher value");
2486 return -3;
2487 }
2488 }
2489
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002490 return 1;
2491}
2492
2493
2494static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
2495 struct sigma_cmd *cmd)
2496{
2497 const char *intf = get_param(cmd, "Interface");
2498 const char *ifname;
2499 int id;
2500
2501 if (intf == NULL)
2502 return -1;
2503
2504 if (strcmp(intf, get_main_ifname()) == 0)
2505 ifname = get_station_ifname();
2506 else
2507 ifname = intf;
2508
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302509 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002510 if (id < 0)
2511 return id;
2512
2513 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2514 send_resp(dut, conn, SIGMA_ERROR,
2515 "errorCode,Failed to set TTLS method");
2516 return 0;
2517 }
2518
2519 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2520 send_resp(dut, conn, SIGMA_ERROR,
2521 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2522 return 0;
2523 }
2524
2525 return 1;
2526}
2527
2528
2529static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
2530 struct sigma_cmd *cmd)
2531{
2532 const char *intf = get_param(cmd, "Interface");
2533 const char *ifname;
2534 int id;
2535
2536 if (intf == NULL)
2537 return -1;
2538
2539 if (strcmp(intf, get_main_ifname()) == 0)
2540 ifname = get_station_ifname();
2541 else
2542 ifname = intf;
2543
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302544 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002545 if (id < 0)
2546 return id;
2547
2548 if (set_network(ifname, id, "eap", "SIM") < 0)
2549 return -2;
2550
2551 return 1;
2552}
2553
2554
2555static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
2556 struct sigma_cmd *cmd)
2557{
2558 const char *intf = get_param(cmd, "Interface");
2559 const char *ifname, *val;
2560 int id;
2561 char buf[100];
2562
2563 if (intf == NULL)
2564 return -1;
2565
2566 if (strcmp(intf, get_main_ifname()) == 0)
2567 ifname = get_station_ifname();
2568 else
2569 ifname = intf;
2570
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302571 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002572 if (id < 0)
2573 return id;
2574
2575 if (set_network(ifname, id, "eap", "PEAP") < 0)
2576 return -2;
2577
2578 val = get_param(cmd, "innerEAP");
2579 if (val) {
2580 if (strcasecmp(val, "MSCHAPv2") == 0) {
2581 if (set_network_quoted(ifname, id, "phase2",
2582 "auth=MSCHAPV2") < 0)
2583 return -2;
2584 } else if (strcasecmp(val, "GTC") == 0) {
2585 if (set_network_quoted(ifname, id, "phase2",
2586 "auth=GTC") < 0)
2587 return -2;
2588 } else
2589 return -1;
2590 }
2591
2592 val = get_param(cmd, "peapVersion");
2593 if (val) {
2594 int ver = atoi(val);
2595 if (ver < 0 || ver > 1)
2596 return -1;
2597 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2598 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2599 return -2;
2600 }
2601
2602 return 1;
2603}
2604
2605
2606static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2607 struct sigma_cmd *cmd)
2608{
2609 const char *intf = get_param(cmd, "Interface");
2610 const char *ifname, *val;
2611 int id;
2612 char buf[100];
2613
2614 if (intf == NULL)
2615 return -1;
2616
2617 if (strcmp(intf, get_main_ifname()) == 0)
2618 ifname = get_station_ifname();
2619 else
2620 ifname = intf;
2621
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302622 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002623 if (id < 0)
2624 return id;
2625
2626 if (set_network(ifname, id, "eap", "FAST") < 0)
2627 return -2;
2628
2629 val = get_param(cmd, "innerEAP");
2630 if (val) {
2631 if (strcasecmp(val, "MSCHAPV2") == 0) {
2632 if (set_network_quoted(ifname, id, "phase2",
2633 "auth=MSCHAPV2") < 0)
2634 return -2;
2635 } else if (strcasecmp(val, "GTC") == 0) {
2636 if (set_network_quoted(ifname, id, "phase2",
2637 "auth=GTC") < 0)
2638 return -2;
2639 } else
2640 return -1;
2641 }
2642
2643 val = get_param(cmd, "validateServer");
2644 if (val) {
2645 /* TODO */
2646 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2647 "validateServer=%s", val);
2648 }
2649
2650 val = get_param(cmd, "pacFile");
2651 if (val) {
2652 snprintf(buf, sizeof(buf), "blob://%s", val);
2653 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2654 return -2;
2655 }
2656
2657 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2658 0)
2659 return -2;
2660
2661 return 1;
2662}
2663
2664
2665static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2666 struct sigma_cmd *cmd)
2667{
2668 const char *intf = get_param(cmd, "Interface");
2669 const char *ifname;
2670 int id;
2671
2672 if (intf == NULL)
2673 return -1;
2674
2675 if (strcmp(intf, get_main_ifname()) == 0)
2676 ifname = get_station_ifname();
2677 else
2678 ifname = intf;
2679
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302680 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002681 if (id < 0)
2682 return id;
2683
2684 if (set_network(ifname, id, "eap", "AKA") < 0)
2685 return -2;
2686
2687 return 1;
2688}
2689
2690
2691static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2692 struct sigma_conn *conn,
2693 struct sigma_cmd *cmd)
2694{
2695 const char *intf = get_param(cmd, "Interface");
2696 const char *ifname;
2697 int id;
2698
2699 if (intf == NULL)
2700 return -1;
2701
2702 if (strcmp(intf, get_main_ifname()) == 0)
2703 ifname = get_station_ifname();
2704 else
2705 ifname = intf;
2706
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302707 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002708 if (id < 0)
2709 return id;
2710
2711 if (set_network(ifname, id, "eap", "AKA'") < 0)
2712 return -2;
2713
2714 return 1;
2715}
2716
2717
2718static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2719 struct sigma_cmd *cmd)
2720{
2721 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002722 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002723 const char *ifname;
2724 int id;
2725
2726 if (strcmp(intf, get_main_ifname()) == 0)
2727 ifname = get_station_ifname();
2728 else
2729 ifname = intf;
2730
2731 id = add_network_common(dut, conn, ifname, cmd);
2732 if (id < 0)
2733 return id;
2734
2735 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2736 return -2;
2737
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002738 if (dut->program == PROGRAM_60GHZ && network_mode &&
2739 strcasecmp(network_mode, "PBSS") == 0 &&
2740 set_network(ifname, id, "pbss", "1") < 0)
2741 return -2;
2742
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002743 return 1;
2744}
2745
2746
Jouni Malinen47dcc952017-10-09 16:43:24 +03002747static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2748 struct sigma_cmd *cmd)
2749{
2750 const char *intf = get_param(cmd, "Interface");
2751 const char *ifname, *val;
2752 int id;
2753
2754 if (intf == NULL)
2755 return -1;
2756
2757 if (strcmp(intf, get_main_ifname()) == 0)
2758 ifname = get_station_ifname();
2759 else
2760 ifname = intf;
2761
2762 id = set_wpa_common(dut, conn, ifname, cmd);
2763 if (id < 0)
2764 return id;
2765
2766 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2767 return -2;
2768
2769 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002770 if (val && strcmp(val, "0") == 0) {
2771 if (wpa_command(ifname,
2772 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2773 sigma_dut_print(dut, DUT_MSG_ERROR,
2774 "Failed to set OWE DH Param element override");
2775 return -2;
2776 }
2777 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002778 sigma_dut_print(dut, DUT_MSG_ERROR,
2779 "Failed to clear owe_group");
2780 return -2;
2781 }
2782
2783 return 1;
2784}
2785
2786
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002787static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2788 struct sigma_cmd *cmd)
2789{
2790 const char *type = get_param(cmd, "Type");
2791
2792 if (type == NULL) {
2793 send_resp(dut, conn, SIGMA_ERROR,
2794 "ErrorCode,Missing Type argument");
2795 return 0;
2796 }
2797
2798 if (strcasecmp(type, "OPEN") == 0)
2799 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002800 if (strcasecmp(type, "OWE") == 0)
2801 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002802 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002803 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002804 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002805 return cmd_sta_set_psk(dut, conn, cmd);
2806 if (strcasecmp(type, "EAPTLS") == 0)
2807 return cmd_sta_set_eaptls(dut, conn, cmd);
2808 if (strcasecmp(type, "EAPTTLS") == 0)
2809 return cmd_sta_set_eapttls(dut, conn, cmd);
2810 if (strcasecmp(type, "EAPPEAP") == 0)
2811 return cmd_sta_set_peap(dut, conn, cmd);
2812 if (strcasecmp(type, "EAPSIM") == 0)
2813 return cmd_sta_set_eapsim(dut, conn, cmd);
2814 if (strcasecmp(type, "EAPFAST") == 0)
2815 return cmd_sta_set_eapfast(dut, conn, cmd);
2816 if (strcasecmp(type, "EAPAKA") == 0)
2817 return cmd_sta_set_eapaka(dut, conn, cmd);
2818 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2819 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002820 if (strcasecmp(type, "wep") == 0)
2821 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002822
2823 send_resp(dut, conn, SIGMA_ERROR,
2824 "ErrorCode,Unsupported Type value");
2825 return 0;
2826}
2827
2828
2829int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2830{
2831#ifdef __linux__
2832 /* special handling for ath6kl */
2833 char path[128], fname[128], *pos;
2834 ssize_t res;
2835 FILE *f;
2836
Jouni Malinene39cd562019-05-29 23:39:56 +03002837 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
2838 intf);
2839 if (res < 0 || res >= sizeof(fname))
2840 return 0;
2841 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002842 if (res < 0)
2843 return 0; /* not ath6kl */
2844
2845 if (res >= (int) sizeof(path))
2846 res = sizeof(path) - 1;
2847 path[res] = '\0';
2848 pos = strrchr(path, '/');
2849 if (pos == NULL)
2850 pos = path;
2851 else
2852 pos++;
2853 snprintf(fname, sizeof(fname),
2854 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2855 "create_qos", pos);
2856 if (!file_exists(fname))
2857 return 0; /* not ath6kl */
2858
2859 if (uapsd) {
2860 f = fopen(fname, "w");
2861 if (f == NULL)
2862 return -1;
2863
2864 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2865 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2866 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2867 "20000 0\n");
2868 fclose(f);
2869 } else {
2870 snprintf(fname, sizeof(fname),
2871 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2872 "delete_qos", pos);
2873
2874 f = fopen(fname, "w");
2875 if (f == NULL)
2876 return -1;
2877
2878 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2879 fprintf(f, "2 4\n");
2880 fclose(f);
2881 }
2882#endif /* __linux__ */
2883
2884 return 0;
2885}
2886
2887
2888static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2889 struct sigma_cmd *cmd)
2890{
2891 const char *intf = get_param(cmd, "Interface");
2892 /* const char *ssid = get_param(cmd, "ssid"); */
2893 const char *val;
2894 int max_sp_len = 4;
2895 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2896 char buf[100];
2897 int ret1, ret2;
2898
2899 val = get_param(cmd, "maxSPLength");
2900 if (val) {
2901 max_sp_len = atoi(val);
2902 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2903 max_sp_len != 4)
2904 return -1;
2905 }
2906
2907 val = get_param(cmd, "acBE");
2908 if (val)
2909 ac_be = atoi(val);
2910
2911 val = get_param(cmd, "acBK");
2912 if (val)
2913 ac_bk = atoi(val);
2914
2915 val = get_param(cmd, "acVI");
2916 if (val)
2917 ac_vi = atoi(val);
2918
2919 val = get_param(cmd, "acVO");
2920 if (val)
2921 ac_vo = atoi(val);
2922
2923 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2924
2925 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2926 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2927 ret1 = wpa_command(intf, buf);
2928
2929 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2930 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2931 ret2 = wpa_command(intf, buf);
2932
2933 if (ret1 && ret2) {
2934 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2935 "UAPSD parameters.");
2936 return -2;
2937 }
2938
2939 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2940 send_resp(dut, conn, SIGMA_ERROR,
2941 "ErrorCode,Failed to set ath6kl QoS parameters");
2942 return 0;
2943 }
2944
2945 return 1;
2946}
2947
2948
2949static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2950 struct sigma_cmd *cmd)
2951{
2952 char buf[1000];
2953 const char *intf = get_param(cmd, "Interface");
2954 const char *grp = get_param(cmd, "Group");
2955 const char *act = get_param(cmd, "Action");
2956 const char *tid = get_param(cmd, "Tid");
2957 const char *dir = get_param(cmd, "Direction");
2958 const char *psb = get_param(cmd, "Psb");
2959 const char *up = get_param(cmd, "Up");
2960 const char *fixed = get_param(cmd, "Fixed");
2961 const char *size = get_param(cmd, "Size");
2962 const char *msize = get_param(cmd, "Maxsize");
2963 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2964 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2965 const char *inact = get_param(cmd, "Inactivity");
2966 const char *sus = get_param(cmd, "Suspension");
2967 const char *mindr = get_param(cmd, "Mindatarate");
2968 const char *meandr = get_param(cmd, "Meandatarate");
2969 const char *peakdr = get_param(cmd, "Peakdatarate");
2970 const char *phyrate = get_param(cmd, "Phyrate");
2971 const char *burstsize = get_param(cmd, "Burstsize");
2972 const char *sba = get_param(cmd, "Sba");
2973 int direction;
2974 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002975 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002976 int fixed_int;
2977 int psb_ts;
2978
2979 if (intf == NULL || grp == NULL || act == NULL )
2980 return -1;
2981
2982 if (strcasecmp(act, "addts") == 0) {
2983 if (tid == NULL || dir == NULL || psb == NULL ||
2984 up == NULL || fixed == NULL || size == NULL)
2985 return -1;
2986
2987 /*
2988 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2989 * possible values, but WMM-AC and V-E test scripts use "UP,
2990 * "DOWN", and "BIDI".
2991 */
2992 if (strcasecmp(dir, "uplink") == 0 ||
2993 strcasecmp(dir, "up") == 0) {
2994 direction = 0;
2995 } else if (strcasecmp(dir, "downlink") == 0 ||
2996 strcasecmp(dir, "down") == 0) {
2997 direction = 1;
2998 } else if (strcasecmp(dir, "bidi") == 0) {
2999 direction = 2;
3000 } else {
3001 sigma_dut_print(dut, DUT_MSG_ERROR,
3002 "Direction %s not supported", dir);
3003 return -1;
3004 }
3005
3006 if (strcasecmp(psb, "legacy") == 0) {
3007 psb_ts = 0;
3008 } else if (strcasecmp(psb, "uapsd") == 0) {
3009 psb_ts = 1;
3010 } else {
3011 sigma_dut_print(dut, DUT_MSG_ERROR,
3012 "PSB %s not supported", psb);
3013 return -1;
3014 }
3015
3016 if (atoi(tid) < 0 || atoi(tid) > 7) {
3017 sigma_dut_print(dut, DUT_MSG_ERROR,
3018 "TID %s not supported", tid);
3019 return -1;
3020 }
3021
3022 if (strcasecmp(fixed, "true") == 0) {
3023 fixed_int = 1;
3024 } else {
3025 fixed_int = 0;
3026 }
3027
Peng Xu93319622017-10-04 17:58:16 -07003028 if (sba)
3029 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003030
3031 dut->dialog_token++;
3032 handle = 7000 + dut->dialog_token;
3033
3034 /*
3035 * size: convert to hex
3036 * maxsi: convert to hex
3037 * mindr: convert to hex
3038 * meandr: convert to hex
3039 * peakdr: convert to hex
3040 * burstsize: convert to hex
3041 * phyrate: convert to hex
3042 * sba: convert to hex with modification
3043 * minsi: convert to integer
3044 * sus: convert to integer
3045 * inact: convert to integer
3046 * maxsi: convert to integer
3047 */
3048
3049 /*
3050 * The Nominal MSDU Size field is 2 octets long and contains an
3051 * unsigned integer that specifies the nominal size, in octets,
3052 * of MSDUs belonging to the traffic under this traffic
3053 * specification and is defined in Figure 16. If the Fixed
3054 * subfield is set to 1, then the size of the MSDU is fixed and
3055 * is indicated by the Size Subfield. If the Fixed subfield is
3056 * set to 0, then the size of the MSDU might not be fixed and
3057 * the Size indicates the nominal MSDU size.
3058 *
3059 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3060 * and specifies the excess allocation of time (and bandwidth)
3061 * over and above the stated rates required to transport an MSDU
3062 * belonging to the traffic in this TSPEC. This field is
3063 * represented as an unsigned binary number with an implicit
3064 * binary point after the leftmost 3 bits. For example, an SBA
3065 * of 1.75 is represented as 0x3800. This field is included to
3066 * account for retransmissions. As such, the value of this field
3067 * must be greater than unity.
3068 */
3069
3070 snprintf(buf, sizeof(buf),
3071 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3072 " 0x%X 0x%X 0x%X"
3073 " 0x%X 0x%X 0x%X"
3074 " 0x%X %d %d %d %d"
3075 " %d %d",
3076 intf, handle, tid, direction, psb_ts, up,
3077 (unsigned int) ((fixed_int << 15) | atoi(size)),
3078 msize ? atoi(msize) : 0,
3079 mindr ? atoi(mindr) : 0,
3080 meandr ? atoi(meandr) : 0,
3081 peakdr ? atoi(peakdr) : 0,
3082 burstsize ? atoi(burstsize) : 0,
3083 phyrate ? atoi(phyrate) : 0,
3084 sba ? ((unsigned int) (((int) sba_fv << 13) |
3085 (int)((sba_fv - (int) sba_fv) *
3086 8192))) : 0,
3087 minsi ? atoi(minsi) : 0,
3088 sus ? atoi(sus) : 0,
3089 0, 0,
3090 inact ? atoi(inact) : 0,
3091 maxsi ? atoi(maxsi) : 0);
3092
3093 if (system(buf) != 0) {
3094 sigma_dut_print(dut, DUT_MSG_ERROR,
3095 "iwpriv addtspec request failed");
3096 send_resp(dut, conn, SIGMA_ERROR,
3097 "errorCode,Failed to execute addTspec command");
3098 return 0;
3099 }
3100
3101 sigma_dut_print(dut, DUT_MSG_INFO,
3102 "iwpriv addtspec request send");
3103
3104 /* Mapping handle to a TID */
3105 dut->tid_to_handle[atoi(tid)] = handle;
3106 } else if (strcasecmp(act, "delts") == 0) {
3107 if (tid == NULL)
3108 return -1;
3109
3110 if (atoi(tid) < 0 || atoi(tid) > 7) {
3111 sigma_dut_print(dut, DUT_MSG_ERROR,
3112 "TID %s not supported", tid);
3113 send_resp(dut, conn, SIGMA_ERROR,
3114 "errorCode,Unsupported TID");
3115 return 0;
3116 }
3117
3118 handle = dut->tid_to_handle[atoi(tid)];
3119
3120 if (handle < 7000 || handle > 7255) {
3121 /* Invalid handle ie no mapping for that TID */
3122 sigma_dut_print(dut, DUT_MSG_ERROR,
3123 "handle-> %d not found", handle);
3124 }
3125
3126 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3127 intf, handle);
3128
3129 if (system(buf) != 0) {
3130 sigma_dut_print(dut, DUT_MSG_ERROR,
3131 "iwpriv deltspec request failed");
3132 send_resp(dut, conn, SIGMA_ERROR,
3133 "errorCode,Failed to execute delTspec command");
3134 return 0;
3135 }
3136
3137 sigma_dut_print(dut, DUT_MSG_INFO,
3138 "iwpriv deltspec request send");
3139
3140 dut->tid_to_handle[atoi(tid)] = 0;
3141 } else {
3142 sigma_dut_print(dut, DUT_MSG_ERROR,
3143 "Action type %s not supported", act);
3144 send_resp(dut, conn, SIGMA_ERROR,
3145 "errorCode,Unsupported Action");
3146 return 0;
3147 }
3148
3149 return 1;
3150}
3151
3152
vamsi krishna52e16f92017-08-29 12:37:34 +05303153static int find_network(struct sigma_dut *dut, const char *ssid)
3154{
3155 char list[4096];
3156 char *pos;
3157
3158 sigma_dut_print(dut, DUT_MSG_DEBUG,
3159 "Search for profile based on SSID: '%s'", ssid);
3160 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
3161 list, sizeof(list)) < 0)
3162 return -1;
3163 pos = strstr(list, ssid);
3164 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3165 return -1;
3166
3167 while (pos > list && pos[-1] != '\n')
3168 pos--;
3169 dut->infra_network_id = atoi(pos);
3170 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3171 return 0;
3172}
3173
3174
Sunil Dutt44595082018-02-12 19:41:45 +05303175#ifdef NL80211_SUPPORT
3176static int sta_config_rsnie(struct sigma_dut *dut, int val)
3177{
3178 struct nl_msg *msg;
3179 int ret;
3180 struct nlattr *params;
3181 int ifindex;
3182
3183 ifindex = if_nametoindex("wlan0");
3184 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3185 NL80211_CMD_VENDOR)) ||
3186 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3187 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3188 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3189 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3190 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3191 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3192 sigma_dut_print(dut, DUT_MSG_ERROR,
3193 "%s: err in adding vendor_cmd and vendor_data",
3194 __func__);
3195 nlmsg_free(msg);
3196 return -1;
3197 }
3198 nla_nest_end(msg, params);
3199
3200 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3201 if (ret) {
3202 sigma_dut_print(dut, DUT_MSG_ERROR,
3203 "%s: err in send_and_recv_msgs, ret=%d",
3204 __func__, ret);
3205 return ret;
3206 }
3207
3208 return 0;
3209}
3210#endif /* NL80211_SUPPORT */
3211
3212
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003213static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
3214 struct sigma_cmd *cmd)
3215{
3216 /* const char *intf = get_param(cmd, "Interface"); */
3217 const char *ssid = get_param(cmd, "ssid");
3218 const char *wps_param = get_param(cmd, "WPS");
3219 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003220 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003221 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003222 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003223 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003224
3225 if (ssid == NULL)
3226 return -1;
3227
Jouni Malinen3c367e82017-06-23 17:01:47 +03003228 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303229#ifdef NL80211_SUPPORT
3230 if (get_driver_type() == DRIVER_WCN) {
3231 sta_config_rsnie(dut, 1);
3232 dut->config_rsnie = 1;
3233 }
3234#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003235 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3236 dut->rsne_override);
3237 if (wpa_command(get_station_ifname(), buf) < 0) {
3238 send_resp(dut, conn, SIGMA_ERROR,
3239 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3240 return 0;
3241 }
3242 }
3243
Jouni Malinen68143132017-09-02 02:34:08 +03003244 if (dut->sae_commit_override) {
3245 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3246 dut->sae_commit_override);
3247 if (wpa_command(get_station_ifname(), buf) < 0) {
3248 send_resp(dut, conn, SIGMA_ERROR,
3249 "ErrorCode,Failed to set SAE commit override");
3250 return 0;
3251 }
3252 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303253#ifdef ANDROID
3254 if (dut->fils_hlp)
3255 process_fils_hlp(dut);
3256#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003257
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003258 if (wps_param &&
3259 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3260 wps = 1;
3261
3262 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003263 if (dut->program == PROGRAM_60GHZ && network_mode &&
3264 strcasecmp(network_mode, "PBSS") == 0 &&
3265 set_network(get_station_ifname(), dut->infra_network_id,
3266 "pbss", "1") < 0)
3267 return -2;
3268
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003269 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3270 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3271 "parameters not yet set");
3272 return 0;
3273 }
3274 if (dut->wps_method == WFA_CS_WPS_PBC) {
3275 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
3276 return -2;
3277 } else {
3278 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3279 dut->wps_pin);
3280 if (wpa_command(get_station_ifname(), buf) < 0)
3281 return -2;
3282 }
3283 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303284 if (strcmp(ssid, dut->infra_ssid) == 0) {
3285 sigma_dut_print(dut, DUT_MSG_DEBUG,
3286 "sta_associate for the most recently added network");
3287 } else if (find_network(dut, ssid) < 0) {
3288 sigma_dut_print(dut, DUT_MSG_DEBUG,
3289 "sta_associate for a previously stored network profile");
3290 send_resp(dut, conn, SIGMA_ERROR,
3291 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003292 return 0;
3293 }
3294
3295 if (bssid &&
3296 set_network(get_station_ifname(), dut->infra_network_id,
3297 "bssid", bssid) < 0) {
3298 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3299 "Invalid bssid argument");
3300 return 0;
3301 }
3302
Jouni Malinen46a19b62017-06-23 14:31:27 +03003303 extra[0] = '\0';
3304 if (chan)
3305 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003306 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003307 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3308 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003309 if (wpa_command(get_station_ifname(), buf) < 0) {
3310 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3311 "network id %d on %s",
3312 dut->infra_network_id,
3313 get_station_ifname());
3314 return -2;
3315 }
3316 }
3317
3318 return 1;
3319}
3320
3321
3322static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3323{
3324 char buf[500], cmd[200];
3325 int res;
3326
3327 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3328 * default path */
3329 res = snprintf(cmd, sizeof(cmd),
3330 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3331 file_exists("./hs20-osu-client") ?
3332 "./hs20-osu-client" : "hs20-osu-client",
3333 sigma_wpas_ctrl,
3334 dut->summary_log ? "-s " : "",
3335 dut->summary_log ? dut->summary_log : "");
3336 if (res < 0 || res >= (int) sizeof(cmd))
3337 return -1;
3338
3339 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3340 if (res < 0 || res >= (int) sizeof(buf))
3341 return -1;
3342 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3343
3344 if (system(buf) != 0) {
3345 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3346 return -1;
3347 }
3348 sigma_dut_print(dut, DUT_MSG_DEBUG,
3349 "Completed hs20-osu-client operation");
3350
3351 return 0;
3352}
3353
3354
3355static int download_ppsmo(struct sigma_dut *dut,
3356 struct sigma_conn *conn,
3357 const char *intf,
3358 struct sigma_cmd *cmd)
3359{
3360 const char *name, *path, *val;
3361 char url[500], buf[600], fbuf[100];
3362 char *fqdn = NULL;
3363
3364 name = get_param(cmd, "FileName");
3365 path = get_param(cmd, "FilePath");
3366 if (name == NULL || path == NULL)
3367 return -1;
3368
3369 if (strcasecmp(path, "VendorSpecific") == 0) {
3370 snprintf(url, sizeof(url), "PPS/%s", name);
3371 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3372 "from the device (%s)", url);
3373 if (!file_exists(url)) {
3374 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3375 "PPS MO file does not exist");
3376 return 0;
3377 }
3378 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3379 if (system(buf) != 0) {
3380 send_resp(dut, conn, SIGMA_ERROR,
3381 "errorCode,Failed to copy PPS MO");
3382 return 0;
3383 }
3384 } else if (strncasecmp(path, "http:", 5) != 0 &&
3385 strncasecmp(path, "https:", 6) != 0) {
3386 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3387 "Unsupported FilePath value");
3388 return 0;
3389 } else {
3390 snprintf(url, sizeof(url), "%s/%s", path, name);
3391 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3392 url);
3393 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3394 remove("pps-tnds.xml");
3395 if (system(buf) != 0) {
3396 send_resp(dut, conn, SIGMA_ERROR,
3397 "errorCode,Failed to download PPS MO");
3398 return 0;
3399 }
3400 }
3401
3402 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3403 send_resp(dut, conn, SIGMA_ERROR,
3404 "errorCode,Failed to parse downloaded PPSMO");
3405 return 0;
3406 }
3407 unlink("pps-tnds.xml");
3408
3409 val = get_param(cmd, "managementTreeURI");
3410 if (val) {
3411 const char *pos, *end;
3412 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3413 val);
3414 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3415 send_resp(dut, conn, SIGMA_ERROR,
3416 "errorCode,Invalid managementTreeURI prefix");
3417 return 0;
3418 }
3419 pos = val + 8;
3420 end = strchr(pos, '/');
3421 if (end == NULL ||
3422 strcmp(end, "/PerProviderSubscription") != 0) {
3423 send_resp(dut, conn, SIGMA_ERROR,
3424 "errorCode,Invalid managementTreeURI postfix");
3425 return 0;
3426 }
3427 if (end - pos >= (int) sizeof(fbuf)) {
3428 send_resp(dut, conn, SIGMA_ERROR,
3429 "errorCode,Too long FQDN in managementTreeURI");
3430 return 0;
3431 }
3432 memcpy(fbuf, pos, end - pos);
3433 fbuf[end - pos] = '\0';
3434 fqdn = fbuf;
3435 sigma_dut_print(dut, DUT_MSG_INFO,
3436 "FQDN from managementTreeURI: %s", fqdn);
3437 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3438 FILE *f = fopen("pps-fqdn", "r");
3439 if (f) {
3440 if (fgets(fbuf, sizeof(fbuf), f)) {
3441 fbuf[sizeof(fbuf) - 1] = '\0';
3442 fqdn = fbuf;
3443 sigma_dut_print(dut, DUT_MSG_DEBUG,
3444 "Use FQDN %s", fqdn);
3445 }
3446 fclose(f);
3447 }
3448 }
3449
3450 if (fqdn == NULL) {
3451 send_resp(dut, conn, SIGMA_ERROR,
3452 "errorCode,No FQDN specified");
3453 return 0;
3454 }
3455
3456 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3457 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3458 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3459
3460 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3461 if (rename("pps.xml", buf) < 0) {
3462 send_resp(dut, conn, SIGMA_ERROR,
3463 "errorCode,Could not move PPS MO");
3464 return 0;
3465 }
3466
3467 if (strcasecmp(path, "VendorSpecific") == 0) {
3468 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3469 fqdn);
3470 if (system(buf)) {
3471 send_resp(dut, conn, SIGMA_ERROR,
3472 "errorCode,Failed to copy OSU CA cert");
3473 return 0;
3474 }
3475
3476 snprintf(buf, sizeof(buf),
3477 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3478 fqdn);
3479 if (system(buf)) {
3480 send_resp(dut, conn, SIGMA_ERROR,
3481 "errorCode,Failed to copy AAA CA cert");
3482 return 0;
3483 }
3484 } else {
3485 snprintf(buf, sizeof(buf),
3486 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3487 fqdn, fqdn);
3488 if (run_hs20_osu(dut, buf) < 0) {
3489 send_resp(dut, conn, SIGMA_ERROR,
3490 "errorCode,Failed to download OSU CA cert");
3491 return 0;
3492 }
3493
3494 snprintf(buf, sizeof(buf),
3495 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3496 fqdn, fqdn);
3497 if (run_hs20_osu(dut, buf) < 0) {
3498 sigma_dut_print(dut, DUT_MSG_INFO,
3499 "Failed to download AAA CA cert");
3500 }
3501 }
3502
3503 if (file_exists("next-client-cert.pem")) {
3504 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3505 if (rename("next-client-cert.pem", buf) < 0) {
3506 send_resp(dut, conn, SIGMA_ERROR,
3507 "errorCode,Could not move client certificate");
3508 return 0;
3509 }
3510 }
3511
3512 if (file_exists("next-client-key.pem")) {
3513 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3514 if (rename("next-client-key.pem", buf) < 0) {
3515 send_resp(dut, conn, SIGMA_ERROR,
3516 "errorCode,Could not move client key");
3517 return 0;
3518 }
3519 }
3520
3521 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3522 if (run_hs20_osu(dut, buf) < 0) {
3523 send_resp(dut, conn, SIGMA_ERROR,
3524 "errorCode,Failed to configure credential from "
3525 "PPSMO");
3526 return 0;
3527 }
3528
3529 return 1;
3530}
3531
3532
3533static int download_cert(struct sigma_dut *dut,
3534 struct sigma_conn *conn,
3535 const char *intf,
3536 struct sigma_cmd *cmd)
3537{
3538 const char *name, *path;
3539 char url[500], buf[600];
3540
3541 name = get_param(cmd, "FileName");
3542 path = get_param(cmd, "FilePath");
3543 if (name == NULL || path == NULL)
3544 return -1;
3545
3546 if (strcasecmp(path, "VendorSpecific") == 0) {
3547 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3548 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3549 "certificate from the device (%s)", url);
3550 if (!file_exists(url)) {
3551 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3552 "certificate file does not exist");
3553 return 0;
3554 }
3555 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3556 if (system(buf) != 0) {
3557 send_resp(dut, conn, SIGMA_ERROR,
3558 "errorCode,Failed to copy client "
3559 "certificate");
3560 return 0;
3561 }
3562
3563 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3564 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3565 "private key from the device (%s)", url);
3566 if (!file_exists(url)) {
3567 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3568 "private key file does not exist");
3569 return 0;
3570 }
3571 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3572 if (system(buf) != 0) {
3573 send_resp(dut, conn, SIGMA_ERROR,
3574 "errorCode,Failed to copy client key");
3575 return 0;
3576 }
3577 } else if (strncasecmp(path, "http:", 5) != 0 &&
3578 strncasecmp(path, "https:", 6) != 0) {
3579 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3580 "Unsupported FilePath value");
3581 return 0;
3582 } else {
3583 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3584 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3585 "certificate/key from %s", url);
3586 snprintf(buf, sizeof(buf),
3587 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3588 if (system(buf) != 0) {
3589 send_resp(dut, conn, SIGMA_ERROR,
3590 "errorCode,Failed to download client "
3591 "certificate");
3592 return 0;
3593 }
3594
3595 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3596 {
3597 send_resp(dut, conn, SIGMA_ERROR,
3598 "errorCode,Failed to copy client key");
3599 return 0;
3600 }
3601 }
3602
3603 return 1;
3604}
3605
3606
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003607static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3608 struct sigma_conn *conn,
3609 struct sigma_cmd *cmd)
3610{
3611 const char *val;
3612 const char *intf = get_param(cmd, "interface");
3613
3614 if (!intf)
3615 return -1;
3616
3617 val = get_param(cmd, "WscIEFragment");
3618 if (val && strcasecmp(val, "enable") == 0) {
3619 sigma_dut_print(dut, DUT_MSG_DEBUG,
3620 "Enable WSC IE fragmentation");
3621
3622 dut->wsc_fragment = 1;
3623 /* set long attributes to force fragmentation */
3624 if (wpa_command(intf, "SET device_name "
3625 WPS_LONG_DEVICE_NAME) < 0)
3626 return -2;
3627 if (wpa_command(intf, "SET manufacturer "
3628 WPS_LONG_MANUFACTURER) < 0)
3629 return -2;
3630 if (wpa_command(intf, "SET model_name "
3631 WPS_LONG_MODEL_NAME) < 0)
3632 return -2;
3633 if (wpa_command(intf, "SET model_number "
3634 WPS_LONG_MODEL_NUMBER) < 0)
3635 return -2;
3636 if (wpa_command(intf, "SET serial_number "
3637 WPS_LONG_SERIAL_NUMBER) < 0)
3638 return -2;
3639 }
3640
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003641 val = get_param(cmd, "RSN_IE");
3642 if (val) {
3643 if (strcasecmp(val, "disable") == 0)
3644 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3645 else if (strcasecmp(val, "enable") == 0)
3646 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3647 }
3648
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003649 val = get_param(cmd, "WpsVersion");
3650 if (val)
3651 dut->wps_forced_version = get_wps_forced_version(dut, val);
3652
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003653 val = get_param(cmd, "WscEAPFragment");
3654 if (val && strcasecmp(val, "enable") == 0)
3655 dut->eap_fragment = 1;
3656
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003657 return 1;
3658}
3659
3660
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003661static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3662 struct sigma_conn *conn,
3663 const char *intf,
3664 struct sigma_cmd *cmd)
3665{
3666 const char *val;
3667
3668 val = get_param(cmd, "FileType");
3669 if (val && strcasecmp(val, "PPSMO") == 0)
3670 return download_ppsmo(dut, conn, intf, cmd);
3671 if (val && strcasecmp(val, "CERT") == 0)
3672 return download_cert(dut, conn, intf, cmd);
3673 if (val) {
3674 send_resp(dut, conn, SIGMA_ERROR,
3675 "ErrorCode,Unsupported FileType");
3676 return 0;
3677 }
3678
3679 return 1;
3680}
3681
3682
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303683static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3684 struct sigma_conn *conn,
3685 const char *intf,
3686 struct sigma_cmd *cmd)
3687{
3688 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303689 char buf[1000];
3690 char text[20];
3691 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303692
3693 val = get_param(cmd, "OCESupport");
3694 if (val && strcasecmp(val, "Disable") == 0) {
3695 if (wpa_command(intf, "SET oce 0") < 0) {
3696 send_resp(dut, conn, SIGMA_ERROR,
3697 "ErrorCode,Failed to disable OCE");
3698 return 0;
3699 }
3700 } else if (val && strcasecmp(val, "Enable") == 0) {
3701 if (wpa_command(intf, "SET oce 1") < 0) {
3702 send_resp(dut, conn, SIGMA_ERROR,
3703 "ErrorCode,Failed to enable OCE");
3704 return 0;
3705 }
3706 }
3707
vamsi krishnaa2799492017-12-05 14:28:01 +05303708 val = get_param(cmd, "FILScap");
3709 if (val && (atoi(val) == 1)) {
3710 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3711 send_resp(dut, conn, SIGMA_ERROR,
3712 "ErrorCode,Failed to enable FILS");
3713 return 0;
3714 }
3715 } else if (val && (atoi(val) == 0)) {
3716 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3717 send_resp(dut, conn, SIGMA_ERROR,
3718 "ErrorCode,Failed to disable FILS");
3719 return 0;
3720 }
3721 }
3722
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303723 val = get_param(cmd, "FILSHLP");
3724 if (val && strcasecmp(val, "Enable") == 0) {
3725 if (get_wpa_status(get_station_ifname(), "address", text,
3726 sizeof(text)) < 0)
3727 return -2;
3728 hwaddr_aton(text, addr);
3729 snprintf(buf, sizeof(buf),
3730 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3731 "080045100140000040004011399e00000000ffffffff00440043"
3732 "012cb30001010600fd4f46410000000000000000000000000000"
3733 "000000000000"
3734 "%02x%02x%02x%02x%02x%02x"
3735 "0000000000000000000000000000000000000000000000000000"
3736 "0000000000000000000000000000000000000000000000000000"
3737 "0000000000000000000000000000000000000000000000000000"
3738 "0000000000000000000000000000000000000000000000000000"
3739 "0000000000000000000000000000000000000000000000000000"
3740 "0000000000000000000000000000000000000000000000000000"
3741 "0000000000000000000000000000000000000000000000000000"
3742 "0000000000000000000000000000000000000000638253633501"
3743 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3744 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3745 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3746 if (wpa_command(intf, buf)) {
3747 send_resp(dut, conn, SIGMA_ERROR,
3748 "ErrorCode,Failed to add HLP");
3749 return 0;
3750 }
3751 dut->fils_hlp = 1;
3752 }
3753
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303754 return 1;
3755}
3756
3757
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003758static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3759 const char *val)
3760{
3761 int counter = 0;
3762 char token[50];
3763 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303764 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003765
Peng Xub8fc5cc2017-05-10 17:27:28 -07003766 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003767 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303768 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003769 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003770 if (strcmp(result, "disable") == 0)
3771 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
3772 else
3773 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303774 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003775 counter++;
3776 }
3777}
3778
3779
3780static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3781 const char *val)
3782{
3783 char buf[100];
3784
3785 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3786 if (system(buf) != 0) {
3787 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3788 }
3789}
3790
3791
3792static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3793 const char *val)
3794{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003795 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003796 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003797 }
3798}
3799
3800
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003801static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3802 const char *val)
3803{
3804#ifdef NL80211_SUPPORT
3805 struct nl_msg *msg;
3806 int ret = 0;
3807 struct nlattr *params;
3808 int ifindex;
3809 int wmmenable = 1;
3810
3811 if (val &&
3812 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3813 wmmenable = 0;
3814
3815 ifindex = if_nametoindex(intf);
3816 if (ifindex == 0) {
3817 sigma_dut_print(dut, DUT_MSG_ERROR,
3818 "%s: Index for interface %s failed",
3819 __func__, intf);
3820 return -1;
3821 }
3822
3823 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3824 NL80211_CMD_VENDOR)) ||
3825 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3826 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3827 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3828 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3829 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3830 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3831 wmmenable)) {
3832 sigma_dut_print(dut, DUT_MSG_ERROR,
3833 "%s: err in adding vendor_cmd and vendor_data",
3834 __func__);
3835 nlmsg_free(msg);
3836 return -1;
3837 }
3838 nla_nest_end(msg, params);
3839
3840 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3841 if (ret) {
3842 sigma_dut_print(dut, DUT_MSG_ERROR,
3843 "%s: err in send_and_recv_msgs, ret=%d",
3844 __func__, ret);
3845 }
3846 return ret;
3847#else /* NL80211_SUPPORT */
3848 sigma_dut_print(dut, DUT_MSG_ERROR,
3849 "WMM cannot be changed without NL80211_SUPPORT defined");
3850 return -1;
3851#endif /* NL80211_SUPPORT */
3852}
3853
3854
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003855static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3856 const char *val)
3857{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003858 int sgi20;
3859
3860 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3861
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003862 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003863}
3864
3865
3866static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3867 const char *val)
3868{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303869 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003870
3871 /* Disable Tx Beam forming when using a fixed rate */
3872 ath_disable_txbf(dut, intf);
3873
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303874 v = atoi(val);
3875 if (v < 0 || v > 32) {
3876 sigma_dut_print(dut, DUT_MSG_ERROR,
3877 "Invalid Fixed MCS rate: %d", v);
3878 return;
3879 }
3880 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003881
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003882 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003883
3884 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003885 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003886}
3887
3888
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08003889static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3890 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003891{
3892 char buf[60];
3893
3894 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3895 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3896 else
3897 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3898
3899 if (system(buf) != 0)
3900 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3901}
3902
3903
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003904static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3905 int ampdu)
3906{
3907 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003908 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003909
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003910 if (ampdu)
3911 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003912 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3913 if (system(buf) != 0) {
3914 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3915 return -1;
3916 }
3917
3918 return 0;
3919}
3920
3921
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003922static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3923 const char *val)
3924{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003925 run_iwpriv(dut, intf, "tx_stbc %s", val);
3926 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003927}
3928
3929
3930static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3931 const char *val)
3932{
3933 char buf[60];
3934
Peng Xucc317ed2017-05-18 16:44:37 -07003935 if (strcmp(val, "160") == 0) {
3936 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3937 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003938 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3939 } else if (strcmp(val, "40") == 0) {
3940 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3941 } else if (strcmp(val, "20") == 0) {
3942 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3943 } else if (strcasecmp(val, "Auto") == 0) {
3944 buf[0] = '\0';
3945 } else {
3946 sigma_dut_print(dut, DUT_MSG_ERROR,
3947 "WIDTH/CTS_WIDTH value not supported");
3948 return -1;
3949 }
3950
3951 if (buf[0] != '\0' && system(buf) != 0) {
3952 sigma_dut_print(dut, DUT_MSG_ERROR,
3953 "Failed to set WIDTH/CTS_WIDTH");
3954 return -1;
3955 }
3956
3957 return 0;
3958}
3959
3960
3961int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3962 const char *intf, const char *val)
3963{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003964 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003965 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003966 dut->chwidth = 0;
3967 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003968 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003969 dut->chwidth = 0;
3970 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003971 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003972 dut->chwidth = 1;
3973 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003974 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003975 dut->chwidth = 2;
3976 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003977 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003978 dut->chwidth = 3;
3979 } else {
3980 send_resp(dut, conn, SIGMA_ERROR,
3981 "ErrorCode,WIDTH not supported");
3982 return -1;
3983 }
3984
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003985 return 0;
3986}
3987
3988
3989static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3990 const char *val)
3991{
3992 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07003993 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003994
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003995 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003996 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003997 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003998 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003999 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004000 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004001 } else {
4002 sigma_dut_print(dut, DUT_MSG_ERROR,
4003 "SP_STREAM value not supported");
4004 return -1;
4005 }
4006
4007 if (system(buf) != 0) {
4008 sigma_dut_print(dut, DUT_MSG_ERROR,
4009 "Failed to set SP_STREAM");
4010 return -1;
4011 }
4012
Arif Hussainac6c5112018-05-25 17:34:00 -07004013 dut->sta_nss = sta_nss;
4014
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004015 return 0;
4016}
4017
4018
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304019static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4020 const char *val)
4021{
4022 char buf[60];
4023
4024 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4025 if (system(buf) != 0)
4026 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4027
4028 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4029 if (system(buf) != 0)
4030 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4031}
4032
4033
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304034static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4035 struct sigma_conn *conn,
4036 const char *intf, int capa)
4037{
4038 char buf[32];
4039
4040 if (capa > 0 && capa < 4) {
4041 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4042 if (wpa_command(intf, buf) < 0) {
4043 send_resp(dut, conn, SIGMA_ERROR,
4044 "ErrorCode, Failed to set cellular data capability");
4045 return 0;
4046 }
4047 return 1;
4048 }
4049
4050 sigma_dut_print(dut, DUT_MSG_ERROR,
4051 "Invalid Cellular data capability: %d", capa);
4052 send_resp(dut, conn, SIGMA_INVALID,
4053 "ErrorCode,Invalid cellular data capability");
4054 return 0;
4055}
4056
4057
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304058static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4059 const char *intf, const char *val)
4060{
4061 if (strcasecmp(val, "Disable") == 0) {
4062 if (wpa_command(intf, "SET roaming 0") < 0) {
4063 send_resp(dut, conn, SIGMA_ERROR,
4064 "ErrorCode,Failed to disable roaming");
4065 return 0;
4066 }
4067 return 1;
4068 }
4069
4070 if (strcasecmp(val, "Enable") == 0) {
4071 if (wpa_command(intf, "SET roaming 1") < 0) {
4072 send_resp(dut, conn, SIGMA_ERROR,
4073 "ErrorCode,Failed to enable roaming");
4074 return 0;
4075 }
4076 return 1;
4077 }
4078
4079 sigma_dut_print(dut, DUT_MSG_ERROR,
4080 "Invalid value provided for roaming: %s", val);
4081 send_resp(dut, conn, SIGMA_INVALID,
4082 "ErrorCode,Unknown value provided for Roaming");
4083 return 0;
4084}
4085
4086
Ashwini Patila75de5a2017-04-13 16:35:05 +05304087static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4088 struct sigma_conn *conn,
4089 const char *intf, const char *val)
4090{
4091 if (strcasecmp(val, "Disable") == 0) {
4092 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4093 send_resp(dut, conn, SIGMA_ERROR,
4094 "ErrorCode,Failed to disable Assoc_disallow");
4095 return 0;
4096 }
4097 return 1;
4098 }
4099
4100 if (strcasecmp(val, "Enable") == 0) {
4101 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4102 send_resp(dut, conn, SIGMA_ERROR,
4103 "ErrorCode,Failed to enable Assoc_disallow");
4104 return 0;
4105 }
4106 return 1;
4107 }
4108
4109 sigma_dut_print(dut, DUT_MSG_ERROR,
4110 "Invalid value provided for Assoc_disallow: %s", val);
4111 send_resp(dut, conn, SIGMA_INVALID,
4112 "ErrorCode,Unknown value provided for Assoc_disallow");
4113 return 0;
4114}
4115
4116
Ashwini Patilc63161e2017-04-13 16:30:23 +05304117static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4118 const char *intf, const char *val)
4119{
4120 if (strcasecmp(val, "Reject") == 0) {
4121 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4122 send_resp(dut, conn, SIGMA_ERROR,
4123 "ErrorCode,Failed to Reject BTM Request");
4124 return 0;
4125 }
4126 return 1;
4127 }
4128
4129 if (strcasecmp(val, "Accept") == 0) {
4130 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4131 send_resp(dut, conn, SIGMA_ERROR,
4132 "ErrorCode,Failed to Accept BTM Request");
4133 return 0;
4134 }
4135 return 1;
4136 }
4137
4138 sigma_dut_print(dut, DUT_MSG_ERROR,
4139 "Invalid value provided for BSS_Transition: %s", val);
4140 send_resp(dut, conn, SIGMA_INVALID,
4141 "ErrorCode,Unknown value provided for BSS_Transition");
4142 return 0;
4143}
4144
4145
Ashwini Patil00402582017-04-13 12:29:39 +05304146static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4147 struct sigma_conn *conn,
4148 const char *intf,
4149 struct sigma_cmd *cmd)
4150{
4151 const char *ch, *pref, *op_class, *reason;
4152 char buf[120];
4153 int len, ret;
4154
4155 pref = get_param(cmd, "Ch_Pref");
4156 if (!pref)
4157 return 1;
4158
4159 if (strcasecmp(pref, "clear") == 0) {
4160 free(dut->non_pref_ch_list);
4161 dut->non_pref_ch_list = NULL;
4162 } else {
4163 op_class = get_param(cmd, "Ch_Op_Class");
4164 if (!op_class) {
4165 send_resp(dut, conn, SIGMA_INVALID,
4166 "ErrorCode,Ch_Op_Class not provided");
4167 return 0;
4168 }
4169
4170 ch = get_param(cmd, "Ch_Pref_Num");
4171 if (!ch) {
4172 send_resp(dut, conn, SIGMA_INVALID,
4173 "ErrorCode,Ch_Pref_Num not provided");
4174 return 0;
4175 }
4176
4177 reason = get_param(cmd, "Ch_Reason_Code");
4178 if (!reason) {
4179 send_resp(dut, conn, SIGMA_INVALID,
4180 "ErrorCode,Ch_Reason_Code not provided");
4181 return 0;
4182 }
4183
4184 if (!dut->non_pref_ch_list) {
4185 dut->non_pref_ch_list =
4186 calloc(1, NON_PREF_CH_LIST_SIZE);
4187 if (!dut->non_pref_ch_list) {
4188 send_resp(dut, conn, SIGMA_ERROR,
4189 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4190 return 0;
4191 }
4192 }
4193 len = strlen(dut->non_pref_ch_list);
4194 ret = snprintf(dut->non_pref_ch_list + len,
4195 NON_PREF_CH_LIST_SIZE - len,
4196 " %s:%s:%s:%s", op_class, ch, pref, reason);
4197 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4198 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4199 dut->non_pref_ch_list);
4200 } else {
4201 sigma_dut_print(dut, DUT_MSG_ERROR,
4202 "snprintf failed for non_pref_list, ret = %d",
4203 ret);
4204 send_resp(dut, conn, SIGMA_ERROR,
4205 "ErrorCode,snprintf failed");
4206 free(dut->non_pref_ch_list);
4207 dut->non_pref_ch_list = NULL;
4208 return 0;
4209 }
4210 }
4211
4212 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4213 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4214 if (ret < 0 || ret >= (int) sizeof(buf)) {
4215 sigma_dut_print(dut, DUT_MSG_DEBUG,
4216 "snprintf failed for set non_pref_chan, ret: %d",
4217 ret);
4218 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4219 return 0;
4220 }
4221
4222 if (wpa_command(intf, buf) < 0) {
4223 send_resp(dut, conn, SIGMA_ERROR,
4224 "ErrorCode,Failed to set non-preferred channel list");
4225 return 0;
4226 }
4227
4228 return 1;
4229}
4230
4231
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004232#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004233
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004234static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4235 uint8_t cfg)
4236{
4237 struct nl_msg *msg;
4238 int ret = 0;
4239 struct nlattr *params;
4240 int ifindex;
4241
4242 ifindex = if_nametoindex(intf);
4243 if (ifindex == 0) {
4244 sigma_dut_print(dut, DUT_MSG_ERROR,
4245 "%s: Index for interface %s failed",
4246 __func__, intf);
4247 return -1;
4248 }
4249
4250 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4251 NL80211_CMD_VENDOR)) ||
4252 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4253 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4254 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4255 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4256 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4257 nla_put_u8(msg,
4258 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4259 cfg)) {
4260 sigma_dut_print(dut, DUT_MSG_ERROR,
4261 "%s: err in adding vendor_cmd and vendor_data",
4262 __func__);
4263 nlmsg_free(msg);
4264 return -1;
4265 }
4266 nla_nest_end(msg, params);
4267
4268 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4269 if (ret) {
4270 sigma_dut_print(dut, DUT_MSG_ERROR,
4271 "%s: err in send_and_recv_msgs, ret=%d",
4272 __func__, ret);
4273 }
4274 return ret;
4275}
4276
4277
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004278static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4279 enum he_fragmentation_val frag)
4280{
4281 struct nl_msg *msg;
4282 int ret = 0;
4283 struct nlattr *params;
4284 int ifindex;
4285
4286 ifindex = if_nametoindex(intf);
4287 if (ifindex == 0) {
4288 sigma_dut_print(dut, DUT_MSG_ERROR,
4289 "%s: Index for interface %s failed",
4290 __func__, intf);
4291 return -1;
4292 }
4293
4294 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4295 NL80211_CMD_VENDOR)) ||
4296 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4297 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4298 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4299 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4300 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4301 nla_put_u8(msg,
4302 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4303 frag)) {
4304 sigma_dut_print(dut, DUT_MSG_ERROR,
4305 "%s: err in adding vendor_cmd and vendor_data",
4306 __func__);
4307 nlmsg_free(msg);
4308 return -1;
4309 }
4310 nla_nest_end(msg, params);
4311
4312 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4313 if (ret) {
4314 sigma_dut_print(dut, DUT_MSG_ERROR,
4315 "%s: err in send_and_recv_msgs, ret=%d",
4316 __func__, ret);
4317 }
4318 return ret;
4319}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004320
4321
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004322static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
4323 enum qca_wlan_he_ltf_cfg ltf)
4324{
4325 struct nl_msg *msg;
4326 int ret = 0;
4327 struct nlattr *params;
4328 int ifindex;
4329
4330 ifindex = if_nametoindex(intf);
4331 if (ifindex == 0) {
4332 sigma_dut_print(dut, DUT_MSG_ERROR,
4333 "%s: Index for interface %s failed",
4334 __func__, intf);
4335 return -1;
4336 }
4337
4338 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4339 NL80211_CMD_VENDOR)) ||
4340 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4341 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4342 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4343 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4344 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4345 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4346 ltf)) {
4347 sigma_dut_print(dut, DUT_MSG_ERROR,
4348 "%s: err in adding vendor_cmd and vendor_data",
4349 __func__);
4350 nlmsg_free(msg);
4351 return -1;
4352 }
4353 nla_nest_end(msg, params);
4354
4355 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4356 if (ret) {
4357 sigma_dut_print(dut, DUT_MSG_ERROR,
4358 "%s: err in send_and_recv_msgs, ret=%d",
4359 __func__, ret);
4360 }
4361 return ret;
4362}
4363
4364
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004365static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4366 int noack, enum qca_wlan_ac_type ac)
4367{
4368 struct nl_msg *msg;
4369 int ret = 0;
4370 struct nlattr *params;
4371 int ifindex;
4372
4373 ifindex = if_nametoindex(intf);
4374 if (ifindex == 0) {
4375 sigma_dut_print(dut, DUT_MSG_ERROR,
4376 "%s: Index for interface %s failed",
4377 __func__, intf);
4378 return -1;
4379 }
4380
4381 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4382 NL80211_CMD_VENDOR)) ||
4383 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4384 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4385 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4386 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4387 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4388 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4389 noack) ||
4390 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4391 ac)) {
4392 sigma_dut_print(dut, DUT_MSG_ERROR,
4393 "%s: err in adding vendor_cmd and vendor_data",
4394 __func__);
4395 nlmsg_free(msg);
4396 return -1;
4397 }
4398 nla_nest_end(msg, params);
4399
4400 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4401 if (ret) {
4402 sigma_dut_print(dut, DUT_MSG_ERROR,
4403 "%s: err in send_and_recv_msgs, ret=%d",
4404 __func__, ret);
4405 }
4406 return ret;
4407}
4408
4409
4410static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4411 const char *val)
4412{
4413 int noack, ret;
4414 char token[100];
4415 char *result;
4416 char *saveptr;
4417 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4418
4419 strlcpy(token, val, sizeof(token));
4420 token[sizeof(token) - 1] = '\0';
4421 result = strtok_r(token, ":", &saveptr);
4422 while (result) {
4423 noack = strcasecmp(result, "Disable") != 0;
4424 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4425 if (ret) {
4426 sigma_dut_print(dut, DUT_MSG_ERROR,
4427 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4428 ac, ret);
4429 }
4430 result = strtok_r(NULL, ":", &saveptr);
4431 ac++;
4432 }
4433}
4434
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004435#endif /* NL80211_SUPPORT */
4436
4437
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004438static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
4439 struct sigma_conn *conn,
4440 struct sigma_cmd *cmd)
4441{
4442 const char *intf = get_param(cmd, "Interface");
4443 const char *val;
4444
4445 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004446 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4447 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004448 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4449 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004450
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004451 if (val && strcasecmp(val, "LOC") == 0)
4452 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004453 if (val && strcasecmp(val, "60GHZ") == 0) {
4454 val = get_param(cmd, "WPS");
4455 if (val && strcasecmp(val, "disable") == 0) {
4456 dut->wps_disable = 1;
4457 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4458 } else {
4459 /* wps_disable can have other value from the previous
4460 * test, so make sure it has the correct value.
4461 */
4462 dut->wps_disable = 0;
4463 }
4464
4465 val = get_param(cmd, "P2P");
4466 if (val && strcasecmp(val, "disable") == 0)
4467 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4468 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004469
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004470 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4471 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4472
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004473#ifdef ANDROID_NAN
4474 if (val && strcasecmp(val, "NAN") == 0)
4475 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4476#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004477#ifdef MIRACAST
4478 if (val && (strcasecmp(val, "WFD") == 0 ||
4479 strcasecmp(val, "DisplayR2") == 0))
4480 return miracast_preset_testparameters(dut, conn, cmd);
4481#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004482
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304483 if (val && strcasecmp(val, "MBO") == 0) {
4484 val = get_param(cmd, "Cellular_Data_Cap");
4485 if (val &&
4486 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4487 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304488
4489 val = get_param(cmd, "Ch_Pref");
4490 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4491 return 0;
4492
Ashwini Patilc63161e2017-04-13 16:30:23 +05304493 val = get_param(cmd, "BSS_Transition");
4494 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4495 return 0;
4496
Ashwini Patila75de5a2017-04-13 16:35:05 +05304497 val = get_param(cmd, "Assoc_Disallow");
4498 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4499 return 0;
4500
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304501 val = get_param(cmd, "Roaming");
4502 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4503 return 0;
4504
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304505 return 1;
4506 }
4507
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304508 if (val && strcasecmp(val, "OCE") == 0)
4509 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4510
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004511#if 0
4512 val = get_param(cmd, "Supplicant");
4513 if (val && strcasecmp(val, "Default") != 0) {
4514 send_resp(dut, conn, SIGMA_ERROR,
4515 "ErrorCode,Only default(Vendor) supplicant "
4516 "supported");
4517 return 0;
4518 }
4519#endif
4520
4521 val = get_param(cmd, "RTS");
4522 if (val) {
4523 switch (get_driver_type()) {
4524 case DRIVER_ATHEROS:
4525 ath_sta_set_rts(dut, intf, val);
4526 break;
4527 default:
4528#if 0
4529 send_resp(dut, conn, SIGMA_ERROR,
4530 "ErrorCode,Setting RTS not supported");
4531 return 0;
4532#else
4533 sigma_dut_print(dut, DUT_MSG_DEBUG,
4534 "Setting RTS not supported");
4535 break;
4536#endif
4537 }
4538 }
4539
4540#if 0
4541 val = get_param(cmd, "FRGMNT");
4542 if (val) {
4543 /* TODO */
4544 send_resp(dut, conn, SIGMA_ERROR,
4545 "ErrorCode,Setting FRGMNT not supported");
4546 return 0;
4547 }
4548#endif
4549
4550#if 0
4551 val = get_param(cmd, "Preamble");
4552 if (val) {
4553 /* TODO: Long/Short */
4554 send_resp(dut, conn, SIGMA_ERROR,
4555 "ErrorCode,Setting Preamble not supported");
4556 return 0;
4557 }
4558#endif
4559
4560 val = get_param(cmd, "Mode");
4561 if (val) {
4562 if (strcmp(val, "11b") == 0 ||
4563 strcmp(val, "11g") == 0 ||
4564 strcmp(val, "11a") == 0 ||
4565 strcmp(val, "11n") == 0 ||
4566 strcmp(val, "11ng") == 0 ||
4567 strcmp(val, "11nl") == 0 ||
4568 strcmp(val, "11nl(nabg)") == 0 ||
4569 strcmp(val, "AC") == 0 ||
4570 strcmp(val, "11AC") == 0 ||
4571 strcmp(val, "11ac") == 0 ||
4572 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004573 strcmp(val, "11an") == 0 ||
4574 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004575 /* STA supports all modes by default */
4576 } else {
4577 send_resp(dut, conn, SIGMA_ERROR,
4578 "ErrorCode,Setting Mode not supported");
4579 return 0;
4580 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004581
4582 /* Change the mode only in case of testbed for HE program
4583 * and for 11a and 11g modes only. */
4584 if (dut->program == PROGRAM_HE &&
4585 dut->device_type == STA_testbed) {
4586 int phymode;
4587 char buf[60];
4588
4589 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004590 phymode = 1; /* IEEE80211_MODE_11A */
4591 } else if (strcmp(val, "11g") == 0) {
4592 phymode = 3; /* IEEE80211_MODE_11G */
4593 } else if (strcmp(val, "11b") == 0) {
4594 phymode = 2; /* IEEE80211_MODE_11B */
4595 } else if (strcmp(val, "11n") == 0 ||
4596 strcmp(val, "11nl") == 0 ||
4597 strcmp(val, "11nl(nabg)") == 0) {
4598 phymode = 22; /* IEEE80211_MODE_11AGN */
4599 } else if (strcmp(val, "11ng") == 0) {
4600 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4601 } else if (strcmp(val, "AC") == 0 ||
4602 strcasecmp(val, "11AC") == 0) {
4603 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4604 } else if (strcmp(val, "11na") == 0 ||
4605 strcasecmp(val, "11an") == 0) {
4606 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4607 } else if (strcmp(val, "11ax") == 0) {
4608 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004609 } else {
4610 sigma_dut_print(dut, DUT_MSG_DEBUG,
4611 "Ignoring mode change for mode: %s",
4612 val);
4613 phymode = -1;
4614 }
4615 if (phymode != -1) {
4616 snprintf(buf, sizeof(buf),
4617 "iwpriv %s setphymode %d",
4618 intf, phymode);
4619 if (system(buf) != 0) {
4620 sigma_dut_print(dut, DUT_MSG_ERROR,
4621 "iwpriv setting of phymode failed");
4622 }
4623 }
4624 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004625 }
4626
4627 val = get_param(cmd, "wmm");
4628 if (val) {
4629 switch (get_driver_type()) {
4630 case DRIVER_ATHEROS:
4631 ath_sta_set_wmm(dut, intf, val);
4632 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004633 case DRIVER_WCN:
4634 wcn_sta_set_wmm(dut, intf, val);
4635 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004636 default:
4637 sigma_dut_print(dut, DUT_MSG_DEBUG,
4638 "Setting wmm not supported");
4639 break;
4640 }
4641 }
4642
4643 val = get_param(cmd, "Powersave");
4644 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004645 char buf[60];
4646
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004647 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004648 if (get_driver_type() == DRIVER_WCN) {
4649 snprintf(buf, sizeof(buf),
4650 "iwpriv %s setPower 2", intf);
4651 if (system(buf) != 0) {
4652 sigma_dut_print(dut, DUT_MSG_ERROR,
4653 "iwpriv setPower 2 failed");
4654 return 0;
4655 }
4656 }
4657
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004658 if (wpa_command(get_station_ifname(),
4659 "P2P_SET ps 0") < 0)
4660 return -2;
4661 /* Make sure test modes are disabled */
4662 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4663 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4664 } else if (strcmp(val, "1") == 0 ||
4665 strcasecmp(val, "PSPoll") == 0 ||
4666 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004667 if (get_driver_type() == DRIVER_WCN) {
4668 snprintf(buf, sizeof(buf),
4669 "iwpriv %s setPower 1", intf);
4670 if (system(buf) != 0) {
4671 sigma_dut_print(dut, DUT_MSG_ERROR,
4672 "iwpriv setPower 1 failed");
4673 return 0;
4674 }
4675 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004676 /* Disable default power save mode */
4677 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4678 /* Enable PS-Poll test mode */
4679 if (wpa_command(get_station_ifname(),
4680 "P2P_SET ps 97") < 0 ||
4681 wpa_command(get_station_ifname(),
4682 "P2P_SET ps 99") < 0)
4683 return -2;
4684 } else if (strcmp(val, "2") == 0 ||
4685 strcasecmp(val, "Fast") == 0) {
4686 /* TODO */
4687 send_resp(dut, conn, SIGMA_ERROR,
4688 "ErrorCode,Powersave=Fast not supported");
4689 return 0;
4690 } else if (strcmp(val, "3") == 0 ||
4691 strcasecmp(val, "PSNonPoll") == 0) {
4692 /* Make sure test modes are disabled */
4693 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4694 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4695
4696 /* Enable default power save mode */
4697 if (wpa_command(get_station_ifname(),
4698 "P2P_SET ps 1") < 0)
4699 return -2;
4700 } else
4701 return -1;
4702 }
4703
4704 val = get_param(cmd, "NoAck");
4705 if (val) {
4706 switch (get_driver_type()) {
4707 case DRIVER_ATHEROS:
4708 ath_sta_set_noack(dut, intf, val);
4709 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004710#ifdef NL80211_SUPPORT
4711 case DRIVER_WCN:
4712 wcn_sta_set_noack(dut, intf, val);
4713 break;
4714#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004715 default:
4716 send_resp(dut, conn, SIGMA_ERROR,
4717 "ErrorCode,Setting NoAck not supported");
4718 return 0;
4719 }
4720 }
4721
4722 val = get_param(cmd, "IgnoreChswitchProhibit");
4723 if (val) {
4724 /* TODO: Enabled/disabled */
4725 if (strcasecmp(val, "Enabled") == 0) {
4726 send_resp(dut, conn, SIGMA_ERROR,
4727 "ErrorCode,Enabling IgnoreChswitchProhibit "
4728 "not supported");
4729 return 0;
4730 }
4731 }
4732
4733 val = get_param(cmd, "TDLS");
4734 if (val) {
4735 if (strcasecmp(val, "Disabled") == 0) {
4736 if (wpa_command(intf, "SET tdls_disabled 1")) {
4737 send_resp(dut, conn, SIGMA_ERROR,
4738 "ErrorCode,Failed to disable TDLS");
4739 return 0;
4740 }
4741 } else if (strcasecmp(val, "Enabled") == 0) {
4742 if (wpa_command(intf, "SET tdls_disabled 0")) {
4743 send_resp(dut, conn, SIGMA_ERROR,
4744 "ErrorCode,Failed to enable TDLS");
4745 return 0;
4746 }
4747 } else {
4748 send_resp(dut, conn, SIGMA_ERROR,
4749 "ErrorCode,Unsupported TDLS value");
4750 return 0;
4751 }
4752 }
4753
4754 val = get_param(cmd, "TDLSmode");
4755 if (val) {
4756 if (strcasecmp(val, "Default") == 0) {
4757 wpa_command(intf, "SET tdls_testing 0");
4758 } else if (strcasecmp(val, "APProhibit") == 0) {
4759 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4760 send_resp(dut, conn, SIGMA_ERROR,
4761 "ErrorCode,Failed to enable ignore "
4762 "APProhibit TDLS mode");
4763 return 0;
4764 }
4765 } else if (strcasecmp(val, "HiLoMac") == 0) {
4766 /* STA should respond with TDLS setup req for a TDLS
4767 * setup req */
4768 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4769 send_resp(dut, conn, SIGMA_ERROR,
4770 "ErrorCode,Failed to enable HiLoMac "
4771 "TDLS mode");
4772 return 0;
4773 }
4774 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4775 /*
4776 * Since all security modes are enabled by default when
4777 * Sigma control is used, there is no need to do
4778 * anything here.
4779 */
4780 } else if (strcasecmp(val, "ExistLink") == 0) {
4781 /*
4782 * Since we allow new TDLS Setup Request even if there
4783 * is an existing link, nothing needs to be done for
4784 * this.
4785 */
4786 } else {
4787 /* TODO:
4788 * ExistLink: STA should send TDLS setup req even if
4789 * direct link already exists
4790 */
4791 send_resp(dut, conn, SIGMA_ERROR,
4792 "ErrorCode,Unsupported TDLSmode value");
4793 return 0;
4794 }
4795 }
4796
4797 val = get_param(cmd, "FakePubKey");
4798 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4799 send_resp(dut, conn, SIGMA_ERROR,
4800 "ErrorCode,Failed to enable FakePubKey");
4801 return 0;
4802 }
4803
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004804#ifdef NL80211_SUPPORT
4805 val = get_param(cmd, "FrgmntSupport");
4806 if (val) {
4807 if (strcasecmp(val, "Enable") == 0) {
4808 if (sta_set_he_fragmentation(dut, intf,
4809 HE_FRAG_LEVEL1)) {
4810 send_resp(dut, conn, SIGMA_ERROR,
4811 "ErrorCode,Failed to enable HE Fragmentation");
4812 return 0;
4813 }
4814 } else if (strcasecmp(val, "Disable") == 0) {
4815 if (sta_set_he_fragmentation(dut, intf,
4816 HE_FRAG_DISABLE)) {
4817 send_resp(dut, conn, SIGMA_ERROR,
4818 "ErrorCode,Failed to disable HE Fragmentation");
4819 return 0;
4820 }
4821 }
4822 }
4823#endif /* NL80211_SUPPORT */
4824
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004825 return 1;
4826}
4827
4828
4829static const char * ath_get_radio_name(const char *radio_name)
4830{
4831 if (radio_name == NULL)
4832 return "wifi0";
4833 if (strcmp(radio_name, "wifi1") == 0)
4834 return "wifi1";
4835 if (strcmp(radio_name, "wifi2") == 0)
4836 return "wifi2";
4837 return "wifi0";
4838}
4839
4840
4841static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4842 const char *val)
4843{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004844 unsigned int vht_mcsmap = 0;
4845 int txchainmask = 0;
4846 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4847
4848 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4849 if (dut->testbed_flag_txsp == 1) {
4850 vht_mcsmap = 0xfffc;
4851 dut->testbed_flag_txsp = 0;
4852 } else {
4853 vht_mcsmap = 0xfffe;
4854 }
4855 txchainmask = 1;
4856 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4857 if (dut->testbed_flag_txsp == 1) {
4858 vht_mcsmap = 0xfff0;
4859 dut->testbed_flag_txsp = 0;
4860 } else {
4861 vht_mcsmap = 0xfffa;
4862 }
4863 txchainmask = 3;
4864 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4865 if (dut->testbed_flag_txsp == 1) {
4866 vht_mcsmap = 0xffc0;
4867 dut->testbed_flag_txsp = 0;
4868 } else {
4869 vht_mcsmap = 0xffea;
4870 }
4871 txchainmask = 7;
4872 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4873 if (dut->testbed_flag_txsp == 1) {
4874 vht_mcsmap = 0xff00;
4875 dut->testbed_flag_txsp = 0;
4876 } else {
4877 vht_mcsmap = 0xffaa;
4878 }
4879 txchainmask = 15;
4880 } else {
4881 if (dut->testbed_flag_txsp == 1) {
4882 vht_mcsmap = 0xffc0;
4883 dut->testbed_flag_txsp = 0;
4884 } else {
4885 vht_mcsmap = 0xffea;
4886 }
4887 }
4888
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004889 if (txchainmask)
4890 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004891
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004892 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004893}
4894
4895
4896static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4897 const char *val)
4898{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004899 unsigned int vht_mcsmap = 0;
4900 int rxchainmask = 0;
4901 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4902
4903 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4904 if (dut->testbed_flag_rxsp == 1) {
4905 vht_mcsmap = 0xfffc;
4906 dut->testbed_flag_rxsp = 0;
4907 } else {
4908 vht_mcsmap = 0xfffe;
4909 }
4910 rxchainmask = 1;
4911 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4912 if (dut->testbed_flag_rxsp == 1) {
4913 vht_mcsmap = 0xfff0;
4914 dut->testbed_flag_rxsp = 0;
4915 } else {
4916 vht_mcsmap = 0xfffa;
4917 }
4918 rxchainmask = 3;
4919 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4920 if (dut->testbed_flag_rxsp == 1) {
4921 vht_mcsmap = 0xffc0;
4922 dut->testbed_flag_rxsp = 0;
4923 } else {
4924 vht_mcsmap = 0xffea;
4925 }
4926 rxchainmask = 7;
4927 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4928 if (dut->testbed_flag_rxsp == 1) {
4929 vht_mcsmap = 0xff00;
4930 dut->testbed_flag_rxsp = 0;
4931 } else {
4932 vht_mcsmap = 0xffaa;
4933 }
4934 rxchainmask = 15;
4935 } else {
4936 if (dut->testbed_flag_rxsp == 1) {
4937 vht_mcsmap = 0xffc0;
4938 dut->testbed_flag_rxsp = 0;
4939 } else {
4940 vht_mcsmap = 0xffea;
4941 }
4942 }
4943
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004944 if (rxchainmask)
4945 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004946
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004947 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004948}
4949
4950
4951void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4952{
4953 if (strcasecmp(val, "enable") == 0) {
4954 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4955 != 0) {
4956 sigma_dut_print(dut, DUT_MSG_ERROR,
4957 "Disable BB_VHTSIGB_CRC_CALC failed");
4958 }
4959
4960 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4961 != 0) {
4962 sigma_dut_print(dut, DUT_MSG_ERROR,
4963 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4964 }
4965 } else {
4966 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4967 != 0) {
4968 sigma_dut_print(dut, DUT_MSG_ERROR,
4969 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4970 }
4971
4972 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4973 != 0) {
4974 sigma_dut_print(dut, DUT_MSG_ERROR,
4975 "Enable BB_VHTSIGB_CRC_CALC failed");
4976 }
4977 }
4978}
4979
4980
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004981static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4982 const char *val)
4983{
4984 char buf[60];
4985
4986 if (strcmp(val, "20") == 0) {
4987 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4988 dut->chwidth = 0;
4989 } else if (strcmp(val, "40") == 0) {
4990 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4991 dut->chwidth = 1;
4992 } else if (strcmp(val, "80") == 0) {
4993 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4994 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05304995 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004996 buf[0] = '\0';
4997 } else {
4998 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4999 val);
5000 return -1;
5001 }
5002
5003 if (buf[0] != '\0' && system(buf) != 0) {
5004 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5005 return -1;
5006 }
5007
5008 return 0;
5009}
5010
5011
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005012static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5013 const char *intf, int addbareject)
5014{
5015#ifdef NL80211_SUPPORT
5016 struct nl_msg *msg;
5017 int ret = 0;
5018 struct nlattr *params;
5019 int ifindex;
5020
5021 ifindex = if_nametoindex(intf);
5022 if (ifindex == 0) {
5023 sigma_dut_print(dut, DUT_MSG_ERROR,
5024 "%s: Index for interface %s failed",
5025 __func__, intf);
5026 return -1;
5027 }
5028
5029 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5030 NL80211_CMD_VENDOR)) ||
5031 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5032 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5033 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5034 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5035 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5036 nla_put_u8(msg,
5037 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5038 !addbareject)) {
5039 sigma_dut_print(dut, DUT_MSG_ERROR,
5040 "%s: err in adding vendor_cmd and vendor_data",
5041 __func__);
5042 nlmsg_free(msg);
5043 return -1;
5044 }
5045 nla_nest_end(msg, params);
5046
5047 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5048 if (ret) {
5049 sigma_dut_print(dut, DUT_MSG_ERROR,
5050 "%s: err in send_and_recv_msgs, ret=%d",
5051 __func__, ret);
5052 }
5053 return ret;
5054#else /* NL80211_SUPPORT */
5055 sigma_dut_print(dut, DUT_MSG_ERROR,
5056 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5057 return -1;
5058#endif /* NL80211_SUPPORT */
5059}
5060
5061
5062static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5063 int addbareject)
5064{
5065 int ret;
5066
5067 switch (get_driver_type()) {
5068 case DRIVER_WCN:
5069 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5070 if (ret) {
5071 sigma_dut_print(dut, DUT_MSG_ERROR,
5072 "nlvendor_sta_set_addba_reject failed, ret:%d",
5073 ret);
5074 return ret;
5075 }
5076 break;
5077 default:
5078 sigma_dut_print(dut, DUT_MSG_ERROR,
5079 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5080 ret = -1;
5081 break;
5082 }
5083
5084 return ret;
5085}
5086
5087
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005088static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5089 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005090{
5091#ifdef NL80211_SUPPORT
5092 struct nl_msg *msg;
5093 int ret = 0;
5094 struct nlattr *params;
5095 int ifindex;
5096
5097 ifindex = if_nametoindex(intf);
5098 if (ifindex == 0) {
5099 sigma_dut_print(dut, DUT_MSG_ERROR,
5100 "%s: Index for interface %s failed",
5101 __func__, intf);
5102 return -1;
5103 }
5104
5105 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5106 NL80211_CMD_VENDOR)) ||
5107 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5108 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5109 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5110 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5111 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5112 nla_put_u8(msg,
5113 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005114 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005115 sigma_dut_print(dut, DUT_MSG_ERROR,
5116 "%s: err in adding vendor_cmd and vendor_data",
5117 __func__);
5118 nlmsg_free(msg);
5119 return -1;
5120 }
5121 nla_nest_end(msg, params);
5122
5123 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5124 if (ret) {
5125 sigma_dut_print(dut, DUT_MSG_ERROR,
5126 "%s: err in send_and_recv_msgs, ret=%d",
5127 __func__, ret);
5128 }
5129 return ret;
5130#else /* NL80211_SUPPORT */
5131 sigma_dut_print(dut, DUT_MSG_ERROR,
5132 "Disable addba not possible without NL80211_SUPPORT defined");
5133 return -1;
5134#endif /* NL80211_SUPPORT */
5135}
5136
5137
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305138#ifdef NL80211_SUPPORT
5139static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5140{
5141 struct nl_msg *msg;
5142 int ret = 0;
5143 int ifindex;
5144
5145 ifindex = if_nametoindex(intf);
5146 if (ifindex == 0) {
5147 sigma_dut_print(dut, DUT_MSG_ERROR,
5148 "%s: Index for interface %s failed",
5149 __func__, intf);
5150 return -1;
5151 }
5152
5153 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5154 NL80211_CMD_SET_WIPHY)) ||
5155 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5156 sigma_dut_print(dut, DUT_MSG_ERROR,
5157 "%s: err in adding RTS threshold",
5158 __func__);
5159 nlmsg_free(msg);
5160 return -1;
5161 }
5162
5163 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5164 if (ret) {
5165 sigma_dut_print(dut, DUT_MSG_ERROR,
5166 "%s: err in send_and_recv_msgs, ret=%d",
5167 __func__, ret);
5168 }
5169 return ret;
5170}
5171#endif /* NL80211_SUPPORT */
5172
5173
5174static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5175{
5176 char buf[100];
5177
5178#ifdef NL80211_SUPPORT
5179 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5180 return 0;
5181 sigma_dut_print(dut, DUT_MSG_DEBUG,
5182 "Fall back to using iwconfig for setting RTS threshold");
5183#endif /* NL80211_SUPPORT */
5184
5185 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5186 if (system(buf) != 0) {
5187 sigma_dut_print(dut, DUT_MSG_ERROR,
5188 "Failed to set RTS threshold %d", val);
5189 return -1;
5190 }
5191 return 0;
5192}
5193
5194
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005195static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5196 struct sigma_conn *conn,
5197 struct sigma_cmd *cmd)
5198{
5199 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005200 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005201 char buf[128];
5202 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005203
5204 val = get_param(cmd, "40_INTOLERANT");
5205 if (val) {
5206 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5207 /* TODO: iwpriv ht40intol through wpa_supplicant */
5208 send_resp(dut, conn, SIGMA_ERROR,
5209 "ErrorCode,40_INTOLERANT not supported");
5210 return 0;
5211 }
5212 }
5213
5214 val = get_param(cmd, "ADDBA_REJECT");
5215 if (val) {
5216 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5217 /* reject any ADDBA with status "decline" */
5218 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005219 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005220 } else {
5221 /* accept ADDBA */
5222 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005223 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005224 }
5225 }
5226
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005227 if (addbareject >= 0 &&
5228 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5229 send_resp(dut, conn, SIGMA_ERROR,
5230 "ErrorCode,set addba_reject failed");
5231 return 0;
5232 }
5233
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005234 val = get_param(cmd, "AMPDU");
5235 if (val) {
5236 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5237 /* enable AMPDU Aggregation */
5238 if (ampdu == 0) {
5239 send_resp(dut, conn, SIGMA_ERROR,
5240 "ErrorCode,Mismatch in "
5241 "addba_reject/ampdu - "
5242 "not supported");
5243 return 0;
5244 }
5245 ampdu = 1;
5246 } else {
5247 /* disable AMPDU Aggregation */
5248 if (ampdu == 1) {
5249 send_resp(dut, conn, SIGMA_ERROR,
5250 "ErrorCode,Mismatch in "
5251 "addba_reject/ampdu - "
5252 "not supported");
5253 return 0;
5254 }
5255 ampdu = 0;
5256 }
5257 }
5258
5259 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005260 int ret;
5261
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005262 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5263 ampdu ? "Enabling" : "Disabling");
5264 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005265 if (wpa_command(intf, buf) < 0 &&
5266 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005267 send_resp(dut, conn, SIGMA_ERROR,
5268 "ErrorCode,set aggr failed");
5269 return 0;
5270 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005271
5272 if (ampdu == 0) {
5273 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005274 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005275 if (ret) {
5276 sigma_dut_print(dut, DUT_MSG_ERROR,
5277 "Failed to disable addba, ret:%d",
5278 ret);
5279 }
5280 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005281 }
5282
5283 val = get_param(cmd, "AMSDU");
5284 if (val) {
5285 switch (get_driver_type()) {
5286 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005287 case DRIVER_WCN:
5288 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005289 break;
5290 default:
5291 if (strcmp(val, "1") == 0 ||
5292 strcasecmp(val, "Enable") == 0) {
5293 /* Enable AMSDU Aggregation */
5294 send_resp(dut, conn, SIGMA_ERROR,
5295 "ErrorCode,AMSDU aggregation not supported");
5296 return 0;
5297 }
5298 break;
5299 }
5300 }
5301
5302 val = get_param(cmd, "STBC_RX");
5303 if (val) {
5304 switch (get_driver_type()) {
5305 case DRIVER_ATHEROS:
5306 ath_sta_set_stbc(dut, intf, val);
5307 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305308 case DRIVER_WCN:
5309 wcn_sta_set_stbc(dut, intf, val);
5310 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005311 default:
5312 send_resp(dut, conn, SIGMA_ERROR,
5313 "ErrorCode,STBC_RX not supported");
5314 return 0;
5315 }
5316 }
5317
5318 val = get_param(cmd, "WIDTH");
5319 if (val) {
5320 switch (get_driver_type()) {
5321 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005322 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005323 send_resp(dut, conn, SIGMA_ERROR,
5324 "ErrorCode,Failed to set WIDTH");
5325 return 0;
5326 }
5327 break;
5328 case DRIVER_ATHEROS:
5329 if (ath_set_width(dut, conn, intf, val) < 0)
5330 return 0;
5331 break;
5332 default:
5333 sigma_dut_print(dut, DUT_MSG_ERROR,
5334 "Setting WIDTH not supported");
5335 break;
5336 }
5337 }
5338
5339 val = get_param(cmd, "SMPS");
5340 if (val) {
5341 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5342 send_resp(dut, conn, SIGMA_ERROR,
5343 "ErrorCode,SMPS not supported");
5344 return 0;
5345 }
5346
5347 val = get_param(cmd, "TXSP_STREAM");
5348 if (val) {
5349 switch (get_driver_type()) {
5350 case DRIVER_WCN:
5351 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5352 send_resp(dut, conn, SIGMA_ERROR,
5353 "ErrorCode,Failed to set TXSP_STREAM");
5354 return 0;
5355 }
5356 break;
5357 case DRIVER_ATHEROS:
5358 ath_sta_set_txsp_stream(dut, intf, val);
5359 break;
5360 default:
5361 sigma_dut_print(dut, DUT_MSG_ERROR,
5362 "Setting TXSP_STREAM not supported");
5363 break;
5364 }
5365 }
5366
5367 val = get_param(cmd, "RXSP_STREAM");
5368 if (val) {
5369 switch (get_driver_type()) {
5370 case DRIVER_WCN:
5371 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5372 send_resp(dut, conn, SIGMA_ERROR,
5373 "ErrorCode,Failed to set RXSP_STREAM");
5374 return 0;
5375 }
5376 break;
5377 case DRIVER_ATHEROS:
5378 ath_sta_set_rxsp_stream(dut, intf, val);
5379 break;
5380 default:
5381 sigma_dut_print(dut, DUT_MSG_ERROR,
5382 "Setting RXSP_STREAM not supported");
5383 break;
5384 }
5385 }
5386
5387 val = get_param(cmd, "DYN_BW_SGNL");
5388 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005389 switch (get_driver_type()) {
5390 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005391 if (strcasecmp(val, "enable") == 0) {
5392 snprintf(buf, sizeof(buf),
5393 "iwpriv %s cwmenable 1", intf);
5394 if (system(buf) != 0) {
5395 sigma_dut_print(dut, DUT_MSG_ERROR,
5396 "iwpriv cwmenable 1 failed");
5397 return 0;
5398 }
5399 } else if (strcasecmp(val, "disable") == 0) {
5400 snprintf(buf, sizeof(buf),
5401 "iwpriv %s cwmenable 0", intf);
5402 if (system(buf) != 0) {
5403 sigma_dut_print(dut, DUT_MSG_ERROR,
5404 "iwpriv cwmenable 0 failed");
5405 return 0;
5406 }
5407 } else {
5408 sigma_dut_print(dut, DUT_MSG_ERROR,
5409 "Unsupported DYN_BW_SGL");
5410 }
5411
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005412 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5413 if (system(buf) != 0) {
5414 sigma_dut_print(dut, DUT_MSG_ERROR,
5415 "Failed to set cts_cbw in DYN_BW_SGNL");
5416 return 0;
5417 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005418 break;
5419 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005420 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005421 ath_config_dyn_bw_sig(dut, intf, val);
5422 break;
5423 default:
5424 sigma_dut_print(dut, DUT_MSG_ERROR,
5425 "Failed to set DYN_BW_SGNL");
5426 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005427 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005428 }
5429
5430 val = get_param(cmd, "RTS_FORCE");
5431 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005432 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005433 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305434 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005435 sigma_dut_print(dut, DUT_MSG_ERROR,
5436 "Failed to set RTS_FORCE 64");
5437 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005438 res = snprintf(buf, sizeof(buf),
5439 "wifitool %s beeliner_fw_test 100 1",
5440 intf);
5441 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005442 sigma_dut_print(dut, DUT_MSG_ERROR,
5443 "wifitool beeliner_fw_test 100 1 failed");
5444 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005445 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305446 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005447 sigma_dut_print(dut, DUT_MSG_ERROR,
5448 "Failed to set RTS_FORCE 2347");
5449 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005450 } else {
5451 send_resp(dut, conn, SIGMA_ERROR,
5452 "ErrorCode,RTS_FORCE value not supported");
5453 return 0;
5454 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005455 }
5456
5457 val = get_param(cmd, "CTS_WIDTH");
5458 if (val) {
5459 switch (get_driver_type()) {
5460 case DRIVER_WCN:
5461 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5462 send_resp(dut, conn, SIGMA_ERROR,
5463 "ErrorCode,Failed to set CTS_WIDTH");
5464 return 0;
5465 }
5466 break;
5467 case DRIVER_ATHEROS:
5468 ath_set_cts_width(dut, intf, val);
5469 break;
5470 default:
5471 sigma_dut_print(dut, DUT_MSG_ERROR,
5472 "Setting CTS_WIDTH not supported");
5473 break;
5474 }
5475 }
5476
5477 val = get_param(cmd, "BW_SGNL");
5478 if (val) {
5479 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005480 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005481 } else if (strcasecmp(val, "Disable") == 0) {
5482 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005483 } else {
5484 send_resp(dut, conn, SIGMA_ERROR,
5485 "ErrorCode,BW_SGNL value not supported");
5486 return 0;
5487 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005488 }
5489
5490 val = get_param(cmd, "Band");
5491 if (val) {
5492 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5493 /* STA supports all bands by default */
5494 } else {
5495 send_resp(dut, conn, SIGMA_ERROR,
5496 "ErrorCode,Unsupported Band");
5497 return 0;
5498 }
5499 }
5500
5501 val = get_param(cmd, "zero_crc");
5502 if (val) {
5503 switch (get_driver_type()) {
5504 case DRIVER_ATHEROS:
5505 ath_set_zero_crc(dut, val);
5506 break;
5507 default:
5508 break;
5509 }
5510 }
5511
5512 return 1;
5513}
5514
5515
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005516static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5517{
5518 switch (get_driver_type()) {
5519#ifdef __linux__
5520 case DRIVER_WIL6210:
5521 return wil6210_set_force_mcs(dut, force, mcs);
5522#endif /* __linux__ */
5523 default:
5524 sigma_dut_print(dut, DUT_MSG_ERROR,
5525 "Unsupported sta_set_force_mcs with the current driver");
5526 return -1;
5527 }
5528}
5529
5530
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005531static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5532{
5533 switch (get_driver_type()) {
5534#ifdef __linux__
5535 case DRIVER_WIL6210:
5536 return wil6210_force_rsn_ie(dut, state);
5537#endif /* __linux__ */
5538 default:
5539 sigma_dut_print(dut, DUT_MSG_ERROR,
5540 "Unsupported sta_60g_force_rsn_ie with the current driver");
5541 return -1;
5542 }
5543}
5544
5545
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005546static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5547 struct sigma_cmd *cmd)
5548{
5549 const char *val;
5550 char buf[100];
5551
5552 val = get_param(cmd, "MSDUSize");
5553 if (val) {
5554 int mtu;
5555
5556 dut->amsdu_size = atoi(val);
5557 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5558 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5559 sigma_dut_print(dut, DUT_MSG_ERROR,
5560 "MSDUSize %d is above max %d or below min %d",
5561 dut->amsdu_size,
5562 IEEE80211_MAX_DATA_LEN_DMG,
5563 IEEE80211_SNAP_LEN_DMG);
5564 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005565 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005566 }
5567
5568 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5569 sigma_dut_print(dut, DUT_MSG_DEBUG,
5570 "Setting amsdu_size to %d", mtu);
5571 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
5572 get_station_ifname(), mtu);
5573
5574 if (system(buf) != 0) {
5575 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5576 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005577 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005578 }
5579 }
5580
5581 val = get_param(cmd, "BAckRcvBuf");
5582 if (val) {
5583 dut->back_rcv_buf = atoi(val);
5584 if (dut->back_rcv_buf == 0) {
5585 sigma_dut_print(dut, DUT_MSG_ERROR,
5586 "Failed to convert %s or value is 0",
5587 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005588 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005589 }
5590
5591 sigma_dut_print(dut, DUT_MSG_DEBUG,
5592 "Setting BAckRcvBuf to %s", val);
5593 }
5594
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005595 val = get_param(cmd, "MCS_FixedRate");
5596 if (val) {
5597 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5598 sigma_dut_print(dut, DUT_MSG_ERROR,
5599 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005600 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005601 }
5602 }
5603
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005604 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005605}
5606
5607
5608static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5609 struct sigma_cmd *cmd)
5610{
5611 int net_id;
5612 char *ifname;
5613 const char *val;
5614 char buf[100];
5615
5616 dut->mode = SIGMA_MODE_STATION;
5617 ifname = get_main_ifname();
5618 if (wpa_command(ifname, "PING") != 0) {
5619 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005620 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005621 }
5622
5623 wpa_command(ifname, "FLUSH");
5624 net_id = add_network_common(dut, conn, ifname, cmd);
5625 if (net_id < 0) {
5626 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5627 return net_id;
5628 }
5629
5630 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5631 if (set_network(ifname, net_id, "mode", "2") < 0) {
5632 sigma_dut_print(dut, DUT_MSG_ERROR,
5633 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005634 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005635 }
5636
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005637 if (set_network(ifname, net_id, "pbss", "1") < 0)
5638 return -2;
5639
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005640 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005641 "Supplicant set network with mode 2. network_id %d",
5642 net_id);
5643
5644 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5645 sigma_dut_print(dut, DUT_MSG_INFO,
5646 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005647 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005648 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005649
5650 val = get_param(cmd, "Security");
5651 if (val && strcasecmp(val, "OPEN") == 0) {
5652 dut->ap_key_mgmt = AP_OPEN;
5653 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5654 sigma_dut_print(dut, DUT_MSG_ERROR,
5655 "Failed to set supplicant to %s security",
5656 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005657 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005658 }
5659 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5660 dut->ap_key_mgmt = AP_WPA2_PSK;
5661 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5662 sigma_dut_print(dut, DUT_MSG_ERROR,
5663 "Failed to set supplicant to %s security",
5664 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005665 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005666 }
5667
5668 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5669 sigma_dut_print(dut, DUT_MSG_ERROR,
5670 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005671 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005672 }
5673 } else if (val) {
5674 sigma_dut_print(dut, DUT_MSG_ERROR,
5675 "Requested Security %s is not supported on 60GHz",
5676 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005677 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005678 }
5679
5680 val = get_param(cmd, "Encrypt");
5681 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5682 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5683 sigma_dut_print(dut, DUT_MSG_ERROR,
5684 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005685 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005686 }
5687 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5688 sigma_dut_print(dut, DUT_MSG_ERROR,
5689 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005690 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005691 }
5692 } else if (val) {
5693 sigma_dut_print(dut, DUT_MSG_ERROR,
5694 "Requested Encrypt %s is not supported on 60 GHz",
5695 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005696 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005697 }
5698
5699 val = get_param(cmd, "PSK");
5700 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5701 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5702 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005703 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005704 }
5705
5706 /* Convert 60G channel to freq */
5707 switch (dut->ap_channel) {
5708 case 1:
5709 val = "58320";
5710 break;
5711 case 2:
5712 val = "60480";
5713 break;
5714 case 3:
5715 val = "62640";
5716 break;
5717 default:
5718 sigma_dut_print(dut, DUT_MSG_ERROR,
5719 "Failed to configure channel %d. Not supported",
5720 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005721 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005722 }
5723
5724 if (set_network(ifname, net_id, "frequency", val) < 0) {
5725 sigma_dut_print(dut, DUT_MSG_ERROR,
5726 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005727 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005728 }
5729
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005730 if (dut->eap_fragment) {
5731 sigma_dut_print(dut, DUT_MSG_DEBUG,
5732 "Set EAP fragment size to 128 bytes.");
5733 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
5734 return ERROR_SEND_STATUS;
5735 }
5736
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005737 sigma_dut_print(dut, DUT_MSG_DEBUG,
5738 "Supplicant set network with frequency");
5739
5740 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5741 if (wpa_command(ifname, buf) < 0) {
5742 sigma_dut_print(dut, DUT_MSG_INFO,
5743 "Failed to select network id %d on %s",
5744 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005745 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005746 }
5747
5748 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5749
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005750 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005751}
5752
5753
Lior David67543f52017-01-03 19:04:22 +02005754static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5755{
5756 char buf[128], fname[128];
5757 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005758 int res;
Lior David67543f52017-01-03 19:04:22 +02005759
5760 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5761 sigma_dut_print(dut, DUT_MSG_ERROR,
5762 "failed to get wil6210 debugfs dir");
5763 return -1;
5764 }
5765
Jouni Malinen3aa72862019-05-29 23:14:51 +03005766 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5767 if (res < 0 || res >= sizeof(fname))
5768 return -1;
Lior David67543f52017-01-03 19:04:22 +02005769 f = fopen(fname, "w");
5770 if (!f) {
5771 sigma_dut_print(dut, DUT_MSG_ERROR,
5772 "failed to open: %s", fname);
5773 return -1;
5774 }
5775
5776 fprintf(f, "%d\n", abft_len);
5777 fclose(f);
5778
5779 return 0;
5780}
5781
5782
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02005783int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5784 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02005785{
5786 switch (get_driver_type()) {
5787 case DRIVER_WIL6210:
5788 return wil6210_set_abft_len(dut, abft_len);
5789 default:
5790 sigma_dut_print(dut, DUT_MSG_ERROR,
5791 "set abft_len not supported");
5792 return -1;
5793 }
5794}
5795
5796
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005797static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5798 struct sigma_cmd *cmd)
5799{
5800 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005801 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005802
5803 if (dut->dev_role != DEVROLE_PCP) {
5804 send_resp(dut, conn, SIGMA_INVALID,
5805 "ErrorCode,Invalid DevRole");
5806 return 0;
5807 }
5808
5809 val = get_param(cmd, "SSID");
5810 if (val) {
5811 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5812 send_resp(dut, conn, SIGMA_INVALID,
5813 "ErrorCode,Invalid SSID");
5814 return -1;
5815 }
5816
Peng Xub8fc5cc2017-05-10 17:27:28 -07005817 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005818 }
5819
5820 val = get_param(cmd, "CHANNEL");
5821 if (val) {
5822 const char *pos;
5823
5824 dut->ap_channel = atoi(val);
5825 pos = strchr(val, ';');
5826 if (pos) {
5827 pos++;
5828 dut->ap_channel_1 = atoi(pos);
5829 }
5830 }
5831
5832 switch (dut->ap_channel) {
5833 case 1:
5834 case 2:
5835 case 3:
5836 break;
5837 default:
5838 sigma_dut_print(dut, DUT_MSG_ERROR,
5839 "Channel %d is not supported", dut->ap_channel);
5840 send_resp(dut, conn, SIGMA_ERROR,
5841 "Requested channel is not supported");
5842 return -1;
5843 }
5844
5845 val = get_param(cmd, "BCNINT");
5846 if (val)
5847 dut->ap_bcnint = atoi(val);
5848
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005849 val = get_param(cmd, "AllocType");
5850 if (val) {
5851 send_resp(dut, conn, SIGMA_ERROR,
5852 "ErrorCode,AllocType is not supported yet");
5853 return -1;
5854 }
5855
5856 val = get_param(cmd, "PercentBI");
5857 if (val) {
5858 send_resp(dut, conn, SIGMA_ERROR,
5859 "ErrorCode,PercentBI is not supported yet");
5860 return -1;
5861 }
5862
5863 val = get_param(cmd, "CBAPOnly");
5864 if (val) {
5865 send_resp(dut, conn, SIGMA_ERROR,
5866 "ErrorCode,CBAPOnly is not supported yet");
5867 return -1;
5868 }
5869
5870 val = get_param(cmd, "AMPDU");
5871 if (val) {
5872 if (strcasecmp(val, "Enable") == 0)
5873 dut->ap_ampdu = 1;
5874 else if (strcasecmp(val, "Disable") == 0)
5875 dut->ap_ampdu = 2;
5876 else {
5877 send_resp(dut, conn, SIGMA_ERROR,
5878 "ErrorCode,AMPDU value is not Enable nor Disabled");
5879 return -1;
5880 }
5881 }
5882
5883 val = get_param(cmd, "AMSDU");
5884 if (val) {
5885 if (strcasecmp(val, "Enable") == 0)
5886 dut->ap_amsdu = 1;
5887 else if (strcasecmp(val, "Disable") == 0)
5888 dut->ap_amsdu = 2;
5889 }
5890
5891 val = get_param(cmd, "NumMSDU");
5892 if (val) {
5893 send_resp(dut, conn, SIGMA_ERROR,
5894 "ErrorCode, NumMSDU is not supported yet");
5895 return -1;
5896 }
5897
5898 val = get_param(cmd, "ABFTLRang");
5899 if (val) {
5900 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005901 "ABFTLRang parameter %s", val);
5902 if (strcmp(val, "Gt1") == 0)
5903 abft_len = 2; /* 2 slots in this case */
5904 }
5905
5906 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5907 send_resp(dut, conn, SIGMA_ERROR,
5908 "ErrorCode, Can't set ABFT length");
5909 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910 }
5911
5912 if (sta_pcp_start(dut, conn, cmd) < 0) {
5913 send_resp(dut, conn, SIGMA_ERROR,
5914 "ErrorCode, Can't start PCP role");
5915 return -1;
5916 }
5917
5918 return sta_set_60g_common(dut, conn, cmd);
5919}
5920
5921
5922static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5923 struct sigma_cmd *cmd)
5924{
5925 const char *val = get_param(cmd, "DiscoveryMode");
5926
5927 if (dut->dev_role != DEVROLE_STA) {
5928 send_resp(dut, conn, SIGMA_INVALID,
5929 "ErrorCode,Invalid DevRole");
5930 return 0;
5931 }
5932
5933 if (val) {
5934 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5935 /* Ignore Discovery mode till Driver expose API. */
5936#if 0
5937 if (strcasecmp(val, "1") == 0) {
5938 send_resp(dut, conn, SIGMA_INVALID,
5939 "ErrorCode,DiscoveryMode 1 not supported");
5940 return 0;
5941 }
5942
5943 if (strcasecmp(val, "0") == 0) {
5944 /* OK */
5945 } else {
5946 send_resp(dut, conn, SIGMA_INVALID,
5947 "ErrorCode,DiscoveryMode not supported");
5948 return 0;
5949 }
5950#endif
5951 }
5952
5953 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005954 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005955 return sta_set_60g_common(dut, conn, cmd);
5956}
5957
5958
5959static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5960 struct sigma_cmd *cmd)
5961{
5962 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005963 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305964
Jouni Malinened77e672018-01-10 16:45:13 +02005965 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005966 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005967 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305968 wpa_command(intf, "DISCONNECT");
5969 return 1;
5970 }
5971
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005972 disconnect_station(dut);
5973 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5974 * due to cached results. */
5975 wpa_command(intf, "SET ignore_old_scan_res 1");
5976 wpa_command(intf, "BSS_FLUSH");
5977 return 1;
5978}
5979
5980
5981static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5982 struct sigma_cmd *cmd)
5983{
5984 const char *intf = get_param(cmd, "Interface");
5985 const char *bssid = get_param(cmd, "bssid");
5986 const char *val = get_param(cmd, "CHANNEL");
5987 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305988 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305989 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005990 int res;
5991 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305992 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305993 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005994
5995 if (bssid == NULL) {
5996 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5997 "argument");
5998 return 0;
5999 }
6000
6001 if (val)
6002 chan = atoi(val);
6003
6004 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6005 /* The current network may be from sta_associate or
6006 * sta_hs2_associate
6007 */
6008 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6009 0 ||
6010 set_network(intf, 0, "bssid", bssid) < 0)
6011 return -2;
6012 }
6013
6014 ctrl = open_wpa_mon(intf);
6015 if (ctrl == NULL) {
6016 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6017 "wpa_supplicant monitor connection");
6018 return -1;
6019 }
6020
Sunil Duttd30ce092018-01-11 23:56:29 +05306021 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6022 sizeof(result)) < 0 ||
6023 strncmp(result, "COMPLETED", 9) != 0) {
6024 sigma_dut_print(dut, DUT_MSG_DEBUG,
6025 "sta_reassoc: Not connected");
6026 fastreassoc = 0;
6027 }
6028
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306029 if (dut->rsne_override) {
6030#ifdef NL80211_SUPPORT
6031 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
6032 sta_config_rsnie(dut, 1);
6033 dut->config_rsnie = 1;
6034 }
6035#endif /* NL80211_SUPPORT */
6036 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6037 dut->rsne_override);
6038 if (wpa_command(intf, buf) < 0) {
6039 send_resp(dut, conn, SIGMA_ERROR,
6040 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6041 return 0;
6042 }
6043 }
6044
Sunil Duttd30ce092018-01-11 23:56:29 +05306045 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006046#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306047 if (chan) {
6048 unsigned int freq;
6049
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006050 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306051 if (!freq) {
6052 sigma_dut_print(dut, DUT_MSG_ERROR,
6053 "Invalid channel number provided: %d",
6054 chan);
6055 send_resp(dut, conn, SIGMA_INVALID,
6056 "ErrorCode,Invalid channel number");
6057 goto close_mon_conn;
6058 }
6059 res = snprintf(buf, sizeof(buf),
6060 "SCAN TYPE=ONLY freq=%d", freq);
6061 } else {
6062 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6063 }
6064 if (res < 0 || res >= (int) sizeof(buf)) {
6065 send_resp(dut, conn, SIGMA_ERROR,
6066 "ErrorCode,snprintf failed");
6067 goto close_mon_conn;
6068 }
6069 if (wpa_command(intf, buf) < 0) {
6070 sigma_dut_print(dut, DUT_MSG_INFO,
6071 "Failed to start scan");
6072 send_resp(dut, conn, SIGMA_ERROR,
6073 "ErrorCode,scan failed");
6074 goto close_mon_conn;
6075 }
6076
6077 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6078 buf, sizeof(buf));
6079 if (res < 0) {
6080 sigma_dut_print(dut, DUT_MSG_INFO,
6081 "Scan did not complete");
6082 send_resp(dut, conn, SIGMA_ERROR,
6083 "ErrorCode,scan did not complete");
6084 goto close_mon_conn;
6085 }
6086
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006087 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6088 < 0) {
6089 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6090 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306091 status = -2;
6092 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006093 }
6094 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6095 bssid, chan);
6096 if (res > 0 && res < (int) sizeof(buf))
6097 res = wpa_command(intf, buf);
6098
6099 if (res < 0 || res >= (int) sizeof(buf)) {
6100 send_resp(dut, conn, SIGMA_ERROR,
6101 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306102 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 }
6104#else /* ANDROID */
6105 sigma_dut_print(dut, DUT_MSG_DEBUG,
6106 "Reassoc using iwpriv - skip chan=%d info",
6107 chan);
6108 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
6109 if (system(buf) != 0) {
6110 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05306111 status = -2;
6112 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006113 }
6114#endif /* ANDROID */
6115 sigma_dut_print(dut, DUT_MSG_INFO,
6116 "sta_reassoc: Run %s successful", buf);
6117 } else if (wpa_command(intf, "REASSOCIATE")) {
6118 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6119 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306120 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006121 }
6122
6123 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6124 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306125 if (res < 0) {
6126 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
6127 status = -1;
6128 goto close_mon_conn;
6129 }
6130 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006131
Ashwini Patil467efef2017-05-25 12:18:27 +05306132close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006133 wpa_ctrl_detach(ctrl);
6134 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306135 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006136}
6137
6138
6139static void hs2_clear_credentials(const char *intf)
6140{
6141 wpa_command(intf, "REMOVE_CRED all");
6142}
6143
6144
Lior Davidcc88b562017-01-03 18:52:09 +02006145#ifdef __linux__
6146static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6147 unsigned int *aid)
6148{
Lior David0fe101e2017-03-09 16:09:50 +02006149 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006150
Lior David0fe101e2017-03-09 16:09:50 +02006151 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006152}
6153#endif /* __linux__ */
6154
6155
6156static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6157 unsigned int *aid)
6158{
6159 switch (get_driver_type()) {
6160#ifdef __linux__
6161 case DRIVER_WIL6210:
6162 return wil6210_get_aid(dut, bssid, aid);
6163#endif /* __linux__ */
6164 default:
6165 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6166 return -1;
6167 }
6168}
6169
6170
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006171static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6172 struct sigma_cmd *cmd)
6173{
6174 char buf[MAX_CMD_LEN];
6175 char bss_list[MAX_CMD_LEN];
6176 const char *parameter = get_param(cmd, "Parameter");
6177
6178 if (parameter == NULL)
6179 return -1;
6180
Lior Davidcc88b562017-01-03 18:52:09 +02006181 if (strcasecmp(parameter, "AID") == 0) {
6182 unsigned int aid = 0;
6183 char bssid[20];
6184
6185 if (get_wpa_status(get_station_ifname(), "bssid",
6186 bssid, sizeof(bssid)) < 0) {
6187 sigma_dut_print(dut, DUT_MSG_ERROR,
6188 "could not get bssid");
6189 return -2;
6190 }
6191
6192 if (sta_get_aid_60g(dut, bssid, &aid))
6193 return -2;
6194
6195 snprintf(buf, sizeof(buf), "aid,%d", aid);
6196 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6197 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6198 return 0;
6199 }
6200
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006201 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6202 char *bss_line;
6203 char *bss_id = NULL;
6204 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306205 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006206
6207 if (ifname == NULL) {
6208 sigma_dut_print(dut, DUT_MSG_INFO,
6209 "For get DiscoveredDevList need Interface name.");
6210 return -1;
6211 }
6212
6213 /*
6214 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6215 * of BSSIDs in "bssid=<BSSID>\n"
6216 */
6217 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6218 bss_list,
6219 sizeof(bss_list)) < 0) {
6220 sigma_dut_print(dut, DUT_MSG_ERROR,
6221 "Failed to get bss list");
6222 return -1;
6223 }
6224
6225 sigma_dut_print(dut, DUT_MSG_DEBUG,
6226 "bss list for ifname:%s is:%s",
6227 ifname, bss_list);
6228
6229 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306230 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006231 while (bss_line) {
6232 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6233 bss_id) {
6234 int len;
6235
6236 len = snprintf(buf + strlen(buf),
6237 sizeof(buf) - strlen(buf),
6238 ",%s", bss_id);
6239 free(bss_id);
6240 bss_id = NULL;
6241 if (len < 0) {
6242 sigma_dut_print(dut,
6243 DUT_MSG_ERROR,
6244 "Failed to read BSSID");
6245 send_resp(dut, conn, SIGMA_ERROR,
6246 "ErrorCode,Failed to read BSS ID");
6247 return 0;
6248 }
6249
6250 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6251 sigma_dut_print(dut,
6252 DUT_MSG_ERROR,
6253 "Response buf too small for list");
6254 send_resp(dut, conn,
6255 SIGMA_ERROR,
6256 "ErrorCode,Response buf too small for list");
6257 return 0;
6258 }
6259 }
6260
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306261 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006262 }
6263
6264 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6265 buf);
6266 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6267 return 0;
6268 }
6269
6270 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6271 return 0;
6272}
6273
6274
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006275static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6276 struct sigma_cmd *cmd)
6277{
6278 char buf[MAX_CMD_LEN];
6279 const char *parameter = get_param(cmd, "Parameter");
6280
6281 if (!parameter)
6282 return -1;
6283
6284 if (strcasecmp(parameter, "RSSI") == 0) {
6285 char rssi[10];
6286
6287 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
6288 rssi, sizeof(rssi)) < 0) {
6289 sigma_dut_print(dut, DUT_MSG_ERROR,
6290 "Could not get RSSI");
6291 return -2;
6292 }
6293
6294 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6295 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6296 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6297 return 0;
6298 }
6299
6300 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6301 return 0;
6302}
6303
6304
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006305static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
6306 struct sigma_cmd *cmd)
6307{
6308 const char *program = get_param(cmd, "Program");
6309
6310 if (program == NULL)
6311 return -1;
6312
6313 if (strcasecmp(program, "P2PNFC") == 0)
6314 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6315
6316 if (strcasecmp(program, "60ghz") == 0)
6317 return sta_get_parameter_60g(dut, conn, cmd);
6318
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006319 if (strcasecmp(program, "he") == 0)
6320 return sta_get_parameter_he(dut, conn, cmd);
6321
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006322#ifdef ANDROID_NAN
6323 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006324 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006325#endif /* ANDROID_NAN */
6326
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006327#ifdef MIRACAST
6328 if (strcasecmp(program, "WFD") == 0 ||
6329 strcasecmp(program, "DisplayR2") == 0)
6330 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6331#endif /* MIRACAST */
6332
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006333 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6334 return 0;
6335}
6336
6337
6338static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6339 const char *type)
6340{
6341 char buf[100];
6342
6343 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006344 run_iwpriv(dut, intf, "chwidth 2");
6345 run_iwpriv(dut, intf, "mode 11ACVHT80");
6346 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006347 }
6348
6349 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006350 run_iwpriv(dut, intf, "chwidth 0");
6351 run_iwpriv(dut, intf, "mode 11naht40");
6352 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006353 }
6354
6355 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006356 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006357
6358 /* Reset CTS width */
6359 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6360 intf);
6361 if (system(buf) != 0) {
6362 sigma_dut_print(dut, DUT_MSG_ERROR,
6363 "wifitool %s beeliner_fw_test 54 0 failed",
6364 intf);
6365 }
6366
6367 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006368 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006369
6370 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6371 if (system(buf) != 0) {
6372 sigma_dut_print(dut, DUT_MSG_ERROR,
6373 "iwpriv rts failed");
6374 }
6375 }
6376
6377 if (type && strcasecmp(type, "Testbed") == 0) {
6378 dut->testbed_flag_txsp = 1;
6379 dut->testbed_flag_rxsp = 1;
6380 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006381 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006382
6383 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006384 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006385
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006386 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006387
6388 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006389 run_iwpriv(dut, intf, "tx_stbc 0");
6390 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006391
6392 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006393 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006394 }
6395
6396 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006397 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006398 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006399
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006400 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006401 }
6402}
6403
6404
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006405#ifdef NL80211_SUPPORT
6406static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6407 enum he_mcs_config mcs)
6408{
6409 struct nl_msg *msg;
6410 int ret = 0;
6411 struct nlattr *params;
6412 int ifindex;
6413
6414 ifindex = if_nametoindex(intf);
6415 if (ifindex == 0) {
6416 sigma_dut_print(dut, DUT_MSG_ERROR,
6417 "%s: Index for interface %s failed",
6418 __func__, intf);
6419 return -1;
6420 }
6421
6422 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6423 NL80211_CMD_VENDOR)) ||
6424 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6425 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6426 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6427 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6428 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6429 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6430 mcs)) {
6431 sigma_dut_print(dut, DUT_MSG_ERROR,
6432 "%s: err in adding vendor_cmd and vendor_data",
6433 __func__);
6434 nlmsg_free(msg);
6435 return -1;
6436 }
6437 nla_nest_end(msg, params);
6438
6439 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6440 if (ret) {
6441 sigma_dut_print(dut, DUT_MSG_ERROR,
6442 "%s: err in send_and_recv_msgs, ret=%d",
6443 __func__, ret);
6444 }
6445 return ret;
6446}
6447#endif /* NL80211_SUPPORT */
6448
6449
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006450static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6451 const char *intf, int enable)
6452{
6453#ifdef NL80211_SUPPORT
6454 struct nl_msg *msg;
6455 int ret = 0;
6456 struct nlattr *params;
6457 int ifindex;
6458
6459 ifindex = if_nametoindex(intf);
6460 if (ifindex == 0) {
6461 sigma_dut_print(dut, DUT_MSG_ERROR,
6462 "%s: Index for interface %s failed",
6463 __func__, intf);
6464 return -1;
6465 }
6466
6467 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6468 NL80211_CMD_VENDOR)) ||
6469 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6470 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6471 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6472 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6473 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6474 nla_put_u8(msg,
6475 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6476 enable)) {
6477 sigma_dut_print(dut, DUT_MSG_ERROR,
6478 "%s: err in adding vendor_cmd and vendor_data",
6479 __func__);
6480 nlmsg_free(msg);
6481 return -1;
6482 }
6483 nla_nest_end(msg, params);
6484
6485 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6486 if (ret) {
6487 sigma_dut_print(dut, DUT_MSG_ERROR,
6488 "%s: err in send_and_recv_msgs, ret=%d",
6489 __func__, ret);
6490 }
6491 return ret;
6492#else /* NL80211_SUPPORT */
6493 sigma_dut_print(dut, DUT_MSG_ERROR,
6494 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6495 return -1;
6496#endif /* NL80211_SUPPORT */
6497}
6498
6499
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006500static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6501 const char *intf, int enable)
6502{
6503#ifdef NL80211_SUPPORT
6504 struct nl_msg *msg;
6505 int ret = 0;
6506 struct nlattr *params;
6507 int ifindex;
6508
6509 ifindex = if_nametoindex(intf);
6510 if (ifindex == 0) {
6511 sigma_dut_print(dut, DUT_MSG_ERROR,
6512 "%s: Index for interface %s failed",
6513 __func__, intf);
6514 return -1;
6515 }
6516
6517 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6518 NL80211_CMD_VENDOR)) ||
6519 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6520 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6521 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6522 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6523 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6524 nla_put_u8(msg,
6525 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6526 enable)) {
6527 sigma_dut_print(dut, DUT_MSG_ERROR,
6528 "%s: err in adding vendor_cmd and vendor_data",
6529 __func__);
6530 nlmsg_free(msg);
6531 return -1;
6532 }
6533 nla_nest_end(msg, params);
6534
6535 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6536 if (ret) {
6537 sigma_dut_print(dut, DUT_MSG_ERROR,
6538 "%s: err in send_and_recv_msgs, ret=%d",
6539 __func__, ret);
6540 }
6541 return ret;
6542#else /* NL80211_SUPPORT */
6543 sigma_dut_print(dut, DUT_MSG_ERROR,
6544 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6545 return -1;
6546#endif /* NL80211_SUPPORT */
6547}
6548
6549
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006550#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006551
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006552static int sta_set_he_testbed_def(struct sigma_dut *dut,
6553 const char *intf, int cfg)
6554{
6555 struct nl_msg *msg;
6556 int ret = 0;
6557 struct nlattr *params;
6558 int ifindex;
6559
6560 ifindex = if_nametoindex(intf);
6561 if (ifindex == 0) {
6562 sigma_dut_print(dut, DUT_MSG_ERROR,
6563 "%s: Index for interface %s failed",
6564 __func__, intf);
6565 return -1;
6566 }
6567
6568 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6569 NL80211_CMD_VENDOR)) ||
6570 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6571 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6572 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6573 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6574 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6575 nla_put_u8(msg,
6576 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6577 cfg)) {
6578 sigma_dut_print(dut, DUT_MSG_ERROR,
6579 "%s: err in adding vendor_cmd and vendor_data",
6580 __func__);
6581 nlmsg_free(msg);
6582 return -1;
6583 }
6584 nla_nest_end(msg, params);
6585
6586 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6587 if (ret) {
6588 sigma_dut_print(dut, DUT_MSG_ERROR,
6589 "%s: err in send_and_recv_msgs, ret=%d",
6590 __func__, ret);
6591 }
6592 return ret;
6593}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006594
6595
6596static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
6597{
6598 struct nl_msg *msg;
6599 int ret = 0;
6600 struct nlattr *params;
6601 int ifindex;
6602
6603 ifindex = if_nametoindex(intf);
6604 if (ifindex == 0) {
6605 sigma_dut_print(dut, DUT_MSG_ERROR,
6606 "%s: Index for interface %s failed",
6607 __func__, intf);
6608 return -1;
6609 }
6610
6611 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6612 NL80211_CMD_VENDOR)) ||
6613 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6614 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6615 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6616 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6617 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6618 nla_put_u8(msg,
6619 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
6620 cfg)) {
6621 sigma_dut_print(dut, DUT_MSG_ERROR,
6622 "%s: err in adding vendor_cmd and vendor_data",
6623 __func__);
6624 nlmsg_free(msg);
6625 return -1;
6626 }
6627 nla_nest_end(msg, params);
6628
6629 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6630 if (ret) {
6631 sigma_dut_print(dut, DUT_MSG_ERROR,
6632 "%s: err in send_and_recv_msgs, ret=%d",
6633 __func__, ret);
6634 }
6635 return ret;
6636}
6637
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006638#endif /* NL80211_SUPPORT */
6639
6640
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006641static int sta_set_addba_buf_size(struct sigma_dut *dut,
6642 const char *intf, int bufsize)
6643{
6644#ifdef NL80211_SUPPORT
6645 struct nl_msg *msg;
6646 int ret = 0;
6647 struct nlattr *params;
6648 int ifindex;
6649
6650 ifindex = if_nametoindex(intf);
6651 if (ifindex == 0) {
6652 sigma_dut_print(dut, DUT_MSG_ERROR,
6653 "%s: Index for interface %s failed",
6654 __func__, intf);
6655 return -1;
6656 }
6657
6658 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6659 NL80211_CMD_VENDOR)) ||
6660 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6661 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6662 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6663 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6664 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006665 nla_put_u16(msg,
6666 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6667 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006668 sigma_dut_print(dut, DUT_MSG_ERROR,
6669 "%s: err in adding vendor_cmd and vendor_data",
6670 __func__);
6671 nlmsg_free(msg);
6672 return -1;
6673 }
6674 nla_nest_end(msg, params);
6675
6676 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6677 if (ret) {
6678 sigma_dut_print(dut, DUT_MSG_ERROR,
6679 "%s: err in send_and_recv_msgs, ret=%d",
6680 __func__, ret);
6681 }
6682 return ret;
6683#else /* NL80211_SUPPORT */
6684 sigma_dut_print(dut, DUT_MSG_ERROR,
6685 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6686 return -1;
6687#endif /* NL80211_SUPPORT */
6688}
6689
6690
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006691static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6692 int enable)
6693{
6694#ifdef NL80211_SUPPORT
6695 struct nl_msg *msg;
6696 int ret = 0;
6697 struct nlattr *params;
6698 int ifindex;
6699
6700 ifindex = if_nametoindex(intf);
6701 if (ifindex == 0) {
6702 sigma_dut_print(dut, DUT_MSG_ERROR,
6703 "%s: Index for interface %s failed",
6704 __func__, intf);
6705 return -1;
6706 }
6707
6708 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6709 NL80211_CMD_VENDOR)) ||
6710 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6711 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6712 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6713 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6714 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6715 nla_put_u8(msg,
6716 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
6717 enable)) {
6718 sigma_dut_print(dut, DUT_MSG_ERROR,
6719 "%s: err in adding vendor_cmd and vendor_data",
6720 __func__);
6721 nlmsg_free(msg);
6722 return -1;
6723 }
6724 nla_nest_end(msg, params);
6725
6726 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6727 if (ret) {
6728 sigma_dut_print(dut, DUT_MSG_ERROR,
6729 "%s: err in send_and_recv_msgs, ret=%d",
6730 __func__, ret);
6731 }
6732 return ret;
6733#else /* NL80211_SUPPORT */
6734 sigma_dut_print(dut, DUT_MSG_ERROR,
6735 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
6736 return -1;
6737#endif /* NL80211_SUPPORT */
6738}
6739
6740
Arif Hussain9765f7d2018-07-03 08:28:26 -07006741static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
6742 int val)
6743{
6744#ifdef NL80211_SUPPORT
6745 struct nl_msg *msg;
6746 int ret = 0;
6747 struct nlattr *params;
6748 int ifindex;
6749
6750 ifindex = if_nametoindex(intf);
6751 if (ifindex == 0) {
6752 sigma_dut_print(dut, DUT_MSG_ERROR,
6753 "%s: Index for interface %s failed, val:%d",
6754 __func__, intf, val);
6755 return -1;
6756 }
6757
6758 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6759 NL80211_CMD_VENDOR)) ||
6760 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6761 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6762 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6763 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6764 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6765 nla_put_u8(msg,
6766 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
6767 val)) {
6768 sigma_dut_print(dut, DUT_MSG_ERROR,
6769 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6770 __func__, val);
6771 nlmsg_free(msg);
6772 return -1;
6773 }
6774 nla_nest_end(msg, params);
6775
6776 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6777 if (ret) {
6778 sigma_dut_print(dut, DUT_MSG_ERROR,
6779 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6780 __func__, ret, val);
6781 }
6782 return ret;
6783#else /* NL80211_SUPPORT */
6784 sigma_dut_print(dut, DUT_MSG_ERROR,
6785 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
6786 return -1;
6787#endif /* NL80211_SUPPORT */
6788}
6789
6790
Arif Hussain68d23f52018-07-11 13:39:08 -07006791#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006792static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
6793 enum qca_wlan_he_mac_padding_dur val)
6794{
Arif Hussain68d23f52018-07-11 13:39:08 -07006795 struct nl_msg *msg;
6796 int ret = 0;
6797 struct nlattr *params;
6798 int ifindex;
6799
6800 ifindex = if_nametoindex(intf);
6801 if (ifindex == 0) {
6802 sigma_dut_print(dut, DUT_MSG_ERROR,
6803 "%s: Index for interface %s failed, val:%d",
6804 __func__, intf, val);
6805 return -1;
6806 }
6807
6808 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6809 NL80211_CMD_VENDOR)) ||
6810 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6811 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6812 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6813 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6814 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6815 nla_put_u8(msg,
6816 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
6817 val)) {
6818 sigma_dut_print(dut, DUT_MSG_ERROR,
6819 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6820 __func__, val);
6821 nlmsg_free(msg);
6822 return -1;
6823 }
6824 nla_nest_end(msg, params);
6825
6826 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6827 if (ret) {
6828 sigma_dut_print(dut, DUT_MSG_ERROR,
6829 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6830 __func__, ret, val);
6831 }
6832 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07006833}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006834#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07006835
6836
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006837static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
6838 int val)
6839{
6840#ifdef NL80211_SUPPORT
6841 struct nl_msg *msg;
6842 int ret = 0;
6843 struct nlattr *params;
6844 int ifindex;
6845
6846 ifindex = if_nametoindex(intf);
6847 if (ifindex == 0) {
6848 sigma_dut_print(dut, DUT_MSG_ERROR,
6849 "%s: Index for interface %s failed, val:%d",
6850 __func__, intf, val);
6851 return -1;
6852 }
6853
6854 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6855 NL80211_CMD_VENDOR)) ||
6856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6857 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6858 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6859 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6860 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6861 nla_put_u8(msg,
6862 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
6863 val)) {
6864 sigma_dut_print(dut, DUT_MSG_ERROR,
6865 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6866 __func__, val);
6867 nlmsg_free(msg);
6868 return -1;
6869 }
6870 nla_nest_end(msg, params);
6871
6872 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6873 if (ret) {
6874 sigma_dut_print(dut, DUT_MSG_ERROR,
6875 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6876 __func__, ret, val);
6877 }
6878 return ret;
6879#else /* NL80211_SUPPORT */
6880 sigma_dut_print(dut, DUT_MSG_ERROR,
6881 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
6882 return -1;
6883#endif /* NL80211_SUPPORT */
6884}
6885
6886
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006887#ifdef NL80211_SUPPORT
6888static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
6889{
6890 struct nl_msg *msg;
6891 int ret = 0;
6892 struct nlattr *params;
6893 int ifindex;
6894
6895 ifindex = if_nametoindex(intf);
6896 if (ifindex == 0) {
6897 sigma_dut_print(dut, DUT_MSG_ERROR,
6898 "%s: Index for interface %s failed",
6899 __func__, intf);
6900 return -1;
6901 }
6902
6903 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6904 NL80211_CMD_VENDOR)) ||
6905 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6906 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6907 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6908 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6909 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6910 nla_put_flag(msg,
6911 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
6912 sigma_dut_print(dut, DUT_MSG_ERROR,
6913 "%s: err in adding vendor_cmd and vendor_data",
6914 __func__);
6915 nlmsg_free(msg);
6916 return -1;
6917 }
6918 nla_nest_end(msg, params);
6919
6920 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6921 if (ret) {
6922 sigma_dut_print(dut, DUT_MSG_ERROR,
6923 "%s: err in send_and_recv_msgs, ret=%d",
6924 __func__, ret);
6925 }
6926 return ret;
6927}
6928#endif /* NL80211_SUPPORT */
6929
6930
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006931static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
6932 int val)
6933{
6934#ifdef NL80211_SUPPORT
6935 struct nl_msg *msg;
6936 int ret = 0;
6937 struct nlattr *params;
6938 int ifindex;
6939
6940 ifindex = if_nametoindex(intf);
6941 if (ifindex == 0) {
6942 sigma_dut_print(dut, DUT_MSG_ERROR,
6943 "%s: Index for interface %s failed, val:%d",
6944 __func__, intf, val);
6945 return -1;
6946 }
6947
6948 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6949 NL80211_CMD_VENDOR)) ||
6950 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6951 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6952 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6953 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6954 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6955 nla_put_u8(msg,
6956 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
6957 val)) {
6958 sigma_dut_print(dut, DUT_MSG_ERROR,
6959 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6960 __func__, val);
6961 nlmsg_free(msg);
6962 return -1;
6963 }
6964 nla_nest_end(msg, params);
6965
6966 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6967 if (ret) {
6968 sigma_dut_print(dut, DUT_MSG_ERROR,
6969 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6970 __func__, ret, val);
6971 }
6972 return ret;
6973#else /* NL80211_SUPPORT */
6974 sigma_dut_print(dut, DUT_MSG_ERROR,
6975 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
6976 return -1;
6977#endif /* NL80211_SUPPORT */
6978}
6979
6980
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006981static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
6982 int val)
6983{
6984#ifdef NL80211_SUPPORT
6985 struct nl_msg *msg;
6986 int ret = 0;
6987 struct nlattr *params;
6988 int ifindex;
6989
6990 ifindex = if_nametoindex(intf);
6991 if (ifindex == 0) {
6992 sigma_dut_print(dut, DUT_MSG_ERROR,
6993 "%s: Index for interface %s failed, val:%d",
6994 __func__, intf, val);
6995 return -1;
6996 }
6997
6998 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6999 NL80211_CMD_VENDOR)) ||
7000 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7001 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7002 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7003 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7004 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7005 nla_put_u8(msg,
7006 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7007 val)) {
7008 sigma_dut_print(dut, DUT_MSG_ERROR,
7009 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7010 __func__, val);
7011 nlmsg_free(msg);
7012 return -1;
7013 }
7014 nla_nest_end(msg, params);
7015
7016 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7017 if (ret) {
7018 sigma_dut_print(dut, DUT_MSG_ERROR,
7019 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7020 __func__, ret, val);
7021 }
7022 return ret;
7023#else /* NL80211_SUPPORT */
7024 sigma_dut_print(dut, DUT_MSG_ERROR,
7025 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7026 return -1;
7027#endif /* NL80211_SUPPORT */
7028}
7029
7030
Arif Hussain480d5f42019-03-12 14:40:42 -07007031static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7032 int val)
7033{
7034#ifdef NL80211_SUPPORT
7035 struct nl_msg *msg;
7036 int ret;
7037 struct nlattr *params;
7038 int ifindex;
7039
7040 ifindex = if_nametoindex(intf);
7041 if (ifindex == 0) {
7042 sigma_dut_print(dut, DUT_MSG_ERROR,
7043 "%s: Index for interface %s failed, val:%d",
7044 __func__, intf, val);
7045 return -1;
7046 }
7047
7048 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7049 NL80211_CMD_VENDOR)) ||
7050 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7051 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7052 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7053 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7054 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7055 nla_put_u8(msg,
7056 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7057 val)) {
7058 sigma_dut_print(dut, DUT_MSG_ERROR,
7059 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7060 __func__, val);
7061 nlmsg_free(msg);
7062 return -1;
7063 }
7064 nla_nest_end(msg, params);
7065
7066 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7067 if (ret) {
7068 sigma_dut_print(dut, DUT_MSG_ERROR,
7069 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7070 __func__, ret, val);
7071 }
7072 return ret;
7073#else /* NL80211_SUPPORT */
7074 sigma_dut_print(dut, DUT_MSG_ERROR,
7075 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7076 return -1;
7077#endif /* NL80211_SUPPORT */
7078}
7079
7080
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007081static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7082 const char *type)
7083{
7084 char buf[60];
7085
7086 if (dut->program == PROGRAM_HE) {
7087 /* resetting phymode to auto in case of HE program */
7088 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7089 if (system(buf) != 0) {
7090 sigma_dut_print(dut, DUT_MSG_ERROR,
7091 "iwpriv %s setphymode failed", intf);
7092 }
7093
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007094 /* reset the rate to Auto rate */
7095 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7096 intf);
7097 if (system(buf) != 0) {
7098 sigma_dut_print(dut, DUT_MSG_ERROR,
7099 "iwpriv %s set_11ax_rate 0xff failed",
7100 intf);
7101 }
7102
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007103 /* reset the LDPC setting */
7104 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7105 if (system(buf) != 0) {
7106 sigma_dut_print(dut, DUT_MSG_ERROR,
7107 "iwpriv %s ldpc 1 failed", intf);
7108 }
7109
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007110 /* reset the power save setting */
7111 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7112 if (system(buf) != 0) {
7113 sigma_dut_print(dut, DUT_MSG_ERROR,
7114 "iwpriv %s setPower 2 failed", intf);
7115 }
7116
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007117 /* remove all network profiles */
7118 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007119
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007120 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7121 sta_set_addba_buf_size(dut, intf, 64);
7122
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007123#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007124 /* Reset the device HE capabilities to its default supported
7125 * configuration. */
7126 sta_set_he_testbed_def(dut, intf, 0);
7127
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007128 /* Disable noackpolicy for all AC */
7129 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7130 sigma_dut_print(dut, DUT_MSG_ERROR,
7131 "Disable of noackpolicy for all AC failed");
7132 }
7133#endif /* NL80211_SUPPORT */
7134
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007135 /* Enable WMM by default */
7136 if (wcn_sta_set_wmm(dut, intf, "on")) {
7137 sigma_dut_print(dut, DUT_MSG_ERROR,
7138 "Enable of WMM in sta_reset_default_wcn failed");
7139 }
7140
7141 /* Disable ADDBA_REJECT by default */
7142 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7143 sigma_dut_print(dut, DUT_MSG_ERROR,
7144 "Disable of addba_reject in sta_reset_default_wcn failed");
7145 }
7146
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007147 /* Enable sending of ADDBA by default */
7148 if (nlvendor_config_send_addba(dut, intf, 1)) {
7149 sigma_dut_print(dut, DUT_MSG_ERROR,
7150 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7151 }
7152
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007153 /* Enable AMPDU by default */
7154 iwpriv_sta_set_ampdu(dut, intf, 1);
7155
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007156#ifdef NL80211_SUPPORT
7157 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
7158 sigma_dut_print(dut, DUT_MSG_ERROR,
7159 "Set LTF config to default in sta_reset_default_wcn failed");
7160 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007161
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007162 /* set the beamformee NSTS(maximum number of
7163 * space-time streams) to default DUT config
7164 */
7165 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007166 sigma_dut_print(dut, DUT_MSG_ERROR,
7167 "Failed to set BeamformeeSTS");
7168 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007169
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007170 if (sta_set_mac_padding_duration(
7171 dut, intf,
7172 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007173 sigma_dut_print(dut, DUT_MSG_ERROR,
7174 "Failed to set MAC padding duration");
7175 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007176
7177 if (sta_set_mu_edca_override(dut, intf, 0)) {
7178 sigma_dut_print(dut, DUT_MSG_ERROR,
7179 "ErrorCode,Failed to set MU EDCA override disable");
7180 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007181
7182 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7183 sigma_dut_print(dut, DUT_MSG_ERROR,
7184 "Failed to set OM ctrl supp");
7185 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007186
7187 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7188 sigma_dut_print(dut, DUT_MSG_ERROR,
7189 "Failed to set Tx SU PPDU enable");
7190 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007191
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007192 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7193 sigma_dut_print(dut, DUT_MSG_ERROR,
7194 "failed to send TB PPDU Tx cfg");
7195 }
7196
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007197 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7198 sigma_dut_print(dut, DUT_MSG_ERROR,
7199 "Failed to set OM ctrl reset");
7200 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007201
7202 /* +HTC-HE support default on */
7203 if (sta_set_he_htc_supp(dut, intf, 1)) {
7204 sigma_dut_print(dut, DUT_MSG_ERROR,
7205 "Setting of +HTC-HE support failed");
7206 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007207#endif /* NL80211_SUPPORT */
7208
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007209 if (sta_set_tx_beamformee(dut, intf, 1)) {
7210 sigma_dut_print(dut, DUT_MSG_ERROR,
7211 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7212 }
7213
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007214 /* Set nss to 1 and MCS 0-7 in case of testbed */
7215 if (type && strcasecmp(type, "Testbed") == 0) {
7216#ifdef NL80211_SUPPORT
7217 int ret;
7218#endif /* NL80211_SUPPORT */
7219
7220 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7221 if (system(buf) != 0) {
7222 sigma_dut_print(dut, DUT_MSG_ERROR,
7223 "iwpriv %s nss failed", intf);
7224 }
7225
7226#ifdef NL80211_SUPPORT
7227 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7228 if (ret) {
7229 sigma_dut_print(dut, DUT_MSG_ERROR,
7230 "Setting of MCS failed, ret:%d",
7231 ret);
7232 }
7233#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007234
7235 /* Disable STBC as default */
7236 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007237
7238 /* Disable AMSDU as default */
7239 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007240
7241#ifdef NL80211_SUPPORT
7242 /* HE fragmentation default off */
7243 if (sta_set_he_fragmentation(dut, intf,
7244 HE_FRAG_DISABLE)) {
7245 sigma_dut_print(dut, DUT_MSG_ERROR,
7246 "Setting of HE fragmentation failed");
7247 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007248
7249 /* set the beamformee NSTS(maximum number of
7250 * space-time streams) to default testbed config
7251 */
7252 if (sta_set_beamformee_sts(dut, intf, 3)) {
7253 sigma_dut_print(dut, DUT_MSG_ERROR,
7254 "Failed to set BeamformeeSTS");
7255 }
7256
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007257 /* +HTC-HE support default off */
7258 if (sta_set_he_htc_supp(dut, intf, 0)) {
7259 sigma_dut_print(dut, DUT_MSG_ERROR,
7260 "Setting of +HTC-HE support failed");
7261 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007262
7263 /* Set device HE capabilities to testbed default
7264 * configuration. */
7265 if (sta_set_he_testbed_def(dut, intf, 1)) {
7266 sigma_dut_print(dut, DUT_MSG_DEBUG,
7267 "Failed to set HE defaults");
7268 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007269
7270 /* Disable VHT support in 2.4 GHz for testbed */
7271 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007272#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007273
7274 /* Enable WEP/TKIP with HE capability in testbed */
7275 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7276 sigma_dut_print(dut, DUT_MSG_ERROR,
7277 "Enabling HE config with WEP/TKIP failed");
7278 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007279 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007280
7281 /* Defaults in case of DUT */
7282 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007283 /* Enable STBC by default */
7284 wcn_sta_set_stbc(dut, intf, "1");
7285
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007286 /* set nss to 2 */
7287 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7288 if (system(buf) != 0) {
7289 sigma_dut_print(dut, DUT_MSG_ERROR,
7290 "iwpriv %s nss 2 failed", intf);
7291 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007292 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007293
7294#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007295 /* Set HE_MCS to 0-11 */
7296 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007297 sigma_dut_print(dut, DUT_MSG_ERROR,
7298 "Setting of MCS failed");
7299 }
7300#endif /* NL80211_SUPPORT */
7301
7302 /* Disable WEP/TKIP with HE capability in DUT */
7303 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7304 sigma_dut_print(dut, DUT_MSG_ERROR,
7305 "Enabling HE config with WEP/TKIP failed");
7306 }
7307 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007308 }
7309}
7310
7311
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007312static int cmd_sta_reset_default(struct sigma_dut *dut,
7313 struct sigma_conn *conn,
7314 struct sigma_cmd *cmd)
7315{
7316 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
7317 struct sigma_cmd *cmd);
7318 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007319 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007320 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007321 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307322 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007323
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007324 if (!program)
7325 program = get_param(cmd, "prog");
7326 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007327 dut->device_type = STA_unknown;
7328 type = get_param(cmd, "type");
7329 if (type && strcasecmp(type, "Testbed") == 0)
7330 dut->device_type = STA_testbed;
7331 if (type && strcasecmp(type, "DUT") == 0)
7332 dut->device_type = STA_dut;
7333
7334 if (dut->program == PROGRAM_TDLS) {
7335 /* Clear TDLS testing mode */
7336 wpa_command(intf, "SET tdls_disabled 0");
7337 wpa_command(intf, "SET tdls_testing 0");
7338 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307339 if (get_driver_type() == DRIVER_WCN) {
7340 /* Enable the WCN driver in TDLS Explicit trigger mode
7341 */
7342 wpa_command(intf, "SET tdls_external_control 0");
7343 wpa_command(intf, "SET tdls_trigger_control 0");
7344 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007345 }
7346
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007347#ifdef MIRACAST
7348 if (dut->program == PROGRAM_WFD ||
7349 dut->program == PROGRAM_DISPLAYR2)
7350 miracast_sta_reset_default(dut, conn, cmd);
7351#endif /* MIRACAST */
7352
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007353 switch (get_driver_type()) {
7354 case DRIVER_ATHEROS:
7355 sta_reset_default_ath(dut, intf, type);
7356 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007357 case DRIVER_WCN:
7358 sta_reset_default_wcn(dut, intf, type);
7359 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007360 default:
7361 break;
7362 }
7363
7364#ifdef ANDROID_NAN
7365 if (dut->program == PROGRAM_NAN)
7366 nan_cmd_sta_reset_default(dut, conn, cmd);
7367#endif /* ANDROID_NAN */
7368
Jouni Malinenba630452018-06-22 11:49:59 +03007369 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007370 unlink("SP/wi-fi.org/pps.xml");
7371 if (system("rm -r SP/*") != 0) {
7372 }
7373 unlink("next-client-cert.pem");
7374 unlink("next-client-key.pem");
7375 }
7376
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007377 /* For WPS program of the 60 GHz band the band type needs to be saved */
7378 if (dut->program == PROGRAM_WPS) {
7379 if (band && strcasecmp(band, "60GHz") == 0) {
7380 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007381 /* For 60 GHz enable WPS for WPS TCs */
7382 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007383 } else {
7384 dut->band = WPS_BAND_NON_60G;
7385 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007386 } else if (dut->program == PROGRAM_60GHZ) {
7387 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7388 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007389 }
7390
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007391 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007392 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007393 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007394
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007395 sigma_dut_print(dut, DUT_MSG_INFO,
7396 "WPS 60 GHz program, wps_disable = %d",
7397 dut->wps_disable);
7398
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007399 if (!dev_role) {
7400 send_resp(dut, conn, SIGMA_ERROR,
7401 "errorCode,Missing DevRole argument");
7402 return 0;
7403 }
7404
7405 if (strcasecmp(dev_role, "STA") == 0)
7406 dut->dev_role = DEVROLE_STA;
7407 else if (strcasecmp(dev_role, "PCP") == 0)
7408 dut->dev_role = DEVROLE_PCP;
7409 else {
7410 send_resp(dut, conn, SIGMA_ERROR,
7411 "errorCode,Unknown DevRole");
7412 return 0;
7413 }
7414
7415 if (dut->device_type == STA_unknown) {
7416 sigma_dut_print(dut, DUT_MSG_ERROR,
7417 "Device type is not STA testbed or DUT");
7418 send_resp(dut, conn, SIGMA_ERROR,
7419 "errorCode,Unknown device type");
7420 return 0;
7421 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007422
7423 sigma_dut_print(dut, DUT_MSG_DEBUG,
7424 "Setting msdu_size to MAX: 7912");
7425 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
7426 get_station_ifname());
7427
7428 if (system(buf) != 0) {
7429 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7430 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007431 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007432 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007433
7434 if (sta_set_force_mcs(dut, 0, 1)) {
7435 sigma_dut_print(dut, DUT_MSG_ERROR,
7436 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007437 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007438 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007439 }
7440
7441 wpa_command(intf, "WPS_ER_STOP");
7442 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307443 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007444 wpa_command(intf, "SET radio_disabled 0");
7445
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007446 dut->wps_forced_version = 0;
7447
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007448 if (dut->wsc_fragment) {
7449 dut->wsc_fragment = 0;
7450 wpa_command(intf, "SET device_name Test client");
7451 wpa_command(intf, "SET manufacturer ");
7452 wpa_command(intf, "SET model_name ");
7453 wpa_command(intf, "SET model_number ");
7454 wpa_command(intf, "SET serial_number ");
7455 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007456 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7457 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7458 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7459 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007460
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007461 if (dut->tmp_mac_addr && dut->set_macaddr) {
7462 dut->tmp_mac_addr = 0;
7463 if (system(dut->set_macaddr) != 0) {
7464 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7465 "temporary MAC address");
7466 }
7467 }
7468
7469 set_ps(intf, dut, 0);
7470
Jouni Malinenba630452018-06-22 11:49:59 +03007471 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7472 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007473 wpa_command(intf, "SET interworking 1");
7474 wpa_command(intf, "SET hs20 1");
7475 }
7476
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007477 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007478 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007479 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007480 wpa_command(intf, "SET pmf 1");
7481 } else {
7482 wpa_command(intf, "SET pmf 0");
7483 }
7484
7485 hs2_clear_credentials(intf);
7486 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7487 wpa_command(intf, "SET access_network_type 15");
7488
7489 static_ip_file(0, NULL, NULL, NULL);
7490 kill_dhcp_client(dut, intf);
7491 clear_ip_addr(dut, intf);
7492
7493 dut->er_oper_performed = 0;
7494 dut->er_oper_bssid[0] = '\0';
7495
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007496 if (dut->program == PROGRAM_LOC) {
7497 /* Disable Interworking by default */
7498 wpa_command(get_station_ifname(), "SET interworking 0");
7499 }
7500
Ashwini Patil00402582017-04-13 12:29:39 +05307501 if (dut->program == PROGRAM_MBO) {
7502 free(dut->non_pref_ch_list);
7503 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307504 free(dut->btm_query_cand_list);
7505 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307506 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307507 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307508 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307509 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307510 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307511 }
7512
Jouni Malinen3c367e82017-06-23 17:01:47 +03007513 free(dut->rsne_override);
7514 dut->rsne_override = NULL;
7515
Jouni Malinen68143132017-09-02 02:34:08 +03007516 free(dut->sae_commit_override);
7517 dut->sae_commit_override = NULL;
7518
Jouni Malinend86e5822017-08-29 03:55:32 +03007519 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007520 free(dut->dpp_peer_uri);
7521 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007522 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007523 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007524
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007525 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7526
vamsi krishnaa2799492017-12-05 14:28:01 +05307527 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307528 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307529 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307530 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7531 dut->fils_hlp = 0;
7532#ifdef ANDROID
7533 hlp_thread_cleanup(dut);
7534#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307535 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307536
Jouni Malinen8179fee2019-03-28 03:19:47 +02007537 dut->akm_values = 0;
7538
Sunil Dutt076081f2018-02-05 19:45:50 +05307539#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05307540 if (get_driver_type() == DRIVER_WCN &&
7541 dut->config_rsnie == 1) {
7542 dut->config_rsnie = 0;
7543 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307544 }
7545#endif /* NL80211_SUPPORT */
7546
Sunil Duttfebf8a82018-02-09 18:50:13 +05307547 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7548 dut->dev_role = DEVROLE_STA_CFON;
7549 return sta_cfon_reset_default(dut, conn, cmd);
7550 }
7551
Jouni Malinen439352d2018-09-13 03:42:23 +03007552 wpa_command(intf, "SET setband AUTO");
7553
Sunil Duttfebf8a82018-02-09 18:50:13 +05307554 if (dut->program != PROGRAM_VHT)
7555 return cmd_sta_p2p_reset(dut, conn, cmd);
7556
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007557 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007558}
7559
7560
7561static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
7562 struct sigma_cmd *cmd)
7563{
7564 const char *program = get_param(cmd, "Program");
7565
7566 if (program == NULL)
7567 return -1;
7568#ifdef ANDROID_NAN
7569 if (strcasecmp(program, "NAN") == 0)
7570 return nan_cmd_sta_get_events(dut, conn, cmd);
7571#endif /* ANDROID_NAN */
7572 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7573 return 0;
7574}
7575
7576
Jouni Malinen82905202018-04-29 17:20:10 +03007577static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7578 struct sigma_cmd *cmd)
7579{
7580 const char *url = get_param(cmd, "url");
7581 const char *method = get_param(cmd, "method");
7582 pid_t pid;
7583 int status;
7584
7585 if (!url || !method)
7586 return -1;
7587
7588 /* TODO: Add support for method,post */
7589 if (strcasecmp(method, "get") != 0) {
7590 send_resp(dut, conn, SIGMA_ERROR,
7591 "ErrorCode,Unsupported method");
7592 return 0;
7593 }
7594
7595 pid = fork();
7596 if (pid < 0) {
7597 perror("fork");
7598 return -1;
7599 }
7600
7601 if (pid == 0) {
7602 char * argv[5] = { "wget", "-O", "/dev/null",
7603 (char *) url, NULL };
7604
7605 execv("/usr/bin/wget", argv);
7606 perror("execv");
7607 exit(0);
7608 return -1;
7609 }
7610
7611 if (waitpid(pid, &status, 0) < 0) {
7612 perror("waitpid");
7613 return -1;
7614 }
7615
7616 if (WIFEXITED(status)) {
7617 const char *errmsg;
7618
7619 if (WEXITSTATUS(status) == 0)
7620 return 1;
7621 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7622 WEXITSTATUS(status));
7623 switch (WEXITSTATUS(status)) {
7624 case 4:
7625 errmsg = "errmsg,Network failure";
7626 break;
7627 case 8:
7628 errmsg = "errmsg,Server issued an error response";
7629 break;
7630 default:
7631 errmsg = "errmsg,Unknown failure from wget";
7632 break;
7633 }
7634 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7635 return 0;
7636 }
7637
7638 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7639 return 0;
7640}
7641
7642
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007643static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
7644 struct sigma_cmd *cmd)
7645{
7646 const char *program = get_param(cmd, "Prog");
7647
Jouni Malinen82905202018-04-29 17:20:10 +03007648 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007649 return -1;
7650#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007651 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007652 return nan_cmd_sta_exec_action(dut, conn, cmd);
7653#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007654
7655 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007656 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007657
7658 if (get_param(cmd, "url"))
7659 return sta_exec_action_url(dut, conn, cmd);
7660
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007661 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7662 return 0;
7663}
7664
7665
7666static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
7667 struct sigma_cmd *cmd)
7668{
7669 const char *intf = get_param(cmd, "Interface");
7670 const char *val, *mcs32, *rate;
7671
7672 val = get_param(cmd, "GREENFIELD");
7673 if (val) {
7674 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7675 /* Enable GD */
7676 send_resp(dut, conn, SIGMA_ERROR,
7677 "ErrorCode,GF not supported");
7678 return 0;
7679 }
7680 }
7681
7682 val = get_param(cmd, "SGI20");
7683 if (val) {
7684 switch (get_driver_type()) {
7685 case DRIVER_ATHEROS:
7686 ath_sta_set_sgi(dut, intf, val);
7687 break;
7688 default:
7689 send_resp(dut, conn, SIGMA_ERROR,
7690 "ErrorCode,SGI20 not supported");
7691 return 0;
7692 }
7693 }
7694
7695 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7696 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7697 if (mcs32 && rate) {
7698 /* TODO */
7699 send_resp(dut, conn, SIGMA_ERROR,
7700 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7701 return 0;
7702 } else if (mcs32 && !rate) {
7703 /* TODO */
7704 send_resp(dut, conn, SIGMA_ERROR,
7705 "ErrorCode,MCS32 not supported");
7706 return 0;
7707 } else if (!mcs32 && rate) {
7708 switch (get_driver_type()) {
7709 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08007710 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007711 ath_sta_set_11nrates(dut, intf, rate);
7712 break;
7713 default:
7714 send_resp(dut, conn, SIGMA_ERROR,
7715 "ErrorCode,MCS32_FIXEDRATE not supported");
7716 return 0;
7717 }
7718 }
7719
7720 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7721}
7722
7723
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007724static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
7725 int mcs_config)
7726{
7727#ifdef NL80211_SUPPORT
7728 int ret;
7729
7730 switch (mcs_config) {
7731 case HE_80_MCS0_7:
7732 case HE_80_MCS0_9:
7733 case HE_80_MCS0_11:
7734 ret = sta_set_he_mcs(dut, intf, mcs_config);
7735 if (ret) {
7736 sigma_dut_print(dut, DUT_MSG_ERROR,
7737 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
7738 mcs_config, ret);
7739 }
7740 break;
7741 default:
7742 sigma_dut_print(dut, DUT_MSG_ERROR,
7743 "cmd_set_max_he_mcs: Invalid mcs %d",
7744 mcs_config);
7745 break;
7746 }
7747#else /* NL80211_SUPPORT */
7748 sigma_dut_print(dut, DUT_MSG_ERROR,
7749 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
7750#endif /* NL80211_SUPPORT */
7751}
7752
7753
Arif Hussain480d5f42019-03-12 14:40:42 -07007754static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
7755 struct sigma_cmd *cmd)
7756{
7757#ifdef NL80211_SUPPORT
7758 struct nlattr *params;
7759 struct nlattr *attr;
7760 struct nlattr *attr1;
7761 struct nl_msg *msg;
7762 int ifindex, ret;
7763 const char *val;
7764 const char *intf = get_param(cmd, "Interface");
7765 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
7766 wake_interval_mantissa = 512;
7767 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
7768 protection = 0;
7769
7770 ifindex = if_nametoindex(intf);
7771 if (ifindex == 0) {
7772 sigma_dut_print(dut, DUT_MSG_ERROR,
7773 "%s: Index for interface %s failed",
7774 __func__, intf);
7775 return -1;
7776 }
7777
7778 val = get_param(cmd, "FlowType");
7779 if (val) {
7780 flow_type = atoi(val);
7781 if (flow_type != 0 && flow_type != 1) {
7782 sigma_dut_print(dut, DUT_MSG_ERROR,
7783 "TWT: Invalid FlowType %d", flow_type);
7784 return -1;
7785 }
7786 }
7787
7788 val = get_param(cmd, "TWT_Trigger");
7789 if (val) {
7790 twt_trigger = atoi(val);
7791 if (twt_trigger != 0 && twt_trigger != 1) {
7792 sigma_dut_print(dut, DUT_MSG_ERROR,
7793 "TWT: Invalid TWT_Trigger %d",
7794 twt_trigger);
7795 return -1;
7796 }
7797 }
7798
7799 val = get_param(cmd, "Protection");
7800 if (val) {
7801 protection = atoi(val);
7802 if (protection != 0 && protection != 1) {
7803 sigma_dut_print(dut, DUT_MSG_ERROR,
7804 "TWT: Invalid Protection %d",
7805 protection);
7806 return -1;
7807 }
7808 }
7809
7810 val = get_param(cmd, "TargetWakeTime");
7811 if (val)
7812 target_wake_time = atoi(val);
7813
7814 val = get_param(cmd, "WakeIntervalMantissa");
7815 if (val)
7816 wake_interval_mantissa = atoi(val);
7817
7818 val = get_param(cmd, "WakeIntervalExp");
7819 if (val)
7820 wake_interval_exp = atoi(val);
7821
7822 val = get_param(cmd, "NominalMinWakeDur");
7823 if (val)
7824 nominal_min_wake_dur = atoi(val);
7825
7826 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7827 NL80211_CMD_VENDOR)) ||
7828 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7829 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7830 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7831 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7832 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7833 !(params = nla_nest_start(
7834 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
7835 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7836 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
7837 wake_interval_exp) ||
7838 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST, 0) ||
7839 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
7840 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER,
7841 twt_trigger) ||
7842 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
7843 flow_type) ||
7844 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION,
7845 protection) ||
7846 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
7847 target_wake_time) ||
7848 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
7849 nominal_min_wake_dur) ||
7850 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
7851 wake_interval_mantissa)) {
7852 sigma_dut_print(dut, DUT_MSG_ERROR,
7853 "%s: err in adding vendor_cmd and vendor_data",
7854 __func__);
7855 nlmsg_free(msg);
7856 return -1;
7857 }
7858 nla_nest_end(msg, attr1);
7859 nla_nest_end(msg, params);
7860 nla_nest_end(msg, attr);
7861
7862 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7863 if (ret) {
7864 sigma_dut_print(dut, DUT_MSG_ERROR,
7865 "%s: err in send_and_recv_msgs, ret=%d",
7866 __func__, ret);
7867 }
7868
7869 return ret;
7870#else /* NL80211_SUPPORT */
7871 sigma_dut_print(dut, DUT_MSG_ERROR,
7872 "TWT request cannot be done without NL80211_SUPPORT defined");
7873 return -1;
7874#endif /* NL80211_SUPPORT */
7875}
7876
7877
7878static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
7879 struct sigma_cmd *cmd)
7880{
7881 #ifdef NL80211_SUPPORT
7882 struct nlattr *params;
7883 struct nlattr *attr;
7884 struct nlattr *attr1;
7885 int ifindex, ret;
7886 struct nl_msg *msg;
7887 const char *intf = get_param(cmd, "Interface");
7888
7889 ifindex = if_nametoindex(intf);
7890 if (ifindex == 0) {
7891 sigma_dut_print(dut, DUT_MSG_ERROR,
7892 "%s: Index for interface %s failed",
7893 __func__, intf);
7894 return -1;
7895 }
7896
7897 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7898 NL80211_CMD_VENDOR)) ||
7899 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7900 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7901 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7902 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7903 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7904 !(params = nla_nest_start(
7905 msg,
7906 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
7907 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7908 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
7909 sigma_dut_print(dut, DUT_MSG_ERROR,
7910 "%s: err in adding vendor_cmd and vendor_data",
7911 __func__);
7912 nlmsg_free(msg);
7913 return -1;
7914 }
7915 nla_nest_end(msg, attr1);
7916 nla_nest_end(msg, params);
7917 nla_nest_end(msg, attr);
7918
7919 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7920 if (ret) {
7921 sigma_dut_print(dut, DUT_MSG_ERROR,
7922 "%s: err in send_and_recv_msgs, ret=%d",
7923 __func__, ret);
7924 }
7925
7926 return ret;
7927#else /* NL80211_SUPPORT */
7928 sigma_dut_print(dut, DUT_MSG_ERROR,
7929 "TWT teardown cannot be done without NL80211_SUPPORT defined");
7930 return -1;
7931#endif /* NL80211_SUPPORT */
7932}
7933
7934
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08007935static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
7936 struct sigma_cmd *cmd)
7937{
7938#ifdef NL80211_SUPPORT
7939 struct nlattr *params;
7940 struct nlattr *attr;
7941 struct nlattr *attr1;
7942 struct nl_msg *msg;
7943 int ifindex, ret;
7944 const char *val;
7945 const char *intf = get_param(cmd, "Interface");
7946 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
7947 ulmu_data_dis = 0;
7948
7949 ifindex = if_nametoindex(intf);
7950 if (ifindex == 0) {
7951 sigma_dut_print(dut, DUT_MSG_ERROR,
7952 "%s: Index for interface %s failed",
7953 __func__, intf);
7954 return -1;
7955 }
7956 val = get_param(cmd, "OMCtrl_RxNSS");
7957 if (val)
7958 rx_nss = atoi(val);
7959
7960 val = get_param(cmd, "OMCtrl_ChnlWidth");
7961 if (val)
7962 ch_bw = atoi(val);
7963
7964 val = get_param(cmd, "OMCtrl_ULMUDisable");
7965 if (val)
7966 ulmu_dis = atoi(val);
7967
7968 val = get_param(cmd, "OMCtrl_TxNSTS");
7969 if (val)
7970 tx_nsts = atoi(val);
7971
7972 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
7973 if (val)
7974 ulmu_data_dis = atoi(val);
7975
7976 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7977 NL80211_CMD_VENDOR)) ||
7978 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7979 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7980 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7981 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7982 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7983 !(params = nla_nest_start(
7984 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
7985 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7986 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
7987 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
7988 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
7989 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
7990 ulmu_data_dis) ||
7991 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
7992 ulmu_dis)) {
7993 sigma_dut_print(dut, DUT_MSG_ERROR,
7994 "%s: err in adding vendor_cmd and vendor_data",
7995 __func__);
7996 nlmsg_free(msg);
7997 return -1;
7998 }
7999 nla_nest_end(msg, attr1);
8000 nla_nest_end(msg, params);
8001 nla_nest_end(msg, attr);
8002
8003 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8004 if (ret) {
8005 sigma_dut_print(dut, DUT_MSG_ERROR,
8006 "%s: err in send_and_recv_msgs, ret=%d",
8007 __func__, ret);
8008 }
8009
8010 return ret;
8011#else /* NL80211_SUPPORT */
8012 sigma_dut_print(dut, DUT_MSG_ERROR,
8013 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8014 return -1;
8015#endif /* NL80211_SUPPORT */
8016}
8017
8018
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008019static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8020 struct sigma_conn *conn,
8021 struct sigma_cmd *cmd)
8022{
8023 const char *intf = get_param(cmd, "Interface");
8024 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008025 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008026 int tkip = -1;
8027 int wep = -1;
8028
Arif Hussaina37e9552018-06-20 17:05:59 -07008029 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008030 val = get_param(cmd, "SGI80");
8031 if (val) {
8032 int sgi80;
8033
8034 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008035 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008036 }
8037
8038 val = get_param(cmd, "TxBF");
8039 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008040 switch (get_driver_type()) {
8041 case DRIVER_WCN:
8042 if (sta_set_tx_beamformee(dut, intf, 1)) {
8043 send_resp(dut, conn, SIGMA_ERROR,
8044 "ErrorCode,Failed to set TX beamformee enable");
8045 return 0;
8046 }
8047 break;
8048 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008049 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008050 send_resp(dut, conn, SIGMA_ERROR,
8051 "ErrorCode,Setting vhtsubfee failed");
8052 return 0;
8053 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008054 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008055 send_resp(dut, conn, SIGMA_ERROR,
8056 "ErrorCode,Setting vhtsubfer failed");
8057 return 0;
8058 }
8059 break;
8060 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008061 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008062 "Unsupported driver type");
8063 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008064 }
8065 }
8066
8067 val = get_param(cmd, "MU_TxBF");
8068 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
8069 switch (get_driver_type()) {
8070 case DRIVER_ATHEROS:
8071 ath_sta_set_txsp_stream(dut, intf, "1SS");
8072 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008073 run_iwpriv(dut, intf, "vhtmubfee 1");
8074 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308075 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008076 case DRIVER_WCN:
8077 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8078 send_resp(dut, conn, SIGMA_ERROR,
8079 "ErrorCode,Failed to set RX/TXSP_STREAM");
8080 return 0;
8081 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308082 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008083 default:
8084 sigma_dut_print(dut, DUT_MSG_ERROR,
8085 "Setting SP_STREAM not supported");
8086 break;
8087 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008088 }
8089
8090 val = get_param(cmd, "LDPC");
8091 if (val) {
8092 int ldpc;
8093
8094 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008095 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008096 }
8097
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008098 val = get_param(cmd, "BCC");
8099 if (val) {
8100 int bcc;
8101
8102 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8103 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8104 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008105 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008106 }
8107
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008108 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8109 if (val && dut->sta_nss == 1)
8110 cmd_set_max_he_mcs(dut, intf, atoi(val));
8111
8112 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8113 if (val && dut->sta_nss == 2)
8114 cmd_set_max_he_mcs(dut, intf, atoi(val));
8115
Arif Hussainac6c5112018-05-25 17:34:00 -07008116 val = get_param(cmd, "MCS_FixedRate");
8117 if (val) {
8118#ifdef NL80211_SUPPORT
8119 int mcs, ratecode = 0;
8120 enum he_mcs_config mcs_config;
8121 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008122 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008123
8124 ratecode = (0x07 & dut->sta_nss) << 5;
8125 mcs = atoi(val);
8126 /* Add the MCS to the ratecode */
8127 if (mcs >= 0 && mcs <= 11) {
8128 ratecode += mcs;
8129 if (dut->device_type == STA_testbed &&
8130 mcs > 7 && mcs <= 11) {
8131 if (mcs <= 9)
8132 mcs_config = HE_80_MCS0_9;
8133 else
8134 mcs_config = HE_80_MCS0_11;
8135 ret = sta_set_he_mcs(dut, intf, mcs_config);
8136 if (ret) {
8137 sigma_dut_print(dut, DUT_MSG_ERROR,
8138 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8139 mcs, mcs_config, ret);
8140 }
8141 }
8142 snprintf(buf, sizeof(buf),
8143 "iwpriv %s set_11ax_rate 0x%03x",
8144 intf, ratecode);
8145 if (system(buf) != 0) {
8146 sigma_dut_print(dut, DUT_MSG_ERROR,
8147 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8148 ratecode);
8149 }
8150 } else {
8151 sigma_dut_print(dut, DUT_MSG_ERROR,
8152 "MCS_FixedRate: HE MCS %d not supported",
8153 mcs);
8154 }
8155#else /* NL80211_SUPPORT */
8156 sigma_dut_print(dut, DUT_MSG_ERROR,
8157 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8158#endif /* NL80211_SUPPORT */
8159 }
8160
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008161 val = get_param(cmd, "opt_md_notif_ie");
8162 if (val) {
8163 char *result = NULL;
8164 char delim[] = ";";
8165 char token[30];
8166 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308167 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008168
Peng Xub8fc5cc2017-05-10 17:27:28 -07008169 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308170 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008171
8172 /* Extract the NSS information */
8173 if (result) {
8174 value = atoi(result);
8175 switch (value) {
8176 case 1:
8177 config_val = 1;
8178 break;
8179 case 2:
8180 config_val = 3;
8181 break;
8182 case 3:
8183 config_val = 7;
8184 break;
8185 case 4:
8186 config_val = 15;
8187 break;
8188 default:
8189 config_val = 3;
8190 break;
8191 }
8192
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008193 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8194 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008195
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008196 }
8197
8198 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308199 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008200 if (result) {
8201 value = atoi(result);
8202 switch (value) {
8203 case 20:
8204 config_val = 0;
8205 break;
8206 case 40:
8207 config_val = 1;
8208 break;
8209 case 80:
8210 config_val = 2;
8211 break;
8212 case 160:
8213 config_val = 3;
8214 break;
8215 default:
8216 config_val = 2;
8217 break;
8218 }
8219
8220 dut->chwidth = config_val;
8221
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008222 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008223 }
8224
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008225 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008226 }
8227
8228 val = get_param(cmd, "nss_mcs_cap");
8229 if (val) {
8230 int nss, mcs;
8231 char token[20];
8232 char *result = NULL;
8233 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308234 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008235
Peng Xub8fc5cc2017-05-10 17:27:28 -07008236 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308237 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308238 if (!result) {
8239 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008240 "NSS not specified");
8241 send_resp(dut, conn, SIGMA_ERROR,
8242 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308243 return 0;
8244 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008245 nss = atoi(result);
8246
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008247 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008248 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008249
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308250 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008251 if (result == NULL) {
8252 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008253 "MCS not specified");
8254 send_resp(dut, conn, SIGMA_ERROR,
8255 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008256 return 0;
8257 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308258 result = strtok_r(result, "-", &saveptr);
8259 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308260 if (!result) {
8261 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008262 "MCS not specified");
8263 send_resp(dut, conn, SIGMA_ERROR,
8264 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308265 return 0;
8266 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008267 mcs = atoi(result);
8268
Arif Hussaina37e9552018-06-20 17:05:59 -07008269 if (program && strcasecmp(program, "HE") == 0) {
8270#ifdef NL80211_SUPPORT
8271 enum he_mcs_config mcs_config;
8272 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008273
Arif Hussaina37e9552018-06-20 17:05:59 -07008274 if (mcs >= 0 && mcs <= 7) {
8275 mcs_config = HE_80_MCS0_7;
8276 } else if (mcs > 7 && mcs <= 9) {
8277 mcs_config = HE_80_MCS0_9;
8278 } else if (mcs > 9 && mcs <= 11) {
8279 mcs_config = HE_80_MCS0_11;
8280 } else {
8281 sigma_dut_print(dut, DUT_MSG_ERROR,
8282 "nss_mcs_cap: HE: Invalid mcs: %d",
8283 mcs);
8284 send_resp(dut, conn, SIGMA_ERROR,
8285 "errorCode,Invalid MCS");
8286 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008287 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008288
8289 ret = sta_set_he_mcs(dut, intf, mcs_config);
8290 if (ret) {
8291 sigma_dut_print(dut, DUT_MSG_ERROR,
8292 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8293 mcs_config, ret);
8294 send_resp(dut, conn, SIGMA_ERROR,
8295 "errorCode,Failed to set MCS");
8296 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008297 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008298#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008299 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008300 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8301#endif /* NL80211_SUPPORT */
8302 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008303 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008304
8305 switch (nss) {
8306 case 1:
8307 switch (mcs) {
8308 case 7:
8309 vht_mcsmap = 0xfffc;
8310 break;
8311 case 8:
8312 vht_mcsmap = 0xfffd;
8313 break;
8314 case 9:
8315 vht_mcsmap = 0xfffe;
8316 break;
8317 default:
8318 vht_mcsmap = 0xfffe;
8319 break;
8320 }
8321 break;
8322 case 2:
8323 switch (mcs) {
8324 case 7:
8325 vht_mcsmap = 0xfff0;
8326 break;
8327 case 8:
8328 vht_mcsmap = 0xfff5;
8329 break;
8330 case 9:
8331 vht_mcsmap = 0xfffa;
8332 break;
8333 default:
8334 vht_mcsmap = 0xfffa;
8335 break;
8336 }
8337 break;
8338 case 3:
8339 switch (mcs) {
8340 case 7:
8341 vht_mcsmap = 0xffc0;
8342 break;
8343 case 8:
8344 vht_mcsmap = 0xffd5;
8345 break;
8346 case 9:
8347 vht_mcsmap = 0xffea;
8348 break;
8349 default:
8350 vht_mcsmap = 0xffea;
8351 break;
8352 }
8353 break;
8354 default:
8355 vht_mcsmap = 0xffea;
8356 break;
8357 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008358 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008359 }
8360 }
8361
8362 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8363
8364 val = get_param(cmd, "Vht_tkip");
8365 if (val)
8366 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8367
8368 val = get_param(cmd, "Vht_wep");
8369 if (val)
8370 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8371
8372 if (tkip != -1 || wep != -1) {
8373 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008374 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008375 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008376 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008377 } else {
8378 sigma_dut_print(dut, DUT_MSG_ERROR,
8379 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8380 return 0;
8381 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008382 }
8383
Arif Hussain55f00da2018-07-03 08:28:26 -07008384 val = get_param(cmd, "txBandwidth");
8385 if (val) {
8386 switch (get_driver_type()) {
8387 case DRIVER_WCN:
8388 if (wcn_sta_set_width(dut, intf, val) < 0) {
8389 send_resp(dut, conn, SIGMA_ERROR,
8390 "ErrorCode,Failed to set txBandwidth");
8391 return 0;
8392 }
8393 break;
8394 case DRIVER_ATHEROS:
8395 if (ath_set_width(dut, conn, intf, val) < 0) {
8396 send_resp(dut, conn, SIGMA_ERROR,
8397 "ErrorCode,Failed to set txBandwidth");
8398 return 0;
8399 }
8400 break;
8401 default:
8402 sigma_dut_print(dut, DUT_MSG_ERROR,
8403 "Setting txBandwidth not supported");
8404 break;
8405 }
8406 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008407
Arif Hussain9765f7d2018-07-03 08:28:26 -07008408 val = get_param(cmd, "BeamformeeSTS");
8409 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008410 if (sta_set_tx_beamformee(dut, intf, 1)) {
8411 send_resp(dut, conn, SIGMA_ERROR,
8412 "ErrorCode,Failed to set TX beamformee enable");
8413 return 0;
8414 }
8415
Arif Hussain9765f7d2018-07-03 08:28:26 -07008416 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8417 send_resp(dut, conn, SIGMA_ERROR,
8418 "ErrorCode,Failed to set BeamformeeSTS");
8419 return 0;
8420 }
8421 }
8422
Arif Hussain68d23f52018-07-11 13:39:08 -07008423 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8424 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008425#ifdef NL80211_SUPPORT
8426 enum qca_wlan_he_mac_padding_dur set_val;
8427
8428 switch (atoi(val)) {
8429 case 16:
8430 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8431 break;
8432 case 8:
8433 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8434 break;
8435 default:
8436 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8437 break;
8438 }
8439 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008440 send_resp(dut, conn, SIGMA_ERROR,
8441 "ErrorCode,Failed to set MAC padding duration");
8442 return 0;
8443 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008444#else /* NL80211_SUPPORT */
8445 sigma_dut_print(dut, DUT_MSG_ERROR,
8446 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8447#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008448 }
8449
Arif Hussain480d5f42019-03-12 14:40:42 -07008450 val = get_param(cmd, "TWT_ReqSupport");
8451 if (val) {
8452 int set_val;
8453
8454 if (strcasecmp(val, "Enable") == 0) {
8455 set_val = 1;
8456 } else if (strcasecmp(val, "Disable") == 0) {
8457 set_val = 0;
8458 } else {
8459 send_resp(dut, conn, SIGMA_ERROR,
8460 "ErrorCode,Invalid TWT_ReqSupport");
8461 return STATUS_SENT;
8462 }
8463
8464 if (sta_set_twt_req_support(dut, intf, set_val)) {
8465 sigma_dut_print(dut, DUT_MSG_ERROR,
8466 "Failed to set TWT req support %d",
8467 set_val);
8468 send_resp(dut, conn, SIGMA_ERROR,
8469 "ErrorCode,Failed to set TWT_ReqSupport");
8470 return STATUS_SENT;
8471 }
8472 }
8473
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008474 val = get_param(cmd, "MU_EDCA");
8475 if (val && (strcasecmp(val, "Override") == 0)) {
8476 if (sta_set_mu_edca_override(dut, intf, 1)) {
8477 send_resp(dut, conn, SIGMA_ERROR,
8478 "ErrorCode,Failed to set MU EDCA override");
8479 return 0;
8480 }
8481 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008482
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008483 val = get_param(cmd, "OMControl");
8484 if (val) {
8485 int set_val = 1;
8486
8487 if (strcasecmp(val, "Enable") == 0)
8488 set_val = 1;
8489 else if (strcasecmp(val, "Disable") == 0)
8490 set_val = 0;
8491
8492 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8493 send_resp(dut, conn, SIGMA_ERROR,
8494 "ErrorCode,Failed to set OM ctrl supp");
8495 return 0;
8496 }
8497 }
8498
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008499 val = get_param(cmd, "ADDBAResp_BufSize");
8500 if (val) {
8501 int buf_size;
8502
8503 if (strcasecmp(val, "gt64") == 0)
8504 buf_size = 256;
8505 else
8506 buf_size = 64;
8507 if (get_driver_type() == DRIVER_WCN &&
8508 sta_set_addba_buf_size(dut, intf, buf_size)) {
8509 send_resp(dut, conn, SIGMA_ERROR,
8510 "ErrorCode,set addbaresp_buff_size failed");
8511 return 0;
8512 }
8513 }
8514
8515 val = get_param(cmd, "ADDBAReq_BufSize");
8516 if (val) {
8517 int buf_size;
8518
8519 if (strcasecmp(val, "gt64") == 0)
8520 buf_size = 256;
8521 else
8522 buf_size = 64;
8523 if (get_driver_type() == DRIVER_WCN &&
8524 sta_set_addba_buf_size(dut, intf, buf_size)) {
8525 send_resp(dut, conn, SIGMA_ERROR,
8526 "ErrorCode,set addbareq_buff_size failed");
8527 return 0;
8528 }
8529 }
8530
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008531 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8532}
8533
8534
8535static int sta_set_wireless_60g(struct sigma_dut *dut,
8536 struct sigma_conn *conn,
8537 struct sigma_cmd *cmd)
8538{
8539 const char *dev_role = get_param(cmd, "DevRole");
8540
8541 if (!dev_role) {
8542 send_resp(dut, conn, SIGMA_INVALID,
8543 "ErrorCode,DevRole not specified");
8544 return 0;
8545 }
8546
8547 if (strcasecmp(dev_role, "PCP") == 0)
8548 return sta_set_60g_pcp(dut, conn, cmd);
8549 if (strcasecmp(dev_role, "STA") == 0)
8550 return sta_set_60g_sta(dut, conn, cmd);
8551 send_resp(dut, conn, SIGMA_INVALID,
8552 "ErrorCode,DevRole not supported");
8553 return 0;
8554}
8555
8556
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308557static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8558 struct sigma_cmd *cmd)
8559{
8560 int status;
8561 const char *intf = get_param(cmd, "Interface");
8562 const char *val = get_param(cmd, "DevRole");
8563
8564 if (val && strcasecmp(val, "STA-CFON") == 0) {
8565 status = sta_cfon_set_wireless(dut, conn, cmd);
8566 if (status)
8567 return status;
8568 }
8569 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8570}
8571
8572
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008573static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
8574 struct sigma_cmd *cmd)
8575{
8576 const char *val;
8577
8578 val = get_param(cmd, "Program");
8579 if (val) {
8580 if (strcasecmp(val, "11n") == 0)
8581 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008582 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008583 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8584 if (strcasecmp(val, "60ghz") == 0)
8585 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308586 if (strcasecmp(val, "OCE") == 0)
8587 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008588 /* sta_set_wireless in WPS program is only used for 60G */
8589 if (is_60g_sigma_dut(dut))
8590 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008591 send_resp(dut, conn, SIGMA_ERROR,
8592 "ErrorCode,Program value not supported");
8593 } else {
8594 send_resp(dut, conn, SIGMA_ERROR,
8595 "ErrorCode,Program argument not available");
8596 }
8597
8598 return 0;
8599}
8600
8601
8602static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8603 int tid)
8604{
8605 char buf[100];
8606 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8607
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308608 if (tid < 0 ||
8609 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8610 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8611 return;
8612 }
8613
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008614 /*
8615 * Two ways to ensure that addba request with a
8616 * non zero TID could be sent out. EV 117296
8617 */
8618 snprintf(buf, sizeof(buf),
8619 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8620 tid);
8621 if (system(buf) != 0) {
8622 sigma_dut_print(dut, DUT_MSG_ERROR,
8623 "Ping did not send out");
8624 }
8625
8626 snprintf(buf, sizeof(buf),
8627 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8628 intf, VI_QOS_TMP_FILE);
8629 if (system(buf) != 0)
8630 return;
8631
8632 snprintf(buf, sizeof(buf),
8633 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8634 intf, VI_QOS_TMP_FILE);
8635 if (system(buf) != 0)
8636 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8637
8638 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8639 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8640 if (system(buf) != 0) {
8641 sigma_dut_print(dut, DUT_MSG_ERROR,
8642 "VI_QOS_TEMP_FILE generation error failed");
8643 }
8644 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8645 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8646 if (system(buf) != 0) {
8647 sigma_dut_print(dut, DUT_MSG_ERROR,
8648 "VI_QOS_FILE generation failed");
8649 }
8650
8651 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8652 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8653 if (system(buf) != 0) {
8654 sigma_dut_print(dut, DUT_MSG_ERROR,
8655 "VI_QOS_FILE generation failed");
8656 }
8657
8658 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8659 if (system(buf) != 0) {
8660 }
8661}
8662
8663
8664static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8665 struct sigma_cmd *cmd)
8666{
8667 const char *intf = get_param(cmd, "Interface");
8668 const char *val;
8669 int tid = 0;
8670 char buf[100];
8671
8672 val = get_param(cmd, "TID");
8673 if (val) {
8674 tid = atoi(val);
8675 if (tid)
8676 ath_sta_inject_frame(dut, intf, tid);
8677 }
8678
8679 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008680 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008681
8682 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8683 if (system(buf) != 0) {
8684 sigma_dut_print(dut, DUT_MSG_ERROR,
8685 "wifitool senddelba failed");
8686 }
8687
8688 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8689 if (system(buf) != 0) {
8690 sigma_dut_print(dut, DUT_MSG_ERROR,
8691 "wifitool sendaddba failed");
8692 }
8693
8694 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8695
8696 return 1;
8697}
8698
8699
Lior David9981b512017-01-20 13:16:40 +02008700#ifdef __linux__
8701
8702static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
8703 int agg_size)
8704{
8705 char dir[128], buf[128];
8706 FILE *f;
8707 regex_t re;
8708 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03008709 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02008710
8711 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
8712 sigma_dut_print(dut, DUT_MSG_ERROR,
8713 "failed to get wil6210 debugfs dir");
8714 return -1;
8715 }
8716
Jouni Malinen3aa72862019-05-29 23:14:51 +03008717 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
8718 if (res < 0 || res >= sizeof(buf))
8719 return -1;
Lior David9981b512017-01-20 13:16:40 +02008720 f = fopen(buf, "r");
8721 if (!f) {
8722 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008723 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03008724 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
8725 if (res < 0 || res >= sizeof(buf))
8726 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008727 f = fopen(buf, "r");
8728 if (!f) {
8729 sigma_dut_print(dut, DUT_MSG_ERROR,
8730 "failed to open: %s", buf);
8731 return -1;
8732 }
Lior David9981b512017-01-20 13:16:40 +02008733 }
8734
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008735 /* can be either VRING tx... or RING... */
8736 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02008737 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
8738 goto out;
8739 }
8740
8741 /* find TX VRING for the mac address */
8742 found = 0;
8743 while (fgets(buf, sizeof(buf), f)) {
8744 if (strcasestr(buf, dest_mac)) {
8745 found = 1;
8746 break;
8747 }
8748 }
8749
8750 if (!found) {
8751 sigma_dut_print(dut, DUT_MSG_ERROR,
8752 "no TX VRING for %s", dest_mac);
8753 goto out;
8754 }
8755
8756 /* extract VRING ID, "VRING tx_<id> = {" */
8757 if (!fgets(buf, sizeof(buf), f)) {
8758 sigma_dut_print(dut, DUT_MSG_ERROR,
8759 "no VRING start line for %s", dest_mac);
8760 goto out;
8761 }
8762
8763 rc = regexec(&re, buf, 2, m, 0);
8764 regfree(&re);
8765 if (rc || m[1].rm_so < 0) {
8766 sigma_dut_print(dut, DUT_MSG_ERROR,
8767 "no VRING TX ID for %s", dest_mac);
8768 goto out;
8769 }
8770 buf[m[1].rm_eo] = 0;
8771 vring_id = atoi(&buf[m[1].rm_so]);
8772
8773 /* send the addba command */
8774 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03008775 res = snprintf(buf, sizeof(buf), "%s/back", dir);
8776 if (res < 0 || res >= sizeof(buf))
8777 return -1;
Lior David9981b512017-01-20 13:16:40 +02008778 f = fopen(buf, "w");
8779 if (!f) {
8780 sigma_dut_print(dut, DUT_MSG_ERROR,
8781 "failed to open: %s", buf);
8782 return -1;
8783 }
8784
8785 fprintf(f, "add %d %d\n", vring_id, agg_size);
8786
8787 ret = 0;
8788
8789out:
8790 fclose(f);
8791
8792 return ret;
8793}
8794
8795
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008796int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8797 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798{
8799 const char *val;
8800 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008801
8802 val = get_param(cmd, "TID");
8803 if (val) {
8804 tid = atoi(val);
8805 if (tid != 0) {
8806 sigma_dut_print(dut, DUT_MSG_ERROR,
8807 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
8808 tid);
8809 }
8810 }
8811
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008812 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008813 if (!val) {
8814 sigma_dut_print(dut, DUT_MSG_ERROR,
8815 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008816 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008817 }
8818
Lior David9981b512017-01-20 13:16:40 +02008819 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008820 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008821
8822 return 1;
8823}
8824
Lior David9981b512017-01-20 13:16:40 +02008825#endif /* __linux__ */
8826
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008827
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008828static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8829 struct sigma_cmd *cmd)
8830{
8831#ifdef NL80211_SUPPORT
8832 const char *intf = get_param(cmd, "Interface");
8833 const char *val;
8834 int tid = -1;
8835 int bufsize = 64;
8836 struct nl_msg *msg;
8837 int ret = 0;
8838 struct nlattr *params;
8839 int ifindex;
8840
8841 val = get_param(cmd, "TID");
8842 if (val)
8843 tid = atoi(val);
8844
8845 if (tid == -1) {
8846 send_resp(dut, conn, SIGMA_ERROR,
8847 "ErrorCode,sta_send_addba tid invalid");
8848 return 0;
8849 }
8850
8851 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8852
8853 ifindex = if_nametoindex(intf);
8854 if (ifindex == 0) {
8855 sigma_dut_print(dut, DUT_MSG_ERROR,
8856 "%s: Index for interface %s failed",
8857 __func__, intf);
8858 send_resp(dut, conn, SIGMA_ERROR,
8859 "ErrorCode,sta_send_addba interface invalid");
8860 return 0;
8861 }
8862
8863 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8864 NL80211_CMD_VENDOR)) ||
8865 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8866 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8867 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8868 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8869 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8870 nla_put_u8(msg,
8871 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
8872 QCA_WLAN_ADD_BA) ||
8873 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
8874 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07008875 nla_put_u16(msg,
8876 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
8877 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008878 sigma_dut_print(dut, DUT_MSG_ERROR,
8879 "%s: err in adding vendor_cmd and vendor_data",
8880 __func__);
8881 nlmsg_free(msg);
8882 send_resp(dut, conn, SIGMA_ERROR,
8883 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
8884 return 0;
8885 }
8886 nla_nest_end(msg, params);
8887
8888 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8889 if (ret) {
8890 sigma_dut_print(dut, DUT_MSG_ERROR,
8891 "%s: err in send_and_recv_msgs, ret=%d",
8892 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05308893 if (ret == -EOPNOTSUPP)
8894 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008895 send_resp(dut, conn, SIGMA_ERROR,
8896 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
8897 return 0;
8898 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008899#else /* NL80211_SUPPORT */
8900 sigma_dut_print(dut, DUT_MSG_ERROR,
8901 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008902#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05308903
8904 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008905}
8906
8907
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008908static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8909 struct sigma_cmd *cmd)
8910{
8911 switch (get_driver_type()) {
8912 case DRIVER_ATHEROS:
8913 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008914 case DRIVER_WCN:
8915 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02008916#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008917 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008918 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02008919#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008920 default:
8921 /*
8922 * There is no driver specific implementation for other drivers.
8923 * Ignore the command and report COMPLETE since the following
8924 * throughput test operation will end up sending ADDBA anyway.
8925 */
8926 return 1;
8927 }
8928}
8929
8930
8931int inject_eth_frame(int s, const void *data, size_t len,
8932 unsigned short ethtype, char *dst, char *src)
8933{
8934 struct iovec iov[4] = {
8935 {
8936 .iov_base = dst,
8937 .iov_len = ETH_ALEN,
8938 },
8939 {
8940 .iov_base = src,
8941 .iov_len = ETH_ALEN,
8942 },
8943 {
8944 .iov_base = &ethtype,
8945 .iov_len = sizeof(unsigned short),
8946 },
8947 {
8948 .iov_base = (void *) data,
8949 .iov_len = len,
8950 }
8951 };
8952 struct msghdr msg = {
8953 .msg_name = NULL,
8954 .msg_namelen = 0,
8955 .msg_iov = iov,
8956 .msg_iovlen = 4,
8957 .msg_control = NULL,
8958 .msg_controllen = 0,
8959 .msg_flags = 0,
8960 };
8961
8962 return sendmsg(s, &msg, 0);
8963}
8964
8965#if defined(__linux__) || defined(__QNXNTO__)
8966
8967int inject_frame(int s, const void *data, size_t len, int encrypt)
8968{
8969#define IEEE80211_RADIOTAP_F_WEP 0x04
8970#define IEEE80211_RADIOTAP_F_FRAG 0x08
8971 unsigned char rtap_hdr[] = {
8972 0x00, 0x00, /* radiotap version */
8973 0x0e, 0x00, /* radiotap length */
8974 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
8975 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
8976 0x00, /* padding */
8977 0x00, 0x00, /* RX and TX flags to indicate that */
8978 0x00, 0x00, /* this is the injected frame directly */
8979 };
8980 struct iovec iov[2] = {
8981 {
8982 .iov_base = &rtap_hdr,
8983 .iov_len = sizeof(rtap_hdr),
8984 },
8985 {
8986 .iov_base = (void *) data,
8987 .iov_len = len,
8988 }
8989 };
8990 struct msghdr msg = {
8991 .msg_name = NULL,
8992 .msg_namelen = 0,
8993 .msg_iov = iov,
8994 .msg_iovlen = 2,
8995 .msg_control = NULL,
8996 .msg_controllen = 0,
8997 .msg_flags = 0,
8998 };
8999
9000 if (encrypt)
9001 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9002
9003 return sendmsg(s, &msg, 0);
9004}
9005
9006
9007int open_monitor(const char *ifname)
9008{
9009#ifdef __QNXNTO__
9010 struct sockaddr_dl ll;
9011 int s;
9012
9013 memset(&ll, 0, sizeof(ll));
9014 ll.sdl_family = AF_LINK;
9015 ll.sdl_index = if_nametoindex(ifname);
9016 if (ll.sdl_index == 0) {
9017 perror("if_nametoindex");
9018 return -1;
9019 }
9020 s = socket(PF_INET, SOCK_RAW, 0);
9021#else /* __QNXNTO__ */
9022 struct sockaddr_ll ll;
9023 int s;
9024
9025 memset(&ll, 0, sizeof(ll));
9026 ll.sll_family = AF_PACKET;
9027 ll.sll_ifindex = if_nametoindex(ifname);
9028 if (ll.sll_ifindex == 0) {
9029 perror("if_nametoindex");
9030 return -1;
9031 }
9032 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9033#endif /* __QNXNTO__ */
9034 if (s < 0) {
9035 perror("socket[PF_PACKET,SOCK_RAW]");
9036 return -1;
9037 }
9038
9039 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9040 perror("monitor socket bind");
9041 close(s);
9042 return -1;
9043 }
9044
9045 return s;
9046}
9047
9048
9049static int hex2num(char c)
9050{
9051 if (c >= '0' && c <= '9')
9052 return c - '0';
9053 if (c >= 'a' && c <= 'f')
9054 return c - 'a' + 10;
9055 if (c >= 'A' && c <= 'F')
9056 return c - 'A' + 10;
9057 return -1;
9058}
9059
9060
9061int hwaddr_aton(const char *txt, unsigned char *addr)
9062{
9063 int i;
9064
9065 for (i = 0; i < 6; i++) {
9066 int a, b;
9067
9068 a = hex2num(*txt++);
9069 if (a < 0)
9070 return -1;
9071 b = hex2num(*txt++);
9072 if (b < 0)
9073 return -1;
9074 *addr++ = (a << 4) | b;
9075 if (i < 5 && *txt++ != ':')
9076 return -1;
9077 }
9078
9079 return 0;
9080}
9081
9082#endif /* defined(__linux__) || defined(__QNXNTO__) */
9083
9084enum send_frame_type {
9085 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9086};
9087enum send_frame_protection {
9088 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9089};
9090
9091
9092static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9093 enum send_frame_type frame,
9094 enum send_frame_protection protected,
9095 const char *dest)
9096{
9097#ifdef __linux__
9098 unsigned char buf[1000], *pos;
9099 int s, res;
9100 char bssid[20], addr[20];
9101 char result[32], ssid[100];
9102 size_t ssid_len;
9103
9104 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
9105 sizeof(result)) < 0 ||
9106 strncmp(result, "COMPLETED", 9) != 0) {
9107 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9108 return 0;
9109 }
9110
9111 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
9112 < 0) {
9113 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9114 "current BSSID");
9115 return 0;
9116 }
9117
9118 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
9119 < 0) {
9120 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9121 "own MAC address");
9122 return 0;
9123 }
9124
9125 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
9126 < 0) {
9127 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9128 "current SSID");
9129 return 0;
9130 }
9131 ssid_len = strlen(ssid);
9132
9133 pos = buf;
9134
9135 /* Frame Control */
9136 switch (frame) {
9137 case DISASSOC:
9138 *pos++ = 0xa0;
9139 break;
9140 case DEAUTH:
9141 *pos++ = 0xc0;
9142 break;
9143 case SAQUERY:
9144 *pos++ = 0xd0;
9145 break;
9146 case AUTH:
9147 *pos++ = 0xb0;
9148 break;
9149 case ASSOCREQ:
9150 *pos++ = 0x00;
9151 break;
9152 case REASSOCREQ:
9153 *pos++ = 0x20;
9154 break;
9155 case DLS_REQ:
9156 *pos++ = 0xd0;
9157 break;
9158 }
9159
9160 if (protected == INCORRECT_KEY)
9161 *pos++ = 0x40; /* Set Protected field to 1 */
9162 else
9163 *pos++ = 0x00;
9164
9165 /* Duration */
9166 *pos++ = 0x00;
9167 *pos++ = 0x00;
9168
9169 /* addr1 = DA (current AP) */
9170 hwaddr_aton(bssid, pos);
9171 pos += 6;
9172 /* addr2 = SA (own address) */
9173 hwaddr_aton(addr, pos);
9174 pos += 6;
9175 /* addr3 = BSSID (current AP) */
9176 hwaddr_aton(bssid, pos);
9177 pos += 6;
9178
9179 /* Seq# (to be filled by driver/mac80211) */
9180 *pos++ = 0x00;
9181 *pos++ = 0x00;
9182
9183 if (protected == INCORRECT_KEY) {
9184 /* CCMP parameters */
9185 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9186 pos += 8;
9187 }
9188
9189 if (protected == INCORRECT_KEY) {
9190 switch (frame) {
9191 case DEAUTH:
9192 /* Reason code (encrypted) */
9193 memcpy(pos, "\xa7\x39", 2);
9194 pos += 2;
9195 break;
9196 case DISASSOC:
9197 /* Reason code (encrypted) */
9198 memcpy(pos, "\xa7\x39", 2);
9199 pos += 2;
9200 break;
9201 case SAQUERY:
9202 /* Category|Action|TransID (encrypted) */
9203 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9204 pos += 4;
9205 break;
9206 default:
9207 return -1;
9208 }
9209
9210 /* CCMP MIC */
9211 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9212 pos += 8;
9213 } else {
9214 switch (frame) {
9215 case DEAUTH:
9216 /* reason code = 8 */
9217 *pos++ = 0x08;
9218 *pos++ = 0x00;
9219 break;
9220 case DISASSOC:
9221 /* reason code = 8 */
9222 *pos++ = 0x08;
9223 *pos++ = 0x00;
9224 break;
9225 case SAQUERY:
9226 /* Category - SA Query */
9227 *pos++ = 0x08;
9228 /* SA query Action - Request */
9229 *pos++ = 0x00;
9230 /* Transaction ID */
9231 *pos++ = 0x12;
9232 *pos++ = 0x34;
9233 break;
9234 case AUTH:
9235 /* Auth Alg (Open) */
9236 *pos++ = 0x00;
9237 *pos++ = 0x00;
9238 /* Seq# */
9239 *pos++ = 0x01;
9240 *pos++ = 0x00;
9241 /* Status code */
9242 *pos++ = 0x00;
9243 *pos++ = 0x00;
9244 break;
9245 case ASSOCREQ:
9246 /* Capability Information */
9247 *pos++ = 0x31;
9248 *pos++ = 0x04;
9249 /* Listen Interval */
9250 *pos++ = 0x0a;
9251 *pos++ = 0x00;
9252 /* SSID */
9253 *pos++ = 0x00;
9254 *pos++ = ssid_len;
9255 memcpy(pos, ssid, ssid_len);
9256 pos += ssid_len;
9257 /* Supported Rates */
9258 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9259 10);
9260 pos += 10;
9261 /* Extended Supported Rates */
9262 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9263 pos += 6;
9264 /* RSN */
9265 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9266 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9267 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9268 pos += 28;
9269 break;
9270 case REASSOCREQ:
9271 /* Capability Information */
9272 *pos++ = 0x31;
9273 *pos++ = 0x04;
9274 /* Listen Interval */
9275 *pos++ = 0x0a;
9276 *pos++ = 0x00;
9277 /* Current AP */
9278 hwaddr_aton(bssid, pos);
9279 pos += 6;
9280 /* SSID */
9281 *pos++ = 0x00;
9282 *pos++ = ssid_len;
9283 memcpy(pos, ssid, ssid_len);
9284 pos += ssid_len;
9285 /* Supported Rates */
9286 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9287 10);
9288 pos += 10;
9289 /* Extended Supported Rates */
9290 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9291 pos += 6;
9292 /* RSN */
9293 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9294 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9295 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9296 pos += 28;
9297 break;
9298 case DLS_REQ:
9299 /* Category - DLS */
9300 *pos++ = 0x02;
9301 /* DLS Action - Request */
9302 *pos++ = 0x00;
9303 /* Destination MACAddress */
9304 if (dest)
9305 hwaddr_aton(dest, pos);
9306 else
9307 memset(pos, 0, 6);
9308 pos += 6;
9309 /* Source MACAddress */
9310 hwaddr_aton(addr, pos);
9311 pos += 6;
9312 /* Capability Information */
9313 *pos++ = 0x10; /* Privacy */
9314 *pos++ = 0x06; /* QoS */
9315 /* DLS Timeout Value */
9316 *pos++ = 0x00;
9317 *pos++ = 0x01;
9318 /* Supported rates */
9319 *pos++ = 0x01;
9320 *pos++ = 0x08;
9321 *pos++ = 0x0c; /* 6 Mbps */
9322 *pos++ = 0x12; /* 9 Mbps */
9323 *pos++ = 0x18; /* 12 Mbps */
9324 *pos++ = 0x24; /* 18 Mbps */
9325 *pos++ = 0x30; /* 24 Mbps */
9326 *pos++ = 0x48; /* 36 Mbps */
9327 *pos++ = 0x60; /* 48 Mbps */
9328 *pos++ = 0x6c; /* 54 Mbps */
9329 /* TODO: Extended Supported Rates */
9330 /* TODO: HT Capabilities */
9331 break;
9332 }
9333 }
9334
9335 s = open_monitor("sigmadut");
9336 if (s < 0) {
9337 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9338 "monitor socket");
9339 return 0;
9340 }
9341
9342 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9343 if (res < 0) {
9344 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9345 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309346 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009347 return 0;
9348 }
9349 if (res < pos - buf) {
9350 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9351 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309352 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009353 return 0;
9354 }
9355
9356 close(s);
9357
9358 return 1;
9359#else /* __linux__ */
9360 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9361 "yet supported");
9362 return 0;
9363#endif /* __linux__ */
9364}
9365
9366
9367static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9368 struct sigma_conn *conn,
9369 struct sigma_cmd *cmd)
9370{
9371 const char *intf = get_param(cmd, "Interface");
9372 const char *sta, *val;
9373 unsigned char addr[ETH_ALEN];
9374 char buf[100];
9375
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009376 if (!intf)
9377 return -1;
9378
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009379 sta = get_param(cmd, "peer");
9380 if (sta == NULL)
9381 sta = get_param(cmd, "station");
9382 if (sta == NULL) {
9383 send_resp(dut, conn, SIGMA_ERROR,
9384 "ErrorCode,Missing peer address");
9385 return 0;
9386 }
9387 if (hwaddr_aton(sta, addr) < 0) {
9388 send_resp(dut, conn, SIGMA_ERROR,
9389 "ErrorCode,Invalid peer address");
9390 return 0;
9391 }
9392
9393 val = get_param(cmd, "type");
9394 if (val == NULL)
9395 return -1;
9396
9397 if (strcasecmp(val, "DISCOVERY") == 0) {
9398 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9399 if (wpa_command(intf, buf) < 0) {
9400 send_resp(dut, conn, SIGMA_ERROR,
9401 "ErrorCode,Failed to send TDLS discovery");
9402 return 0;
9403 }
9404 return 1;
9405 }
9406
9407 if (strcasecmp(val, "SETUP") == 0) {
9408 int status = 0, timeout = 0;
9409
9410 val = get_param(cmd, "Status");
9411 if (val)
9412 status = atoi(val);
9413
9414 val = get_param(cmd, "Timeout");
9415 if (val)
9416 timeout = atoi(val);
9417
9418 if (status != 0 && status != 37) {
9419 send_resp(dut, conn, SIGMA_ERROR,
9420 "ErrorCode,Unsupported status value");
9421 return 0;
9422 }
9423
9424 if (timeout != 0 && timeout != 301) {
9425 send_resp(dut, conn, SIGMA_ERROR,
9426 "ErrorCode,Unsupported timeout value");
9427 return 0;
9428 }
9429
9430 if (status && timeout) {
9431 send_resp(dut, conn, SIGMA_ERROR,
9432 "ErrorCode,Unsupported timeout+status "
9433 "combination");
9434 return 0;
9435 }
9436
9437 if (status == 37 &&
9438 wpa_command(intf, "SET tdls_testing 0x200")) {
9439 send_resp(dut, conn, SIGMA_ERROR,
9440 "ErrorCode,Failed to enable "
9441 "decline setup response test mode");
9442 return 0;
9443 }
9444
9445 if (timeout == 301) {
9446 int res;
9447 if (dut->no_tpk_expiration)
9448 res = wpa_command(intf,
9449 "SET tdls_testing 0x108");
9450 else
9451 res = wpa_command(intf,
9452 "SET tdls_testing 0x8");
9453 if (res) {
9454 send_resp(dut, conn, SIGMA_ERROR,
9455 "ErrorCode,Failed to set short TPK "
9456 "lifetime");
9457 return 0;
9458 }
9459 }
9460
9461 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9462 if (wpa_command(intf, buf) < 0) {
9463 send_resp(dut, conn, SIGMA_ERROR,
9464 "ErrorCode,Failed to send TDLS setup");
9465 return 0;
9466 }
9467 return 1;
9468 }
9469
9470 if (strcasecmp(val, "TEARDOWN") == 0) {
9471 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9472 if (wpa_command(intf, buf) < 0) {
9473 send_resp(dut, conn, SIGMA_ERROR,
9474 "ErrorCode,Failed to send TDLS teardown");
9475 return 0;
9476 }
9477 return 1;
9478 }
9479
9480 send_resp(dut, conn, SIGMA_ERROR,
9481 "ErrorCode,Unsupported TDLS frame");
9482 return 0;
9483}
9484
9485
9486static int sta_ap_known(const char *ifname, const char *bssid)
9487{
9488 char buf[4096];
9489
Jouni Malinendd32f192018-09-15 02:55:19 +03009490 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009491 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9492 return 0;
9493 if (strncmp(buf, "id=", 3) != 0)
9494 return 0;
9495 return 1;
9496}
9497
9498
9499static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9500 const char *bssid)
9501{
9502 int res;
9503 struct wpa_ctrl *ctrl;
9504 char buf[256];
9505
9506 if (sta_ap_known(ifname, bssid))
9507 return 0;
9508 sigma_dut_print(dut, DUT_MSG_DEBUG,
9509 "AP not in BSS table - start scan");
9510
9511 ctrl = open_wpa_mon(ifname);
9512 if (ctrl == NULL) {
9513 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9514 "wpa_supplicant monitor connection");
9515 return -1;
9516 }
9517
9518 if (wpa_command(ifname, "SCAN") < 0) {
9519 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9520 wpa_ctrl_detach(ctrl);
9521 wpa_ctrl_close(ctrl);
9522 return -1;
9523 }
9524
9525 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9526 buf, sizeof(buf));
9527
9528 wpa_ctrl_detach(ctrl);
9529 wpa_ctrl_close(ctrl);
9530
9531 if (res < 0) {
9532 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9533 return -1;
9534 }
9535
9536 if (sta_ap_known(ifname, bssid))
9537 return 0;
9538 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9539 return -1;
9540}
9541
9542
9543static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9544 struct sigma_conn *conn,
9545 struct sigma_cmd *cmd,
9546 const char *intf)
9547{
9548 char buf[200];
9549
9550 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9551 if (system(buf) != 0) {
9552 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9553 "ndsend");
9554 return 0;
9555 }
9556
9557 return 1;
9558}
9559
9560
9561static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9562 struct sigma_conn *conn,
9563 struct sigma_cmd *cmd,
9564 const char *intf)
9565{
9566 char buf[200];
9567 const char *ip = get_param(cmd, "SenderIP");
9568
Peng Xu26b356d2017-10-04 17:58:16 -07009569 if (!ip)
9570 return 0;
9571
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009572 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9573 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9574 if (system(buf) == 0) {
9575 sigma_dut_print(dut, DUT_MSG_INFO,
9576 "Neighbor Solicitation got a response "
9577 "for %s@%s", ip, intf);
9578 }
9579
9580 return 1;
9581}
9582
9583
9584static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9585 struct sigma_conn *conn,
9586 struct sigma_cmd *cmd,
9587 const char *ifname)
9588{
9589 char buf[200];
9590 const char *ip = get_param(cmd, "SenderIP");
9591
9592 if (ip == NULL) {
9593 send_resp(dut, conn, SIGMA_ERROR,
9594 "ErrorCode,Missing SenderIP parameter");
9595 return 0;
9596 }
9597 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9598 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9599 if (system(buf) != 0) {
9600 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9601 "for %s@%s", ip, ifname);
9602 }
9603
9604 return 1;
9605}
9606
9607
9608static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9609 struct sigma_conn *conn,
9610 struct sigma_cmd *cmd,
9611 const char *ifname)
9612{
9613 char buf[200];
9614 char ip[16];
9615 int s;
Peng Xub3756882017-10-04 14:39:09 -07009616 struct ifreq ifr;
9617 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009618
9619 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009620 if (s < 0) {
9621 perror("socket");
9622 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009623 }
9624
Peng Xub3756882017-10-04 14:39:09 -07009625 memset(&ifr, 0, sizeof(ifr));
9626 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9627 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9628 sigma_dut_print(dut, DUT_MSG_INFO,
9629 "Failed to get %s IP address: %s",
9630 ifname, strerror(errno));
9631 close(s);
9632 return -1;
9633 }
9634 close(s);
9635
9636 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9637 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9638
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009639 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9640 ip);
9641 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9642 if (system(buf) != 0) {
9643 }
9644
9645 return 1;
9646}
9647
9648
9649static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9650 struct sigma_conn *conn,
9651 struct sigma_cmd *cmd,
9652 const char *ifname)
9653{
9654 char buf[200], addr[20];
9655 char dst[ETH_ALEN], src[ETH_ALEN];
9656 short ethtype = htons(ETH_P_ARP);
9657 char *pos;
9658 int s, res;
9659 const char *val;
9660 struct sockaddr_in taddr;
9661
9662 val = get_param(cmd, "dest");
9663 if (val)
9664 hwaddr_aton(val, (unsigned char *) dst);
9665
9666 val = get_param(cmd, "DestIP");
9667 if (val)
9668 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009669 else
9670 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009671
9672 if (get_wpa_status(get_station_ifname(), "address", addr,
9673 sizeof(addr)) < 0)
9674 return -2;
9675 hwaddr_aton(addr, (unsigned char *) src);
9676
9677 pos = buf;
9678 *pos++ = 0x00;
9679 *pos++ = 0x01;
9680 *pos++ = 0x08;
9681 *pos++ = 0x00;
9682 *pos++ = 0x06;
9683 *pos++ = 0x04;
9684 *pos++ = 0x00;
9685 *pos++ = 0x02;
9686 memcpy(pos, src, ETH_ALEN);
9687 pos += ETH_ALEN;
9688 memcpy(pos, &taddr.sin_addr, 4);
9689 pos += 4;
9690 memcpy(pos, dst, ETH_ALEN);
9691 pos += ETH_ALEN;
9692 memcpy(pos, &taddr.sin_addr, 4);
9693 pos += 4;
9694
9695 s = open_monitor(get_station_ifname());
9696 if (s < 0) {
9697 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9698 "monitor socket");
9699 return 0;
9700 }
9701
9702 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
9703 if (res < 0) {
9704 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9705 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309706 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009707 return 0;
9708 }
9709
9710 close(s);
9711
9712 return 1;
9713}
9714
9715
9716static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
9717 struct sigma_conn *conn,
9718 struct sigma_cmd *cmd,
9719 const char *intf, const char *dest)
9720{
9721 char buf[100];
9722
9723 if (if_nametoindex("sigmadut") == 0) {
9724 snprintf(buf, sizeof(buf),
9725 "iw dev %s interface add sigmadut type monitor",
9726 get_station_ifname());
9727 if (system(buf) != 0 ||
9728 if_nametoindex("sigmadut") == 0) {
9729 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9730 "monitor interface with '%s'", buf);
9731 return -2;
9732 }
9733 }
9734
9735 if (system("ifconfig sigmadut up") != 0) {
9736 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9737 "monitor interface up");
9738 return -2;
9739 }
9740
9741 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
9742}
9743
9744
9745static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
9746 struct sigma_conn *conn,
9747 struct sigma_cmd *cmd)
9748{
9749 const char *intf = get_param(cmd, "Interface");
9750 const char *dest = get_param(cmd, "Dest");
9751 const char *type = get_param(cmd, "FrameName");
9752 const char *val;
9753 char buf[200], *pos, *end;
9754 int count, count2;
9755
9756 if (type == NULL)
9757 type = get_param(cmd, "Type");
9758
9759 if (intf == NULL || dest == NULL || type == NULL)
9760 return -1;
9761
9762 if (strcasecmp(type, "NeighAdv") == 0)
9763 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
9764
9765 if (strcasecmp(type, "NeighSolicitReq") == 0)
9766 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
9767
9768 if (strcasecmp(type, "ARPProbe") == 0)
9769 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
9770
9771 if (strcasecmp(type, "ARPAnnounce") == 0)
9772 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
9773
9774 if (strcasecmp(type, "ARPReply") == 0)
9775 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
9776
9777 if (strcasecmp(type, "DLS-request") == 0 ||
9778 strcasecmp(type, "DLSrequest") == 0)
9779 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
9780 dest);
9781
9782 if (strcasecmp(type, "ANQPQuery") != 0 &&
9783 strcasecmp(type, "Query") != 0) {
9784 send_resp(dut, conn, SIGMA_ERROR,
9785 "ErrorCode,Unsupported HS 2.0 send frame type");
9786 return 0;
9787 }
9788
9789 if (sta_scan_ap(dut, intf, dest) < 0) {
9790 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
9791 "the requested AP");
9792 return 0;
9793 }
9794
9795 pos = buf;
9796 end = buf + sizeof(buf);
9797 count = 0;
9798 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
9799
9800 val = get_param(cmd, "ANQP_CAP_LIST");
9801 if (val && atoi(val)) {
9802 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
9803 count++;
9804 }
9805
9806 val = get_param(cmd, "VENUE_NAME");
9807 if (val && atoi(val)) {
9808 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
9809 count++;
9810 }
9811
9812 val = get_param(cmd, "NETWORK_AUTH_TYPE");
9813 if (val && atoi(val)) {
9814 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
9815 count++;
9816 }
9817
9818 val = get_param(cmd, "ROAMING_CONS");
9819 if (val && atoi(val)) {
9820 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
9821 count++;
9822 }
9823
9824 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
9825 if (val && atoi(val)) {
9826 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
9827 count++;
9828 }
9829
9830 val = get_param(cmd, "NAI_REALM_LIST");
9831 if (val && atoi(val)) {
9832 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
9833 count++;
9834 }
9835
9836 val = get_param(cmd, "3GPP_INFO");
9837 if (val && atoi(val)) {
9838 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
9839 count++;
9840 }
9841
9842 val = get_param(cmd, "DOMAIN_LIST");
9843 if (val && atoi(val)) {
9844 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
9845 count++;
9846 }
9847
Jouni Malinen34cf9532018-04-29 19:26:33 +03009848 val = get_param(cmd, "Venue_URL");
9849 if (val && atoi(val)) {
9850 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
9851 count++;
9852 }
9853
Jouni Malinend3bca5d2018-04-29 17:25:23 +03009854 val = get_param(cmd, "Advice_Of_Charge");
9855 if (val && atoi(val)) {
9856 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
9857 count++;
9858 }
9859
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009860 if (count && wpa_command(intf, buf)) {
9861 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
9862 return 0;
9863 }
9864
9865 pos = buf;
9866 end = buf + sizeof(buf);
9867 count2 = 0;
9868 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
9869
9870 val = get_param(cmd, "HS_CAP_LIST");
9871 if (val && atoi(val)) {
9872 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
9873 count2++;
9874 }
9875
9876 val = get_param(cmd, "OPER_NAME");
9877 if (val && atoi(val)) {
9878 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
9879 count2++;
9880 }
9881
9882 val = get_param(cmd, "WAN_METRICS");
9883 if (!val)
9884 val = get_param(cmd, "WAN_MAT");
9885 if (!val)
9886 val = get_param(cmd, "WAN_MET");
9887 if (val && atoi(val)) {
9888 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
9889 count2++;
9890 }
9891
9892 val = get_param(cmd, "CONNECTION_CAPABILITY");
9893 if (val && atoi(val)) {
9894 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
9895 count2++;
9896 }
9897
9898 val = get_param(cmd, "OP_CLASS");
9899 if (val && atoi(val)) {
9900 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
9901 count2++;
9902 }
9903
9904 val = get_param(cmd, "OSU_PROVIDER_LIST");
9905 if (val && atoi(val)) {
9906 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
9907 count2++;
9908 }
9909
Jouni Malinenf67afec2018-04-29 19:24:58 +03009910 val = get_param(cmd, "OPER_ICON_METADATA");
9911 if (!val)
9912 val = get_param(cmd, "OPERATOR_ICON_METADATA");
9913 if (val && atoi(val)) {
9914 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
9915 count2++;
9916 }
9917
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009918 if (count && count2) {
9919 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
9920 "second query");
9921 sleep(1);
9922 }
9923
9924 if (count2 && wpa_command(intf, buf)) {
9925 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
9926 "failed");
9927 return 0;
9928 }
9929
9930 val = get_param(cmd, "NAI_HOME_REALM_LIST");
9931 if (val) {
9932 if (count || count2) {
9933 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9934 "sending out second query");
9935 sleep(1);
9936 }
9937
9938 if (strcmp(val, "1") == 0)
9939 val = "mail.example.com";
9940 snprintf(buf, end - pos,
9941 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
9942 dest, val);
9943 if (wpa_command(intf, buf)) {
9944 send_resp(dut, conn, SIGMA_ERROR,
9945 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
9946 "failed");
9947 return 0;
9948 }
9949 }
9950
9951 val = get_param(cmd, "ICON_REQUEST");
9952 if (val) {
9953 if (count || count2) {
9954 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9955 "sending out second query");
9956 sleep(1);
9957 }
9958
9959 snprintf(buf, end - pos,
9960 "HS20_ICON_REQUEST %s %s", dest, val);
9961 if (wpa_command(intf, buf)) {
9962 send_resp(dut, conn, SIGMA_ERROR,
9963 "ErrorCode,HS20_ICON_REQUEST failed");
9964 return 0;
9965 }
9966 }
9967
9968 return 1;
9969}
9970
9971
9972static int ath_sta_send_frame_vht(struct sigma_dut *dut,
9973 struct sigma_conn *conn,
9974 struct sigma_cmd *cmd)
9975{
9976 const char *val;
9977 char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009978 int chwidth, nss;
9979
9980 val = get_param(cmd, "framename");
9981 if (!val)
9982 return -1;
9983 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9984
9985 /* Command sequence to generate Op mode notification */
9986 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
9987 ifname = get_station_ifname();
9988
9989 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07009990 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009991
9992 /* Extract Channel width */
9993 val = get_param(cmd, "Channel_width");
9994 if (val) {
9995 switch (atoi(val)) {
9996 case 20:
9997 chwidth = 0;
9998 break;
9999 case 40:
10000 chwidth = 1;
10001 break;
10002 case 80:
10003 chwidth = 2;
10004 break;
10005 case 160:
10006 chwidth = 3;
10007 break;
10008 default:
10009 chwidth = 2;
10010 break;
10011 }
10012
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010013 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010014 }
10015
10016 /* Extract NSS */
10017 val = get_param(cmd, "NSS");
10018 if (val) {
10019 switch (atoi(val)) {
10020 case 1:
10021 nss = 1;
10022 break;
10023 case 2:
10024 nss = 3;
10025 break;
10026 case 3:
10027 nss = 7;
10028 break;
10029 default:
10030 /* We do not support NSS > 3 */
10031 nss = 3;
10032 break;
10033 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010034 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010035 }
10036
10037 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010038 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010039 }
10040
10041 return 1;
10042}
10043
10044
10045static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10046 struct sigma_conn *conn,
10047 struct sigma_cmd *cmd)
10048{
10049 switch (get_driver_type()) {
10050 case DRIVER_ATHEROS:
10051 return ath_sta_send_frame_vht(dut, conn, cmd);
10052 default:
10053 send_resp(dut, conn, SIGMA_ERROR,
10054 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10055 return 0;
10056 }
10057}
10058
10059
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010060static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10061 struct sigma_cmd *cmd)
10062{
10063 const char *val;
10064 const char *intf = get_param(cmd, "Interface");
10065
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010066 if (!intf)
10067 return -1;
10068
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010069 val = get_param(cmd, "framename");
10070 if (!val)
10071 return -1;
10072 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10073
10074 /* Command sequence to generate Op mode notification */
10075 if (val && strcasecmp(val, "action") == 0) {
10076 val = get_param(cmd, "PPDUTxType");
10077 if (val && strcasecmp(val, "TB") == 0) {
10078 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10079 sigma_dut_print(dut, DUT_MSG_ERROR,
10080 "failed to send TB PPDU Tx cfg");
10081 send_resp(dut, conn, SIGMA_ERROR,
10082 "ErrorCode,set TB PPDU Tx cfg failed");
10083 return 0;
10084 }
10085 return 1;
10086 }
10087
10088 sigma_dut_print(dut, DUT_MSG_ERROR,
10089 "Action Tx type is not defined");
10090 }
10091
10092 return 1;
10093}
10094
10095
10096static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10097 struct sigma_conn *conn,
10098 struct sigma_cmd *cmd)
10099{
10100 switch (get_driver_type()) {
10101 case DRIVER_WCN:
10102 return wcn_sta_send_frame_he(dut, conn, cmd);
10103 default:
10104 send_resp(dut, conn, SIGMA_ERROR,
10105 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10106 return 0;
10107 }
10108}
10109
10110
Lior David0fe101e2017-03-09 16:09:50 +020010111#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010112
10113static int
10114wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10115 const char *frame_name, const char *dest_mac)
10116{
10117 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10118 const char *ssid = get_param(cmd, "ssid");
10119 const char *countstr = get_param(cmd, "count");
10120 const char *channelstr = get_param(cmd, "channel");
10121 const char *group_id = get_param(cmd, "groupid");
10122 const char *client_id = get_param(cmd, "clientmac");
10123 int count, channel, freq, i;
10124 const char *fname;
10125 char frame[1024], src_mac[20], group_id_attr[25],
10126 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10127 const char *group_ssid;
10128 const int group_ssid_prefix_len = 9;
10129 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10130 size_t framelen = sizeof(frame);
10131 struct template_frame_tag tags[2];
10132 size_t tags_total = ARRAY_SIZE(tags);
10133 int tag_index, len, dst_len;
10134
10135 if (!countstr || !channelstr) {
10136 sigma_dut_print(dut, DUT_MSG_ERROR,
10137 "Missing argument: count, channel");
10138 return -1;
10139 }
10140 if (isprobereq && !ssid) {
10141 sigma_dut_print(dut, DUT_MSG_ERROR,
10142 "Missing argument: ssid");
10143 return -1;
10144 }
10145 if (!isprobereq && (!group_id || !client_id)) {
10146 sigma_dut_print(dut, DUT_MSG_ERROR,
10147 "Missing argument: group_id, client_id");
10148 return -1;
10149 }
10150
10151 count = atoi(countstr);
10152 channel = atoi(channelstr);
10153 freq = channel_to_freq(dut, channel);
10154
10155 if (!freq) {
10156 sigma_dut_print(dut, DUT_MSG_ERROR,
10157 "invalid channel: %s", channelstr);
10158 return -1;
10159 }
10160
10161 if (isprobereq) {
10162 if (strcasecmp(ssid, "wildcard") == 0) {
10163 fname = "probe_req_wildcard.txt";
10164 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10165 fname = "probe_req_P2P_Wildcard.txt";
10166 } else {
10167 sigma_dut_print(dut, DUT_MSG_ERROR,
10168 "invalid probe request type");
10169 return -1;
10170 }
10171 } else {
10172 fname = "P2P_device_discovery_req.txt";
10173 }
10174
10175 if (parse_template_frame_file(dut, fname, frame, &framelen,
10176 tags, &tags_total)) {
10177 sigma_dut_print(dut, DUT_MSG_ERROR,
10178 "invalid frame template: %s", fname);
10179 return -1;
10180 }
10181
10182 if (get_wpa_status(get_station_ifname(), "address",
10183 src_mac, sizeof(src_mac)) < 0 ||
10184 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10185 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10186 return -1;
10187 /* Use wildcard BSSID, since we are in PBSS */
10188 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10189
10190 if (!isprobereq) {
10191 tag_index = find_template_frame_tag(tags, tags_total, 1);
10192 if (tag_index < 0) {
10193 sigma_dut_print(dut, DUT_MSG_ERROR,
10194 "can't find device id attribute");
10195 return -1;
10196 }
10197 if (parse_mac_address(dut, client_id,
10198 (unsigned char *) client_mac)) {
10199 sigma_dut_print(dut, DUT_MSG_ERROR,
10200 "invalid client_id: %s", client_id);
10201 return -1;
10202 }
10203 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10204 framelen - tags[tag_index].offset,
10205 IEEE80211_P2P_ATTR_DEVICE_ID,
10206 client_mac, ETH_ALEN)) {
10207 sigma_dut_print(dut, DUT_MSG_ERROR,
10208 "fail to replace device id attribute");
10209 return -1;
10210 }
10211
10212 /*
10213 * group_id arg contains device MAC address followed by
10214 * space and SSID (DIRECT-somessid).
10215 * group id attribute contains device address (6 bytes)
10216 * followed by SSID prefix DIRECT-XX (9 bytes)
10217 */
10218 if (strlen(group_id) < sizeof(device_macstr)) {
10219 sigma_dut_print(dut, DUT_MSG_ERROR,
10220 "group_id arg too short");
10221 return -1;
10222 }
10223 memcpy(device_macstr, group_id, sizeof(device_macstr));
10224 device_macstr[sizeof(device_macstr) - 1] = '\0';
10225 if (parse_mac_address(dut, device_macstr,
10226 (unsigned char *) group_id_attr)) {
10227 sigma_dut_print(dut, DUT_MSG_ERROR,
10228 "fail to parse device address from group_id");
10229 return -1;
10230 }
10231 group_ssid = strchr(group_id, ' ');
10232 if (!group_ssid) {
10233 sigma_dut_print(dut, DUT_MSG_ERROR,
10234 "invalid group_id arg, no ssid");
10235 return -1;
10236 }
10237 group_ssid++;
10238 len = strlen(group_ssid);
10239 if (len < group_ssid_prefix_len) {
10240 sigma_dut_print(dut, DUT_MSG_ERROR,
10241 "group_id SSID too short");
10242 return -1;
10243 }
10244 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10245 if (len > dst_len) {
10246 sigma_dut_print(dut, DUT_MSG_ERROR,
10247 "group_id SSID (%s) too long",
10248 group_ssid);
10249 return -1;
10250 }
10251
10252 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10253 tag_index = find_template_frame_tag(tags, tags_total, 2);
10254 if (tag_index < 0) {
10255 sigma_dut_print(dut, DUT_MSG_ERROR,
10256 "can't find group id attribute");
10257 return -1;
10258 }
10259 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10260 framelen - tags[tag_index].offset,
10261 IEEE80211_P2P_ATTR_GROUP_ID,
10262 group_id_attr,
10263 sizeof(group_id_attr))) {
10264 sigma_dut_print(dut, DUT_MSG_ERROR,
10265 "fail to replace group id attribute");
10266 return -1;
10267 }
10268 }
10269
10270 for (i = 0; i < count; i++) {
10271 if (wil6210_transmit_frame(dut, freq,
10272 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10273 frame, framelen)) {
10274 sigma_dut_print(dut, DUT_MSG_ERROR,
10275 "fail to transmit probe request frame");
10276 return -1;
10277 }
10278 }
10279
10280 return 0;
10281}
10282
10283
Lior David0fe101e2017-03-09 16:09:50 +020010284int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10285 struct sigma_cmd *cmd)
10286{
10287 const char *frame_name = get_param(cmd, "framename");
10288 const char *mac = get_param(cmd, "dest_mac");
10289
10290 if (!frame_name || !mac) {
10291 sigma_dut_print(dut, DUT_MSG_ERROR,
10292 "framename and dest_mac must be provided");
10293 return -1;
10294 }
10295
10296 if (strcasecmp(frame_name, "brp") == 0) {
10297 const char *l_rx = get_param(cmd, "L-RX");
10298 int l_rx_i;
10299
10300 if (!l_rx) {
10301 sigma_dut_print(dut, DUT_MSG_ERROR,
10302 "L-RX must be provided");
10303 return -1;
10304 }
10305 l_rx_i = atoi(l_rx);
10306
10307 sigma_dut_print(dut, DUT_MSG_INFO,
10308 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10309 mac, l_rx);
10310 if (l_rx_i != 16) {
10311 sigma_dut_print(dut, DUT_MSG_ERROR,
10312 "unsupported L-RX: %s", l_rx);
10313 return -1;
10314 }
10315
10316 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10317 return -1;
10318 } else if (strcasecmp(frame_name, "ssw") == 0) {
10319 sigma_dut_print(dut, DUT_MSG_INFO,
10320 "dev_send_frame: SLS, dest_mac %s", mac);
10321 if (wil6210_send_sls(dut, mac))
10322 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010323 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10324 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10325 sigma_dut_print(dut, DUT_MSG_INFO,
10326 "dev_send_frame: %s, dest_mac %s", frame_name,
10327 mac);
10328 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10329 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010330 } else {
10331 sigma_dut_print(dut, DUT_MSG_ERROR,
10332 "unsupported frame type: %s", frame_name);
10333 return -1;
10334 }
10335
10336 return 1;
10337}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010338
Lior David0fe101e2017-03-09 16:09:50 +020010339#endif /* __linux__ */
10340
10341
10342static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10343 struct sigma_conn *conn,
10344 struct sigma_cmd *cmd)
10345{
10346 switch (get_driver_type()) {
10347#ifdef __linux__
10348 case DRIVER_WIL6210:
10349 return wil6210_send_frame_60g(dut, conn, cmd);
10350#endif /* __linux__ */
10351 default:
10352 send_resp(dut, conn, SIGMA_ERROR,
10353 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10354 return 0;
10355 }
10356}
10357
10358
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010359static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10360 const char *intf, struct sigma_cmd *cmd)
10361{
10362 const char *val, *addr;
10363 char buf[100];
10364
10365 addr = get_param(cmd, "DestMac");
10366 if (!addr) {
10367 send_resp(dut, conn, SIGMA_INVALID,
10368 "ErrorCode,AP MAC address is missing");
10369 return 0;
10370 }
10371
10372 val = get_param(cmd, "ANQPQuery_ID");
10373 if (!val) {
10374 send_resp(dut, conn, SIGMA_INVALID,
10375 "ErrorCode,Missing ANQPQuery_ID");
10376 return 0;
10377 }
10378
10379 if (strcasecmp(val, "NeighborReportReq") == 0) {
10380 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10381 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10382 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10383 } else {
10384 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10385 val);
10386 send_resp(dut, conn, SIGMA_INVALID,
10387 "ErrorCode,Invalid ANQPQuery_ID");
10388 return 0;
10389 }
10390
Ashwini Patild174f2c2017-04-13 16:49:46 +053010391 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10392 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10393 * if associated, AP BSSID).
10394 */
10395 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10396 send_resp(dut, conn, SIGMA_ERROR,
10397 "ErrorCode,Failed to set gas_address3");
10398 return 0;
10399 }
10400
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010401 if (wpa_command(intf, buf) < 0) {
10402 send_resp(dut, conn, SIGMA_ERROR,
10403 "ErrorCode,Failed to send ANQP query");
10404 return 0;
10405 }
10406
10407 return 1;
10408}
10409
10410
10411static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10412 struct sigma_conn *conn,
10413 const char *intf,
10414 struct sigma_cmd *cmd)
10415{
10416 const char *val = get_param(cmd, "FrameName");
10417
10418 if (val && strcasecmp(val, "ANQPQuery") == 0)
10419 return mbo_send_anqp_query(dut, conn, intf, cmd);
10420
10421 return 2;
10422}
10423
10424
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010425int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
10426 struct sigma_cmd *cmd)
10427{
10428 const char *intf = get_param(cmd, "Interface");
10429 const char *val;
10430 enum send_frame_type frame;
10431 enum send_frame_protection protected;
10432 char buf[100];
10433 unsigned char addr[ETH_ALEN];
10434 int res;
10435
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010436 if (!intf)
10437 return -1;
10438
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010439 val = get_param(cmd, "program");
10440 if (val == NULL)
10441 val = get_param(cmd, "frame");
10442 if (val && strcasecmp(val, "TDLS") == 0)
10443 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10444 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010445 strcasecmp(val, "HS2-R2") == 0 ||
10446 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010447 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10448 if (val && strcasecmp(val, "VHT") == 0)
10449 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010450 if (val && strcasecmp(val, "HE") == 0)
10451 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010452 if (val && strcasecmp(val, "LOC") == 0)
10453 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010454 if (val && strcasecmp(val, "60GHz") == 0)
10455 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010456 if (val && strcasecmp(val, "MBO") == 0) {
10457 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10458 if (res != 2)
10459 return res;
10460 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010461
10462 val = get_param(cmd, "TD_DISC");
10463 if (val) {
10464 if (hwaddr_aton(val, addr) < 0)
10465 return -1;
10466 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10467 if (wpa_command(intf, buf) < 0) {
10468 send_resp(dut, conn, SIGMA_ERROR,
10469 "ErrorCode,Failed to send TDLS discovery");
10470 return 0;
10471 }
10472 return 1;
10473 }
10474
10475 val = get_param(cmd, "TD_Setup");
10476 if (val) {
10477 if (hwaddr_aton(val, addr) < 0)
10478 return -1;
10479 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10480 if (wpa_command(intf, buf) < 0) {
10481 send_resp(dut, conn, SIGMA_ERROR,
10482 "ErrorCode,Failed to start TDLS setup");
10483 return 0;
10484 }
10485 return 1;
10486 }
10487
10488 val = get_param(cmd, "TD_TearDown");
10489 if (val) {
10490 if (hwaddr_aton(val, addr) < 0)
10491 return -1;
10492 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10493 if (wpa_command(intf, buf) < 0) {
10494 send_resp(dut, conn, SIGMA_ERROR,
10495 "ErrorCode,Failed to tear down TDLS link");
10496 return 0;
10497 }
10498 return 1;
10499 }
10500
10501 val = get_param(cmd, "TD_ChannelSwitch");
10502 if (val) {
10503 /* TODO */
10504 send_resp(dut, conn, SIGMA_ERROR,
10505 "ErrorCode,TD_ChannelSwitch not yet supported");
10506 return 0;
10507 }
10508
10509 val = get_param(cmd, "TD_NF");
10510 if (val) {
10511 /* TODO */
10512 send_resp(dut, conn, SIGMA_ERROR,
10513 "ErrorCode,TD_NF not yet supported");
10514 return 0;
10515 }
10516
10517 val = get_param(cmd, "PMFFrameType");
10518 if (val == NULL)
10519 val = get_param(cmd, "FrameName");
10520 if (val == NULL)
10521 val = get_param(cmd, "Type");
10522 if (val == NULL)
10523 return -1;
10524 if (strcasecmp(val, "disassoc") == 0)
10525 frame = DISASSOC;
10526 else if (strcasecmp(val, "deauth") == 0)
10527 frame = DEAUTH;
10528 else if (strcasecmp(val, "saquery") == 0)
10529 frame = SAQUERY;
10530 else if (strcasecmp(val, "auth") == 0)
10531 frame = AUTH;
10532 else if (strcasecmp(val, "assocreq") == 0)
10533 frame = ASSOCREQ;
10534 else if (strcasecmp(val, "reassocreq") == 0)
10535 frame = REASSOCREQ;
10536 else if (strcasecmp(val, "neigreq") == 0) {
10537 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10538
10539 val = get_param(cmd, "ssid");
10540 if (val == NULL)
10541 return -1;
10542
10543 res = send_neighbor_request(dut, intf, val);
10544 if (res) {
10545 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10546 "Failed to send neighbor report request");
10547 return 0;
10548 }
10549
10550 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010551 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10552 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010553 sigma_dut_print(dut, DUT_MSG_DEBUG,
10554 "Got Transition Management Query");
10555
Ashwini Patil5acd7382017-04-13 15:55:04 +053010556 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010557 if (res) {
10558 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10559 "Failed to send Transition Management Query");
10560 return 0;
10561 }
10562
10563 return 1;
10564 } else {
10565 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10566 "PMFFrameType");
10567 return 0;
10568 }
10569
10570 val = get_param(cmd, "PMFProtected");
10571 if (val == NULL)
10572 val = get_param(cmd, "Protected");
10573 if (val == NULL)
10574 return -1;
10575 if (strcasecmp(val, "Correct-key") == 0 ||
10576 strcasecmp(val, "CorrectKey") == 0)
10577 protected = CORRECT_KEY;
10578 else if (strcasecmp(val, "IncorrectKey") == 0)
10579 protected = INCORRECT_KEY;
10580 else if (strcasecmp(val, "Unprotected") == 0)
10581 protected = UNPROTECTED;
10582 else {
10583 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10584 "PMFProtected");
10585 return 0;
10586 }
10587
10588 if (protected != UNPROTECTED &&
10589 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10590 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10591 "PMFProtected for auth/assocreq/reassocreq");
10592 return 0;
10593 }
10594
10595 if (if_nametoindex("sigmadut") == 0) {
10596 snprintf(buf, sizeof(buf),
10597 "iw dev %s interface add sigmadut type monitor",
10598 get_station_ifname());
10599 if (system(buf) != 0 ||
10600 if_nametoindex("sigmadut") == 0) {
10601 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10602 "monitor interface with '%s'", buf);
10603 return -2;
10604 }
10605 }
10606
10607 if (system("ifconfig sigmadut up") != 0) {
10608 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10609 "monitor interface up");
10610 return -2;
10611 }
10612
10613 return sta_inject_frame(dut, conn, frame, protected, NULL);
10614}
10615
10616
10617static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10618 struct sigma_conn *conn,
10619 struct sigma_cmd *cmd,
10620 const char *ifname)
10621{
10622 char buf[200];
10623 const char *val;
10624
10625 val = get_param(cmd, "ClearARP");
10626 if (val && atoi(val) == 1) {
10627 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10628 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10629 if (system(buf) != 0) {
10630 send_resp(dut, conn, SIGMA_ERROR,
10631 "errorCode,Failed to clear ARP cache");
10632 return 0;
10633 }
10634 }
10635
10636 return 1;
10637}
10638
10639
10640int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10641 struct sigma_cmd *cmd)
10642{
10643 const char *intf = get_param(cmd, "Interface");
10644 const char *val;
10645
10646 if (intf == NULL)
10647 return -1;
10648
10649 val = get_param(cmd, "program");
10650 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010651 strcasecmp(val, "HS2-R2") == 0 ||
10652 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010653 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10654
10655 return -1;
10656}
10657
10658
10659static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
10660 struct sigma_cmd *cmd)
10661{
10662 const char *intf = get_param(cmd, "Interface");
10663 const char *mac = get_param(cmd, "MAC");
10664
10665 if (intf == NULL || mac == NULL)
10666 return -1;
10667
10668 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10669 "interface %s to %s", intf, mac);
10670
10671 if (dut->set_macaddr) {
10672 char buf[128];
10673 int res;
10674 if (strcasecmp(mac, "default") == 0) {
10675 res = snprintf(buf, sizeof(buf), "%s",
10676 dut->set_macaddr);
10677 dut->tmp_mac_addr = 0;
10678 } else {
10679 res = snprintf(buf, sizeof(buf), "%s %s",
10680 dut->set_macaddr, mac);
10681 dut->tmp_mac_addr = 1;
10682 }
10683 if (res < 0 || res >= (int) sizeof(buf))
10684 return -1;
10685 if (system(buf) != 0) {
10686 send_resp(dut, conn, SIGMA_ERROR,
10687 "errorCode,Failed to set MAC "
10688 "address");
10689 return 0;
10690 }
10691 return 1;
10692 }
10693
10694 if (strcasecmp(mac, "default") == 0)
10695 return 1;
10696
10697 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10698 "command");
10699 return 0;
10700}
10701
10702
10703static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
10704 struct sigma_conn *conn, const char *intf,
10705 int val)
10706{
10707 char buf[200];
10708 int res;
10709
10710 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
10711 intf, val);
10712 if (res < 0 || res >= (int) sizeof(buf))
10713 return -1;
10714 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10715 if (system(buf) != 0) {
10716 send_resp(dut, conn, SIGMA_ERROR,
10717 "errorCode,Failed to configure offchannel mode");
10718 return 0;
10719 }
10720
10721 return 1;
10722}
10723
10724
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010725static int off_chan_val(enum sec_ch_offset off)
10726{
10727 switch (off) {
10728 case SEC_CH_NO:
10729 return 0;
10730 case SEC_CH_40ABOVE:
10731 return 40;
10732 case SEC_CH_40BELOW:
10733 return -40;
10734 }
10735
10736 return 0;
10737}
10738
10739
10740static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
10741 const char *intf, int off_ch_num,
10742 enum sec_ch_offset sec)
10743{
10744 char buf[200];
10745 int res;
10746
10747 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
10748 intf, off_ch_num);
10749 if (res < 0 || res >= (int) sizeof(buf))
10750 return -1;
10751 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10752 if (system(buf) != 0) {
10753 send_resp(dut, conn, SIGMA_ERROR,
10754 "errorCode,Failed to set offchan");
10755 return 0;
10756 }
10757
10758 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
10759 intf, off_chan_val(sec));
10760 if (res < 0 || res >= (int) sizeof(buf))
10761 return -1;
10762 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10763 if (system(buf) != 0) {
10764 send_resp(dut, conn, SIGMA_ERROR,
10765 "errorCode,Failed to set sec chan offset");
10766 return 0;
10767 }
10768
10769 return 1;
10770}
10771
10772
10773static int tdls_set_offchannel_offset(struct sigma_dut *dut,
10774 struct sigma_conn *conn,
10775 const char *intf, int off_ch_num,
10776 enum sec_ch_offset sec)
10777{
10778 char buf[200];
10779 int res;
10780
10781 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
10782 off_ch_num);
10783 if (res < 0 || res >= (int) sizeof(buf))
10784 return -1;
10785 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10786
10787 if (wpa_command(intf, buf) < 0) {
10788 send_resp(dut, conn, SIGMA_ERROR,
10789 "ErrorCode,Failed to set offchan");
10790 return 0;
10791 }
10792 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
10793 off_chan_val(sec));
10794 if (res < 0 || res >= (int) sizeof(buf))
10795 return -1;
10796
10797 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10798
10799 if (wpa_command(intf, buf) < 0) {
10800 send_resp(dut, conn, SIGMA_ERROR,
10801 "ErrorCode,Failed to set sec chan offset");
10802 return 0;
10803 }
10804
10805 return 1;
10806}
10807
10808
10809static int tdls_set_offchannel_mode(struct sigma_dut *dut,
10810 struct sigma_conn *conn,
10811 const char *intf, int val)
10812{
10813 char buf[200];
10814 int res;
10815
10816 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
10817 val);
10818 if (res < 0 || res >= (int) sizeof(buf))
10819 return -1;
10820 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10821
10822 if (wpa_command(intf, buf) < 0) {
10823 send_resp(dut, conn, SIGMA_ERROR,
10824 "ErrorCode,Failed to configure offchannel mode");
10825 return 0;
10826 }
10827
10828 return 1;
10829}
10830
10831
10832static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
10833 struct sigma_conn *conn,
10834 struct sigma_cmd *cmd)
10835{
10836 const char *val;
10837 enum {
10838 CHSM_NOT_SET,
10839 CHSM_ENABLE,
10840 CHSM_DISABLE,
10841 CHSM_REJREQ,
10842 CHSM_UNSOLRESP
10843 } chsm = CHSM_NOT_SET;
10844 int off_ch_num = -1;
10845 enum sec_ch_offset sec_ch = SEC_CH_NO;
10846 int res;
10847
10848 val = get_param(cmd, "Uapsd");
10849 if (val) {
10850 char buf[100];
10851 if (strcasecmp(val, "Enable") == 0)
10852 snprintf(buf, sizeof(buf), "SET ps 99");
10853 else if (strcasecmp(val, "Disable") == 0)
10854 snprintf(buf, sizeof(buf), "SET ps 98");
10855 else {
10856 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10857 "Unsupported uapsd parameter value");
10858 return 0;
10859 }
10860 if (wpa_command(intf, buf)) {
10861 send_resp(dut, conn, SIGMA_ERROR,
10862 "ErrorCode,Failed to change U-APSD "
10863 "powersave mode");
10864 return 0;
10865 }
10866 }
10867
10868 val = get_param(cmd, "TPKTIMER");
10869 if (val && strcasecmp(val, "DISABLE") == 0) {
10870 if (wpa_command(intf, "SET tdls_testing 0x100")) {
10871 send_resp(dut, conn, SIGMA_ERROR,
10872 "ErrorCode,Failed to enable no TPK "
10873 "expiration test mode");
10874 return 0;
10875 }
10876 dut->no_tpk_expiration = 1;
10877 }
10878
10879 val = get_param(cmd, "ChSwitchMode");
10880 if (val) {
10881 if (strcasecmp(val, "Enable") == 0 ||
10882 strcasecmp(val, "Initiate") == 0)
10883 chsm = CHSM_ENABLE;
10884 else if (strcasecmp(val, "Disable") == 0 ||
10885 strcasecmp(val, "passive") == 0)
10886 chsm = CHSM_DISABLE;
10887 else if (strcasecmp(val, "RejReq") == 0)
10888 chsm = CHSM_REJREQ;
10889 else if (strcasecmp(val, "UnSolResp") == 0)
10890 chsm = CHSM_UNSOLRESP;
10891 else {
10892 send_resp(dut, conn, SIGMA_ERROR,
10893 "ErrorCode,Unknown ChSwitchMode value");
10894 return 0;
10895 }
10896 }
10897
10898 val = get_param(cmd, "OffChNum");
10899 if (val) {
10900 off_ch_num = atoi(val);
10901 if (off_ch_num == 0) {
10902 send_resp(dut, conn, SIGMA_ERROR,
10903 "ErrorCode,Invalid OffChNum");
10904 return 0;
10905 }
10906 }
10907
10908 val = get_param(cmd, "SecChOffset");
10909 if (val) {
10910 if (strcmp(val, "20") == 0)
10911 sec_ch = SEC_CH_NO;
10912 else if (strcasecmp(val, "40above") == 0)
10913 sec_ch = SEC_CH_40ABOVE;
10914 else if (strcasecmp(val, "40below") == 0)
10915 sec_ch = SEC_CH_40BELOW;
10916 else {
10917 send_resp(dut, conn, SIGMA_ERROR,
10918 "ErrorCode,Unknown SecChOffset value");
10919 return 0;
10920 }
10921 }
10922
10923 if (chsm == CHSM_NOT_SET) {
10924 /* no offchannel changes requested */
10925 return 1;
10926 }
10927
10928 if (strcmp(intf, get_main_ifname()) != 0 &&
10929 strcmp(intf, get_station_ifname()) != 0) {
10930 send_resp(dut, conn, SIGMA_ERROR,
10931 "ErrorCode,Unknown interface");
10932 return 0;
10933 }
10934
10935 switch (chsm) {
10936 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030010937 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010938 break;
10939 case CHSM_ENABLE:
10940 if (off_ch_num < 0) {
10941 send_resp(dut, conn, SIGMA_ERROR,
10942 "ErrorCode,Missing OffChNum argument");
10943 return 0;
10944 }
10945 if (wifi_chip_type == DRIVER_WCN) {
10946 res = tdls_set_offchannel_offset(dut, conn, intf,
10947 off_ch_num, sec_ch);
10948 } else {
10949 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10950 sec_ch);
10951 }
10952 if (res != 1)
10953 return res;
10954 if (wifi_chip_type == DRIVER_WCN)
10955 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
10956 else
10957 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
10958 break;
10959 case CHSM_DISABLE:
10960 if (wifi_chip_type == DRIVER_WCN)
10961 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
10962 else
10963 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
10964 break;
10965 case CHSM_REJREQ:
10966 if (wifi_chip_type == DRIVER_WCN)
10967 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
10968 else
10969 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
10970 break;
10971 case CHSM_UNSOLRESP:
10972 if (off_ch_num < 0) {
10973 send_resp(dut, conn, SIGMA_ERROR,
10974 "ErrorCode,Missing OffChNum argument");
10975 return 0;
10976 }
10977 if (wifi_chip_type == DRIVER_WCN) {
10978 res = tdls_set_offchannel_offset(dut, conn, intf,
10979 off_ch_num, sec_ch);
10980 } else {
10981 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10982 sec_ch);
10983 }
10984 if (res != 1)
10985 return res;
10986 if (wifi_chip_type == DRIVER_WCN)
10987 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
10988 else
10989 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
10990 break;
10991 }
10992
10993 return res;
10994}
10995
10996
10997static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
10998 struct sigma_conn *conn,
10999 struct sigma_cmd *cmd)
11000{
11001 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011002 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011003
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011004 novap_reset(dut, intf);
11005
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011006 val = get_param(cmd, "nss_mcs_opt");
11007 if (val) {
11008 /* String (nss_operating_mode; mcs_operating_mode) */
11009 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011010 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011011
11012 token = strdup(val);
11013 if (!token)
11014 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011015 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011016 if (!result) {
11017 sigma_dut_print(dut, DUT_MSG_ERROR,
11018 "VHT NSS not specified");
11019 goto failed;
11020 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011021 if (strcasecmp(result, "def") != 0) {
11022 nss = atoi(result);
11023 if (nss == 4)
11024 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011025 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011026 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011027
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011028 }
11029
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011030 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011031 if (!result) {
11032 sigma_dut_print(dut, DUT_MSG_ERROR,
11033 "VHT MCS not specified");
11034 goto failed;
11035 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011036 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011037 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011038 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011039 } else {
11040 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011041 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011042 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011043 }
11044 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011045 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011046 }
11047
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011048 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011049 return 1;
11050failed:
11051 free(token);
11052 return 0;
11053}
11054
11055
11056static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11057 struct sigma_conn *conn,
11058 struct sigma_cmd *cmd)
11059{
11060 switch (get_driver_type()) {
11061 case DRIVER_ATHEROS:
11062 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11063 default:
11064 send_resp(dut, conn, SIGMA_ERROR,
11065 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11066 return 0;
11067 }
11068}
11069
11070
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011071static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11072 struct sigma_conn *conn,
11073 struct sigma_cmd *cmd)
11074{
11075 const char *val;
11076 char *token = NULL, *result;
11077 char buf[60];
11078
11079 val = get_param(cmd, "nss_mcs_opt");
11080 if (val) {
11081 /* String (nss_operating_mode; mcs_operating_mode) */
11082 int nss, mcs, ratecode;
11083 char *saveptr;
11084
11085 token = strdup(val);
11086 if (!token)
11087 return -2;
11088
11089 result = strtok_r(token, ";", &saveptr);
11090 if (!result) {
11091 sigma_dut_print(dut, DUT_MSG_ERROR,
11092 "HE NSS not specified");
11093 goto failed;
11094 }
11095 nss = 1;
11096 if (strcasecmp(result, "def") != 0)
11097 nss = atoi(result);
11098
11099 result = strtok_r(NULL, ";", &saveptr);
11100 if (!result) {
11101 sigma_dut_print(dut, DUT_MSG_ERROR,
11102 "HE MCS not specified");
11103 goto failed;
11104 }
11105 mcs = 7;
11106 if (strcasecmp(result, "def") != 0)
11107 mcs = atoi(result);
11108
Arif Hussain557bf412018-05-25 17:29:36 -070011109 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011110 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011111 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011112 } else if (nss > 2) {
11113 sigma_dut_print(dut, DUT_MSG_ERROR,
11114 "HE NSS %d not supported", nss);
11115 goto failed;
11116 }
11117
Arif Hussain557bf412018-05-25 17:29:36 -070011118 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11119 if (system(buf) != 0) {
11120 sigma_dut_print(dut, DUT_MSG_ERROR,
11121 "nss_mcs_opt: iwpriv %s nss %d failed",
11122 intf, nss);
11123 goto failed;
11124 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011125 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011126
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011127 /* Add the MCS to the ratecode */
11128 if (mcs >= 0 && mcs <= 11) {
11129 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011130#ifdef NL80211_SUPPORT
11131 if (dut->device_type == STA_testbed) {
11132 enum he_mcs_config mcs_config;
11133 int ret;
11134
11135 if (mcs <= 7)
11136 mcs_config = HE_80_MCS0_7;
11137 else if (mcs <= 9)
11138 mcs_config = HE_80_MCS0_9;
11139 else
11140 mcs_config = HE_80_MCS0_11;
11141 ret = sta_set_he_mcs(dut, intf, mcs_config);
11142 if (ret) {
11143 sigma_dut_print(dut, DUT_MSG_ERROR,
11144 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11145 mcs, mcs_config, ret);
11146 goto failed;
11147 }
11148 }
11149#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011150 } else {
11151 sigma_dut_print(dut, DUT_MSG_ERROR,
11152 "HE MCS %d not supported", mcs);
11153 goto failed;
11154 }
11155 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11156 intf, ratecode);
11157 if (system(buf) != 0) {
11158 sigma_dut_print(dut, DUT_MSG_ERROR,
11159 "iwpriv setting of 11ax rates failed");
11160 goto failed;
11161 }
11162 free(token);
11163 }
11164
11165 val = get_param(cmd, "GI");
11166 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011167 int fix_rate_sgi;
11168
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011169 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011170 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011171 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011172 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011173 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11174 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011175 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011176 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011177 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11178 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011179 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011180 } else {
11181 send_resp(dut, conn, SIGMA_ERROR,
11182 "errorCode,GI value not supported");
11183 return 0;
11184 }
11185 if (system(buf) != 0) {
11186 send_resp(dut, conn, SIGMA_ERROR,
11187 "errorCode,Failed to set shortgi");
11188 return 0;
11189 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011190 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11191 intf, fix_rate_sgi);
11192 if (system(buf) != 0) {
11193 send_resp(dut, conn, SIGMA_ERROR,
11194 "errorCode,Failed to set fix rate shortgi");
11195 return STATUS_SENT;
11196 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011197 }
11198
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011199 val = get_param(cmd, "LTF");
11200 if (val) {
11201#ifdef NL80211_SUPPORT
11202 if (strcmp(val, "3.2") == 0) {
11203 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11204 } if (strcmp(val, "6.4") == 0) {
11205 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11206 } else if (strcmp(val, "12.8") == 0) {
11207 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11208 } else {
11209 send_resp(dut, conn, SIGMA_ERROR,
11210 "errorCode, LTF value not supported");
11211 return 0;
11212 }
11213#else /* NL80211_SUPPORT */
11214 sigma_dut_print(dut, DUT_MSG_ERROR,
11215 "LTF cannot be set without NL80211_SUPPORT defined");
11216 return -2;
11217#endif /* NL80211_SUPPORT */
11218 }
11219
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011220 val = get_param(cmd, "TxSUPPDU");
11221 if (val) {
11222 int set_val = 1;
11223
11224 if (strcasecmp(val, "Enable") == 0)
11225 set_val = 1;
11226 else if (strcasecmp(val, "Disable") == 0)
11227 set_val = 0;
11228
11229 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11230 send_resp(dut, conn, SIGMA_ERROR,
11231 "ErrorCode,Failed to set Tx SU PPDU config");
11232 return 0;
11233 }
11234 }
11235
Arif Hussain480d5f42019-03-12 14:40:42 -070011236 val = get_param(cmd, "TWT_Setup");
11237 if (val) {
11238 if (strcasecmp(val, "Request") == 0) {
11239 if (sta_twt_request(dut, conn, cmd)) {
11240 send_resp(dut, conn, SIGMA_ERROR,
11241 "ErrorCode,sta_twt_request failed");
11242 return STATUS_SENT;
11243 }
11244 } else if (strcasecmp(val, "Teardown") == 0) {
11245 if (sta_twt_teardown(dut, conn, cmd)) {
11246 send_resp(dut, conn, SIGMA_ERROR,
11247 "ErrorCode,sta_twt_teardown failed");
11248 return STATUS_SENT;
11249 }
11250 }
11251 }
11252
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011253 val = get_param(cmd, "transmitOMI");
11254 if (val && sta_transmit_omi(dut, conn, cmd)) {
11255 send_resp(dut, conn, SIGMA_ERROR,
11256 "ErrorCode,sta_transmit_omi failed");
11257 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011258 }
11259
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011260 val = get_param(cmd, "Powersave");
11261 if (val) {
11262 char buf[60];
11263
11264 if (strcasecmp(val, "off") == 0) {
11265 snprintf(buf, sizeof(buf),
11266 "iwpriv %s setPower 2", intf);
11267 if (system(buf) != 0) {
11268 sigma_dut_print(dut, DUT_MSG_ERROR,
11269 "iwpriv setPower 2 failed");
11270 return 0;
11271 }
11272 } else if (strcasecmp(val, "on") == 0) {
11273 snprintf(buf, sizeof(buf),
11274 "iwpriv %s setPower 1", intf);
11275 if (system(buf) != 0) {
11276 sigma_dut_print(dut, DUT_MSG_ERROR,
11277 "iwpriv setPower 1 failed");
11278 return 0;
11279 }
11280 } else {
11281 sigma_dut_print(dut, DUT_MSG_ERROR,
11282 "Unsupported Powersave value '%s'",
11283 val);
11284 return -1;
11285 }
11286 }
11287
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011288 val = get_param(cmd, "MU_EDCA");
11289 if (val) {
11290 if (strcasecmp(val, "Override") == 0) {
11291 if (sta_set_mu_edca_override(dut, intf, 1)) {
11292 send_resp(dut, conn, SIGMA_ERROR,
11293 "errorCode,MU EDCA override set failed");
11294 return STATUS_SENT;
11295 }
11296 } else if (strcasecmp(val, "Disable") == 0) {
11297 if (sta_set_mu_edca_override(dut, intf, 0)) {
11298 send_resp(dut, conn, SIGMA_ERROR,
11299 "errorCode,MU EDCA override disable failed");
11300 return STATUS_SENT;
11301 }
11302 }
11303 }
11304
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011305 return 1;
11306
11307failed:
11308 free(token);
11309 return -2;
11310}
11311
11312
11313static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11314 struct sigma_conn *conn,
11315 struct sigma_cmd *cmd)
11316{
11317 switch (get_driver_type()) {
11318 case DRIVER_WCN:
11319 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11320 default:
11321 send_resp(dut, conn, SIGMA_ERROR,
11322 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11323 return 0;
11324 }
11325}
11326
11327
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011328static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11329 struct sigma_conn *conn,
11330 struct sigma_cmd *cmd)
11331{
11332 const char *val;
11333
11334 val = get_param(cmd, "powersave");
11335 if (val) {
11336 char buf[60];
11337
11338 if (strcasecmp(val, "off") == 0) {
11339 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11340 intf);
11341 if (system(buf) != 0) {
11342 sigma_dut_print(dut, DUT_MSG_ERROR,
11343 "iwpriv setPower 2 failed");
11344 return 0;
11345 }
11346 } else if (strcasecmp(val, "on") == 0) {
11347 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11348 intf);
11349 if (system(buf) != 0) {
11350 sigma_dut_print(dut, DUT_MSG_ERROR,
11351 "iwpriv setPower 1 failed");
11352 return 0;
11353 }
11354 } else {
11355 sigma_dut_print(dut, DUT_MSG_ERROR,
11356 "Unsupported power save config");
11357 return -1;
11358 }
11359 return 1;
11360 }
11361
11362 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11363
11364 return 0;
11365}
11366
11367
Ashwini Patil5acd7382017-04-13 15:55:04 +053011368static int btm_query_candidate_list(struct sigma_dut *dut,
11369 struct sigma_conn *conn,
11370 struct sigma_cmd *cmd)
11371{
11372 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11373 int len, ret;
11374 char buf[10];
11375
11376 /*
11377 * Neighbor Report elements format:
11378 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11379 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11380 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11381 */
11382
11383 bssid = get_param(cmd, "Nebor_BSSID");
11384 if (!bssid) {
11385 send_resp(dut, conn, SIGMA_INVALID,
11386 "errorCode,Nebor_BSSID is missing");
11387 return 0;
11388 }
11389
11390 info = get_param(cmd, "Nebor_Bssid_Info");
11391 if (!info) {
11392 sigma_dut_print(dut, DUT_MSG_INFO,
11393 "Using default value for Nebor_Bssid_Info: %s",
11394 DEFAULT_NEIGHBOR_BSSID_INFO);
11395 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11396 }
11397
11398 op_class = get_param(cmd, "Nebor_Op_Class");
11399 if (!op_class) {
11400 send_resp(dut, conn, SIGMA_INVALID,
11401 "errorCode,Nebor_Op_Class is missing");
11402 return 0;
11403 }
11404
11405 ch = get_param(cmd, "Nebor_Op_Ch");
11406 if (!ch) {
11407 send_resp(dut, conn, SIGMA_INVALID,
11408 "errorCode,Nebor_Op_Ch is missing");
11409 return 0;
11410 }
11411
11412 phy_type = get_param(cmd, "Nebor_Phy_Type");
11413 if (!phy_type) {
11414 sigma_dut_print(dut, DUT_MSG_INFO,
11415 "Using default value for Nebor_Phy_Type: %s",
11416 DEFAULT_NEIGHBOR_PHY_TYPE);
11417 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11418 }
11419
11420 /* Parse optional subelements */
11421 buf[0] = '\0';
11422 pref = get_param(cmd, "Nebor_Pref");
11423 if (pref) {
11424 /* hexdump for preferrence subelement */
11425 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11426 if (ret < 0 || ret >= (int) sizeof(buf)) {
11427 sigma_dut_print(dut, DUT_MSG_ERROR,
11428 "snprintf failed for optional subelement ret: %d",
11429 ret);
11430 send_resp(dut, conn, SIGMA_ERROR,
11431 "errorCode,snprintf failed for subelement");
11432 return 0;
11433 }
11434 }
11435
11436 if (!dut->btm_query_cand_list) {
11437 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11438 if (!dut->btm_query_cand_list) {
11439 send_resp(dut, conn, SIGMA_ERROR,
11440 "errorCode,Failed to allocate memory for btm_query_cand_list");
11441 return 0;
11442 }
11443 }
11444
11445 len = strlen(dut->btm_query_cand_list);
11446 ret = snprintf(dut->btm_query_cand_list + len,
11447 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11448 bssid, info, op_class, ch, phy_type, buf);
11449 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11450 sigma_dut_print(dut, DUT_MSG_ERROR,
11451 "snprintf failed for neighbor report list ret: %d",
11452 ret);
11453 send_resp(dut, conn, SIGMA_ERROR,
11454 "errorCode,snprintf failed for neighbor report");
11455 free(dut->btm_query_cand_list);
11456 dut->btm_query_cand_list = NULL;
11457 return 0;
11458 }
11459
11460 return 1;
11461}
11462
11463
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011464int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11465 struct sigma_ese_alloc *allocs, int *allocs_size)
11466{
11467 int max_count = *allocs_size;
11468 int count = 0, i;
11469 const char *val;
11470
11471 do {
11472 val = get_param_indexed(cmd, "AllocID", count);
11473 if (val)
11474 count++;
11475 } while (val);
11476
11477 if (count == 0 || count > max_count) {
11478 sigma_dut_print(dut, DUT_MSG_ERROR,
11479 "Invalid number of allocations(%d)", count);
11480 return -1;
11481 }
11482
11483 for (i = 0; i < count; i++) {
11484 val = get_param_indexed(cmd, "PercentBI", i);
11485 if (!val) {
11486 sigma_dut_print(dut, DUT_MSG_ERROR,
11487 "Missing PercentBI parameter at index %d",
11488 i);
11489 return -1;
11490 }
11491 allocs[i].percent_bi = atoi(val);
11492
11493 val = get_param_indexed(cmd, "SrcAID", i);
11494 if (val)
11495 allocs[i].src_aid = strtol(val, NULL, 0);
11496 else
11497 allocs[i].src_aid = ESE_BCAST_AID;
11498
11499 val = get_param_indexed(cmd, "DestAID", i);
11500 if (val)
11501 allocs[i].dst_aid = strtol(val, NULL, 0);
11502 else
11503 allocs[i].dst_aid = ESE_BCAST_AID;
11504
11505 allocs[i].type = ESE_CBAP;
11506 sigma_dut_print(dut, DUT_MSG_INFO,
11507 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11508 i, allocs[i].percent_bi, allocs[i].src_aid,
11509 allocs[i].dst_aid);
11510 }
11511
11512 *allocs_size = count;
11513 return 0;
11514}
11515
11516
11517static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11518 struct sigma_ese_alloc *allocs)
11519{
11520 switch (get_driver_type()) {
11521#ifdef __linux__
11522 case DRIVER_WIL6210:
11523 if (wil6210_set_ese(dut, count, allocs))
11524 return -1;
11525 return 1;
11526#endif /* __linux__ */
11527 default:
11528 sigma_dut_print(dut, DUT_MSG_ERROR,
11529 "Unsupported sta_set_60g_ese with the current driver");
11530 return -1;
11531 }
11532}
11533
11534
11535static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11536 struct sigma_conn *conn,
11537 struct sigma_cmd *cmd)
11538{
11539 const char *val;
11540
11541 val = get_param(cmd, "ExtSchIE");
11542 if (val && !strcasecmp(val, "Enable")) {
11543 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11544 int count = MAX_ESE_ALLOCS;
11545
11546 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11547 return -1;
11548 return sta_set_60g_ese(dut, count, allocs);
11549 }
11550
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011551 val = get_param(cmd, "MCS_FixedRate");
11552 if (val) {
11553 int sta_mcs = atoi(val);
11554
11555 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11556 sta_mcs);
11557 wil6210_set_force_mcs(dut, 1, sta_mcs);
11558
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011559 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011560 }
11561
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011562 send_resp(dut, conn, SIGMA_ERROR,
11563 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011564 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011565}
11566
11567
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011568static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
11569 struct sigma_cmd *cmd)
11570{
11571 const char *intf = get_param(cmd, "Interface");
11572 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011573 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011574
11575 if (intf == NULL || prog == NULL)
11576 return -1;
11577
Ashwini Patil5acd7382017-04-13 15:55:04 +053011578 /* BSS Transition candidate list for BTM query */
11579 val = get_param(cmd, "Nebor_BSSID");
11580 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11581 return 0;
11582
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011583 if (strcasecmp(prog, "TDLS") == 0)
11584 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11585
11586 if (strcasecmp(prog, "VHT") == 0)
11587 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11588
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011589 if (strcasecmp(prog, "HE") == 0)
11590 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11591
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011592 if (strcasecmp(prog, "MBO") == 0) {
11593 val = get_param(cmd, "Cellular_Data_Cap");
11594 if (val &&
11595 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11596 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011597
11598 val = get_param(cmd, "Ch_Pref");
11599 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11600 return 0;
11601
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011602 return 1;
11603 }
11604
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011605 if (strcasecmp(prog, "60GHz") == 0)
11606 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11607
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011608 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11609 return 0;
11610}
11611
11612
11613static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
11614 struct sigma_cmd *cmd)
11615{
11616 const char *intf = get_param(cmd, "Interface");
11617 const char *mode = get_param(cmd, "Mode");
11618 int res;
11619
11620 if (intf == NULL || mode == NULL)
11621 return -1;
11622
11623 if (strcasecmp(mode, "On") == 0)
11624 res = wpa_command(intf, "SET radio_disabled 0");
11625 else if (strcasecmp(mode, "Off") == 0)
11626 res = wpa_command(intf, "SET radio_disabled 1");
11627 else
11628 return -1;
11629
11630 if (res) {
11631 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11632 "radio mode");
11633 return 0;
11634 }
11635
11636 return 1;
11637}
11638
11639
11640static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
11641 struct sigma_cmd *cmd)
11642{
11643 const char *intf = get_param(cmd, "Interface");
11644 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011645 const char *prog = get_param(cmd, "program");
11646 const char *powersave = get_param(cmd, "powersave");
11647 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011648
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011649 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011650 return -1;
11651
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011652 if (prog && strcasecmp(prog, "60GHz") == 0) {
11653 /*
11654 * The CAPI mode parameter does not exist in 60G
11655 * unscheduled PS.
11656 */
11657 if (strcasecmp(powersave, "unscheduled") == 0)
11658 res = set_ps(intf, dut, 1);
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011659 } else if (prog && get_driver_type() == DRIVER_WCN &&
11660 strcasecmp(prog, "HE") == 0) {
11661 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011662 } else {
11663 if (mode == NULL)
11664 return -1;
11665
11666 if (strcasecmp(mode, "On") == 0)
11667 res = set_ps(intf, dut, 1);
11668 else if (strcasecmp(mode, "Off") == 0)
11669 res = set_ps(intf, dut, 0);
11670 else
11671 return -1;
11672 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011673
11674 if (res) {
11675 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11676 "power save mode");
11677 return 0;
11678 }
11679
11680 return 1;
11681}
11682
11683
11684static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
11685 struct sigma_cmd *cmd)
11686{
11687 const char *intf = get_param(cmd, "Interface");
11688 const char *val, *bssid;
11689 int res;
11690 char *buf;
11691 size_t buf_len;
11692
11693 val = get_param(cmd, "BSSID_FILTER");
11694 if (val == NULL)
11695 return -1;
11696
11697 bssid = get_param(cmd, "BSSID_List");
11698 if (atoi(val) == 0 || bssid == NULL) {
11699 /* Disable BSSID filter */
11700 if (wpa_command(intf, "SET bssid_filter ")) {
11701 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
11702 "to disable BSSID filter");
11703 return 0;
11704 }
11705
11706 return 1;
11707 }
11708
11709 buf_len = 100 + strlen(bssid);
11710 buf = malloc(buf_len);
11711 if (buf == NULL)
11712 return -1;
11713
11714 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
11715 res = wpa_command(intf, buf);
11716 free(buf);
11717 if (res) {
11718 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
11719 "BSSID filter");
11720 return 0;
11721 }
11722
11723 return 1;
11724}
11725
11726
11727static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
11728 struct sigma_cmd *cmd)
11729{
11730 const char *intf = get_param(cmd, "Interface");
11731 const char *val;
11732
11733 /* TODO: ARP */
11734
11735 val = get_param(cmd, "HS2_CACHE_PROFILE");
11736 if (val && strcasecmp(val, "All") == 0)
11737 hs2_clear_credentials(intf);
11738
11739 return 1;
11740}
11741
11742
11743static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
11744 struct sigma_cmd *cmd)
11745{
11746 const char *intf = get_param(cmd, "Interface");
11747 const char *key_type = get_param(cmd, "KeyType");
11748 char buf[100], resp[200];
11749
11750 if (key_type == NULL)
11751 return -1;
11752
11753 if (strcasecmp(key_type, "GTK") == 0) {
11754 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
11755 strncmp(buf, "FAIL", 4) == 0) {
11756 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11757 "not fetch current GTK");
11758 return 0;
11759 }
11760 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
11761 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11762 return 0;
11763 } else {
11764 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11765 "KeyType");
11766 return 0;
11767 }
11768
11769 return 1;
11770}
11771
11772
11773static int hs2_set_policy(struct sigma_dut *dut)
11774{
11775#ifdef ANDROID
11776 system("ip rule del prio 23000");
11777 if (system("ip rule add from all lookup main prio 23000") != 0) {
11778 sigma_dut_print(dut, DUT_MSG_ERROR,
11779 "Failed to run:ip rule add from all lookup main prio");
11780 return -1;
11781 }
11782 if (system("ip route flush cache") != 0) {
11783 sigma_dut_print(dut, DUT_MSG_ERROR,
11784 "Failed to run ip route flush cache");
11785 return -1;
11786 }
11787 return 1;
11788#else /* ANDROID */
11789 return 0;
11790#endif /* ANDROID */
11791}
11792
11793
11794static int cmd_sta_hs2_associate(struct sigma_dut *dut,
11795 struct sigma_conn *conn,
11796 struct sigma_cmd *cmd)
11797{
11798 const char *intf = get_param(cmd, "Interface");
11799 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030011800 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011801 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030011802 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011803 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
11804 int tries = 0;
11805 int ignore_blacklist = 0;
11806 const char *events[] = {
11807 "CTRL-EVENT-CONNECTED",
11808 "INTERWORKING-BLACKLISTED",
11809 "INTERWORKING-NO-MATCH",
11810 NULL
11811 };
11812
11813 start_sta_mode(dut);
11814
Jouni Malinen439352d2018-09-13 03:42:23 +030011815 if (band) {
11816 if (strcmp(band, "2.4") == 0) {
11817 wpa_command(intf, "SET setband 2G");
11818 } else if (strcmp(band, "5") == 0) {
11819 wpa_command(intf, "SET setband 5G");
11820 } else {
11821 send_resp(dut, conn, SIGMA_ERROR,
11822 "errorCode,Unsupported band");
11823 return 0;
11824 }
11825 }
11826
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011827 blacklisted[0] = '\0';
11828 if (val && atoi(val))
11829 ignore_blacklist = 1;
11830
11831try_again:
11832 ctrl = open_wpa_mon(intf);
11833 if (ctrl == NULL) {
11834 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11835 "wpa_supplicant monitor connection");
11836 return -2;
11837 }
11838
11839 tries++;
11840 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
11841 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
11842 "Interworking connection");
11843 wpa_ctrl_detach(ctrl);
11844 wpa_ctrl_close(ctrl);
11845 return 0;
11846 }
11847
11848 buf[0] = '\0';
11849 while (1) {
11850 char *pos;
11851 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11852 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
11853 if (!pos)
11854 break;
11855 pos += 25;
11856 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
11857 pos);
11858 if (!blacklisted[0])
11859 memcpy(blacklisted, pos, strlen(pos) + 1);
11860 }
11861
11862 if (ignore_blacklist && blacklisted[0]) {
11863 char *end;
11864 end = strchr(blacklisted, ' ');
11865 if (end)
11866 *end = '\0';
11867 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
11868 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030011869 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
11870 blacklisted);
11871 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011872 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
11873 wpa_ctrl_detach(ctrl);
11874 wpa_ctrl_close(ctrl);
11875 return 0;
11876 }
11877 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11878 buf, sizeof(buf));
11879 }
11880
11881 wpa_ctrl_detach(ctrl);
11882 wpa_ctrl_close(ctrl);
11883
11884 if (res < 0) {
11885 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11886 "connect");
11887 return 0;
11888 }
11889
11890 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
11891 strstr(buf, "INTERWORKING-BLACKLISTED")) {
11892 if (tries < 2) {
11893 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
11894 goto try_again;
11895 }
11896 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
11897 "matching credentials found");
11898 return 0;
11899 }
11900
11901 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11902 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11903 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11904 "get current BSSID/SSID");
11905 return 0;
11906 }
11907
11908 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
11909 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11910 hs2_set_policy(dut);
11911 return 0;
11912}
11913
11914
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011915static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
11916 struct sigma_conn *conn,
11917 struct sigma_cmd *cmd)
11918{
11919 const char *intf = get_param(cmd, "Interface");
11920 const char *display = get_param(cmd, "Display");
11921 struct wpa_ctrl *ctrl;
11922 char buf[300], params[400], *pos;
11923 char bssid[20];
11924 int info_avail = 0;
11925 unsigned int old_timeout;
11926 int res;
11927
11928 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
11929 send_resp(dut, conn, SIGMA_ERROR,
11930 "ErrorCode,Could not get current BSSID");
11931 return 0;
11932 }
11933 ctrl = open_wpa_mon(intf);
11934 if (!ctrl) {
11935 sigma_dut_print(dut, DUT_MSG_ERROR,
11936 "Failed to open wpa_supplicant monitor connection");
11937 return -2;
11938 }
11939
11940 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
11941 wpa_command(intf, buf);
11942
11943 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
11944 if (res < 0) {
11945 send_resp(dut, conn, SIGMA_ERROR,
11946 "ErrorCode,Could not complete GAS query");
11947 goto fail;
11948 }
11949
11950 old_timeout = dut->default_timeout;
11951 dut->default_timeout = 2;
11952 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
11953 dut->default_timeout = old_timeout;
11954 if (res < 0)
11955 goto done;
11956 pos = strchr(buf, ' ');
11957 if (!pos)
11958 goto done;
11959 pos++;
11960 pos = strchr(pos, ' ');
11961 if (!pos)
11962 goto done;
11963 pos++;
11964 info_avail = 1;
11965 snprintf(params, sizeof(params), "browser %s", pos);
11966
11967 if (display && strcasecmp(display, "Yes") == 0) {
11968 pid_t pid;
11969
11970 pid = fork();
11971 if (pid < 0) {
11972 perror("fork");
11973 return -1;
11974 }
11975
11976 if (pid == 0) {
11977 run_hs20_osu(dut, params);
11978 exit(0);
11979 }
11980 }
11981
11982done:
11983 snprintf(buf, sizeof(buf), "Info_available,%s",
11984 info_avail ? "Yes" : "No");
11985 send_resp(dut, conn, SIGMA_COMPLETE, buf);
11986fail:
11987 wpa_ctrl_detach(ctrl);
11988 wpa_ctrl_close(ctrl);
11989 return 0;
11990}
11991
11992
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011993static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
11994 struct sigma_conn *conn,
11995 const char *ifname,
11996 struct sigma_cmd *cmd)
11997{
11998 const char *val;
11999 int id;
12000
12001 id = add_cred(ifname);
12002 if (id < 0)
12003 return -2;
12004 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12005
12006 val = get_param(cmd, "prefer");
12007 if (val && atoi(val) > 0)
12008 set_cred(ifname, id, "priority", "1");
12009
12010 val = get_param(cmd, "REALM");
12011 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12012 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12013 "realm");
12014 return 0;
12015 }
12016
12017 val = get_param(cmd, "HOME_FQDN");
12018 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12019 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12020 "home_fqdn");
12021 return 0;
12022 }
12023
12024 val = get_param(cmd, "Username");
12025 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12026 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12027 "username");
12028 return 0;
12029 }
12030
12031 val = get_param(cmd, "Password");
12032 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12033 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12034 "password");
12035 return 0;
12036 }
12037
12038 val = get_param(cmd, "ROOT_CA");
12039 if (val) {
12040 char fname[200];
12041 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12042#ifdef __linux__
12043 if (!file_exists(fname)) {
12044 char msg[300];
12045 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12046 "file (%s) not found", fname);
12047 send_resp(dut, conn, SIGMA_ERROR, msg);
12048 return 0;
12049 }
12050#endif /* __linux__ */
12051 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12052 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12053 "not set root CA");
12054 return 0;
12055 }
12056 }
12057
12058 return 1;
12059}
12060
12061
12062static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12063{
12064 FILE *in, *out;
12065 char buf[500];
12066 int found = 0;
12067
12068 in = fopen("devdetail.xml", "r");
12069 if (in == NULL)
12070 return -1;
12071 out = fopen("devdetail.xml.tmp", "w");
12072 if (out == NULL) {
12073 fclose(in);
12074 return -1;
12075 }
12076
12077 while (fgets(buf, sizeof(buf), in)) {
12078 char *pos = strstr(buf, "<IMSI>");
12079 if (pos) {
12080 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12081 imsi);
12082 pos += 6;
12083 *pos = '\0';
12084 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12085 found++;
12086 } else {
12087 fprintf(out, "%s", buf);
12088 }
12089 }
12090
12091 fclose(out);
12092 fclose(in);
12093 if (found)
12094 rename("devdetail.xml.tmp", "devdetail.xml");
12095 else
12096 unlink("devdetail.xml.tmp");
12097
12098 return 0;
12099}
12100
12101
12102static int sta_add_credential_sim(struct sigma_dut *dut,
12103 struct sigma_conn *conn,
12104 const char *ifname, struct sigma_cmd *cmd)
12105{
12106 const char *val, *imsi = NULL;
12107 int id;
12108 char buf[200];
12109 int res;
12110 const char *pos;
12111 size_t mnc_len;
12112 char plmn_mcc[4];
12113 char plmn_mnc[4];
12114
12115 id = add_cred(ifname);
12116 if (id < 0)
12117 return -2;
12118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12119
12120 val = get_param(cmd, "prefer");
12121 if (val && atoi(val) > 0)
12122 set_cred(ifname, id, "priority", "1");
12123
12124 val = get_param(cmd, "PLMN_MCC");
12125 if (val == NULL) {
12126 send_resp(dut, conn, SIGMA_ERROR,
12127 "errorCode,Missing PLMN_MCC");
12128 return 0;
12129 }
12130 if (strlen(val) != 3) {
12131 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12132 return 0;
12133 }
12134 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12135
12136 val = get_param(cmd, "PLMN_MNC");
12137 if (val == NULL) {
12138 send_resp(dut, conn, SIGMA_ERROR,
12139 "errorCode,Missing PLMN_MNC");
12140 return 0;
12141 }
12142 if (strlen(val) != 2 && strlen(val) != 3) {
12143 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12144 return 0;
12145 }
12146 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12147
12148 val = get_param(cmd, "IMSI");
12149 if (val == NULL) {
12150 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12151 "IMSI");
12152 return 0;
12153 }
12154
12155 imsi = pos = val;
12156
12157 if (strncmp(plmn_mcc, pos, 3) != 0) {
12158 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12159 return 0;
12160 }
12161 pos += 3;
12162
12163 mnc_len = strlen(plmn_mnc);
12164 if (mnc_len < 2) {
12165 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12166 return 0;
12167 }
12168
12169 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12170 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12171 return 0;
12172 }
12173 pos += mnc_len;
12174
12175 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12176 if (res < 0 || res >= (int) sizeof(buf))
12177 return -1;
12178 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12179 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12180 "not set IMSI");
12181 return 0;
12182 }
12183
12184 val = get_param(cmd, "Password");
12185 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12186 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12187 "not set password");
12188 return 0;
12189 }
12190
Jouni Malinenba630452018-06-22 11:49:59 +030012191 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012192 /*
12193 * Set provisioning_sp for the test cases where SIM/USIM
12194 * provisioning is used.
12195 */
12196 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12197 "wi-fi.org") < 0) {
12198 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12199 "not set provisioning_sp");
12200 return 0;
12201 }
12202
12203 update_devdetail_imsi(dut, imsi);
12204 }
12205
12206 return 1;
12207}
12208
12209
12210static int sta_add_credential_cert(struct sigma_dut *dut,
12211 struct sigma_conn *conn,
12212 const char *ifname,
12213 struct sigma_cmd *cmd)
12214{
12215 const char *val;
12216 int id;
12217
12218 id = add_cred(ifname);
12219 if (id < 0)
12220 return -2;
12221 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12222
12223 val = get_param(cmd, "prefer");
12224 if (val && atoi(val) > 0)
12225 set_cred(ifname, id, "priority", "1");
12226
12227 val = get_param(cmd, "REALM");
12228 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12229 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12230 "realm");
12231 return 0;
12232 }
12233
12234 val = get_param(cmd, "HOME_FQDN");
12235 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12236 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12237 "home_fqdn");
12238 return 0;
12239 }
12240
12241 val = get_param(cmd, "Username");
12242 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12243 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12244 "username");
12245 return 0;
12246 }
12247
12248 val = get_param(cmd, "clientCertificate");
12249 if (val) {
12250 char fname[200];
12251 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12252#ifdef __linux__
12253 if (!file_exists(fname)) {
12254 char msg[300];
12255 snprintf(msg, sizeof(msg),
12256 "ErrorCode,clientCertificate "
12257 "file (%s) not found", fname);
12258 send_resp(dut, conn, SIGMA_ERROR, msg);
12259 return 0;
12260 }
12261#endif /* __linux__ */
12262 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12263 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12264 "not set client_cert");
12265 return 0;
12266 }
12267 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12268 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12269 "not set private_key");
12270 return 0;
12271 }
12272 }
12273
12274 val = get_param(cmd, "ROOT_CA");
12275 if (val) {
12276 char fname[200];
12277 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12278#ifdef __linux__
12279 if (!file_exists(fname)) {
12280 char msg[300];
12281 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12282 "file (%s) not found", fname);
12283 send_resp(dut, conn, SIGMA_ERROR, msg);
12284 return 0;
12285 }
12286#endif /* __linux__ */
12287 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12288 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12289 "not set root CA");
12290 return 0;
12291 }
12292 }
12293
12294 return 1;
12295}
12296
12297
12298static int cmd_sta_add_credential(struct sigma_dut *dut,
12299 struct sigma_conn *conn,
12300 struct sigma_cmd *cmd)
12301{
12302 const char *intf = get_param(cmd, "Interface");
12303 const char *type;
12304
12305 start_sta_mode(dut);
12306
12307 type = get_param(cmd, "Type");
12308 if (!type)
12309 return -1;
12310
12311 if (strcasecmp(type, "uname_pwd") == 0)
12312 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12313
12314 if (strcasecmp(type, "sim") == 0)
12315 return sta_add_credential_sim(dut, conn, intf, cmd);
12316
12317 if (strcasecmp(type, "cert") == 0)
12318 return sta_add_credential_cert(dut, conn, intf, cmd);
12319
12320 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12321 "type");
12322 return 0;
12323}
12324
12325
12326static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
12327 struct sigma_cmd *cmd)
12328{
12329 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012330 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012331 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012332 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012333 int res;
12334
Arif Hussain66a4af02019-02-07 15:04:51 -080012335 val = get_param(cmd, "GetParameter");
12336 if (val && strcmp(val, "SSID_BSSID") == 0) {
12337 if (get_wpa_ssid_bssid(dut, get_station_ifname(),
12338 buf, sizeof(buf)) < 0) {
12339 sigma_dut_print(dut, DUT_MSG_ERROR,
12340 "Could not get ssid bssid");
12341 return ERROR_SEND_STATUS;
12342 }
12343
12344 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12345 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12346 return STATUS_SENT;
12347 }
12348
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012349 val = get_param(cmd, "HESSID");
12350 if (val) {
12351 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12352 if (res < 0 || res >= (int) sizeof(buf))
12353 return -1;
12354 wpa_command(intf, buf);
12355 }
12356
12357 val = get_param(cmd, "ACCS_NET_TYPE");
12358 if (val) {
12359 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12360 val);
12361 if (res < 0 || res >= (int) sizeof(buf))
12362 return -1;
12363 wpa_command(intf, buf);
12364 }
12365
vamsi krishna89ad8c62017-09-19 12:51:18 +053012366 bssid = get_param(cmd, "Bssid");
12367 ssid = get_param(cmd, "Ssid");
12368
12369 if (ssid) {
12370 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12371 send_resp(dut, conn, SIGMA_ERROR,
12372 "ErrorCode,Too long SSID");
12373 return 0;
12374 }
12375 ascii2hexstr(ssid, ssid_hex);
12376 }
12377
12378 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12379 bssid ? " bssid=": "",
12380 bssid ? bssid : "",
12381 ssid ? " ssid " : "",
12382 ssid ? ssid_hex : "");
12383 if (res < 0 || res >= (int) sizeof(buf))
12384 return -1;
12385
12386 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012387 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12388 "scan");
12389 return 0;
12390 }
12391
12392 return 1;
12393}
12394
12395
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012396static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
12397 struct sigma_cmd *cmd)
12398{
12399 const char *intf = get_param(cmd, "Interface");
12400 const char *bssid;
12401 char buf[4096], *pos;
12402 int freq, chan;
12403 char *ssid;
12404 char resp[100];
12405 int res;
12406 struct wpa_ctrl *ctrl;
12407
12408 bssid = get_param(cmd, "BSSID");
12409 if (!bssid) {
12410 send_resp(dut, conn, SIGMA_INVALID,
12411 "errorCode,BSSID argument is missing");
12412 return 0;
12413 }
12414
12415 ctrl = open_wpa_mon(intf);
12416 if (!ctrl) {
12417 sigma_dut_print(dut, DUT_MSG_ERROR,
12418 "Failed to open wpa_supplicant monitor connection");
12419 return -1;
12420 }
12421
12422 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12423 send_resp(dut, conn, SIGMA_ERROR,
12424 "errorCode,Could not start scan");
12425 wpa_ctrl_detach(ctrl);
12426 wpa_ctrl_close(ctrl);
12427 return 0;
12428 }
12429
12430 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12431 buf, sizeof(buf));
12432
12433 wpa_ctrl_detach(ctrl);
12434 wpa_ctrl_close(ctrl);
12435
12436 if (res < 0) {
12437 send_resp(dut, conn, SIGMA_ERROR,
12438 "errorCode,Scan did not complete");
12439 return 0;
12440 }
12441
12442 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12443 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12444 strncmp(buf, "id=", 3) != 0) {
12445 send_resp(dut, conn, SIGMA_ERROR,
12446 "errorCode,Specified BSSID not found");
12447 return 0;
12448 }
12449
12450 pos = strstr(buf, "\nfreq=");
12451 if (!pos) {
12452 send_resp(dut, conn, SIGMA_ERROR,
12453 "errorCode,Channel not found");
12454 return 0;
12455 }
12456 freq = atoi(pos + 6);
12457 chan = freq_to_channel(freq);
12458
12459 pos = strstr(buf, "\nssid=");
12460 if (!pos) {
12461 send_resp(dut, conn, SIGMA_ERROR,
12462 "errorCode,SSID not found");
12463 return 0;
12464 }
12465 ssid = pos + 6;
12466 pos = strchr(ssid, '\n');
12467 if (pos)
12468 *pos = '\0';
12469 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12470 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12471 return 0;
12472}
12473
12474
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012475static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
12476 struct sigma_cmd *cmd)
12477{
12478#ifdef __linux__
12479 struct timeval tv;
12480 struct tm tm;
12481 time_t t;
12482 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012483 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012484
12485 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
12486
12487 memset(&tm, 0, sizeof(tm));
12488 val = get_param(cmd, "seconds");
12489 if (val)
12490 tm.tm_sec = atoi(val);
12491 val = get_param(cmd, "minutes");
12492 if (val)
12493 tm.tm_min = atoi(val);
12494 val = get_param(cmd, "hours");
12495 if (val)
12496 tm.tm_hour = atoi(val);
12497 val = get_param(cmd, "date");
12498 if (val)
12499 tm.tm_mday = atoi(val);
12500 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012501 if (val) {
12502 v = atoi(val);
12503 if (v < 1 || v > 12) {
12504 send_resp(dut, conn, SIGMA_INVALID,
12505 "errorCode,Invalid month");
12506 return 0;
12507 }
12508 tm.tm_mon = v - 1;
12509 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012510 val = get_param(cmd, "year");
12511 if (val) {
12512 int year = atoi(val);
12513#ifdef ANDROID
12514 if (year > 2035)
12515 year = 2035; /* years beyond 2035 not supported */
12516#endif /* ANDROID */
12517 tm.tm_year = year - 1900;
12518 }
12519 t = mktime(&tm);
12520 if (t == (time_t) -1) {
12521 send_resp(dut, conn, SIGMA_ERROR,
12522 "errorCode,Invalid date or time");
12523 return 0;
12524 }
12525
12526 memset(&tv, 0, sizeof(tv));
12527 tv.tv_sec = t;
12528
12529 if (settimeofday(&tv, NULL) < 0) {
12530 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12531 strerror(errno));
12532 send_resp(dut, conn, SIGMA_ERROR,
12533 "errorCode,Failed to set time");
12534 return 0;
12535 }
12536
12537 return 1;
12538#endif /* __linux__ */
12539
12540 return -1;
12541}
12542
12543
12544static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
12545 struct sigma_cmd *cmd)
12546{
12547 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012548 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012549 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012550 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012551 int res;
12552 struct wpa_ctrl *ctrl;
12553
12554 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012555 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012556
12557 val = get_param(cmd, "ProdESSAssoc");
12558 if (val)
12559 prod_ess_assoc = atoi(val);
12560
12561 kill_dhcp_client(dut, intf);
12562 if (start_dhcp_client(dut, intf) < 0)
12563 return -2;
12564
12565 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12566 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12567 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012568 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012569 prod_ess_assoc ? "" : "-N",
12570 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012571 name ? "'" : "",
12572 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12573 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012574
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012575 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012576 if (run_hs20_osu(dut, buf) < 0) {
12577 FILE *f;
12578
12579 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12580
12581 f = fopen("hs20-osu-client.res", "r");
12582 if (f) {
12583 char resp[400], res[300], *pos;
12584 if (!fgets(res, sizeof(res), f))
12585 res[0] = '\0';
12586 pos = strchr(res, '\n');
12587 if (pos)
12588 *pos = '\0';
12589 fclose(f);
12590 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12591 res);
12592 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12593 if (system(resp) != 0) {
12594 }
12595 snprintf(resp, sizeof(resp),
12596 "SSID,,BSSID,,failureReason,%s", res);
12597 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12598 return 0;
12599 }
12600
12601 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12602 return 0;
12603 }
12604
12605 if (!prod_ess_assoc)
12606 goto report;
12607
12608 ctrl = open_wpa_mon(intf);
12609 if (ctrl == NULL) {
12610 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12611 "wpa_supplicant monitor connection");
12612 return -1;
12613 }
12614
12615 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12616 buf, sizeof(buf));
12617
12618 wpa_ctrl_detach(ctrl);
12619 wpa_ctrl_close(ctrl);
12620
12621 if (res < 0) {
12622 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12623 "network after OSU");
12624 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12625 return 0;
12626 }
12627
12628report:
12629 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12630 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12631 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12632 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12633 return 0;
12634 }
12635
12636 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12637 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012638 return 0;
12639}
12640
12641
12642static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
12643 struct sigma_cmd *cmd)
12644{
12645 const char *val;
12646 int timeout = 120;
12647
12648 val = get_param(cmd, "PolicyUpdate");
12649 if (val == NULL || atoi(val) == 0)
12650 return 1; /* No operation requested */
12651
12652 val = get_param(cmd, "Timeout");
12653 if (val)
12654 timeout = atoi(val);
12655
12656 if (timeout) {
12657 /* TODO: time out the command and return
12658 * PolicyUpdateStatus,TIMEOUT if needed. */
12659 }
12660
12661 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12662 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12663 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12664 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12665 return 0;
12666 }
12667
12668 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12669 return 0;
12670}
12671
12672
12673static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
12674 struct sigma_cmd *cmd)
12675{
12676 struct wpa_ctrl *ctrl;
12677 const char *intf = get_param(cmd, "Interface");
12678 const char *bssid = get_param(cmd, "Bssid");
12679 const char *ssid = get_param(cmd, "SSID");
12680 const char *security = get_param(cmd, "Security");
12681 const char *passphrase = get_param(cmd, "Passphrase");
12682 const char *pin = get_param(cmd, "PIN");
12683 char buf[1000];
12684 char ssid_hex[200], passphrase_hex[200];
12685 const char *keymgmt, *cipher;
12686
12687 if (intf == NULL)
12688 intf = get_main_ifname();
12689
12690 if (!bssid) {
12691 send_resp(dut, conn, SIGMA_ERROR,
12692 "ErrorCode,Missing Bssid argument");
12693 return 0;
12694 }
12695
12696 if (!ssid) {
12697 send_resp(dut, conn, SIGMA_ERROR,
12698 "ErrorCode,Missing SSID argument");
12699 return 0;
12700 }
12701
12702 if (!security) {
12703 send_resp(dut, conn, SIGMA_ERROR,
12704 "ErrorCode,Missing Security argument");
12705 return 0;
12706 }
12707
12708 if (!passphrase) {
12709 send_resp(dut, conn, SIGMA_ERROR,
12710 "ErrorCode,Missing Passphrase argument");
12711 return 0;
12712 }
12713
12714 if (!pin) {
12715 send_resp(dut, conn, SIGMA_ERROR,
12716 "ErrorCode,Missing PIN argument");
12717 return 0;
12718 }
12719
vamsi krishna8c9c1562017-05-12 15:51:46 +053012720 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
12721 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012722 send_resp(dut, conn, SIGMA_ERROR,
12723 "ErrorCode,Too long SSID/passphrase");
12724 return 0;
12725 }
12726
12727 ctrl = open_wpa_mon(intf);
12728 if (ctrl == NULL) {
12729 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12730 "wpa_supplicant monitor connection");
12731 return -2;
12732 }
12733
12734 if (strcasecmp(security, "wpa2-psk") == 0) {
12735 keymgmt = "WPA2PSK";
12736 cipher = "CCMP";
12737 } else {
12738 wpa_ctrl_detach(ctrl);
12739 wpa_ctrl_close(ctrl);
12740 send_resp(dut, conn, SIGMA_ERROR,
12741 "ErrorCode,Unsupported Security value");
12742 return 0;
12743 }
12744
12745 ascii2hexstr(ssid, ssid_hex);
12746 ascii2hexstr(passphrase, passphrase_hex);
12747 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
12748 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
12749
12750 if (wpa_command(intf, buf) < 0) {
12751 wpa_ctrl_detach(ctrl);
12752 wpa_ctrl_close(ctrl);
12753 send_resp(dut, conn, SIGMA_ERROR,
12754 "ErrorCode,Failed to start registrar");
12755 return 0;
12756 }
12757
12758 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
12759 dut->er_oper_performed = 1;
12760
12761 return wps_connection_event(dut, conn, ctrl, intf, 0);
12762}
12763
12764
12765static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
12766 struct sigma_conn *conn,
12767 struct sigma_cmd *cmd)
12768{
12769 struct wpa_ctrl *ctrl;
12770 const char *intf = get_param(cmd, "Interface");
12771 const char *bssid = get_param(cmd, "Bssid");
12772 char buf[100];
12773
12774 if (!bssid) {
12775 send_resp(dut, conn, SIGMA_ERROR,
12776 "ErrorCode,Missing Bssid argument");
12777 return 0;
12778 }
12779
12780 ctrl = open_wpa_mon(intf);
12781 if (ctrl == NULL) {
12782 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12783 "wpa_supplicant monitor connection");
12784 return -2;
12785 }
12786
12787 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
12788
12789 if (wpa_command(intf, buf) < 0) {
12790 wpa_ctrl_detach(ctrl);
12791 wpa_ctrl_close(ctrl);
12792 send_resp(dut, conn, SIGMA_ERROR,
12793 "ErrorCode,Failed to start registrar");
12794 return 0;
12795 }
12796
12797 return wps_connection_event(dut, conn, ctrl, intf, 0);
12798}
12799
12800
vamsi krishna9b144002017-09-20 13:28:13 +053012801static int cmd_start_wps_registration(struct sigma_dut *dut,
12802 struct sigma_conn *conn,
12803 struct sigma_cmd *cmd)
12804{
12805 struct wpa_ctrl *ctrl;
12806 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012807 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012808 const char *config_method = get_param(cmd, "WPSConfigMethod");
12809 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053012810 int res;
12811 char buf[256];
12812 const char *events[] = {
12813 "CTRL-EVENT-CONNECTED",
12814 "WPS-OVERLAP-DETECTED",
12815 "WPS-TIMEOUT",
12816 "WPS-FAIL",
12817 NULL
12818 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012819 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053012820
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012821 /* 60G WPS tests do not pass Interface parameter */
12822 if (!intf)
12823 intf = get_main_ifname();
12824
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012825 if (dut->mode == SIGMA_MODE_AP)
12826 return ap_wps_registration(dut, conn, cmd);
12827
12828 if (config_method) {
12829 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
12830 * sta_wps_enter_pin before calling start_wps_registration. */
12831 if (strcasecmp(config_method, "PBC") == 0)
12832 dut->wps_method = WFA_CS_WPS_PBC;
12833 }
12834 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
12835 send_resp(dut, conn, SIGMA_ERROR,
12836 "ErrorCode,WPS parameters not yet set");
12837 return STATUS_SENT;
12838 }
12839
12840 /* Make sure WPS is enabled (also for STA mode) */
12841 dut->wps_disable = 0;
12842
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012843 if (dut->band == WPS_BAND_60G && network_mode &&
12844 strcasecmp(network_mode, "PBSS") == 0) {
12845 sigma_dut_print(dut, DUT_MSG_DEBUG,
12846 "Set PBSS network mode, network id %d", id);
12847 if (set_network(get_station_ifname(), id, "pbss", "1") < 0)
12848 return -2;
12849 }
12850
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012851 if (dut->force_rsn_ie) {
12852 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
12853 dut->force_rsn_ie);
12854 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
12855 sigma_dut_print(dut, DUT_MSG_INFO,
12856 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012857 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012858 }
12859 }
12860
vamsi krishna9b144002017-09-20 13:28:13 +053012861 ctrl = open_wpa_mon(intf);
12862 if (!ctrl) {
12863 sigma_dut_print(dut, DUT_MSG_ERROR,
12864 "Failed to open wpa_supplicant monitor connection");
12865 return -2;
12866 }
12867
12868 role = get_param(cmd, "WpsRole");
12869 if (!role) {
12870 send_resp(dut, conn, SIGMA_INVALID,
12871 "ErrorCode,WpsRole not provided");
12872 goto fail;
12873 }
12874
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012875 if (strcasecmp(role, "Enrollee") != 0) {
12876 /* Registrar role for STA not supported */
12877 send_resp(dut, conn, SIGMA_ERROR,
12878 "ErrorCode,Unsupported WpsRole value");
12879 goto fail;
12880 }
12881
12882 if (is_60g_sigma_dut(dut)) {
12883 if (dut->wps_method == WFA_CS_WPS_PBC)
12884 snprintf(buf, sizeof(buf), "WPS_PBC");
12885 else /* WFA_CS_WPS_PIN_KEYPAD */
12886 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
12887 dut->wps_pin);
12888 if (wpa_command(intf, buf) < 0) {
12889 send_resp(dut, conn, SIGMA_ERROR,
12890 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053012891 goto fail;
12892 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012893 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12894 if (res < 0) {
12895 send_resp(dut, conn, SIGMA_ERROR,
12896 "ErrorCode,WPS connection did not complete");
12897 goto fail;
12898 }
12899 if (strstr(buf, "WPS-TIMEOUT")) {
12900 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
12901 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
12902 send_resp(dut, conn, SIGMA_COMPLETE,
12903 "WpsState,OverlapSession");
12904 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
12905 send_resp(dut, conn, SIGMA_COMPLETE,
12906 "WpsState,Successful");
12907 } else {
12908 send_resp(dut, conn, SIGMA_COMPLETE,
12909 "WpsState,Failure");
12910 }
12911 } else {
12912 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053012913 if (wpa_command(intf, "WPS_PBC") < 0) {
12914 send_resp(dut, conn, SIGMA_ERROR,
12915 "ErrorCode,Failed to enable PBC");
12916 goto fail;
12917 }
12918 } else {
12919 /* TODO: PIN method */
12920 send_resp(dut, conn, SIGMA_ERROR,
12921 "ErrorCode,Unsupported WpsConfigMethod value");
12922 goto fail;
12923 }
12924 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12925 if (res < 0) {
12926 send_resp(dut, conn, SIGMA_ERROR,
12927 "ErrorCode,WPS connection did not complete");
12928 goto fail;
12929 }
12930 if (strstr(buf, "WPS-TIMEOUT")) {
12931 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
12932 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
12933 send_resp(dut, conn, SIGMA_ERROR,
12934 "ErrorCode,OverlapSession");
12935 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
12936 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
12937 } else {
12938 send_resp(dut, conn, SIGMA_ERROR,
12939 "ErrorCode,WPS operation failed");
12940 }
vamsi krishna9b144002017-09-20 13:28:13 +053012941 }
12942
12943fail:
12944 wpa_ctrl_detach(ctrl);
12945 wpa_ctrl_close(ctrl);
12946 return 0;
12947}
12948
12949
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012950static int req_intf(struct sigma_cmd *cmd)
12951{
12952 return get_param(cmd, "interface") == NULL ? -1 : 0;
12953}
12954
12955
12956void sta_register_cmds(void)
12957{
12958 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
12959 cmd_sta_get_ip_config);
12960 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
12961 cmd_sta_set_ip_config);
12962 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
12963 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
12964 cmd_sta_get_mac_address);
12965 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
12966 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
12967 cmd_sta_verify_ip_connection);
12968 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
12969 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
12970 cmd_sta_set_encryption);
12971 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
12972 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
12973 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
12974 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
12975 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
12976 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
12977 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
12978 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
12979 cmd_sta_set_eapakaprime);
12980 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
12981 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
12982 /* TODO: sta_set_ibss */
12983 /* TODO: sta_set_mode */
12984 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
12985 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
12986 /* TODO: sta_up_load */
12987 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
12988 cmd_sta_preset_testparameters);
12989 /* TODO: sta_set_system */
12990 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
12991 /* TODO: sta_set_rifs_test */
12992 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
12993 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
12994 /* TODO: sta_send_coexist_mgmt */
12995 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
12996 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
12997 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
12998 sigma_dut_reg_cmd("sta_reset_default", req_intf,
12999 cmd_sta_reset_default);
13000 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13001 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13002 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13003 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13004 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013005 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013006 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13007 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13008 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13009 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13010 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013011 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13012 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013013 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13014 cmd_sta_add_credential);
13015 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013016 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013017 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13018 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13019 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13020 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13021 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13022 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013023 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013024 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13025 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013026 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013027 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013028}