blob: 04dc9cbc115472d71e887387087c57e8e50ef60c [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 Malinen134fe3c2019-06-12 04:16:49 +03002337 dut->sta_associate_wait_connect = 1;
2338
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002339 return id;
2340}
2341
2342
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002343static int set_tls_cipher(const char *ifname, int id, const char *cipher)
2344{
2345 const char *val;
2346
2347 if (!cipher)
2348 return 0;
2349
2350 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
2351 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
2352 else if (strcasecmp(cipher,
2353 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2354 val = "ECDHE-RSA-AES256-GCM-SHA384";
2355 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
2356 val = "DHE-RSA-AES256-GCM-SHA384";
2357 else if (strcasecmp(cipher,
2358 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
2359 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
2360 else
2361 return -1;
2362
2363 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
2364 set_network_quoted(ifname, id, "phase1", "");
2365
2366 return set_network_quoted(ifname, id, "openssl_ciphers", val);
2367}
2368
2369
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002370static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
2371 struct sigma_cmd *cmd)
2372{
2373 const char *intf = get_param(cmd, "Interface");
2374 const char *ifname, *val;
2375 int id;
2376 char buf[200];
2377#ifdef ANDROID
2378 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
2379 int length;
2380 int jb_or_newer = 0;
2381 char prop[PROPERTY_VALUE_MAX];
2382#endif /* ANDROID */
2383
2384 if (intf == NULL)
2385 return -1;
2386
2387 if (strcmp(intf, get_main_ifname()) == 0)
2388 ifname = get_station_ifname();
2389 else
2390 ifname = intf;
2391
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302392 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002393 if (id < 0)
2394 return id;
2395
2396 if (set_network(ifname, id, "eap", "TLS") < 0)
2397 return -2;
2398
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05302399 if (!get_param(cmd, "username") &&
2400 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002401 "wifi-user@wifilabs.local") < 0)
2402 return -2;
2403
2404 val = get_param(cmd, "clientCertificate");
2405 if (val == NULL)
2406 return -1;
2407#ifdef ANDROID
2408 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2409 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
2410 if (length < 0) {
2411 /*
2412 * JB started reporting keystore type mismatches, so retry with
2413 * the GET_PUBKEY command if the generic GET fails.
2414 */
2415 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
2416 buf, kvalue);
2417 }
2418
2419 if (property_get("ro.build.version.release", prop, NULL) != 0) {
2420 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
2421 if (strncmp(prop, "4.0", 3) != 0)
2422 jb_or_newer = 1;
2423 } else
2424 jb_or_newer = 1; /* assume newer */
2425
2426 if (jb_or_newer && length > 0) {
2427 sigma_dut_print(dut, DUT_MSG_INFO,
2428 "Use Android keystore [%s]", buf);
2429 if (set_network(ifname, id, "engine", "1") < 0)
2430 return -2;
2431 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2432 return -2;
2433 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2434 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2435 return -2;
2436 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2437 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2438 return -2;
2439 return 1;
2440 } else if (length > 0) {
2441 sigma_dut_print(dut, DUT_MSG_INFO,
2442 "Use Android keystore [%s]", buf);
2443 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2444 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2445 return -2;
2446 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2447 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2448 return -2;
2449 return 1;
2450 }
2451#endif /* ANDROID */
2452
2453 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2454#ifdef __linux__
2455 if (!file_exists(buf)) {
2456 char msg[300];
2457 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2458 "(%s) not found", buf);
2459 send_resp(dut, conn, SIGMA_ERROR, msg);
2460 return -3;
2461 }
2462#endif /* __linux__ */
2463 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2464 return -2;
2465 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2466 return -2;
2467
2468 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2469 return -2;
2470
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002471 val = get_param(cmd, "keyMgmtType");
2472 if (val && strcasecmp(val, "SuiteB") == 0) {
2473 val = get_param(cmd, "CertType");
2474 if (val && strcasecmp(val, "RSA") == 0) {
2475 if (set_network_quoted(ifname, id, "phase1",
2476 "tls_suiteb=1") < 0)
2477 return -2;
2478 } else {
2479 if (set_network_quoted(ifname, id, "openssl_ciphers",
2480 "SUITEB192") < 0)
2481 return -2;
2482 }
2483
2484 val = get_param(cmd, "TLSCipher");
2485 if (set_tls_cipher(ifname, id, val) < 0) {
2486 send_resp(dut, conn, SIGMA_ERROR,
2487 "ErrorCode,Unsupported TLSCipher value");
2488 return -3;
2489 }
2490 }
2491
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002492 return 1;
2493}
2494
2495
2496static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
2497 struct sigma_cmd *cmd)
2498{
2499 const char *intf = get_param(cmd, "Interface");
2500 const char *ifname;
2501 int id;
2502
2503 if (intf == NULL)
2504 return -1;
2505
2506 if (strcmp(intf, get_main_ifname()) == 0)
2507 ifname = get_station_ifname();
2508 else
2509 ifname = intf;
2510
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302511 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002512 if (id < 0)
2513 return id;
2514
2515 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2516 send_resp(dut, conn, SIGMA_ERROR,
2517 "errorCode,Failed to set TTLS method");
2518 return 0;
2519 }
2520
2521 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2522 send_resp(dut, conn, SIGMA_ERROR,
2523 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2524 return 0;
2525 }
2526
2527 return 1;
2528}
2529
2530
2531static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
2532 struct sigma_cmd *cmd)
2533{
2534 const char *intf = get_param(cmd, "Interface");
2535 const char *ifname;
2536 int id;
2537
2538 if (intf == NULL)
2539 return -1;
2540
2541 if (strcmp(intf, get_main_ifname()) == 0)
2542 ifname = get_station_ifname();
2543 else
2544 ifname = intf;
2545
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302546 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002547 if (id < 0)
2548 return id;
2549
2550 if (set_network(ifname, id, "eap", "SIM") < 0)
2551 return -2;
2552
2553 return 1;
2554}
2555
2556
2557static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
2558 struct sigma_cmd *cmd)
2559{
2560 const char *intf = get_param(cmd, "Interface");
2561 const char *ifname, *val;
2562 int id;
2563 char buf[100];
2564
2565 if (intf == NULL)
2566 return -1;
2567
2568 if (strcmp(intf, get_main_ifname()) == 0)
2569 ifname = get_station_ifname();
2570 else
2571 ifname = intf;
2572
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302573 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002574 if (id < 0)
2575 return id;
2576
2577 if (set_network(ifname, id, "eap", "PEAP") < 0)
2578 return -2;
2579
2580 val = get_param(cmd, "innerEAP");
2581 if (val) {
2582 if (strcasecmp(val, "MSCHAPv2") == 0) {
2583 if (set_network_quoted(ifname, id, "phase2",
2584 "auth=MSCHAPV2") < 0)
2585 return -2;
2586 } else if (strcasecmp(val, "GTC") == 0) {
2587 if (set_network_quoted(ifname, id, "phase2",
2588 "auth=GTC") < 0)
2589 return -2;
2590 } else
2591 return -1;
2592 }
2593
2594 val = get_param(cmd, "peapVersion");
2595 if (val) {
2596 int ver = atoi(val);
2597 if (ver < 0 || ver > 1)
2598 return -1;
2599 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2600 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2601 return -2;
2602 }
2603
2604 return 1;
2605}
2606
2607
2608static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2609 struct sigma_cmd *cmd)
2610{
2611 const char *intf = get_param(cmd, "Interface");
2612 const char *ifname, *val;
2613 int id;
2614 char buf[100];
2615
2616 if (intf == NULL)
2617 return -1;
2618
2619 if (strcmp(intf, get_main_ifname()) == 0)
2620 ifname = get_station_ifname();
2621 else
2622 ifname = intf;
2623
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302624 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002625 if (id < 0)
2626 return id;
2627
2628 if (set_network(ifname, id, "eap", "FAST") < 0)
2629 return -2;
2630
2631 val = get_param(cmd, "innerEAP");
2632 if (val) {
2633 if (strcasecmp(val, "MSCHAPV2") == 0) {
2634 if (set_network_quoted(ifname, id, "phase2",
2635 "auth=MSCHAPV2") < 0)
2636 return -2;
2637 } else if (strcasecmp(val, "GTC") == 0) {
2638 if (set_network_quoted(ifname, id, "phase2",
2639 "auth=GTC") < 0)
2640 return -2;
2641 } else
2642 return -1;
2643 }
2644
2645 val = get_param(cmd, "validateServer");
2646 if (val) {
2647 /* TODO */
2648 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2649 "validateServer=%s", val);
2650 }
2651
2652 val = get_param(cmd, "pacFile");
2653 if (val) {
2654 snprintf(buf, sizeof(buf), "blob://%s", val);
2655 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2656 return -2;
2657 }
2658
2659 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2660 0)
2661 return -2;
2662
2663 return 1;
2664}
2665
2666
2667static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2668 struct sigma_cmd *cmd)
2669{
2670 const char *intf = get_param(cmd, "Interface");
2671 const char *ifname;
2672 int id;
2673
2674 if (intf == NULL)
2675 return -1;
2676
2677 if (strcmp(intf, get_main_ifname()) == 0)
2678 ifname = get_station_ifname();
2679 else
2680 ifname = intf;
2681
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302682 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002683 if (id < 0)
2684 return id;
2685
2686 if (set_network(ifname, id, "eap", "AKA") < 0)
2687 return -2;
2688
2689 return 1;
2690}
2691
2692
2693static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2694 struct sigma_conn *conn,
2695 struct sigma_cmd *cmd)
2696{
2697 const char *intf = get_param(cmd, "Interface");
2698 const char *ifname;
2699 int id;
2700
2701 if (intf == NULL)
2702 return -1;
2703
2704 if (strcmp(intf, get_main_ifname()) == 0)
2705 ifname = get_station_ifname();
2706 else
2707 ifname = intf;
2708
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302709 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002710 if (id < 0)
2711 return id;
2712
2713 if (set_network(ifname, id, "eap", "AKA'") < 0)
2714 return -2;
2715
2716 return 1;
2717}
2718
2719
2720static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2721 struct sigma_cmd *cmd)
2722{
2723 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002724 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002725 const char *ifname;
2726 int id;
2727
2728 if (strcmp(intf, get_main_ifname()) == 0)
2729 ifname = get_station_ifname();
2730 else
2731 ifname = intf;
2732
2733 id = add_network_common(dut, conn, ifname, cmd);
2734 if (id < 0)
2735 return id;
2736
2737 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2738 return -2;
2739
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002740 if (dut->program == PROGRAM_60GHZ && network_mode &&
2741 strcasecmp(network_mode, "PBSS") == 0 &&
2742 set_network(ifname, id, "pbss", "1") < 0)
2743 return -2;
2744
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002745 return 1;
2746}
2747
2748
Jouni Malinen47dcc952017-10-09 16:43:24 +03002749static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2750 struct sigma_cmd *cmd)
2751{
2752 const char *intf = get_param(cmd, "Interface");
2753 const char *ifname, *val;
2754 int id;
2755
2756 if (intf == NULL)
2757 return -1;
2758
2759 if (strcmp(intf, get_main_ifname()) == 0)
2760 ifname = get_station_ifname();
2761 else
2762 ifname = intf;
2763
2764 id = set_wpa_common(dut, conn, ifname, cmd);
2765 if (id < 0)
2766 return id;
2767
2768 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2769 return -2;
2770
2771 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002772 if (val && strcmp(val, "0") == 0) {
2773 if (wpa_command(ifname,
2774 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2775 sigma_dut_print(dut, DUT_MSG_ERROR,
2776 "Failed to set OWE DH Param element override");
2777 return -2;
2778 }
2779 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002780 sigma_dut_print(dut, DUT_MSG_ERROR,
2781 "Failed to clear owe_group");
2782 return -2;
2783 }
2784
2785 return 1;
2786}
2787
2788
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002789static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2790 struct sigma_cmd *cmd)
2791{
2792 const char *type = get_param(cmd, "Type");
2793
2794 if (type == NULL) {
2795 send_resp(dut, conn, SIGMA_ERROR,
2796 "ErrorCode,Missing Type argument");
2797 return 0;
2798 }
2799
2800 if (strcasecmp(type, "OPEN") == 0)
2801 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002802 if (strcasecmp(type, "OWE") == 0)
2803 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002804 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002805 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002806 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002807 return cmd_sta_set_psk(dut, conn, cmd);
2808 if (strcasecmp(type, "EAPTLS") == 0)
2809 return cmd_sta_set_eaptls(dut, conn, cmd);
2810 if (strcasecmp(type, "EAPTTLS") == 0)
2811 return cmd_sta_set_eapttls(dut, conn, cmd);
2812 if (strcasecmp(type, "EAPPEAP") == 0)
2813 return cmd_sta_set_peap(dut, conn, cmd);
2814 if (strcasecmp(type, "EAPSIM") == 0)
2815 return cmd_sta_set_eapsim(dut, conn, cmd);
2816 if (strcasecmp(type, "EAPFAST") == 0)
2817 return cmd_sta_set_eapfast(dut, conn, cmd);
2818 if (strcasecmp(type, "EAPAKA") == 0)
2819 return cmd_sta_set_eapaka(dut, conn, cmd);
2820 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2821 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002822 if (strcasecmp(type, "wep") == 0)
2823 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002824
2825 send_resp(dut, conn, SIGMA_ERROR,
2826 "ErrorCode,Unsupported Type value");
2827 return 0;
2828}
2829
2830
2831int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2832{
2833#ifdef __linux__
2834 /* special handling for ath6kl */
2835 char path[128], fname[128], *pos;
2836 ssize_t res;
2837 FILE *f;
2838
Jouni Malinene39cd562019-05-29 23:39:56 +03002839 res = snprintf(fname, sizeof(fname), "/sys/class/net/%s/phy80211",
2840 intf);
2841 if (res < 0 || res >= sizeof(fname))
2842 return 0;
2843 res = readlink(fname, path, sizeof(path));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002844 if (res < 0)
2845 return 0; /* not ath6kl */
2846
2847 if (res >= (int) sizeof(path))
2848 res = sizeof(path) - 1;
2849 path[res] = '\0';
2850 pos = strrchr(path, '/');
2851 if (pos == NULL)
2852 pos = path;
2853 else
2854 pos++;
2855 snprintf(fname, sizeof(fname),
2856 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2857 "create_qos", pos);
2858 if (!file_exists(fname))
2859 return 0; /* not ath6kl */
2860
2861 if (uapsd) {
2862 f = fopen(fname, "w");
2863 if (f == NULL)
2864 return -1;
2865
2866 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2867 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2868 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2869 "20000 0\n");
2870 fclose(f);
2871 } else {
2872 snprintf(fname, sizeof(fname),
2873 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2874 "delete_qos", pos);
2875
2876 f = fopen(fname, "w");
2877 if (f == NULL)
2878 return -1;
2879
2880 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2881 fprintf(f, "2 4\n");
2882 fclose(f);
2883 }
2884#endif /* __linux__ */
2885
2886 return 0;
2887}
2888
2889
2890static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2891 struct sigma_cmd *cmd)
2892{
2893 const char *intf = get_param(cmd, "Interface");
2894 /* const char *ssid = get_param(cmd, "ssid"); */
2895 const char *val;
2896 int max_sp_len = 4;
2897 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2898 char buf[100];
2899 int ret1, ret2;
2900
2901 val = get_param(cmd, "maxSPLength");
2902 if (val) {
2903 max_sp_len = atoi(val);
2904 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2905 max_sp_len != 4)
2906 return -1;
2907 }
2908
2909 val = get_param(cmd, "acBE");
2910 if (val)
2911 ac_be = atoi(val);
2912
2913 val = get_param(cmd, "acBK");
2914 if (val)
2915 ac_bk = atoi(val);
2916
2917 val = get_param(cmd, "acVI");
2918 if (val)
2919 ac_vi = atoi(val);
2920
2921 val = get_param(cmd, "acVO");
2922 if (val)
2923 ac_vo = atoi(val);
2924
2925 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2926
2927 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2928 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2929 ret1 = wpa_command(intf, buf);
2930
2931 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2932 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2933 ret2 = wpa_command(intf, buf);
2934
2935 if (ret1 && ret2) {
2936 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2937 "UAPSD parameters.");
2938 return -2;
2939 }
2940
2941 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2942 send_resp(dut, conn, SIGMA_ERROR,
2943 "ErrorCode,Failed to set ath6kl QoS parameters");
2944 return 0;
2945 }
2946
2947 return 1;
2948}
2949
2950
2951static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2952 struct sigma_cmd *cmd)
2953{
2954 char buf[1000];
2955 const char *intf = get_param(cmd, "Interface");
2956 const char *grp = get_param(cmd, "Group");
2957 const char *act = get_param(cmd, "Action");
2958 const char *tid = get_param(cmd, "Tid");
2959 const char *dir = get_param(cmd, "Direction");
2960 const char *psb = get_param(cmd, "Psb");
2961 const char *up = get_param(cmd, "Up");
2962 const char *fixed = get_param(cmd, "Fixed");
2963 const char *size = get_param(cmd, "Size");
2964 const char *msize = get_param(cmd, "Maxsize");
2965 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2966 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2967 const char *inact = get_param(cmd, "Inactivity");
2968 const char *sus = get_param(cmd, "Suspension");
2969 const char *mindr = get_param(cmd, "Mindatarate");
2970 const char *meandr = get_param(cmd, "Meandatarate");
2971 const char *peakdr = get_param(cmd, "Peakdatarate");
2972 const char *phyrate = get_param(cmd, "Phyrate");
2973 const char *burstsize = get_param(cmd, "Burstsize");
2974 const char *sba = get_param(cmd, "Sba");
2975 int direction;
2976 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002977 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002978 int fixed_int;
2979 int psb_ts;
2980
2981 if (intf == NULL || grp == NULL || act == NULL )
2982 return -1;
2983
2984 if (strcasecmp(act, "addts") == 0) {
2985 if (tid == NULL || dir == NULL || psb == NULL ||
2986 up == NULL || fixed == NULL || size == NULL)
2987 return -1;
2988
2989 /*
2990 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2991 * possible values, but WMM-AC and V-E test scripts use "UP,
2992 * "DOWN", and "BIDI".
2993 */
2994 if (strcasecmp(dir, "uplink") == 0 ||
2995 strcasecmp(dir, "up") == 0) {
2996 direction = 0;
2997 } else if (strcasecmp(dir, "downlink") == 0 ||
2998 strcasecmp(dir, "down") == 0) {
2999 direction = 1;
3000 } else if (strcasecmp(dir, "bidi") == 0) {
3001 direction = 2;
3002 } else {
3003 sigma_dut_print(dut, DUT_MSG_ERROR,
3004 "Direction %s not supported", dir);
3005 return -1;
3006 }
3007
3008 if (strcasecmp(psb, "legacy") == 0) {
3009 psb_ts = 0;
3010 } else if (strcasecmp(psb, "uapsd") == 0) {
3011 psb_ts = 1;
3012 } else {
3013 sigma_dut_print(dut, DUT_MSG_ERROR,
3014 "PSB %s not supported", psb);
3015 return -1;
3016 }
3017
3018 if (atoi(tid) < 0 || atoi(tid) > 7) {
3019 sigma_dut_print(dut, DUT_MSG_ERROR,
3020 "TID %s not supported", tid);
3021 return -1;
3022 }
3023
3024 if (strcasecmp(fixed, "true") == 0) {
3025 fixed_int = 1;
3026 } else {
3027 fixed_int = 0;
3028 }
3029
Peng Xu93319622017-10-04 17:58:16 -07003030 if (sba)
3031 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003032
3033 dut->dialog_token++;
3034 handle = 7000 + dut->dialog_token;
3035
3036 /*
3037 * size: convert to hex
3038 * maxsi: convert to hex
3039 * mindr: convert to hex
3040 * meandr: convert to hex
3041 * peakdr: convert to hex
3042 * burstsize: convert to hex
3043 * phyrate: convert to hex
3044 * sba: convert to hex with modification
3045 * minsi: convert to integer
3046 * sus: convert to integer
3047 * inact: convert to integer
3048 * maxsi: convert to integer
3049 */
3050
3051 /*
3052 * The Nominal MSDU Size field is 2 octets long and contains an
3053 * unsigned integer that specifies the nominal size, in octets,
3054 * of MSDUs belonging to the traffic under this traffic
3055 * specification and is defined in Figure 16. If the Fixed
3056 * subfield is set to 1, then the size of the MSDU is fixed and
3057 * is indicated by the Size Subfield. If the Fixed subfield is
3058 * set to 0, then the size of the MSDU might not be fixed and
3059 * the Size indicates the nominal MSDU size.
3060 *
3061 * The Surplus Bandwidth Allowance Factor field is 2 octets long
3062 * and specifies the excess allocation of time (and bandwidth)
3063 * over and above the stated rates required to transport an MSDU
3064 * belonging to the traffic in this TSPEC. This field is
3065 * represented as an unsigned binary number with an implicit
3066 * binary point after the leftmost 3 bits. For example, an SBA
3067 * of 1.75 is represented as 0x3800. This field is included to
3068 * account for retransmissions. As such, the value of this field
3069 * must be greater than unity.
3070 */
3071
3072 snprintf(buf, sizeof(buf),
3073 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
3074 " 0x%X 0x%X 0x%X"
3075 " 0x%X 0x%X 0x%X"
3076 " 0x%X %d %d %d %d"
3077 " %d %d",
3078 intf, handle, tid, direction, psb_ts, up,
3079 (unsigned int) ((fixed_int << 15) | atoi(size)),
3080 msize ? atoi(msize) : 0,
3081 mindr ? atoi(mindr) : 0,
3082 meandr ? atoi(meandr) : 0,
3083 peakdr ? atoi(peakdr) : 0,
3084 burstsize ? atoi(burstsize) : 0,
3085 phyrate ? atoi(phyrate) : 0,
3086 sba ? ((unsigned int) (((int) sba_fv << 13) |
3087 (int)((sba_fv - (int) sba_fv) *
3088 8192))) : 0,
3089 minsi ? atoi(minsi) : 0,
3090 sus ? atoi(sus) : 0,
3091 0, 0,
3092 inact ? atoi(inact) : 0,
3093 maxsi ? atoi(maxsi) : 0);
3094
3095 if (system(buf) != 0) {
3096 sigma_dut_print(dut, DUT_MSG_ERROR,
3097 "iwpriv addtspec request failed");
3098 send_resp(dut, conn, SIGMA_ERROR,
3099 "errorCode,Failed to execute addTspec command");
3100 return 0;
3101 }
3102
3103 sigma_dut_print(dut, DUT_MSG_INFO,
3104 "iwpriv addtspec request send");
3105
3106 /* Mapping handle to a TID */
3107 dut->tid_to_handle[atoi(tid)] = handle;
3108 } else if (strcasecmp(act, "delts") == 0) {
3109 if (tid == NULL)
3110 return -1;
3111
3112 if (atoi(tid) < 0 || atoi(tid) > 7) {
3113 sigma_dut_print(dut, DUT_MSG_ERROR,
3114 "TID %s not supported", tid);
3115 send_resp(dut, conn, SIGMA_ERROR,
3116 "errorCode,Unsupported TID");
3117 return 0;
3118 }
3119
3120 handle = dut->tid_to_handle[atoi(tid)];
3121
3122 if (handle < 7000 || handle > 7255) {
3123 /* Invalid handle ie no mapping for that TID */
3124 sigma_dut_print(dut, DUT_MSG_ERROR,
3125 "handle-> %d not found", handle);
3126 }
3127
3128 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
3129 intf, handle);
3130
3131 if (system(buf) != 0) {
3132 sigma_dut_print(dut, DUT_MSG_ERROR,
3133 "iwpriv deltspec request failed");
3134 send_resp(dut, conn, SIGMA_ERROR,
3135 "errorCode,Failed to execute delTspec command");
3136 return 0;
3137 }
3138
3139 sigma_dut_print(dut, DUT_MSG_INFO,
3140 "iwpriv deltspec request send");
3141
3142 dut->tid_to_handle[atoi(tid)] = 0;
3143 } else {
3144 sigma_dut_print(dut, DUT_MSG_ERROR,
3145 "Action type %s not supported", act);
3146 send_resp(dut, conn, SIGMA_ERROR,
3147 "errorCode,Unsupported Action");
3148 return 0;
3149 }
3150
3151 return 1;
3152}
3153
3154
vamsi krishna52e16f92017-08-29 12:37:34 +05303155static int find_network(struct sigma_dut *dut, const char *ssid)
3156{
3157 char list[4096];
3158 char *pos;
3159
3160 sigma_dut_print(dut, DUT_MSG_DEBUG,
3161 "Search for profile based on SSID: '%s'", ssid);
3162 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
3163 list, sizeof(list)) < 0)
3164 return -1;
3165 pos = strstr(list, ssid);
3166 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
3167 return -1;
3168
3169 while (pos > list && pos[-1] != '\n')
3170 pos--;
3171 dut->infra_network_id = atoi(pos);
3172 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
3173 return 0;
3174}
3175
3176
Sunil Dutt44595082018-02-12 19:41:45 +05303177#ifdef NL80211_SUPPORT
3178static int sta_config_rsnie(struct sigma_dut *dut, int val)
3179{
3180 struct nl_msg *msg;
3181 int ret;
3182 struct nlattr *params;
3183 int ifindex;
3184
3185 ifindex = if_nametoindex("wlan0");
3186 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3187 NL80211_CMD_VENDOR)) ||
3188 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3189 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3190 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3191 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
3192 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3193 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
3194 sigma_dut_print(dut, DUT_MSG_ERROR,
3195 "%s: err in adding vendor_cmd and vendor_data",
3196 __func__);
3197 nlmsg_free(msg);
3198 return -1;
3199 }
3200 nla_nest_end(msg, params);
3201
3202 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3203 if (ret) {
3204 sigma_dut_print(dut, DUT_MSG_ERROR,
3205 "%s: err in send_and_recv_msgs, ret=%d",
3206 __func__, ret);
3207 return ret;
3208 }
3209
3210 return 0;
3211}
3212#endif /* NL80211_SUPPORT */
3213
3214
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003215static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
3216 struct sigma_cmd *cmd)
3217{
3218 /* const char *intf = get_param(cmd, "Interface"); */
3219 const char *ssid = get_param(cmd, "ssid");
3220 const char *wps_param = get_param(cmd, "WPS");
3221 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03003222 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003223 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003224 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03003225 char buf[1000], extra[50];
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003226 int e;
3227 enum sigma_cmd_result ret = SUCCESS_SEND_STATUS;
3228 struct wpa_ctrl *ctrl = NULL;
3229 int num_network_not_found = 0;
3230 int num_disconnected = 0;
3231 int tod = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003232
3233 if (ssid == NULL)
3234 return -1;
3235
Jouni Malinen3c367e82017-06-23 17:01:47 +03003236 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05303237#ifdef NL80211_SUPPORT
3238 if (get_driver_type() == DRIVER_WCN) {
3239 sta_config_rsnie(dut, 1);
3240 dut->config_rsnie = 1;
3241 }
3242#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03003243 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
3244 dut->rsne_override);
3245 if (wpa_command(get_station_ifname(), buf) < 0) {
3246 send_resp(dut, conn, SIGMA_ERROR,
3247 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
3248 return 0;
3249 }
3250 }
3251
Jouni Malinen68143132017-09-02 02:34:08 +03003252 if (dut->sae_commit_override) {
3253 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
3254 dut->sae_commit_override);
3255 if (wpa_command(get_station_ifname(), buf) < 0) {
3256 send_resp(dut, conn, SIGMA_ERROR,
3257 "ErrorCode,Failed to set SAE commit override");
3258 return 0;
3259 }
3260 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303261#ifdef ANDROID
3262 if (dut->fils_hlp)
3263 process_fils_hlp(dut);
3264#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03003265
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003266 if (wps_param &&
3267 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
3268 wps = 1;
3269
3270 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02003271 if (dut->program == PROGRAM_60GHZ && network_mode &&
3272 strcasecmp(network_mode, "PBSS") == 0 &&
3273 set_network(get_station_ifname(), dut->infra_network_id,
3274 "pbss", "1") < 0)
3275 return -2;
3276
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003277 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
3278 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
3279 "parameters not yet set");
3280 return 0;
3281 }
3282 if (dut->wps_method == WFA_CS_WPS_PBC) {
3283 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
3284 return -2;
3285 } else {
3286 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
3287 dut->wps_pin);
3288 if (wpa_command(get_station_ifname(), buf) < 0)
3289 return -2;
3290 }
3291 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05303292 if (strcmp(ssid, dut->infra_ssid) == 0) {
3293 sigma_dut_print(dut, DUT_MSG_DEBUG,
3294 "sta_associate for the most recently added network");
3295 } else if (find_network(dut, ssid) < 0) {
3296 sigma_dut_print(dut, DUT_MSG_DEBUG,
3297 "sta_associate for a previously stored network profile");
3298 send_resp(dut, conn, SIGMA_ERROR,
3299 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003300 return 0;
3301 }
3302
3303 if (bssid &&
3304 set_network(get_station_ifname(), dut->infra_network_id,
3305 "bssid", bssid) < 0) {
3306 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3307 "Invalid bssid argument");
3308 return 0;
3309 }
3310
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003311 if (dut->program == PROGRAM_WPA3 &&
3312 dut->sta_associate_wait_connect) {
3313 ctrl = open_wpa_mon(get_station_ifname());
3314 if (!ctrl)
3315 return ERROR_SEND_STATUS;
3316 }
3317
Jouni Malinen46a19b62017-06-23 14:31:27 +03003318 extra[0] = '\0';
3319 if (chan)
3320 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02003321 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03003322 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
3323 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003324 if (wpa_command(get_station_ifname(), buf) < 0) {
3325 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
3326 "network id %d on %s",
3327 dut->infra_network_id,
3328 get_station_ifname());
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003329 ret = ERROR_SEND_STATUS;
3330 goto done;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003331 }
3332 }
3333
Jouni Malinen134fe3c2019-06-12 04:16:49 +03003334 if (!ctrl)
3335 return SUCCESS_SEND_STATUS;
3336
3337 /* Wait for connection result to be able to store server certificate
3338 * hash for trust root override testing
3339 * (dev_exec_action,ServerCertTrust). */
3340
3341 for (e = 0; e < 20; e++) {
3342 const char *events[] = {
3343 "CTRL-EVENT-EAP-PEER-CERT",
3344 "CTRL-EVENT-EAP-TLS-CERT-ERROR",
3345 "CTRL-EVENT-DISCONNECTED",
3346 "CTRL-EVENT-CONNECTED",
3347 "CTRL-EVENT-NETWORK-NOT-FOUND",
3348 NULL
3349 };
3350 char buf[1024];
3351 int res;
3352
3353 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
3354 if (res < 0) {
3355 send_resp(dut, conn, SIGMA_ERROR,
3356 "ErrorCode,Association did not complete");
3357 ret = STATUS_SENT_ERROR;
3358 break;
3359 }
3360 sigma_dut_print(dut, DUT_MSG_DEBUG, "Connection event: %s",
3361 buf);
3362
3363 if (strstr(buf, "CTRL-EVENT-EAP-PEER-CERT") &&
3364 strstr(buf, " depth=0")) {
3365 char *pos = strstr(buf, " hash=");
3366
3367 if (pos) {
3368 char *end;
3369
3370 tod = strstr(buf, " tod=1") != NULL;
3371 sigma_dut_print(dut, DUT_MSG_DEBUG,
3372 "Server certificate TOD policy: %d",
3373 tod);
3374
3375 pos += 6;
3376 end = strchr(pos, ' ');
3377 if (end)
3378 *end = '\0';
3379 strlcpy(dut->server_cert_hash, pos,
3380 sizeof(dut->server_cert_hash));
3381 sigma_dut_print(dut, DUT_MSG_DEBUG,
3382 "Server certificate hash: %s",
3383 dut->server_cert_hash);
3384 }
3385 }
3386
3387 if (strstr(buf, "CTRL-EVENT-EAP-TLS-CERT-ERROR")) {
3388 send_resp(dut, conn, SIGMA_COMPLETE,
3389 "Result,TLS server certificate validation failed");
3390 ret = STATUS_SENT_ERROR;
3391 break;
3392 }
3393
3394 if (strstr(buf, "CTRL-EVENT-NETWORK-NOT-FOUND")) {
3395 num_network_not_found++;
3396
3397 if (num_network_not_found > 2) {
3398 send_resp(dut, conn, SIGMA_COMPLETE,
3399 "Result,Network not found");
3400 ret = STATUS_SENT_ERROR;
3401 break;
3402 }
3403 }
3404
3405 if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
3406 num_disconnected++;
3407
3408 if (num_disconnected > 2) {
3409 send_resp(dut, conn, SIGMA_COMPLETE,
3410 "Result,Connection failed");
3411 ret = STATUS_SENT_ERROR;
3412 break;
3413 }
3414 }
3415
3416 if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
3417 if (tod >= 0) {
3418 sigma_dut_print(dut, DUT_MSG_DEBUG,
3419 "Network profile TOD policy update: %d -> %d",
3420 dut->sta_tod_policy, tod);
3421 dut->sta_tod_policy = tod;
3422 }
3423 break;
3424 }
3425 }
3426done:
3427 if (ctrl) {
3428 wpa_ctrl_detach(ctrl);
3429 wpa_ctrl_close(ctrl);
3430 }
3431 return ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003432}
3433
3434
3435static int run_hs20_osu(struct sigma_dut *dut, const char *params)
3436{
3437 char buf[500], cmd[200];
3438 int res;
3439
3440 /* Use hs20-osu-client file at the current dir, if found; otherwise use
3441 * default path */
3442 res = snprintf(cmd, sizeof(cmd),
3443 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
3444 file_exists("./hs20-osu-client") ?
3445 "./hs20-osu-client" : "hs20-osu-client",
3446 sigma_wpas_ctrl,
3447 dut->summary_log ? "-s " : "",
3448 dut->summary_log ? dut->summary_log : "");
3449 if (res < 0 || res >= (int) sizeof(cmd))
3450 return -1;
3451
3452 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
3453 if (res < 0 || res >= (int) sizeof(buf))
3454 return -1;
3455 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
3456
3457 if (system(buf) != 0) {
3458 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
3459 return -1;
3460 }
3461 sigma_dut_print(dut, DUT_MSG_DEBUG,
3462 "Completed hs20-osu-client operation");
3463
3464 return 0;
3465}
3466
3467
3468static int download_ppsmo(struct sigma_dut *dut,
3469 struct sigma_conn *conn,
3470 const char *intf,
3471 struct sigma_cmd *cmd)
3472{
3473 const char *name, *path, *val;
3474 char url[500], buf[600], fbuf[100];
3475 char *fqdn = NULL;
3476
3477 name = get_param(cmd, "FileName");
3478 path = get_param(cmd, "FilePath");
3479 if (name == NULL || path == NULL)
3480 return -1;
3481
3482 if (strcasecmp(path, "VendorSpecific") == 0) {
3483 snprintf(url, sizeof(url), "PPS/%s", name);
3484 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
3485 "from the device (%s)", url);
3486 if (!file_exists(url)) {
3487 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3488 "PPS MO file does not exist");
3489 return 0;
3490 }
3491 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
3492 if (system(buf) != 0) {
3493 send_resp(dut, conn, SIGMA_ERROR,
3494 "errorCode,Failed to copy PPS MO");
3495 return 0;
3496 }
3497 } else if (strncasecmp(path, "http:", 5) != 0 &&
3498 strncasecmp(path, "https:", 6) != 0) {
3499 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3500 "Unsupported FilePath value");
3501 return 0;
3502 } else {
3503 snprintf(url, sizeof(url), "%s/%s", path, name);
3504 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
3505 url);
3506 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
3507 remove("pps-tnds.xml");
3508 if (system(buf) != 0) {
3509 send_resp(dut, conn, SIGMA_ERROR,
3510 "errorCode,Failed to download PPS MO");
3511 return 0;
3512 }
3513 }
3514
3515 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
3516 send_resp(dut, conn, SIGMA_ERROR,
3517 "errorCode,Failed to parse downloaded PPSMO");
3518 return 0;
3519 }
3520 unlink("pps-tnds.xml");
3521
3522 val = get_param(cmd, "managementTreeURI");
3523 if (val) {
3524 const char *pos, *end;
3525 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
3526 val);
3527 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
3528 send_resp(dut, conn, SIGMA_ERROR,
3529 "errorCode,Invalid managementTreeURI prefix");
3530 return 0;
3531 }
3532 pos = val + 8;
3533 end = strchr(pos, '/');
3534 if (end == NULL ||
3535 strcmp(end, "/PerProviderSubscription") != 0) {
3536 send_resp(dut, conn, SIGMA_ERROR,
3537 "errorCode,Invalid managementTreeURI postfix");
3538 return 0;
3539 }
3540 if (end - pos >= (int) sizeof(fbuf)) {
3541 send_resp(dut, conn, SIGMA_ERROR,
3542 "errorCode,Too long FQDN in managementTreeURI");
3543 return 0;
3544 }
3545 memcpy(fbuf, pos, end - pos);
3546 fbuf[end - pos] = '\0';
3547 fqdn = fbuf;
3548 sigma_dut_print(dut, DUT_MSG_INFO,
3549 "FQDN from managementTreeURI: %s", fqdn);
3550 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3551 FILE *f = fopen("pps-fqdn", "r");
3552 if (f) {
3553 if (fgets(fbuf, sizeof(fbuf), f)) {
3554 fbuf[sizeof(fbuf) - 1] = '\0';
3555 fqdn = fbuf;
3556 sigma_dut_print(dut, DUT_MSG_DEBUG,
3557 "Use FQDN %s", fqdn);
3558 }
3559 fclose(f);
3560 }
3561 }
3562
3563 if (fqdn == NULL) {
3564 send_resp(dut, conn, SIGMA_ERROR,
3565 "errorCode,No FQDN specified");
3566 return 0;
3567 }
3568
3569 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3570 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3571 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3572
3573 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3574 if (rename("pps.xml", buf) < 0) {
3575 send_resp(dut, conn, SIGMA_ERROR,
3576 "errorCode,Could not move PPS MO");
3577 return 0;
3578 }
3579
3580 if (strcasecmp(path, "VendorSpecific") == 0) {
3581 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3582 fqdn);
3583 if (system(buf)) {
3584 send_resp(dut, conn, SIGMA_ERROR,
3585 "errorCode,Failed to copy OSU CA cert");
3586 return 0;
3587 }
3588
3589 snprintf(buf, sizeof(buf),
3590 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3591 fqdn);
3592 if (system(buf)) {
3593 send_resp(dut, conn, SIGMA_ERROR,
3594 "errorCode,Failed to copy AAA CA cert");
3595 return 0;
3596 }
3597 } else {
3598 snprintf(buf, sizeof(buf),
3599 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3600 fqdn, fqdn);
3601 if (run_hs20_osu(dut, buf) < 0) {
3602 send_resp(dut, conn, SIGMA_ERROR,
3603 "errorCode,Failed to download OSU CA cert");
3604 return 0;
3605 }
3606
3607 snprintf(buf, sizeof(buf),
3608 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3609 fqdn, fqdn);
3610 if (run_hs20_osu(dut, buf) < 0) {
3611 sigma_dut_print(dut, DUT_MSG_INFO,
3612 "Failed to download AAA CA cert");
3613 }
3614 }
3615
3616 if (file_exists("next-client-cert.pem")) {
3617 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3618 if (rename("next-client-cert.pem", buf) < 0) {
3619 send_resp(dut, conn, SIGMA_ERROR,
3620 "errorCode,Could not move client certificate");
3621 return 0;
3622 }
3623 }
3624
3625 if (file_exists("next-client-key.pem")) {
3626 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3627 if (rename("next-client-key.pem", buf) < 0) {
3628 send_resp(dut, conn, SIGMA_ERROR,
3629 "errorCode,Could not move client key");
3630 return 0;
3631 }
3632 }
3633
3634 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3635 if (run_hs20_osu(dut, buf) < 0) {
3636 send_resp(dut, conn, SIGMA_ERROR,
3637 "errorCode,Failed to configure credential from "
3638 "PPSMO");
3639 return 0;
3640 }
3641
3642 return 1;
3643}
3644
3645
3646static int download_cert(struct sigma_dut *dut,
3647 struct sigma_conn *conn,
3648 const char *intf,
3649 struct sigma_cmd *cmd)
3650{
3651 const char *name, *path;
3652 char url[500], buf[600];
3653
3654 name = get_param(cmd, "FileName");
3655 path = get_param(cmd, "FilePath");
3656 if (name == NULL || path == NULL)
3657 return -1;
3658
3659 if (strcasecmp(path, "VendorSpecific") == 0) {
3660 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3661 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3662 "certificate from the device (%s)", url);
3663 if (!file_exists(url)) {
3664 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3665 "certificate file does not exist");
3666 return 0;
3667 }
3668 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3669 if (system(buf) != 0) {
3670 send_resp(dut, conn, SIGMA_ERROR,
3671 "errorCode,Failed to copy client "
3672 "certificate");
3673 return 0;
3674 }
3675
3676 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3677 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3678 "private key from the device (%s)", url);
3679 if (!file_exists(url)) {
3680 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3681 "private key file does not exist");
3682 return 0;
3683 }
3684 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3685 if (system(buf) != 0) {
3686 send_resp(dut, conn, SIGMA_ERROR,
3687 "errorCode,Failed to copy client key");
3688 return 0;
3689 }
3690 } else if (strncasecmp(path, "http:", 5) != 0 &&
3691 strncasecmp(path, "https:", 6) != 0) {
3692 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3693 "Unsupported FilePath value");
3694 return 0;
3695 } else {
3696 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3697 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3698 "certificate/key from %s", url);
3699 snprintf(buf, sizeof(buf),
3700 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3701 if (system(buf) != 0) {
3702 send_resp(dut, conn, SIGMA_ERROR,
3703 "errorCode,Failed to download client "
3704 "certificate");
3705 return 0;
3706 }
3707
3708 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3709 {
3710 send_resp(dut, conn, SIGMA_ERROR,
3711 "errorCode,Failed to copy client key");
3712 return 0;
3713 }
3714 }
3715
3716 return 1;
3717}
3718
3719
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003720static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3721 struct sigma_conn *conn,
3722 struct sigma_cmd *cmd)
3723{
3724 const char *val;
3725 const char *intf = get_param(cmd, "interface");
3726
3727 if (!intf)
3728 return -1;
3729
3730 val = get_param(cmd, "WscIEFragment");
3731 if (val && strcasecmp(val, "enable") == 0) {
3732 sigma_dut_print(dut, DUT_MSG_DEBUG,
3733 "Enable WSC IE fragmentation");
3734
3735 dut->wsc_fragment = 1;
3736 /* set long attributes to force fragmentation */
3737 if (wpa_command(intf, "SET device_name "
3738 WPS_LONG_DEVICE_NAME) < 0)
3739 return -2;
3740 if (wpa_command(intf, "SET manufacturer "
3741 WPS_LONG_MANUFACTURER) < 0)
3742 return -2;
3743 if (wpa_command(intf, "SET model_name "
3744 WPS_LONG_MODEL_NAME) < 0)
3745 return -2;
3746 if (wpa_command(intf, "SET model_number "
3747 WPS_LONG_MODEL_NUMBER) < 0)
3748 return -2;
3749 if (wpa_command(intf, "SET serial_number "
3750 WPS_LONG_SERIAL_NUMBER) < 0)
3751 return -2;
3752 }
3753
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003754 val = get_param(cmd, "RSN_IE");
3755 if (val) {
3756 if (strcasecmp(val, "disable") == 0)
3757 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3758 else if (strcasecmp(val, "enable") == 0)
3759 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3760 }
3761
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02003762 val = get_param(cmd, "WpsVersion");
3763 if (val)
3764 dut->wps_forced_version = get_wps_forced_version(dut, val);
3765
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02003766 val = get_param(cmd, "WscEAPFragment");
3767 if (val && strcasecmp(val, "enable") == 0)
3768 dut->eap_fragment = 1;
3769
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003770 return 1;
3771}
3772
3773
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003774static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3775 struct sigma_conn *conn,
3776 const char *intf,
3777 struct sigma_cmd *cmd)
3778{
3779 const char *val;
3780
3781 val = get_param(cmd, "FileType");
3782 if (val && strcasecmp(val, "PPSMO") == 0)
3783 return download_ppsmo(dut, conn, intf, cmd);
3784 if (val && strcasecmp(val, "CERT") == 0)
3785 return download_cert(dut, conn, intf, cmd);
3786 if (val) {
3787 send_resp(dut, conn, SIGMA_ERROR,
3788 "ErrorCode,Unsupported FileType");
3789 return 0;
3790 }
3791
3792 return 1;
3793}
3794
3795
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303796static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3797 struct sigma_conn *conn,
3798 const char *intf,
3799 struct sigma_cmd *cmd)
3800{
3801 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303802 char buf[1000];
3803 char text[20];
3804 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303805
3806 val = get_param(cmd, "OCESupport");
3807 if (val && strcasecmp(val, "Disable") == 0) {
3808 if (wpa_command(intf, "SET oce 0") < 0) {
3809 send_resp(dut, conn, SIGMA_ERROR,
3810 "ErrorCode,Failed to disable OCE");
3811 return 0;
3812 }
3813 } else if (val && strcasecmp(val, "Enable") == 0) {
3814 if (wpa_command(intf, "SET oce 1") < 0) {
3815 send_resp(dut, conn, SIGMA_ERROR,
3816 "ErrorCode,Failed to enable OCE");
3817 return 0;
3818 }
3819 }
3820
vamsi krishnaa2799492017-12-05 14:28:01 +05303821 val = get_param(cmd, "FILScap");
3822 if (val && (atoi(val) == 1)) {
3823 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3824 send_resp(dut, conn, SIGMA_ERROR,
3825 "ErrorCode,Failed to enable FILS");
3826 return 0;
3827 }
3828 } else if (val && (atoi(val) == 0)) {
3829 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3830 send_resp(dut, conn, SIGMA_ERROR,
3831 "ErrorCode,Failed to disable FILS");
3832 return 0;
3833 }
3834 }
3835
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303836 val = get_param(cmd, "FILSHLP");
3837 if (val && strcasecmp(val, "Enable") == 0) {
3838 if (get_wpa_status(get_station_ifname(), "address", text,
3839 sizeof(text)) < 0)
3840 return -2;
3841 hwaddr_aton(text, addr);
3842 snprintf(buf, sizeof(buf),
3843 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3844 "080045100140000040004011399e00000000ffffffff00440043"
3845 "012cb30001010600fd4f46410000000000000000000000000000"
3846 "000000000000"
3847 "%02x%02x%02x%02x%02x%02x"
3848 "0000000000000000000000000000000000000000000000000000"
3849 "0000000000000000000000000000000000000000000000000000"
3850 "0000000000000000000000000000000000000000000000000000"
3851 "0000000000000000000000000000000000000000000000000000"
3852 "0000000000000000000000000000000000000000000000000000"
3853 "0000000000000000000000000000000000000000000000000000"
3854 "0000000000000000000000000000000000000000000000000000"
3855 "0000000000000000000000000000000000000000638253633501"
3856 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3857 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3858 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3859 if (wpa_command(intf, buf)) {
3860 send_resp(dut, conn, SIGMA_ERROR,
3861 "ErrorCode,Failed to add HLP");
3862 return 0;
3863 }
3864 dut->fils_hlp = 1;
3865 }
3866
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303867 return 1;
3868}
3869
3870
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003871static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3872 const char *val)
3873{
3874 int counter = 0;
3875 char token[50];
3876 char *result;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303877 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003878
Peng Xub8fc5cc2017-05-10 17:27:28 -07003879 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003880 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303881 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003882 while (result) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003883 if (strcmp(result, "disable") == 0)
3884 run_iwpriv(dut, intf, "noackpolicy %d 1 0", counter);
3885 else
3886 run_iwpriv(dut, intf, "noackpolicy %d 1 1", counter);
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303887 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003888 counter++;
3889 }
3890}
3891
3892
3893static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3894 const char *val)
3895{
3896 char buf[100];
3897
3898 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3899 if (system(buf) != 0) {
3900 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3901 }
3902}
3903
3904
3905static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3906 const char *val)
3907{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003908 if (strcasecmp(val, "off") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003909 run_iwpriv(dut, intf, "wmm 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003910 }
3911}
3912
3913
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003914static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3915 const char *val)
3916{
3917#ifdef NL80211_SUPPORT
3918 struct nl_msg *msg;
3919 int ret = 0;
3920 struct nlattr *params;
3921 int ifindex;
3922 int wmmenable = 1;
3923
3924 if (val &&
3925 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3926 wmmenable = 0;
3927
3928 ifindex = if_nametoindex(intf);
3929 if (ifindex == 0) {
3930 sigma_dut_print(dut, DUT_MSG_ERROR,
3931 "%s: Index for interface %s failed",
3932 __func__, intf);
3933 return -1;
3934 }
3935
3936 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3937 NL80211_CMD_VENDOR)) ||
3938 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3939 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3940 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3941 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3942 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3943 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3944 wmmenable)) {
3945 sigma_dut_print(dut, DUT_MSG_ERROR,
3946 "%s: err in adding vendor_cmd and vendor_data",
3947 __func__);
3948 nlmsg_free(msg);
3949 return -1;
3950 }
3951 nla_nest_end(msg, params);
3952
3953 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3954 if (ret) {
3955 sigma_dut_print(dut, DUT_MSG_ERROR,
3956 "%s: err in send_and_recv_msgs, ret=%d",
3957 __func__, ret);
3958 }
3959 return ret;
3960#else /* NL80211_SUPPORT */
3961 sigma_dut_print(dut, DUT_MSG_ERROR,
3962 "WMM cannot be changed without NL80211_SUPPORT defined");
3963 return -1;
3964#endif /* NL80211_SUPPORT */
3965}
3966
3967
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003968static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3969 const char *val)
3970{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003971 int sgi20;
3972
3973 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3974
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003975 run_iwpriv(dut, intf, "shortgi %d", sgi20);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003976}
3977
3978
3979static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3980 const char *val)
3981{
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303982 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003983
3984 /* Disable Tx Beam forming when using a fixed rate */
3985 ath_disable_txbf(dut, intf);
3986
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303987 v = atoi(val);
3988 if (v < 0 || v > 32) {
3989 sigma_dut_print(dut, DUT_MSG_ERROR,
3990 "Invalid Fixed MCS rate: %d", v);
3991 return;
3992 }
3993 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003994
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003995 run_iwpriv(dut, intf, "set11NRates 0x%x", rate_code);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003996
3997 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07003998 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003999}
4000
4001
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004002static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
4003 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004004{
4005 char buf[60];
4006
4007 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
4008 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
4009 else
4010 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4011
4012 if (system(buf) != 0)
4013 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
4014}
4015
4016
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004017static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
4018 int ampdu)
4019{
4020 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004021 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004022
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08004023 if (ampdu)
4024 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004025 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
4026 if (system(buf) != 0) {
4027 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
4028 return -1;
4029 }
4030
4031 return 0;
4032}
4033
4034
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004035static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4036 const char *val)
4037{
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004038 run_iwpriv(dut, intf, "tx_stbc %s", val);
4039 run_iwpriv(dut, intf, "rx_stbc %s", val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004040}
4041
4042
4043static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
4044 const char *val)
4045{
4046 char buf[60];
4047
Peng Xucc317ed2017-05-18 16:44:37 -07004048 if (strcmp(val, "160") == 0) {
4049 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
4050 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004051 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4052 } else if (strcmp(val, "40") == 0) {
4053 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
4054 } else if (strcmp(val, "20") == 0) {
4055 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
4056 } else if (strcasecmp(val, "Auto") == 0) {
4057 buf[0] = '\0';
4058 } else {
4059 sigma_dut_print(dut, DUT_MSG_ERROR,
4060 "WIDTH/CTS_WIDTH value not supported");
4061 return -1;
4062 }
4063
4064 if (buf[0] != '\0' && system(buf) != 0) {
4065 sigma_dut_print(dut, DUT_MSG_ERROR,
4066 "Failed to set WIDTH/CTS_WIDTH");
4067 return -1;
4068 }
4069
4070 return 0;
4071}
4072
4073
4074int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
4075 const char *intf, const char *val)
4076{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004077 if (strcasecmp(val, "Auto") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004078 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004079 dut->chwidth = 0;
4080 } else if (strcasecmp(val, "20") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004081 run_iwpriv(dut, intf, "chwidth 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004082 dut->chwidth = 0;
4083 } else if (strcasecmp(val, "40") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004084 run_iwpriv(dut, intf, "chwidth 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004085 dut->chwidth = 1;
4086 } else if (strcasecmp(val, "80") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004087 run_iwpriv(dut, intf, "chwidth 2");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004088 dut->chwidth = 2;
4089 } else if (strcasecmp(val, "160") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07004090 run_iwpriv(dut, intf, "chwidth 3");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004091 dut->chwidth = 3;
4092 } else {
4093 send_resp(dut, conn, SIGMA_ERROR,
4094 "ErrorCode,WIDTH not supported");
4095 return -1;
4096 }
4097
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004098 return 0;
4099}
4100
4101
4102static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
4103 const char *val)
4104{
4105 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07004106 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004107
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004108 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004109 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004110 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08004111 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004112 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07004113 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004114 } else {
4115 sigma_dut_print(dut, DUT_MSG_ERROR,
4116 "SP_STREAM value not supported");
4117 return -1;
4118 }
4119
4120 if (system(buf) != 0) {
4121 sigma_dut_print(dut, DUT_MSG_ERROR,
4122 "Failed to set SP_STREAM");
4123 return -1;
4124 }
4125
Arif Hussainac6c5112018-05-25 17:34:00 -07004126 dut->sta_nss = sta_nss;
4127
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004128 return 0;
4129}
4130
4131
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304132static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
4133 const char *val)
4134{
4135 char buf[60];
4136
4137 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
4138 if (system(buf) != 0)
4139 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
4140
4141 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
4142 if (system(buf) != 0)
4143 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
4144}
4145
4146
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304147static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
4148 struct sigma_conn *conn,
4149 const char *intf, int capa)
4150{
4151 char buf[32];
4152
4153 if (capa > 0 && capa < 4) {
4154 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
4155 if (wpa_command(intf, buf) < 0) {
4156 send_resp(dut, conn, SIGMA_ERROR,
4157 "ErrorCode, Failed to set cellular data capability");
4158 return 0;
4159 }
4160 return 1;
4161 }
4162
4163 sigma_dut_print(dut, DUT_MSG_ERROR,
4164 "Invalid Cellular data capability: %d", capa);
4165 send_resp(dut, conn, SIGMA_INVALID,
4166 "ErrorCode,Invalid cellular data capability");
4167 return 0;
4168}
4169
4170
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304171static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
4172 const char *intf, const char *val)
4173{
4174 if (strcasecmp(val, "Disable") == 0) {
4175 if (wpa_command(intf, "SET roaming 0") < 0) {
4176 send_resp(dut, conn, SIGMA_ERROR,
4177 "ErrorCode,Failed to disable roaming");
4178 return 0;
4179 }
4180 return 1;
4181 }
4182
4183 if (strcasecmp(val, "Enable") == 0) {
4184 if (wpa_command(intf, "SET roaming 1") < 0) {
4185 send_resp(dut, conn, SIGMA_ERROR,
4186 "ErrorCode,Failed to enable roaming");
4187 return 0;
4188 }
4189 return 1;
4190 }
4191
4192 sigma_dut_print(dut, DUT_MSG_ERROR,
4193 "Invalid value provided for roaming: %s", val);
4194 send_resp(dut, conn, SIGMA_INVALID,
4195 "ErrorCode,Unknown value provided for Roaming");
4196 return 0;
4197}
4198
4199
Ashwini Patila75de5a2017-04-13 16:35:05 +05304200static int mbo_set_assoc_disallow(struct sigma_dut *dut,
4201 struct sigma_conn *conn,
4202 const char *intf, const char *val)
4203{
4204 if (strcasecmp(val, "Disable") == 0) {
4205 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
4206 send_resp(dut, conn, SIGMA_ERROR,
4207 "ErrorCode,Failed to disable Assoc_disallow");
4208 return 0;
4209 }
4210 return 1;
4211 }
4212
4213 if (strcasecmp(val, "Enable") == 0) {
4214 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
4215 send_resp(dut, conn, SIGMA_ERROR,
4216 "ErrorCode,Failed to enable Assoc_disallow");
4217 return 0;
4218 }
4219 return 1;
4220 }
4221
4222 sigma_dut_print(dut, DUT_MSG_ERROR,
4223 "Invalid value provided for Assoc_disallow: %s", val);
4224 send_resp(dut, conn, SIGMA_INVALID,
4225 "ErrorCode,Unknown value provided for Assoc_disallow");
4226 return 0;
4227}
4228
4229
Ashwini Patilc63161e2017-04-13 16:30:23 +05304230static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
4231 const char *intf, const char *val)
4232{
4233 if (strcasecmp(val, "Reject") == 0) {
4234 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
4235 send_resp(dut, conn, SIGMA_ERROR,
4236 "ErrorCode,Failed to Reject BTM Request");
4237 return 0;
4238 }
4239 return 1;
4240 }
4241
4242 if (strcasecmp(val, "Accept") == 0) {
4243 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
4244 send_resp(dut, conn, SIGMA_ERROR,
4245 "ErrorCode,Failed to Accept BTM Request");
4246 return 0;
4247 }
4248 return 1;
4249 }
4250
4251 sigma_dut_print(dut, DUT_MSG_ERROR,
4252 "Invalid value provided for BSS_Transition: %s", val);
4253 send_resp(dut, conn, SIGMA_INVALID,
4254 "ErrorCode,Unknown value provided for BSS_Transition");
4255 return 0;
4256}
4257
4258
Ashwini Patil00402582017-04-13 12:29:39 +05304259static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
4260 struct sigma_conn *conn,
4261 const char *intf,
4262 struct sigma_cmd *cmd)
4263{
4264 const char *ch, *pref, *op_class, *reason;
4265 char buf[120];
4266 int len, ret;
4267
4268 pref = get_param(cmd, "Ch_Pref");
4269 if (!pref)
4270 return 1;
4271
4272 if (strcasecmp(pref, "clear") == 0) {
4273 free(dut->non_pref_ch_list);
4274 dut->non_pref_ch_list = NULL;
4275 } else {
4276 op_class = get_param(cmd, "Ch_Op_Class");
4277 if (!op_class) {
4278 send_resp(dut, conn, SIGMA_INVALID,
4279 "ErrorCode,Ch_Op_Class not provided");
4280 return 0;
4281 }
4282
4283 ch = get_param(cmd, "Ch_Pref_Num");
4284 if (!ch) {
4285 send_resp(dut, conn, SIGMA_INVALID,
4286 "ErrorCode,Ch_Pref_Num not provided");
4287 return 0;
4288 }
4289
4290 reason = get_param(cmd, "Ch_Reason_Code");
4291 if (!reason) {
4292 send_resp(dut, conn, SIGMA_INVALID,
4293 "ErrorCode,Ch_Reason_Code not provided");
4294 return 0;
4295 }
4296
4297 if (!dut->non_pref_ch_list) {
4298 dut->non_pref_ch_list =
4299 calloc(1, NON_PREF_CH_LIST_SIZE);
4300 if (!dut->non_pref_ch_list) {
4301 send_resp(dut, conn, SIGMA_ERROR,
4302 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
4303 return 0;
4304 }
4305 }
4306 len = strlen(dut->non_pref_ch_list);
4307 ret = snprintf(dut->non_pref_ch_list + len,
4308 NON_PREF_CH_LIST_SIZE - len,
4309 " %s:%s:%s:%s", op_class, ch, pref, reason);
4310 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
4311 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
4312 dut->non_pref_ch_list);
4313 } else {
4314 sigma_dut_print(dut, DUT_MSG_ERROR,
4315 "snprintf failed for non_pref_list, ret = %d",
4316 ret);
4317 send_resp(dut, conn, SIGMA_ERROR,
4318 "ErrorCode,snprintf failed");
4319 free(dut->non_pref_ch_list);
4320 dut->non_pref_ch_list = NULL;
4321 return 0;
4322 }
4323 }
4324
4325 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
4326 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
4327 if (ret < 0 || ret >= (int) sizeof(buf)) {
4328 sigma_dut_print(dut, DUT_MSG_DEBUG,
4329 "snprintf failed for set non_pref_chan, ret: %d",
4330 ret);
4331 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
4332 return 0;
4333 }
4334
4335 if (wpa_command(intf, buf) < 0) {
4336 send_resp(dut, conn, SIGMA_ERROR,
4337 "ErrorCode,Failed to set non-preferred channel list");
4338 return 0;
4339 }
4340
4341 return 1;
4342}
4343
4344
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004345#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004346
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08004347static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
4348 uint8_t cfg)
4349{
4350 struct nl_msg *msg;
4351 int ret = 0;
4352 struct nlattr *params;
4353 int ifindex;
4354
4355 ifindex = if_nametoindex(intf);
4356 if (ifindex == 0) {
4357 sigma_dut_print(dut, DUT_MSG_ERROR,
4358 "%s: Index for interface %s failed",
4359 __func__, intf);
4360 return -1;
4361 }
4362
4363 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4364 NL80211_CMD_VENDOR)) ||
4365 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4366 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4367 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4368 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4369 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4370 nla_put_u8(msg,
4371 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
4372 cfg)) {
4373 sigma_dut_print(dut, DUT_MSG_ERROR,
4374 "%s: err in adding vendor_cmd and vendor_data",
4375 __func__);
4376 nlmsg_free(msg);
4377 return -1;
4378 }
4379 nla_nest_end(msg, params);
4380
4381 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4382 if (ret) {
4383 sigma_dut_print(dut, DUT_MSG_ERROR,
4384 "%s: err in send_and_recv_msgs, ret=%d",
4385 __func__, ret);
4386 }
4387 return ret;
4388}
4389
4390
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004391static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
4392 enum he_fragmentation_val frag)
4393{
4394 struct nl_msg *msg;
4395 int ret = 0;
4396 struct nlattr *params;
4397 int ifindex;
4398
4399 ifindex = if_nametoindex(intf);
4400 if (ifindex == 0) {
4401 sigma_dut_print(dut, DUT_MSG_ERROR,
4402 "%s: Index for interface %s failed",
4403 __func__, intf);
4404 return -1;
4405 }
4406
4407 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4408 NL80211_CMD_VENDOR)) ||
4409 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4410 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4411 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4412 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4413 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4414 nla_put_u8(msg,
4415 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
4416 frag)) {
4417 sigma_dut_print(dut, DUT_MSG_ERROR,
4418 "%s: err in adding vendor_cmd and vendor_data",
4419 __func__);
4420 nlmsg_free(msg);
4421 return -1;
4422 }
4423 nla_nest_end(msg, params);
4424
4425 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4426 if (ret) {
4427 sigma_dut_print(dut, DUT_MSG_ERROR,
4428 "%s: err in send_and_recv_msgs, ret=%d",
4429 __func__, ret);
4430 }
4431 return ret;
4432}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004433
4434
Subhani Shaik8e7a3052018-04-24 14:03:00 -07004435static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
4436 enum qca_wlan_he_ltf_cfg ltf)
4437{
4438 struct nl_msg *msg;
4439 int ret = 0;
4440 struct nlattr *params;
4441 int ifindex;
4442
4443 ifindex = if_nametoindex(intf);
4444 if (ifindex == 0) {
4445 sigma_dut_print(dut, DUT_MSG_ERROR,
4446 "%s: Index for interface %s failed",
4447 __func__, intf);
4448 return -1;
4449 }
4450
4451 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4452 NL80211_CMD_VENDOR)) ||
4453 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4454 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4455 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4456 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4457 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4458 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
4459 ltf)) {
4460 sigma_dut_print(dut, DUT_MSG_ERROR,
4461 "%s: err in adding vendor_cmd and vendor_data",
4462 __func__);
4463 nlmsg_free(msg);
4464 return -1;
4465 }
4466 nla_nest_end(msg, params);
4467
4468 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4469 if (ret) {
4470 sigma_dut_print(dut, DUT_MSG_ERROR,
4471 "%s: err in send_and_recv_msgs, ret=%d",
4472 __func__, ret);
4473 }
4474 return ret;
4475}
4476
4477
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004478static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
4479 int noack, enum qca_wlan_ac_type ac)
4480{
4481 struct nl_msg *msg;
4482 int ret = 0;
4483 struct nlattr *params;
4484 int ifindex;
4485
4486 ifindex = if_nametoindex(intf);
4487 if (ifindex == 0) {
4488 sigma_dut_print(dut, DUT_MSG_ERROR,
4489 "%s: Index for interface %s failed",
4490 __func__, intf);
4491 return -1;
4492 }
4493
4494 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4495 NL80211_CMD_VENDOR)) ||
4496 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4497 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4498 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4499 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4500 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4501 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4502 noack) ||
4503 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4504 ac)) {
4505 sigma_dut_print(dut, DUT_MSG_ERROR,
4506 "%s: err in adding vendor_cmd and vendor_data",
4507 __func__);
4508 nlmsg_free(msg);
4509 return -1;
4510 }
4511 nla_nest_end(msg, params);
4512
4513 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4514 if (ret) {
4515 sigma_dut_print(dut, DUT_MSG_ERROR,
4516 "%s: err in send_and_recv_msgs, ret=%d",
4517 __func__, ret);
4518 }
4519 return ret;
4520}
4521
4522
4523static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4524 const char *val)
4525{
4526 int noack, ret;
4527 char token[100];
4528 char *result;
4529 char *saveptr;
4530 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4531
4532 strlcpy(token, val, sizeof(token));
4533 token[sizeof(token) - 1] = '\0';
4534 result = strtok_r(token, ":", &saveptr);
4535 while (result) {
4536 noack = strcasecmp(result, "Disable") != 0;
4537 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4538 if (ret) {
4539 sigma_dut_print(dut, DUT_MSG_ERROR,
4540 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4541 ac, ret);
4542 }
4543 result = strtok_r(NULL, ":", &saveptr);
4544 ac++;
4545 }
4546}
4547
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004548#endif /* NL80211_SUPPORT */
4549
4550
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004551static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
4552 struct sigma_conn *conn,
4553 struct sigma_cmd *cmd)
4554{
4555 const char *intf = get_param(cmd, "Interface");
4556 const char *val;
4557
4558 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004559 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4560 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004561 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4562 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004563
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004564 if (val && strcasecmp(val, "LOC") == 0)
4565 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004566 if (val && strcasecmp(val, "60GHZ") == 0) {
4567 val = get_param(cmd, "WPS");
4568 if (val && strcasecmp(val, "disable") == 0) {
4569 dut->wps_disable = 1;
4570 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4571 } else {
4572 /* wps_disable can have other value from the previous
4573 * test, so make sure it has the correct value.
4574 */
4575 dut->wps_disable = 0;
4576 }
4577
4578 val = get_param(cmd, "P2P");
4579 if (val && strcasecmp(val, "disable") == 0)
4580 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4581 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004582
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004583 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4584 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4585
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004586#ifdef ANDROID_NAN
4587 if (val && strcasecmp(val, "NAN") == 0)
4588 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4589#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004590#ifdef MIRACAST
4591 if (val && (strcasecmp(val, "WFD") == 0 ||
4592 strcasecmp(val, "DisplayR2") == 0))
4593 return miracast_preset_testparameters(dut, conn, cmd);
4594#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004595
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304596 if (val && strcasecmp(val, "MBO") == 0) {
4597 val = get_param(cmd, "Cellular_Data_Cap");
4598 if (val &&
4599 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4600 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304601
4602 val = get_param(cmd, "Ch_Pref");
4603 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4604 return 0;
4605
Ashwini Patilc63161e2017-04-13 16:30:23 +05304606 val = get_param(cmd, "BSS_Transition");
4607 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4608 return 0;
4609
Ashwini Patila75de5a2017-04-13 16:35:05 +05304610 val = get_param(cmd, "Assoc_Disallow");
4611 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4612 return 0;
4613
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304614 val = get_param(cmd, "Roaming");
4615 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4616 return 0;
4617
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304618 return 1;
4619 }
4620
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304621 if (val && strcasecmp(val, "OCE") == 0)
4622 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4623
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004624#if 0
4625 val = get_param(cmd, "Supplicant");
4626 if (val && strcasecmp(val, "Default") != 0) {
4627 send_resp(dut, conn, SIGMA_ERROR,
4628 "ErrorCode,Only default(Vendor) supplicant "
4629 "supported");
4630 return 0;
4631 }
4632#endif
4633
4634 val = get_param(cmd, "RTS");
4635 if (val) {
4636 switch (get_driver_type()) {
4637 case DRIVER_ATHEROS:
4638 ath_sta_set_rts(dut, intf, val);
4639 break;
4640 default:
4641#if 0
4642 send_resp(dut, conn, SIGMA_ERROR,
4643 "ErrorCode,Setting RTS not supported");
4644 return 0;
4645#else
4646 sigma_dut_print(dut, DUT_MSG_DEBUG,
4647 "Setting RTS not supported");
4648 break;
4649#endif
4650 }
4651 }
4652
4653#if 0
4654 val = get_param(cmd, "FRGMNT");
4655 if (val) {
4656 /* TODO */
4657 send_resp(dut, conn, SIGMA_ERROR,
4658 "ErrorCode,Setting FRGMNT not supported");
4659 return 0;
4660 }
4661#endif
4662
4663#if 0
4664 val = get_param(cmd, "Preamble");
4665 if (val) {
4666 /* TODO: Long/Short */
4667 send_resp(dut, conn, SIGMA_ERROR,
4668 "ErrorCode,Setting Preamble not supported");
4669 return 0;
4670 }
4671#endif
4672
4673 val = get_param(cmd, "Mode");
4674 if (val) {
4675 if (strcmp(val, "11b") == 0 ||
4676 strcmp(val, "11g") == 0 ||
4677 strcmp(val, "11a") == 0 ||
4678 strcmp(val, "11n") == 0 ||
4679 strcmp(val, "11ng") == 0 ||
4680 strcmp(val, "11nl") == 0 ||
4681 strcmp(val, "11nl(nabg)") == 0 ||
4682 strcmp(val, "AC") == 0 ||
4683 strcmp(val, "11AC") == 0 ||
4684 strcmp(val, "11ac") == 0 ||
4685 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004686 strcmp(val, "11an") == 0 ||
4687 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004688 /* STA supports all modes by default */
4689 } else {
4690 send_resp(dut, conn, SIGMA_ERROR,
4691 "ErrorCode,Setting Mode not supported");
4692 return 0;
4693 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004694
4695 /* Change the mode only in case of testbed for HE program
4696 * and for 11a and 11g modes only. */
4697 if (dut->program == PROGRAM_HE &&
4698 dut->device_type == STA_testbed) {
4699 int phymode;
4700 char buf[60];
4701
4702 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004703 phymode = 1; /* IEEE80211_MODE_11A */
4704 } else if (strcmp(val, "11g") == 0) {
4705 phymode = 3; /* IEEE80211_MODE_11G */
4706 } else if (strcmp(val, "11b") == 0) {
4707 phymode = 2; /* IEEE80211_MODE_11B */
4708 } else if (strcmp(val, "11n") == 0 ||
4709 strcmp(val, "11nl") == 0 ||
4710 strcmp(val, "11nl(nabg)") == 0) {
4711 phymode = 22; /* IEEE80211_MODE_11AGN */
4712 } else if (strcmp(val, "11ng") == 0) {
4713 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4714 } else if (strcmp(val, "AC") == 0 ||
4715 strcasecmp(val, "11AC") == 0) {
4716 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4717 } else if (strcmp(val, "11na") == 0 ||
4718 strcasecmp(val, "11an") == 0) {
4719 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4720 } else if (strcmp(val, "11ax") == 0) {
4721 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004722 } else {
4723 sigma_dut_print(dut, DUT_MSG_DEBUG,
4724 "Ignoring mode change for mode: %s",
4725 val);
4726 phymode = -1;
4727 }
4728 if (phymode != -1) {
4729 snprintf(buf, sizeof(buf),
4730 "iwpriv %s setphymode %d",
4731 intf, phymode);
4732 if (system(buf) != 0) {
4733 sigma_dut_print(dut, DUT_MSG_ERROR,
4734 "iwpriv setting of phymode failed");
4735 }
4736 }
4737 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004738 }
4739
4740 val = get_param(cmd, "wmm");
4741 if (val) {
4742 switch (get_driver_type()) {
4743 case DRIVER_ATHEROS:
4744 ath_sta_set_wmm(dut, intf, val);
4745 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004746 case DRIVER_WCN:
4747 wcn_sta_set_wmm(dut, intf, val);
4748 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004749 default:
4750 sigma_dut_print(dut, DUT_MSG_DEBUG,
4751 "Setting wmm not supported");
4752 break;
4753 }
4754 }
4755
4756 val = get_param(cmd, "Powersave");
4757 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004758 char buf[60];
4759
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004760 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004761 if (get_driver_type() == DRIVER_WCN) {
4762 snprintf(buf, sizeof(buf),
4763 "iwpriv %s setPower 2", intf);
4764 if (system(buf) != 0) {
4765 sigma_dut_print(dut, DUT_MSG_ERROR,
4766 "iwpriv setPower 2 failed");
4767 return 0;
4768 }
4769 }
4770
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004771 if (wpa_command(get_station_ifname(),
4772 "P2P_SET ps 0") < 0)
4773 return -2;
4774 /* Make sure test modes are disabled */
4775 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4776 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4777 } else if (strcmp(val, "1") == 0 ||
4778 strcasecmp(val, "PSPoll") == 0 ||
4779 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004780 if (get_driver_type() == DRIVER_WCN) {
4781 snprintf(buf, sizeof(buf),
4782 "iwpriv %s setPower 1", intf);
4783 if (system(buf) != 0) {
4784 sigma_dut_print(dut, DUT_MSG_ERROR,
4785 "iwpriv setPower 1 failed");
4786 return 0;
4787 }
4788 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004789 /* Disable default power save mode */
4790 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4791 /* Enable PS-Poll test mode */
4792 if (wpa_command(get_station_ifname(),
4793 "P2P_SET ps 97") < 0 ||
4794 wpa_command(get_station_ifname(),
4795 "P2P_SET ps 99") < 0)
4796 return -2;
4797 } else if (strcmp(val, "2") == 0 ||
4798 strcasecmp(val, "Fast") == 0) {
4799 /* TODO */
4800 send_resp(dut, conn, SIGMA_ERROR,
4801 "ErrorCode,Powersave=Fast not supported");
4802 return 0;
4803 } else if (strcmp(val, "3") == 0 ||
4804 strcasecmp(val, "PSNonPoll") == 0) {
4805 /* Make sure test modes are disabled */
4806 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4807 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4808
4809 /* Enable default power save mode */
4810 if (wpa_command(get_station_ifname(),
4811 "P2P_SET ps 1") < 0)
4812 return -2;
4813 } else
4814 return -1;
4815 }
4816
4817 val = get_param(cmd, "NoAck");
4818 if (val) {
4819 switch (get_driver_type()) {
4820 case DRIVER_ATHEROS:
4821 ath_sta_set_noack(dut, intf, val);
4822 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004823#ifdef NL80211_SUPPORT
4824 case DRIVER_WCN:
4825 wcn_sta_set_noack(dut, intf, val);
4826 break;
4827#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004828 default:
4829 send_resp(dut, conn, SIGMA_ERROR,
4830 "ErrorCode,Setting NoAck not supported");
4831 return 0;
4832 }
4833 }
4834
4835 val = get_param(cmd, "IgnoreChswitchProhibit");
4836 if (val) {
4837 /* TODO: Enabled/disabled */
4838 if (strcasecmp(val, "Enabled") == 0) {
4839 send_resp(dut, conn, SIGMA_ERROR,
4840 "ErrorCode,Enabling IgnoreChswitchProhibit "
4841 "not supported");
4842 return 0;
4843 }
4844 }
4845
4846 val = get_param(cmd, "TDLS");
4847 if (val) {
4848 if (strcasecmp(val, "Disabled") == 0) {
4849 if (wpa_command(intf, "SET tdls_disabled 1")) {
4850 send_resp(dut, conn, SIGMA_ERROR,
4851 "ErrorCode,Failed to disable TDLS");
4852 return 0;
4853 }
4854 } else if (strcasecmp(val, "Enabled") == 0) {
4855 if (wpa_command(intf, "SET tdls_disabled 0")) {
4856 send_resp(dut, conn, SIGMA_ERROR,
4857 "ErrorCode,Failed to enable TDLS");
4858 return 0;
4859 }
4860 } else {
4861 send_resp(dut, conn, SIGMA_ERROR,
4862 "ErrorCode,Unsupported TDLS value");
4863 return 0;
4864 }
4865 }
4866
4867 val = get_param(cmd, "TDLSmode");
4868 if (val) {
4869 if (strcasecmp(val, "Default") == 0) {
4870 wpa_command(intf, "SET tdls_testing 0");
4871 } else if (strcasecmp(val, "APProhibit") == 0) {
4872 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4873 send_resp(dut, conn, SIGMA_ERROR,
4874 "ErrorCode,Failed to enable ignore "
4875 "APProhibit TDLS mode");
4876 return 0;
4877 }
4878 } else if (strcasecmp(val, "HiLoMac") == 0) {
4879 /* STA should respond with TDLS setup req for a TDLS
4880 * setup req */
4881 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4882 send_resp(dut, conn, SIGMA_ERROR,
4883 "ErrorCode,Failed to enable HiLoMac "
4884 "TDLS mode");
4885 return 0;
4886 }
4887 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4888 /*
4889 * Since all security modes are enabled by default when
4890 * Sigma control is used, there is no need to do
4891 * anything here.
4892 */
4893 } else if (strcasecmp(val, "ExistLink") == 0) {
4894 /*
4895 * Since we allow new TDLS Setup Request even if there
4896 * is an existing link, nothing needs to be done for
4897 * this.
4898 */
4899 } else {
4900 /* TODO:
4901 * ExistLink: STA should send TDLS setup req even if
4902 * direct link already exists
4903 */
4904 send_resp(dut, conn, SIGMA_ERROR,
4905 "ErrorCode,Unsupported TDLSmode value");
4906 return 0;
4907 }
4908 }
4909
4910 val = get_param(cmd, "FakePubKey");
4911 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4912 send_resp(dut, conn, SIGMA_ERROR,
4913 "ErrorCode,Failed to enable FakePubKey");
4914 return 0;
4915 }
4916
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004917#ifdef NL80211_SUPPORT
4918 val = get_param(cmd, "FrgmntSupport");
4919 if (val) {
4920 if (strcasecmp(val, "Enable") == 0) {
4921 if (sta_set_he_fragmentation(dut, intf,
4922 HE_FRAG_LEVEL1)) {
4923 send_resp(dut, conn, SIGMA_ERROR,
4924 "ErrorCode,Failed to enable HE Fragmentation");
4925 return 0;
4926 }
4927 } else if (strcasecmp(val, "Disable") == 0) {
4928 if (sta_set_he_fragmentation(dut, intf,
4929 HE_FRAG_DISABLE)) {
4930 send_resp(dut, conn, SIGMA_ERROR,
4931 "ErrorCode,Failed to disable HE Fragmentation");
4932 return 0;
4933 }
4934 }
4935 }
4936#endif /* NL80211_SUPPORT */
4937
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004938 return 1;
4939}
4940
4941
4942static const char * ath_get_radio_name(const char *radio_name)
4943{
4944 if (radio_name == NULL)
4945 return "wifi0";
4946 if (strcmp(radio_name, "wifi1") == 0)
4947 return "wifi1";
4948 if (strcmp(radio_name, "wifi2") == 0)
4949 return "wifi2";
4950 return "wifi0";
4951}
4952
4953
4954static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4955 const char *val)
4956{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004957 unsigned int vht_mcsmap = 0;
4958 int txchainmask = 0;
4959 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4960
4961 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4962 if (dut->testbed_flag_txsp == 1) {
4963 vht_mcsmap = 0xfffc;
4964 dut->testbed_flag_txsp = 0;
4965 } else {
4966 vht_mcsmap = 0xfffe;
4967 }
4968 txchainmask = 1;
4969 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4970 if (dut->testbed_flag_txsp == 1) {
4971 vht_mcsmap = 0xfff0;
4972 dut->testbed_flag_txsp = 0;
4973 } else {
4974 vht_mcsmap = 0xfffa;
4975 }
4976 txchainmask = 3;
4977 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4978 if (dut->testbed_flag_txsp == 1) {
4979 vht_mcsmap = 0xffc0;
4980 dut->testbed_flag_txsp = 0;
4981 } else {
4982 vht_mcsmap = 0xffea;
4983 }
4984 txchainmask = 7;
4985 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4986 if (dut->testbed_flag_txsp == 1) {
4987 vht_mcsmap = 0xff00;
4988 dut->testbed_flag_txsp = 0;
4989 } else {
4990 vht_mcsmap = 0xffaa;
4991 }
4992 txchainmask = 15;
4993 } else {
4994 if (dut->testbed_flag_txsp == 1) {
4995 vht_mcsmap = 0xffc0;
4996 dut->testbed_flag_txsp = 0;
4997 } else {
4998 vht_mcsmap = 0xffea;
4999 }
5000 }
5001
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005002 if (txchainmask)
5003 run_iwpriv(dut, basedev, "txchainmask %d", txchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005004
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005005 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005006}
5007
5008
5009static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
5010 const char *val)
5011{
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005012 unsigned int vht_mcsmap = 0;
5013 int rxchainmask = 0;
5014 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
5015
5016 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
5017 if (dut->testbed_flag_rxsp == 1) {
5018 vht_mcsmap = 0xfffc;
5019 dut->testbed_flag_rxsp = 0;
5020 } else {
5021 vht_mcsmap = 0xfffe;
5022 }
5023 rxchainmask = 1;
5024 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
5025 if (dut->testbed_flag_rxsp == 1) {
5026 vht_mcsmap = 0xfff0;
5027 dut->testbed_flag_rxsp = 0;
5028 } else {
5029 vht_mcsmap = 0xfffa;
5030 }
5031 rxchainmask = 3;
5032 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
5033 if (dut->testbed_flag_rxsp == 1) {
5034 vht_mcsmap = 0xffc0;
5035 dut->testbed_flag_rxsp = 0;
5036 } else {
5037 vht_mcsmap = 0xffea;
5038 }
5039 rxchainmask = 7;
5040 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
5041 if (dut->testbed_flag_rxsp == 1) {
5042 vht_mcsmap = 0xff00;
5043 dut->testbed_flag_rxsp = 0;
5044 } else {
5045 vht_mcsmap = 0xffaa;
5046 }
5047 rxchainmask = 15;
5048 } else {
5049 if (dut->testbed_flag_rxsp == 1) {
5050 vht_mcsmap = 0xffc0;
5051 dut->testbed_flag_rxsp = 0;
5052 } else {
5053 vht_mcsmap = 0xffea;
5054 }
5055 }
5056
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005057 if (rxchainmask)
5058 run_iwpriv(dut, basedev, "rxchainmask %d", rxchainmask);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005059
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005060 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005061}
5062
5063
5064void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
5065{
5066 if (strcasecmp(val, "enable") == 0) {
5067 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
5068 != 0) {
5069 sigma_dut_print(dut, DUT_MSG_ERROR,
5070 "Disable BB_VHTSIGB_CRC_CALC failed");
5071 }
5072
5073 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
5074 != 0) {
5075 sigma_dut_print(dut, DUT_MSG_ERROR,
5076 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5077 }
5078 } else {
5079 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
5080 != 0) {
5081 sigma_dut_print(dut, DUT_MSG_ERROR,
5082 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
5083 }
5084
5085 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
5086 != 0) {
5087 sigma_dut_print(dut, DUT_MSG_ERROR,
5088 "Enable BB_VHTSIGB_CRC_CALC failed");
5089 }
5090 }
5091}
5092
5093
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005094static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
5095 const char *val)
5096{
5097 char buf[60];
5098
5099 if (strcmp(val, "20") == 0) {
5100 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5101 dut->chwidth = 0;
5102 } else if (strcmp(val, "40") == 0) {
5103 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
5104 dut->chwidth = 1;
5105 } else if (strcmp(val, "80") == 0) {
5106 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5107 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05305108 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005109 buf[0] = '\0';
5110 } else {
5111 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
5112 val);
5113 return -1;
5114 }
5115
5116 if (buf[0] != '\0' && system(buf) != 0) {
5117 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
5118 return -1;
5119 }
5120
5121 return 0;
5122}
5123
5124
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005125static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
5126 const char *intf, int addbareject)
5127{
5128#ifdef NL80211_SUPPORT
5129 struct nl_msg *msg;
5130 int ret = 0;
5131 struct nlattr *params;
5132 int ifindex;
5133
5134 ifindex = if_nametoindex(intf);
5135 if (ifindex == 0) {
5136 sigma_dut_print(dut, DUT_MSG_ERROR,
5137 "%s: Index for interface %s failed",
5138 __func__, intf);
5139 return -1;
5140 }
5141
5142 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5143 NL80211_CMD_VENDOR)) ||
5144 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5145 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5146 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5147 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5148 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5149 nla_put_u8(msg,
5150 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
5151 !addbareject)) {
5152 sigma_dut_print(dut, DUT_MSG_ERROR,
5153 "%s: err in adding vendor_cmd and vendor_data",
5154 __func__);
5155 nlmsg_free(msg);
5156 return -1;
5157 }
5158 nla_nest_end(msg, params);
5159
5160 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5161 if (ret) {
5162 sigma_dut_print(dut, DUT_MSG_ERROR,
5163 "%s: err in send_and_recv_msgs, ret=%d",
5164 __func__, ret);
5165 }
5166 return ret;
5167#else /* NL80211_SUPPORT */
5168 sigma_dut_print(dut, DUT_MSG_ERROR,
5169 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
5170 return -1;
5171#endif /* NL80211_SUPPORT */
5172}
5173
5174
5175static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
5176 int addbareject)
5177{
5178 int ret;
5179
5180 switch (get_driver_type()) {
5181 case DRIVER_WCN:
5182 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
5183 if (ret) {
5184 sigma_dut_print(dut, DUT_MSG_ERROR,
5185 "nlvendor_sta_set_addba_reject failed, ret:%d",
5186 ret);
5187 return ret;
5188 }
5189 break;
5190 default:
5191 sigma_dut_print(dut, DUT_MSG_ERROR,
5192 "errorCode,Unsupported ADDBA_REJECT with the current driver");
5193 ret = -1;
5194 break;
5195 }
5196
5197 return ret;
5198}
5199
5200
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005201static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
5202 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005203{
5204#ifdef NL80211_SUPPORT
5205 struct nl_msg *msg;
5206 int ret = 0;
5207 struct nlattr *params;
5208 int ifindex;
5209
5210 ifindex = if_nametoindex(intf);
5211 if (ifindex == 0) {
5212 sigma_dut_print(dut, DUT_MSG_ERROR,
5213 "%s: Index for interface %s failed",
5214 __func__, intf);
5215 return -1;
5216 }
5217
5218 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5219 NL80211_CMD_VENDOR)) ||
5220 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5221 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5222 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5223 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5224 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5225 nla_put_u8(msg,
5226 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005227 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005228 sigma_dut_print(dut, DUT_MSG_ERROR,
5229 "%s: err in adding vendor_cmd and vendor_data",
5230 __func__);
5231 nlmsg_free(msg);
5232 return -1;
5233 }
5234 nla_nest_end(msg, params);
5235
5236 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5237 if (ret) {
5238 sigma_dut_print(dut, DUT_MSG_ERROR,
5239 "%s: err in send_and_recv_msgs, ret=%d",
5240 __func__, ret);
5241 }
5242 return ret;
5243#else /* NL80211_SUPPORT */
5244 sigma_dut_print(dut, DUT_MSG_ERROR,
5245 "Disable addba not possible without NL80211_SUPPORT defined");
5246 return -1;
5247#endif /* NL80211_SUPPORT */
5248}
5249
5250
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305251#ifdef NL80211_SUPPORT
5252static int nl80211_sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5253{
5254 struct nl_msg *msg;
5255 int ret = 0;
5256 int ifindex;
5257
5258 ifindex = if_nametoindex(intf);
5259 if (ifindex == 0) {
5260 sigma_dut_print(dut, DUT_MSG_ERROR,
5261 "%s: Index for interface %s failed",
5262 __func__, intf);
5263 return -1;
5264 }
5265
5266 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5267 NL80211_CMD_SET_WIPHY)) ||
5268 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
5269 sigma_dut_print(dut, DUT_MSG_ERROR,
5270 "%s: err in adding RTS threshold",
5271 __func__);
5272 nlmsg_free(msg);
5273 return -1;
5274 }
5275
5276 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5277 if (ret) {
5278 sigma_dut_print(dut, DUT_MSG_ERROR,
5279 "%s: err in send_and_recv_msgs, ret=%d",
5280 __func__, ret);
5281 }
5282 return ret;
5283}
5284#endif /* NL80211_SUPPORT */
5285
5286
5287static int sta_set_rts(struct sigma_dut *dut, const char *intf, int val)
5288{
5289 char buf[100];
5290
5291#ifdef NL80211_SUPPORT
5292 if (nl80211_sta_set_rts(dut, intf, val) == 0)
5293 return 0;
5294 sigma_dut_print(dut, DUT_MSG_DEBUG,
5295 "Fall back to using iwconfig for setting RTS threshold");
5296#endif /* NL80211_SUPPORT */
5297
5298 snprintf(buf, sizeof(buf), "iwconfig %s rts %d", intf, val);
5299 if (system(buf) != 0) {
5300 sigma_dut_print(dut, DUT_MSG_ERROR,
5301 "Failed to set RTS threshold %d", val);
5302 return -1;
5303 }
5304 return 0;
5305}
5306
5307
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005308static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
5309 struct sigma_conn *conn,
5310 struct sigma_cmd *cmd)
5311{
5312 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005313 int ampdu = -1, addbareject = -1;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005314 char buf[128];
5315 int res;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005316
5317 val = get_param(cmd, "40_INTOLERANT");
5318 if (val) {
5319 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5320 /* TODO: iwpriv ht40intol through wpa_supplicant */
5321 send_resp(dut, conn, SIGMA_ERROR,
5322 "ErrorCode,40_INTOLERANT not supported");
5323 return 0;
5324 }
5325 }
5326
5327 val = get_param(cmd, "ADDBA_REJECT");
5328 if (val) {
5329 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5330 /* reject any ADDBA with status "decline" */
5331 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005332 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005333 } else {
5334 /* accept ADDBA */
5335 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005336 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005337 }
5338 }
5339
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08005340 if (addbareject >= 0 &&
5341 sta_set_addba_reject(dut, intf, addbareject) < 0) {
5342 send_resp(dut, conn, SIGMA_ERROR,
5343 "ErrorCode,set addba_reject failed");
5344 return 0;
5345 }
5346
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005347 val = get_param(cmd, "AMPDU");
5348 if (val) {
5349 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
5350 /* enable AMPDU Aggregation */
5351 if (ampdu == 0) {
5352 send_resp(dut, conn, SIGMA_ERROR,
5353 "ErrorCode,Mismatch in "
5354 "addba_reject/ampdu - "
5355 "not supported");
5356 return 0;
5357 }
5358 ampdu = 1;
5359 } else {
5360 /* disable AMPDU Aggregation */
5361 if (ampdu == 1) {
5362 send_resp(dut, conn, SIGMA_ERROR,
5363 "ErrorCode,Mismatch in "
5364 "addba_reject/ampdu - "
5365 "not supported");
5366 return 0;
5367 }
5368 ampdu = 0;
5369 }
5370 }
5371
5372 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005373 int ret;
5374
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005375 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
5376 ampdu ? "Enabling" : "Disabling");
5377 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07005378 if (wpa_command(intf, buf) < 0 &&
5379 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005380 send_resp(dut, conn, SIGMA_ERROR,
5381 "ErrorCode,set aggr failed");
5382 return 0;
5383 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005384
5385 if (ampdu == 0) {
5386 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08005387 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08005388 if (ret) {
5389 sigma_dut_print(dut, DUT_MSG_ERROR,
5390 "Failed to disable addba, ret:%d",
5391 ret);
5392 }
5393 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005394 }
5395
5396 val = get_param(cmd, "AMSDU");
5397 if (val) {
5398 switch (get_driver_type()) {
5399 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08005400 case DRIVER_WCN:
5401 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005402 break;
5403 default:
5404 if (strcmp(val, "1") == 0 ||
5405 strcasecmp(val, "Enable") == 0) {
5406 /* Enable AMSDU Aggregation */
5407 send_resp(dut, conn, SIGMA_ERROR,
5408 "ErrorCode,AMSDU aggregation not supported");
5409 return 0;
5410 }
5411 break;
5412 }
5413 }
5414
5415 val = get_param(cmd, "STBC_RX");
5416 if (val) {
5417 switch (get_driver_type()) {
5418 case DRIVER_ATHEROS:
5419 ath_sta_set_stbc(dut, intf, val);
5420 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05305421 case DRIVER_WCN:
5422 wcn_sta_set_stbc(dut, intf, val);
5423 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005424 default:
5425 send_resp(dut, conn, SIGMA_ERROR,
5426 "ErrorCode,STBC_RX not supported");
5427 return 0;
5428 }
5429 }
5430
5431 val = get_param(cmd, "WIDTH");
5432 if (val) {
5433 switch (get_driver_type()) {
5434 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08005435 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005436 send_resp(dut, conn, SIGMA_ERROR,
5437 "ErrorCode,Failed to set WIDTH");
5438 return 0;
5439 }
5440 break;
5441 case DRIVER_ATHEROS:
5442 if (ath_set_width(dut, conn, intf, val) < 0)
5443 return 0;
5444 break;
5445 default:
5446 sigma_dut_print(dut, DUT_MSG_ERROR,
5447 "Setting WIDTH not supported");
5448 break;
5449 }
5450 }
5451
5452 val = get_param(cmd, "SMPS");
5453 if (val) {
5454 /* TODO: Dynamic/0, Static/1, No Limit/2 */
5455 send_resp(dut, conn, SIGMA_ERROR,
5456 "ErrorCode,SMPS not supported");
5457 return 0;
5458 }
5459
5460 val = get_param(cmd, "TXSP_STREAM");
5461 if (val) {
5462 switch (get_driver_type()) {
5463 case DRIVER_WCN:
5464 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5465 send_resp(dut, conn, SIGMA_ERROR,
5466 "ErrorCode,Failed to set TXSP_STREAM");
5467 return 0;
5468 }
5469 break;
5470 case DRIVER_ATHEROS:
5471 ath_sta_set_txsp_stream(dut, intf, val);
5472 break;
5473 default:
5474 sigma_dut_print(dut, DUT_MSG_ERROR,
5475 "Setting TXSP_STREAM not supported");
5476 break;
5477 }
5478 }
5479
5480 val = get_param(cmd, "RXSP_STREAM");
5481 if (val) {
5482 switch (get_driver_type()) {
5483 case DRIVER_WCN:
5484 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
5485 send_resp(dut, conn, SIGMA_ERROR,
5486 "ErrorCode,Failed to set RXSP_STREAM");
5487 return 0;
5488 }
5489 break;
5490 case DRIVER_ATHEROS:
5491 ath_sta_set_rxsp_stream(dut, intf, val);
5492 break;
5493 default:
5494 sigma_dut_print(dut, DUT_MSG_ERROR,
5495 "Setting RXSP_STREAM not supported");
5496 break;
5497 }
5498 }
5499
5500 val = get_param(cmd, "DYN_BW_SGNL");
5501 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005502 switch (get_driver_type()) {
5503 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08005504 if (strcasecmp(val, "enable") == 0) {
5505 snprintf(buf, sizeof(buf),
5506 "iwpriv %s cwmenable 1", intf);
5507 if (system(buf) != 0) {
5508 sigma_dut_print(dut, DUT_MSG_ERROR,
5509 "iwpriv cwmenable 1 failed");
5510 return 0;
5511 }
5512 } else if (strcasecmp(val, "disable") == 0) {
5513 snprintf(buf, sizeof(buf),
5514 "iwpriv %s cwmenable 0", intf);
5515 if (system(buf) != 0) {
5516 sigma_dut_print(dut, DUT_MSG_ERROR,
5517 "iwpriv cwmenable 0 failed");
5518 return 0;
5519 }
5520 } else {
5521 sigma_dut_print(dut, DUT_MSG_ERROR,
5522 "Unsupported DYN_BW_SGL");
5523 }
5524
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005525 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
5526 if (system(buf) != 0) {
5527 sigma_dut_print(dut, DUT_MSG_ERROR,
5528 "Failed to set cts_cbw in DYN_BW_SGNL");
5529 return 0;
5530 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005531 break;
5532 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005533 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005534 ath_config_dyn_bw_sig(dut, intf, val);
5535 break;
5536 default:
5537 sigma_dut_print(dut, DUT_MSG_ERROR,
5538 "Failed to set DYN_BW_SGNL");
5539 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005540 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005541 }
5542
5543 val = get_param(cmd, "RTS_FORCE");
5544 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005545 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005546 if (strcasecmp(val, "Enable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305547 if (sta_set_rts(dut, intf, 64) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005548 sigma_dut_print(dut, DUT_MSG_ERROR,
5549 "Failed to set RTS_FORCE 64");
5550 }
Jouni Malinen3aa72862019-05-29 23:14:51 +03005551 res = snprintf(buf, sizeof(buf),
5552 "wifitool %s beeliner_fw_test 100 1",
5553 intf);
5554 if (res < 0 || res >= sizeof(buf) || system(buf) != 0) {
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005555 sigma_dut_print(dut, DUT_MSG_ERROR,
5556 "wifitool beeliner_fw_test 100 1 failed");
5557 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005558 } else if (strcasecmp(val, "Disable") == 0) {
Veerendranath Jakkamadcd6202019-04-17 12:32:21 +05305559 if (sta_set_rts(dut, intf, 2347) != 0) {
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005560 sigma_dut_print(dut, DUT_MSG_ERROR,
5561 "Failed to set RTS_FORCE 2347");
5562 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005563 } else {
5564 send_resp(dut, conn, SIGMA_ERROR,
5565 "ErrorCode,RTS_FORCE value not supported");
5566 return 0;
5567 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005568 }
5569
5570 val = get_param(cmd, "CTS_WIDTH");
5571 if (val) {
5572 switch (get_driver_type()) {
5573 case DRIVER_WCN:
5574 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5575 send_resp(dut, conn, SIGMA_ERROR,
5576 "ErrorCode,Failed to set CTS_WIDTH");
5577 return 0;
5578 }
5579 break;
5580 case DRIVER_ATHEROS:
5581 ath_set_cts_width(dut, intf, val);
5582 break;
5583 default:
5584 sigma_dut_print(dut, DUT_MSG_ERROR,
5585 "Setting CTS_WIDTH not supported");
5586 break;
5587 }
5588 }
5589
5590 val = get_param(cmd, "BW_SGNL");
5591 if (val) {
5592 if (strcasecmp(val, "Enable") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07005593 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005594 } else if (strcasecmp(val, "Disable") == 0) {
5595 /* TODO: Disable */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005596 } else {
5597 send_resp(dut, conn, SIGMA_ERROR,
5598 "ErrorCode,BW_SGNL value not supported");
5599 return 0;
5600 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005601 }
5602
5603 val = get_param(cmd, "Band");
5604 if (val) {
5605 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5606 /* STA supports all bands by default */
5607 } else {
5608 send_resp(dut, conn, SIGMA_ERROR,
5609 "ErrorCode,Unsupported Band");
5610 return 0;
5611 }
5612 }
5613
5614 val = get_param(cmd, "zero_crc");
5615 if (val) {
5616 switch (get_driver_type()) {
5617 case DRIVER_ATHEROS:
5618 ath_set_zero_crc(dut, val);
5619 break;
5620 default:
5621 break;
5622 }
5623 }
5624
5625 return 1;
5626}
5627
5628
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005629static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5630{
5631 switch (get_driver_type()) {
5632#ifdef __linux__
5633 case DRIVER_WIL6210:
5634 return wil6210_set_force_mcs(dut, force, mcs);
5635#endif /* __linux__ */
5636 default:
5637 sigma_dut_print(dut, DUT_MSG_ERROR,
5638 "Unsupported sta_set_force_mcs with the current driver");
5639 return -1;
5640 }
5641}
5642
5643
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005644static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5645{
5646 switch (get_driver_type()) {
5647#ifdef __linux__
5648 case DRIVER_WIL6210:
5649 return wil6210_force_rsn_ie(dut, state);
5650#endif /* __linux__ */
5651 default:
5652 sigma_dut_print(dut, DUT_MSG_ERROR,
5653 "Unsupported sta_60g_force_rsn_ie with the current driver");
5654 return -1;
5655 }
5656}
5657
5658
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005659static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5660 struct sigma_cmd *cmd)
5661{
5662 const char *val;
5663 char buf[100];
5664
5665 val = get_param(cmd, "MSDUSize");
5666 if (val) {
5667 int mtu;
5668
5669 dut->amsdu_size = atoi(val);
5670 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5671 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5672 sigma_dut_print(dut, DUT_MSG_ERROR,
5673 "MSDUSize %d is above max %d or below min %d",
5674 dut->amsdu_size,
5675 IEEE80211_MAX_DATA_LEN_DMG,
5676 IEEE80211_SNAP_LEN_DMG);
5677 dut->amsdu_size = 0;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005678 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005679 }
5680
5681 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5682 sigma_dut_print(dut, DUT_MSG_DEBUG,
5683 "Setting amsdu_size to %d", mtu);
5684 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
5685 get_station_ifname(), mtu);
5686
5687 if (system(buf) != 0) {
5688 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5689 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005690 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005691 }
5692 }
5693
5694 val = get_param(cmd, "BAckRcvBuf");
5695 if (val) {
5696 dut->back_rcv_buf = atoi(val);
5697 if (dut->back_rcv_buf == 0) {
5698 sigma_dut_print(dut, DUT_MSG_ERROR,
5699 "Failed to convert %s or value is 0",
5700 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005701 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005702 }
5703
5704 sigma_dut_print(dut, DUT_MSG_DEBUG,
5705 "Setting BAckRcvBuf to %s", val);
5706 }
5707
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005708 val = get_param(cmd, "MCS_FixedRate");
5709 if (val) {
5710 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5711 sigma_dut_print(dut, DUT_MSG_ERROR,
5712 "Failed to force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005713 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005714 }
5715 }
5716
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005717 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005718}
5719
5720
5721static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5722 struct sigma_cmd *cmd)
5723{
5724 int net_id;
5725 char *ifname;
5726 const char *val;
5727 char buf[100];
5728
5729 dut->mode = SIGMA_MODE_STATION;
5730 ifname = get_main_ifname();
5731 if (wpa_command(ifname, "PING") != 0) {
5732 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005733 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005734 }
5735
5736 wpa_command(ifname, "FLUSH");
5737 net_id = add_network_common(dut, conn, ifname, cmd);
5738 if (net_id < 0) {
5739 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5740 return net_id;
5741 }
5742
5743 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5744 if (set_network(ifname, net_id, "mode", "2") < 0) {
5745 sigma_dut_print(dut, DUT_MSG_ERROR,
5746 "Failed to set supplicant network mode");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005747 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005748 }
5749
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005750 if (set_network(ifname, net_id, "pbss", "1") < 0)
5751 return -2;
5752
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005753 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005754 "Supplicant set network with mode 2. network_id %d",
5755 net_id);
5756
5757 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5758 sigma_dut_print(dut, DUT_MSG_INFO,
5759 "Failed to set supplicant to WPS ENABLE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005760 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005761 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005762
5763 val = get_param(cmd, "Security");
5764 if (val && strcasecmp(val, "OPEN") == 0) {
5765 dut->ap_key_mgmt = AP_OPEN;
5766 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5767 sigma_dut_print(dut, DUT_MSG_ERROR,
5768 "Failed to set supplicant to %s security",
5769 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005770 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005771 }
5772 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5773 dut->ap_key_mgmt = AP_WPA2_PSK;
5774 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5775 sigma_dut_print(dut, DUT_MSG_ERROR,
5776 "Failed to set supplicant to %s security",
5777 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005778 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005779 }
5780
5781 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5782 sigma_dut_print(dut, DUT_MSG_ERROR,
5783 "Failed to set supplicant to proto RSN");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005784 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005785 }
5786 } else if (val) {
5787 sigma_dut_print(dut, DUT_MSG_ERROR,
5788 "Requested Security %s is not supported on 60GHz",
5789 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005790 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005791 }
5792
5793 val = get_param(cmd, "Encrypt");
5794 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5795 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5796 sigma_dut_print(dut, DUT_MSG_ERROR,
5797 "Failed to set supplicant to pairwise GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005798 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005799 }
5800 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5801 sigma_dut_print(dut, DUT_MSG_ERROR,
5802 "Failed to set supplicant to group GCMP");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005803 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005804 }
5805 } else if (val) {
5806 sigma_dut_print(dut, DUT_MSG_ERROR,
5807 "Requested Encrypt %s is not supported on 60 GHz",
5808 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005809 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005810 }
5811
5812 val = get_param(cmd, "PSK");
5813 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5814 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5815 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005816 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005817 }
5818
5819 /* Convert 60G channel to freq */
5820 switch (dut->ap_channel) {
5821 case 1:
5822 val = "58320";
5823 break;
5824 case 2:
5825 val = "60480";
5826 break;
5827 case 3:
5828 val = "62640";
5829 break;
5830 default:
5831 sigma_dut_print(dut, DUT_MSG_ERROR,
5832 "Failed to configure channel %d. Not supported",
5833 dut->ap_channel);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005834 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005835 }
5836
5837 if (set_network(ifname, net_id, "frequency", val) < 0) {
5838 sigma_dut_print(dut, DUT_MSG_ERROR,
5839 "Failed to set supplicant network frequency");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005840 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005841 }
5842
Alexei Avshalom Lazar2eccf4d2019-01-31 10:03:59 +02005843 if (dut->eap_fragment) {
5844 sigma_dut_print(dut, DUT_MSG_DEBUG,
5845 "Set EAP fragment size to 128 bytes.");
5846 if (set_network(ifname, net_id, "fragment_size", "128") < 0)
5847 return ERROR_SEND_STATUS;
5848 }
5849
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005850 sigma_dut_print(dut, DUT_MSG_DEBUG,
5851 "Supplicant set network with frequency");
5852
5853 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5854 if (wpa_command(ifname, buf) < 0) {
5855 sigma_dut_print(dut, DUT_MSG_INFO,
5856 "Failed to select network id %d on %s",
5857 net_id, ifname);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005858 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005859 }
5860
5861 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5862
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005863 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005864}
5865
5866
Lior David67543f52017-01-03 19:04:22 +02005867static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5868{
5869 char buf[128], fname[128];
5870 FILE *f;
Jouni Malinen3aa72862019-05-29 23:14:51 +03005871 int res;
Lior David67543f52017-01-03 19:04:22 +02005872
5873 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5874 sigma_dut_print(dut, DUT_MSG_ERROR,
5875 "failed to get wil6210 debugfs dir");
5876 return -1;
5877 }
5878
Jouni Malinen3aa72862019-05-29 23:14:51 +03005879 res = snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5880 if (res < 0 || res >= sizeof(fname))
5881 return -1;
Lior David67543f52017-01-03 19:04:22 +02005882 f = fopen(fname, "w");
5883 if (!f) {
5884 sigma_dut_print(dut, DUT_MSG_ERROR,
5885 "failed to open: %s", fname);
5886 return -1;
5887 }
5888
5889 fprintf(f, "%d\n", abft_len);
5890 fclose(f);
5891
5892 return 0;
5893}
5894
5895
Alexei Avshalom Lazar49498b82019-01-31 15:16:32 +02005896int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5897 int abft_len)
Lior David67543f52017-01-03 19:04:22 +02005898{
5899 switch (get_driver_type()) {
5900 case DRIVER_WIL6210:
5901 return wil6210_set_abft_len(dut, abft_len);
5902 default:
5903 sigma_dut_print(dut, DUT_MSG_ERROR,
5904 "set abft_len not supported");
5905 return -1;
5906 }
5907}
5908
5909
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005910static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5911 struct sigma_cmd *cmd)
5912{
5913 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005914 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005915
5916 if (dut->dev_role != DEVROLE_PCP) {
5917 send_resp(dut, conn, SIGMA_INVALID,
5918 "ErrorCode,Invalid DevRole");
5919 return 0;
5920 }
5921
5922 val = get_param(cmd, "SSID");
5923 if (val) {
5924 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5925 send_resp(dut, conn, SIGMA_INVALID,
5926 "ErrorCode,Invalid SSID");
5927 return -1;
5928 }
5929
Peng Xub8fc5cc2017-05-10 17:27:28 -07005930 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005931 }
5932
5933 val = get_param(cmd, "CHANNEL");
5934 if (val) {
5935 const char *pos;
5936
5937 dut->ap_channel = atoi(val);
5938 pos = strchr(val, ';');
5939 if (pos) {
5940 pos++;
5941 dut->ap_channel_1 = atoi(pos);
5942 }
5943 }
5944
5945 switch (dut->ap_channel) {
5946 case 1:
5947 case 2:
5948 case 3:
5949 break;
5950 default:
5951 sigma_dut_print(dut, DUT_MSG_ERROR,
5952 "Channel %d is not supported", dut->ap_channel);
5953 send_resp(dut, conn, SIGMA_ERROR,
5954 "Requested channel is not supported");
5955 return -1;
5956 }
5957
5958 val = get_param(cmd, "BCNINT");
5959 if (val)
5960 dut->ap_bcnint = atoi(val);
5961
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005962 val = get_param(cmd, "AllocType");
5963 if (val) {
5964 send_resp(dut, conn, SIGMA_ERROR,
5965 "ErrorCode,AllocType is not supported yet");
5966 return -1;
5967 }
5968
5969 val = get_param(cmd, "PercentBI");
5970 if (val) {
5971 send_resp(dut, conn, SIGMA_ERROR,
5972 "ErrorCode,PercentBI is not supported yet");
5973 return -1;
5974 }
5975
5976 val = get_param(cmd, "CBAPOnly");
5977 if (val) {
5978 send_resp(dut, conn, SIGMA_ERROR,
5979 "ErrorCode,CBAPOnly is not supported yet");
5980 return -1;
5981 }
5982
5983 val = get_param(cmd, "AMPDU");
5984 if (val) {
5985 if (strcasecmp(val, "Enable") == 0)
5986 dut->ap_ampdu = 1;
5987 else if (strcasecmp(val, "Disable") == 0)
5988 dut->ap_ampdu = 2;
5989 else {
5990 send_resp(dut, conn, SIGMA_ERROR,
5991 "ErrorCode,AMPDU value is not Enable nor Disabled");
5992 return -1;
5993 }
5994 }
5995
5996 val = get_param(cmd, "AMSDU");
5997 if (val) {
5998 if (strcasecmp(val, "Enable") == 0)
5999 dut->ap_amsdu = 1;
6000 else if (strcasecmp(val, "Disable") == 0)
6001 dut->ap_amsdu = 2;
6002 }
6003
6004 val = get_param(cmd, "NumMSDU");
6005 if (val) {
6006 send_resp(dut, conn, SIGMA_ERROR,
6007 "ErrorCode, NumMSDU is not supported yet");
6008 return -1;
6009 }
6010
6011 val = get_param(cmd, "ABFTLRang");
6012 if (val) {
6013 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02006014 "ABFTLRang parameter %s", val);
6015 if (strcmp(val, "Gt1") == 0)
6016 abft_len = 2; /* 2 slots in this case */
6017 }
6018
6019 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
6020 send_resp(dut, conn, SIGMA_ERROR,
6021 "ErrorCode, Can't set ABFT length");
6022 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006023 }
6024
6025 if (sta_pcp_start(dut, conn, cmd) < 0) {
6026 send_resp(dut, conn, SIGMA_ERROR,
6027 "ErrorCode, Can't start PCP role");
6028 return -1;
6029 }
6030
6031 return sta_set_60g_common(dut, conn, cmd);
6032}
6033
6034
6035static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
6036 struct sigma_cmd *cmd)
6037{
6038 const char *val = get_param(cmd, "DiscoveryMode");
6039
6040 if (dut->dev_role != DEVROLE_STA) {
6041 send_resp(dut, conn, SIGMA_INVALID,
6042 "ErrorCode,Invalid DevRole");
6043 return 0;
6044 }
6045
6046 if (val) {
6047 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
6048 /* Ignore Discovery mode till Driver expose API. */
6049#if 0
6050 if (strcasecmp(val, "1") == 0) {
6051 send_resp(dut, conn, SIGMA_INVALID,
6052 "ErrorCode,DiscoveryMode 1 not supported");
6053 return 0;
6054 }
6055
6056 if (strcasecmp(val, "0") == 0) {
6057 /* OK */
6058 } else {
6059 send_resp(dut, conn, SIGMA_INVALID,
6060 "ErrorCode,DiscoveryMode not supported");
6061 return 0;
6062 }
6063#endif
6064 }
6065
6066 if (start_sta_mode(dut) != 0)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02006067 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006068 return sta_set_60g_common(dut, conn, cmd);
6069}
6070
6071
6072static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
6073 struct sigma_cmd *cmd)
6074{
6075 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02006076 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05306077
Jouni Malinened77e672018-01-10 16:45:13 +02006078 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08006079 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02006080 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05306081 wpa_command(intf, "DISCONNECT");
6082 return 1;
6083 }
6084
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006085 disconnect_station(dut);
6086 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
6087 * due to cached results. */
6088 wpa_command(intf, "SET ignore_old_scan_res 1");
6089 wpa_command(intf, "BSS_FLUSH");
6090 return 1;
6091}
6092
6093
6094static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
6095 struct sigma_cmd *cmd)
6096{
6097 const char *intf = get_param(cmd, "Interface");
6098 const char *bssid = get_param(cmd, "bssid");
6099 const char *val = get_param(cmd, "CHANNEL");
6100 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306101 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05306102 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006103 int res;
6104 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05306105 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05306106 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006107
6108 if (bssid == NULL) {
6109 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
6110 "argument");
6111 return 0;
6112 }
6113
6114 if (val)
6115 chan = atoi(val);
6116
6117 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
6118 /* The current network may be from sta_associate or
6119 * sta_hs2_associate
6120 */
6121 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
6122 0 ||
6123 set_network(intf, 0, "bssid", bssid) < 0)
6124 return -2;
6125 }
6126
6127 ctrl = open_wpa_mon(intf);
6128 if (ctrl == NULL) {
6129 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6130 "wpa_supplicant monitor connection");
6131 return -1;
6132 }
6133
Sunil Duttd30ce092018-01-11 23:56:29 +05306134 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
6135 sizeof(result)) < 0 ||
6136 strncmp(result, "COMPLETED", 9) != 0) {
6137 sigma_dut_print(dut, DUT_MSG_DEBUG,
6138 "sta_reassoc: Not connected");
6139 fastreassoc = 0;
6140 }
6141
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05306142 if (dut->rsne_override) {
6143#ifdef NL80211_SUPPORT
6144 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
6145 sta_config_rsnie(dut, 1);
6146 dut->config_rsnie = 1;
6147 }
6148#endif /* NL80211_SUPPORT */
6149 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
6150 dut->rsne_override);
6151 if (wpa_command(intf, buf) < 0) {
6152 send_resp(dut, conn, SIGMA_ERROR,
6153 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
6154 return 0;
6155 }
6156 }
6157
Sunil Duttd30ce092018-01-11 23:56:29 +05306158 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006159#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306160 if (chan) {
6161 unsigned int freq;
6162
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02006163 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05306164 if (!freq) {
6165 sigma_dut_print(dut, DUT_MSG_ERROR,
6166 "Invalid channel number provided: %d",
6167 chan);
6168 send_resp(dut, conn, SIGMA_INVALID,
6169 "ErrorCode,Invalid channel number");
6170 goto close_mon_conn;
6171 }
6172 res = snprintf(buf, sizeof(buf),
6173 "SCAN TYPE=ONLY freq=%d", freq);
6174 } else {
6175 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
6176 }
6177 if (res < 0 || res >= (int) sizeof(buf)) {
6178 send_resp(dut, conn, SIGMA_ERROR,
6179 "ErrorCode,snprintf failed");
6180 goto close_mon_conn;
6181 }
6182 if (wpa_command(intf, buf) < 0) {
6183 sigma_dut_print(dut, DUT_MSG_INFO,
6184 "Failed to start scan");
6185 send_resp(dut, conn, SIGMA_ERROR,
6186 "ErrorCode,scan failed");
6187 goto close_mon_conn;
6188 }
6189
6190 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6191 buf, sizeof(buf));
6192 if (res < 0) {
6193 sigma_dut_print(dut, DUT_MSG_INFO,
6194 "Scan did not complete");
6195 send_resp(dut, conn, SIGMA_ERROR,
6196 "ErrorCode,scan did not complete");
6197 goto close_mon_conn;
6198 }
6199
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006200 if (set_network(intf, dut->infra_network_id, "bssid", "any")
6201 < 0) {
6202 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6203 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306204 status = -2;
6205 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006206 }
6207 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
6208 bssid, chan);
6209 if (res > 0 && res < (int) sizeof(buf))
6210 res = wpa_command(intf, buf);
6211
6212 if (res < 0 || res >= (int) sizeof(buf)) {
6213 send_resp(dut, conn, SIGMA_ERROR,
6214 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05306215 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006216 }
6217#else /* ANDROID */
6218 sigma_dut_print(dut, DUT_MSG_DEBUG,
6219 "Reassoc using iwpriv - skip chan=%d info",
6220 chan);
6221 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
6222 if (system(buf) != 0) {
6223 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05306224 status = -2;
6225 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006226 }
6227#endif /* ANDROID */
6228 sigma_dut_print(dut, DUT_MSG_INFO,
6229 "sta_reassoc: Run %s successful", buf);
6230 } else if (wpa_command(intf, "REASSOCIATE")) {
6231 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6232 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05306233 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006234 }
6235
6236 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
6237 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05306238 if (res < 0) {
6239 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
6240 status = -1;
6241 goto close_mon_conn;
6242 }
6243 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006244
Ashwini Patil467efef2017-05-25 12:18:27 +05306245close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006246 wpa_ctrl_detach(ctrl);
6247 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05306248 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006249}
6250
6251
6252static void hs2_clear_credentials(const char *intf)
6253{
6254 wpa_command(intf, "REMOVE_CRED all");
6255}
6256
6257
Lior Davidcc88b562017-01-03 18:52:09 +02006258#ifdef __linux__
6259static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
6260 unsigned int *aid)
6261{
Lior David0fe101e2017-03-09 16:09:50 +02006262 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02006263
Lior David0fe101e2017-03-09 16:09:50 +02006264 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02006265}
6266#endif /* __linux__ */
6267
6268
6269static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
6270 unsigned int *aid)
6271{
6272 switch (get_driver_type()) {
6273#ifdef __linux__
6274 case DRIVER_WIL6210:
6275 return wil6210_get_aid(dut, bssid, aid);
6276#endif /* __linux__ */
6277 default:
6278 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
6279 return -1;
6280 }
6281}
6282
6283
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006284static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6285 struct sigma_cmd *cmd)
6286{
6287 char buf[MAX_CMD_LEN];
6288 char bss_list[MAX_CMD_LEN];
6289 const char *parameter = get_param(cmd, "Parameter");
6290
6291 if (parameter == NULL)
6292 return -1;
6293
Lior Davidcc88b562017-01-03 18:52:09 +02006294 if (strcasecmp(parameter, "AID") == 0) {
6295 unsigned int aid = 0;
6296 char bssid[20];
6297
6298 if (get_wpa_status(get_station_ifname(), "bssid",
6299 bssid, sizeof(bssid)) < 0) {
6300 sigma_dut_print(dut, DUT_MSG_ERROR,
6301 "could not get bssid");
6302 return -2;
6303 }
6304
6305 if (sta_get_aid_60g(dut, bssid, &aid))
6306 return -2;
6307
6308 snprintf(buf, sizeof(buf), "aid,%d", aid);
6309 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
6310 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6311 return 0;
6312 }
6313
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006314 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
6315 char *bss_line;
6316 char *bss_id = NULL;
6317 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306318 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006319
6320 if (ifname == NULL) {
6321 sigma_dut_print(dut, DUT_MSG_INFO,
6322 "For get DiscoveredDevList need Interface name.");
6323 return -1;
6324 }
6325
6326 /*
6327 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
6328 * of BSSIDs in "bssid=<BSSID>\n"
6329 */
6330 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
6331 bss_list,
6332 sizeof(bss_list)) < 0) {
6333 sigma_dut_print(dut, DUT_MSG_ERROR,
6334 "Failed to get bss list");
6335 return -1;
6336 }
6337
6338 sigma_dut_print(dut, DUT_MSG_DEBUG,
6339 "bss list for ifname:%s is:%s",
6340 ifname, bss_list);
6341
6342 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306343 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006344 while (bss_line) {
6345 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
6346 bss_id) {
6347 int len;
6348
6349 len = snprintf(buf + strlen(buf),
6350 sizeof(buf) - strlen(buf),
6351 ",%s", bss_id);
6352 free(bss_id);
6353 bss_id = NULL;
6354 if (len < 0) {
6355 sigma_dut_print(dut,
6356 DUT_MSG_ERROR,
6357 "Failed to read BSSID");
6358 send_resp(dut, conn, SIGMA_ERROR,
6359 "ErrorCode,Failed to read BSS ID");
6360 return 0;
6361 }
6362
6363 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
6364 sigma_dut_print(dut,
6365 DUT_MSG_ERROR,
6366 "Response buf too small for list");
6367 send_resp(dut, conn,
6368 SIGMA_ERROR,
6369 "ErrorCode,Response buf too small for list");
6370 return 0;
6371 }
6372 }
6373
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05306374 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006375 }
6376
6377 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
6378 buf);
6379 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6380 return 0;
6381 }
6382
6383 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6384 return 0;
6385}
6386
6387
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006388static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
6389 struct sigma_cmd *cmd)
6390{
6391 char buf[MAX_CMD_LEN];
6392 const char *parameter = get_param(cmd, "Parameter");
6393
6394 if (!parameter)
6395 return -1;
6396
6397 if (strcasecmp(parameter, "RSSI") == 0) {
6398 char rssi[10];
6399
6400 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
6401 rssi, sizeof(rssi)) < 0) {
6402 sigma_dut_print(dut, DUT_MSG_ERROR,
6403 "Could not get RSSI");
6404 return -2;
6405 }
6406
6407 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
6408 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
6409 send_resp(dut, conn, SIGMA_COMPLETE, buf);
6410 return 0;
6411 }
6412
6413 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6414 return 0;
6415}
6416
6417
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006418static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
6419 struct sigma_cmd *cmd)
6420{
6421 const char *program = get_param(cmd, "Program");
6422
6423 if (program == NULL)
6424 return -1;
6425
6426 if (strcasecmp(program, "P2PNFC") == 0)
6427 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
6428
6429 if (strcasecmp(program, "60ghz") == 0)
6430 return sta_get_parameter_60g(dut, conn, cmd);
6431
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07006432 if (strcasecmp(program, "he") == 0)
6433 return sta_get_parameter_he(dut, conn, cmd);
6434
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006435#ifdef ANDROID_NAN
6436 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07006437 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006438#endif /* ANDROID_NAN */
6439
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006440#ifdef MIRACAST
6441 if (strcasecmp(program, "WFD") == 0 ||
6442 strcasecmp(program, "DisplayR2") == 0)
6443 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
6444#endif /* MIRACAST */
6445
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006446 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6447 return 0;
6448}
6449
6450
6451static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
6452 const char *type)
6453{
6454 char buf[100];
6455
6456 if (dut->program == PROGRAM_VHT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006457 run_iwpriv(dut, intf, "chwidth 2");
6458 run_iwpriv(dut, intf, "mode 11ACVHT80");
6459 run_iwpriv(dut, intf, "vhtmcs -1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006460 }
6461
6462 if (dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006463 run_iwpriv(dut, intf, "chwidth 0");
6464 run_iwpriv(dut, intf, "mode 11naht40");
6465 run_iwpriv(dut, intf, "set11NRates 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006466 }
6467
6468 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006469 run_iwpriv(dut, intf, "powersave 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006470
6471 /* Reset CTS width */
6472 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
6473 intf);
6474 if (system(buf) != 0) {
6475 sigma_dut_print(dut, DUT_MSG_ERROR,
6476 "wifitool %s beeliner_fw_test 54 0 failed",
6477 intf);
6478 }
6479
6480 /* Enable Dynamic Bandwidth signalling by default */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006481 run_iwpriv(dut, intf, "cwmenable 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006482
6483 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
6484 if (system(buf) != 0) {
6485 sigma_dut_print(dut, DUT_MSG_ERROR,
6486 "iwpriv rts failed");
6487 }
6488 }
6489
6490 if (type && strcasecmp(type, "Testbed") == 0) {
6491 dut->testbed_flag_txsp = 1;
6492 dut->testbed_flag_rxsp = 1;
6493 /* STA has to set spatial stream to 2 per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006494 run_iwpriv(dut, intf, "vht_mcsmap 0xfff0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006495
6496 /* Disable LDPC per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006497 run_iwpriv(dut, intf, "ldpc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006498
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006499 run_iwpriv(dut, intf, "amsdu 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006500
6501 /* TODO: Disable STBC 2x1 transmit and receive */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006502 run_iwpriv(dut, intf, "tx_stbc 0");
6503 run_iwpriv(dut, intf, "rx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006504
6505 /* STA has to disable Short GI per Appendix H */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006506 run_iwpriv(dut, intf, "shortgi 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006507 }
6508
6509 if (type && strcasecmp(type, "DUT") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006510 run_iwpriv(dut, intf, "nss 3");
Arif Hussainac6c5112018-05-25 17:34:00 -07006511 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006512
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07006513 run_iwpriv(dut, intf, "shortgi 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006514 }
6515}
6516
6517
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006518#ifdef NL80211_SUPPORT
6519static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6520 enum he_mcs_config mcs)
6521{
6522 struct nl_msg *msg;
6523 int ret = 0;
6524 struct nlattr *params;
6525 int ifindex;
6526
6527 ifindex = if_nametoindex(intf);
6528 if (ifindex == 0) {
6529 sigma_dut_print(dut, DUT_MSG_ERROR,
6530 "%s: Index for interface %s failed",
6531 __func__, intf);
6532 return -1;
6533 }
6534
6535 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6536 NL80211_CMD_VENDOR)) ||
6537 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6538 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6539 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6540 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6541 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6542 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6543 mcs)) {
6544 sigma_dut_print(dut, DUT_MSG_ERROR,
6545 "%s: err in adding vendor_cmd and vendor_data",
6546 __func__);
6547 nlmsg_free(msg);
6548 return -1;
6549 }
6550 nla_nest_end(msg, params);
6551
6552 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6553 if (ret) {
6554 sigma_dut_print(dut, DUT_MSG_ERROR,
6555 "%s: err in send_and_recv_msgs, ret=%d",
6556 __func__, ret);
6557 }
6558 return ret;
6559}
6560#endif /* NL80211_SUPPORT */
6561
6562
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006563static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6564 const char *intf, int enable)
6565{
6566#ifdef NL80211_SUPPORT
6567 struct nl_msg *msg;
6568 int ret = 0;
6569 struct nlattr *params;
6570 int ifindex;
6571
6572 ifindex = if_nametoindex(intf);
6573 if (ifindex == 0) {
6574 sigma_dut_print(dut, DUT_MSG_ERROR,
6575 "%s: Index for interface %s failed",
6576 __func__, intf);
6577 return -1;
6578 }
6579
6580 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6581 NL80211_CMD_VENDOR)) ||
6582 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6583 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6584 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6585 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6586 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6587 nla_put_u8(msg,
6588 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6589 enable)) {
6590 sigma_dut_print(dut, DUT_MSG_ERROR,
6591 "%s: err in adding vendor_cmd and vendor_data",
6592 __func__);
6593 nlmsg_free(msg);
6594 return -1;
6595 }
6596 nla_nest_end(msg, params);
6597
6598 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6599 if (ret) {
6600 sigma_dut_print(dut, DUT_MSG_ERROR,
6601 "%s: err in send_and_recv_msgs, ret=%d",
6602 __func__, ret);
6603 }
6604 return ret;
6605#else /* NL80211_SUPPORT */
6606 sigma_dut_print(dut, DUT_MSG_ERROR,
6607 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6608 return -1;
6609#endif /* NL80211_SUPPORT */
6610}
6611
6612
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006613static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6614 const char *intf, int enable)
6615{
6616#ifdef NL80211_SUPPORT
6617 struct nl_msg *msg;
6618 int ret = 0;
6619 struct nlattr *params;
6620 int ifindex;
6621
6622 ifindex = if_nametoindex(intf);
6623 if (ifindex == 0) {
6624 sigma_dut_print(dut, DUT_MSG_ERROR,
6625 "%s: Index for interface %s failed",
6626 __func__, intf);
6627 return -1;
6628 }
6629
6630 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6631 NL80211_CMD_VENDOR)) ||
6632 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6633 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6634 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6635 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6636 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6637 nla_put_u8(msg,
6638 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6639 enable)) {
6640 sigma_dut_print(dut, DUT_MSG_ERROR,
6641 "%s: err in adding vendor_cmd and vendor_data",
6642 __func__);
6643 nlmsg_free(msg);
6644 return -1;
6645 }
6646 nla_nest_end(msg, params);
6647
6648 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6649 if (ret) {
6650 sigma_dut_print(dut, DUT_MSG_ERROR,
6651 "%s: err in send_and_recv_msgs, ret=%d",
6652 __func__, ret);
6653 }
6654 return ret;
6655#else /* NL80211_SUPPORT */
6656 sigma_dut_print(dut, DUT_MSG_ERROR,
6657 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6658 return -1;
6659#endif /* NL80211_SUPPORT */
6660}
6661
6662
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006663#ifdef NL80211_SUPPORT
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006664
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006665static int sta_set_he_testbed_def(struct sigma_dut *dut,
6666 const char *intf, int cfg)
6667{
6668 struct nl_msg *msg;
6669 int ret = 0;
6670 struct nlattr *params;
6671 int ifindex;
6672
6673 ifindex = if_nametoindex(intf);
6674 if (ifindex == 0) {
6675 sigma_dut_print(dut, DUT_MSG_ERROR,
6676 "%s: Index for interface %s failed",
6677 __func__, intf);
6678 return -1;
6679 }
6680
6681 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6682 NL80211_CMD_VENDOR)) ||
6683 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6684 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6685 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6686 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6687 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6688 nla_put_u8(msg,
6689 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SET_HE_TESTBED_DEFAULTS,
6690 cfg)) {
6691 sigma_dut_print(dut, DUT_MSG_ERROR,
6692 "%s: err in adding vendor_cmd and vendor_data",
6693 __func__);
6694 nlmsg_free(msg);
6695 return -1;
6696 }
6697 nla_nest_end(msg, params);
6698
6699 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6700 if (ret) {
6701 sigma_dut_print(dut, DUT_MSG_ERROR,
6702 "%s: err in send_and_recv_msgs, ret=%d",
6703 __func__, ret);
6704 }
6705 return ret;
6706}
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08006707
6708
6709static int sta_set_2g_vht_supp(struct sigma_dut *dut, const char *intf, int cfg)
6710{
6711 struct nl_msg *msg;
6712 int ret = 0;
6713 struct nlattr *params;
6714 int ifindex;
6715
6716 ifindex = if_nametoindex(intf);
6717 if (ifindex == 0) {
6718 sigma_dut_print(dut, DUT_MSG_ERROR,
6719 "%s: Index for interface %s failed",
6720 __func__, intf);
6721 return -1;
6722 }
6723
6724 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6725 NL80211_CMD_VENDOR)) ||
6726 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6727 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6728 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6729 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6730 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6731 nla_put_u8(msg,
6732 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_2G_VHT,
6733 cfg)) {
6734 sigma_dut_print(dut, DUT_MSG_ERROR,
6735 "%s: err in adding vendor_cmd and vendor_data",
6736 __func__);
6737 nlmsg_free(msg);
6738 return -1;
6739 }
6740 nla_nest_end(msg, params);
6741
6742 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6743 if (ret) {
6744 sigma_dut_print(dut, DUT_MSG_ERROR,
6745 "%s: err in send_and_recv_msgs, ret=%d",
6746 __func__, ret);
6747 }
6748 return ret;
6749}
6750
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08006751#endif /* NL80211_SUPPORT */
6752
6753
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006754static int sta_set_addba_buf_size(struct sigma_dut *dut,
6755 const char *intf, int bufsize)
6756{
6757#ifdef NL80211_SUPPORT
6758 struct nl_msg *msg;
6759 int ret = 0;
6760 struct nlattr *params;
6761 int ifindex;
6762
6763 ifindex = if_nametoindex(intf);
6764 if (ifindex == 0) {
6765 sigma_dut_print(dut, DUT_MSG_ERROR,
6766 "%s: Index for interface %s failed",
6767 __func__, intf);
6768 return -1;
6769 }
6770
6771 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6772 NL80211_CMD_VENDOR)) ||
6773 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6774 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6775 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6776 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6777 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006778 nla_put_u16(msg,
6779 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6780 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006781 sigma_dut_print(dut, DUT_MSG_ERROR,
6782 "%s: err in adding vendor_cmd and vendor_data",
6783 __func__);
6784 nlmsg_free(msg);
6785 return -1;
6786 }
6787 nla_nest_end(msg, params);
6788
6789 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6790 if (ret) {
6791 sigma_dut_print(dut, DUT_MSG_ERROR,
6792 "%s: err in send_and_recv_msgs, ret=%d",
6793 __func__, ret);
6794 }
6795 return ret;
6796#else /* NL80211_SUPPORT */
6797 sigma_dut_print(dut, DUT_MSG_ERROR,
6798 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6799 return -1;
6800#endif /* NL80211_SUPPORT */
6801}
6802
6803
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006804static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6805 int enable)
6806{
6807#ifdef NL80211_SUPPORT
6808 struct nl_msg *msg;
6809 int ret = 0;
6810 struct nlattr *params;
6811 int ifindex;
6812
6813 ifindex = if_nametoindex(intf);
6814 if (ifindex == 0) {
6815 sigma_dut_print(dut, DUT_MSG_ERROR,
6816 "%s: Index for interface %s failed",
6817 __func__, intf);
6818 return -1;
6819 }
6820
6821 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6822 NL80211_CMD_VENDOR)) ||
6823 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6824 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6825 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6826 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6827 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6828 nla_put_u8(msg,
6829 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
6830 enable)) {
6831 sigma_dut_print(dut, DUT_MSG_ERROR,
6832 "%s: err in adding vendor_cmd and vendor_data",
6833 __func__);
6834 nlmsg_free(msg);
6835 return -1;
6836 }
6837 nla_nest_end(msg, params);
6838
6839 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6840 if (ret) {
6841 sigma_dut_print(dut, DUT_MSG_ERROR,
6842 "%s: err in send_and_recv_msgs, ret=%d",
6843 __func__, ret);
6844 }
6845 return ret;
6846#else /* NL80211_SUPPORT */
6847 sigma_dut_print(dut, DUT_MSG_ERROR,
6848 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
6849 return -1;
6850#endif /* NL80211_SUPPORT */
6851}
6852
6853
Arif Hussain9765f7d2018-07-03 08:28:26 -07006854static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
6855 int val)
6856{
6857#ifdef NL80211_SUPPORT
6858 struct nl_msg *msg;
6859 int ret = 0;
6860 struct nlattr *params;
6861 int ifindex;
6862
6863 ifindex = if_nametoindex(intf);
6864 if (ifindex == 0) {
6865 sigma_dut_print(dut, DUT_MSG_ERROR,
6866 "%s: Index for interface %s failed, val:%d",
6867 __func__, intf, val);
6868 return -1;
6869 }
6870
6871 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6872 NL80211_CMD_VENDOR)) ||
6873 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6874 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6875 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6876 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6877 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6878 nla_put_u8(msg,
6879 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
6880 val)) {
6881 sigma_dut_print(dut, DUT_MSG_ERROR,
6882 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6883 __func__, val);
6884 nlmsg_free(msg);
6885 return -1;
6886 }
6887 nla_nest_end(msg, params);
6888
6889 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6890 if (ret) {
6891 sigma_dut_print(dut, DUT_MSG_ERROR,
6892 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6893 __func__, ret, val);
6894 }
6895 return ret;
6896#else /* NL80211_SUPPORT */
6897 sigma_dut_print(dut, DUT_MSG_ERROR,
6898 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
6899 return -1;
6900#endif /* NL80211_SUPPORT */
6901}
6902
6903
Arif Hussain68d23f52018-07-11 13:39:08 -07006904#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006905static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
6906 enum qca_wlan_he_mac_padding_dur val)
6907{
Arif Hussain68d23f52018-07-11 13:39:08 -07006908 struct nl_msg *msg;
6909 int ret = 0;
6910 struct nlattr *params;
6911 int ifindex;
6912
6913 ifindex = if_nametoindex(intf);
6914 if (ifindex == 0) {
6915 sigma_dut_print(dut, DUT_MSG_ERROR,
6916 "%s: Index for interface %s failed, val:%d",
6917 __func__, intf, val);
6918 return -1;
6919 }
6920
6921 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6922 NL80211_CMD_VENDOR)) ||
6923 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6924 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6925 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6926 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6927 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6928 nla_put_u8(msg,
6929 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
6930 val)) {
6931 sigma_dut_print(dut, DUT_MSG_ERROR,
6932 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6933 __func__, val);
6934 nlmsg_free(msg);
6935 return -1;
6936 }
6937 nla_nest_end(msg, params);
6938
6939 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6940 if (ret) {
6941 sigma_dut_print(dut, DUT_MSG_ERROR,
6942 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6943 __func__, ret, val);
6944 }
6945 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07006946}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006947#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07006948
6949
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006950static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
6951 int val)
6952{
6953#ifdef NL80211_SUPPORT
6954 struct nl_msg *msg;
6955 int ret = 0;
6956 struct nlattr *params;
6957 int ifindex;
6958
6959 ifindex = if_nametoindex(intf);
6960 if (ifindex == 0) {
6961 sigma_dut_print(dut, DUT_MSG_ERROR,
6962 "%s: Index for interface %s failed, val:%d",
6963 __func__, intf, val);
6964 return -1;
6965 }
6966
6967 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6968 NL80211_CMD_VENDOR)) ||
6969 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6970 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6971 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6972 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6973 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6974 nla_put_u8(msg,
6975 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
6976 val)) {
6977 sigma_dut_print(dut, DUT_MSG_ERROR,
6978 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6979 __func__, val);
6980 nlmsg_free(msg);
6981 return -1;
6982 }
6983 nla_nest_end(msg, params);
6984
6985 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6986 if (ret) {
6987 sigma_dut_print(dut, DUT_MSG_ERROR,
6988 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6989 __func__, ret, val);
6990 }
6991 return ret;
6992#else /* NL80211_SUPPORT */
6993 sigma_dut_print(dut, DUT_MSG_ERROR,
6994 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
6995 return -1;
6996#endif /* NL80211_SUPPORT */
6997}
6998
6999
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007000#ifdef NL80211_SUPPORT
7001static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
7002{
7003 struct nl_msg *msg;
7004 int ret = 0;
7005 struct nlattr *params;
7006 int ifindex;
7007
7008 ifindex = if_nametoindex(intf);
7009 if (ifindex == 0) {
7010 sigma_dut_print(dut, DUT_MSG_ERROR,
7011 "%s: Index for interface %s failed",
7012 __func__, intf);
7013 return -1;
7014 }
7015
7016 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7017 NL80211_CMD_VENDOR)) ||
7018 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7019 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7020 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7021 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7022 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7023 nla_put_flag(msg,
7024 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
7025 sigma_dut_print(dut, DUT_MSG_ERROR,
7026 "%s: err in adding vendor_cmd and vendor_data",
7027 __func__);
7028 nlmsg_free(msg);
7029 return -1;
7030 }
7031 nla_nest_end(msg, params);
7032
7033 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7034 if (ret) {
7035 sigma_dut_print(dut, DUT_MSG_ERROR,
7036 "%s: err in send_and_recv_msgs, ret=%d",
7037 __func__, ret);
7038 }
7039 return ret;
7040}
7041#endif /* NL80211_SUPPORT */
7042
7043
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007044static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
7045 int val)
7046{
7047#ifdef NL80211_SUPPORT
7048 struct nl_msg *msg;
7049 int ret = 0;
7050 struct nlattr *params;
7051 int ifindex;
7052
7053 ifindex = if_nametoindex(intf);
7054 if (ifindex == 0) {
7055 sigma_dut_print(dut, DUT_MSG_ERROR,
7056 "%s: Index for interface %s failed, val:%d",
7057 __func__, intf, val);
7058 return -1;
7059 }
7060
7061 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7062 NL80211_CMD_VENDOR)) ||
7063 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7064 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7065 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7066 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7067 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7068 nla_put_u8(msg,
7069 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
7070 val)) {
7071 sigma_dut_print(dut, DUT_MSG_ERROR,
7072 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7073 __func__, val);
7074 nlmsg_free(msg);
7075 return -1;
7076 }
7077 nla_nest_end(msg, params);
7078
7079 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7080 if (ret) {
7081 sigma_dut_print(dut, DUT_MSG_ERROR,
7082 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7083 __func__, ret, val);
7084 }
7085 return ret;
7086#else /* NL80211_SUPPORT */
7087 sigma_dut_print(dut, DUT_MSG_ERROR,
7088 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
7089 return -1;
7090#endif /* NL80211_SUPPORT */
7091}
7092
7093
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007094static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
7095 int val)
7096{
7097#ifdef NL80211_SUPPORT
7098 struct nl_msg *msg;
7099 int ret = 0;
7100 struct nlattr *params;
7101 int ifindex;
7102
7103 ifindex = if_nametoindex(intf);
7104 if (ifindex == 0) {
7105 sigma_dut_print(dut, DUT_MSG_ERROR,
7106 "%s: Index for interface %s failed, val:%d",
7107 __func__, intf, val);
7108 return -1;
7109 }
7110
7111 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7112 NL80211_CMD_VENDOR)) ||
7113 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7114 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7115 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7116 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7117 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7118 nla_put_u8(msg,
7119 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
7120 val)) {
7121 sigma_dut_print(dut, DUT_MSG_ERROR,
7122 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7123 __func__, val);
7124 nlmsg_free(msg);
7125 return -1;
7126 }
7127 nla_nest_end(msg, params);
7128
7129 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7130 if (ret) {
7131 sigma_dut_print(dut, DUT_MSG_ERROR,
7132 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7133 __func__, ret, val);
7134 }
7135 return ret;
7136#else /* NL80211_SUPPORT */
7137 sigma_dut_print(dut, DUT_MSG_ERROR,
7138 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
7139 return -1;
7140#endif /* NL80211_SUPPORT */
7141}
7142
7143
Arif Hussain480d5f42019-03-12 14:40:42 -07007144static int sta_set_twt_req_support(struct sigma_dut *dut, const char *intf,
7145 int val)
7146{
7147#ifdef NL80211_SUPPORT
7148 struct nl_msg *msg;
7149 int ret;
7150 struct nlattr *params;
7151 int ifindex;
7152
7153 ifindex = if_nametoindex(intf);
7154 if (ifindex == 0) {
7155 sigma_dut_print(dut, DUT_MSG_ERROR,
7156 "%s: Index for interface %s failed, val:%d",
7157 __func__, intf, val);
7158 return -1;
7159 }
7160
7161 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7162 NL80211_CMD_VENDOR)) ||
7163 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7164 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7165 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7166 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7167 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7168 nla_put_u8(msg,
7169 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TWT_REQ_SUPPORT,
7170 val)) {
7171 sigma_dut_print(dut, DUT_MSG_ERROR,
7172 "%s: err in adding vendor_cmd and vendor_data, val: %d",
7173 __func__, val);
7174 nlmsg_free(msg);
7175 return -1;
7176 }
7177 nla_nest_end(msg, params);
7178
7179 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7180 if (ret) {
7181 sigma_dut_print(dut, DUT_MSG_ERROR,
7182 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
7183 __func__, ret, val);
7184 }
7185 return ret;
7186#else /* NL80211_SUPPORT */
7187 sigma_dut_print(dut, DUT_MSG_ERROR,
7188 "TWT Request cannot be changed without NL80211_SUPPORT defined");
7189 return -1;
7190#endif /* NL80211_SUPPORT */
7191}
7192
7193
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007194static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
7195 const char *type)
7196{
7197 char buf[60];
7198
7199 if (dut->program == PROGRAM_HE) {
7200 /* resetting phymode to auto in case of HE program */
7201 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
7202 if (system(buf) != 0) {
7203 sigma_dut_print(dut, DUT_MSG_ERROR,
7204 "iwpriv %s setphymode failed", intf);
7205 }
7206
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07007207 /* reset the rate to Auto rate */
7208 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
7209 intf);
7210 if (system(buf) != 0) {
7211 sigma_dut_print(dut, DUT_MSG_ERROR,
7212 "iwpriv %s set_11ax_rate 0xff failed",
7213 intf);
7214 }
7215
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07007216 /* reset the LDPC setting */
7217 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
7218 if (system(buf) != 0) {
7219 sigma_dut_print(dut, DUT_MSG_ERROR,
7220 "iwpriv %s ldpc 1 failed", intf);
7221 }
7222
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08007223 /* reset the power save setting */
7224 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
7225 if (system(buf) != 0) {
7226 sigma_dut_print(dut, DUT_MSG_ERROR,
7227 "iwpriv %s setPower 2 failed", intf);
7228 }
7229
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007230 /* remove all network profiles */
7231 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007232
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08007233 /* Configure ADDBA Req/Rsp buffer size to be 64 */
7234 sta_set_addba_buf_size(dut, intf, 64);
7235
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007236#ifdef NL80211_SUPPORT
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007237 /* Reset the device HE capabilities to its default supported
7238 * configuration. */
7239 sta_set_he_testbed_def(dut, intf, 0);
7240
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08007241 /* Disable noackpolicy for all AC */
7242 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
7243 sigma_dut_print(dut, DUT_MSG_ERROR,
7244 "Disable of noackpolicy for all AC failed");
7245 }
7246#endif /* NL80211_SUPPORT */
7247
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08007248 /* Enable WMM by default */
7249 if (wcn_sta_set_wmm(dut, intf, "on")) {
7250 sigma_dut_print(dut, DUT_MSG_ERROR,
7251 "Enable of WMM in sta_reset_default_wcn failed");
7252 }
7253
7254 /* Disable ADDBA_REJECT by default */
7255 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
7256 sigma_dut_print(dut, DUT_MSG_ERROR,
7257 "Disable of addba_reject in sta_reset_default_wcn failed");
7258 }
7259
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08007260 /* Enable sending of ADDBA by default */
7261 if (nlvendor_config_send_addba(dut, intf, 1)) {
7262 sigma_dut_print(dut, DUT_MSG_ERROR,
7263 "Enable sending of ADDBA in sta_reset_default_wcn failed");
7264 }
7265
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08007266 /* Enable AMPDU by default */
7267 iwpriv_sta_set_ampdu(dut, intf, 1);
7268
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007269#ifdef NL80211_SUPPORT
7270 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
7271 sigma_dut_print(dut, DUT_MSG_ERROR,
7272 "Set LTF config to default in sta_reset_default_wcn failed");
7273 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07007274
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007275 /* set the beamformee NSTS(maximum number of
7276 * space-time streams) to default DUT config
7277 */
7278 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07007279 sigma_dut_print(dut, DUT_MSG_ERROR,
7280 "Failed to set BeamformeeSTS");
7281 }
Arif Hussain68d23f52018-07-11 13:39:08 -07007282
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007283 if (sta_set_mac_padding_duration(
7284 dut, intf,
7285 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007286 sigma_dut_print(dut, DUT_MSG_ERROR,
7287 "Failed to set MAC padding duration");
7288 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007289
7290 if (sta_set_mu_edca_override(dut, intf, 0)) {
7291 sigma_dut_print(dut, DUT_MSG_ERROR,
7292 "ErrorCode,Failed to set MU EDCA override disable");
7293 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007294
7295 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
7296 sigma_dut_print(dut, DUT_MSG_ERROR,
7297 "Failed to set OM ctrl supp");
7298 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07007299
7300 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
7301 sigma_dut_print(dut, DUT_MSG_ERROR,
7302 "Failed to set Tx SU PPDU enable");
7303 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007304
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07007305 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
7306 sigma_dut_print(dut, DUT_MSG_ERROR,
7307 "failed to send TB PPDU Tx cfg");
7308 }
7309
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07007310 if (sta_set_he_om_ctrl_reset(dut, intf)) {
7311 sigma_dut_print(dut, DUT_MSG_ERROR,
7312 "Failed to set OM ctrl reset");
7313 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007314
7315 /* +HTC-HE support default on */
7316 if (sta_set_he_htc_supp(dut, intf, 1)) {
7317 sigma_dut_print(dut, DUT_MSG_ERROR,
7318 "Setting of +HTC-HE support failed");
7319 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07007320#endif /* NL80211_SUPPORT */
7321
Arif Hussain8d5b27b2018-05-14 14:31:03 -07007322 if (sta_set_tx_beamformee(dut, intf, 1)) {
7323 sigma_dut_print(dut, DUT_MSG_ERROR,
7324 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
7325 }
7326
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007327 /* Set nss to 1 and MCS 0-7 in case of testbed */
7328 if (type && strcasecmp(type, "Testbed") == 0) {
7329#ifdef NL80211_SUPPORT
7330 int ret;
7331#endif /* NL80211_SUPPORT */
7332
7333 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
7334 if (system(buf) != 0) {
7335 sigma_dut_print(dut, DUT_MSG_ERROR,
7336 "iwpriv %s nss failed", intf);
7337 }
7338
7339#ifdef NL80211_SUPPORT
7340 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
7341 if (ret) {
7342 sigma_dut_print(dut, DUT_MSG_ERROR,
7343 "Setting of MCS failed, ret:%d",
7344 ret);
7345 }
7346#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08007347
7348 /* Disable STBC as default */
7349 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08007350
7351 /* Disable AMSDU as default */
7352 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007353
7354#ifdef NL80211_SUPPORT
7355 /* HE fragmentation default off */
7356 if (sta_set_he_fragmentation(dut, intf,
7357 HE_FRAG_DISABLE)) {
7358 sigma_dut_print(dut, DUT_MSG_ERROR,
7359 "Setting of HE fragmentation failed");
7360 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08007361
7362 /* set the beamformee NSTS(maximum number of
7363 * space-time streams) to default testbed config
7364 */
7365 if (sta_set_beamformee_sts(dut, intf, 3)) {
7366 sigma_dut_print(dut, DUT_MSG_ERROR,
7367 "Failed to set BeamformeeSTS");
7368 }
7369
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08007370 /* +HTC-HE support default off */
7371 if (sta_set_he_htc_supp(dut, intf, 0)) {
7372 sigma_dut_print(dut, DUT_MSG_ERROR,
7373 "Setting of +HTC-HE support failed");
7374 }
Kiran Kumar Lokere765bdd82019-02-24 22:14:43 -08007375
7376 /* Set device HE capabilities to testbed default
7377 * configuration. */
7378 if (sta_set_he_testbed_def(dut, intf, 1)) {
7379 sigma_dut_print(dut, DUT_MSG_DEBUG,
7380 "Failed to set HE defaults");
7381 }
Kiran Kumar Lokere642f7ce2019-02-25 18:28:10 -08007382
7383 /* Disable VHT support in 2.4 GHz for testbed */
7384 sta_set_2g_vht_supp(dut, intf, 0);
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08007385#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08007386
7387 /* Enable WEP/TKIP with HE capability in testbed */
7388 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
7389 sigma_dut_print(dut, DUT_MSG_ERROR,
7390 "Enabling HE config with WEP/TKIP failed");
7391 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08007392 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007393
7394 /* Defaults in case of DUT */
7395 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07007396 /* Enable STBC by default */
7397 wcn_sta_set_stbc(dut, intf, "1");
7398
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007399 /* set nss to 2 */
7400 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
7401 if (system(buf) != 0) {
7402 sigma_dut_print(dut, DUT_MSG_ERROR,
7403 "iwpriv %s nss 2 failed", intf);
7404 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007405 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007406
7407#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07007408 /* Set HE_MCS to 0-11 */
7409 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08007410 sigma_dut_print(dut, DUT_MSG_ERROR,
7411 "Setting of MCS failed");
7412 }
7413#endif /* NL80211_SUPPORT */
7414
7415 /* Disable WEP/TKIP with HE capability in DUT */
7416 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
7417 sigma_dut_print(dut, DUT_MSG_ERROR,
7418 "Enabling HE config with WEP/TKIP failed");
7419 }
7420 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007421 }
7422}
7423
7424
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007425static int cmd_sta_reset_default(struct sigma_dut *dut,
7426 struct sigma_conn *conn,
7427 struct sigma_cmd *cmd)
7428{
7429 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
7430 struct sigma_cmd *cmd);
7431 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007432 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007433 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007434 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307435 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007436
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007437 if (!program)
7438 program = get_param(cmd, "prog");
7439 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007440 dut->device_type = STA_unknown;
7441 type = get_param(cmd, "type");
7442 if (type && strcasecmp(type, "Testbed") == 0)
7443 dut->device_type = STA_testbed;
7444 if (type && strcasecmp(type, "DUT") == 0)
7445 dut->device_type = STA_dut;
7446
7447 if (dut->program == PROGRAM_TDLS) {
7448 /* Clear TDLS testing mode */
7449 wpa_command(intf, "SET tdls_disabled 0");
7450 wpa_command(intf, "SET tdls_testing 0");
7451 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05307452 if (get_driver_type() == DRIVER_WCN) {
7453 /* Enable the WCN driver in TDLS Explicit trigger mode
7454 */
7455 wpa_command(intf, "SET tdls_external_control 0");
7456 wpa_command(intf, "SET tdls_trigger_control 0");
7457 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007458 }
7459
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07007460#ifdef MIRACAST
7461 if (dut->program == PROGRAM_WFD ||
7462 dut->program == PROGRAM_DISPLAYR2)
7463 miracast_sta_reset_default(dut, conn, cmd);
7464#endif /* MIRACAST */
7465
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007466 switch (get_driver_type()) {
7467 case DRIVER_ATHEROS:
7468 sta_reset_default_ath(dut, intf, type);
7469 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08007470 case DRIVER_WCN:
7471 sta_reset_default_wcn(dut, intf, type);
7472 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007473 default:
7474 break;
7475 }
7476
7477#ifdef ANDROID_NAN
7478 if (dut->program == PROGRAM_NAN)
7479 nan_cmd_sta_reset_default(dut, conn, cmd);
7480#endif /* ANDROID_NAN */
7481
Jouni Malinenba630452018-06-22 11:49:59 +03007482 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007483 unlink("SP/wi-fi.org/pps.xml");
7484 if (system("rm -r SP/*") != 0) {
7485 }
7486 unlink("next-client-cert.pem");
7487 unlink("next-client-key.pem");
7488 }
7489
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007490 /* For WPS program of the 60 GHz band the band type needs to be saved */
7491 if (dut->program == PROGRAM_WPS) {
7492 if (band && strcasecmp(band, "60GHz") == 0) {
7493 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007494 /* For 60 GHz enable WPS for WPS TCs */
7495 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007496 } else {
7497 dut->band = WPS_BAND_NON_60G;
7498 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007499 } else if (dut->program == PROGRAM_60GHZ) {
7500 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
7501 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007502 }
7503
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02007504 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007505 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007506 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007507
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02007508 sigma_dut_print(dut, DUT_MSG_INFO,
7509 "WPS 60 GHz program, wps_disable = %d",
7510 dut->wps_disable);
7511
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007512 if (!dev_role) {
7513 send_resp(dut, conn, SIGMA_ERROR,
7514 "errorCode,Missing DevRole argument");
7515 return 0;
7516 }
7517
7518 if (strcasecmp(dev_role, "STA") == 0)
7519 dut->dev_role = DEVROLE_STA;
7520 else if (strcasecmp(dev_role, "PCP") == 0)
7521 dut->dev_role = DEVROLE_PCP;
7522 else {
7523 send_resp(dut, conn, SIGMA_ERROR,
7524 "errorCode,Unknown DevRole");
7525 return 0;
7526 }
7527
7528 if (dut->device_type == STA_unknown) {
7529 sigma_dut_print(dut, DUT_MSG_ERROR,
7530 "Device type is not STA testbed or DUT");
7531 send_resp(dut, conn, SIGMA_ERROR,
7532 "errorCode,Unknown device type");
7533 return 0;
7534 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007535
7536 sigma_dut_print(dut, DUT_MSG_DEBUG,
7537 "Setting msdu_size to MAX: 7912");
7538 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
7539 get_station_ifname());
7540
7541 if (system(buf) != 0) {
7542 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7543 buf);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007544 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007545 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007546
7547 if (sta_set_force_mcs(dut, 0, 1)) {
7548 sigma_dut_print(dut, DUT_MSG_ERROR,
7549 "Failed to reset force MCS");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007550 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007551 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007552 }
7553
7554 wpa_command(intf, "WPS_ER_STOP");
7555 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307556 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007557 wpa_command(intf, "SET radio_disabled 0");
7558
Alexei Avshalom Lazar744ae8a2019-01-31 17:26:46 +02007559 dut->wps_forced_version = 0;
7560
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007561 if (dut->wsc_fragment) {
7562 dut->wsc_fragment = 0;
7563 wpa_command(intf, "SET device_name Test client");
7564 wpa_command(intf, "SET manufacturer ");
7565 wpa_command(intf, "SET model_name ");
7566 wpa_command(intf, "SET model_number ");
7567 wpa_command(intf, "SET serial_number ");
7568 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007569 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7570 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7571 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7572 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007573
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007574 if (dut->tmp_mac_addr && dut->set_macaddr) {
7575 dut->tmp_mac_addr = 0;
7576 if (system(dut->set_macaddr) != 0) {
7577 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7578 "temporary MAC address");
7579 }
7580 }
7581
7582 set_ps(intf, dut, 0);
7583
Jouni Malinenba630452018-06-22 11:49:59 +03007584 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7585 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007586 wpa_command(intf, "SET interworking 1");
7587 wpa_command(intf, "SET hs20 1");
7588 }
7589
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007590 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007591 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007592 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007593 wpa_command(intf, "SET pmf 1");
7594 } else {
7595 wpa_command(intf, "SET pmf 0");
7596 }
7597
7598 hs2_clear_credentials(intf);
7599 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7600 wpa_command(intf, "SET access_network_type 15");
7601
7602 static_ip_file(0, NULL, NULL, NULL);
7603 kill_dhcp_client(dut, intf);
7604 clear_ip_addr(dut, intf);
7605
7606 dut->er_oper_performed = 0;
7607 dut->er_oper_bssid[0] = '\0';
7608
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007609 if (dut->program == PROGRAM_LOC) {
7610 /* Disable Interworking by default */
7611 wpa_command(get_station_ifname(), "SET interworking 0");
7612 }
7613
Ashwini Patil00402582017-04-13 12:29:39 +05307614 if (dut->program == PROGRAM_MBO) {
7615 free(dut->non_pref_ch_list);
7616 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307617 free(dut->btm_query_cand_list);
7618 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307619 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307620 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307621 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307622 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307623 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307624 }
7625
Jouni Malinen3c367e82017-06-23 17:01:47 +03007626 free(dut->rsne_override);
7627 dut->rsne_override = NULL;
7628
Jouni Malinen68143132017-09-02 02:34:08 +03007629 free(dut->sae_commit_override);
7630 dut->sae_commit_override = NULL;
7631
Jouni Malinen134fe3c2019-06-12 04:16:49 +03007632 dut->sta_associate_wait_connect = 0;
7633 dut->server_cert_hash[0] = '\0';
7634 dut->sta_tod_policy = 0;
7635
Jouni Malinend86e5822017-08-29 03:55:32 +03007636 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007637 free(dut->dpp_peer_uri);
7638 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007639 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007640 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007641
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007642 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7643
vamsi krishnaa2799492017-12-05 14:28:01 +05307644 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307645 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307646 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307647 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7648 dut->fils_hlp = 0;
7649#ifdef ANDROID
7650 hlp_thread_cleanup(dut);
7651#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307652 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307653
Jouni Malinen8179fee2019-03-28 03:19:47 +02007654 dut->akm_values = 0;
7655
Sunil Dutt076081f2018-02-05 19:45:50 +05307656#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05307657 if (get_driver_type() == DRIVER_WCN &&
7658 dut->config_rsnie == 1) {
7659 dut->config_rsnie = 0;
7660 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307661 }
7662#endif /* NL80211_SUPPORT */
7663
Sunil Duttfebf8a82018-02-09 18:50:13 +05307664 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7665 dut->dev_role = DEVROLE_STA_CFON;
7666 return sta_cfon_reset_default(dut, conn, cmd);
7667 }
7668
Jouni Malinen439352d2018-09-13 03:42:23 +03007669 wpa_command(intf, "SET setband AUTO");
7670
Sunil Duttfebf8a82018-02-09 18:50:13 +05307671 if (dut->program != PROGRAM_VHT)
7672 return cmd_sta_p2p_reset(dut, conn, cmd);
7673
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007674 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007675}
7676
7677
7678static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
7679 struct sigma_cmd *cmd)
7680{
7681 const char *program = get_param(cmd, "Program");
7682
7683 if (program == NULL)
7684 return -1;
7685#ifdef ANDROID_NAN
7686 if (strcasecmp(program, "NAN") == 0)
7687 return nan_cmd_sta_get_events(dut, conn, cmd);
7688#endif /* ANDROID_NAN */
7689 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7690 return 0;
7691}
7692
7693
Jouni Malinen82905202018-04-29 17:20:10 +03007694static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7695 struct sigma_cmd *cmd)
7696{
7697 const char *url = get_param(cmd, "url");
7698 const char *method = get_param(cmd, "method");
7699 pid_t pid;
7700 int status;
7701
7702 if (!url || !method)
7703 return -1;
7704
7705 /* TODO: Add support for method,post */
7706 if (strcasecmp(method, "get") != 0) {
7707 send_resp(dut, conn, SIGMA_ERROR,
7708 "ErrorCode,Unsupported method");
7709 return 0;
7710 }
7711
7712 pid = fork();
7713 if (pid < 0) {
7714 perror("fork");
7715 return -1;
7716 }
7717
7718 if (pid == 0) {
7719 char * argv[5] = { "wget", "-O", "/dev/null",
7720 (char *) url, NULL };
7721
7722 execv("/usr/bin/wget", argv);
7723 perror("execv");
7724 exit(0);
7725 return -1;
7726 }
7727
7728 if (waitpid(pid, &status, 0) < 0) {
7729 perror("waitpid");
7730 return -1;
7731 }
7732
7733 if (WIFEXITED(status)) {
7734 const char *errmsg;
7735
7736 if (WEXITSTATUS(status) == 0)
7737 return 1;
7738 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7739 WEXITSTATUS(status));
7740 switch (WEXITSTATUS(status)) {
7741 case 4:
7742 errmsg = "errmsg,Network failure";
7743 break;
7744 case 8:
7745 errmsg = "errmsg,Server issued an error response";
7746 break;
7747 default:
7748 errmsg = "errmsg,Unknown failure from wget";
7749 break;
7750 }
7751 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7752 return 0;
7753 }
7754
7755 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7756 return 0;
7757}
7758
7759
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007760static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
7761 struct sigma_cmd *cmd)
7762{
7763 const char *program = get_param(cmd, "Prog");
7764
Jouni Malinen82905202018-04-29 17:20:10 +03007765 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007766 return -1;
7767#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007768 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007769 return nan_cmd_sta_exec_action(dut, conn, cmd);
7770#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007771
7772 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007773 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007774
7775 if (get_param(cmd, "url"))
7776 return sta_exec_action_url(dut, conn, cmd);
7777
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007778 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7779 return 0;
7780}
7781
7782
7783static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
7784 struct sigma_cmd *cmd)
7785{
7786 const char *intf = get_param(cmd, "Interface");
7787 const char *val, *mcs32, *rate;
7788
7789 val = get_param(cmd, "GREENFIELD");
7790 if (val) {
7791 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7792 /* Enable GD */
7793 send_resp(dut, conn, SIGMA_ERROR,
7794 "ErrorCode,GF not supported");
7795 return 0;
7796 }
7797 }
7798
7799 val = get_param(cmd, "SGI20");
7800 if (val) {
7801 switch (get_driver_type()) {
7802 case DRIVER_ATHEROS:
7803 ath_sta_set_sgi(dut, intf, val);
7804 break;
7805 default:
7806 send_resp(dut, conn, SIGMA_ERROR,
7807 "ErrorCode,SGI20 not supported");
7808 return 0;
7809 }
7810 }
7811
7812 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7813 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7814 if (mcs32 && rate) {
7815 /* TODO */
7816 send_resp(dut, conn, SIGMA_ERROR,
7817 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7818 return 0;
7819 } else if (mcs32 && !rate) {
7820 /* TODO */
7821 send_resp(dut, conn, SIGMA_ERROR,
7822 "ErrorCode,MCS32 not supported");
7823 return 0;
7824 } else if (!mcs32 && rate) {
7825 switch (get_driver_type()) {
7826 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08007827 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007828 ath_sta_set_11nrates(dut, intf, rate);
7829 break;
7830 default:
7831 send_resp(dut, conn, SIGMA_ERROR,
7832 "ErrorCode,MCS32_FIXEDRATE not supported");
7833 return 0;
7834 }
7835 }
7836
7837 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7838}
7839
7840
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007841static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
7842 int mcs_config)
7843{
7844#ifdef NL80211_SUPPORT
7845 int ret;
7846
7847 switch (mcs_config) {
7848 case HE_80_MCS0_7:
7849 case HE_80_MCS0_9:
7850 case HE_80_MCS0_11:
7851 ret = sta_set_he_mcs(dut, intf, mcs_config);
7852 if (ret) {
7853 sigma_dut_print(dut, DUT_MSG_ERROR,
7854 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
7855 mcs_config, ret);
7856 }
7857 break;
7858 default:
7859 sigma_dut_print(dut, DUT_MSG_ERROR,
7860 "cmd_set_max_he_mcs: Invalid mcs %d",
7861 mcs_config);
7862 break;
7863 }
7864#else /* NL80211_SUPPORT */
7865 sigma_dut_print(dut, DUT_MSG_ERROR,
7866 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
7867#endif /* NL80211_SUPPORT */
7868}
7869
7870
Arif Hussain480d5f42019-03-12 14:40:42 -07007871static int sta_twt_request(struct sigma_dut *dut, struct sigma_conn *conn,
7872 struct sigma_cmd *cmd)
7873{
7874#ifdef NL80211_SUPPORT
7875 struct nlattr *params;
7876 struct nlattr *attr;
7877 struct nlattr *attr1;
7878 struct nl_msg *msg;
7879 int ifindex, ret;
7880 const char *val;
7881 const char *intf = get_param(cmd, "Interface");
7882 int wake_interval_exp = 10, nominal_min_wake_dur = 255,
7883 wake_interval_mantissa = 512;
7884 int flow_type = 0, twt_trigger = 0, target_wake_time = 0,
7885 protection = 0;
7886
7887 ifindex = if_nametoindex(intf);
7888 if (ifindex == 0) {
7889 sigma_dut_print(dut, DUT_MSG_ERROR,
7890 "%s: Index for interface %s failed",
7891 __func__, intf);
7892 return -1;
7893 }
7894
7895 val = get_param(cmd, "FlowType");
7896 if (val) {
7897 flow_type = atoi(val);
7898 if (flow_type != 0 && flow_type != 1) {
7899 sigma_dut_print(dut, DUT_MSG_ERROR,
7900 "TWT: Invalid FlowType %d", flow_type);
7901 return -1;
7902 }
7903 }
7904
7905 val = get_param(cmd, "TWT_Trigger");
7906 if (val) {
7907 twt_trigger = atoi(val);
7908 if (twt_trigger != 0 && twt_trigger != 1) {
7909 sigma_dut_print(dut, DUT_MSG_ERROR,
7910 "TWT: Invalid TWT_Trigger %d",
7911 twt_trigger);
7912 return -1;
7913 }
7914 }
7915
7916 val = get_param(cmd, "Protection");
7917 if (val) {
7918 protection = atoi(val);
7919 if (protection != 0 && protection != 1) {
7920 sigma_dut_print(dut, DUT_MSG_ERROR,
7921 "TWT: Invalid Protection %d",
7922 protection);
7923 return -1;
7924 }
7925 }
7926
7927 val = get_param(cmd, "TargetWakeTime");
7928 if (val)
7929 target_wake_time = atoi(val);
7930
7931 val = get_param(cmd, "WakeIntervalMantissa");
7932 if (val)
7933 wake_interval_mantissa = atoi(val);
7934
7935 val = get_param(cmd, "WakeIntervalExp");
7936 if (val)
7937 wake_interval_exp = atoi(val);
7938
7939 val = get_param(cmd, "NominalMinWakeDur");
7940 if (val)
7941 nominal_min_wake_dur = atoi(val);
7942
7943 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7944 NL80211_CMD_VENDOR)) ||
7945 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7946 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7947 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7948 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7949 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7950 !(params = nla_nest_start(
7951 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_SETUP)) ||
7952 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7953 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_EXP,
7954 wake_interval_exp) ||
7955 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_BCAST, 0) ||
7956 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_REQ_TYPE, 1) ||
7957 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_TRIGGER,
7958 twt_trigger) ||
7959 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE,
7960 flow_type) ||
7961 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_PROTECTION,
7962 protection) ||
7963 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_TIME,
7964 target_wake_time) ||
7965 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_DURATION,
7966 nominal_min_wake_dur) ||
7967 nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_WAKE_INTVL_MANTISSA,
7968 wake_interval_mantissa)) {
7969 sigma_dut_print(dut, DUT_MSG_ERROR,
7970 "%s: err in adding vendor_cmd and vendor_data",
7971 __func__);
7972 nlmsg_free(msg);
7973 return -1;
7974 }
7975 nla_nest_end(msg, attr1);
7976 nla_nest_end(msg, params);
7977 nla_nest_end(msg, attr);
7978
7979 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7980 if (ret) {
7981 sigma_dut_print(dut, DUT_MSG_ERROR,
7982 "%s: err in send_and_recv_msgs, ret=%d",
7983 __func__, ret);
7984 }
7985
7986 return ret;
7987#else /* NL80211_SUPPORT */
7988 sigma_dut_print(dut, DUT_MSG_ERROR,
7989 "TWT request cannot be done without NL80211_SUPPORT defined");
7990 return -1;
7991#endif /* NL80211_SUPPORT */
7992}
7993
7994
7995static int sta_twt_teardown(struct sigma_dut *dut, struct sigma_conn *conn,
7996 struct sigma_cmd *cmd)
7997{
7998 #ifdef NL80211_SUPPORT
7999 struct nlattr *params;
8000 struct nlattr *attr;
8001 struct nlattr *attr1;
8002 int ifindex, ret;
8003 struct nl_msg *msg;
8004 const char *intf = get_param(cmd, "Interface");
8005
8006 ifindex = if_nametoindex(intf);
8007 if (ifindex == 0) {
8008 sigma_dut_print(dut, DUT_MSG_ERROR,
8009 "%s: Index for interface %s failed",
8010 __func__, intf);
8011 return -1;
8012 }
8013
8014 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8015 NL80211_CMD_VENDOR)) ||
8016 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8017 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8018 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8019 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8020 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8021 !(params = nla_nest_start(
8022 msg,
8023 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_TWT_TERMINATE)) ||
8024 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8025 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_TWT_SETUP_FLOW_TYPE, 0)) {
8026 sigma_dut_print(dut, DUT_MSG_ERROR,
8027 "%s: err in adding vendor_cmd and vendor_data",
8028 __func__);
8029 nlmsg_free(msg);
8030 return -1;
8031 }
8032 nla_nest_end(msg, attr1);
8033 nla_nest_end(msg, params);
8034 nla_nest_end(msg, attr);
8035
8036 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8037 if (ret) {
8038 sigma_dut_print(dut, DUT_MSG_ERROR,
8039 "%s: err in send_and_recv_msgs, ret=%d",
8040 __func__, ret);
8041 }
8042
8043 return ret;
8044#else /* NL80211_SUPPORT */
8045 sigma_dut_print(dut, DUT_MSG_ERROR,
8046 "TWT teardown cannot be done without NL80211_SUPPORT defined");
8047 return -1;
8048#endif /* NL80211_SUPPORT */
8049}
8050
8051
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -08008052static int sta_transmit_omi(struct sigma_dut *dut, struct sigma_conn *conn,
8053 struct sigma_cmd *cmd)
8054{
8055#ifdef NL80211_SUPPORT
8056 struct nlattr *params;
8057 struct nlattr *attr;
8058 struct nlattr *attr1;
8059 struct nl_msg *msg;
8060 int ifindex, ret;
8061 const char *val;
8062 const char *intf = get_param(cmd, "Interface");
8063 uint8_t rx_nss = 0xFF, ch_bw = 0xFF, tx_nsts = 0xFF, ulmu_dis = 0,
8064 ulmu_data_dis = 0;
8065
8066 ifindex = if_nametoindex(intf);
8067 if (ifindex == 0) {
8068 sigma_dut_print(dut, DUT_MSG_ERROR,
8069 "%s: Index for interface %s failed",
8070 __func__, intf);
8071 return -1;
8072 }
8073 val = get_param(cmd, "OMCtrl_RxNSS");
8074 if (val)
8075 rx_nss = atoi(val);
8076
8077 val = get_param(cmd, "OMCtrl_ChnlWidth");
8078 if (val)
8079 ch_bw = atoi(val);
8080
8081 val = get_param(cmd, "OMCtrl_ULMUDisable");
8082 if (val)
8083 ulmu_dis = atoi(val);
8084
8085 val = get_param(cmd, "OMCtrl_TxNSTS");
8086 if (val)
8087 tx_nsts = atoi(val);
8088
8089 val = get_param(cmd, "OMCtrl_ULMUDataDisable");
8090 if (val)
8091 ulmu_data_dis = atoi(val);
8092
8093 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8094 NL80211_CMD_VENDOR)) ||
8095 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8096 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8097 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8098 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8099 !(attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8100 !(params = nla_nest_start(
8101 msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OMI_TX)) ||
8102 !(attr1 = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8103 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_RX_NSS, rx_nss) ||
8104 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_CH_BW, ch_bw) ||
8105 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_TX_NSTS, tx_nsts) ||
8106 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DATA_DISABLE,
8107 ulmu_data_dis) ||
8108 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_HE_OMI_ULMU_DISABLE,
8109 ulmu_dis)) {
8110 sigma_dut_print(dut, DUT_MSG_ERROR,
8111 "%s: err in adding vendor_cmd and vendor_data",
8112 __func__);
8113 nlmsg_free(msg);
8114 return -1;
8115 }
8116 nla_nest_end(msg, attr1);
8117 nla_nest_end(msg, params);
8118 nla_nest_end(msg, attr);
8119
8120 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8121 if (ret) {
8122 sigma_dut_print(dut, DUT_MSG_ERROR,
8123 "%s: err in send_and_recv_msgs, ret=%d",
8124 __func__, ret);
8125 }
8126
8127 return ret;
8128#else /* NL80211_SUPPORT */
8129 sigma_dut_print(dut, DUT_MSG_ERROR,
8130 "OMI TX cannot be processed without NL80211_SUPPORT defined");
8131 return -1;
8132#endif /* NL80211_SUPPORT */
8133}
8134
8135
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008136static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
8137 struct sigma_conn *conn,
8138 struct sigma_cmd *cmd)
8139{
8140 const char *intf = get_param(cmd, "Interface");
8141 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07008142 const char *program;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008143 int tkip = -1;
8144 int wep = -1;
8145
Arif Hussaina37e9552018-06-20 17:05:59 -07008146 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008147 val = get_param(cmd, "SGI80");
8148 if (val) {
8149 int sgi80;
8150
8151 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008152 run_iwpriv(dut, intf, "shortgi %d", sgi80);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008153 }
8154
8155 val = get_param(cmd, "TxBF");
8156 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008157 switch (get_driver_type()) {
8158 case DRIVER_WCN:
8159 if (sta_set_tx_beamformee(dut, intf, 1)) {
8160 send_resp(dut, conn, SIGMA_ERROR,
8161 "ErrorCode,Failed to set TX beamformee enable");
8162 return 0;
8163 }
8164 break;
8165 case DRIVER_ATHEROS:
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008166 if (run_iwpriv(dut, intf, "vhtsubfee 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008167 send_resp(dut, conn, SIGMA_ERROR,
8168 "ErrorCode,Setting vhtsubfee failed");
8169 return 0;
8170 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008171 if (run_iwpriv(dut, intf, "vhtsubfer 1") < 0) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008172 send_resp(dut, conn, SIGMA_ERROR,
8173 "ErrorCode,Setting vhtsubfer failed");
8174 return 0;
8175 }
8176 break;
8177 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008178 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07008179 "Unsupported driver type");
8180 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008181 }
8182 }
8183
8184 val = get_param(cmd, "MU_TxBF");
8185 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
8186 switch (get_driver_type()) {
8187 case DRIVER_ATHEROS:
8188 ath_sta_set_txsp_stream(dut, intf, "1SS");
8189 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008190 run_iwpriv(dut, intf, "vhtmubfee 1");
8191 run_iwpriv(dut, intf, "vhtmubfer 1");
Sunil Duttae9e5d12018-06-29 11:50:47 +05308192 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008193 case DRIVER_WCN:
8194 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
8195 send_resp(dut, conn, SIGMA_ERROR,
8196 "ErrorCode,Failed to set RX/TXSP_STREAM");
8197 return 0;
8198 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05308199 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008200 default:
8201 sigma_dut_print(dut, DUT_MSG_ERROR,
8202 "Setting SP_STREAM not supported");
8203 break;
8204 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008205 }
8206
8207 val = get_param(cmd, "LDPC");
8208 if (val) {
8209 int ldpc;
8210
8211 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008212 run_iwpriv(dut, intf, "ldpc %d", ldpc);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008213 }
8214
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008215 val = get_param(cmd, "BCC");
8216 if (val) {
8217 int bcc;
8218
8219 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8220 /* use LDPC iwpriv itself to set bcc coding, bcc coding
8221 * is mutually exclusive to bcc */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008222 run_iwpriv(dut, intf, "ldpc %d", !bcc);
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08008223 }
8224
Arif Hussain7b47d2d2018-05-09 10:44:02 -07008225 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
8226 if (val && dut->sta_nss == 1)
8227 cmd_set_max_he_mcs(dut, intf, atoi(val));
8228
8229 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
8230 if (val && dut->sta_nss == 2)
8231 cmd_set_max_he_mcs(dut, intf, atoi(val));
8232
Arif Hussainac6c5112018-05-25 17:34:00 -07008233 val = get_param(cmd, "MCS_FixedRate");
8234 if (val) {
8235#ifdef NL80211_SUPPORT
8236 int mcs, ratecode = 0;
8237 enum he_mcs_config mcs_config;
8238 int ret;
Jouni Malinenb9b671d2019-04-26 13:23:17 +03008239 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07008240
8241 ratecode = (0x07 & dut->sta_nss) << 5;
8242 mcs = atoi(val);
8243 /* Add the MCS to the ratecode */
8244 if (mcs >= 0 && mcs <= 11) {
8245 ratecode += mcs;
8246 if (dut->device_type == STA_testbed &&
8247 mcs > 7 && mcs <= 11) {
8248 if (mcs <= 9)
8249 mcs_config = HE_80_MCS0_9;
8250 else
8251 mcs_config = HE_80_MCS0_11;
8252 ret = sta_set_he_mcs(dut, intf, mcs_config);
8253 if (ret) {
8254 sigma_dut_print(dut, DUT_MSG_ERROR,
8255 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
8256 mcs, mcs_config, ret);
8257 }
8258 }
8259 snprintf(buf, sizeof(buf),
8260 "iwpriv %s set_11ax_rate 0x%03x",
8261 intf, ratecode);
8262 if (system(buf) != 0) {
8263 sigma_dut_print(dut, DUT_MSG_ERROR,
8264 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
8265 ratecode);
8266 }
8267 } else {
8268 sigma_dut_print(dut, DUT_MSG_ERROR,
8269 "MCS_FixedRate: HE MCS %d not supported",
8270 mcs);
8271 }
8272#else /* NL80211_SUPPORT */
8273 sigma_dut_print(dut, DUT_MSG_ERROR,
8274 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
8275#endif /* NL80211_SUPPORT */
8276 }
8277
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008278 val = get_param(cmd, "opt_md_notif_ie");
8279 if (val) {
8280 char *result = NULL;
8281 char delim[] = ";";
8282 char token[30];
8283 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308284 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008285
Peng Xub8fc5cc2017-05-10 17:27:28 -07008286 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308287 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008288
8289 /* Extract the NSS information */
8290 if (result) {
8291 value = atoi(result);
8292 switch (value) {
8293 case 1:
8294 config_val = 1;
8295 break;
8296 case 2:
8297 config_val = 3;
8298 break;
8299 case 3:
8300 config_val = 7;
8301 break;
8302 case 4:
8303 config_val = 15;
8304 break;
8305 default:
8306 config_val = 3;
8307 break;
8308 }
8309
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008310 run_iwpriv(dut, intf, "rxchainmask %d", config_val);
8311 run_iwpriv(dut, intf, "txchainmask %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008312
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008313 }
8314
8315 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308316 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008317 if (result) {
8318 value = atoi(result);
8319 switch (value) {
8320 case 20:
8321 config_val = 0;
8322 break;
8323 case 40:
8324 config_val = 1;
8325 break;
8326 case 80:
8327 config_val = 2;
8328 break;
8329 case 160:
8330 config_val = 3;
8331 break;
8332 default:
8333 config_val = 2;
8334 break;
8335 }
8336
8337 dut->chwidth = config_val;
8338
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008339 run_iwpriv(dut, intf, "chwidth %d", config_val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008340 }
8341
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008342 run_iwpriv(dut, intf, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008343 }
8344
8345 val = get_param(cmd, "nss_mcs_cap");
8346 if (val) {
8347 int nss, mcs;
8348 char token[20];
8349 char *result = NULL;
8350 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308351 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008352
Peng Xub8fc5cc2017-05-10 17:27:28 -07008353 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308354 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308355 if (!result) {
8356 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008357 "NSS not specified");
8358 send_resp(dut, conn, SIGMA_ERROR,
8359 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308360 return 0;
8361 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008362 nss = atoi(result);
8363
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008364 run_iwpriv(dut, intf, "nss %d", nss);
Arif Hussainac6c5112018-05-25 17:34:00 -07008365 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008366
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308367 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008368 if (result == NULL) {
8369 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008370 "MCS not specified");
8371 send_resp(dut, conn, SIGMA_ERROR,
8372 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008373 return 0;
8374 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05308375 result = strtok_r(result, "-", &saveptr);
8376 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308377 if (!result) {
8378 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008379 "MCS not specified");
8380 send_resp(dut, conn, SIGMA_ERROR,
8381 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05308382 return 0;
8383 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008384 mcs = atoi(result);
8385
Arif Hussaina37e9552018-06-20 17:05:59 -07008386 if (program && strcasecmp(program, "HE") == 0) {
8387#ifdef NL80211_SUPPORT
8388 enum he_mcs_config mcs_config;
8389 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008390
Arif Hussaina37e9552018-06-20 17:05:59 -07008391 if (mcs >= 0 && mcs <= 7) {
8392 mcs_config = HE_80_MCS0_7;
8393 } else if (mcs > 7 && mcs <= 9) {
8394 mcs_config = HE_80_MCS0_9;
8395 } else if (mcs > 9 && mcs <= 11) {
8396 mcs_config = HE_80_MCS0_11;
8397 } else {
8398 sigma_dut_print(dut, DUT_MSG_ERROR,
8399 "nss_mcs_cap: HE: Invalid mcs: %d",
8400 mcs);
8401 send_resp(dut, conn, SIGMA_ERROR,
8402 "errorCode,Invalid MCS");
8403 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008404 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008405
8406 ret = sta_set_he_mcs(dut, intf, mcs_config);
8407 if (ret) {
8408 sigma_dut_print(dut, DUT_MSG_ERROR,
8409 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
8410 mcs_config, ret);
8411 send_resp(dut, conn, SIGMA_ERROR,
8412 "errorCode,Failed to set MCS");
8413 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008414 }
Arif Hussaina37e9552018-06-20 17:05:59 -07008415#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008416 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07008417 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
8418#endif /* NL80211_SUPPORT */
8419 } else {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008420 run_iwpriv(dut, intf, "vhtmcs %d", mcs);
Arif Hussaina37e9552018-06-20 17:05:59 -07008421
8422 switch (nss) {
8423 case 1:
8424 switch (mcs) {
8425 case 7:
8426 vht_mcsmap = 0xfffc;
8427 break;
8428 case 8:
8429 vht_mcsmap = 0xfffd;
8430 break;
8431 case 9:
8432 vht_mcsmap = 0xfffe;
8433 break;
8434 default:
8435 vht_mcsmap = 0xfffe;
8436 break;
8437 }
8438 break;
8439 case 2:
8440 switch (mcs) {
8441 case 7:
8442 vht_mcsmap = 0xfff0;
8443 break;
8444 case 8:
8445 vht_mcsmap = 0xfff5;
8446 break;
8447 case 9:
8448 vht_mcsmap = 0xfffa;
8449 break;
8450 default:
8451 vht_mcsmap = 0xfffa;
8452 break;
8453 }
8454 break;
8455 case 3:
8456 switch (mcs) {
8457 case 7:
8458 vht_mcsmap = 0xffc0;
8459 break;
8460 case 8:
8461 vht_mcsmap = 0xffd5;
8462 break;
8463 case 9:
8464 vht_mcsmap = 0xffea;
8465 break;
8466 default:
8467 vht_mcsmap = 0xffea;
8468 break;
8469 }
8470 break;
8471 default:
8472 vht_mcsmap = 0xffea;
8473 break;
8474 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008475 run_iwpriv(dut, intf, "vht_mcsmap 0x%04x", vht_mcsmap);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008476 }
8477 }
8478
8479 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
8480
8481 val = get_param(cmd, "Vht_tkip");
8482 if (val)
8483 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8484
8485 val = get_param(cmd, "Vht_wep");
8486 if (val)
8487 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
8488
8489 if (tkip != -1 || wep != -1) {
8490 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008491 run_iwpriv(dut, intf, "htweptkip 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008492 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008493 run_iwpriv(dut, intf, "htweptkip 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008494 } else {
8495 sigma_dut_print(dut, DUT_MSG_ERROR,
8496 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
8497 return 0;
8498 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008499 }
8500
Arif Hussain55f00da2018-07-03 08:28:26 -07008501 val = get_param(cmd, "txBandwidth");
8502 if (val) {
8503 switch (get_driver_type()) {
8504 case DRIVER_WCN:
8505 if (wcn_sta_set_width(dut, intf, val) < 0) {
8506 send_resp(dut, conn, SIGMA_ERROR,
8507 "ErrorCode,Failed to set txBandwidth");
8508 return 0;
8509 }
8510 break;
8511 case DRIVER_ATHEROS:
8512 if (ath_set_width(dut, conn, intf, val) < 0) {
8513 send_resp(dut, conn, SIGMA_ERROR,
8514 "ErrorCode,Failed to set txBandwidth");
8515 return 0;
8516 }
8517 break;
8518 default:
8519 sigma_dut_print(dut, DUT_MSG_ERROR,
8520 "Setting txBandwidth not supported");
8521 break;
8522 }
8523 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008524
Arif Hussain9765f7d2018-07-03 08:28:26 -07008525 val = get_param(cmd, "BeamformeeSTS");
8526 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07008527 if (sta_set_tx_beamformee(dut, intf, 1)) {
8528 send_resp(dut, conn, SIGMA_ERROR,
8529 "ErrorCode,Failed to set TX beamformee enable");
8530 return 0;
8531 }
8532
Arif Hussain9765f7d2018-07-03 08:28:26 -07008533 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
8534 send_resp(dut, conn, SIGMA_ERROR,
8535 "ErrorCode,Failed to set BeamformeeSTS");
8536 return 0;
8537 }
8538 }
8539
Arif Hussain68d23f52018-07-11 13:39:08 -07008540 val = get_param(cmd, "Trig_MAC_Padding_Dur");
8541 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008542#ifdef NL80211_SUPPORT
8543 enum qca_wlan_he_mac_padding_dur set_val;
8544
8545 switch (atoi(val)) {
8546 case 16:
8547 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
8548 break;
8549 case 8:
8550 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
8551 break;
8552 default:
8553 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
8554 break;
8555 }
8556 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07008557 send_resp(dut, conn, SIGMA_ERROR,
8558 "ErrorCode,Failed to set MAC padding duration");
8559 return 0;
8560 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07008561#else /* NL80211_SUPPORT */
8562 sigma_dut_print(dut, DUT_MSG_ERROR,
8563 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
8564#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07008565 }
8566
Arif Hussain480d5f42019-03-12 14:40:42 -07008567 val = get_param(cmd, "TWT_ReqSupport");
8568 if (val) {
8569 int set_val;
8570
8571 if (strcasecmp(val, "Enable") == 0) {
8572 set_val = 1;
8573 } else if (strcasecmp(val, "Disable") == 0) {
8574 set_val = 0;
8575 } else {
8576 send_resp(dut, conn, SIGMA_ERROR,
8577 "ErrorCode,Invalid TWT_ReqSupport");
8578 return STATUS_SENT;
8579 }
8580
8581 if (sta_set_twt_req_support(dut, intf, set_val)) {
8582 sigma_dut_print(dut, DUT_MSG_ERROR,
8583 "Failed to set TWT req support %d",
8584 set_val);
8585 send_resp(dut, conn, SIGMA_ERROR,
8586 "ErrorCode,Failed to set TWT_ReqSupport");
8587 return STATUS_SENT;
8588 }
8589 }
8590
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07008591 val = get_param(cmd, "MU_EDCA");
8592 if (val && (strcasecmp(val, "Override") == 0)) {
8593 if (sta_set_mu_edca_override(dut, intf, 1)) {
8594 send_resp(dut, conn, SIGMA_ERROR,
8595 "ErrorCode,Failed to set MU EDCA override");
8596 return 0;
8597 }
8598 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008599
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07008600 val = get_param(cmd, "OMControl");
8601 if (val) {
8602 int set_val = 1;
8603
8604 if (strcasecmp(val, "Enable") == 0)
8605 set_val = 1;
8606 else if (strcasecmp(val, "Disable") == 0)
8607 set_val = 0;
8608
8609 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
8610 send_resp(dut, conn, SIGMA_ERROR,
8611 "ErrorCode,Failed to set OM ctrl supp");
8612 return 0;
8613 }
8614 }
8615
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07008616 val = get_param(cmd, "ADDBAResp_BufSize");
8617 if (val) {
8618 int buf_size;
8619
8620 if (strcasecmp(val, "gt64") == 0)
8621 buf_size = 256;
8622 else
8623 buf_size = 64;
8624 if (get_driver_type() == DRIVER_WCN &&
8625 sta_set_addba_buf_size(dut, intf, buf_size)) {
8626 send_resp(dut, conn, SIGMA_ERROR,
8627 "ErrorCode,set addbaresp_buff_size failed");
8628 return 0;
8629 }
8630 }
8631
8632 val = get_param(cmd, "ADDBAReq_BufSize");
8633 if (val) {
8634 int buf_size;
8635
8636 if (strcasecmp(val, "gt64") == 0)
8637 buf_size = 256;
8638 else
8639 buf_size = 64;
8640 if (get_driver_type() == DRIVER_WCN &&
8641 sta_set_addba_buf_size(dut, intf, buf_size)) {
8642 send_resp(dut, conn, SIGMA_ERROR,
8643 "ErrorCode,set addbareq_buff_size failed");
8644 return 0;
8645 }
8646 }
8647
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008648 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8649}
8650
8651
8652static int sta_set_wireless_60g(struct sigma_dut *dut,
8653 struct sigma_conn *conn,
8654 struct sigma_cmd *cmd)
8655{
8656 const char *dev_role = get_param(cmd, "DevRole");
8657
8658 if (!dev_role) {
8659 send_resp(dut, conn, SIGMA_INVALID,
8660 "ErrorCode,DevRole not specified");
8661 return 0;
8662 }
8663
8664 if (strcasecmp(dev_role, "PCP") == 0)
8665 return sta_set_60g_pcp(dut, conn, cmd);
8666 if (strcasecmp(dev_role, "STA") == 0)
8667 return sta_set_60g_sta(dut, conn, cmd);
8668 send_resp(dut, conn, SIGMA_INVALID,
8669 "ErrorCode,DevRole not supported");
8670 return 0;
8671}
8672
8673
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308674static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
8675 struct sigma_cmd *cmd)
8676{
8677 int status;
8678 const char *intf = get_param(cmd, "Interface");
8679 const char *val = get_param(cmd, "DevRole");
8680
8681 if (val && strcasecmp(val, "STA-CFON") == 0) {
8682 status = sta_cfon_set_wireless(dut, conn, cmd);
8683 if (status)
8684 return status;
8685 }
8686 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
8687}
8688
8689
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008690static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
8691 struct sigma_cmd *cmd)
8692{
8693 const char *val;
8694
8695 val = get_param(cmd, "Program");
8696 if (val) {
8697 if (strcasecmp(val, "11n") == 0)
8698 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08008699 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008700 return cmd_sta_set_wireless_vht(dut, conn, cmd);
8701 if (strcasecmp(val, "60ghz") == 0)
8702 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05308703 if (strcasecmp(val, "OCE") == 0)
8704 return sta_set_wireless_oce(dut, conn, cmd);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02008705 /* sta_set_wireless in WPS program is only used for 60G */
8706 if (is_60g_sigma_dut(dut))
8707 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008708 send_resp(dut, conn, SIGMA_ERROR,
8709 "ErrorCode,Program value not supported");
8710 } else {
8711 send_resp(dut, conn, SIGMA_ERROR,
8712 "ErrorCode,Program argument not available");
8713 }
8714
8715 return 0;
8716}
8717
8718
8719static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
8720 int tid)
8721{
8722 char buf[100];
8723 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
8724
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05308725 if (tid < 0 ||
8726 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
8727 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
8728 return;
8729 }
8730
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008731 /*
8732 * Two ways to ensure that addba request with a
8733 * non zero TID could be sent out. EV 117296
8734 */
8735 snprintf(buf, sizeof(buf),
8736 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
8737 tid);
8738 if (system(buf) != 0) {
8739 sigma_dut_print(dut, DUT_MSG_ERROR,
8740 "Ping did not send out");
8741 }
8742
8743 snprintf(buf, sizeof(buf),
8744 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8745 intf, VI_QOS_TMP_FILE);
8746 if (system(buf) != 0)
8747 return;
8748
8749 snprintf(buf, sizeof(buf),
8750 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8751 intf, VI_QOS_TMP_FILE);
8752 if (system(buf) != 0)
8753 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8754
8755 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8756 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8757 if (system(buf) != 0) {
8758 sigma_dut_print(dut, DUT_MSG_ERROR,
8759 "VI_QOS_TEMP_FILE generation error failed");
8760 }
8761 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8762 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8763 if (system(buf) != 0) {
8764 sigma_dut_print(dut, DUT_MSG_ERROR,
8765 "VI_QOS_FILE generation failed");
8766 }
8767
8768 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8769 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8770 if (system(buf) != 0) {
8771 sigma_dut_print(dut, DUT_MSG_ERROR,
8772 "VI_QOS_FILE generation failed");
8773 }
8774
8775 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8776 if (system(buf) != 0) {
8777 }
8778}
8779
8780
8781static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8782 struct sigma_cmd *cmd)
8783{
8784 const char *intf = get_param(cmd, "Interface");
8785 const char *val;
8786 int tid = 0;
8787 char buf[100];
8788
8789 val = get_param(cmd, "TID");
8790 if (val) {
8791 tid = atoi(val);
8792 if (tid)
8793 ath_sta_inject_frame(dut, intf, tid);
8794 }
8795
8796 /* Command sequence for ADDBA request on Peregrine based devices */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -07008797 run_iwpriv(dut, intf, "setaddbaoper 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008798
8799 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8800 if (system(buf) != 0) {
8801 sigma_dut_print(dut, DUT_MSG_ERROR,
8802 "wifitool senddelba failed");
8803 }
8804
8805 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8806 if (system(buf) != 0) {
8807 sigma_dut_print(dut, DUT_MSG_ERROR,
8808 "wifitool sendaddba failed");
8809 }
8810
8811 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8812
8813 return 1;
8814}
8815
8816
Lior David9981b512017-01-20 13:16:40 +02008817#ifdef __linux__
8818
8819static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
8820 int agg_size)
8821{
8822 char dir[128], buf[128];
8823 FILE *f;
8824 regex_t re;
8825 regmatch_t m[2];
Jouni Malinen3aa72862019-05-29 23:14:51 +03008826 int rc, ret = -1, vring_id, found, res;
Lior David9981b512017-01-20 13:16:40 +02008827
8828 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
8829 sigma_dut_print(dut, DUT_MSG_ERROR,
8830 "failed to get wil6210 debugfs dir");
8831 return -1;
8832 }
8833
Jouni Malinen3aa72862019-05-29 23:14:51 +03008834 res = snprintf(buf, sizeof(buf), "%s/vrings", dir);
8835 if (res < 0 || res >= sizeof(buf))
8836 return -1;
Lior David9981b512017-01-20 13:16:40 +02008837 f = fopen(buf, "r");
8838 if (!f) {
8839 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008840 /* newer wil6210 driver renamed file to "rings" */
Jouni Malinen3aa72862019-05-29 23:14:51 +03008841 res = snprintf(buf, sizeof(buf), "%s/rings", dir);
8842 if (res < 0 || res >= sizeof(buf))
8843 return -1;
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008844 f = fopen(buf, "r");
8845 if (!f) {
8846 sigma_dut_print(dut, DUT_MSG_ERROR,
8847 "failed to open: %s", buf);
8848 return -1;
8849 }
Lior David9981b512017-01-20 13:16:40 +02008850 }
8851
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008852 /* can be either VRING tx... or RING... */
8853 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02008854 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
8855 goto out;
8856 }
8857
8858 /* find TX VRING for the mac address */
8859 found = 0;
8860 while (fgets(buf, sizeof(buf), f)) {
8861 if (strcasestr(buf, dest_mac)) {
8862 found = 1;
8863 break;
8864 }
8865 }
8866
8867 if (!found) {
8868 sigma_dut_print(dut, DUT_MSG_ERROR,
8869 "no TX VRING for %s", dest_mac);
8870 goto out;
8871 }
8872
8873 /* extract VRING ID, "VRING tx_<id> = {" */
8874 if (!fgets(buf, sizeof(buf), f)) {
8875 sigma_dut_print(dut, DUT_MSG_ERROR,
8876 "no VRING start line for %s", dest_mac);
8877 goto out;
8878 }
8879
8880 rc = regexec(&re, buf, 2, m, 0);
8881 regfree(&re);
8882 if (rc || m[1].rm_so < 0) {
8883 sigma_dut_print(dut, DUT_MSG_ERROR,
8884 "no VRING TX ID for %s", dest_mac);
8885 goto out;
8886 }
8887 buf[m[1].rm_eo] = 0;
8888 vring_id = atoi(&buf[m[1].rm_so]);
8889
8890 /* send the addba command */
8891 fclose(f);
Jouni Malinen3aa72862019-05-29 23:14:51 +03008892 res = snprintf(buf, sizeof(buf), "%s/back", dir);
8893 if (res < 0 || res >= sizeof(buf))
8894 return -1;
Lior David9981b512017-01-20 13:16:40 +02008895 f = fopen(buf, "w");
8896 if (!f) {
8897 sigma_dut_print(dut, DUT_MSG_ERROR,
8898 "failed to open: %s", buf);
8899 return -1;
8900 }
8901
8902 fprintf(f, "add %d %d\n", vring_id, agg_size);
8903
8904 ret = 0;
8905
8906out:
8907 fclose(f);
8908
8909 return ret;
8910}
8911
8912
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008913int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8914 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008915{
8916 const char *val;
8917 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008918
8919 val = get_param(cmd, "TID");
8920 if (val) {
8921 tid = atoi(val);
8922 if (tid != 0) {
8923 sigma_dut_print(dut, DUT_MSG_ERROR,
8924 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
8925 tid);
8926 }
8927 }
8928
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008929 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008930 if (!val) {
8931 sigma_dut_print(dut, DUT_MSG_ERROR,
8932 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008933 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008934 }
8935
Lior David9981b512017-01-20 13:16:40 +02008936 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008937 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008938
8939 return 1;
8940}
8941
Lior David9981b512017-01-20 13:16:40 +02008942#endif /* __linux__ */
8943
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008944
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008945static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8946 struct sigma_cmd *cmd)
8947{
8948#ifdef NL80211_SUPPORT
8949 const char *intf = get_param(cmd, "Interface");
8950 const char *val;
8951 int tid = -1;
8952 int bufsize = 64;
8953 struct nl_msg *msg;
8954 int ret = 0;
8955 struct nlattr *params;
8956 int ifindex;
8957
8958 val = get_param(cmd, "TID");
8959 if (val)
8960 tid = atoi(val);
8961
8962 if (tid == -1) {
8963 send_resp(dut, conn, SIGMA_ERROR,
8964 "ErrorCode,sta_send_addba tid invalid");
8965 return 0;
8966 }
8967
8968 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8969
8970 ifindex = if_nametoindex(intf);
8971 if (ifindex == 0) {
8972 sigma_dut_print(dut, DUT_MSG_ERROR,
8973 "%s: Index for interface %s failed",
8974 __func__, intf);
8975 send_resp(dut, conn, SIGMA_ERROR,
8976 "ErrorCode,sta_send_addba interface invalid");
8977 return 0;
8978 }
8979
8980 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8981 NL80211_CMD_VENDOR)) ||
8982 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8983 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8984 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8985 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8986 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8987 nla_put_u8(msg,
8988 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
8989 QCA_WLAN_ADD_BA) ||
8990 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
8991 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07008992 nla_put_u16(msg,
8993 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
8994 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008995 sigma_dut_print(dut, DUT_MSG_ERROR,
8996 "%s: err in adding vendor_cmd and vendor_data",
8997 __func__);
8998 nlmsg_free(msg);
8999 send_resp(dut, conn, SIGMA_ERROR,
9000 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
9001 return 0;
9002 }
9003 nla_nest_end(msg, params);
9004
9005 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
9006 if (ret) {
9007 sigma_dut_print(dut, DUT_MSG_ERROR,
9008 "%s: err in send_and_recv_msgs, ret=%d",
9009 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05309010 if (ret == -EOPNOTSUPP)
9011 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009012 send_resp(dut, conn, SIGMA_ERROR,
9013 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
9014 return 0;
9015 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009016#else /* NL80211_SUPPORT */
9017 sigma_dut_print(dut, DUT_MSG_ERROR,
9018 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009019#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05309020
9021 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009022}
9023
9024
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009025static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
9026 struct sigma_cmd *cmd)
9027{
9028 switch (get_driver_type()) {
9029 case DRIVER_ATHEROS:
9030 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08009031 case DRIVER_WCN:
9032 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02009033#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009034 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02009035 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02009036#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009037 default:
9038 /*
9039 * There is no driver specific implementation for other drivers.
9040 * Ignore the command and report COMPLETE since the following
9041 * throughput test operation will end up sending ADDBA anyway.
9042 */
9043 return 1;
9044 }
9045}
9046
9047
9048int inject_eth_frame(int s, const void *data, size_t len,
9049 unsigned short ethtype, char *dst, char *src)
9050{
9051 struct iovec iov[4] = {
9052 {
9053 .iov_base = dst,
9054 .iov_len = ETH_ALEN,
9055 },
9056 {
9057 .iov_base = src,
9058 .iov_len = ETH_ALEN,
9059 },
9060 {
9061 .iov_base = &ethtype,
9062 .iov_len = sizeof(unsigned short),
9063 },
9064 {
9065 .iov_base = (void *) data,
9066 .iov_len = len,
9067 }
9068 };
9069 struct msghdr msg = {
9070 .msg_name = NULL,
9071 .msg_namelen = 0,
9072 .msg_iov = iov,
9073 .msg_iovlen = 4,
9074 .msg_control = NULL,
9075 .msg_controllen = 0,
9076 .msg_flags = 0,
9077 };
9078
9079 return sendmsg(s, &msg, 0);
9080}
9081
9082#if defined(__linux__) || defined(__QNXNTO__)
9083
9084int inject_frame(int s, const void *data, size_t len, int encrypt)
9085{
9086#define IEEE80211_RADIOTAP_F_WEP 0x04
9087#define IEEE80211_RADIOTAP_F_FRAG 0x08
9088 unsigned char rtap_hdr[] = {
9089 0x00, 0x00, /* radiotap version */
9090 0x0e, 0x00, /* radiotap length */
9091 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
9092 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
9093 0x00, /* padding */
9094 0x00, 0x00, /* RX and TX flags to indicate that */
9095 0x00, 0x00, /* this is the injected frame directly */
9096 };
9097 struct iovec iov[2] = {
9098 {
9099 .iov_base = &rtap_hdr,
9100 .iov_len = sizeof(rtap_hdr),
9101 },
9102 {
9103 .iov_base = (void *) data,
9104 .iov_len = len,
9105 }
9106 };
9107 struct msghdr msg = {
9108 .msg_name = NULL,
9109 .msg_namelen = 0,
9110 .msg_iov = iov,
9111 .msg_iovlen = 2,
9112 .msg_control = NULL,
9113 .msg_controllen = 0,
9114 .msg_flags = 0,
9115 };
9116
9117 if (encrypt)
9118 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
9119
9120 return sendmsg(s, &msg, 0);
9121}
9122
9123
9124int open_monitor(const char *ifname)
9125{
9126#ifdef __QNXNTO__
9127 struct sockaddr_dl ll;
9128 int s;
9129
9130 memset(&ll, 0, sizeof(ll));
9131 ll.sdl_family = AF_LINK;
9132 ll.sdl_index = if_nametoindex(ifname);
9133 if (ll.sdl_index == 0) {
9134 perror("if_nametoindex");
9135 return -1;
9136 }
9137 s = socket(PF_INET, SOCK_RAW, 0);
9138#else /* __QNXNTO__ */
9139 struct sockaddr_ll ll;
9140 int s;
9141
9142 memset(&ll, 0, sizeof(ll));
9143 ll.sll_family = AF_PACKET;
9144 ll.sll_ifindex = if_nametoindex(ifname);
9145 if (ll.sll_ifindex == 0) {
9146 perror("if_nametoindex");
9147 return -1;
9148 }
9149 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
9150#endif /* __QNXNTO__ */
9151 if (s < 0) {
9152 perror("socket[PF_PACKET,SOCK_RAW]");
9153 return -1;
9154 }
9155
9156 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
9157 perror("monitor socket bind");
9158 close(s);
9159 return -1;
9160 }
9161
9162 return s;
9163}
9164
9165
9166static int hex2num(char c)
9167{
9168 if (c >= '0' && c <= '9')
9169 return c - '0';
9170 if (c >= 'a' && c <= 'f')
9171 return c - 'a' + 10;
9172 if (c >= 'A' && c <= 'F')
9173 return c - 'A' + 10;
9174 return -1;
9175}
9176
9177
9178int hwaddr_aton(const char *txt, unsigned char *addr)
9179{
9180 int i;
9181
9182 for (i = 0; i < 6; i++) {
9183 int a, b;
9184
9185 a = hex2num(*txt++);
9186 if (a < 0)
9187 return -1;
9188 b = hex2num(*txt++);
9189 if (b < 0)
9190 return -1;
9191 *addr++ = (a << 4) | b;
9192 if (i < 5 && *txt++ != ':')
9193 return -1;
9194 }
9195
9196 return 0;
9197}
9198
9199#endif /* defined(__linux__) || defined(__QNXNTO__) */
9200
9201enum send_frame_type {
9202 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
9203};
9204enum send_frame_protection {
9205 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
9206};
9207
9208
9209static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9210 enum send_frame_type frame,
9211 enum send_frame_protection protected,
9212 const char *dest)
9213{
9214#ifdef __linux__
9215 unsigned char buf[1000], *pos;
9216 int s, res;
9217 char bssid[20], addr[20];
9218 char result[32], ssid[100];
9219 size_t ssid_len;
9220
9221 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
9222 sizeof(result)) < 0 ||
9223 strncmp(result, "COMPLETED", 9) != 0) {
9224 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
9225 return 0;
9226 }
9227
9228 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
9229 < 0) {
9230 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9231 "current BSSID");
9232 return 0;
9233 }
9234
9235 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
9236 < 0) {
9237 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9238 "own MAC address");
9239 return 0;
9240 }
9241
9242 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
9243 < 0) {
9244 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
9245 "current SSID");
9246 return 0;
9247 }
9248 ssid_len = strlen(ssid);
9249
9250 pos = buf;
9251
9252 /* Frame Control */
9253 switch (frame) {
9254 case DISASSOC:
9255 *pos++ = 0xa0;
9256 break;
9257 case DEAUTH:
9258 *pos++ = 0xc0;
9259 break;
9260 case SAQUERY:
9261 *pos++ = 0xd0;
9262 break;
9263 case AUTH:
9264 *pos++ = 0xb0;
9265 break;
9266 case ASSOCREQ:
9267 *pos++ = 0x00;
9268 break;
9269 case REASSOCREQ:
9270 *pos++ = 0x20;
9271 break;
9272 case DLS_REQ:
9273 *pos++ = 0xd0;
9274 break;
9275 }
9276
9277 if (protected == INCORRECT_KEY)
9278 *pos++ = 0x40; /* Set Protected field to 1 */
9279 else
9280 *pos++ = 0x00;
9281
9282 /* Duration */
9283 *pos++ = 0x00;
9284 *pos++ = 0x00;
9285
9286 /* addr1 = DA (current AP) */
9287 hwaddr_aton(bssid, pos);
9288 pos += 6;
9289 /* addr2 = SA (own address) */
9290 hwaddr_aton(addr, pos);
9291 pos += 6;
9292 /* addr3 = BSSID (current AP) */
9293 hwaddr_aton(bssid, pos);
9294 pos += 6;
9295
9296 /* Seq# (to be filled by driver/mac80211) */
9297 *pos++ = 0x00;
9298 *pos++ = 0x00;
9299
9300 if (protected == INCORRECT_KEY) {
9301 /* CCMP parameters */
9302 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
9303 pos += 8;
9304 }
9305
9306 if (protected == INCORRECT_KEY) {
9307 switch (frame) {
9308 case DEAUTH:
9309 /* Reason code (encrypted) */
9310 memcpy(pos, "\xa7\x39", 2);
9311 pos += 2;
9312 break;
9313 case DISASSOC:
9314 /* Reason code (encrypted) */
9315 memcpy(pos, "\xa7\x39", 2);
9316 pos += 2;
9317 break;
9318 case SAQUERY:
9319 /* Category|Action|TransID (encrypted) */
9320 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
9321 pos += 4;
9322 break;
9323 default:
9324 return -1;
9325 }
9326
9327 /* CCMP MIC */
9328 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
9329 pos += 8;
9330 } else {
9331 switch (frame) {
9332 case DEAUTH:
9333 /* reason code = 8 */
9334 *pos++ = 0x08;
9335 *pos++ = 0x00;
9336 break;
9337 case DISASSOC:
9338 /* reason code = 8 */
9339 *pos++ = 0x08;
9340 *pos++ = 0x00;
9341 break;
9342 case SAQUERY:
9343 /* Category - SA Query */
9344 *pos++ = 0x08;
9345 /* SA query Action - Request */
9346 *pos++ = 0x00;
9347 /* Transaction ID */
9348 *pos++ = 0x12;
9349 *pos++ = 0x34;
9350 break;
9351 case AUTH:
9352 /* Auth Alg (Open) */
9353 *pos++ = 0x00;
9354 *pos++ = 0x00;
9355 /* Seq# */
9356 *pos++ = 0x01;
9357 *pos++ = 0x00;
9358 /* Status code */
9359 *pos++ = 0x00;
9360 *pos++ = 0x00;
9361 break;
9362 case ASSOCREQ:
9363 /* Capability Information */
9364 *pos++ = 0x31;
9365 *pos++ = 0x04;
9366 /* Listen Interval */
9367 *pos++ = 0x0a;
9368 *pos++ = 0x00;
9369 /* SSID */
9370 *pos++ = 0x00;
9371 *pos++ = ssid_len;
9372 memcpy(pos, ssid, ssid_len);
9373 pos += ssid_len;
9374 /* Supported Rates */
9375 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9376 10);
9377 pos += 10;
9378 /* Extended Supported Rates */
9379 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9380 pos += 6;
9381 /* RSN */
9382 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9383 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9384 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9385 pos += 28;
9386 break;
9387 case REASSOCREQ:
9388 /* Capability Information */
9389 *pos++ = 0x31;
9390 *pos++ = 0x04;
9391 /* Listen Interval */
9392 *pos++ = 0x0a;
9393 *pos++ = 0x00;
9394 /* Current AP */
9395 hwaddr_aton(bssid, pos);
9396 pos += 6;
9397 /* SSID */
9398 *pos++ = 0x00;
9399 *pos++ = ssid_len;
9400 memcpy(pos, ssid, ssid_len);
9401 pos += ssid_len;
9402 /* Supported Rates */
9403 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
9404 10);
9405 pos += 10;
9406 /* Extended Supported Rates */
9407 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
9408 pos += 6;
9409 /* RSN */
9410 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
9411 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
9412 "\x00\x00\x00\x00\x0f\xac\x06", 28);
9413 pos += 28;
9414 break;
9415 case DLS_REQ:
9416 /* Category - DLS */
9417 *pos++ = 0x02;
9418 /* DLS Action - Request */
9419 *pos++ = 0x00;
9420 /* Destination MACAddress */
9421 if (dest)
9422 hwaddr_aton(dest, pos);
9423 else
9424 memset(pos, 0, 6);
9425 pos += 6;
9426 /* Source MACAddress */
9427 hwaddr_aton(addr, pos);
9428 pos += 6;
9429 /* Capability Information */
9430 *pos++ = 0x10; /* Privacy */
9431 *pos++ = 0x06; /* QoS */
9432 /* DLS Timeout Value */
9433 *pos++ = 0x00;
9434 *pos++ = 0x01;
9435 /* Supported rates */
9436 *pos++ = 0x01;
9437 *pos++ = 0x08;
9438 *pos++ = 0x0c; /* 6 Mbps */
9439 *pos++ = 0x12; /* 9 Mbps */
9440 *pos++ = 0x18; /* 12 Mbps */
9441 *pos++ = 0x24; /* 18 Mbps */
9442 *pos++ = 0x30; /* 24 Mbps */
9443 *pos++ = 0x48; /* 36 Mbps */
9444 *pos++ = 0x60; /* 48 Mbps */
9445 *pos++ = 0x6c; /* 54 Mbps */
9446 /* TODO: Extended Supported Rates */
9447 /* TODO: HT Capabilities */
9448 break;
9449 }
9450 }
9451
9452 s = open_monitor("sigmadut");
9453 if (s < 0) {
9454 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9455 "monitor socket");
9456 return 0;
9457 }
9458
9459 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
9460 if (res < 0) {
9461 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9462 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309463 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009464 return 0;
9465 }
9466 if (res < pos - buf) {
9467 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
9468 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309469 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009470 return 0;
9471 }
9472
9473 close(s);
9474
9475 return 1;
9476#else /* __linux__ */
9477 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
9478 "yet supported");
9479 return 0;
9480#endif /* __linux__ */
9481}
9482
9483
9484static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
9485 struct sigma_conn *conn,
9486 struct sigma_cmd *cmd)
9487{
9488 const char *intf = get_param(cmd, "Interface");
9489 const char *sta, *val;
9490 unsigned char addr[ETH_ALEN];
9491 char buf[100];
9492
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +03009493 if (!intf)
9494 return -1;
9495
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009496 sta = get_param(cmd, "peer");
9497 if (sta == NULL)
9498 sta = get_param(cmd, "station");
9499 if (sta == NULL) {
9500 send_resp(dut, conn, SIGMA_ERROR,
9501 "ErrorCode,Missing peer address");
9502 return 0;
9503 }
9504 if (hwaddr_aton(sta, addr) < 0) {
9505 send_resp(dut, conn, SIGMA_ERROR,
9506 "ErrorCode,Invalid peer address");
9507 return 0;
9508 }
9509
9510 val = get_param(cmd, "type");
9511 if (val == NULL)
9512 return -1;
9513
9514 if (strcasecmp(val, "DISCOVERY") == 0) {
9515 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
9516 if (wpa_command(intf, buf) < 0) {
9517 send_resp(dut, conn, SIGMA_ERROR,
9518 "ErrorCode,Failed to send TDLS discovery");
9519 return 0;
9520 }
9521 return 1;
9522 }
9523
9524 if (strcasecmp(val, "SETUP") == 0) {
9525 int status = 0, timeout = 0;
9526
9527 val = get_param(cmd, "Status");
9528 if (val)
9529 status = atoi(val);
9530
9531 val = get_param(cmd, "Timeout");
9532 if (val)
9533 timeout = atoi(val);
9534
9535 if (status != 0 && status != 37) {
9536 send_resp(dut, conn, SIGMA_ERROR,
9537 "ErrorCode,Unsupported status value");
9538 return 0;
9539 }
9540
9541 if (timeout != 0 && timeout != 301) {
9542 send_resp(dut, conn, SIGMA_ERROR,
9543 "ErrorCode,Unsupported timeout value");
9544 return 0;
9545 }
9546
9547 if (status && timeout) {
9548 send_resp(dut, conn, SIGMA_ERROR,
9549 "ErrorCode,Unsupported timeout+status "
9550 "combination");
9551 return 0;
9552 }
9553
9554 if (status == 37 &&
9555 wpa_command(intf, "SET tdls_testing 0x200")) {
9556 send_resp(dut, conn, SIGMA_ERROR,
9557 "ErrorCode,Failed to enable "
9558 "decline setup response test mode");
9559 return 0;
9560 }
9561
9562 if (timeout == 301) {
9563 int res;
9564 if (dut->no_tpk_expiration)
9565 res = wpa_command(intf,
9566 "SET tdls_testing 0x108");
9567 else
9568 res = wpa_command(intf,
9569 "SET tdls_testing 0x8");
9570 if (res) {
9571 send_resp(dut, conn, SIGMA_ERROR,
9572 "ErrorCode,Failed to set short TPK "
9573 "lifetime");
9574 return 0;
9575 }
9576 }
9577
9578 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
9579 if (wpa_command(intf, buf) < 0) {
9580 send_resp(dut, conn, SIGMA_ERROR,
9581 "ErrorCode,Failed to send TDLS setup");
9582 return 0;
9583 }
9584 return 1;
9585 }
9586
9587 if (strcasecmp(val, "TEARDOWN") == 0) {
9588 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
9589 if (wpa_command(intf, buf) < 0) {
9590 send_resp(dut, conn, SIGMA_ERROR,
9591 "ErrorCode,Failed to send TDLS teardown");
9592 return 0;
9593 }
9594 return 1;
9595 }
9596
9597 send_resp(dut, conn, SIGMA_ERROR,
9598 "ErrorCode,Unsupported TDLS frame");
9599 return 0;
9600}
9601
9602
9603static int sta_ap_known(const char *ifname, const char *bssid)
9604{
9605 char buf[4096];
9606
Jouni Malinendd32f192018-09-15 02:55:19 +03009607 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009608 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
9609 return 0;
9610 if (strncmp(buf, "id=", 3) != 0)
9611 return 0;
9612 return 1;
9613}
9614
9615
9616static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
9617 const char *bssid)
9618{
9619 int res;
9620 struct wpa_ctrl *ctrl;
9621 char buf[256];
9622
9623 if (sta_ap_known(ifname, bssid))
9624 return 0;
9625 sigma_dut_print(dut, DUT_MSG_DEBUG,
9626 "AP not in BSS table - start scan");
9627
9628 ctrl = open_wpa_mon(ifname);
9629 if (ctrl == NULL) {
9630 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
9631 "wpa_supplicant monitor connection");
9632 return -1;
9633 }
9634
9635 if (wpa_command(ifname, "SCAN") < 0) {
9636 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
9637 wpa_ctrl_detach(ctrl);
9638 wpa_ctrl_close(ctrl);
9639 return -1;
9640 }
9641
9642 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
9643 buf, sizeof(buf));
9644
9645 wpa_ctrl_detach(ctrl);
9646 wpa_ctrl_close(ctrl);
9647
9648 if (res < 0) {
9649 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
9650 return -1;
9651 }
9652
9653 if (sta_ap_known(ifname, bssid))
9654 return 0;
9655 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
9656 return -1;
9657}
9658
9659
9660static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
9661 struct sigma_conn *conn,
9662 struct sigma_cmd *cmd,
9663 const char *intf)
9664{
9665 char buf[200];
9666
9667 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
9668 if (system(buf) != 0) {
9669 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
9670 "ndsend");
9671 return 0;
9672 }
9673
9674 return 1;
9675}
9676
9677
9678static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
9679 struct sigma_conn *conn,
9680 struct sigma_cmd *cmd,
9681 const char *intf)
9682{
9683 char buf[200];
9684 const char *ip = get_param(cmd, "SenderIP");
9685
Peng Xu26b356d2017-10-04 17:58:16 -07009686 if (!ip)
9687 return 0;
9688
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009689 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
9690 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9691 if (system(buf) == 0) {
9692 sigma_dut_print(dut, DUT_MSG_INFO,
9693 "Neighbor Solicitation got a response "
9694 "for %s@%s", ip, intf);
9695 }
9696
9697 return 1;
9698}
9699
9700
9701static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
9702 struct sigma_conn *conn,
9703 struct sigma_cmd *cmd,
9704 const char *ifname)
9705{
9706 char buf[200];
9707 const char *ip = get_param(cmd, "SenderIP");
9708
9709 if (ip == NULL) {
9710 send_resp(dut, conn, SIGMA_ERROR,
9711 "ErrorCode,Missing SenderIP parameter");
9712 return 0;
9713 }
9714 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
9715 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9716 if (system(buf) != 0) {
9717 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
9718 "for %s@%s", ip, ifname);
9719 }
9720
9721 return 1;
9722}
9723
9724
9725static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
9726 struct sigma_conn *conn,
9727 struct sigma_cmd *cmd,
9728 const char *ifname)
9729{
9730 char buf[200];
9731 char ip[16];
9732 int s;
Peng Xub3756882017-10-04 14:39:09 -07009733 struct ifreq ifr;
9734 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009735
9736 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07009737 if (s < 0) {
9738 perror("socket");
9739 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009740 }
9741
Peng Xub3756882017-10-04 14:39:09 -07009742 memset(&ifr, 0, sizeof(ifr));
9743 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
9744 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
9745 sigma_dut_print(dut, DUT_MSG_INFO,
9746 "Failed to get %s IP address: %s",
9747 ifname, strerror(errno));
9748 close(s);
9749 return -1;
9750 }
9751 close(s);
9752
9753 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9754 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9755
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009756 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9757 ip);
9758 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9759 if (system(buf) != 0) {
9760 }
9761
9762 return 1;
9763}
9764
9765
9766static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9767 struct sigma_conn *conn,
9768 struct sigma_cmd *cmd,
9769 const char *ifname)
9770{
9771 char buf[200], addr[20];
9772 char dst[ETH_ALEN], src[ETH_ALEN];
9773 short ethtype = htons(ETH_P_ARP);
9774 char *pos;
9775 int s, res;
9776 const char *val;
9777 struct sockaddr_in taddr;
9778
9779 val = get_param(cmd, "dest");
9780 if (val)
9781 hwaddr_aton(val, (unsigned char *) dst);
9782
9783 val = get_param(cmd, "DestIP");
9784 if (val)
9785 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009786 else
9787 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009788
9789 if (get_wpa_status(get_station_ifname(), "address", addr,
9790 sizeof(addr)) < 0)
9791 return -2;
9792 hwaddr_aton(addr, (unsigned char *) src);
9793
9794 pos = buf;
9795 *pos++ = 0x00;
9796 *pos++ = 0x01;
9797 *pos++ = 0x08;
9798 *pos++ = 0x00;
9799 *pos++ = 0x06;
9800 *pos++ = 0x04;
9801 *pos++ = 0x00;
9802 *pos++ = 0x02;
9803 memcpy(pos, src, ETH_ALEN);
9804 pos += ETH_ALEN;
9805 memcpy(pos, &taddr.sin_addr, 4);
9806 pos += 4;
9807 memcpy(pos, dst, ETH_ALEN);
9808 pos += ETH_ALEN;
9809 memcpy(pos, &taddr.sin_addr, 4);
9810 pos += 4;
9811
9812 s = open_monitor(get_station_ifname());
9813 if (s < 0) {
9814 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9815 "monitor socket");
9816 return 0;
9817 }
9818
9819 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
9820 if (res < 0) {
9821 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9822 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309823 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009824 return 0;
9825 }
9826
9827 close(s);
9828
9829 return 1;
9830}
9831
9832
9833static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
9834 struct sigma_conn *conn,
9835 struct sigma_cmd *cmd,
9836 const char *intf, const char *dest)
9837{
9838 char buf[100];
9839
9840 if (if_nametoindex("sigmadut") == 0) {
9841 snprintf(buf, sizeof(buf),
9842 "iw dev %s interface add sigmadut type monitor",
9843 get_station_ifname());
9844 if (system(buf) != 0 ||
9845 if_nametoindex("sigmadut") == 0) {
9846 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9847 "monitor interface with '%s'", buf);
9848 return -2;
9849 }
9850 }
9851
9852 if (system("ifconfig sigmadut up") != 0) {
9853 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9854 "monitor interface up");
9855 return -2;
9856 }
9857
9858 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
9859}
9860
9861
9862static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
9863 struct sigma_conn *conn,
9864 struct sigma_cmd *cmd)
9865{
9866 const char *intf = get_param(cmd, "Interface");
9867 const char *dest = get_param(cmd, "Dest");
9868 const char *type = get_param(cmd, "FrameName");
9869 const char *val;
9870 char buf[200], *pos, *end;
9871 int count, count2;
9872
9873 if (type == NULL)
9874 type = get_param(cmd, "Type");
9875
9876 if (intf == NULL || dest == NULL || type == NULL)
9877 return -1;
9878
9879 if (strcasecmp(type, "NeighAdv") == 0)
9880 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
9881
9882 if (strcasecmp(type, "NeighSolicitReq") == 0)
9883 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
9884
9885 if (strcasecmp(type, "ARPProbe") == 0)
9886 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
9887
9888 if (strcasecmp(type, "ARPAnnounce") == 0)
9889 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
9890
9891 if (strcasecmp(type, "ARPReply") == 0)
9892 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
9893
9894 if (strcasecmp(type, "DLS-request") == 0 ||
9895 strcasecmp(type, "DLSrequest") == 0)
9896 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
9897 dest);
9898
9899 if (strcasecmp(type, "ANQPQuery") != 0 &&
9900 strcasecmp(type, "Query") != 0) {
9901 send_resp(dut, conn, SIGMA_ERROR,
9902 "ErrorCode,Unsupported HS 2.0 send frame type");
9903 return 0;
9904 }
9905
9906 if (sta_scan_ap(dut, intf, dest) < 0) {
9907 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
9908 "the requested AP");
9909 return 0;
9910 }
9911
9912 pos = buf;
9913 end = buf + sizeof(buf);
9914 count = 0;
9915 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
9916
9917 val = get_param(cmd, "ANQP_CAP_LIST");
9918 if (val && atoi(val)) {
9919 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
9920 count++;
9921 }
9922
9923 val = get_param(cmd, "VENUE_NAME");
9924 if (val && atoi(val)) {
9925 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
9926 count++;
9927 }
9928
9929 val = get_param(cmd, "NETWORK_AUTH_TYPE");
9930 if (val && atoi(val)) {
9931 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
9932 count++;
9933 }
9934
9935 val = get_param(cmd, "ROAMING_CONS");
9936 if (val && atoi(val)) {
9937 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
9938 count++;
9939 }
9940
9941 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
9942 if (val && atoi(val)) {
9943 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
9944 count++;
9945 }
9946
9947 val = get_param(cmd, "NAI_REALM_LIST");
9948 if (val && atoi(val)) {
9949 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
9950 count++;
9951 }
9952
9953 val = get_param(cmd, "3GPP_INFO");
9954 if (val && atoi(val)) {
9955 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
9956 count++;
9957 }
9958
9959 val = get_param(cmd, "DOMAIN_LIST");
9960 if (val && atoi(val)) {
9961 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
9962 count++;
9963 }
9964
Jouni Malinen34cf9532018-04-29 19:26:33 +03009965 val = get_param(cmd, "Venue_URL");
9966 if (val && atoi(val)) {
9967 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
9968 count++;
9969 }
9970
Jouni Malinend3bca5d2018-04-29 17:25:23 +03009971 val = get_param(cmd, "Advice_Of_Charge");
9972 if (val && atoi(val)) {
9973 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
9974 count++;
9975 }
9976
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009977 if (count && wpa_command(intf, buf)) {
9978 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
9979 return 0;
9980 }
9981
9982 pos = buf;
9983 end = buf + sizeof(buf);
9984 count2 = 0;
9985 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
9986
9987 val = get_param(cmd, "HS_CAP_LIST");
9988 if (val && atoi(val)) {
9989 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
9990 count2++;
9991 }
9992
9993 val = get_param(cmd, "OPER_NAME");
9994 if (val && atoi(val)) {
9995 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
9996 count2++;
9997 }
9998
9999 val = get_param(cmd, "WAN_METRICS");
10000 if (!val)
10001 val = get_param(cmd, "WAN_MAT");
10002 if (!val)
10003 val = get_param(cmd, "WAN_MET");
10004 if (val && atoi(val)) {
10005 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
10006 count2++;
10007 }
10008
10009 val = get_param(cmd, "CONNECTION_CAPABILITY");
10010 if (val && atoi(val)) {
10011 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
10012 count2++;
10013 }
10014
10015 val = get_param(cmd, "OP_CLASS");
10016 if (val && atoi(val)) {
10017 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
10018 count2++;
10019 }
10020
10021 val = get_param(cmd, "OSU_PROVIDER_LIST");
10022 if (val && atoi(val)) {
10023 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
10024 count2++;
10025 }
10026
Jouni Malinenf67afec2018-04-29 19:24:58 +030010027 val = get_param(cmd, "OPER_ICON_METADATA");
10028 if (!val)
10029 val = get_param(cmd, "OPERATOR_ICON_METADATA");
10030 if (val && atoi(val)) {
10031 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
10032 count2++;
10033 }
10034
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010035 if (count && count2) {
10036 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
10037 "second query");
10038 sleep(1);
10039 }
10040
10041 if (count2 && wpa_command(intf, buf)) {
10042 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
10043 "failed");
10044 return 0;
10045 }
10046
10047 val = get_param(cmd, "NAI_HOME_REALM_LIST");
10048 if (val) {
10049 if (count || count2) {
10050 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10051 "sending out second query");
10052 sleep(1);
10053 }
10054
10055 if (strcmp(val, "1") == 0)
10056 val = "mail.example.com";
10057 snprintf(buf, end - pos,
10058 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
10059 dest, val);
10060 if (wpa_command(intf, buf)) {
10061 send_resp(dut, conn, SIGMA_ERROR,
10062 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
10063 "failed");
10064 return 0;
10065 }
10066 }
10067
10068 val = get_param(cmd, "ICON_REQUEST");
10069 if (val) {
10070 if (count || count2) {
10071 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
10072 "sending out second query");
10073 sleep(1);
10074 }
10075
10076 snprintf(buf, end - pos,
10077 "HS20_ICON_REQUEST %s %s", dest, val);
10078 if (wpa_command(intf, buf)) {
10079 send_resp(dut, conn, SIGMA_ERROR,
10080 "ErrorCode,HS20_ICON_REQUEST failed");
10081 return 0;
10082 }
10083 }
10084
10085 return 1;
10086}
10087
10088
10089static int ath_sta_send_frame_vht(struct sigma_dut *dut,
10090 struct sigma_conn *conn,
10091 struct sigma_cmd *cmd)
10092{
10093 const char *val;
10094 char *ifname;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010095 int chwidth, nss;
10096
10097 val = get_param(cmd, "framename");
10098 if (!val)
10099 return -1;
10100 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10101
10102 /* Command sequence to generate Op mode notification */
10103 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
10104 ifname = get_station_ifname();
10105
10106 /* Disable STBC */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010107 run_iwpriv(dut, ifname, "tx_stbc 0");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010108
10109 /* Extract Channel width */
10110 val = get_param(cmd, "Channel_width");
10111 if (val) {
10112 switch (atoi(val)) {
10113 case 20:
10114 chwidth = 0;
10115 break;
10116 case 40:
10117 chwidth = 1;
10118 break;
10119 case 80:
10120 chwidth = 2;
10121 break;
10122 case 160:
10123 chwidth = 3;
10124 break;
10125 default:
10126 chwidth = 2;
10127 break;
10128 }
10129
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010130 run_iwpriv(dut, ifname, "chwidth %d", chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010131 }
10132
10133 /* Extract NSS */
10134 val = get_param(cmd, "NSS");
10135 if (val) {
10136 switch (atoi(val)) {
10137 case 1:
10138 nss = 1;
10139 break;
10140 case 2:
10141 nss = 3;
10142 break;
10143 case 3:
10144 nss = 7;
10145 break;
10146 default:
10147 /* We do not support NSS > 3 */
10148 nss = 3;
10149 break;
10150 }
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010151 run_iwpriv(dut, ifname, "rxchainmask %d", nss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010152 }
10153
10154 /* Opmode notify */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070010155 run_iwpriv(dut, ifname, "opmode_notify 1");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010156 }
10157
10158 return 1;
10159}
10160
10161
10162static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
10163 struct sigma_conn *conn,
10164 struct sigma_cmd *cmd)
10165{
10166 switch (get_driver_type()) {
10167 case DRIVER_ATHEROS:
10168 return ath_sta_send_frame_vht(dut, conn, cmd);
10169 default:
10170 send_resp(dut, conn, SIGMA_ERROR,
10171 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
10172 return 0;
10173 }
10174}
10175
10176
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010177static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
10178 struct sigma_cmd *cmd)
10179{
10180 const char *val;
10181 const char *intf = get_param(cmd, "Interface");
10182
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010183 if (!intf)
10184 return -1;
10185
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010186 val = get_param(cmd, "framename");
10187 if (!val)
10188 return -1;
10189 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
10190
10191 /* Command sequence to generate Op mode notification */
10192 if (val && strcasecmp(val, "action") == 0) {
10193 val = get_param(cmd, "PPDUTxType");
10194 if (val && strcasecmp(val, "TB") == 0) {
10195 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
10196 sigma_dut_print(dut, DUT_MSG_ERROR,
10197 "failed to send TB PPDU Tx cfg");
10198 send_resp(dut, conn, SIGMA_ERROR,
10199 "ErrorCode,set TB PPDU Tx cfg failed");
10200 return 0;
10201 }
10202 return 1;
10203 }
10204
10205 sigma_dut_print(dut, DUT_MSG_ERROR,
10206 "Action Tx type is not defined");
10207 }
10208
10209 return 1;
10210}
10211
10212
10213static int cmd_sta_send_frame_he(struct sigma_dut *dut,
10214 struct sigma_conn *conn,
10215 struct sigma_cmd *cmd)
10216{
10217 switch (get_driver_type()) {
10218 case DRIVER_WCN:
10219 return wcn_sta_send_frame_he(dut, conn, cmd);
10220 default:
10221 send_resp(dut, conn, SIGMA_ERROR,
10222 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
10223 return 0;
10224 }
10225}
10226
10227
Lior David0fe101e2017-03-09 16:09:50 +020010228#ifdef __linux__
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010229
10230static int
10231wil6210_send_p2p_frame_60g(struct sigma_dut *dut, struct sigma_cmd *cmd,
10232 const char *frame_name, const char *dest_mac)
10233{
10234 int isprobereq = strcasecmp(frame_name, "probereq") == 0;
10235 const char *ssid = get_param(cmd, "ssid");
10236 const char *countstr = get_param(cmd, "count");
10237 const char *channelstr = get_param(cmd, "channel");
10238 const char *group_id = get_param(cmd, "groupid");
10239 const char *client_id = get_param(cmd, "clientmac");
10240 int count, channel, freq, i;
10241 const char *fname;
10242 char frame[1024], src_mac[20], group_id_attr[25],
10243 device_macstr[3 * ETH_ALEN], client_mac[ETH_ALEN];
10244 const char *group_ssid;
10245 const int group_ssid_prefix_len = 9;
10246 struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *) frame;
10247 size_t framelen = sizeof(frame);
10248 struct template_frame_tag tags[2];
10249 size_t tags_total = ARRAY_SIZE(tags);
10250 int tag_index, len, dst_len;
10251
10252 if (!countstr || !channelstr) {
10253 sigma_dut_print(dut, DUT_MSG_ERROR,
10254 "Missing argument: count, channel");
10255 return -1;
10256 }
10257 if (isprobereq && !ssid) {
10258 sigma_dut_print(dut, DUT_MSG_ERROR,
10259 "Missing argument: ssid");
10260 return -1;
10261 }
10262 if (!isprobereq && (!group_id || !client_id)) {
10263 sigma_dut_print(dut, DUT_MSG_ERROR,
10264 "Missing argument: group_id, client_id");
10265 return -1;
10266 }
10267
10268 count = atoi(countstr);
10269 channel = atoi(channelstr);
10270 freq = channel_to_freq(dut, channel);
10271
10272 if (!freq) {
10273 sigma_dut_print(dut, DUT_MSG_ERROR,
10274 "invalid channel: %s", channelstr);
10275 return -1;
10276 }
10277
10278 if (isprobereq) {
10279 if (strcasecmp(ssid, "wildcard") == 0) {
10280 fname = "probe_req_wildcard.txt";
10281 } else if (strcasecmp(ssid, "P2P_Wildcard") == 0) {
10282 fname = "probe_req_P2P_Wildcard.txt";
10283 } else {
10284 sigma_dut_print(dut, DUT_MSG_ERROR,
10285 "invalid probe request type");
10286 return -1;
10287 }
10288 } else {
10289 fname = "P2P_device_discovery_req.txt";
10290 }
10291
10292 if (parse_template_frame_file(dut, fname, frame, &framelen,
10293 tags, &tags_total)) {
10294 sigma_dut_print(dut, DUT_MSG_ERROR,
10295 "invalid frame template: %s", fname);
10296 return -1;
10297 }
10298
10299 if (get_wpa_status(get_station_ifname(), "address",
10300 src_mac, sizeof(src_mac)) < 0 ||
10301 parse_mac_address(dut, src_mac, &hdr->addr2[0]) ||
10302 parse_mac_address(dut, dest_mac, &hdr->addr1[0]))
10303 return -1;
10304 /* Use wildcard BSSID, since we are in PBSS */
10305 memset(&hdr->addr3, 0xFF, ETH_ALEN);
10306
10307 if (!isprobereq) {
10308 tag_index = find_template_frame_tag(tags, tags_total, 1);
10309 if (tag_index < 0) {
10310 sigma_dut_print(dut, DUT_MSG_ERROR,
10311 "can't find device id attribute");
10312 return -1;
10313 }
10314 if (parse_mac_address(dut, client_id,
10315 (unsigned char *) client_mac)) {
10316 sigma_dut_print(dut, DUT_MSG_ERROR,
10317 "invalid client_id: %s", client_id);
10318 return -1;
10319 }
10320 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10321 framelen - tags[tag_index].offset,
10322 IEEE80211_P2P_ATTR_DEVICE_ID,
10323 client_mac, ETH_ALEN)) {
10324 sigma_dut_print(dut, DUT_MSG_ERROR,
10325 "fail to replace device id attribute");
10326 return -1;
10327 }
10328
10329 /*
10330 * group_id arg contains device MAC address followed by
10331 * space and SSID (DIRECT-somessid).
10332 * group id attribute contains device address (6 bytes)
10333 * followed by SSID prefix DIRECT-XX (9 bytes)
10334 */
10335 if (strlen(group_id) < sizeof(device_macstr)) {
10336 sigma_dut_print(dut, DUT_MSG_ERROR,
10337 "group_id arg too short");
10338 return -1;
10339 }
10340 memcpy(device_macstr, group_id, sizeof(device_macstr));
10341 device_macstr[sizeof(device_macstr) - 1] = '\0';
10342 if (parse_mac_address(dut, device_macstr,
10343 (unsigned char *) group_id_attr)) {
10344 sigma_dut_print(dut, DUT_MSG_ERROR,
10345 "fail to parse device address from group_id");
10346 return -1;
10347 }
10348 group_ssid = strchr(group_id, ' ');
10349 if (!group_ssid) {
10350 sigma_dut_print(dut, DUT_MSG_ERROR,
10351 "invalid group_id arg, no ssid");
10352 return -1;
10353 }
10354 group_ssid++;
10355 len = strlen(group_ssid);
10356 if (len < group_ssid_prefix_len) {
10357 sigma_dut_print(dut, DUT_MSG_ERROR,
10358 "group_id SSID too short");
10359 return -1;
10360 }
10361 dst_len = sizeof(group_id_attr) - ETH_ALEN;
10362 if (len > dst_len) {
10363 sigma_dut_print(dut, DUT_MSG_ERROR,
10364 "group_id SSID (%s) too long",
10365 group_ssid);
10366 return -1;
10367 }
10368
10369 memcpy(group_id_attr + ETH_ALEN, group_ssid, len);
10370 tag_index = find_template_frame_tag(tags, tags_total, 2);
10371 if (tag_index < 0) {
10372 sigma_dut_print(dut, DUT_MSG_ERROR,
10373 "can't find group id attribute");
10374 return -1;
10375 }
10376 if (replace_p2p_attribute(dut, &frame[tags[tag_index].offset],
10377 framelen - tags[tag_index].offset,
10378 IEEE80211_P2P_ATTR_GROUP_ID,
10379 group_id_attr,
10380 sizeof(group_id_attr))) {
10381 sigma_dut_print(dut, DUT_MSG_ERROR,
10382 "fail to replace group id attribute");
10383 return -1;
10384 }
10385 }
10386
10387 for (i = 0; i < count; i++) {
10388 if (wil6210_transmit_frame(dut, freq,
10389 WIL_TRANSMIT_FRAME_DEFAULT_ROC,
10390 frame, framelen)) {
10391 sigma_dut_print(dut, DUT_MSG_ERROR,
10392 "fail to transmit probe request frame");
10393 return -1;
10394 }
10395 }
10396
10397 return 0;
10398}
10399
10400
Lior David0fe101e2017-03-09 16:09:50 +020010401int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
10402 struct sigma_cmd *cmd)
10403{
10404 const char *frame_name = get_param(cmd, "framename");
10405 const char *mac = get_param(cmd, "dest_mac");
10406
10407 if (!frame_name || !mac) {
10408 sigma_dut_print(dut, DUT_MSG_ERROR,
10409 "framename and dest_mac must be provided");
10410 return -1;
10411 }
10412
10413 if (strcasecmp(frame_name, "brp") == 0) {
10414 const char *l_rx = get_param(cmd, "L-RX");
10415 int l_rx_i;
10416
10417 if (!l_rx) {
10418 sigma_dut_print(dut, DUT_MSG_ERROR,
10419 "L-RX must be provided");
10420 return -1;
10421 }
10422 l_rx_i = atoi(l_rx);
10423
10424 sigma_dut_print(dut, DUT_MSG_INFO,
10425 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
10426 mac, l_rx);
10427 if (l_rx_i != 16) {
10428 sigma_dut_print(dut, DUT_MSG_ERROR,
10429 "unsupported L-RX: %s", l_rx);
10430 return -1;
10431 }
10432
10433 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
10434 return -1;
10435 } else if (strcasecmp(frame_name, "ssw") == 0) {
10436 sigma_dut_print(dut, DUT_MSG_INFO,
10437 "dev_send_frame: SLS, dest_mac %s", mac);
10438 if (wil6210_send_sls(dut, mac))
10439 return -1;
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010440 } else if ((strcasecmp(frame_name, "probereq") == 0) ||
10441 (strcasecmp(frame_name, "devdiscreq") == 0)) {
10442 sigma_dut_print(dut, DUT_MSG_INFO,
10443 "dev_send_frame: %s, dest_mac %s", frame_name,
10444 mac);
10445 if (wil6210_send_p2p_frame_60g(dut, cmd, frame_name, mac))
10446 return -1;
Lior David0fe101e2017-03-09 16:09:50 +020010447 } else {
10448 sigma_dut_print(dut, DUT_MSG_ERROR,
10449 "unsupported frame type: %s", frame_name);
10450 return -1;
10451 }
10452
10453 return 1;
10454}
Alexei Avshalom Lazara90032d2019-05-02 13:34:02 +030010455
Lior David0fe101e2017-03-09 16:09:50 +020010456#endif /* __linux__ */
10457
10458
10459static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
10460 struct sigma_conn *conn,
10461 struct sigma_cmd *cmd)
10462{
10463 switch (get_driver_type()) {
10464#ifdef __linux__
10465 case DRIVER_WIL6210:
10466 return wil6210_send_frame_60g(dut, conn, cmd);
10467#endif /* __linux__ */
10468 default:
10469 send_resp(dut, conn, SIGMA_ERROR,
10470 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
10471 return 0;
10472 }
10473}
10474
10475
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010476static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
10477 const char *intf, struct sigma_cmd *cmd)
10478{
10479 const char *val, *addr;
10480 char buf[100];
10481
10482 addr = get_param(cmd, "DestMac");
10483 if (!addr) {
10484 send_resp(dut, conn, SIGMA_INVALID,
10485 "ErrorCode,AP MAC address is missing");
10486 return 0;
10487 }
10488
10489 val = get_param(cmd, "ANQPQuery_ID");
10490 if (!val) {
10491 send_resp(dut, conn, SIGMA_INVALID,
10492 "ErrorCode,Missing ANQPQuery_ID");
10493 return 0;
10494 }
10495
10496 if (strcasecmp(val, "NeighborReportReq") == 0) {
10497 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
10498 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
10499 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
10500 } else {
10501 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
10502 val);
10503 send_resp(dut, conn, SIGMA_INVALID,
10504 "ErrorCode,Invalid ANQPQuery_ID");
10505 return 0;
10506 }
10507
Ashwini Patild174f2c2017-04-13 16:49:46 +053010508 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
10509 * (Address3 = Wildcard BSSID when sent to not-associated AP;
10510 * if associated, AP BSSID).
10511 */
10512 if (wpa_command(intf, "SET gas_address3 1") < 0) {
10513 send_resp(dut, conn, SIGMA_ERROR,
10514 "ErrorCode,Failed to set gas_address3");
10515 return 0;
10516 }
10517
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010518 if (wpa_command(intf, buf) < 0) {
10519 send_resp(dut, conn, SIGMA_ERROR,
10520 "ErrorCode,Failed to send ANQP query");
10521 return 0;
10522 }
10523
10524 return 1;
10525}
10526
10527
10528static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
10529 struct sigma_conn *conn,
10530 const char *intf,
10531 struct sigma_cmd *cmd)
10532{
10533 const char *val = get_param(cmd, "FrameName");
10534
10535 if (val && strcasecmp(val, "ANQPQuery") == 0)
10536 return mbo_send_anqp_query(dut, conn, intf, cmd);
10537
10538 return 2;
10539}
10540
10541
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010542int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
10543 struct sigma_cmd *cmd)
10544{
10545 const char *intf = get_param(cmd, "Interface");
10546 const char *val;
10547 enum send_frame_type frame;
10548 enum send_frame_protection protected;
10549 char buf[100];
10550 unsigned char addr[ETH_ALEN];
10551 int res;
10552
Alexei Avshalom Lazar4a3c2f82019-05-02 13:35:37 +030010553 if (!intf)
10554 return -1;
10555
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010556 val = get_param(cmd, "program");
10557 if (val == NULL)
10558 val = get_param(cmd, "frame");
10559 if (val && strcasecmp(val, "TDLS") == 0)
10560 return cmd_sta_send_frame_tdls(dut, conn, cmd);
10561 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010562 strcasecmp(val, "HS2-R2") == 0 ||
10563 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010564 return cmd_sta_send_frame_hs2(dut, conn, cmd);
10565 if (val && strcasecmp(val, "VHT") == 0)
10566 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -070010567 if (val && strcasecmp(val, "HE") == 0)
10568 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -070010569 if (val && strcasecmp(val, "LOC") == 0)
10570 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +020010571 if (val && strcasecmp(val, "60GHz") == 0)
10572 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +053010573 if (val && strcasecmp(val, "MBO") == 0) {
10574 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
10575 if (res != 2)
10576 return res;
10577 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010578
10579 val = get_param(cmd, "TD_DISC");
10580 if (val) {
10581 if (hwaddr_aton(val, addr) < 0)
10582 return -1;
10583 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
10584 if (wpa_command(intf, buf) < 0) {
10585 send_resp(dut, conn, SIGMA_ERROR,
10586 "ErrorCode,Failed to send TDLS discovery");
10587 return 0;
10588 }
10589 return 1;
10590 }
10591
10592 val = get_param(cmd, "TD_Setup");
10593 if (val) {
10594 if (hwaddr_aton(val, addr) < 0)
10595 return -1;
10596 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
10597 if (wpa_command(intf, buf) < 0) {
10598 send_resp(dut, conn, SIGMA_ERROR,
10599 "ErrorCode,Failed to start TDLS setup");
10600 return 0;
10601 }
10602 return 1;
10603 }
10604
10605 val = get_param(cmd, "TD_TearDown");
10606 if (val) {
10607 if (hwaddr_aton(val, addr) < 0)
10608 return -1;
10609 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
10610 if (wpa_command(intf, buf) < 0) {
10611 send_resp(dut, conn, SIGMA_ERROR,
10612 "ErrorCode,Failed to tear down TDLS link");
10613 return 0;
10614 }
10615 return 1;
10616 }
10617
10618 val = get_param(cmd, "TD_ChannelSwitch");
10619 if (val) {
10620 /* TODO */
10621 send_resp(dut, conn, SIGMA_ERROR,
10622 "ErrorCode,TD_ChannelSwitch not yet supported");
10623 return 0;
10624 }
10625
10626 val = get_param(cmd, "TD_NF");
10627 if (val) {
10628 /* TODO */
10629 send_resp(dut, conn, SIGMA_ERROR,
10630 "ErrorCode,TD_NF not yet supported");
10631 return 0;
10632 }
10633
10634 val = get_param(cmd, "PMFFrameType");
10635 if (val == NULL)
10636 val = get_param(cmd, "FrameName");
10637 if (val == NULL)
10638 val = get_param(cmd, "Type");
10639 if (val == NULL)
10640 return -1;
10641 if (strcasecmp(val, "disassoc") == 0)
10642 frame = DISASSOC;
10643 else if (strcasecmp(val, "deauth") == 0)
10644 frame = DEAUTH;
10645 else if (strcasecmp(val, "saquery") == 0)
10646 frame = SAQUERY;
10647 else if (strcasecmp(val, "auth") == 0)
10648 frame = AUTH;
10649 else if (strcasecmp(val, "assocreq") == 0)
10650 frame = ASSOCREQ;
10651 else if (strcasecmp(val, "reassocreq") == 0)
10652 frame = REASSOCREQ;
10653 else if (strcasecmp(val, "neigreq") == 0) {
10654 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
10655
10656 val = get_param(cmd, "ssid");
10657 if (val == NULL)
10658 return -1;
10659
10660 res = send_neighbor_request(dut, intf, val);
10661 if (res) {
10662 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10663 "Failed to send neighbor report request");
10664 return 0;
10665 }
10666
10667 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +053010668 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
10669 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010670 sigma_dut_print(dut, DUT_MSG_DEBUG,
10671 "Got Transition Management Query");
10672
Ashwini Patil5acd7382017-04-13 15:55:04 +053010673 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010674 if (res) {
10675 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10676 "Failed to send Transition Management Query");
10677 return 0;
10678 }
10679
10680 return 1;
10681 } else {
10682 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10683 "PMFFrameType");
10684 return 0;
10685 }
10686
10687 val = get_param(cmd, "PMFProtected");
10688 if (val == NULL)
10689 val = get_param(cmd, "Protected");
10690 if (val == NULL)
10691 return -1;
10692 if (strcasecmp(val, "Correct-key") == 0 ||
10693 strcasecmp(val, "CorrectKey") == 0)
10694 protected = CORRECT_KEY;
10695 else if (strcasecmp(val, "IncorrectKey") == 0)
10696 protected = INCORRECT_KEY;
10697 else if (strcasecmp(val, "Unprotected") == 0)
10698 protected = UNPROTECTED;
10699 else {
10700 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10701 "PMFProtected");
10702 return 0;
10703 }
10704
10705 if (protected != UNPROTECTED &&
10706 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
10707 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
10708 "PMFProtected for auth/assocreq/reassocreq");
10709 return 0;
10710 }
10711
10712 if (if_nametoindex("sigmadut") == 0) {
10713 snprintf(buf, sizeof(buf),
10714 "iw dev %s interface add sigmadut type monitor",
10715 get_station_ifname());
10716 if (system(buf) != 0 ||
10717 if_nametoindex("sigmadut") == 0) {
10718 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
10719 "monitor interface with '%s'", buf);
10720 return -2;
10721 }
10722 }
10723
10724 if (system("ifconfig sigmadut up") != 0) {
10725 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
10726 "monitor interface up");
10727 return -2;
10728 }
10729
10730 return sta_inject_frame(dut, conn, frame, protected, NULL);
10731}
10732
10733
10734static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
10735 struct sigma_conn *conn,
10736 struct sigma_cmd *cmd,
10737 const char *ifname)
10738{
10739 char buf[200];
10740 const char *val;
10741
10742 val = get_param(cmd, "ClearARP");
10743 if (val && atoi(val) == 1) {
10744 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
10745 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10746 if (system(buf) != 0) {
10747 send_resp(dut, conn, SIGMA_ERROR,
10748 "errorCode,Failed to clear ARP cache");
10749 return 0;
10750 }
10751 }
10752
10753 return 1;
10754}
10755
10756
10757int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
10758 struct sigma_cmd *cmd)
10759{
10760 const char *intf = get_param(cmd, "Interface");
10761 const char *val;
10762
10763 if (intf == NULL)
10764 return -1;
10765
10766 val = get_param(cmd, "program");
10767 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +030010768 strcasecmp(val, "HS2-R2") == 0 ||
10769 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010770 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
10771
10772 return -1;
10773}
10774
10775
10776static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
10777 struct sigma_cmd *cmd)
10778{
10779 const char *intf = get_param(cmd, "Interface");
10780 const char *mac = get_param(cmd, "MAC");
10781
10782 if (intf == NULL || mac == NULL)
10783 return -1;
10784
10785 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
10786 "interface %s to %s", intf, mac);
10787
10788 if (dut->set_macaddr) {
10789 char buf[128];
10790 int res;
10791 if (strcasecmp(mac, "default") == 0) {
10792 res = snprintf(buf, sizeof(buf), "%s",
10793 dut->set_macaddr);
10794 dut->tmp_mac_addr = 0;
10795 } else {
10796 res = snprintf(buf, sizeof(buf), "%s %s",
10797 dut->set_macaddr, mac);
10798 dut->tmp_mac_addr = 1;
10799 }
10800 if (res < 0 || res >= (int) sizeof(buf))
10801 return -1;
10802 if (system(buf) != 0) {
10803 send_resp(dut, conn, SIGMA_ERROR,
10804 "errorCode,Failed to set MAC "
10805 "address");
10806 return 0;
10807 }
10808 return 1;
10809 }
10810
10811 if (strcasecmp(mac, "default") == 0)
10812 return 1;
10813
10814 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10815 "command");
10816 return 0;
10817}
10818
10819
10820static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
10821 struct sigma_conn *conn, const char *intf,
10822 int val)
10823{
10824 char buf[200];
10825 int res;
10826
10827 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
10828 intf, val);
10829 if (res < 0 || res >= (int) sizeof(buf))
10830 return -1;
10831 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10832 if (system(buf) != 0) {
10833 send_resp(dut, conn, SIGMA_ERROR,
10834 "errorCode,Failed to configure offchannel mode");
10835 return 0;
10836 }
10837
10838 return 1;
10839}
10840
10841
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010842static int off_chan_val(enum sec_ch_offset off)
10843{
10844 switch (off) {
10845 case SEC_CH_NO:
10846 return 0;
10847 case SEC_CH_40ABOVE:
10848 return 40;
10849 case SEC_CH_40BELOW:
10850 return -40;
10851 }
10852
10853 return 0;
10854}
10855
10856
10857static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
10858 const char *intf, int off_ch_num,
10859 enum sec_ch_offset sec)
10860{
10861 char buf[200];
10862 int res;
10863
10864 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
10865 intf, off_ch_num);
10866 if (res < 0 || res >= (int) sizeof(buf))
10867 return -1;
10868 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10869 if (system(buf) != 0) {
10870 send_resp(dut, conn, SIGMA_ERROR,
10871 "errorCode,Failed to set offchan");
10872 return 0;
10873 }
10874
10875 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
10876 intf, off_chan_val(sec));
10877 if (res < 0 || res >= (int) sizeof(buf))
10878 return -1;
10879 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10880 if (system(buf) != 0) {
10881 send_resp(dut, conn, SIGMA_ERROR,
10882 "errorCode,Failed to set sec chan offset");
10883 return 0;
10884 }
10885
10886 return 1;
10887}
10888
10889
10890static int tdls_set_offchannel_offset(struct sigma_dut *dut,
10891 struct sigma_conn *conn,
10892 const char *intf, int off_ch_num,
10893 enum sec_ch_offset sec)
10894{
10895 char buf[200];
10896 int res;
10897
10898 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
10899 off_ch_num);
10900 if (res < 0 || res >= (int) sizeof(buf))
10901 return -1;
10902 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10903
10904 if (wpa_command(intf, buf) < 0) {
10905 send_resp(dut, conn, SIGMA_ERROR,
10906 "ErrorCode,Failed to set offchan");
10907 return 0;
10908 }
10909 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
10910 off_chan_val(sec));
10911 if (res < 0 || res >= (int) sizeof(buf))
10912 return -1;
10913
10914 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10915
10916 if (wpa_command(intf, buf) < 0) {
10917 send_resp(dut, conn, SIGMA_ERROR,
10918 "ErrorCode,Failed to set sec chan offset");
10919 return 0;
10920 }
10921
10922 return 1;
10923}
10924
10925
10926static int tdls_set_offchannel_mode(struct sigma_dut *dut,
10927 struct sigma_conn *conn,
10928 const char *intf, int val)
10929{
10930 char buf[200];
10931 int res;
10932
10933 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
10934 val);
10935 if (res < 0 || res >= (int) sizeof(buf))
10936 return -1;
10937 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10938
10939 if (wpa_command(intf, buf) < 0) {
10940 send_resp(dut, conn, SIGMA_ERROR,
10941 "ErrorCode,Failed to configure offchannel mode");
10942 return 0;
10943 }
10944
10945 return 1;
10946}
10947
10948
10949static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
10950 struct sigma_conn *conn,
10951 struct sigma_cmd *cmd)
10952{
10953 const char *val;
10954 enum {
10955 CHSM_NOT_SET,
10956 CHSM_ENABLE,
10957 CHSM_DISABLE,
10958 CHSM_REJREQ,
10959 CHSM_UNSOLRESP
10960 } chsm = CHSM_NOT_SET;
10961 int off_ch_num = -1;
10962 enum sec_ch_offset sec_ch = SEC_CH_NO;
10963 int res;
10964
10965 val = get_param(cmd, "Uapsd");
10966 if (val) {
10967 char buf[100];
10968 if (strcasecmp(val, "Enable") == 0)
10969 snprintf(buf, sizeof(buf), "SET ps 99");
10970 else if (strcasecmp(val, "Disable") == 0)
10971 snprintf(buf, sizeof(buf), "SET ps 98");
10972 else {
10973 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10974 "Unsupported uapsd parameter value");
10975 return 0;
10976 }
10977 if (wpa_command(intf, buf)) {
10978 send_resp(dut, conn, SIGMA_ERROR,
10979 "ErrorCode,Failed to change U-APSD "
10980 "powersave mode");
10981 return 0;
10982 }
10983 }
10984
10985 val = get_param(cmd, "TPKTIMER");
10986 if (val && strcasecmp(val, "DISABLE") == 0) {
10987 if (wpa_command(intf, "SET tdls_testing 0x100")) {
10988 send_resp(dut, conn, SIGMA_ERROR,
10989 "ErrorCode,Failed to enable no TPK "
10990 "expiration test mode");
10991 return 0;
10992 }
10993 dut->no_tpk_expiration = 1;
10994 }
10995
10996 val = get_param(cmd, "ChSwitchMode");
10997 if (val) {
10998 if (strcasecmp(val, "Enable") == 0 ||
10999 strcasecmp(val, "Initiate") == 0)
11000 chsm = CHSM_ENABLE;
11001 else if (strcasecmp(val, "Disable") == 0 ||
11002 strcasecmp(val, "passive") == 0)
11003 chsm = CHSM_DISABLE;
11004 else if (strcasecmp(val, "RejReq") == 0)
11005 chsm = CHSM_REJREQ;
11006 else if (strcasecmp(val, "UnSolResp") == 0)
11007 chsm = CHSM_UNSOLRESP;
11008 else {
11009 send_resp(dut, conn, SIGMA_ERROR,
11010 "ErrorCode,Unknown ChSwitchMode value");
11011 return 0;
11012 }
11013 }
11014
11015 val = get_param(cmd, "OffChNum");
11016 if (val) {
11017 off_ch_num = atoi(val);
11018 if (off_ch_num == 0) {
11019 send_resp(dut, conn, SIGMA_ERROR,
11020 "ErrorCode,Invalid OffChNum");
11021 return 0;
11022 }
11023 }
11024
11025 val = get_param(cmd, "SecChOffset");
11026 if (val) {
11027 if (strcmp(val, "20") == 0)
11028 sec_ch = SEC_CH_NO;
11029 else if (strcasecmp(val, "40above") == 0)
11030 sec_ch = SEC_CH_40ABOVE;
11031 else if (strcasecmp(val, "40below") == 0)
11032 sec_ch = SEC_CH_40BELOW;
11033 else {
11034 send_resp(dut, conn, SIGMA_ERROR,
11035 "ErrorCode,Unknown SecChOffset value");
11036 return 0;
11037 }
11038 }
11039
11040 if (chsm == CHSM_NOT_SET) {
11041 /* no offchannel changes requested */
11042 return 1;
11043 }
11044
11045 if (strcmp(intf, get_main_ifname()) != 0 &&
11046 strcmp(intf, get_station_ifname()) != 0) {
11047 send_resp(dut, conn, SIGMA_ERROR,
11048 "ErrorCode,Unknown interface");
11049 return 0;
11050 }
11051
11052 switch (chsm) {
11053 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030011054 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011055 break;
11056 case CHSM_ENABLE:
11057 if (off_ch_num < 0) {
11058 send_resp(dut, conn, SIGMA_ERROR,
11059 "ErrorCode,Missing OffChNum argument");
11060 return 0;
11061 }
11062 if (wifi_chip_type == DRIVER_WCN) {
11063 res = tdls_set_offchannel_offset(dut, conn, intf,
11064 off_ch_num, sec_ch);
11065 } else {
11066 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11067 sec_ch);
11068 }
11069 if (res != 1)
11070 return res;
11071 if (wifi_chip_type == DRIVER_WCN)
11072 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
11073 else
11074 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
11075 break;
11076 case CHSM_DISABLE:
11077 if (wifi_chip_type == DRIVER_WCN)
11078 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
11079 else
11080 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
11081 break;
11082 case CHSM_REJREQ:
11083 if (wifi_chip_type == DRIVER_WCN)
11084 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
11085 else
11086 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
11087 break;
11088 case CHSM_UNSOLRESP:
11089 if (off_ch_num < 0) {
11090 send_resp(dut, conn, SIGMA_ERROR,
11091 "ErrorCode,Missing OffChNum argument");
11092 return 0;
11093 }
11094 if (wifi_chip_type == DRIVER_WCN) {
11095 res = tdls_set_offchannel_offset(dut, conn, intf,
11096 off_ch_num, sec_ch);
11097 } else {
11098 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
11099 sec_ch);
11100 }
11101 if (res != 1)
11102 return res;
11103 if (wifi_chip_type == DRIVER_WCN)
11104 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
11105 else
11106 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
11107 break;
11108 }
11109
11110 return res;
11111}
11112
11113
11114static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11115 struct sigma_conn *conn,
11116 struct sigma_cmd *cmd)
11117{
11118 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011119 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011120
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080011121 novap_reset(dut, intf);
11122
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011123 val = get_param(cmd, "nss_mcs_opt");
11124 if (val) {
11125 /* String (nss_operating_mode; mcs_operating_mode) */
11126 int nss, mcs;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011127 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011128
11129 token = strdup(val);
11130 if (!token)
11131 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011132 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011133 if (!result) {
11134 sigma_dut_print(dut, DUT_MSG_ERROR,
11135 "VHT NSS not specified");
11136 goto failed;
11137 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011138 if (strcasecmp(result, "def") != 0) {
11139 nss = atoi(result);
11140 if (nss == 4)
11141 ath_disable_txbf(dut, intf);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011142 if (run_iwpriv(dut, intf, "nss %d", nss) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011143 goto failed;
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011144
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011145 }
11146
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053011147 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053011148 if (!result) {
11149 sigma_dut_print(dut, DUT_MSG_ERROR,
11150 "VHT MCS not specified");
11151 goto failed;
11152 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011153 if (strcasecmp(result, "def") == 0) {
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011154 if (run_iwpriv(dut, intf, "set11NRates 0") < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011155 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011156 } else {
11157 mcs = atoi(result);
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011158 if (run_iwpriv(dut, intf, "vhtmcs %d", mcs) < 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011159 goto failed;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011160 }
11161 /* Channel width gets messed up, fix this */
Priyadharshini Gowthamanb999e9e2019-04-22 15:45:55 -070011162 run_iwpriv(dut, intf, "chwidth %d", dut->chwidth);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011163 }
11164
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053011165 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011166 return 1;
11167failed:
11168 free(token);
11169 return 0;
11170}
11171
11172
11173static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
11174 struct sigma_conn *conn,
11175 struct sigma_cmd *cmd)
11176{
11177 switch (get_driver_type()) {
11178 case DRIVER_ATHEROS:
11179 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
11180 default:
11181 send_resp(dut, conn, SIGMA_ERROR,
11182 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
11183 return 0;
11184 }
11185}
11186
11187
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011188static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11189 struct sigma_conn *conn,
11190 struct sigma_cmd *cmd)
11191{
11192 const char *val;
11193 char *token = NULL, *result;
11194 char buf[60];
11195
11196 val = get_param(cmd, "nss_mcs_opt");
11197 if (val) {
11198 /* String (nss_operating_mode; mcs_operating_mode) */
11199 int nss, mcs, ratecode;
11200 char *saveptr;
11201
11202 token = strdup(val);
11203 if (!token)
11204 return -2;
11205
11206 result = strtok_r(token, ";", &saveptr);
11207 if (!result) {
11208 sigma_dut_print(dut, DUT_MSG_ERROR,
11209 "HE NSS not specified");
11210 goto failed;
11211 }
11212 nss = 1;
11213 if (strcasecmp(result, "def") != 0)
11214 nss = atoi(result);
11215
11216 result = strtok_r(NULL, ";", &saveptr);
11217 if (!result) {
11218 sigma_dut_print(dut, DUT_MSG_ERROR,
11219 "HE MCS not specified");
11220 goto failed;
11221 }
11222 mcs = 7;
11223 if (strcasecmp(result, "def") != 0)
11224 mcs = atoi(result);
11225
Arif Hussain557bf412018-05-25 17:29:36 -070011226 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011227 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070011228 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011229 } else if (nss > 2) {
11230 sigma_dut_print(dut, DUT_MSG_ERROR,
11231 "HE NSS %d not supported", nss);
11232 goto failed;
11233 }
11234
Arif Hussain557bf412018-05-25 17:29:36 -070011235 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
11236 if (system(buf) != 0) {
11237 sigma_dut_print(dut, DUT_MSG_ERROR,
11238 "nss_mcs_opt: iwpriv %s nss %d failed",
11239 intf, nss);
11240 goto failed;
11241 }
Arif Hussainac6c5112018-05-25 17:34:00 -070011242 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070011243
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011244 /* Add the MCS to the ratecode */
11245 if (mcs >= 0 && mcs <= 11) {
11246 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070011247#ifdef NL80211_SUPPORT
11248 if (dut->device_type == STA_testbed) {
11249 enum he_mcs_config mcs_config;
11250 int ret;
11251
11252 if (mcs <= 7)
11253 mcs_config = HE_80_MCS0_7;
11254 else if (mcs <= 9)
11255 mcs_config = HE_80_MCS0_9;
11256 else
11257 mcs_config = HE_80_MCS0_11;
11258 ret = sta_set_he_mcs(dut, intf, mcs_config);
11259 if (ret) {
11260 sigma_dut_print(dut, DUT_MSG_ERROR,
11261 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
11262 mcs, mcs_config, ret);
11263 goto failed;
11264 }
11265 }
11266#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011267 } else {
11268 sigma_dut_print(dut, DUT_MSG_ERROR,
11269 "HE MCS %d not supported", mcs);
11270 goto failed;
11271 }
11272 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
11273 intf, ratecode);
11274 if (system(buf) != 0) {
11275 sigma_dut_print(dut, DUT_MSG_ERROR,
11276 "iwpriv setting of 11ax rates failed");
11277 goto failed;
11278 }
11279 free(token);
11280 }
11281
11282 val = get_param(cmd, "GI");
11283 if (val) {
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011284 int fix_rate_sgi;
11285
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011286 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011287 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011288 fix_rate_sgi = 1;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011289 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011290 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
11291 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011292 fix_rate_sgi = 2;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011293 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070011294 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
11295 intf);
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011296 fix_rate_sgi = 3;
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011297 } else {
11298 send_resp(dut, conn, SIGMA_ERROR,
11299 "errorCode,GI value not supported");
11300 return 0;
11301 }
11302 if (system(buf) != 0) {
11303 send_resp(dut, conn, SIGMA_ERROR,
11304 "errorCode,Failed to set shortgi");
11305 return 0;
11306 }
Kiran Kumar Lokeref6592d72019-01-16 18:44:00 -080011307 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d",
11308 intf, fix_rate_sgi);
11309 if (system(buf) != 0) {
11310 send_resp(dut, conn, SIGMA_ERROR,
11311 "errorCode,Failed to set fix rate shortgi");
11312 return STATUS_SENT;
11313 }
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011314 }
11315
Subhani Shaik8e7a3052018-04-24 14:03:00 -070011316 val = get_param(cmd, "LTF");
11317 if (val) {
11318#ifdef NL80211_SUPPORT
11319 if (strcmp(val, "3.2") == 0) {
11320 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
11321 } if (strcmp(val, "6.4") == 0) {
11322 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
11323 } else if (strcmp(val, "12.8") == 0) {
11324 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
11325 } else {
11326 send_resp(dut, conn, SIGMA_ERROR,
11327 "errorCode, LTF value not supported");
11328 return 0;
11329 }
11330#else /* NL80211_SUPPORT */
11331 sigma_dut_print(dut, DUT_MSG_ERROR,
11332 "LTF cannot be set without NL80211_SUPPORT defined");
11333 return -2;
11334#endif /* NL80211_SUPPORT */
11335 }
11336
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070011337 val = get_param(cmd, "TxSUPPDU");
11338 if (val) {
11339 int set_val = 1;
11340
11341 if (strcasecmp(val, "Enable") == 0)
11342 set_val = 1;
11343 else if (strcasecmp(val, "Disable") == 0)
11344 set_val = 0;
11345
11346 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
11347 send_resp(dut, conn, SIGMA_ERROR,
11348 "ErrorCode,Failed to set Tx SU PPDU config");
11349 return 0;
11350 }
11351 }
11352
Arif Hussain480d5f42019-03-12 14:40:42 -070011353 val = get_param(cmd, "TWT_Setup");
11354 if (val) {
11355 if (strcasecmp(val, "Request") == 0) {
11356 if (sta_twt_request(dut, conn, cmd)) {
11357 send_resp(dut, conn, SIGMA_ERROR,
11358 "ErrorCode,sta_twt_request failed");
11359 return STATUS_SENT;
11360 }
11361 } else if (strcasecmp(val, "Teardown") == 0) {
11362 if (sta_twt_teardown(dut, conn, cmd)) {
11363 send_resp(dut, conn, SIGMA_ERROR,
11364 "ErrorCode,sta_twt_teardown failed");
11365 return STATUS_SENT;
11366 }
11367 }
11368 }
11369
Kiran Kumar Lokere50eb2cd2018-12-18 18:31:28 -080011370 val = get_param(cmd, "transmitOMI");
11371 if (val && sta_transmit_omi(dut, conn, cmd)) {
11372 send_resp(dut, conn, SIGMA_ERROR,
11373 "ErrorCode,sta_transmit_omi failed");
11374 return STATUS_SENT;
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070011375 }
11376
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080011377 val = get_param(cmd, "Powersave");
11378 if (val) {
11379 char buf[60];
11380
11381 if (strcasecmp(val, "off") == 0) {
11382 snprintf(buf, sizeof(buf),
11383 "iwpriv %s setPower 2", intf);
11384 if (system(buf) != 0) {
11385 sigma_dut_print(dut, DUT_MSG_ERROR,
11386 "iwpriv setPower 2 failed");
11387 return 0;
11388 }
11389 } else if (strcasecmp(val, "on") == 0) {
11390 snprintf(buf, sizeof(buf),
11391 "iwpriv %s setPower 1", intf);
11392 if (system(buf) != 0) {
11393 sigma_dut_print(dut, DUT_MSG_ERROR,
11394 "iwpriv setPower 1 failed");
11395 return 0;
11396 }
11397 } else {
11398 sigma_dut_print(dut, DUT_MSG_ERROR,
11399 "Unsupported Powersave value '%s'",
11400 val);
11401 return -1;
11402 }
11403 }
11404
Kiran Kumar Lokere2c4b7ce2019-01-30 12:02:28 -080011405 val = get_param(cmd, "MU_EDCA");
11406 if (val) {
11407 if (strcasecmp(val, "Override") == 0) {
11408 if (sta_set_mu_edca_override(dut, intf, 1)) {
11409 send_resp(dut, conn, SIGMA_ERROR,
11410 "errorCode,MU EDCA override set failed");
11411 return STATUS_SENT;
11412 }
11413 } else if (strcasecmp(val, "Disable") == 0) {
11414 if (sta_set_mu_edca_override(dut, intf, 0)) {
11415 send_resp(dut, conn, SIGMA_ERROR,
11416 "errorCode,MU EDCA override disable failed");
11417 return STATUS_SENT;
11418 }
11419 }
11420 }
11421
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011422 return 1;
11423
11424failed:
11425 free(token);
11426 return -2;
11427}
11428
11429
11430static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
11431 struct sigma_conn *conn,
11432 struct sigma_cmd *cmd)
11433{
11434 switch (get_driver_type()) {
11435 case DRIVER_WCN:
11436 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
11437 default:
11438 send_resp(dut, conn, SIGMA_ERROR,
11439 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
11440 return 0;
11441 }
11442}
11443
11444
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080011445static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
11446 struct sigma_conn *conn,
11447 struct sigma_cmd *cmd)
11448{
11449 const char *val;
11450
11451 val = get_param(cmd, "powersave");
11452 if (val) {
11453 char buf[60];
11454
11455 if (strcasecmp(val, "off") == 0) {
11456 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
11457 intf);
11458 if (system(buf) != 0) {
11459 sigma_dut_print(dut, DUT_MSG_ERROR,
11460 "iwpriv setPower 2 failed");
11461 return 0;
11462 }
11463 } else if (strcasecmp(val, "on") == 0) {
11464 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
11465 intf);
11466 if (system(buf) != 0) {
11467 sigma_dut_print(dut, DUT_MSG_ERROR,
11468 "iwpriv setPower 1 failed");
11469 return 0;
11470 }
11471 } else {
11472 sigma_dut_print(dut, DUT_MSG_ERROR,
11473 "Unsupported power save config");
11474 return -1;
11475 }
11476 return 1;
11477 }
11478
11479 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
11480
11481 return 0;
11482}
11483
11484
Ashwini Patil5acd7382017-04-13 15:55:04 +053011485static int btm_query_candidate_list(struct sigma_dut *dut,
11486 struct sigma_conn *conn,
11487 struct sigma_cmd *cmd)
11488{
11489 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
11490 int len, ret;
11491 char buf[10];
11492
11493 /*
11494 * Neighbor Report elements format:
11495 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
11496 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
11497 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
11498 */
11499
11500 bssid = get_param(cmd, "Nebor_BSSID");
11501 if (!bssid) {
11502 send_resp(dut, conn, SIGMA_INVALID,
11503 "errorCode,Nebor_BSSID is missing");
11504 return 0;
11505 }
11506
11507 info = get_param(cmd, "Nebor_Bssid_Info");
11508 if (!info) {
11509 sigma_dut_print(dut, DUT_MSG_INFO,
11510 "Using default value for Nebor_Bssid_Info: %s",
11511 DEFAULT_NEIGHBOR_BSSID_INFO);
11512 info = DEFAULT_NEIGHBOR_BSSID_INFO;
11513 }
11514
11515 op_class = get_param(cmd, "Nebor_Op_Class");
11516 if (!op_class) {
11517 send_resp(dut, conn, SIGMA_INVALID,
11518 "errorCode,Nebor_Op_Class is missing");
11519 return 0;
11520 }
11521
11522 ch = get_param(cmd, "Nebor_Op_Ch");
11523 if (!ch) {
11524 send_resp(dut, conn, SIGMA_INVALID,
11525 "errorCode,Nebor_Op_Ch is missing");
11526 return 0;
11527 }
11528
11529 phy_type = get_param(cmd, "Nebor_Phy_Type");
11530 if (!phy_type) {
11531 sigma_dut_print(dut, DUT_MSG_INFO,
11532 "Using default value for Nebor_Phy_Type: %s",
11533 DEFAULT_NEIGHBOR_PHY_TYPE);
11534 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
11535 }
11536
11537 /* Parse optional subelements */
11538 buf[0] = '\0';
11539 pref = get_param(cmd, "Nebor_Pref");
11540 if (pref) {
11541 /* hexdump for preferrence subelement */
11542 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
11543 if (ret < 0 || ret >= (int) sizeof(buf)) {
11544 sigma_dut_print(dut, DUT_MSG_ERROR,
11545 "snprintf failed for optional subelement ret: %d",
11546 ret);
11547 send_resp(dut, conn, SIGMA_ERROR,
11548 "errorCode,snprintf failed for subelement");
11549 return 0;
11550 }
11551 }
11552
11553 if (!dut->btm_query_cand_list) {
11554 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
11555 if (!dut->btm_query_cand_list) {
11556 send_resp(dut, conn, SIGMA_ERROR,
11557 "errorCode,Failed to allocate memory for btm_query_cand_list");
11558 return 0;
11559 }
11560 }
11561
11562 len = strlen(dut->btm_query_cand_list);
11563 ret = snprintf(dut->btm_query_cand_list + len,
11564 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
11565 bssid, info, op_class, ch, phy_type, buf);
11566 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
11567 sigma_dut_print(dut, DUT_MSG_ERROR,
11568 "snprintf failed for neighbor report list ret: %d",
11569 ret);
11570 send_resp(dut, conn, SIGMA_ERROR,
11571 "errorCode,snprintf failed for neighbor report");
11572 free(dut->btm_query_cand_list);
11573 dut->btm_query_cand_list = NULL;
11574 return 0;
11575 }
11576
11577 return 1;
11578}
11579
11580
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011581int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
11582 struct sigma_ese_alloc *allocs, int *allocs_size)
11583{
11584 int max_count = *allocs_size;
11585 int count = 0, i;
11586 const char *val;
11587
11588 do {
11589 val = get_param_indexed(cmd, "AllocID", count);
11590 if (val)
11591 count++;
11592 } while (val);
11593
11594 if (count == 0 || count > max_count) {
11595 sigma_dut_print(dut, DUT_MSG_ERROR,
11596 "Invalid number of allocations(%d)", count);
11597 return -1;
11598 }
11599
11600 for (i = 0; i < count; i++) {
11601 val = get_param_indexed(cmd, "PercentBI", i);
11602 if (!val) {
11603 sigma_dut_print(dut, DUT_MSG_ERROR,
11604 "Missing PercentBI parameter at index %d",
11605 i);
11606 return -1;
11607 }
11608 allocs[i].percent_bi = atoi(val);
11609
11610 val = get_param_indexed(cmd, "SrcAID", i);
11611 if (val)
11612 allocs[i].src_aid = strtol(val, NULL, 0);
11613 else
11614 allocs[i].src_aid = ESE_BCAST_AID;
11615
11616 val = get_param_indexed(cmd, "DestAID", i);
11617 if (val)
11618 allocs[i].dst_aid = strtol(val, NULL, 0);
11619 else
11620 allocs[i].dst_aid = ESE_BCAST_AID;
11621
11622 allocs[i].type = ESE_CBAP;
11623 sigma_dut_print(dut, DUT_MSG_INFO,
11624 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
11625 i, allocs[i].percent_bi, allocs[i].src_aid,
11626 allocs[i].dst_aid);
11627 }
11628
11629 *allocs_size = count;
11630 return 0;
11631}
11632
11633
11634static int sta_set_60g_ese(struct sigma_dut *dut, int count,
11635 struct sigma_ese_alloc *allocs)
11636{
11637 switch (get_driver_type()) {
11638#ifdef __linux__
11639 case DRIVER_WIL6210:
11640 if (wil6210_set_ese(dut, count, allocs))
11641 return -1;
11642 return 1;
11643#endif /* __linux__ */
11644 default:
11645 sigma_dut_print(dut, DUT_MSG_ERROR,
11646 "Unsupported sta_set_60g_ese with the current driver");
11647 return -1;
11648 }
11649}
11650
11651
11652static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
11653 struct sigma_conn *conn,
11654 struct sigma_cmd *cmd)
11655{
11656 const char *val;
11657
11658 val = get_param(cmd, "ExtSchIE");
11659 if (val && !strcasecmp(val, "Enable")) {
11660 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
11661 int count = MAX_ESE_ALLOCS;
11662
11663 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
11664 return -1;
11665 return sta_set_60g_ese(dut, count, allocs);
11666 }
11667
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011668 val = get_param(cmd, "MCS_FixedRate");
11669 if (val) {
11670 int sta_mcs = atoi(val);
11671
11672 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
11673 sta_mcs);
11674 wil6210_set_force_mcs(dut, 1, sta_mcs);
11675
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011676 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020011677 }
11678
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011679 send_resp(dut, conn, SIGMA_ERROR,
11680 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020011681 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011682}
11683
11684
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011685static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
11686 struct sigma_cmd *cmd)
11687{
11688 const char *intf = get_param(cmd, "Interface");
11689 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011690 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011691
11692 if (intf == NULL || prog == NULL)
11693 return -1;
11694
Ashwini Patil5acd7382017-04-13 15:55:04 +053011695 /* BSS Transition candidate list for BTM query */
11696 val = get_param(cmd, "Nebor_BSSID");
11697 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
11698 return 0;
11699
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011700 if (strcasecmp(prog, "TDLS") == 0)
11701 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
11702
11703 if (strcasecmp(prog, "VHT") == 0)
11704 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
11705
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080011706 if (strcasecmp(prog, "HE") == 0)
11707 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
11708
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011709 if (strcasecmp(prog, "MBO") == 0) {
11710 val = get_param(cmd, "Cellular_Data_Cap");
11711 if (val &&
11712 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
11713 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053011714
11715 val = get_param(cmd, "Ch_Pref");
11716 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
11717 return 0;
11718
Ashwini Patil68d02cd2017-01-10 15:39:16 +053011719 return 1;
11720 }
11721
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020011722 if (strcasecmp(prog, "60GHz") == 0)
11723 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
11724
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011725 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
11726 return 0;
11727}
11728
11729
11730static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
11731 struct sigma_cmd *cmd)
11732{
11733 const char *intf = get_param(cmd, "Interface");
11734 const char *mode = get_param(cmd, "Mode");
11735 int res;
11736
11737 if (intf == NULL || mode == NULL)
11738 return -1;
11739
11740 if (strcasecmp(mode, "On") == 0)
11741 res = wpa_command(intf, "SET radio_disabled 0");
11742 else if (strcasecmp(mode, "Off") == 0)
11743 res = wpa_command(intf, "SET radio_disabled 1");
11744 else
11745 return -1;
11746
11747 if (res) {
11748 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11749 "radio mode");
11750 return 0;
11751 }
11752
11753 return 1;
11754}
11755
11756
11757static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
11758 struct sigma_cmd *cmd)
11759{
11760 const char *intf = get_param(cmd, "Interface");
11761 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011762 const char *prog = get_param(cmd, "program");
11763 const char *powersave = get_param(cmd, "powersave");
11764 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011765
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011766 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011767 return -1;
11768
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011769 if (prog && strcasecmp(prog, "60GHz") == 0) {
11770 /*
11771 * The CAPI mode parameter does not exist in 60G
11772 * unscheduled PS.
11773 */
11774 if (strcasecmp(powersave, "unscheduled") == 0)
11775 res = set_ps(intf, dut, 1);
Alexei Avshalom Lazar2f6fdb42019-02-04 14:16:08 +020011776 } else if (prog && get_driver_type() == DRIVER_WCN &&
11777 strcasecmp(prog, "HE") == 0) {
11778 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020011779 } else {
11780 if (mode == NULL)
11781 return -1;
11782
11783 if (strcasecmp(mode, "On") == 0)
11784 res = set_ps(intf, dut, 1);
11785 else if (strcasecmp(mode, "Off") == 0)
11786 res = set_ps(intf, dut, 0);
11787 else
11788 return -1;
11789 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011790
11791 if (res) {
11792 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
11793 "power save mode");
11794 return 0;
11795 }
11796
11797 return 1;
11798}
11799
11800
11801static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
11802 struct sigma_cmd *cmd)
11803{
11804 const char *intf = get_param(cmd, "Interface");
11805 const char *val, *bssid;
11806 int res;
11807 char *buf;
11808 size_t buf_len;
11809
11810 val = get_param(cmd, "BSSID_FILTER");
11811 if (val == NULL)
11812 return -1;
11813
11814 bssid = get_param(cmd, "BSSID_List");
11815 if (atoi(val) == 0 || bssid == NULL) {
11816 /* Disable BSSID filter */
11817 if (wpa_command(intf, "SET bssid_filter ")) {
11818 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
11819 "to disable BSSID filter");
11820 return 0;
11821 }
11822
11823 return 1;
11824 }
11825
11826 buf_len = 100 + strlen(bssid);
11827 buf = malloc(buf_len);
11828 if (buf == NULL)
11829 return -1;
11830
11831 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
11832 res = wpa_command(intf, buf);
11833 free(buf);
11834 if (res) {
11835 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
11836 "BSSID filter");
11837 return 0;
11838 }
11839
11840 return 1;
11841}
11842
11843
11844static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
11845 struct sigma_cmd *cmd)
11846{
11847 const char *intf = get_param(cmd, "Interface");
11848 const char *val;
11849
11850 /* TODO: ARP */
11851
11852 val = get_param(cmd, "HS2_CACHE_PROFILE");
11853 if (val && strcasecmp(val, "All") == 0)
11854 hs2_clear_credentials(intf);
11855
11856 return 1;
11857}
11858
11859
11860static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
11861 struct sigma_cmd *cmd)
11862{
11863 const char *intf = get_param(cmd, "Interface");
11864 const char *key_type = get_param(cmd, "KeyType");
11865 char buf[100], resp[200];
11866
11867 if (key_type == NULL)
11868 return -1;
11869
11870 if (strcasecmp(key_type, "GTK") == 0) {
11871 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
11872 strncmp(buf, "FAIL", 4) == 0) {
11873 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11874 "not fetch current GTK");
11875 return 0;
11876 }
11877 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
11878 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11879 return 0;
11880 } else {
11881 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
11882 "KeyType");
11883 return 0;
11884 }
11885
11886 return 1;
11887}
11888
11889
11890static int hs2_set_policy(struct sigma_dut *dut)
11891{
11892#ifdef ANDROID
11893 system("ip rule del prio 23000");
11894 if (system("ip rule add from all lookup main prio 23000") != 0) {
11895 sigma_dut_print(dut, DUT_MSG_ERROR,
11896 "Failed to run:ip rule add from all lookup main prio");
11897 return -1;
11898 }
11899 if (system("ip route flush cache") != 0) {
11900 sigma_dut_print(dut, DUT_MSG_ERROR,
11901 "Failed to run ip route flush cache");
11902 return -1;
11903 }
11904 return 1;
11905#else /* ANDROID */
11906 return 0;
11907#endif /* ANDROID */
11908}
11909
11910
11911static int cmd_sta_hs2_associate(struct sigma_dut *dut,
11912 struct sigma_conn *conn,
11913 struct sigma_cmd *cmd)
11914{
11915 const char *intf = get_param(cmd, "Interface");
11916 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030011917 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011918 struct wpa_ctrl *ctrl;
Jouni Malinen3aa72862019-05-29 23:14:51 +030011919 int res, r;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011920 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
11921 int tries = 0;
11922 int ignore_blacklist = 0;
11923 const char *events[] = {
11924 "CTRL-EVENT-CONNECTED",
11925 "INTERWORKING-BLACKLISTED",
11926 "INTERWORKING-NO-MATCH",
11927 NULL
11928 };
11929
11930 start_sta_mode(dut);
11931
Jouni Malinen439352d2018-09-13 03:42:23 +030011932 if (band) {
11933 if (strcmp(band, "2.4") == 0) {
11934 wpa_command(intf, "SET setband 2G");
11935 } else if (strcmp(band, "5") == 0) {
11936 wpa_command(intf, "SET setband 5G");
11937 } else {
11938 send_resp(dut, conn, SIGMA_ERROR,
11939 "errorCode,Unsupported band");
11940 return 0;
11941 }
11942 }
11943
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011944 blacklisted[0] = '\0';
11945 if (val && atoi(val))
11946 ignore_blacklist = 1;
11947
11948try_again:
11949 ctrl = open_wpa_mon(intf);
11950 if (ctrl == NULL) {
11951 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11952 "wpa_supplicant monitor connection");
11953 return -2;
11954 }
11955
11956 tries++;
11957 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
11958 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
11959 "Interworking connection");
11960 wpa_ctrl_detach(ctrl);
11961 wpa_ctrl_close(ctrl);
11962 return 0;
11963 }
11964
11965 buf[0] = '\0';
11966 while (1) {
11967 char *pos;
11968 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11969 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
11970 if (!pos)
11971 break;
11972 pos += 25;
11973 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
11974 pos);
11975 if (!blacklisted[0])
11976 memcpy(blacklisted, pos, strlen(pos) + 1);
11977 }
11978
11979 if (ignore_blacklist && blacklisted[0]) {
11980 char *end;
11981 end = strchr(blacklisted, ' ');
11982 if (end)
11983 *end = '\0';
11984 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
11985 blacklisted);
Jouni Malinen3aa72862019-05-29 23:14:51 +030011986 r = snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
11987 blacklisted);
11988 if (r < 0 || r >= sizeof(buf) || wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011989 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
11990 wpa_ctrl_detach(ctrl);
11991 wpa_ctrl_close(ctrl);
11992 return 0;
11993 }
11994 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11995 buf, sizeof(buf));
11996 }
11997
11998 wpa_ctrl_detach(ctrl);
11999 wpa_ctrl_close(ctrl);
12000
12001 if (res < 0) {
12002 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12003 "connect");
12004 return 0;
12005 }
12006
12007 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
12008 strstr(buf, "INTERWORKING-BLACKLISTED")) {
12009 if (tries < 2) {
12010 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
12011 goto try_again;
12012 }
12013 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
12014 "matching credentials found");
12015 return 0;
12016 }
12017
12018 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12019 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12020 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
12021 "get current BSSID/SSID");
12022 return 0;
12023 }
12024
12025 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
12026 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12027 hs2_set_policy(dut);
12028 return 0;
12029}
12030
12031
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012032static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
12033 struct sigma_conn *conn,
12034 struct sigma_cmd *cmd)
12035{
12036 const char *intf = get_param(cmd, "Interface");
12037 const char *display = get_param(cmd, "Display");
12038 struct wpa_ctrl *ctrl;
12039 char buf[300], params[400], *pos;
12040 char bssid[20];
12041 int info_avail = 0;
12042 unsigned int old_timeout;
12043 int res;
12044
12045 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
12046 send_resp(dut, conn, SIGMA_ERROR,
12047 "ErrorCode,Could not get current BSSID");
12048 return 0;
12049 }
12050 ctrl = open_wpa_mon(intf);
12051 if (!ctrl) {
12052 sigma_dut_print(dut, DUT_MSG_ERROR,
12053 "Failed to open wpa_supplicant monitor connection");
12054 return -2;
12055 }
12056
12057 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
12058 wpa_command(intf, buf);
12059
12060 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
12061 if (res < 0) {
12062 send_resp(dut, conn, SIGMA_ERROR,
12063 "ErrorCode,Could not complete GAS query");
12064 goto fail;
12065 }
12066
12067 old_timeout = dut->default_timeout;
12068 dut->default_timeout = 2;
12069 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
12070 dut->default_timeout = old_timeout;
12071 if (res < 0)
12072 goto done;
12073 pos = strchr(buf, ' ');
12074 if (!pos)
12075 goto done;
12076 pos++;
12077 pos = strchr(pos, ' ');
12078 if (!pos)
12079 goto done;
12080 pos++;
12081 info_avail = 1;
12082 snprintf(params, sizeof(params), "browser %s", pos);
12083
12084 if (display && strcasecmp(display, "Yes") == 0) {
12085 pid_t pid;
12086
12087 pid = fork();
12088 if (pid < 0) {
12089 perror("fork");
12090 return -1;
12091 }
12092
12093 if (pid == 0) {
12094 run_hs20_osu(dut, params);
12095 exit(0);
12096 }
12097 }
12098
12099done:
12100 snprintf(buf, sizeof(buf), "Info_available,%s",
12101 info_avail ? "Yes" : "No");
12102 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12103fail:
12104 wpa_ctrl_detach(ctrl);
12105 wpa_ctrl_close(ctrl);
12106 return 0;
12107}
12108
12109
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012110static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
12111 struct sigma_conn *conn,
12112 const char *ifname,
12113 struct sigma_cmd *cmd)
12114{
12115 const char *val;
12116 int id;
12117
12118 id = add_cred(ifname);
12119 if (id < 0)
12120 return -2;
12121 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12122
12123 val = get_param(cmd, "prefer");
12124 if (val && atoi(val) > 0)
12125 set_cred(ifname, id, "priority", "1");
12126
12127 val = get_param(cmd, "REALM");
12128 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12129 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12130 "realm");
12131 return 0;
12132 }
12133
12134 val = get_param(cmd, "HOME_FQDN");
12135 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12136 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12137 "home_fqdn");
12138 return 0;
12139 }
12140
12141 val = get_param(cmd, "Username");
12142 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12143 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12144 "username");
12145 return 0;
12146 }
12147
12148 val = get_param(cmd, "Password");
12149 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
12150 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12151 "password");
12152 return 0;
12153 }
12154
12155 val = get_param(cmd, "ROOT_CA");
12156 if (val) {
12157 char fname[200];
12158 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12159#ifdef __linux__
12160 if (!file_exists(fname)) {
12161 char msg[300];
12162 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12163 "file (%s) not found", fname);
12164 send_resp(dut, conn, SIGMA_ERROR, msg);
12165 return 0;
12166 }
12167#endif /* __linux__ */
12168 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12169 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12170 "not set root CA");
12171 return 0;
12172 }
12173 }
12174
12175 return 1;
12176}
12177
12178
12179static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
12180{
12181 FILE *in, *out;
12182 char buf[500];
12183 int found = 0;
12184
12185 in = fopen("devdetail.xml", "r");
12186 if (in == NULL)
12187 return -1;
12188 out = fopen("devdetail.xml.tmp", "w");
12189 if (out == NULL) {
12190 fclose(in);
12191 return -1;
12192 }
12193
12194 while (fgets(buf, sizeof(buf), in)) {
12195 char *pos = strstr(buf, "<IMSI>");
12196 if (pos) {
12197 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
12198 imsi);
12199 pos += 6;
12200 *pos = '\0';
12201 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
12202 found++;
12203 } else {
12204 fprintf(out, "%s", buf);
12205 }
12206 }
12207
12208 fclose(out);
12209 fclose(in);
12210 if (found)
12211 rename("devdetail.xml.tmp", "devdetail.xml");
12212 else
12213 unlink("devdetail.xml.tmp");
12214
12215 return 0;
12216}
12217
12218
12219static int sta_add_credential_sim(struct sigma_dut *dut,
12220 struct sigma_conn *conn,
12221 const char *ifname, struct sigma_cmd *cmd)
12222{
12223 const char *val, *imsi = NULL;
12224 int id;
12225 char buf[200];
12226 int res;
12227 const char *pos;
12228 size_t mnc_len;
12229 char plmn_mcc[4];
12230 char plmn_mnc[4];
12231
12232 id = add_cred(ifname);
12233 if (id < 0)
12234 return -2;
12235 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12236
12237 val = get_param(cmd, "prefer");
12238 if (val && atoi(val) > 0)
12239 set_cred(ifname, id, "priority", "1");
12240
12241 val = get_param(cmd, "PLMN_MCC");
12242 if (val == NULL) {
12243 send_resp(dut, conn, SIGMA_ERROR,
12244 "errorCode,Missing PLMN_MCC");
12245 return 0;
12246 }
12247 if (strlen(val) != 3) {
12248 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
12249 return 0;
12250 }
12251 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
12252
12253 val = get_param(cmd, "PLMN_MNC");
12254 if (val == NULL) {
12255 send_resp(dut, conn, SIGMA_ERROR,
12256 "errorCode,Missing PLMN_MNC");
12257 return 0;
12258 }
12259 if (strlen(val) != 2 && strlen(val) != 3) {
12260 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
12261 return 0;
12262 }
12263 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
12264
12265 val = get_param(cmd, "IMSI");
12266 if (val == NULL) {
12267 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
12268 "IMSI");
12269 return 0;
12270 }
12271
12272 imsi = pos = val;
12273
12274 if (strncmp(plmn_mcc, pos, 3) != 0) {
12275 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
12276 return 0;
12277 }
12278 pos += 3;
12279
12280 mnc_len = strlen(plmn_mnc);
12281 if (mnc_len < 2) {
12282 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
12283 return 0;
12284 }
12285
12286 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
12287 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
12288 return 0;
12289 }
12290 pos += mnc_len;
12291
12292 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
12293 if (res < 0 || res >= (int) sizeof(buf))
12294 return -1;
12295 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
12296 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12297 "not set IMSI");
12298 return 0;
12299 }
12300
12301 val = get_param(cmd, "Password");
12302 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
12303 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12304 "not set password");
12305 return 0;
12306 }
12307
Jouni Malinenba630452018-06-22 11:49:59 +030012308 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012309 /*
12310 * Set provisioning_sp for the test cases where SIM/USIM
12311 * provisioning is used.
12312 */
12313 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
12314 "wi-fi.org") < 0) {
12315 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12316 "not set provisioning_sp");
12317 return 0;
12318 }
12319
12320 update_devdetail_imsi(dut, imsi);
12321 }
12322
12323 return 1;
12324}
12325
12326
12327static int sta_add_credential_cert(struct sigma_dut *dut,
12328 struct sigma_conn *conn,
12329 const char *ifname,
12330 struct sigma_cmd *cmd)
12331{
12332 const char *val;
12333 int id;
12334
12335 id = add_cred(ifname);
12336 if (id < 0)
12337 return -2;
12338 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
12339
12340 val = get_param(cmd, "prefer");
12341 if (val && atoi(val) > 0)
12342 set_cred(ifname, id, "priority", "1");
12343
12344 val = get_param(cmd, "REALM");
12345 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
12346 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12347 "realm");
12348 return 0;
12349 }
12350
12351 val = get_param(cmd, "HOME_FQDN");
12352 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
12353 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12354 "home_fqdn");
12355 return 0;
12356 }
12357
12358 val = get_param(cmd, "Username");
12359 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
12360 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
12361 "username");
12362 return 0;
12363 }
12364
12365 val = get_param(cmd, "clientCertificate");
12366 if (val) {
12367 char fname[200];
12368 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12369#ifdef __linux__
12370 if (!file_exists(fname)) {
12371 char msg[300];
12372 snprintf(msg, sizeof(msg),
12373 "ErrorCode,clientCertificate "
12374 "file (%s) not found", fname);
12375 send_resp(dut, conn, SIGMA_ERROR, msg);
12376 return 0;
12377 }
12378#endif /* __linux__ */
12379 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
12380 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12381 "not set client_cert");
12382 return 0;
12383 }
12384 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
12385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12386 "not set private_key");
12387 return 0;
12388 }
12389 }
12390
12391 val = get_param(cmd, "ROOT_CA");
12392 if (val) {
12393 char fname[200];
12394 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
12395#ifdef __linux__
12396 if (!file_exists(fname)) {
12397 char msg[300];
12398 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
12399 "file (%s) not found", fname);
12400 send_resp(dut, conn, SIGMA_ERROR, msg);
12401 return 0;
12402 }
12403#endif /* __linux__ */
12404 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
12405 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
12406 "not set root CA");
12407 return 0;
12408 }
12409 }
12410
12411 return 1;
12412}
12413
12414
12415static int cmd_sta_add_credential(struct sigma_dut *dut,
12416 struct sigma_conn *conn,
12417 struct sigma_cmd *cmd)
12418{
12419 const char *intf = get_param(cmd, "Interface");
12420 const char *type;
12421
12422 start_sta_mode(dut);
12423
12424 type = get_param(cmd, "Type");
12425 if (!type)
12426 return -1;
12427
12428 if (strcasecmp(type, "uname_pwd") == 0)
12429 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
12430
12431 if (strcasecmp(type, "sim") == 0)
12432 return sta_add_credential_sim(dut, conn, intf, cmd);
12433
12434 if (strcasecmp(type, "cert") == 0)
12435 return sta_add_credential_cert(dut, conn, intf, cmd);
12436
12437 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
12438 "type");
12439 return 0;
12440}
12441
12442
12443static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
12444 struct sigma_cmd *cmd)
12445{
12446 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053012447 const char *val, *bssid, *ssid;
Arif Hussain66a4af02019-02-07 15:04:51 -080012448 char buf[4096];
vamsi krishna89ad8c62017-09-19 12:51:18 +053012449 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012450 int res;
12451
Arif Hussain66a4af02019-02-07 15:04:51 -080012452 val = get_param(cmd, "GetParameter");
12453 if (val && strcmp(val, "SSID_BSSID") == 0) {
12454 if (get_wpa_ssid_bssid(dut, get_station_ifname(),
12455 buf, sizeof(buf)) < 0) {
12456 sigma_dut_print(dut, DUT_MSG_ERROR,
12457 "Could not get ssid bssid");
12458 return ERROR_SEND_STATUS;
12459 }
12460
12461 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
12462 send_resp(dut, conn, SIGMA_COMPLETE, buf);
12463 return STATUS_SENT;
12464 }
12465
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012466 val = get_param(cmd, "HESSID");
12467 if (val) {
12468 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
12469 if (res < 0 || res >= (int) sizeof(buf))
12470 return -1;
12471 wpa_command(intf, buf);
12472 }
12473
12474 val = get_param(cmd, "ACCS_NET_TYPE");
12475 if (val) {
12476 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
12477 val);
12478 if (res < 0 || res >= (int) sizeof(buf))
12479 return -1;
12480 wpa_command(intf, buf);
12481 }
12482
vamsi krishna89ad8c62017-09-19 12:51:18 +053012483 bssid = get_param(cmd, "Bssid");
12484 ssid = get_param(cmd, "Ssid");
12485
12486 if (ssid) {
12487 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
12488 send_resp(dut, conn, SIGMA_ERROR,
12489 "ErrorCode,Too long SSID");
12490 return 0;
12491 }
12492 ascii2hexstr(ssid, ssid_hex);
12493 }
12494
12495 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
12496 bssid ? " bssid=": "",
12497 bssid ? bssid : "",
12498 ssid ? " ssid " : "",
12499 ssid ? ssid_hex : "");
12500 if (res < 0 || res >= (int) sizeof(buf))
12501 return -1;
12502
12503 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012504 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
12505 "scan");
12506 return 0;
12507 }
12508
12509 return 1;
12510}
12511
12512
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012513static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
12514 struct sigma_cmd *cmd)
12515{
12516 const char *intf = get_param(cmd, "Interface");
12517 const char *bssid;
12518 char buf[4096], *pos;
12519 int freq, chan;
12520 char *ssid;
12521 char resp[100];
12522 int res;
12523 struct wpa_ctrl *ctrl;
12524
12525 bssid = get_param(cmd, "BSSID");
12526 if (!bssid) {
12527 send_resp(dut, conn, SIGMA_INVALID,
12528 "errorCode,BSSID argument is missing");
12529 return 0;
12530 }
12531
12532 ctrl = open_wpa_mon(intf);
12533 if (!ctrl) {
12534 sigma_dut_print(dut, DUT_MSG_ERROR,
12535 "Failed to open wpa_supplicant monitor connection");
12536 return -1;
12537 }
12538
12539 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
12540 send_resp(dut, conn, SIGMA_ERROR,
12541 "errorCode,Could not start scan");
12542 wpa_ctrl_detach(ctrl);
12543 wpa_ctrl_close(ctrl);
12544 return 0;
12545 }
12546
12547 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
12548 buf, sizeof(buf));
12549
12550 wpa_ctrl_detach(ctrl);
12551 wpa_ctrl_close(ctrl);
12552
12553 if (res < 0) {
12554 send_resp(dut, conn, SIGMA_ERROR,
12555 "errorCode,Scan did not complete");
12556 return 0;
12557 }
12558
12559 snprintf(buf, sizeof(buf), "BSS %s", bssid);
12560 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
12561 strncmp(buf, "id=", 3) != 0) {
12562 send_resp(dut, conn, SIGMA_ERROR,
12563 "errorCode,Specified BSSID not found");
12564 return 0;
12565 }
12566
12567 pos = strstr(buf, "\nfreq=");
12568 if (!pos) {
12569 send_resp(dut, conn, SIGMA_ERROR,
12570 "errorCode,Channel not found");
12571 return 0;
12572 }
12573 freq = atoi(pos + 6);
12574 chan = freq_to_channel(freq);
12575
12576 pos = strstr(buf, "\nssid=");
12577 if (!pos) {
12578 send_resp(dut, conn, SIGMA_ERROR,
12579 "errorCode,SSID not found");
12580 return 0;
12581 }
12582 ssid = pos + 6;
12583 pos = strchr(ssid, '\n');
12584 if (pos)
12585 *pos = '\0';
12586 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
12587 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12588 return 0;
12589}
12590
12591
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012592static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
12593 struct sigma_cmd *cmd)
12594{
12595#ifdef __linux__
12596 struct timeval tv;
12597 struct tm tm;
12598 time_t t;
12599 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012600 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012601
12602 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
12603
12604 memset(&tm, 0, sizeof(tm));
12605 val = get_param(cmd, "seconds");
12606 if (val)
12607 tm.tm_sec = atoi(val);
12608 val = get_param(cmd, "minutes");
12609 if (val)
12610 tm.tm_min = atoi(val);
12611 val = get_param(cmd, "hours");
12612 if (val)
12613 tm.tm_hour = atoi(val);
12614 val = get_param(cmd, "date");
12615 if (val)
12616 tm.tm_mday = atoi(val);
12617 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053012618 if (val) {
12619 v = atoi(val);
12620 if (v < 1 || v > 12) {
12621 send_resp(dut, conn, SIGMA_INVALID,
12622 "errorCode,Invalid month");
12623 return 0;
12624 }
12625 tm.tm_mon = v - 1;
12626 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012627 val = get_param(cmd, "year");
12628 if (val) {
12629 int year = atoi(val);
12630#ifdef ANDROID
12631 if (year > 2035)
12632 year = 2035; /* years beyond 2035 not supported */
12633#endif /* ANDROID */
12634 tm.tm_year = year - 1900;
12635 }
12636 t = mktime(&tm);
12637 if (t == (time_t) -1) {
12638 send_resp(dut, conn, SIGMA_ERROR,
12639 "errorCode,Invalid date or time");
12640 return 0;
12641 }
12642
12643 memset(&tv, 0, sizeof(tv));
12644 tv.tv_sec = t;
12645
12646 if (settimeofday(&tv, NULL) < 0) {
12647 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
12648 strerror(errno));
12649 send_resp(dut, conn, SIGMA_ERROR,
12650 "errorCode,Failed to set time");
12651 return 0;
12652 }
12653
12654 return 1;
12655#endif /* __linux__ */
12656
12657 return -1;
12658}
12659
12660
12661static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
12662 struct sigma_cmd *cmd)
12663{
12664 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012665 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012666 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012667 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012668 int res;
12669 struct wpa_ctrl *ctrl;
12670
12671 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012672 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012673
12674 val = get_param(cmd, "ProdESSAssoc");
12675 if (val)
12676 prod_ess_assoc = atoi(val);
12677
12678 kill_dhcp_client(dut, intf);
12679 if (start_dhcp_client(dut, intf) < 0)
12680 return -2;
12681
12682 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
12683 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12684 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012685 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012686 prod_ess_assoc ? "" : "-N",
12687 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030012688 name ? "'" : "",
12689 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
12690 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012691
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053012692 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012693 if (run_hs20_osu(dut, buf) < 0) {
12694 FILE *f;
12695
12696 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
12697
12698 f = fopen("hs20-osu-client.res", "r");
12699 if (f) {
12700 char resp[400], res[300], *pos;
12701 if (!fgets(res, sizeof(res), f))
12702 res[0] = '\0';
12703 pos = strchr(res, '\n');
12704 if (pos)
12705 *pos = '\0';
12706 fclose(f);
12707 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
12708 res);
12709 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
12710 if (system(resp) != 0) {
12711 }
12712 snprintf(resp, sizeof(resp),
12713 "SSID,,BSSID,,failureReason,%s", res);
12714 send_resp(dut, conn, SIGMA_COMPLETE, resp);
12715 return 0;
12716 }
12717
12718 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12719 return 0;
12720 }
12721
12722 if (!prod_ess_assoc)
12723 goto report;
12724
12725 ctrl = open_wpa_mon(intf);
12726 if (ctrl == NULL) {
12727 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12728 "wpa_supplicant monitor connection");
12729 return -1;
12730 }
12731
12732 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
12733 buf, sizeof(buf));
12734
12735 wpa_ctrl_detach(ctrl);
12736 wpa_ctrl_close(ctrl);
12737
12738 if (res < 0) {
12739 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
12740 "network after OSU");
12741 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12742 return 0;
12743 }
12744
12745report:
12746 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
12747 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
12748 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
12749 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
12750 return 0;
12751 }
12752
12753 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
12754 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012755 return 0;
12756}
12757
12758
12759static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
12760 struct sigma_cmd *cmd)
12761{
12762 const char *val;
12763 int timeout = 120;
12764
12765 val = get_param(cmd, "PolicyUpdate");
12766 if (val == NULL || atoi(val) == 0)
12767 return 1; /* No operation requested */
12768
12769 val = get_param(cmd, "Timeout");
12770 if (val)
12771 timeout = atoi(val);
12772
12773 if (timeout) {
12774 /* TODO: time out the command and return
12775 * PolicyUpdateStatus,TIMEOUT if needed. */
12776 }
12777
12778 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
12779 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
12780 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
12781 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
12782 return 0;
12783 }
12784
12785 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
12786 return 0;
12787}
12788
12789
12790static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
12791 struct sigma_cmd *cmd)
12792{
12793 struct wpa_ctrl *ctrl;
12794 const char *intf = get_param(cmd, "Interface");
12795 const char *bssid = get_param(cmd, "Bssid");
12796 const char *ssid = get_param(cmd, "SSID");
12797 const char *security = get_param(cmd, "Security");
12798 const char *passphrase = get_param(cmd, "Passphrase");
12799 const char *pin = get_param(cmd, "PIN");
12800 char buf[1000];
12801 char ssid_hex[200], passphrase_hex[200];
12802 const char *keymgmt, *cipher;
12803
12804 if (intf == NULL)
12805 intf = get_main_ifname();
12806
12807 if (!bssid) {
12808 send_resp(dut, conn, SIGMA_ERROR,
12809 "ErrorCode,Missing Bssid argument");
12810 return 0;
12811 }
12812
12813 if (!ssid) {
12814 send_resp(dut, conn, SIGMA_ERROR,
12815 "ErrorCode,Missing SSID argument");
12816 return 0;
12817 }
12818
12819 if (!security) {
12820 send_resp(dut, conn, SIGMA_ERROR,
12821 "ErrorCode,Missing Security argument");
12822 return 0;
12823 }
12824
12825 if (!passphrase) {
12826 send_resp(dut, conn, SIGMA_ERROR,
12827 "ErrorCode,Missing Passphrase argument");
12828 return 0;
12829 }
12830
12831 if (!pin) {
12832 send_resp(dut, conn, SIGMA_ERROR,
12833 "ErrorCode,Missing PIN argument");
12834 return 0;
12835 }
12836
vamsi krishna8c9c1562017-05-12 15:51:46 +053012837 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
12838 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012839 send_resp(dut, conn, SIGMA_ERROR,
12840 "ErrorCode,Too long SSID/passphrase");
12841 return 0;
12842 }
12843
12844 ctrl = open_wpa_mon(intf);
12845 if (ctrl == NULL) {
12846 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12847 "wpa_supplicant monitor connection");
12848 return -2;
12849 }
12850
12851 if (strcasecmp(security, "wpa2-psk") == 0) {
12852 keymgmt = "WPA2PSK";
12853 cipher = "CCMP";
12854 } else {
12855 wpa_ctrl_detach(ctrl);
12856 wpa_ctrl_close(ctrl);
12857 send_resp(dut, conn, SIGMA_ERROR,
12858 "ErrorCode,Unsupported Security value");
12859 return 0;
12860 }
12861
12862 ascii2hexstr(ssid, ssid_hex);
12863 ascii2hexstr(passphrase, passphrase_hex);
12864 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
12865 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
12866
12867 if (wpa_command(intf, buf) < 0) {
12868 wpa_ctrl_detach(ctrl);
12869 wpa_ctrl_close(ctrl);
12870 send_resp(dut, conn, SIGMA_ERROR,
12871 "ErrorCode,Failed to start registrar");
12872 return 0;
12873 }
12874
12875 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
12876 dut->er_oper_performed = 1;
12877
12878 return wps_connection_event(dut, conn, ctrl, intf, 0);
12879}
12880
12881
12882static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
12883 struct sigma_conn *conn,
12884 struct sigma_cmd *cmd)
12885{
12886 struct wpa_ctrl *ctrl;
12887 const char *intf = get_param(cmd, "Interface");
12888 const char *bssid = get_param(cmd, "Bssid");
12889 char buf[100];
12890
12891 if (!bssid) {
12892 send_resp(dut, conn, SIGMA_ERROR,
12893 "ErrorCode,Missing Bssid argument");
12894 return 0;
12895 }
12896
12897 ctrl = open_wpa_mon(intf);
12898 if (ctrl == NULL) {
12899 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
12900 "wpa_supplicant monitor connection");
12901 return -2;
12902 }
12903
12904 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
12905
12906 if (wpa_command(intf, buf) < 0) {
12907 wpa_ctrl_detach(ctrl);
12908 wpa_ctrl_close(ctrl);
12909 send_resp(dut, conn, SIGMA_ERROR,
12910 "ErrorCode,Failed to start registrar");
12911 return 0;
12912 }
12913
12914 return wps_connection_event(dut, conn, ctrl, intf, 0);
12915}
12916
12917
vamsi krishna9b144002017-09-20 13:28:13 +053012918static int cmd_start_wps_registration(struct sigma_dut *dut,
12919 struct sigma_conn *conn,
12920 struct sigma_cmd *cmd)
12921{
12922 struct wpa_ctrl *ctrl;
12923 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012924 const char *network_mode = get_param(cmd, "network_mode");
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012925 const char *config_method = get_param(cmd, "WPSConfigMethod");
12926 const char *role;
vamsi krishna9b144002017-09-20 13:28:13 +053012927 int res;
12928 char buf[256];
12929 const char *events[] = {
12930 "CTRL-EVENT-CONNECTED",
12931 "WPS-OVERLAP-DETECTED",
12932 "WPS-TIMEOUT",
12933 "WPS-FAIL",
12934 NULL
12935 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012936 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053012937
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012938 /* 60G WPS tests do not pass Interface parameter */
12939 if (!intf)
12940 intf = get_main_ifname();
12941
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012942 if (dut->mode == SIGMA_MODE_AP)
12943 return ap_wps_registration(dut, conn, cmd);
12944
12945 if (config_method) {
12946 /* WFA_CS_WPS_PIN_KEYPAD mode is set when using the
12947 * sta_wps_enter_pin before calling start_wps_registration. */
12948 if (strcasecmp(config_method, "PBC") == 0)
12949 dut->wps_method = WFA_CS_WPS_PBC;
12950 }
12951 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
12952 send_resp(dut, conn, SIGMA_ERROR,
12953 "ErrorCode,WPS parameters not yet set");
12954 return STATUS_SENT;
12955 }
12956
12957 /* Make sure WPS is enabled (also for STA mode) */
12958 dut->wps_disable = 0;
12959
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012960 if (dut->band == WPS_BAND_60G && network_mode &&
12961 strcasecmp(network_mode, "PBSS") == 0) {
12962 sigma_dut_print(dut, DUT_MSG_DEBUG,
12963 "Set PBSS network mode, network id %d", id);
12964 if (set_network(get_station_ifname(), id, "pbss", "1") < 0)
12965 return -2;
12966 }
12967
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012968 if (dut->force_rsn_ie) {
12969 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
12970 dut->force_rsn_ie);
12971 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
12972 sigma_dut_print(dut, DUT_MSG_INFO,
12973 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012974 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012975 }
12976 }
12977
vamsi krishna9b144002017-09-20 13:28:13 +053012978 ctrl = open_wpa_mon(intf);
12979 if (!ctrl) {
12980 sigma_dut_print(dut, DUT_MSG_ERROR,
12981 "Failed to open wpa_supplicant monitor connection");
12982 return -2;
12983 }
12984
12985 role = get_param(cmd, "WpsRole");
12986 if (!role) {
12987 send_resp(dut, conn, SIGMA_INVALID,
12988 "ErrorCode,WpsRole not provided");
12989 goto fail;
12990 }
12991
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020012992 if (strcasecmp(role, "Enrollee") != 0) {
12993 /* Registrar role for STA not supported */
12994 send_resp(dut, conn, SIGMA_ERROR,
12995 "ErrorCode,Unsupported WpsRole value");
12996 goto fail;
12997 }
12998
12999 if (is_60g_sigma_dut(dut)) {
13000 if (dut->wps_method == WFA_CS_WPS_PBC)
13001 snprintf(buf, sizeof(buf), "WPS_PBC");
13002 else /* WFA_CS_WPS_PIN_KEYPAD */
13003 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
13004 dut->wps_pin);
13005 if (wpa_command(intf, buf) < 0) {
13006 send_resp(dut, conn, SIGMA_ERROR,
13007 "ErrorCode,Failed to start WPS");
vamsi krishna9b144002017-09-20 13:28:13 +053013008 goto fail;
13009 }
Alexei Avshalom Lazar043230b2019-02-04 14:11:24 +020013010 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13011 if (res < 0) {
13012 send_resp(dut, conn, SIGMA_ERROR,
13013 "ErrorCode,WPS connection did not complete");
13014 goto fail;
13015 }
13016 if (strstr(buf, "WPS-TIMEOUT")) {
13017 send_resp(dut, conn, SIGMA_COMPLETE, "WpsState,NoPeer");
13018 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13019 send_resp(dut, conn, SIGMA_COMPLETE,
13020 "WpsState,OverlapSession");
13021 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13022 send_resp(dut, conn, SIGMA_COMPLETE,
13023 "WpsState,Successful");
13024 } else {
13025 send_resp(dut, conn, SIGMA_COMPLETE,
13026 "WpsState,Failure");
13027 }
13028 } else {
13029 if (dut->wps_method == WFA_CS_WPS_PBC) {
vamsi krishna9b144002017-09-20 13:28:13 +053013030 if (wpa_command(intf, "WPS_PBC") < 0) {
13031 send_resp(dut, conn, SIGMA_ERROR,
13032 "ErrorCode,Failed to enable PBC");
13033 goto fail;
13034 }
13035 } else {
13036 /* TODO: PIN method */
13037 send_resp(dut, conn, SIGMA_ERROR,
13038 "ErrorCode,Unsupported WpsConfigMethod value");
13039 goto fail;
13040 }
13041 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
13042 if (res < 0) {
13043 send_resp(dut, conn, SIGMA_ERROR,
13044 "ErrorCode,WPS connection did not complete");
13045 goto fail;
13046 }
13047 if (strstr(buf, "WPS-TIMEOUT")) {
13048 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
13049 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
13050 send_resp(dut, conn, SIGMA_ERROR,
13051 "ErrorCode,OverlapSession");
13052 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
13053 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
13054 } else {
13055 send_resp(dut, conn, SIGMA_ERROR,
13056 "ErrorCode,WPS operation failed");
13057 }
vamsi krishna9b144002017-09-20 13:28:13 +053013058 }
13059
13060fail:
13061 wpa_ctrl_detach(ctrl);
13062 wpa_ctrl_close(ctrl);
13063 return 0;
13064}
13065
13066
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013067static int req_intf(struct sigma_cmd *cmd)
13068{
13069 return get_param(cmd, "interface") == NULL ? -1 : 0;
13070}
13071
13072
13073void sta_register_cmds(void)
13074{
13075 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
13076 cmd_sta_get_ip_config);
13077 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
13078 cmd_sta_set_ip_config);
13079 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
13080 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
13081 cmd_sta_get_mac_address);
13082 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
13083 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
13084 cmd_sta_verify_ip_connection);
13085 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
13086 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
13087 cmd_sta_set_encryption);
13088 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
13089 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
13090 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
13091 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
13092 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
13093 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
13094 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
13095 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
13096 cmd_sta_set_eapakaprime);
13097 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
13098 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
13099 /* TODO: sta_set_ibss */
13100 /* TODO: sta_set_mode */
13101 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
13102 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
13103 /* TODO: sta_up_load */
13104 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
13105 cmd_sta_preset_testparameters);
13106 /* TODO: sta_set_system */
13107 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
13108 /* TODO: sta_set_rifs_test */
13109 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
13110 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
13111 /* TODO: sta_send_coexist_mgmt */
13112 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
13113 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
13114 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
13115 sigma_dut_reg_cmd("sta_reset_default", req_intf,
13116 cmd_sta_reset_default);
13117 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
13118 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
13119 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
13120 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
13121 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020013122 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013123 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
13124 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
13125 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
13126 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
13127 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030013128 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
13129 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013130 sigma_dut_reg_cmd("sta_add_credential", req_intf,
13131 cmd_sta_add_credential);
13132 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020013133 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013134 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
13135 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
13136 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
13137 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
13138 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
13139 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030013140 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013141 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
13142 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020013143 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053013144 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020013145}