blob: b0a2a3917e37fa3d3011afbdadf6eb8b70f2c496 [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>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020014#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020015#include <regex.h>
16#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020017#include <sys/time.h>
18#include <netpacket/packet.h>
19#include <linux/if_ether.h>
20#ifdef ANDROID
21#include <cutils/properties.h>
22#include <android/log.h>
23#include "keystore_get.h"
24#else /* ANDROID */
25#include <ifaddrs.h>
26#endif /* ANDROID */
27#include <netdb.h>
28#endif /* __linux__ */
29#ifdef __QNXNTO__
30#include <net/if_dl.h>
31#endif /* __QNXNTO__ */
32#include "wpa_ctrl.h"
33#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070034#include "miracast.h"
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070035#include "qca-vendor_copy.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020036
37/* Temporary files for sta_send_addba */
38#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
39#define VI_QOS_FILE "/tmp/vi-qos.txt"
40#define VI_QOS_REFFILE "/etc/vi-qos.txt"
41
42/*
43 * MTU for Ethernet need to take into account 8-byte SNAP header
44 * to be added when encapsulating Ethernet frame into 802.11
45 */
46#ifndef IEEE80211_MAX_DATA_LEN_DMG
47#define IEEE80211_MAX_DATA_LEN_DMG 7920
48#endif
49#ifndef IEEE80211_SNAP_LEN_DMG
50#define IEEE80211_SNAP_LEN_DMG 8
51#endif
52
Ashwini Patil00402582017-04-13 12:29:39 +053053#define NON_PREF_CH_LIST_SIZE 100
Ashwini Patil5acd7382017-04-13 15:55:04 +053054#define NEIGHBOR_REPORT_SIZE 1000
55#define DEFAULT_NEIGHBOR_BSSID_INFO "17"
56#define DEFAULT_NEIGHBOR_PHY_TYPE "1"
Ashwini Patil00402582017-04-13 12:29:39 +053057
Jouni Malinencd4e3c32015-10-29 12:39:56 +020058extern char *sigma_wpas_ctrl;
59extern char *sigma_cert_path;
60extern enum driver_type wifi_chip_type;
61extern char *sigma_radio_ifname[];
62
Lior David0fe101e2017-03-09 16:09:50 +020063#ifdef __linux__
64#define WIL_WMI_MAX_PAYLOAD 248
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020065#define WIL_WMI_ESE_CFG_CMDID 0xa01
Lior David0fe101e2017-03-09 16:09:50 +020066#define WIL_WMI_BF_TRIG_CMDID 0x83a
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020067#define WIL_WMI_UNIT_TEST_CMDID 0x900
Lior David0fe101e2017-03-09 16:09:50 +020068
69struct wil_wmi_header {
70 uint8_t mid;
71 uint8_t reserved;
72 uint16_t cmd;
73 uint32_t ts;
74} __attribute__((packed));
75
76enum wil_wmi_bf_trig_type {
77 WIL_WMI_SLS,
78 WIL_WMI_BRP_RX,
79 WIL_WMI_BRP_TX,
80};
81
82struct wil_wmi_bf_trig_cmd {
83 /* enum wil_wmi_bf_trig_type */
84 uint32_t bf_type;
85 /* cid when type == WMI_BRP_RX */
86 uint32_t sta_id;
87 uint32_t reserved;
88 /* mac address when type = WIL_WMI_SLS */
89 uint8_t dest_mac[6];
90} __attribute__((packed));
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020091
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020092enum wil_wmi_sched_scheme_advertisment {
93 WIL_WMI_ADVERTISE_ESE_DISABLED,
94 WIL_WMI_ADVERTISE_ESE_IN_BEACON,
95 WIL_WMI_ADVERTISE_ESE_IN_ANNOUNCE_FRAME,
96};
97
98enum wil_wmi_ese_slot_type {
99 WIL_WMI_ESE_SP,
100 WIL_WMI_ESE_CBAP,
101 WIL_WMI_ESE_ANNOUNCE_NO_ACK,
102};
103
104struct wil_wmi_ese_slot {
105 /* offset from start of BI in microseconds */
106 uint32_t tbtt_offset;
107 uint8_t flags;
108 /* enum wil_wmi_ese_slot_type */
109 uint8_t slot_type;
110 /* duration in microseconds */
111 uint16_t duration;
112 /* frame exchange sequence duration, microseconds */
113 uint16_t tx_op;
114 /* time between 2 blocks for periodic allocation(microseconds) */
115 uint16_t period;
116 /* number of blocks in periodic allocation */
117 uint8_t num_blocks;
118 /* for semi-active allocations */
119 uint8_t idle_period;
120 uint8_t src_aid;
121 uint8_t dst_aid;
122 uint32_t reserved;
123} __attribute__((packed));
124
125#define WIL_WMI_MAX_ESE_SLOTS 4
126struct wil_wmi_ese_cfg {
127 uint8_t serial_num;
128 /* wil_wmi_sched_scheme_advertisment */
129 uint8_t ese_advertisment;
130 uint16_t flags;
131 uint8_t num_allocs;
132 uint8_t reserved[3];
133 uint64_t start_tbtt;
134 /* allocations list */
135 struct wil_wmi_ese_slot slots[WIL_WMI_MAX_ESE_SLOTS];
136} __attribute__((packed));
137
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200138#define WIL_WMI_UT_FORCE_MCS 6
139struct wil_wmi_force_mcs {
140 /* WIL_WMI_UT_HW_SYSAPI */
141 uint16_t module_id;
142 /* WIL_WMI_UT_FORCE_MCS */
143 uint16_t subtype_id;
144 /* cid (ignored in oob_mode, affects all stations) */
145 uint32_t cid;
146 /* 1 to force MCS, 0 to restore default behavior */
147 uint32_t force_enable;
148 /* MCS index, 0-12 */
149 uint32_t mcs;
150} __attribute__((packed));
151
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200152#define WIL_WMI_UT_HW_SYSAPI 10
153#define WIL_WMI_UT_FORCE_RSN_IE 0x29
154struct wil_wmi_force_rsn_ie {
155 /* WIL_WMI_UT_HW_SYSAPI */
156 uint16_t module_id;
157 /* WIL_WMI_UT_FORCE_RSN_IE */
158 uint16_t subtype_id;
159 /* 0 = no change, 1 = remove if exists, 2 = add if does not exist */
160 uint32_t state;
161} __attribute__((packed));
Lior David0fe101e2017-03-09 16:09:50 +0200162#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200163
164#ifdef ANDROID
165
166static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
167
168#define ANDROID_KEYSTORE_GET 'g'
169#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
170
171static int android_keystore_get(char cmd, const char *key, unsigned char *val)
172{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200173 /* Android 4.3 changed keystore design, so need to use keystore_get() */
174#ifndef KEYSTORE_MESSAGE_SIZE
175#define KEYSTORE_MESSAGE_SIZE 65535
176#endif /* KEYSTORE_MESSAGE_SIZE */
177
178 ssize_t len;
179 uint8_t *value = NULL;
180
181 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
182 "keystore command '%c' key '%s' --> keystore_get",
183 cmd, key);
184
185 len = keystore_get(key, strlen(key), &value);
186 if (len < 0) {
187 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
188 "keystore_get() failed");
189 return -1;
190 }
191
192 if (len > KEYSTORE_MESSAGE_SIZE)
193 len = KEYSTORE_MESSAGE_SIZE;
194 memcpy(val, value, len);
195 free(value);
196 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200197}
198#endif /* ANDROID */
199
200
201int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
202{
203#ifdef __linux__
204 char buf[100];
205
206 if (wifi_chip_type == DRIVER_WCN) {
207 if (enabled) {
208 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530209 if (system(buf) != 0)
210 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200211 } else {
212 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530213 if (system(buf) != 0)
214 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200215 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530216 if (system(buf) != 0)
217 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200218 }
219
220 return 0;
221 }
222
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530223set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200224 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
225 intf, enabled ? "on" : "off");
226 if (system(buf) != 0) {
227 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
228 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530229 if (system(buf) != 0) {
230 sigma_dut_print(dut, DUT_MSG_ERROR,
231 "Failed to set power save %s",
232 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200233 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530234 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200235 }
236
237 return 0;
238#else /* __linux__ */
239 return -1;
240#endif /* __linux__ */
241}
242
243
Lior Davidcc88b562017-01-03 18:52:09 +0200244#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200245
Lior Davidcc88b562017-01-03 18:52:09 +0200246static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
247 size_t len)
248{
249 DIR *dir, *wil_dir;
250 struct dirent *entry;
251 int ret = -1;
252 const char *root_path = "/sys/kernel/debug/ieee80211";
253
254 dir = opendir(root_path);
255 if (!dir)
256 return -2;
257
258 while ((entry = readdir(dir))) {
259 if (strcmp(entry->d_name, ".") == 0 ||
260 strcmp(entry->d_name, "..") == 0)
261 continue;
262
263 if (snprintf(path, len, "%s/%s/wil6210",
264 root_path, entry->d_name) >= (int) len) {
265 ret = -3;
266 break;
267 }
268
269 wil_dir = opendir(path);
270 if (wil_dir) {
271 closedir(wil_dir);
272 ret = 0;
273 break;
274 }
275 }
276
277 closedir(dir);
278 return ret;
279}
Lior David0fe101e2017-03-09 16:09:50 +0200280
281
282static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
283 void *payload, uint16_t length)
284{
285 struct {
286 struct wil_wmi_header hdr;
287 char payload[WIL_WMI_MAX_PAYLOAD];
288 } __attribute__((packed)) cmd;
289 char buf[128], fname[128];
290 size_t towrite, written;
291 FILE *f;
292
293 if (length > WIL_WMI_MAX_PAYLOAD) {
294 sigma_dut_print(dut, DUT_MSG_ERROR,
295 "payload too large(%u, max %u)",
296 length, WIL_WMI_MAX_PAYLOAD);
297 return -1;
298 }
299
300 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
301 cmd.hdr.cmd = command;
302 memcpy(cmd.payload, payload, length);
303
304 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
305 sigma_dut_print(dut, DUT_MSG_ERROR,
306 "failed to get wil6210 debugfs dir");
307 return -1;
308 }
309
310 snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
311 f = fopen(fname, "wb");
312 if (!f) {
313 sigma_dut_print(dut, DUT_MSG_ERROR,
314 "failed to open: %s", fname);
315 return -1;
316 }
317
318 towrite = sizeof(cmd.hdr) + length;
319 written = fwrite(&cmd, 1, towrite, f);
320 fclose(f);
321 if (written != towrite) {
322 sigma_dut_print(dut, DUT_MSG_ERROR,
323 "failed to send wmi %u", command);
324 return -1;
325 }
326
327 return 0;
328}
329
330
331static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
332 const char *pattern, unsigned int *field)
333{
334 char buf[128], fname[128];
335 FILE *f;
336 regex_t re;
337 regmatch_t m[2];
338 int rc, ret = -1;
339
340 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
341 sigma_dut_print(dut, DUT_MSG_ERROR,
342 "failed to get wil6210 debugfs dir");
343 return -1;
344 }
345
346 snprintf(fname, sizeof(fname), "%s/stations", buf);
347 f = fopen(fname, "r");
348 if (!f) {
349 sigma_dut_print(dut, DUT_MSG_ERROR,
350 "failed to open: %s", fname);
351 return -1;
352 }
353
354 if (regcomp(&re, pattern, REG_EXTENDED)) {
355 sigma_dut_print(dut, DUT_MSG_ERROR,
356 "regcomp failed: %s", pattern);
357 goto out;
358 }
359
360 /*
361 * find the entry for the mac address
362 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
363 */
364 while (fgets(buf, sizeof(buf), f)) {
365 if (strcasestr(buf, bssid)) {
366 /* extract the field (CID/AID/state) */
367 rc = regexec(&re, buf, 2, m, 0);
368 if (!rc && (m[1].rm_so >= 0)) {
369 buf[m[1].rm_eo] = 0;
370 *field = atoi(&buf[m[1].rm_so]);
371 ret = 0;
372 break;
373 }
374 }
375 }
376
377 regfree(&re);
378 if (ret)
379 sigma_dut_print(dut, DUT_MSG_ERROR,
380 "could not extract field");
381
382out:
383 fclose(f);
384
385 return ret;
386}
387
388
389static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
390 unsigned int *cid)
391{
392 const char *pattern = "\\[([0-9]+)\\]";
393
394 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
395}
396
397
398static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
399 int l_rx)
400{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700401 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200402 unsigned int cid;
403
Rakesh Sunki556237d2017-03-30 14:49:31 -0700404 memset(&cmd, 0, sizeof(cmd));
405
Lior David0fe101e2017-03-09 16:09:50 +0200406 if (wil6210_get_cid(dut, mac, &cid))
407 return -1;
408
409 cmd.bf_type = WIL_WMI_BRP_RX;
410 cmd.sta_id = cid;
411 /* training length (l_rx) is ignored, FW always uses length 16 */
412 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
413 &cmd, sizeof(cmd));
414}
415
416
417static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
418{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700419 struct wil_wmi_bf_trig_cmd cmd;
420
421 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200422
423 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
424 return -1;
425
426 cmd.bf_type = WIL_WMI_SLS;
427 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
428 &cmd, sizeof(cmd));
429}
430
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200431
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +0200432int wil6210_set_ese(struct sigma_dut *dut, int count,
433 struct sigma_ese_alloc *allocs)
434{
435 struct wil_wmi_ese_cfg cmd = { };
436 int i;
437
438 if (count == 0 || count > WIL_WMI_MAX_ESE_SLOTS)
439 return -1;
440
441 if (dut->ap_bcnint <= 0) {
442 sigma_dut_print(dut, DUT_MSG_ERROR,
443 "invalid beacon interval(%d), check test",
444 dut->ap_bcnint);
445 return -1;
446 }
447
448 cmd.ese_advertisment = WIL_WMI_ADVERTISE_ESE_IN_BEACON;
449 cmd.flags = 0x1d;
450 cmd.num_allocs = count;
451 for (i = 0; i < count; i++) {
452 /*
453 * Convert percent from BI (BI specified in milliseconds)
454 * to absolute duration in microseconds.
455 */
456 cmd.slots[i].duration =
457 (allocs[i].percent_bi * dut->ap_bcnint * 1000) / 100;
458 switch (allocs[i].type) {
459 case ESE_CBAP:
460 cmd.slots[i].slot_type = WIL_WMI_ESE_CBAP;
461 break;
462 case ESE_SP:
463 cmd.slots[i].slot_type = WIL_WMI_ESE_SP;
464 break;
465 default:
466 sigma_dut_print(dut, DUT_MSG_ERROR,
467 "invalid slot type(%d) at index %d",
468 allocs[i].type, i);
469 return -1;
470 }
471 cmd.slots[i].src_aid = allocs[i].src_aid;
472 cmd.slots[i].dst_aid = allocs[i].dst_aid;
473 sigma_dut_print(dut, DUT_MSG_INFO,
474 "slot %d, duration %u, type %d, srcAID %u dstAID %u",
475 i, cmd.slots[i].duration,
476 cmd.slots[i].slot_type, cmd.slots[i].src_aid,
477 cmd.slots[i].dst_aid);
478 }
479
480 return wil6210_wmi_send(dut, WIL_WMI_ESE_CFG_CMDID, &cmd, sizeof(cmd));
481}
482
483
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +0200484int wil6210_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
485{
486 struct wil_wmi_force_mcs cmd = { };
487
488 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
489 cmd.subtype_id = WIL_WMI_UT_FORCE_MCS;
490 cmd.force_enable = (uint32_t) force;
491 cmd.mcs = (uint32_t) mcs;
492
493 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
494 &cmd, sizeof(cmd));
495}
496
497
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +0200498static int wil6210_force_rsn_ie(struct sigma_dut *dut, int state)
499{
500 struct wil_wmi_force_rsn_ie cmd = { };
501
502 cmd.module_id = WIL_WMI_UT_HW_SYSAPI;
503 cmd.subtype_id = WIL_WMI_UT_FORCE_RSN_IE;
504 cmd.state = (uint32_t) state;
505
506 return wil6210_wmi_send(dut, WIL_WMI_UNIT_TEST_CMDID,
507 &cmd, sizeof(cmd));
508}
509
Lior Davidcc88b562017-01-03 18:52:09 +0200510#endif /* __linux__ */
511
512
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200513static void static_ip_file(int proto, const char *addr, const char *mask,
514 const char *gw)
515{
516 if (proto) {
517 FILE *f = fopen("static-ip", "w");
518 if (f) {
519 fprintf(f, "%d %s %s %s\n", proto, addr,
520 mask ? mask : "N/A",
521 gw ? gw : "N/A");
522 fclose(f);
523 }
524 } else {
525 unlink("static-ip");
526 }
527}
528
529
530static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
531 const char *ssid)
532{
533#ifdef __linux__
534 char buf[100];
535
536 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
537 intf, ssid);
538 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
539
540 if (system(buf) != 0) {
541 sigma_dut_print(dut, DUT_MSG_ERROR,
542 "iwpriv neighbor request failed");
543 return -1;
544 }
545
546 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
547
548 return 0;
549#else /* __linux__ */
550 return -1;
551#endif /* __linux__ */
552}
553
554
555static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530556 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200557{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530558 const char *val;
559 int reason_code = 0;
560 char buf[1024];
561
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200562 /*
563 * In the earlier builds we used WNM_QUERY and in later
564 * builds used WNM_BSS_QUERY.
565 */
566
Ashwini Patil5acd7382017-04-13 15:55:04 +0530567 val = get_param(cmd, "BTMQuery_Reason_Code");
568 if (val)
569 reason_code = atoi(val);
570
571 val = get_param(cmd, "Cand_List");
572 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
573 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
574 dut->btm_query_cand_list);
575 free(dut->btm_query_cand_list);
576 dut->btm_query_cand_list = NULL;
577 } else {
578 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
579 }
580
581 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200582 sigma_dut_print(dut, DUT_MSG_ERROR,
583 "transition management query failed");
584 return -1;
585 }
586
587 sigma_dut_print(dut, DUT_MSG_DEBUG,
588 "transition management query sent");
589
590 return 0;
591}
592
593
594int is_ip_addr(const char *str)
595{
596 const char *pos = str;
597 struct in_addr addr;
598
599 while (*pos) {
600 if (*pos != '.' && (*pos < '0' || *pos > '9'))
601 return 0;
602 pos++;
603 }
604
605 return inet_aton(str, &addr);
606}
607
608
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200609int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
610 size_t buf_len)
611{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530612 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200613 char ip[16], mask[15], dns[16], sec_dns[16];
614 int is_dhcp = 0;
615 int s;
616#ifdef ANDROID
617 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530618#else /* ANDROID */
619 FILE *f;
620#ifdef __linux__
621 const char *str_ps;
622#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200623#endif /* ANDROID */
624
625 ip[0] = '\0';
626 mask[0] = '\0';
627 dns[0] = '\0';
628 sec_dns[0] = '\0';
629
630 s = socket(PF_INET, SOCK_DGRAM, 0);
631 if (s >= 0) {
632 struct ifreq ifr;
633 struct sockaddr_in saddr;
634
635 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700636 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200637 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
638 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
639 "%s IP address: %s",
640 ifname, strerror(errno));
641 } else {
642 memcpy(&saddr, &ifr.ifr_addr,
643 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700644 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200645 }
646
647 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
648 memcpy(&saddr, &ifr.ifr_addr,
649 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700650 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200651 }
652 close(s);
653 }
654
655#ifdef ANDROID
656 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
657 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
658 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
659 if (property_get(tmp, prop, NULL) != 0 &&
660 strcmp(prop, "ok") == 0) {
661 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
662 ifname);
663 if (property_get(tmp, prop, NULL) != 0 &&
664 strcmp(ip, prop) == 0)
665 is_dhcp = 1;
666 }
667 }
668
669 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700670 if (property_get(tmp, prop, NULL) != 0)
671 strlcpy(dns, prop, sizeof(dns));
672 else if (property_get("net.dns1", prop, NULL) != 0)
673 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200674
675 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700676 if (property_get(tmp, prop, NULL) != 0)
677 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200678#else /* ANDROID */
679#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530680 if (get_driver_type() == DRIVER_OPENWRT)
681 str_ps = "ps -w";
682 else
683 str_ps = "ps ax";
684 snprintf(tmp, sizeof(tmp),
685 "%s | grep dhclient | grep -v grep | grep -q %s",
686 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200687 if (system(tmp) == 0)
688 is_dhcp = 1;
689 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530690 snprintf(tmp, sizeof(tmp),
691 "%s | grep udhcpc | grep -v grep | grep -q %s",
692 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200693 if (system(tmp) == 0)
694 is_dhcp = 1;
695 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530696 snprintf(tmp, sizeof(tmp),
697 "%s | grep dhcpcd | grep -v grep | grep -q %s",
698 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200699 if (system(tmp) == 0)
700 is_dhcp = 1;
701 }
702 }
703#endif /* __linux__ */
704
705 f = fopen("/etc/resolv.conf", "r");
706 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530707 char *pos, *pos2;
708
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200709 while (fgets(tmp, sizeof(tmp), f)) {
710 if (strncmp(tmp, "nameserver", 10) != 0)
711 continue;
712 pos = tmp + 10;
713 while (*pos == ' ' || *pos == '\t')
714 pos++;
715 pos2 = pos;
716 while (*pos2) {
717 if (*pos2 == '\n' || *pos2 == '\r') {
718 *pos2 = '\0';
719 break;
720 }
721 pos2++;
722 }
Peng Xub8fc5cc2017-05-10 17:27:28 -0700723 if (!dns[0])
724 strlcpy(dns, pos, sizeof(dns));
725 else if (!sec_dns[0])
726 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200727 }
728 fclose(f);
729 }
730#endif /* ANDROID */
731
732 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
733 is_dhcp, ip, mask, dns);
734 buf[buf_len - 1] = '\0';
735
736 return 0;
737}
738
739
740
741
742int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
743 size_t buf_len)
744{
745#ifdef __linux__
746#ifdef ANDROID
747 char cmd[200], result[1000], *pos, *end;
748 FILE *f;
749 size_t len;
750
751 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
752 f = popen(cmd, "r");
753 if (f == NULL)
754 return -1;
755 len = fread(result, 1, sizeof(result) - 1, f);
756 pclose(f);
757 if (len == 0)
758 return -1;
759 result[len] = '\0';
760 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
761
762 pos = strstr(result, "inet6 ");
763 if (pos == NULL)
764 return -1;
765 pos += 6;
766 end = strchr(pos, ' ');
767 if (end)
768 *end = '\0';
769 end = strchr(pos, '/');
770 if (end)
771 *end = '\0';
772 snprintf(buf, buf_len, "ip,%s", pos);
773 buf[buf_len - 1] = '\0';
774 return 0;
775#else /* ANDROID */
776 struct ifaddrs *ifaddr, *ifa;
777 int res, found = 0;
778 char host[NI_MAXHOST];
779
780 if (getifaddrs(&ifaddr) < 0) {
781 perror("getifaddrs");
782 return -1;
783 }
784
785 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
786 if (strcasecmp(ifname, ifa->ifa_name) != 0)
787 continue;
788 if (ifa->ifa_addr == NULL ||
789 ifa->ifa_addr->sa_family != AF_INET6)
790 continue;
791
792 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
793 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
794 if (res != 0) {
795 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
796 gai_strerror(res));
797 continue;
798 }
799 if (strncmp(host, "fe80::", 6) == 0)
800 continue; /* skip link-local */
801
802 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
803 found = 1;
804 break;
805 }
806
807 freeifaddrs(ifaddr);
808
809 if (found) {
810 char *pos;
811 pos = strchr(host, '%');
812 if (pos)
813 *pos = '\0';
814 snprintf(buf, buf_len, "ip,%s", host);
815 buf[buf_len - 1] = '\0';
816 return 0;
817 }
818
819#endif /* ANDROID */
820#endif /* __linux__ */
821 return -1;
822}
823
824
825static int cmd_sta_get_ip_config(struct sigma_dut *dut,
826 struct sigma_conn *conn,
827 struct sigma_cmd *cmd)
828{
829 const char *intf = get_param(cmd, "Interface");
830 const char *ifname;
831 char buf[200];
832 const char *val;
833 int type = 1;
834
835 if (intf == NULL)
836 return -1;
837
838 if (strcmp(intf, get_main_ifname()) == 0)
839 ifname = get_station_ifname();
840 else
841 ifname = intf;
842
843 /*
844 * UCC may assume the IP address to be available immediately after
845 * association without trying to run sta_get_ip_config multiple times.
846 * Sigma CAPI does not specify this command as a block command that
847 * would wait for the address to become available, but to pass tests
848 * more reliably, it looks like such a wait may be needed here.
849 */
850 if (wait_ip_addr(dut, ifname, 15) < 0) {
851 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
852 "for sta_get_ip_config");
853 /*
854 * Try to continue anyway since many UCC tests do not really
855 * care about the return value from here..
856 */
857 }
858
859 val = get_param(cmd, "Type");
860 if (val)
861 type = atoi(val);
862 if (type == 2 || dut->last_set_ip_config_ipv6) {
863 int i;
864
865 /*
866 * Since we do not have proper wait for IPv6 addresses, use a
867 * fixed two second delay here as a workaround for UCC script
868 * assuming IPv6 address is available when this command returns.
869 * Some scripts did not use Type,2 properly for IPv6, so include
870 * also the cases where the previous sta_set_ip_config indicated
871 * use of IPv6.
872 */
873 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
874 for (i = 0; i < 10; i++) {
875 sleep(1);
876 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
877 {
878 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
879 send_resp(dut, conn, SIGMA_COMPLETE, buf);
880#ifdef ANDROID
881 sigma_dut_print(dut, DUT_MSG_INFO,
882 "Adding IPv6 rule on Android");
883 add_ipv6_rule(dut, intf);
884#endif /* ANDROID */
885
886 return 0;
887 }
888 }
889 }
890 if (type == 1) {
891 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
892 return -2;
893 } else if (type == 2) {
894 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
895 return -2;
896 } else {
897 send_resp(dut, conn, SIGMA_ERROR,
898 "errorCode,Unsupported address type");
899 return 0;
900 }
901
902 send_resp(dut, conn, SIGMA_COMPLETE, buf);
903 return 0;
904}
905
906
907static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
908{
909#ifdef __linux__
910 char buf[200];
911 char path[128];
912 struct stat s;
913
914#ifdef ANDROID
915 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
916#else /* ANDROID */
917 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
918#endif /* ANDROID */
919 if (stat(path, &s) == 0) {
920 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
921 sigma_dut_print(dut, DUT_MSG_INFO,
922 "Kill previous DHCP client: %s", buf);
923 if (system(buf) != 0)
924 sigma_dut_print(dut, DUT_MSG_INFO,
925 "Failed to kill DHCP client");
926 unlink(path);
927 sleep(1);
928 } else {
929 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
930
931 if (stat(path, &s) == 0) {
932 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
933 sigma_dut_print(dut, DUT_MSG_INFO,
934 "Kill previous DHCP client: %s", buf);
935 if (system(buf) != 0)
936 sigma_dut_print(dut, DUT_MSG_INFO,
937 "Failed to kill DHCP client");
938 unlink(path);
939 sleep(1);
940 }
941 }
942#endif /* __linux__ */
943}
944
945
946static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
947{
948#ifdef __linux__
949 char buf[200];
950
951#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +0530952 if (access("/system/bin/dhcpcd", F_OK) != -1) {
953 snprintf(buf, sizeof(buf),
954 "/system/bin/dhcpcd -b %s", ifname);
955 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
956 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
957 } else {
958 sigma_dut_print(dut, DUT_MSG_ERROR,
959 "DHCP client program missing");
960 return 0;
961 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200962#else /* ANDROID */
963 snprintf(buf, sizeof(buf),
964 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
965 ifname, ifname);
966#endif /* ANDROID */
967 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
968 if (system(buf) != 0) {
969 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
970 if (system(buf) != 0) {
971 sigma_dut_print(dut, DUT_MSG_INFO,
972 "Failed to start DHCP client");
973#ifndef ANDROID
974 return -1;
975#endif /* ANDROID */
976 }
977 }
978#endif /* __linux__ */
979
980 return 0;
981}
982
983
984static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
985{
986#ifdef __linux__
987 char buf[200];
988
989 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
990 if (system(buf) != 0) {
991 sigma_dut_print(dut, DUT_MSG_INFO,
992 "Failed to clear IP addresses");
993 return -1;
994 }
995#endif /* __linux__ */
996
997 return 0;
998}
999
1000
1001#ifdef ANDROID
1002static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
1003{
1004 char cmd[200], *result, *pos;
1005 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301006 int tableid;
1007 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001008
1009 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
1010 ifname);
1011 fp = popen(cmd, "r");
1012 if (fp == NULL)
1013 return -1;
1014
1015 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301016 if (result == NULL) {
1017 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001018 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05301019 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001020
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301021 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001022 fclose(fp);
1023
1024 if (len == 0) {
1025 free(result);
1026 return -1;
1027 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +05301028 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001029
1030 pos = strstr(result, "table ");
1031 if (pos == NULL) {
1032 free(result);
1033 return -1;
1034 }
1035
1036 pos += strlen("table ");
1037 tableid = atoi(pos);
1038 if (tableid != 0) {
1039 if (system("ip -6 rule del prio 22000") != 0) {
1040 /* ignore any error */
1041 }
1042 snprintf(cmd, sizeof(cmd),
1043 "ip -6 rule add from all lookup %d prio 22000",
1044 tableid);
1045 if (system(cmd) != 0) {
1046 sigma_dut_print(dut, DUT_MSG_INFO,
1047 "Failed to run %s", cmd);
1048 free(result);
1049 return -1;
1050 }
1051 } else {
1052 sigma_dut_print(dut, DUT_MSG_INFO,
1053 "No Valid Table Id found %s", pos);
1054 free(result);
1055 return -1;
1056 }
1057 free(result);
1058
1059 return 0;
1060}
1061#endif /* ANDROID */
1062
1063
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301064int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
1065 const char *ip, const char *mask)
1066{
1067 char buf[200];
1068
1069 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1070 ifname, ip, mask);
1071 return system(buf) == 0;
1072}
1073
1074
1075int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
1076{
1077 char buf[200];
1078
1079 if (!is_ip_addr(gw)) {
1080 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
1081 return -1;
1082 }
1083
1084 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1085 if (!dut->no_ip_addr_set && system(buf) != 0) {
1086 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1087 gw);
1088 if (system(buf) != 0)
1089 return 0;
1090 }
1091
1092 return 1;
1093}
1094
1095
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001096static int cmd_sta_set_ip_config(struct sigma_dut *dut,
1097 struct sigma_conn *conn,
1098 struct sigma_cmd *cmd)
1099{
1100 const char *intf = get_param(cmd, "Interface");
1101 const char *ifname;
1102 char buf[200];
1103 const char *val, *ip, *mask, *gw;
1104 int type = 1;
1105
1106 if (intf == NULL)
1107 return -1;
1108
1109 if (strcmp(intf, get_main_ifname()) == 0)
1110 ifname = get_station_ifname();
1111 else
1112 ifname = intf;
1113
1114 if (if_nametoindex(ifname) == 0) {
1115 send_resp(dut, conn, SIGMA_ERROR,
1116 "ErrorCode,Unknown interface");
1117 return 0;
1118 }
1119
1120 val = get_param(cmd, "Type");
1121 if (val) {
1122 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301123 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001124 send_resp(dut, conn, SIGMA_ERROR,
1125 "ErrorCode,Unsupported address type");
1126 return 0;
1127 }
1128 }
1129
1130 dut->last_set_ip_config_ipv6 = 0;
1131
1132 val = get_param(cmd, "dhcp");
1133 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
1134 static_ip_file(0, NULL, NULL, NULL);
1135#ifdef __linux__
1136 if (type == 2) {
1137 dut->last_set_ip_config_ipv6 = 1;
1138 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
1139 "stateless address autoconfiguration");
1140#ifdef ANDROID
1141 /*
1142 * This sleep is required as the assignment in case of
1143 * Android is taking time and is done by the kernel.
1144 * The subsequent ping for IPv6 is impacting HS20 test
1145 * case.
1146 */
1147 sleep(2);
1148 add_ipv6_rule(dut, intf);
1149#endif /* ANDROID */
1150 /* Assume this happens by default */
1151 return 1;
1152 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301153 if (type != 3) {
1154 kill_dhcp_client(dut, ifname);
1155 if (start_dhcp_client(dut, ifname) < 0)
1156 return -2;
1157 } else {
1158 sigma_dut_print(dut, DUT_MSG_DEBUG,
1159 "Using FILS HLP DHCPv4 Rapid Commit");
1160 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001161
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001162 return 1;
1163#endif /* __linux__ */
1164 return -2;
1165 }
1166
1167 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301168 if (!ip) {
1169 send_resp(dut, conn, SIGMA_INVALID,
1170 "ErrorCode,Missing IP address");
1171 return 0;
1172 }
1173
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001174 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301175 if (!mask) {
1176 send_resp(dut, conn, SIGMA_INVALID,
1177 "ErrorCode,Missing subnet mask");
1178 return 0;
1179 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001180
1181 if (type == 2) {
1182 int net = atoi(mask);
1183
1184 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1185 return -1;
1186
1187 if (dut->no_ip_addr_set) {
1188 snprintf(buf, sizeof(buf),
1189 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1190 ifname);
1191 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1192 if (system(buf) != 0) {
1193 sigma_dut_print(dut, DUT_MSG_DEBUG,
1194 "Failed to disable IPv6 address before association");
1195 }
1196 } else {
1197 snprintf(buf, sizeof(buf),
1198 "ip -6 addr del %s/%s dev %s",
1199 ip, mask, ifname);
1200 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1201 if (system(buf) != 0) {
1202 /*
1203 * This command may fail if the address being
1204 * deleted does not exist. Inaction here is
1205 * intentional.
1206 */
1207 }
1208
1209 snprintf(buf, sizeof(buf),
1210 "ip -6 addr add %s/%s dev %s",
1211 ip, mask, ifname);
1212 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1213 if (system(buf) != 0) {
1214 send_resp(dut, conn, SIGMA_ERROR,
1215 "ErrorCode,Failed to set IPv6 address");
1216 return 0;
1217 }
1218 }
1219
1220 dut->last_set_ip_config_ipv6 = 1;
1221 static_ip_file(6, ip, mask, NULL);
1222 return 1;
1223 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301224 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001225 return -1;
1226 }
1227
1228 kill_dhcp_client(dut, ifname);
1229
1230 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301231 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001232 send_resp(dut, conn, SIGMA_ERROR,
1233 "ErrorCode,Failed to set IP address");
1234 return 0;
1235 }
1236 }
1237
1238 gw = get_param(cmd, "defaultGateway");
1239 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301240 if (set_ipv4_gw(dut, gw) < 1) {
1241 send_resp(dut, conn, SIGMA_ERROR,
1242 "ErrorCode,Failed to set default gateway");
1243 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001244 }
1245 }
1246
1247 val = get_param(cmd, "primary-dns");
1248 if (val) {
1249 /* TODO */
1250 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1251 "setting", val);
1252 }
1253
1254 val = get_param(cmd, "secondary-dns");
1255 if (val) {
1256 /* TODO */
1257 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1258 "setting", val);
1259 }
1260
1261 static_ip_file(4, ip, mask, gw);
1262
1263 return 1;
1264}
1265
1266
1267static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1268 struct sigma_cmd *cmd)
1269{
1270 /* const char *intf = get_param(cmd, "Interface"); */
1271 /* TODO: could report more details here */
1272 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1273 return 0;
1274}
1275
1276
1277static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1278 struct sigma_conn *conn,
1279 struct sigma_cmd *cmd)
1280{
1281 /* const char *intf = get_param(cmd, "Interface"); */
1282 char addr[20], resp[50];
1283
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301284 if (dut->dev_role == DEVROLE_STA_CFON)
1285 return sta_cfon_get_mac_address(dut, conn, cmd);
1286
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001287 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1288 < 0)
1289 return -2;
1290
1291 snprintf(resp, sizeof(resp), "mac,%s", addr);
1292 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1293 return 0;
1294}
1295
1296
1297static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1298 struct sigma_cmd *cmd)
1299{
1300 /* const char *intf = get_param(cmd, "Interface"); */
1301 int connected = 0;
1302 char result[32];
1303 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1304 sizeof(result)) < 0) {
1305 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1306 "%s status", get_station_ifname());
1307 return -2;
1308 }
1309
1310 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1311 if (strncmp(result, "COMPLETED", 9) == 0)
1312 connected = 1;
1313
1314 if (connected)
1315 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1316 else
1317 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1318
1319 return 0;
1320}
1321
1322
1323static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1324 struct sigma_conn *conn,
1325 struct sigma_cmd *cmd)
1326{
1327 /* const char *intf = get_param(cmd, "Interface"); */
1328 const char *dst, *timeout;
1329 int wait_time = 90;
1330 char buf[100];
1331 int res;
1332
1333 dst = get_param(cmd, "destination");
1334 if (dst == NULL || !is_ip_addr(dst))
1335 return -1;
1336
1337 timeout = get_param(cmd, "timeout");
1338 if (timeout) {
1339 wait_time = atoi(timeout);
1340 if (wait_time < 1)
1341 wait_time = 1;
1342 }
1343
1344 /* TODO: force renewal of IP lease if DHCP is enabled */
1345
1346 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1347 res = system(buf);
1348 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1349 if (res == 0)
1350 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1351 else if (res == 256)
1352 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1353 else
1354 return -2;
1355
1356 return 0;
1357}
1358
1359
1360static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1361 struct sigma_cmd *cmd)
1362{
1363 /* const char *intf = get_param(cmd, "Interface"); */
1364 char bssid[20], resp[50];
1365
1366 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1367 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001368 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001369
1370 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1371 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1372 return 0;
1373}
1374
1375
1376#ifdef __SAMSUNG__
1377static int add_use_network(const char *ifname)
1378{
1379 char buf[100];
1380
1381 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1382 wpa_command(ifname, buf);
1383 return 0;
1384}
1385#endif /* __SAMSUNG__ */
1386
1387
1388static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1389 const char *ifname, struct sigma_cmd *cmd)
1390{
1391 const char *ssid = get_param(cmd, "ssid");
1392 int id;
1393 const char *val;
1394
1395 if (ssid == NULL)
1396 return -1;
1397
1398 start_sta_mode(dut);
1399
1400#ifdef __SAMSUNG__
1401 add_use_network(ifname);
1402#endif /* __SAMSUNG__ */
1403
1404 id = add_network(ifname);
1405 if (id < 0)
1406 return -2;
1407 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1408
1409 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1410 return -2;
1411
1412 dut->infra_network_id = id;
1413 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1414
1415 val = get_param(cmd, "program");
1416 if (!val)
1417 val = get_param(cmd, "prog");
1418 if (val && strcasecmp(val, "hs2") == 0) {
1419 char buf[100];
1420 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1421 wpa_command(ifname, buf);
1422
1423 val = get_param(cmd, "prefer");
1424 if (val && atoi(val) > 0)
1425 set_network(ifname, id, "priority", "1");
1426 }
1427
1428 return id;
1429}
1430
1431
1432static int cmd_sta_set_encryption(struct sigma_dut *dut,
1433 struct sigma_conn *conn,
1434 struct sigma_cmd *cmd)
1435{
1436 const char *intf = get_param(cmd, "Interface");
1437 const char *ssid = get_param(cmd, "ssid");
1438 const char *type = get_param(cmd, "encpType");
1439 const char *ifname;
1440 char buf[200];
1441 int id;
1442
1443 if (intf == NULL || ssid == NULL)
1444 return -1;
1445
1446 if (strcmp(intf, get_main_ifname()) == 0)
1447 ifname = get_station_ifname();
1448 else
1449 ifname = intf;
1450
1451 id = add_network_common(dut, conn, ifname, cmd);
1452 if (id < 0)
1453 return id;
1454
1455 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1456 return -2;
1457
1458 if (type && strcasecmp(type, "wep") == 0) {
1459 const char *val;
1460 int i;
1461
1462 val = get_param(cmd, "activeKey");
1463 if (val) {
1464 int keyid;
1465 keyid = atoi(val);
1466 if (keyid < 1 || keyid > 4)
1467 return -1;
1468 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1469 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1470 return -2;
1471 }
1472
1473 for (i = 0; i < 4; i++) {
1474 snprintf(buf, sizeof(buf), "key%d", i + 1);
1475 val = get_param(cmd, buf);
1476 if (val == NULL)
1477 continue;
1478 snprintf(buf, sizeof(buf), "wep_key%d", i);
1479 if (set_network(ifname, id, buf, val) < 0)
1480 return -2;
1481 }
1482 }
1483
1484 return 1;
1485}
1486
1487
1488static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1489 const char *ifname, struct sigma_cmd *cmd)
1490{
1491 const char *val;
1492 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001493 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001494 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301495 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001496
1497 id = add_network_common(dut, conn, ifname, cmd);
1498 if (id < 0)
1499 return id;
1500
Jouni Malinen47dcc952017-10-09 16:43:24 +03001501 val = get_param(cmd, "Type");
1502 owe = val && strcasecmp(val, "OWE") == 0;
1503
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001504 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001505 if (!val && owe)
1506 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001507 if (val == NULL) {
1508 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1509 return 0;
1510 }
1511 if (strcasecmp(val, "wpa") == 0 ||
1512 strcasecmp(val, "wpa-psk") == 0) {
1513 if (set_network(ifname, id, "proto", "WPA") < 0)
1514 return -2;
1515 } else if (strcasecmp(val, "wpa2") == 0 ||
1516 strcasecmp(val, "wpa2-psk") == 0 ||
1517 strcasecmp(val, "wpa2-ft") == 0 ||
1518 strcasecmp(val, "wpa2-sha256") == 0) {
1519 if (set_network(ifname, id, "proto", "WPA2") < 0)
1520 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301521 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1522 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001523 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1524 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001525 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301526 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001527 if (set_network(ifname, id, "proto", "WPA2") < 0)
1528 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001529 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001530 } else {
1531 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1532 return 0;
1533 }
1534
1535 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001536 if (val) {
1537 cipher_set = 1;
1538 if (strcasecmp(val, "tkip") == 0) {
1539 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1540 return -2;
1541 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1542 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1543 return -2;
1544 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1545 if (set_network(ifname, id, "pairwise",
1546 "CCMP TKIP") < 0)
1547 return -2;
1548 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1549 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1550 return -2;
1551 if (set_network(ifname, id, "group", "GCMP") < 0)
1552 return -2;
1553 } else {
1554 send_resp(dut, conn, SIGMA_ERROR,
1555 "errorCode,Unrecognized encpType value");
1556 return 0;
1557 }
1558 }
1559
1560 val = get_param(cmd, "PairwiseCipher");
1561 if (val) {
1562 cipher_set = 1;
1563 /* TODO: Support space separated list */
1564 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1565 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1566 return -2;
1567 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1568 if (set_network(ifname, id, "pairwise",
1569 "CCMP-256") < 0)
1570 return -2;
1571 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1572 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1573 return -2;
1574 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1575 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1576 return -2;
1577 } else {
1578 send_resp(dut, conn, SIGMA_ERROR,
1579 "errorCode,Unrecognized PairwiseCipher value");
1580 return 0;
1581 }
1582 }
1583
Jouni Malinen47dcc952017-10-09 16:43:24 +03001584 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001585 send_resp(dut, conn, SIGMA_ERROR,
1586 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001587 return 0;
1588 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001589
1590 val = get_param(cmd, "GroupCipher");
1591 if (val) {
1592 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1593 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1594 return -2;
1595 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1596 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1597 return -2;
1598 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1599 if (set_network(ifname, id, "group", "GCMP") < 0)
1600 return -2;
1601 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1602 if (set_network(ifname, id, "group", "CCMP") < 0)
1603 return -2;
1604 } else {
1605 send_resp(dut, conn, SIGMA_ERROR,
1606 "errorCode,Unrecognized GroupCipher value");
1607 return 0;
1608 }
1609 }
1610
Jouni Malinen7b239522017-09-14 21:37:18 +03001611 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001612 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001613 const char *cipher;
1614
1615 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1616 cipher = "BIP-GMAC-256";
1617 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1618 cipher = "BIP-CMAC-256";
1619 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1620 cipher = "BIP-GMAC-128";
1621 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1622 cipher = "AES-128-CMAC";
1623 } else {
1624 send_resp(dut, conn, SIGMA_INVALID,
1625 "errorCode,Unsupported GroupMgntCipher");
1626 return 0;
1627 }
1628 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1629 send_resp(dut, conn, SIGMA_INVALID,
1630 "errorCode,Failed to set GroupMgntCipher");
1631 return 0;
1632 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001633 }
1634
1635 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301636
1637 if (dut->program == PROGRAM_OCE) {
1638 dut->sta_pmf = STA_PMF_OPTIONAL;
1639 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1640 return -2;
1641 }
1642
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001643 val = get_param(cmd, "PMF");
1644 if (val) {
1645 if (strcasecmp(val, "Required") == 0 ||
1646 strcasecmp(val, "Forced_Required") == 0) {
1647 dut->sta_pmf = STA_PMF_REQUIRED;
1648 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1649 return -2;
1650 } else if (strcasecmp(val, "Optional") == 0) {
1651 dut->sta_pmf = STA_PMF_OPTIONAL;
1652 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1653 return -2;
1654 } else if (strcasecmp(val, "Disabled") == 0 ||
Kiran Kumar Lokere07da3b22018-12-16 22:42:49 -08001655 strcasecmp(val, "Disable") == 0 ||
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001656 strcasecmp(val, "Forced_Disabled") == 0) {
1657 dut->sta_pmf = STA_PMF_DISABLED;
1658 } else {
1659 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1660 return 0;
1661 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05301662 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02001663 dut->sta_pmf = STA_PMF_REQUIRED;
1664 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1665 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001666 }
1667
1668 return id;
1669}
1670
1671
1672static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1673 struct sigma_cmd *cmd)
1674{
1675 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03001676 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02001677 const char *pmf = get_param(cmd, "PMF");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02001678 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001679 const char *ifname, *val, *alg;
1680 int id;
1681
1682 if (intf == NULL)
1683 return -1;
1684
1685 if (strcmp(intf, get_main_ifname()) == 0)
1686 ifname = get_station_ifname();
1687 else
1688 ifname = intf;
1689
1690 id = set_wpa_common(dut, conn, ifname, cmd);
1691 if (id < 0)
1692 return id;
1693
1694 val = get_param(cmd, "keyMgmtType");
1695 alg = get_param(cmd, "micAlg");
1696
Jouni Malinen992a81e2017-08-22 13:57:47 +03001697 if (type && strcasecmp(type, "SAE") == 0) {
1698 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1699 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
1700 return -2;
1701 } else {
1702 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
1703 return -2;
1704 }
1705 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1706 sigma_dut_print(dut, DUT_MSG_ERROR,
1707 "Failed to clear sae_groups to default");
1708 return -2;
1709 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001710 if (!pmf) {
1711 dut->sta_pmf = STA_PMF_REQUIRED;
1712 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1713 return -2;
1714 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001715 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
1716 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1717 if (set_network(ifname, id, "key_mgmt",
1718 "FT-SAE FT-PSK") < 0)
1719 return -2;
1720 } else {
1721 if (set_network(ifname, id, "key_mgmt",
1722 "SAE WPA-PSK") < 0)
1723 return -2;
1724 }
1725 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1726 sigma_dut_print(dut, DUT_MSG_ERROR,
1727 "Failed to clear sae_groups to default");
1728 return -2;
1729 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001730 if (!pmf) {
1731 dut->sta_pmf = STA_PMF_OPTIONAL;
1732 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1733 return -2;
1734 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03001735 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001736 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1737 return -2;
1738 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1739 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1740 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05301741 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1742 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
1743 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001744 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1745 dut->sta_pmf == STA_PMF_REQUIRED) {
1746 if (set_network(ifname, id, "key_mgmt",
1747 "WPA-PSK WPA-PSK-SHA256") < 0)
1748 return -2;
1749 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1750 if (set_network(ifname, id, "key_mgmt",
1751 "WPA-PSK WPA-PSK-SHA256") < 0)
1752 return -2;
1753 } else {
1754 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1755 return -2;
1756 }
1757
1758 val = get_param(cmd, "passPhrase");
1759 if (val == NULL)
1760 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03001761 if (type && strcasecmp(type, "SAE") == 0) {
1762 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
1763 return -2;
1764 } else {
1765 if (set_network_quoted(ifname, id, "psk", val) < 0)
1766 return -2;
1767 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001768
Jouni Malinen992a81e2017-08-22 13:57:47 +03001769 val = get_param(cmd, "ECGroupID");
1770 if (val) {
1771 char buf[50];
1772
1773 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
1774 if (wpa_command(ifname, buf) != 0) {
1775 sigma_dut_print(dut, DUT_MSG_ERROR,
1776 "Failed to clear sae_groups");
1777 return -2;
1778 }
1779 }
1780
Jouni Malinen68143132017-09-02 02:34:08 +03001781 val = get_param(cmd, "InvalidSAEElement");
1782 if (val) {
1783 free(dut->sae_commit_override);
1784 dut->sae_commit_override = strdup(val);
1785 }
1786
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02001787 if (dut->program == PROGRAM_60GHZ && network_mode &&
1788 strcasecmp(network_mode, "PBSS") == 0 &&
1789 set_network(ifname, id, "pbss", "1") < 0)
1790 return -2;
1791
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001792 return 1;
1793}
1794
1795
1796static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301797 const char *ifname, int username_identity,
1798 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001799{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301800 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001801 int id;
1802 char buf[200];
1803#ifdef ANDROID
1804 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1805 int length;
1806#endif /* ANDROID */
1807
1808 id = set_wpa_common(dut, conn, ifname, cmd);
1809 if (id < 0)
1810 return id;
1811
1812 val = get_param(cmd, "keyMgmtType");
1813 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301814 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001815
Jouni Malinenad395a22017-09-01 21:13:46 +03001816 if (val && strcasecmp(val, "SuiteB") == 0) {
1817 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
1818 0)
1819 return -2;
1820 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001821 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1822 return -2;
1823 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1824 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1825 return -2;
1826 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1827 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1828 return -2;
1829 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1830 dut->sta_pmf == STA_PMF_REQUIRED) {
1831 if (set_network(ifname, id, "key_mgmt",
1832 "WPA-EAP WPA-EAP-SHA256") < 0)
1833 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301834 } else if (akm && atoi(akm) == 14) {
1835 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1836 dut->sta_pmf == STA_PMF_REQUIRED) {
1837 if (set_network(ifname, id, "key_mgmt",
1838 "WPA-EAP-SHA256 FILS-SHA256") < 0)
1839 return -2;
1840 } else {
1841 if (set_network(ifname, id, "key_mgmt",
1842 "WPA-EAP FILS-SHA256") < 0)
1843 return -2;
1844 }
1845
1846 if (set_network(ifname, id, "erp", "1") < 0)
1847 return -2;
1848 } else if (akm && atoi(akm) == 15) {
1849 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1850 dut->sta_pmf == STA_PMF_REQUIRED) {
1851 if (set_network(ifname, id, "key_mgmt",
1852 "WPA-EAP-SHA256 FILS-SHA384") < 0)
1853 return -2;
1854 } else {
1855 if (set_network(ifname, id, "key_mgmt",
1856 "WPA-EAP FILS-SHA384") < 0)
1857 return -2;
1858 }
1859
1860 if (set_network(ifname, id, "erp", "1") < 0)
1861 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001862 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1863 if (set_network(ifname, id, "key_mgmt",
1864 "WPA-EAP WPA-EAP-SHA256") < 0)
1865 return -2;
1866 } else {
1867 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1868 return -2;
1869 }
1870
1871 val = get_param(cmd, "trustedRootCA");
1872 if (val) {
1873#ifdef ANDROID
1874 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1875 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1876 kvalue);
1877 if (length > 0) {
1878 sigma_dut_print(dut, DUT_MSG_INFO,
1879 "Use Android keystore [%s]", buf);
1880 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1881 val);
1882 goto ca_cert_selected;
1883 }
1884#endif /* ANDROID */
1885
1886 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1887#ifdef __linux__
1888 if (!file_exists(buf)) {
1889 char msg[300];
1890 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1891 "file (%s) not found", buf);
1892 send_resp(dut, conn, SIGMA_ERROR, msg);
1893 return -3;
1894 }
1895#endif /* __linux__ */
1896#ifdef ANDROID
1897ca_cert_selected:
1898#endif /* ANDROID */
1899 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1900 return -2;
1901 }
1902
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301903 if (username_identity) {
1904 val = get_param(cmd, "username");
1905 if (val) {
1906 if (set_network_quoted(ifname, id, "identity", val) < 0)
1907 return -2;
1908 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001909
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301910 val = get_param(cmd, "password");
1911 if (val) {
1912 if (set_network_quoted(ifname, id, "password", val) < 0)
1913 return -2;
1914 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001915 }
1916
1917 return id;
1918}
1919
1920
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001921static int set_tls_cipher(const char *ifname, int id, const char *cipher)
1922{
1923 const char *val;
1924
1925 if (!cipher)
1926 return 0;
1927
1928 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
1929 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
1930 else if (strcasecmp(cipher,
1931 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1932 val = "ECDHE-RSA-AES256-GCM-SHA384";
1933 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1934 val = "DHE-RSA-AES256-GCM-SHA384";
1935 else if (strcasecmp(cipher,
1936 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
1937 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
1938 else
1939 return -1;
1940
1941 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
1942 set_network_quoted(ifname, id, "phase1", "");
1943
1944 return set_network_quoted(ifname, id, "openssl_ciphers", val);
1945}
1946
1947
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001948static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1949 struct sigma_cmd *cmd)
1950{
1951 const char *intf = get_param(cmd, "Interface");
1952 const char *ifname, *val;
1953 int id;
1954 char buf[200];
1955#ifdef ANDROID
1956 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1957 int length;
1958 int jb_or_newer = 0;
1959 char prop[PROPERTY_VALUE_MAX];
1960#endif /* ANDROID */
1961
1962 if (intf == NULL)
1963 return -1;
1964
1965 if (strcmp(intf, get_main_ifname()) == 0)
1966 ifname = get_station_ifname();
1967 else
1968 ifname = intf;
1969
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301970 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001971 if (id < 0)
1972 return id;
1973
1974 if (set_network(ifname, id, "eap", "TLS") < 0)
1975 return -2;
1976
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301977 if (!get_param(cmd, "username") &&
1978 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001979 "wifi-user@wifilabs.local") < 0)
1980 return -2;
1981
1982 val = get_param(cmd, "clientCertificate");
1983 if (val == NULL)
1984 return -1;
1985#ifdef ANDROID
1986 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1987 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1988 if (length < 0) {
1989 /*
1990 * JB started reporting keystore type mismatches, so retry with
1991 * the GET_PUBKEY command if the generic GET fails.
1992 */
1993 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1994 buf, kvalue);
1995 }
1996
1997 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1998 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1999 if (strncmp(prop, "4.0", 3) != 0)
2000 jb_or_newer = 1;
2001 } else
2002 jb_or_newer = 1; /* assume newer */
2003
2004 if (jb_or_newer && length > 0) {
2005 sigma_dut_print(dut, DUT_MSG_INFO,
2006 "Use Android keystore [%s]", buf);
2007 if (set_network(ifname, id, "engine", "1") < 0)
2008 return -2;
2009 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
2010 return -2;
2011 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
2012 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
2013 return -2;
2014 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2015 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2016 return -2;
2017 return 1;
2018 } else if (length > 0) {
2019 sigma_dut_print(dut, DUT_MSG_INFO,
2020 "Use Android keystore [%s]", buf);
2021 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
2022 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2023 return -2;
2024 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
2025 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2026 return -2;
2027 return 1;
2028 }
2029#endif /* ANDROID */
2030
2031 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
2032#ifdef __linux__
2033 if (!file_exists(buf)) {
2034 char msg[300];
2035 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
2036 "(%s) not found", buf);
2037 send_resp(dut, conn, SIGMA_ERROR, msg);
2038 return -3;
2039 }
2040#endif /* __linux__ */
2041 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
2042 return -2;
2043 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
2044 return -2;
2045
2046 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
2047 return -2;
2048
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03002049 val = get_param(cmd, "keyMgmtType");
2050 if (val && strcasecmp(val, "SuiteB") == 0) {
2051 val = get_param(cmd, "CertType");
2052 if (val && strcasecmp(val, "RSA") == 0) {
2053 if (set_network_quoted(ifname, id, "phase1",
2054 "tls_suiteb=1") < 0)
2055 return -2;
2056 } else {
2057 if (set_network_quoted(ifname, id, "openssl_ciphers",
2058 "SUITEB192") < 0)
2059 return -2;
2060 }
2061
2062 val = get_param(cmd, "TLSCipher");
2063 if (set_tls_cipher(ifname, id, val) < 0) {
2064 send_resp(dut, conn, SIGMA_ERROR,
2065 "ErrorCode,Unsupported TLSCipher value");
2066 return -3;
2067 }
2068 }
2069
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002070 return 1;
2071}
2072
2073
2074static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
2075 struct sigma_cmd *cmd)
2076{
2077 const char *intf = get_param(cmd, "Interface");
2078 const char *ifname;
2079 int id;
2080
2081 if (intf == NULL)
2082 return -1;
2083
2084 if (strcmp(intf, get_main_ifname()) == 0)
2085 ifname = get_station_ifname();
2086 else
2087 ifname = intf;
2088
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302089 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002090 if (id < 0)
2091 return id;
2092
2093 if (set_network(ifname, id, "eap", "TTLS") < 0) {
2094 send_resp(dut, conn, SIGMA_ERROR,
2095 "errorCode,Failed to set TTLS method");
2096 return 0;
2097 }
2098
2099 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
2100 send_resp(dut, conn, SIGMA_ERROR,
2101 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
2102 return 0;
2103 }
2104
2105 return 1;
2106}
2107
2108
2109static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
2110 struct sigma_cmd *cmd)
2111{
2112 const char *intf = get_param(cmd, "Interface");
2113 const char *ifname;
2114 int id;
2115
2116 if (intf == NULL)
2117 return -1;
2118
2119 if (strcmp(intf, get_main_ifname()) == 0)
2120 ifname = get_station_ifname();
2121 else
2122 ifname = intf;
2123
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302124 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002125 if (id < 0)
2126 return id;
2127
2128 if (set_network(ifname, id, "eap", "SIM") < 0)
2129 return -2;
2130
2131 return 1;
2132}
2133
2134
2135static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
2136 struct sigma_cmd *cmd)
2137{
2138 const char *intf = get_param(cmd, "Interface");
2139 const char *ifname, *val;
2140 int id;
2141 char buf[100];
2142
2143 if (intf == NULL)
2144 return -1;
2145
2146 if (strcmp(intf, get_main_ifname()) == 0)
2147 ifname = get_station_ifname();
2148 else
2149 ifname = intf;
2150
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302151 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002152 if (id < 0)
2153 return id;
2154
2155 if (set_network(ifname, id, "eap", "PEAP") < 0)
2156 return -2;
2157
2158 val = get_param(cmd, "innerEAP");
2159 if (val) {
2160 if (strcasecmp(val, "MSCHAPv2") == 0) {
2161 if (set_network_quoted(ifname, id, "phase2",
2162 "auth=MSCHAPV2") < 0)
2163 return -2;
2164 } else if (strcasecmp(val, "GTC") == 0) {
2165 if (set_network_quoted(ifname, id, "phase2",
2166 "auth=GTC") < 0)
2167 return -2;
2168 } else
2169 return -1;
2170 }
2171
2172 val = get_param(cmd, "peapVersion");
2173 if (val) {
2174 int ver = atoi(val);
2175 if (ver < 0 || ver > 1)
2176 return -1;
2177 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2178 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2179 return -2;
2180 }
2181
2182 return 1;
2183}
2184
2185
2186static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2187 struct sigma_cmd *cmd)
2188{
2189 const char *intf = get_param(cmd, "Interface");
2190 const char *ifname, *val;
2191 int id;
2192 char buf[100];
2193
2194 if (intf == NULL)
2195 return -1;
2196
2197 if (strcmp(intf, get_main_ifname()) == 0)
2198 ifname = get_station_ifname();
2199 else
2200 ifname = intf;
2201
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302202 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002203 if (id < 0)
2204 return id;
2205
2206 if (set_network(ifname, id, "eap", "FAST") < 0)
2207 return -2;
2208
2209 val = get_param(cmd, "innerEAP");
2210 if (val) {
2211 if (strcasecmp(val, "MSCHAPV2") == 0) {
2212 if (set_network_quoted(ifname, id, "phase2",
2213 "auth=MSCHAPV2") < 0)
2214 return -2;
2215 } else if (strcasecmp(val, "GTC") == 0) {
2216 if (set_network_quoted(ifname, id, "phase2",
2217 "auth=GTC") < 0)
2218 return -2;
2219 } else
2220 return -1;
2221 }
2222
2223 val = get_param(cmd, "validateServer");
2224 if (val) {
2225 /* TODO */
2226 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2227 "validateServer=%s", val);
2228 }
2229
2230 val = get_param(cmd, "pacFile");
2231 if (val) {
2232 snprintf(buf, sizeof(buf), "blob://%s", val);
2233 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2234 return -2;
2235 }
2236
2237 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2238 0)
2239 return -2;
2240
2241 return 1;
2242}
2243
2244
2245static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2246 struct sigma_cmd *cmd)
2247{
2248 const char *intf = get_param(cmd, "Interface");
2249 const char *ifname;
2250 int id;
2251
2252 if (intf == NULL)
2253 return -1;
2254
2255 if (strcmp(intf, get_main_ifname()) == 0)
2256 ifname = get_station_ifname();
2257 else
2258 ifname = intf;
2259
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302260 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002261 if (id < 0)
2262 return id;
2263
2264 if (set_network(ifname, id, "eap", "AKA") < 0)
2265 return -2;
2266
2267 return 1;
2268}
2269
2270
2271static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2272 struct sigma_conn *conn,
2273 struct sigma_cmd *cmd)
2274{
2275 const char *intf = get_param(cmd, "Interface");
2276 const char *ifname;
2277 int id;
2278
2279 if (intf == NULL)
2280 return -1;
2281
2282 if (strcmp(intf, get_main_ifname()) == 0)
2283 ifname = get_station_ifname();
2284 else
2285 ifname = intf;
2286
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302287 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002288 if (id < 0)
2289 return id;
2290
2291 if (set_network(ifname, id, "eap", "AKA'") < 0)
2292 return -2;
2293
2294 return 1;
2295}
2296
2297
2298static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2299 struct sigma_cmd *cmd)
2300{
2301 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002302 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002303 const char *ifname;
2304 int id;
2305
2306 if (strcmp(intf, get_main_ifname()) == 0)
2307 ifname = get_station_ifname();
2308 else
2309 ifname = intf;
2310
2311 id = add_network_common(dut, conn, ifname, cmd);
2312 if (id < 0)
2313 return id;
2314
2315 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2316 return -2;
2317
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002318 if (dut->program == PROGRAM_60GHZ && network_mode &&
2319 strcasecmp(network_mode, "PBSS") == 0 &&
2320 set_network(ifname, id, "pbss", "1") < 0)
2321 return -2;
2322
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002323 return 1;
2324}
2325
2326
Jouni Malinen47dcc952017-10-09 16:43:24 +03002327static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2328 struct sigma_cmd *cmd)
2329{
2330 const char *intf = get_param(cmd, "Interface");
2331 const char *ifname, *val;
2332 int id;
2333
2334 if (intf == NULL)
2335 return -1;
2336
2337 if (strcmp(intf, get_main_ifname()) == 0)
2338 ifname = get_station_ifname();
2339 else
2340 ifname = intf;
2341
2342 id = set_wpa_common(dut, conn, ifname, cmd);
2343 if (id < 0)
2344 return id;
2345
2346 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2347 return -2;
2348
2349 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002350 if (val && strcmp(val, "0") == 0) {
2351 if (wpa_command(ifname,
2352 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2353 sigma_dut_print(dut, DUT_MSG_ERROR,
2354 "Failed to set OWE DH Param element override");
2355 return -2;
2356 }
2357 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002358 sigma_dut_print(dut, DUT_MSG_ERROR,
2359 "Failed to clear owe_group");
2360 return -2;
2361 }
2362
2363 return 1;
2364}
2365
2366
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002367static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2368 struct sigma_cmd *cmd)
2369{
2370 const char *type = get_param(cmd, "Type");
2371
2372 if (type == NULL) {
2373 send_resp(dut, conn, SIGMA_ERROR,
2374 "ErrorCode,Missing Type argument");
2375 return 0;
2376 }
2377
2378 if (strcasecmp(type, "OPEN") == 0)
2379 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002380 if (strcasecmp(type, "OWE") == 0)
2381 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002382 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002383 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002384 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002385 return cmd_sta_set_psk(dut, conn, cmd);
2386 if (strcasecmp(type, "EAPTLS") == 0)
2387 return cmd_sta_set_eaptls(dut, conn, cmd);
2388 if (strcasecmp(type, "EAPTTLS") == 0)
2389 return cmd_sta_set_eapttls(dut, conn, cmd);
2390 if (strcasecmp(type, "EAPPEAP") == 0)
2391 return cmd_sta_set_peap(dut, conn, cmd);
2392 if (strcasecmp(type, "EAPSIM") == 0)
2393 return cmd_sta_set_eapsim(dut, conn, cmd);
2394 if (strcasecmp(type, "EAPFAST") == 0)
2395 return cmd_sta_set_eapfast(dut, conn, cmd);
2396 if (strcasecmp(type, "EAPAKA") == 0)
2397 return cmd_sta_set_eapaka(dut, conn, cmd);
2398 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2399 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002400 if (strcasecmp(type, "wep") == 0)
2401 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002402
2403 send_resp(dut, conn, SIGMA_ERROR,
2404 "ErrorCode,Unsupported Type value");
2405 return 0;
2406}
2407
2408
2409int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2410{
2411#ifdef __linux__
2412 /* special handling for ath6kl */
2413 char path[128], fname[128], *pos;
2414 ssize_t res;
2415 FILE *f;
2416
2417 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
2418 res = readlink(path, path, sizeof(path));
2419 if (res < 0)
2420 return 0; /* not ath6kl */
2421
2422 if (res >= (int) sizeof(path))
2423 res = sizeof(path) - 1;
2424 path[res] = '\0';
2425 pos = strrchr(path, '/');
2426 if (pos == NULL)
2427 pos = path;
2428 else
2429 pos++;
2430 snprintf(fname, sizeof(fname),
2431 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2432 "create_qos", pos);
2433 if (!file_exists(fname))
2434 return 0; /* not ath6kl */
2435
2436 if (uapsd) {
2437 f = fopen(fname, "w");
2438 if (f == NULL)
2439 return -1;
2440
2441 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2442 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2443 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2444 "20000 0\n");
2445 fclose(f);
2446 } else {
2447 snprintf(fname, sizeof(fname),
2448 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2449 "delete_qos", pos);
2450
2451 f = fopen(fname, "w");
2452 if (f == NULL)
2453 return -1;
2454
2455 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2456 fprintf(f, "2 4\n");
2457 fclose(f);
2458 }
2459#endif /* __linux__ */
2460
2461 return 0;
2462}
2463
2464
2465static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2466 struct sigma_cmd *cmd)
2467{
2468 const char *intf = get_param(cmd, "Interface");
2469 /* const char *ssid = get_param(cmd, "ssid"); */
2470 const char *val;
2471 int max_sp_len = 4;
2472 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2473 char buf[100];
2474 int ret1, ret2;
2475
2476 val = get_param(cmd, "maxSPLength");
2477 if (val) {
2478 max_sp_len = atoi(val);
2479 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2480 max_sp_len != 4)
2481 return -1;
2482 }
2483
2484 val = get_param(cmd, "acBE");
2485 if (val)
2486 ac_be = atoi(val);
2487
2488 val = get_param(cmd, "acBK");
2489 if (val)
2490 ac_bk = atoi(val);
2491
2492 val = get_param(cmd, "acVI");
2493 if (val)
2494 ac_vi = atoi(val);
2495
2496 val = get_param(cmd, "acVO");
2497 if (val)
2498 ac_vo = atoi(val);
2499
2500 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2501
2502 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2503 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2504 ret1 = wpa_command(intf, buf);
2505
2506 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2507 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2508 ret2 = wpa_command(intf, buf);
2509
2510 if (ret1 && ret2) {
2511 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2512 "UAPSD parameters.");
2513 return -2;
2514 }
2515
2516 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2517 send_resp(dut, conn, SIGMA_ERROR,
2518 "ErrorCode,Failed to set ath6kl QoS parameters");
2519 return 0;
2520 }
2521
2522 return 1;
2523}
2524
2525
2526static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2527 struct sigma_cmd *cmd)
2528{
2529 char buf[1000];
2530 const char *intf = get_param(cmd, "Interface");
2531 const char *grp = get_param(cmd, "Group");
2532 const char *act = get_param(cmd, "Action");
2533 const char *tid = get_param(cmd, "Tid");
2534 const char *dir = get_param(cmd, "Direction");
2535 const char *psb = get_param(cmd, "Psb");
2536 const char *up = get_param(cmd, "Up");
2537 const char *fixed = get_param(cmd, "Fixed");
2538 const char *size = get_param(cmd, "Size");
2539 const char *msize = get_param(cmd, "Maxsize");
2540 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2541 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2542 const char *inact = get_param(cmd, "Inactivity");
2543 const char *sus = get_param(cmd, "Suspension");
2544 const char *mindr = get_param(cmd, "Mindatarate");
2545 const char *meandr = get_param(cmd, "Meandatarate");
2546 const char *peakdr = get_param(cmd, "Peakdatarate");
2547 const char *phyrate = get_param(cmd, "Phyrate");
2548 const char *burstsize = get_param(cmd, "Burstsize");
2549 const char *sba = get_param(cmd, "Sba");
2550 int direction;
2551 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002552 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002553 int fixed_int;
2554 int psb_ts;
2555
2556 if (intf == NULL || grp == NULL || act == NULL )
2557 return -1;
2558
2559 if (strcasecmp(act, "addts") == 0) {
2560 if (tid == NULL || dir == NULL || psb == NULL ||
2561 up == NULL || fixed == NULL || size == NULL)
2562 return -1;
2563
2564 /*
2565 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2566 * possible values, but WMM-AC and V-E test scripts use "UP,
2567 * "DOWN", and "BIDI".
2568 */
2569 if (strcasecmp(dir, "uplink") == 0 ||
2570 strcasecmp(dir, "up") == 0) {
2571 direction = 0;
2572 } else if (strcasecmp(dir, "downlink") == 0 ||
2573 strcasecmp(dir, "down") == 0) {
2574 direction = 1;
2575 } else if (strcasecmp(dir, "bidi") == 0) {
2576 direction = 2;
2577 } else {
2578 sigma_dut_print(dut, DUT_MSG_ERROR,
2579 "Direction %s not supported", dir);
2580 return -1;
2581 }
2582
2583 if (strcasecmp(psb, "legacy") == 0) {
2584 psb_ts = 0;
2585 } else if (strcasecmp(psb, "uapsd") == 0) {
2586 psb_ts = 1;
2587 } else {
2588 sigma_dut_print(dut, DUT_MSG_ERROR,
2589 "PSB %s not supported", psb);
2590 return -1;
2591 }
2592
2593 if (atoi(tid) < 0 || atoi(tid) > 7) {
2594 sigma_dut_print(dut, DUT_MSG_ERROR,
2595 "TID %s not supported", tid);
2596 return -1;
2597 }
2598
2599 if (strcasecmp(fixed, "true") == 0) {
2600 fixed_int = 1;
2601 } else {
2602 fixed_int = 0;
2603 }
2604
Peng Xu93319622017-10-04 17:58:16 -07002605 if (sba)
2606 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002607
2608 dut->dialog_token++;
2609 handle = 7000 + dut->dialog_token;
2610
2611 /*
2612 * size: convert to hex
2613 * maxsi: convert to hex
2614 * mindr: convert to hex
2615 * meandr: convert to hex
2616 * peakdr: convert to hex
2617 * burstsize: convert to hex
2618 * phyrate: convert to hex
2619 * sba: convert to hex with modification
2620 * minsi: convert to integer
2621 * sus: convert to integer
2622 * inact: convert to integer
2623 * maxsi: convert to integer
2624 */
2625
2626 /*
2627 * The Nominal MSDU Size field is 2 octets long and contains an
2628 * unsigned integer that specifies the nominal size, in octets,
2629 * of MSDUs belonging to the traffic under this traffic
2630 * specification and is defined in Figure 16. If the Fixed
2631 * subfield is set to 1, then the size of the MSDU is fixed and
2632 * is indicated by the Size Subfield. If the Fixed subfield is
2633 * set to 0, then the size of the MSDU might not be fixed and
2634 * the Size indicates the nominal MSDU size.
2635 *
2636 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2637 * and specifies the excess allocation of time (and bandwidth)
2638 * over and above the stated rates required to transport an MSDU
2639 * belonging to the traffic in this TSPEC. This field is
2640 * represented as an unsigned binary number with an implicit
2641 * binary point after the leftmost 3 bits. For example, an SBA
2642 * of 1.75 is represented as 0x3800. This field is included to
2643 * account for retransmissions. As such, the value of this field
2644 * must be greater than unity.
2645 */
2646
2647 snprintf(buf, sizeof(buf),
2648 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2649 " 0x%X 0x%X 0x%X"
2650 " 0x%X 0x%X 0x%X"
2651 " 0x%X %d %d %d %d"
2652 " %d %d",
2653 intf, handle, tid, direction, psb_ts, up,
2654 (unsigned int) ((fixed_int << 15) | atoi(size)),
2655 msize ? atoi(msize) : 0,
2656 mindr ? atoi(mindr) : 0,
2657 meandr ? atoi(meandr) : 0,
2658 peakdr ? atoi(peakdr) : 0,
2659 burstsize ? atoi(burstsize) : 0,
2660 phyrate ? atoi(phyrate) : 0,
2661 sba ? ((unsigned int) (((int) sba_fv << 13) |
2662 (int)((sba_fv - (int) sba_fv) *
2663 8192))) : 0,
2664 minsi ? atoi(minsi) : 0,
2665 sus ? atoi(sus) : 0,
2666 0, 0,
2667 inact ? atoi(inact) : 0,
2668 maxsi ? atoi(maxsi) : 0);
2669
2670 if (system(buf) != 0) {
2671 sigma_dut_print(dut, DUT_MSG_ERROR,
2672 "iwpriv addtspec request failed");
2673 send_resp(dut, conn, SIGMA_ERROR,
2674 "errorCode,Failed to execute addTspec command");
2675 return 0;
2676 }
2677
2678 sigma_dut_print(dut, DUT_MSG_INFO,
2679 "iwpriv addtspec request send");
2680
2681 /* Mapping handle to a TID */
2682 dut->tid_to_handle[atoi(tid)] = handle;
2683 } else if (strcasecmp(act, "delts") == 0) {
2684 if (tid == NULL)
2685 return -1;
2686
2687 if (atoi(tid) < 0 || atoi(tid) > 7) {
2688 sigma_dut_print(dut, DUT_MSG_ERROR,
2689 "TID %s not supported", tid);
2690 send_resp(dut, conn, SIGMA_ERROR,
2691 "errorCode,Unsupported TID");
2692 return 0;
2693 }
2694
2695 handle = dut->tid_to_handle[atoi(tid)];
2696
2697 if (handle < 7000 || handle > 7255) {
2698 /* Invalid handle ie no mapping for that TID */
2699 sigma_dut_print(dut, DUT_MSG_ERROR,
2700 "handle-> %d not found", handle);
2701 }
2702
2703 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2704 intf, handle);
2705
2706 if (system(buf) != 0) {
2707 sigma_dut_print(dut, DUT_MSG_ERROR,
2708 "iwpriv deltspec request failed");
2709 send_resp(dut, conn, SIGMA_ERROR,
2710 "errorCode,Failed to execute delTspec command");
2711 return 0;
2712 }
2713
2714 sigma_dut_print(dut, DUT_MSG_INFO,
2715 "iwpriv deltspec request send");
2716
2717 dut->tid_to_handle[atoi(tid)] = 0;
2718 } else {
2719 sigma_dut_print(dut, DUT_MSG_ERROR,
2720 "Action type %s not supported", act);
2721 send_resp(dut, conn, SIGMA_ERROR,
2722 "errorCode,Unsupported Action");
2723 return 0;
2724 }
2725
2726 return 1;
2727}
2728
2729
vamsi krishna52e16f92017-08-29 12:37:34 +05302730static int find_network(struct sigma_dut *dut, const char *ssid)
2731{
2732 char list[4096];
2733 char *pos;
2734
2735 sigma_dut_print(dut, DUT_MSG_DEBUG,
2736 "Search for profile based on SSID: '%s'", ssid);
2737 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
2738 list, sizeof(list)) < 0)
2739 return -1;
2740 pos = strstr(list, ssid);
2741 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
2742 return -1;
2743
2744 while (pos > list && pos[-1] != '\n')
2745 pos--;
2746 dut->infra_network_id = atoi(pos);
2747 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
2748 return 0;
2749}
2750
2751
Sunil Dutt44595082018-02-12 19:41:45 +05302752#ifdef NL80211_SUPPORT
2753static int sta_config_rsnie(struct sigma_dut *dut, int val)
2754{
2755 struct nl_msg *msg;
2756 int ret;
2757 struct nlattr *params;
2758 int ifindex;
2759
2760 ifindex = if_nametoindex("wlan0");
2761 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
2762 NL80211_CMD_VENDOR)) ||
2763 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
2764 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2765 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2766 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
2767 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2768 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
2769 sigma_dut_print(dut, DUT_MSG_ERROR,
2770 "%s: err in adding vendor_cmd and vendor_data",
2771 __func__);
2772 nlmsg_free(msg);
2773 return -1;
2774 }
2775 nla_nest_end(msg, params);
2776
2777 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
2778 if (ret) {
2779 sigma_dut_print(dut, DUT_MSG_ERROR,
2780 "%s: err in send_and_recv_msgs, ret=%d",
2781 __func__, ret);
2782 return ret;
2783 }
2784
2785 return 0;
2786}
2787#endif /* NL80211_SUPPORT */
2788
2789
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002790static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2791 struct sigma_cmd *cmd)
2792{
2793 /* const char *intf = get_param(cmd, "Interface"); */
2794 const char *ssid = get_param(cmd, "ssid");
2795 const char *wps_param = get_param(cmd, "WPS");
2796 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03002797 const char *chan = get_param(cmd, "channel");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002798 const char *network_mode = get_param(cmd, "network_mode");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002799 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03002800 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002801
2802 if (ssid == NULL)
2803 return -1;
2804
Jouni Malinen3c367e82017-06-23 17:01:47 +03002805 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05302806#ifdef NL80211_SUPPORT
2807 if (get_driver_type() == DRIVER_WCN) {
2808 sta_config_rsnie(dut, 1);
2809 dut->config_rsnie = 1;
2810 }
2811#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03002812 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
2813 dut->rsne_override);
2814 if (wpa_command(get_station_ifname(), buf) < 0) {
2815 send_resp(dut, conn, SIGMA_ERROR,
2816 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
2817 return 0;
2818 }
2819 }
2820
Jouni Malinen68143132017-09-02 02:34:08 +03002821 if (dut->sae_commit_override) {
2822 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
2823 dut->sae_commit_override);
2824 if (wpa_command(get_station_ifname(), buf) < 0) {
2825 send_resp(dut, conn, SIGMA_ERROR,
2826 "ErrorCode,Failed to set SAE commit override");
2827 return 0;
2828 }
2829 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05302830#ifdef ANDROID
2831 if (dut->fils_hlp)
2832 process_fils_hlp(dut);
2833#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03002834
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002835 if (wps_param &&
2836 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2837 wps = 1;
2838
2839 if (wps) {
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02002840 if (dut->program == PROGRAM_60GHZ && network_mode &&
2841 strcasecmp(network_mode, "PBSS") == 0 &&
2842 set_network(get_station_ifname(), dut->infra_network_id,
2843 "pbss", "1") < 0)
2844 return -2;
2845
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002846 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2847 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2848 "parameters not yet set");
2849 return 0;
2850 }
2851 if (dut->wps_method == WFA_CS_WPS_PBC) {
2852 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2853 return -2;
2854 } else {
2855 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2856 dut->wps_pin);
2857 if (wpa_command(get_station_ifname(), buf) < 0)
2858 return -2;
2859 }
2860 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05302861 if (strcmp(ssid, dut->infra_ssid) == 0) {
2862 sigma_dut_print(dut, DUT_MSG_DEBUG,
2863 "sta_associate for the most recently added network");
2864 } else if (find_network(dut, ssid) < 0) {
2865 sigma_dut_print(dut, DUT_MSG_DEBUG,
2866 "sta_associate for a previously stored network profile");
2867 send_resp(dut, conn, SIGMA_ERROR,
2868 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002869 return 0;
2870 }
2871
2872 if (bssid &&
2873 set_network(get_station_ifname(), dut->infra_network_id,
2874 "bssid", bssid) < 0) {
2875 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2876 "Invalid bssid argument");
2877 return 0;
2878 }
2879
Jouni Malinen46a19b62017-06-23 14:31:27 +03002880 extra[0] = '\0';
2881 if (chan)
2882 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02002883 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03002884 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
2885 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002886 if (wpa_command(get_station_ifname(), buf) < 0) {
2887 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2888 "network id %d on %s",
2889 dut->infra_network_id,
2890 get_station_ifname());
2891 return -2;
2892 }
2893 }
2894
2895 return 1;
2896}
2897
2898
2899static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2900{
2901 char buf[500], cmd[200];
2902 int res;
2903
2904 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2905 * default path */
2906 res = snprintf(cmd, sizeof(cmd),
2907 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2908 file_exists("./hs20-osu-client") ?
2909 "./hs20-osu-client" : "hs20-osu-client",
2910 sigma_wpas_ctrl,
2911 dut->summary_log ? "-s " : "",
2912 dut->summary_log ? dut->summary_log : "");
2913 if (res < 0 || res >= (int) sizeof(cmd))
2914 return -1;
2915
2916 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2917 if (res < 0 || res >= (int) sizeof(buf))
2918 return -1;
2919 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2920
2921 if (system(buf) != 0) {
2922 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2923 return -1;
2924 }
2925 sigma_dut_print(dut, DUT_MSG_DEBUG,
2926 "Completed hs20-osu-client operation");
2927
2928 return 0;
2929}
2930
2931
2932static int download_ppsmo(struct sigma_dut *dut,
2933 struct sigma_conn *conn,
2934 const char *intf,
2935 struct sigma_cmd *cmd)
2936{
2937 const char *name, *path, *val;
2938 char url[500], buf[600], fbuf[100];
2939 char *fqdn = NULL;
2940
2941 name = get_param(cmd, "FileName");
2942 path = get_param(cmd, "FilePath");
2943 if (name == NULL || path == NULL)
2944 return -1;
2945
2946 if (strcasecmp(path, "VendorSpecific") == 0) {
2947 snprintf(url, sizeof(url), "PPS/%s", name);
2948 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2949 "from the device (%s)", url);
2950 if (!file_exists(url)) {
2951 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2952 "PPS MO file does not exist");
2953 return 0;
2954 }
2955 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2956 if (system(buf) != 0) {
2957 send_resp(dut, conn, SIGMA_ERROR,
2958 "errorCode,Failed to copy PPS MO");
2959 return 0;
2960 }
2961 } else if (strncasecmp(path, "http:", 5) != 0 &&
2962 strncasecmp(path, "https:", 6) != 0) {
2963 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2964 "Unsupported FilePath value");
2965 return 0;
2966 } else {
2967 snprintf(url, sizeof(url), "%s/%s", path, name);
2968 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2969 url);
2970 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2971 remove("pps-tnds.xml");
2972 if (system(buf) != 0) {
2973 send_resp(dut, conn, SIGMA_ERROR,
2974 "errorCode,Failed to download PPS MO");
2975 return 0;
2976 }
2977 }
2978
2979 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2980 send_resp(dut, conn, SIGMA_ERROR,
2981 "errorCode,Failed to parse downloaded PPSMO");
2982 return 0;
2983 }
2984 unlink("pps-tnds.xml");
2985
2986 val = get_param(cmd, "managementTreeURI");
2987 if (val) {
2988 const char *pos, *end;
2989 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2990 val);
2991 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2992 send_resp(dut, conn, SIGMA_ERROR,
2993 "errorCode,Invalid managementTreeURI prefix");
2994 return 0;
2995 }
2996 pos = val + 8;
2997 end = strchr(pos, '/');
2998 if (end == NULL ||
2999 strcmp(end, "/PerProviderSubscription") != 0) {
3000 send_resp(dut, conn, SIGMA_ERROR,
3001 "errorCode,Invalid managementTreeURI postfix");
3002 return 0;
3003 }
3004 if (end - pos >= (int) sizeof(fbuf)) {
3005 send_resp(dut, conn, SIGMA_ERROR,
3006 "errorCode,Too long FQDN in managementTreeURI");
3007 return 0;
3008 }
3009 memcpy(fbuf, pos, end - pos);
3010 fbuf[end - pos] = '\0';
3011 fqdn = fbuf;
3012 sigma_dut_print(dut, DUT_MSG_INFO,
3013 "FQDN from managementTreeURI: %s", fqdn);
3014 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
3015 FILE *f = fopen("pps-fqdn", "r");
3016 if (f) {
3017 if (fgets(fbuf, sizeof(fbuf), f)) {
3018 fbuf[sizeof(fbuf) - 1] = '\0';
3019 fqdn = fbuf;
3020 sigma_dut_print(dut, DUT_MSG_DEBUG,
3021 "Use FQDN %s", fqdn);
3022 }
3023 fclose(f);
3024 }
3025 }
3026
3027 if (fqdn == NULL) {
3028 send_resp(dut, conn, SIGMA_ERROR,
3029 "errorCode,No FQDN specified");
3030 return 0;
3031 }
3032
3033 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3034 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
3035 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
3036
3037 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
3038 if (rename("pps.xml", buf) < 0) {
3039 send_resp(dut, conn, SIGMA_ERROR,
3040 "errorCode,Could not move PPS MO");
3041 return 0;
3042 }
3043
3044 if (strcasecmp(path, "VendorSpecific") == 0) {
3045 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
3046 fqdn);
3047 if (system(buf)) {
3048 send_resp(dut, conn, SIGMA_ERROR,
3049 "errorCode,Failed to copy OSU CA cert");
3050 return 0;
3051 }
3052
3053 snprintf(buf, sizeof(buf),
3054 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
3055 fqdn);
3056 if (system(buf)) {
3057 send_resp(dut, conn, SIGMA_ERROR,
3058 "errorCode,Failed to copy AAA CA cert");
3059 return 0;
3060 }
3061 } else {
3062 snprintf(buf, sizeof(buf),
3063 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
3064 fqdn, fqdn);
3065 if (run_hs20_osu(dut, buf) < 0) {
3066 send_resp(dut, conn, SIGMA_ERROR,
3067 "errorCode,Failed to download OSU CA cert");
3068 return 0;
3069 }
3070
3071 snprintf(buf, sizeof(buf),
3072 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
3073 fqdn, fqdn);
3074 if (run_hs20_osu(dut, buf) < 0) {
3075 sigma_dut_print(dut, DUT_MSG_INFO,
3076 "Failed to download AAA CA cert");
3077 }
3078 }
3079
3080 if (file_exists("next-client-cert.pem")) {
3081 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
3082 if (rename("next-client-cert.pem", buf) < 0) {
3083 send_resp(dut, conn, SIGMA_ERROR,
3084 "errorCode,Could not move client certificate");
3085 return 0;
3086 }
3087 }
3088
3089 if (file_exists("next-client-key.pem")) {
3090 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
3091 if (rename("next-client-key.pem", buf) < 0) {
3092 send_resp(dut, conn, SIGMA_ERROR,
3093 "errorCode,Could not move client key");
3094 return 0;
3095 }
3096 }
3097
3098 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
3099 if (run_hs20_osu(dut, buf) < 0) {
3100 send_resp(dut, conn, SIGMA_ERROR,
3101 "errorCode,Failed to configure credential from "
3102 "PPSMO");
3103 return 0;
3104 }
3105
3106 return 1;
3107}
3108
3109
3110static int download_cert(struct sigma_dut *dut,
3111 struct sigma_conn *conn,
3112 const char *intf,
3113 struct sigma_cmd *cmd)
3114{
3115 const char *name, *path;
3116 char url[500], buf[600];
3117
3118 name = get_param(cmd, "FileName");
3119 path = get_param(cmd, "FilePath");
3120 if (name == NULL || path == NULL)
3121 return -1;
3122
3123 if (strcasecmp(path, "VendorSpecific") == 0) {
3124 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
3125 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3126 "certificate from the device (%s)", url);
3127 if (!file_exists(url)) {
3128 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3129 "certificate file does not exist");
3130 return 0;
3131 }
3132 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
3133 if (system(buf) != 0) {
3134 send_resp(dut, conn, SIGMA_ERROR,
3135 "errorCode,Failed to copy client "
3136 "certificate");
3137 return 0;
3138 }
3139
3140 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
3141 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
3142 "private key from the device (%s)", url);
3143 if (!file_exists(url)) {
3144 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
3145 "private key file does not exist");
3146 return 0;
3147 }
3148 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
3149 if (system(buf) != 0) {
3150 send_resp(dut, conn, SIGMA_ERROR,
3151 "errorCode,Failed to copy client key");
3152 return 0;
3153 }
3154 } else if (strncasecmp(path, "http:", 5) != 0 &&
3155 strncasecmp(path, "https:", 6) != 0) {
3156 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
3157 "Unsupported FilePath value");
3158 return 0;
3159 } else {
3160 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
3161 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
3162 "certificate/key from %s", url);
3163 snprintf(buf, sizeof(buf),
3164 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
3165 if (system(buf) != 0) {
3166 send_resp(dut, conn, SIGMA_ERROR,
3167 "errorCode,Failed to download client "
3168 "certificate");
3169 return 0;
3170 }
3171
3172 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3173 {
3174 send_resp(dut, conn, SIGMA_ERROR,
3175 "errorCode,Failed to copy client key");
3176 return 0;
3177 }
3178 }
3179
3180 return 1;
3181}
3182
3183
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003184static int cmd_sta_preset_testparameters_60ghz(struct sigma_dut *dut,
3185 struct sigma_conn *conn,
3186 struct sigma_cmd *cmd)
3187{
3188 const char *val;
3189 const char *intf = get_param(cmd, "interface");
3190
3191 if (!intf)
3192 return -1;
3193
3194 val = get_param(cmd, "WscIEFragment");
3195 if (val && strcasecmp(val, "enable") == 0) {
3196 sigma_dut_print(dut, DUT_MSG_DEBUG,
3197 "Enable WSC IE fragmentation");
3198
3199 dut->wsc_fragment = 1;
3200 /* set long attributes to force fragmentation */
3201 if (wpa_command(intf, "SET device_name "
3202 WPS_LONG_DEVICE_NAME) < 0)
3203 return -2;
3204 if (wpa_command(intf, "SET manufacturer "
3205 WPS_LONG_MANUFACTURER) < 0)
3206 return -2;
3207 if (wpa_command(intf, "SET model_name "
3208 WPS_LONG_MODEL_NAME) < 0)
3209 return -2;
3210 if (wpa_command(intf, "SET model_number "
3211 WPS_LONG_MODEL_NUMBER) < 0)
3212 return -2;
3213 if (wpa_command(intf, "SET serial_number "
3214 WPS_LONG_SERIAL_NUMBER) < 0)
3215 return -2;
3216 }
3217
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02003218 val = get_param(cmd, "RSN_IE");
3219 if (val) {
3220 if (strcasecmp(val, "disable") == 0)
3221 dut->force_rsn_ie = FORCE_RSN_IE_REMOVE;
3222 else if (strcasecmp(val, "enable") == 0)
3223 dut->force_rsn_ie = FORCE_RSN_IE_ADD;
3224 }
3225
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02003226 return 1;
3227}
3228
3229
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003230static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3231 struct sigma_conn *conn,
3232 const char *intf,
3233 struct sigma_cmd *cmd)
3234{
3235 const char *val;
3236
3237 val = get_param(cmd, "FileType");
3238 if (val && strcasecmp(val, "PPSMO") == 0)
3239 return download_ppsmo(dut, conn, intf, cmd);
3240 if (val && strcasecmp(val, "CERT") == 0)
3241 return download_cert(dut, conn, intf, cmd);
3242 if (val) {
3243 send_resp(dut, conn, SIGMA_ERROR,
3244 "ErrorCode,Unsupported FileType");
3245 return 0;
3246 }
3247
3248 return 1;
3249}
3250
3251
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303252static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3253 struct sigma_conn *conn,
3254 const char *intf,
3255 struct sigma_cmd *cmd)
3256{
3257 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303258 char buf[1000];
3259 char text[20];
3260 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303261
3262 val = get_param(cmd, "OCESupport");
3263 if (val && strcasecmp(val, "Disable") == 0) {
3264 if (wpa_command(intf, "SET oce 0") < 0) {
3265 send_resp(dut, conn, SIGMA_ERROR,
3266 "ErrorCode,Failed to disable OCE");
3267 return 0;
3268 }
3269 } else if (val && strcasecmp(val, "Enable") == 0) {
3270 if (wpa_command(intf, "SET oce 1") < 0) {
3271 send_resp(dut, conn, SIGMA_ERROR,
3272 "ErrorCode,Failed to enable OCE");
3273 return 0;
3274 }
3275 }
3276
vamsi krishnaa2799492017-12-05 14:28:01 +05303277 val = get_param(cmd, "FILScap");
3278 if (val && (atoi(val) == 1)) {
3279 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3280 send_resp(dut, conn, SIGMA_ERROR,
3281 "ErrorCode,Failed to enable FILS");
3282 return 0;
3283 }
3284 } else if (val && (atoi(val) == 0)) {
3285 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3286 send_resp(dut, conn, SIGMA_ERROR,
3287 "ErrorCode,Failed to disable FILS");
3288 return 0;
3289 }
3290 }
3291
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303292 val = get_param(cmd, "FILSHLP");
3293 if (val && strcasecmp(val, "Enable") == 0) {
3294 if (get_wpa_status(get_station_ifname(), "address", text,
3295 sizeof(text)) < 0)
3296 return -2;
3297 hwaddr_aton(text, addr);
3298 snprintf(buf, sizeof(buf),
3299 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3300 "080045100140000040004011399e00000000ffffffff00440043"
3301 "012cb30001010600fd4f46410000000000000000000000000000"
3302 "000000000000"
3303 "%02x%02x%02x%02x%02x%02x"
3304 "0000000000000000000000000000000000000000000000000000"
3305 "0000000000000000000000000000000000000000000000000000"
3306 "0000000000000000000000000000000000000000000000000000"
3307 "0000000000000000000000000000000000000000000000000000"
3308 "0000000000000000000000000000000000000000000000000000"
3309 "0000000000000000000000000000000000000000000000000000"
3310 "0000000000000000000000000000000000000000000000000000"
3311 "0000000000000000000000000000000000000000638253633501"
3312 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3313 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3314 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3315 if (wpa_command(intf, buf)) {
3316 send_resp(dut, conn, SIGMA_ERROR,
3317 "ErrorCode,Failed to add HLP");
3318 return 0;
3319 }
3320 dut->fils_hlp = 1;
3321 }
3322
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303323 return 1;
3324}
3325
3326
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003327static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3328 const char *val)
3329{
3330 int counter = 0;
3331 char token[50];
3332 char *result;
3333 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303334 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003335
Peng Xub8fc5cc2017-05-10 17:27:28 -07003336 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003337 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303338 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003339 while (result) {
3340 if (strcmp(result, "disable") == 0) {
3341 snprintf(buf, sizeof(buf),
3342 "iwpriv %s noackpolicy %d 1 0",
3343 intf, counter);
3344 } else {
3345 snprintf(buf, sizeof(buf),
3346 "iwpriv %s noackpolicy %d 1 1",
3347 intf, counter);
3348 }
3349 if (system(buf) != 0) {
3350 sigma_dut_print(dut, DUT_MSG_ERROR,
3351 "iwpriv noackpolicy failed");
3352 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303353 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003354 counter++;
3355 }
3356}
3357
3358
3359static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3360 const char *val)
3361{
3362 char buf[100];
3363
3364 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3365 if (system(buf) != 0) {
3366 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3367 }
3368}
3369
3370
3371static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3372 const char *val)
3373{
3374 char buf[100];
3375
3376 if (strcasecmp(val, "off") == 0) {
3377 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
3378 if (system(buf) != 0) {
3379 sigma_dut_print(dut, DUT_MSG_ERROR,
3380 "Failed to turn off WMM");
3381 }
3382 }
3383}
3384
3385
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003386static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3387 const char *val)
3388{
3389#ifdef NL80211_SUPPORT
3390 struct nl_msg *msg;
3391 int ret = 0;
3392 struct nlattr *params;
3393 int ifindex;
3394 int wmmenable = 1;
3395
3396 if (val &&
3397 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3398 wmmenable = 0;
3399
3400 ifindex = if_nametoindex(intf);
3401 if (ifindex == 0) {
3402 sigma_dut_print(dut, DUT_MSG_ERROR,
3403 "%s: Index for interface %s failed",
3404 __func__, intf);
3405 return -1;
3406 }
3407
3408 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3409 NL80211_CMD_VENDOR)) ||
3410 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3411 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3412 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3413 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3414 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3415 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3416 wmmenable)) {
3417 sigma_dut_print(dut, DUT_MSG_ERROR,
3418 "%s: err in adding vendor_cmd and vendor_data",
3419 __func__);
3420 nlmsg_free(msg);
3421 return -1;
3422 }
3423 nla_nest_end(msg, params);
3424
3425 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3426 if (ret) {
3427 sigma_dut_print(dut, DUT_MSG_ERROR,
3428 "%s: err in send_and_recv_msgs, ret=%d",
3429 __func__, ret);
3430 }
3431 return ret;
3432#else /* NL80211_SUPPORT */
3433 sigma_dut_print(dut, DUT_MSG_ERROR,
3434 "WMM cannot be changed without NL80211_SUPPORT defined");
3435 return -1;
3436#endif /* NL80211_SUPPORT */
3437}
3438
3439
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003440static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3441 const char *val)
3442{
3443 char buf[100];
3444 int sgi20;
3445
3446 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3447
3448 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
3449 if (system(buf) != 0)
3450 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
3451}
3452
3453
3454static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3455 const char *val)
3456{
3457 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303458 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003459
3460 /* Disable Tx Beam forming when using a fixed rate */
3461 ath_disable_txbf(dut, intf);
3462
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303463 v = atoi(val);
3464 if (v < 0 || v > 32) {
3465 sigma_dut_print(dut, DUT_MSG_ERROR,
3466 "Invalid Fixed MCS rate: %d", v);
3467 return;
3468 }
3469 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003470
3471 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
3472 intf, rate_code);
3473 if (system(buf) != 0) {
3474 sigma_dut_print(dut, DUT_MSG_ERROR,
3475 "iwpriv set11NRates failed");
3476 }
3477
3478 /* Channel width gets messed up, fix this */
3479 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
3480 if (system(buf) != 0)
3481 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
3482}
3483
3484
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08003485static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3486 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003487{
3488 char buf[60];
3489
3490 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3491 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3492 else
3493 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3494
3495 if (system(buf) != 0)
3496 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3497}
3498
3499
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003500static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3501 int ampdu)
3502{
3503 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003504 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003505
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003506 if (ampdu)
3507 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003508 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3509 if (system(buf) != 0) {
3510 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3511 return -1;
3512 }
3513
3514 return 0;
3515}
3516
3517
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003518static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3519 const char *val)
3520{
3521 char buf[60];
3522
3523 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3524 if (system(buf) != 0) {
3525 sigma_dut_print(dut, DUT_MSG_ERROR,
3526 "iwpriv tx_stbc failed");
3527 }
3528
3529 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3530 if (system(buf) != 0) {
3531 sigma_dut_print(dut, DUT_MSG_ERROR,
3532 "iwpriv rx_stbc failed");
3533 }
3534}
3535
3536
3537static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3538 const char *val)
3539{
3540 char buf[60];
3541
Peng Xucc317ed2017-05-18 16:44:37 -07003542 if (strcmp(val, "160") == 0) {
3543 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3544 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003545 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3546 } else if (strcmp(val, "40") == 0) {
3547 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3548 } else if (strcmp(val, "20") == 0) {
3549 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3550 } else if (strcasecmp(val, "Auto") == 0) {
3551 buf[0] = '\0';
3552 } else {
3553 sigma_dut_print(dut, DUT_MSG_ERROR,
3554 "WIDTH/CTS_WIDTH value not supported");
3555 return -1;
3556 }
3557
3558 if (buf[0] != '\0' && system(buf) != 0) {
3559 sigma_dut_print(dut, DUT_MSG_ERROR,
3560 "Failed to set WIDTH/CTS_WIDTH");
3561 return -1;
3562 }
3563
3564 return 0;
3565}
3566
3567
3568int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3569 const char *intf, const char *val)
3570{
3571 char buf[60];
3572
3573 if (strcasecmp(val, "Auto") == 0) {
3574 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3575 dut->chwidth = 0;
3576 } else if (strcasecmp(val, "20") == 0) {
3577 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3578 dut->chwidth = 0;
3579 } else if (strcasecmp(val, "40") == 0) {
3580 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
3581 dut->chwidth = 1;
3582 } else if (strcasecmp(val, "80") == 0) {
3583 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
3584 dut->chwidth = 2;
3585 } else if (strcasecmp(val, "160") == 0) {
3586 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
3587 dut->chwidth = 3;
3588 } else {
3589 send_resp(dut, conn, SIGMA_ERROR,
3590 "ErrorCode,WIDTH not supported");
3591 return -1;
3592 }
3593
3594 if (system(buf) != 0) {
3595 sigma_dut_print(dut, DUT_MSG_ERROR,
3596 "iwpriv chwidth failed");
3597 }
3598
3599 return 0;
3600}
3601
3602
3603static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3604 const char *val)
3605{
3606 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07003607 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003608
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003609 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003610 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003611 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003612 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003613 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003614 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003615 } else {
3616 sigma_dut_print(dut, DUT_MSG_ERROR,
3617 "SP_STREAM value not supported");
3618 return -1;
3619 }
3620
3621 if (system(buf) != 0) {
3622 sigma_dut_print(dut, DUT_MSG_ERROR,
3623 "Failed to set SP_STREAM");
3624 return -1;
3625 }
3626
Arif Hussainac6c5112018-05-25 17:34:00 -07003627 dut->sta_nss = sta_nss;
3628
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003629 return 0;
3630}
3631
3632
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303633static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3634 const char *val)
3635{
3636 char buf[60];
3637
3638 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3639 if (system(buf) != 0)
3640 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
3641
3642 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3643 if (system(buf) != 0)
3644 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
3645}
3646
3647
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303648static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
3649 struct sigma_conn *conn,
3650 const char *intf, int capa)
3651{
3652 char buf[32];
3653
3654 if (capa > 0 && capa < 4) {
3655 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
3656 if (wpa_command(intf, buf) < 0) {
3657 send_resp(dut, conn, SIGMA_ERROR,
3658 "ErrorCode, Failed to set cellular data capability");
3659 return 0;
3660 }
3661 return 1;
3662 }
3663
3664 sigma_dut_print(dut, DUT_MSG_ERROR,
3665 "Invalid Cellular data capability: %d", capa);
3666 send_resp(dut, conn, SIGMA_INVALID,
3667 "ErrorCode,Invalid cellular data capability");
3668 return 0;
3669}
3670
3671
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303672static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
3673 const char *intf, const char *val)
3674{
3675 if (strcasecmp(val, "Disable") == 0) {
3676 if (wpa_command(intf, "SET roaming 0") < 0) {
3677 send_resp(dut, conn, SIGMA_ERROR,
3678 "ErrorCode,Failed to disable roaming");
3679 return 0;
3680 }
3681 return 1;
3682 }
3683
3684 if (strcasecmp(val, "Enable") == 0) {
3685 if (wpa_command(intf, "SET roaming 1") < 0) {
3686 send_resp(dut, conn, SIGMA_ERROR,
3687 "ErrorCode,Failed to enable roaming");
3688 return 0;
3689 }
3690 return 1;
3691 }
3692
3693 sigma_dut_print(dut, DUT_MSG_ERROR,
3694 "Invalid value provided for roaming: %s", val);
3695 send_resp(dut, conn, SIGMA_INVALID,
3696 "ErrorCode,Unknown value provided for Roaming");
3697 return 0;
3698}
3699
3700
Ashwini Patila75de5a2017-04-13 16:35:05 +05303701static int mbo_set_assoc_disallow(struct sigma_dut *dut,
3702 struct sigma_conn *conn,
3703 const char *intf, const char *val)
3704{
3705 if (strcasecmp(val, "Disable") == 0) {
3706 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
3707 send_resp(dut, conn, SIGMA_ERROR,
3708 "ErrorCode,Failed to disable Assoc_disallow");
3709 return 0;
3710 }
3711 return 1;
3712 }
3713
3714 if (strcasecmp(val, "Enable") == 0) {
3715 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3716 send_resp(dut, conn, SIGMA_ERROR,
3717 "ErrorCode,Failed to enable Assoc_disallow");
3718 return 0;
3719 }
3720 return 1;
3721 }
3722
3723 sigma_dut_print(dut, DUT_MSG_ERROR,
3724 "Invalid value provided for Assoc_disallow: %s", val);
3725 send_resp(dut, conn, SIGMA_INVALID,
3726 "ErrorCode,Unknown value provided for Assoc_disallow");
3727 return 0;
3728}
3729
3730
Ashwini Patilc63161e2017-04-13 16:30:23 +05303731static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3732 const char *intf, const char *val)
3733{
3734 if (strcasecmp(val, "Reject") == 0) {
3735 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3736 send_resp(dut, conn, SIGMA_ERROR,
3737 "ErrorCode,Failed to Reject BTM Request");
3738 return 0;
3739 }
3740 return 1;
3741 }
3742
3743 if (strcasecmp(val, "Accept") == 0) {
3744 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3745 send_resp(dut, conn, SIGMA_ERROR,
3746 "ErrorCode,Failed to Accept BTM Request");
3747 return 0;
3748 }
3749 return 1;
3750 }
3751
3752 sigma_dut_print(dut, DUT_MSG_ERROR,
3753 "Invalid value provided for BSS_Transition: %s", val);
3754 send_resp(dut, conn, SIGMA_INVALID,
3755 "ErrorCode,Unknown value provided for BSS_Transition");
3756 return 0;
3757}
3758
3759
Ashwini Patil00402582017-04-13 12:29:39 +05303760static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3761 struct sigma_conn *conn,
3762 const char *intf,
3763 struct sigma_cmd *cmd)
3764{
3765 const char *ch, *pref, *op_class, *reason;
3766 char buf[120];
3767 int len, ret;
3768
3769 pref = get_param(cmd, "Ch_Pref");
3770 if (!pref)
3771 return 1;
3772
3773 if (strcasecmp(pref, "clear") == 0) {
3774 free(dut->non_pref_ch_list);
3775 dut->non_pref_ch_list = NULL;
3776 } else {
3777 op_class = get_param(cmd, "Ch_Op_Class");
3778 if (!op_class) {
3779 send_resp(dut, conn, SIGMA_INVALID,
3780 "ErrorCode,Ch_Op_Class not provided");
3781 return 0;
3782 }
3783
3784 ch = get_param(cmd, "Ch_Pref_Num");
3785 if (!ch) {
3786 send_resp(dut, conn, SIGMA_INVALID,
3787 "ErrorCode,Ch_Pref_Num not provided");
3788 return 0;
3789 }
3790
3791 reason = get_param(cmd, "Ch_Reason_Code");
3792 if (!reason) {
3793 send_resp(dut, conn, SIGMA_INVALID,
3794 "ErrorCode,Ch_Reason_Code not provided");
3795 return 0;
3796 }
3797
3798 if (!dut->non_pref_ch_list) {
3799 dut->non_pref_ch_list =
3800 calloc(1, NON_PREF_CH_LIST_SIZE);
3801 if (!dut->non_pref_ch_list) {
3802 send_resp(dut, conn, SIGMA_ERROR,
3803 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3804 return 0;
3805 }
3806 }
3807 len = strlen(dut->non_pref_ch_list);
3808 ret = snprintf(dut->non_pref_ch_list + len,
3809 NON_PREF_CH_LIST_SIZE - len,
3810 " %s:%s:%s:%s", op_class, ch, pref, reason);
3811 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3812 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3813 dut->non_pref_ch_list);
3814 } else {
3815 sigma_dut_print(dut, DUT_MSG_ERROR,
3816 "snprintf failed for non_pref_list, ret = %d",
3817 ret);
3818 send_resp(dut, conn, SIGMA_ERROR,
3819 "ErrorCode,snprintf failed");
3820 free(dut->non_pref_ch_list);
3821 dut->non_pref_ch_list = NULL;
3822 return 0;
3823 }
3824 }
3825
3826 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3827 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3828 if (ret < 0 || ret >= (int) sizeof(buf)) {
3829 sigma_dut_print(dut, DUT_MSG_DEBUG,
3830 "snprintf failed for set non_pref_chan, ret: %d",
3831 ret);
3832 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3833 return 0;
3834 }
3835
3836 if (wpa_command(intf, buf) < 0) {
3837 send_resp(dut, conn, SIGMA_ERROR,
3838 "ErrorCode,Failed to set non-preferred channel list");
3839 return 0;
3840 }
3841
3842 return 1;
3843}
3844
3845
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003846#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003847
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08003848static int sta_set_he_htc_supp(struct sigma_dut *dut, const char *intf,
3849 uint8_t cfg)
3850{
3851 struct nl_msg *msg;
3852 int ret = 0;
3853 struct nlattr *params;
3854 int ifindex;
3855
3856 ifindex = if_nametoindex(intf);
3857 if (ifindex == 0) {
3858 sigma_dut_print(dut, DUT_MSG_ERROR,
3859 "%s: Index for interface %s failed",
3860 __func__, intf);
3861 return -1;
3862 }
3863
3864 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3865 NL80211_CMD_VENDOR)) ||
3866 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3867 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3868 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3869 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3870 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3871 nla_put_u8(msg,
3872 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_HTC_HE_SUPP,
3873 cfg)) {
3874 sigma_dut_print(dut, DUT_MSG_ERROR,
3875 "%s: err in adding vendor_cmd and vendor_data",
3876 __func__);
3877 nlmsg_free(msg);
3878 return -1;
3879 }
3880 nla_nest_end(msg, params);
3881
3882 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3883 if (ret) {
3884 sigma_dut_print(dut, DUT_MSG_ERROR,
3885 "%s: err in send_and_recv_msgs, ret=%d",
3886 __func__, ret);
3887 }
3888 return ret;
3889}
3890
3891
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003892static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
3893 enum he_fragmentation_val frag)
3894{
3895 struct nl_msg *msg;
3896 int ret = 0;
3897 struct nlattr *params;
3898 int ifindex;
3899
3900 ifindex = if_nametoindex(intf);
3901 if (ifindex == 0) {
3902 sigma_dut_print(dut, DUT_MSG_ERROR,
3903 "%s: Index for interface %s failed",
3904 __func__, intf);
3905 return -1;
3906 }
3907
3908 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3909 NL80211_CMD_VENDOR)) ||
3910 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3911 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3912 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3913 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3914 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3915 nla_put_u8(msg,
3916 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
3917 frag)) {
3918 sigma_dut_print(dut, DUT_MSG_ERROR,
3919 "%s: err in adding vendor_cmd and vendor_data",
3920 __func__);
3921 nlmsg_free(msg);
3922 return -1;
3923 }
3924 nla_nest_end(msg, params);
3925
3926 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3927 if (ret) {
3928 sigma_dut_print(dut, DUT_MSG_ERROR,
3929 "%s: err in send_and_recv_msgs, ret=%d",
3930 __func__, ret);
3931 }
3932 return ret;
3933}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003934
3935
Subhani Shaik8e7a3052018-04-24 14:03:00 -07003936static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
3937 enum qca_wlan_he_ltf_cfg ltf)
3938{
3939 struct nl_msg *msg;
3940 int ret = 0;
3941 struct nlattr *params;
3942 int ifindex;
3943
3944 ifindex = if_nametoindex(intf);
3945 if (ifindex == 0) {
3946 sigma_dut_print(dut, DUT_MSG_ERROR,
3947 "%s: Index for interface %s failed",
3948 __func__, intf);
3949 return -1;
3950 }
3951
3952 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3953 NL80211_CMD_VENDOR)) ||
3954 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3955 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3956 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3957 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3958 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3959 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
3960 ltf)) {
3961 sigma_dut_print(dut, DUT_MSG_ERROR,
3962 "%s: err in adding vendor_cmd and vendor_data",
3963 __func__);
3964 nlmsg_free(msg);
3965 return -1;
3966 }
3967 nla_nest_end(msg, params);
3968
3969 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3970 if (ret) {
3971 sigma_dut_print(dut, DUT_MSG_ERROR,
3972 "%s: err in send_and_recv_msgs, ret=%d",
3973 __func__, ret);
3974 }
3975 return ret;
3976}
3977
3978
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003979static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
3980 int noack, enum qca_wlan_ac_type ac)
3981{
3982 struct nl_msg *msg;
3983 int ret = 0;
3984 struct nlattr *params;
3985 int ifindex;
3986
3987 ifindex = if_nametoindex(intf);
3988 if (ifindex == 0) {
3989 sigma_dut_print(dut, DUT_MSG_ERROR,
3990 "%s: Index for interface %s failed",
3991 __func__, intf);
3992 return -1;
3993 }
3994
3995 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3996 NL80211_CMD_VENDOR)) ||
3997 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3998 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3999 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4000 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4001 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4002 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
4003 noack) ||
4004 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
4005 ac)) {
4006 sigma_dut_print(dut, DUT_MSG_ERROR,
4007 "%s: err in adding vendor_cmd and vendor_data",
4008 __func__);
4009 nlmsg_free(msg);
4010 return -1;
4011 }
4012 nla_nest_end(msg, params);
4013
4014 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4015 if (ret) {
4016 sigma_dut_print(dut, DUT_MSG_ERROR,
4017 "%s: err in send_and_recv_msgs, ret=%d",
4018 __func__, ret);
4019 }
4020 return ret;
4021}
4022
4023
4024static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
4025 const char *val)
4026{
4027 int noack, ret;
4028 char token[100];
4029 char *result;
4030 char *saveptr;
4031 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
4032
4033 strlcpy(token, val, sizeof(token));
4034 token[sizeof(token) - 1] = '\0';
4035 result = strtok_r(token, ":", &saveptr);
4036 while (result) {
4037 noack = strcasecmp(result, "Disable") != 0;
4038 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
4039 if (ret) {
4040 sigma_dut_print(dut, DUT_MSG_ERROR,
4041 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
4042 ac, ret);
4043 }
4044 result = strtok_r(NULL, ":", &saveptr);
4045 ac++;
4046 }
4047}
4048
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08004049#endif /* NL80211_SUPPORT */
4050
4051
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004052static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
4053 struct sigma_conn *conn,
4054 struct sigma_cmd *cmd)
4055{
4056 const char *intf = get_param(cmd, "Interface");
4057 const char *val;
4058
4059 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03004060 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
4061 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004062 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
4063 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004064
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004065 if (val && strcasecmp(val, "LOC") == 0)
4066 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02004067 if (val && strcasecmp(val, "60GHZ") == 0) {
4068 val = get_param(cmd, "WPS");
4069 if (val && strcasecmp(val, "disable") == 0) {
4070 dut->wps_disable = 1;
4071 sigma_dut_print(dut, DUT_MSG_INFO, "WPS disabled");
4072 } else {
4073 /* wps_disable can have other value from the previous
4074 * test, so make sure it has the correct value.
4075 */
4076 dut->wps_disable = 0;
4077 }
4078
4079 val = get_param(cmd, "P2P");
4080 if (val && strcasecmp(val, "disable") == 0)
4081 sigma_dut_print(dut, DUT_MSG_INFO, "P2P disabled");
4082 }
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004083
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02004084 if (dut->program == PROGRAM_WPS && dut->band == WPS_BAND_60G)
4085 return cmd_sta_preset_testparameters_60ghz(dut, conn, cmd);
4086
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004087#ifdef ANDROID_NAN
4088 if (val && strcasecmp(val, "NAN") == 0)
4089 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
4090#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004091#ifdef MIRACAST
4092 if (val && (strcasecmp(val, "WFD") == 0 ||
4093 strcasecmp(val, "DisplayR2") == 0))
4094 return miracast_preset_testparameters(dut, conn, cmd);
4095#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004096
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304097 if (val && strcasecmp(val, "MBO") == 0) {
4098 val = get_param(cmd, "Cellular_Data_Cap");
4099 if (val &&
4100 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
4101 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05304102
4103 val = get_param(cmd, "Ch_Pref");
4104 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
4105 return 0;
4106
Ashwini Patilc63161e2017-04-13 16:30:23 +05304107 val = get_param(cmd, "BSS_Transition");
4108 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
4109 return 0;
4110
Ashwini Patila75de5a2017-04-13 16:35:05 +05304111 val = get_param(cmd, "Assoc_Disallow");
4112 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
4113 return 0;
4114
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304115 val = get_param(cmd, "Roaming");
4116 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
4117 return 0;
4118
Ashwini Patil68d02cd2017-01-10 15:39:16 +05304119 return 1;
4120 }
4121
Ankita Bajaja2cb5672017-10-25 16:08:28 +05304122 if (val && strcasecmp(val, "OCE") == 0)
4123 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
4124
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004125#if 0
4126 val = get_param(cmd, "Supplicant");
4127 if (val && strcasecmp(val, "Default") != 0) {
4128 send_resp(dut, conn, SIGMA_ERROR,
4129 "ErrorCode,Only default(Vendor) supplicant "
4130 "supported");
4131 return 0;
4132 }
4133#endif
4134
4135 val = get_param(cmd, "RTS");
4136 if (val) {
4137 switch (get_driver_type()) {
4138 case DRIVER_ATHEROS:
4139 ath_sta_set_rts(dut, intf, val);
4140 break;
4141 default:
4142#if 0
4143 send_resp(dut, conn, SIGMA_ERROR,
4144 "ErrorCode,Setting RTS not supported");
4145 return 0;
4146#else
4147 sigma_dut_print(dut, DUT_MSG_DEBUG,
4148 "Setting RTS not supported");
4149 break;
4150#endif
4151 }
4152 }
4153
4154#if 0
4155 val = get_param(cmd, "FRGMNT");
4156 if (val) {
4157 /* TODO */
4158 send_resp(dut, conn, SIGMA_ERROR,
4159 "ErrorCode,Setting FRGMNT not supported");
4160 return 0;
4161 }
4162#endif
4163
4164#if 0
4165 val = get_param(cmd, "Preamble");
4166 if (val) {
4167 /* TODO: Long/Short */
4168 send_resp(dut, conn, SIGMA_ERROR,
4169 "ErrorCode,Setting Preamble not supported");
4170 return 0;
4171 }
4172#endif
4173
4174 val = get_param(cmd, "Mode");
4175 if (val) {
4176 if (strcmp(val, "11b") == 0 ||
4177 strcmp(val, "11g") == 0 ||
4178 strcmp(val, "11a") == 0 ||
4179 strcmp(val, "11n") == 0 ||
4180 strcmp(val, "11ng") == 0 ||
4181 strcmp(val, "11nl") == 0 ||
4182 strcmp(val, "11nl(nabg)") == 0 ||
4183 strcmp(val, "AC") == 0 ||
4184 strcmp(val, "11AC") == 0 ||
4185 strcmp(val, "11ac") == 0 ||
4186 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08004187 strcmp(val, "11an") == 0 ||
4188 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004189 /* STA supports all modes by default */
4190 } else {
4191 send_resp(dut, conn, SIGMA_ERROR,
4192 "ErrorCode,Setting Mode not supported");
4193 return 0;
4194 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004195
4196 /* Change the mode only in case of testbed for HE program
4197 * and for 11a and 11g modes only. */
4198 if (dut->program == PROGRAM_HE &&
4199 dut->device_type == STA_testbed) {
4200 int phymode;
4201 char buf[60];
4202
4203 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08004204 phymode = 1; /* IEEE80211_MODE_11A */
4205 } else if (strcmp(val, "11g") == 0) {
4206 phymode = 3; /* IEEE80211_MODE_11G */
4207 } else if (strcmp(val, "11b") == 0) {
4208 phymode = 2; /* IEEE80211_MODE_11B */
4209 } else if (strcmp(val, "11n") == 0 ||
4210 strcmp(val, "11nl") == 0 ||
4211 strcmp(val, "11nl(nabg)") == 0) {
4212 phymode = 22; /* IEEE80211_MODE_11AGN */
4213 } else if (strcmp(val, "11ng") == 0) {
4214 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
4215 } else if (strcmp(val, "AC") == 0 ||
4216 strcasecmp(val, "11AC") == 0) {
4217 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
4218 } else if (strcmp(val, "11na") == 0 ||
4219 strcasecmp(val, "11an") == 0) {
4220 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
4221 } else if (strcmp(val, "11ax") == 0) {
4222 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08004223 } else {
4224 sigma_dut_print(dut, DUT_MSG_DEBUG,
4225 "Ignoring mode change for mode: %s",
4226 val);
4227 phymode = -1;
4228 }
4229 if (phymode != -1) {
4230 snprintf(buf, sizeof(buf),
4231 "iwpriv %s setphymode %d",
4232 intf, phymode);
4233 if (system(buf) != 0) {
4234 sigma_dut_print(dut, DUT_MSG_ERROR,
4235 "iwpriv setting of phymode failed");
4236 }
4237 }
4238 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004239 }
4240
4241 val = get_param(cmd, "wmm");
4242 if (val) {
4243 switch (get_driver_type()) {
4244 case DRIVER_ATHEROS:
4245 ath_sta_set_wmm(dut, intf, val);
4246 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08004247 case DRIVER_WCN:
4248 wcn_sta_set_wmm(dut, intf, val);
4249 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004250 default:
4251 sigma_dut_print(dut, DUT_MSG_DEBUG,
4252 "Setting wmm not supported");
4253 break;
4254 }
4255 }
4256
4257 val = get_param(cmd, "Powersave");
4258 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004259 char buf[60];
4260
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004261 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004262 if (get_driver_type() == DRIVER_WCN) {
4263 snprintf(buf, sizeof(buf),
4264 "iwpriv %s setPower 2", intf);
4265 if (system(buf) != 0) {
4266 sigma_dut_print(dut, DUT_MSG_ERROR,
4267 "iwpriv setPower 2 failed");
4268 return 0;
4269 }
4270 }
4271
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004272 if (wpa_command(get_station_ifname(),
4273 "P2P_SET ps 0") < 0)
4274 return -2;
4275 /* Make sure test modes are disabled */
4276 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4277 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4278 } else if (strcmp(val, "1") == 0 ||
4279 strcasecmp(val, "PSPoll") == 0 ||
4280 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004281 if (get_driver_type() == DRIVER_WCN) {
4282 snprintf(buf, sizeof(buf),
4283 "iwpriv %s setPower 1", intf);
4284 if (system(buf) != 0) {
4285 sigma_dut_print(dut, DUT_MSG_ERROR,
4286 "iwpriv setPower 1 failed");
4287 return 0;
4288 }
4289 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004290 /* Disable default power save mode */
4291 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4292 /* Enable PS-Poll test mode */
4293 if (wpa_command(get_station_ifname(),
4294 "P2P_SET ps 97") < 0 ||
4295 wpa_command(get_station_ifname(),
4296 "P2P_SET ps 99") < 0)
4297 return -2;
4298 } else if (strcmp(val, "2") == 0 ||
4299 strcasecmp(val, "Fast") == 0) {
4300 /* TODO */
4301 send_resp(dut, conn, SIGMA_ERROR,
4302 "ErrorCode,Powersave=Fast not supported");
4303 return 0;
4304 } else if (strcmp(val, "3") == 0 ||
4305 strcasecmp(val, "PSNonPoll") == 0) {
4306 /* Make sure test modes are disabled */
4307 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4308 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4309
4310 /* Enable default power save mode */
4311 if (wpa_command(get_station_ifname(),
4312 "P2P_SET ps 1") < 0)
4313 return -2;
4314 } else
4315 return -1;
4316 }
4317
4318 val = get_param(cmd, "NoAck");
4319 if (val) {
4320 switch (get_driver_type()) {
4321 case DRIVER_ATHEROS:
4322 ath_sta_set_noack(dut, intf, val);
4323 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004324#ifdef NL80211_SUPPORT
4325 case DRIVER_WCN:
4326 wcn_sta_set_noack(dut, intf, val);
4327 break;
4328#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004329 default:
4330 send_resp(dut, conn, SIGMA_ERROR,
4331 "ErrorCode,Setting NoAck not supported");
4332 return 0;
4333 }
4334 }
4335
4336 val = get_param(cmd, "IgnoreChswitchProhibit");
4337 if (val) {
4338 /* TODO: Enabled/disabled */
4339 if (strcasecmp(val, "Enabled") == 0) {
4340 send_resp(dut, conn, SIGMA_ERROR,
4341 "ErrorCode,Enabling IgnoreChswitchProhibit "
4342 "not supported");
4343 return 0;
4344 }
4345 }
4346
4347 val = get_param(cmd, "TDLS");
4348 if (val) {
4349 if (strcasecmp(val, "Disabled") == 0) {
4350 if (wpa_command(intf, "SET tdls_disabled 1")) {
4351 send_resp(dut, conn, SIGMA_ERROR,
4352 "ErrorCode,Failed to disable TDLS");
4353 return 0;
4354 }
4355 } else if (strcasecmp(val, "Enabled") == 0) {
4356 if (wpa_command(intf, "SET tdls_disabled 0")) {
4357 send_resp(dut, conn, SIGMA_ERROR,
4358 "ErrorCode,Failed to enable TDLS");
4359 return 0;
4360 }
4361 } else {
4362 send_resp(dut, conn, SIGMA_ERROR,
4363 "ErrorCode,Unsupported TDLS value");
4364 return 0;
4365 }
4366 }
4367
4368 val = get_param(cmd, "TDLSmode");
4369 if (val) {
4370 if (strcasecmp(val, "Default") == 0) {
4371 wpa_command(intf, "SET tdls_testing 0");
4372 } else if (strcasecmp(val, "APProhibit") == 0) {
4373 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4374 send_resp(dut, conn, SIGMA_ERROR,
4375 "ErrorCode,Failed to enable ignore "
4376 "APProhibit TDLS mode");
4377 return 0;
4378 }
4379 } else if (strcasecmp(val, "HiLoMac") == 0) {
4380 /* STA should respond with TDLS setup req for a TDLS
4381 * setup req */
4382 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4383 send_resp(dut, conn, SIGMA_ERROR,
4384 "ErrorCode,Failed to enable HiLoMac "
4385 "TDLS mode");
4386 return 0;
4387 }
4388 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4389 /*
4390 * Since all security modes are enabled by default when
4391 * Sigma control is used, there is no need to do
4392 * anything here.
4393 */
4394 } else if (strcasecmp(val, "ExistLink") == 0) {
4395 /*
4396 * Since we allow new TDLS Setup Request even if there
4397 * is an existing link, nothing needs to be done for
4398 * this.
4399 */
4400 } else {
4401 /* TODO:
4402 * ExistLink: STA should send TDLS setup req even if
4403 * direct link already exists
4404 */
4405 send_resp(dut, conn, SIGMA_ERROR,
4406 "ErrorCode,Unsupported TDLSmode value");
4407 return 0;
4408 }
4409 }
4410
4411 val = get_param(cmd, "FakePubKey");
4412 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4413 send_resp(dut, conn, SIGMA_ERROR,
4414 "ErrorCode,Failed to enable FakePubKey");
4415 return 0;
4416 }
4417
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004418#ifdef NL80211_SUPPORT
4419 val = get_param(cmd, "FrgmntSupport");
4420 if (val) {
4421 if (strcasecmp(val, "Enable") == 0) {
4422 if (sta_set_he_fragmentation(dut, intf,
4423 HE_FRAG_LEVEL1)) {
4424 send_resp(dut, conn, SIGMA_ERROR,
4425 "ErrorCode,Failed to enable HE Fragmentation");
4426 return 0;
4427 }
4428 } else if (strcasecmp(val, "Disable") == 0) {
4429 if (sta_set_he_fragmentation(dut, intf,
4430 HE_FRAG_DISABLE)) {
4431 send_resp(dut, conn, SIGMA_ERROR,
4432 "ErrorCode,Failed to disable HE Fragmentation");
4433 return 0;
4434 }
4435 }
4436 }
4437#endif /* NL80211_SUPPORT */
4438
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004439 return 1;
4440}
4441
4442
4443static const char * ath_get_radio_name(const char *radio_name)
4444{
4445 if (radio_name == NULL)
4446 return "wifi0";
4447 if (strcmp(radio_name, "wifi1") == 0)
4448 return "wifi1";
4449 if (strcmp(radio_name, "wifi2") == 0)
4450 return "wifi2";
4451 return "wifi0";
4452}
4453
4454
4455static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4456 const char *val)
4457{
4458 char buf[60];
4459 unsigned int vht_mcsmap = 0;
4460 int txchainmask = 0;
4461 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4462
4463 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4464 if (dut->testbed_flag_txsp == 1) {
4465 vht_mcsmap = 0xfffc;
4466 dut->testbed_flag_txsp = 0;
4467 } else {
4468 vht_mcsmap = 0xfffe;
4469 }
4470 txchainmask = 1;
4471 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4472 if (dut->testbed_flag_txsp == 1) {
4473 vht_mcsmap = 0xfff0;
4474 dut->testbed_flag_txsp = 0;
4475 } else {
4476 vht_mcsmap = 0xfffa;
4477 }
4478 txchainmask = 3;
4479 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4480 if (dut->testbed_flag_txsp == 1) {
4481 vht_mcsmap = 0xffc0;
4482 dut->testbed_flag_txsp = 0;
4483 } else {
4484 vht_mcsmap = 0xffea;
4485 }
4486 txchainmask = 7;
4487 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4488 if (dut->testbed_flag_txsp == 1) {
4489 vht_mcsmap = 0xff00;
4490 dut->testbed_flag_txsp = 0;
4491 } else {
4492 vht_mcsmap = 0xffaa;
4493 }
4494 txchainmask = 15;
4495 } else {
4496 if (dut->testbed_flag_txsp == 1) {
4497 vht_mcsmap = 0xffc0;
4498 dut->testbed_flag_txsp = 0;
4499 } else {
4500 vht_mcsmap = 0xffea;
4501 }
4502 }
4503
4504 if (txchainmask) {
4505 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4506 basedev, txchainmask);
4507 if (system(buf) != 0) {
4508 sigma_dut_print(dut, DUT_MSG_ERROR,
4509 "iwpriv txchainmask failed");
4510 }
4511 }
4512
4513 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4514 intf, vht_mcsmap);
4515 if (system(buf) != 0) {
4516 sigma_dut_print(dut, DUT_MSG_ERROR,
4517 "iwpriv %s vht_mcsmap 0x%04x failed",
4518 intf, vht_mcsmap);
4519 }
4520}
4521
4522
4523static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4524 const char *val)
4525{
4526 char buf[60];
4527 unsigned int vht_mcsmap = 0;
4528 int rxchainmask = 0;
4529 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4530
4531 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4532 if (dut->testbed_flag_rxsp == 1) {
4533 vht_mcsmap = 0xfffc;
4534 dut->testbed_flag_rxsp = 0;
4535 } else {
4536 vht_mcsmap = 0xfffe;
4537 }
4538 rxchainmask = 1;
4539 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4540 if (dut->testbed_flag_rxsp == 1) {
4541 vht_mcsmap = 0xfff0;
4542 dut->testbed_flag_rxsp = 0;
4543 } else {
4544 vht_mcsmap = 0xfffa;
4545 }
4546 rxchainmask = 3;
4547 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4548 if (dut->testbed_flag_rxsp == 1) {
4549 vht_mcsmap = 0xffc0;
4550 dut->testbed_flag_rxsp = 0;
4551 } else {
4552 vht_mcsmap = 0xffea;
4553 }
4554 rxchainmask = 7;
4555 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4556 if (dut->testbed_flag_rxsp == 1) {
4557 vht_mcsmap = 0xff00;
4558 dut->testbed_flag_rxsp = 0;
4559 } else {
4560 vht_mcsmap = 0xffaa;
4561 }
4562 rxchainmask = 15;
4563 } else {
4564 if (dut->testbed_flag_rxsp == 1) {
4565 vht_mcsmap = 0xffc0;
4566 dut->testbed_flag_rxsp = 0;
4567 } else {
4568 vht_mcsmap = 0xffea;
4569 }
4570 }
4571
4572 if (rxchainmask) {
4573 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4574 basedev, rxchainmask);
4575 if (system(buf) != 0) {
4576 sigma_dut_print(dut, DUT_MSG_ERROR,
4577 "iwpriv rxchainmask failed");
4578 }
4579 }
4580
4581 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4582 intf, vht_mcsmap);
4583 if (system(buf) != 0) {
4584 sigma_dut_print(dut, DUT_MSG_ERROR,
4585 "iwpriv %s vht_mcsmap 0x%04x",
4586 intf, vht_mcsmap);
4587 }
4588}
4589
4590
4591void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4592{
4593 if (strcasecmp(val, "enable") == 0) {
4594 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4595 != 0) {
4596 sigma_dut_print(dut, DUT_MSG_ERROR,
4597 "Disable BB_VHTSIGB_CRC_CALC failed");
4598 }
4599
4600 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4601 != 0) {
4602 sigma_dut_print(dut, DUT_MSG_ERROR,
4603 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4604 }
4605 } else {
4606 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4607 != 0) {
4608 sigma_dut_print(dut, DUT_MSG_ERROR,
4609 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4610 }
4611
4612 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4613 != 0) {
4614 sigma_dut_print(dut, DUT_MSG_ERROR,
4615 "Enable BB_VHTSIGB_CRC_CALC failed");
4616 }
4617 }
4618}
4619
4620
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004621static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4622 const char *val)
4623{
4624 char buf[60];
4625
4626 if (strcmp(val, "20") == 0) {
4627 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4628 dut->chwidth = 0;
4629 } else if (strcmp(val, "40") == 0) {
4630 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4631 dut->chwidth = 1;
4632 } else if (strcmp(val, "80") == 0) {
4633 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4634 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05304635 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004636 buf[0] = '\0';
4637 } else {
4638 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4639 val);
4640 return -1;
4641 }
4642
4643 if (buf[0] != '\0' && system(buf) != 0) {
4644 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4645 return -1;
4646 }
4647
4648 return 0;
4649}
4650
4651
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004652static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4653 const char *intf, int addbareject)
4654{
4655#ifdef NL80211_SUPPORT
4656 struct nl_msg *msg;
4657 int ret = 0;
4658 struct nlattr *params;
4659 int ifindex;
4660
4661 ifindex = if_nametoindex(intf);
4662 if (ifindex == 0) {
4663 sigma_dut_print(dut, DUT_MSG_ERROR,
4664 "%s: Index for interface %s failed",
4665 __func__, intf);
4666 return -1;
4667 }
4668
4669 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4670 NL80211_CMD_VENDOR)) ||
4671 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4672 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4673 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4674 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4675 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4676 nla_put_u8(msg,
4677 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4678 !addbareject)) {
4679 sigma_dut_print(dut, DUT_MSG_ERROR,
4680 "%s: err in adding vendor_cmd and vendor_data",
4681 __func__);
4682 nlmsg_free(msg);
4683 return -1;
4684 }
4685 nla_nest_end(msg, params);
4686
4687 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4688 if (ret) {
4689 sigma_dut_print(dut, DUT_MSG_ERROR,
4690 "%s: err in send_and_recv_msgs, ret=%d",
4691 __func__, ret);
4692 }
4693 return ret;
4694#else /* NL80211_SUPPORT */
4695 sigma_dut_print(dut, DUT_MSG_ERROR,
4696 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4697 return -1;
4698#endif /* NL80211_SUPPORT */
4699}
4700
4701
4702static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4703 int addbareject)
4704{
4705 int ret;
4706
4707 switch (get_driver_type()) {
4708 case DRIVER_WCN:
4709 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4710 if (ret) {
4711 sigma_dut_print(dut, DUT_MSG_ERROR,
4712 "nlvendor_sta_set_addba_reject failed, ret:%d",
4713 ret);
4714 return ret;
4715 }
4716 break;
4717 default:
4718 sigma_dut_print(dut, DUT_MSG_ERROR,
4719 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4720 ret = -1;
4721 break;
4722 }
4723
4724 return ret;
4725}
4726
4727
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004728static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
4729 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004730{
4731#ifdef NL80211_SUPPORT
4732 struct nl_msg *msg;
4733 int ret = 0;
4734 struct nlattr *params;
4735 int ifindex;
4736
4737 ifindex = if_nametoindex(intf);
4738 if (ifindex == 0) {
4739 sigma_dut_print(dut, DUT_MSG_ERROR,
4740 "%s: Index for interface %s failed",
4741 __func__, intf);
4742 return -1;
4743 }
4744
4745 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4746 NL80211_CMD_VENDOR)) ||
4747 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4748 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4749 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4750 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4751 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4752 nla_put_u8(msg,
4753 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004754 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004755 sigma_dut_print(dut, DUT_MSG_ERROR,
4756 "%s: err in adding vendor_cmd and vendor_data",
4757 __func__);
4758 nlmsg_free(msg);
4759 return -1;
4760 }
4761 nla_nest_end(msg, params);
4762
4763 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4764 if (ret) {
4765 sigma_dut_print(dut, DUT_MSG_ERROR,
4766 "%s: err in send_and_recv_msgs, ret=%d",
4767 __func__, ret);
4768 }
4769 return ret;
4770#else /* NL80211_SUPPORT */
4771 sigma_dut_print(dut, DUT_MSG_ERROR,
4772 "Disable addba not possible without NL80211_SUPPORT defined");
4773 return -1;
4774#endif /* NL80211_SUPPORT */
4775}
4776
4777
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004778static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4779 struct sigma_conn *conn,
4780 struct sigma_cmd *cmd)
4781{
4782 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004783 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004784 char buf[30];
4785
4786 val = get_param(cmd, "40_INTOLERANT");
4787 if (val) {
4788 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4789 /* TODO: iwpriv ht40intol through wpa_supplicant */
4790 send_resp(dut, conn, SIGMA_ERROR,
4791 "ErrorCode,40_INTOLERANT not supported");
4792 return 0;
4793 }
4794 }
4795
4796 val = get_param(cmd, "ADDBA_REJECT");
4797 if (val) {
4798 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4799 /* reject any ADDBA with status "decline" */
4800 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004801 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004802 } else {
4803 /* accept ADDBA */
4804 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004805 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004806 }
4807 }
4808
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004809 if (addbareject >= 0 &&
4810 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4811 send_resp(dut, conn, SIGMA_ERROR,
4812 "ErrorCode,set addba_reject failed");
4813 return 0;
4814 }
4815
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004816 val = get_param(cmd, "AMPDU");
4817 if (val) {
4818 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4819 /* enable AMPDU Aggregation */
4820 if (ampdu == 0) {
4821 send_resp(dut, conn, SIGMA_ERROR,
4822 "ErrorCode,Mismatch in "
4823 "addba_reject/ampdu - "
4824 "not supported");
4825 return 0;
4826 }
4827 ampdu = 1;
4828 } else {
4829 /* disable AMPDU Aggregation */
4830 if (ampdu == 1) {
4831 send_resp(dut, conn, SIGMA_ERROR,
4832 "ErrorCode,Mismatch in "
4833 "addba_reject/ampdu - "
4834 "not supported");
4835 return 0;
4836 }
4837 ampdu = 0;
4838 }
4839 }
4840
4841 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004842 int ret;
4843
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004844 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4845 ampdu ? "Enabling" : "Disabling");
4846 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004847 if (wpa_command(intf, buf) < 0 &&
4848 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004849 send_resp(dut, conn, SIGMA_ERROR,
4850 "ErrorCode,set aggr failed");
4851 return 0;
4852 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004853
4854 if (ampdu == 0) {
4855 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004856 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004857 if (ret) {
4858 sigma_dut_print(dut, DUT_MSG_ERROR,
4859 "Failed to disable addba, ret:%d",
4860 ret);
4861 }
4862 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004863 }
4864
4865 val = get_param(cmd, "AMSDU");
4866 if (val) {
4867 switch (get_driver_type()) {
4868 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004869 case DRIVER_WCN:
4870 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004871 break;
4872 default:
4873 if (strcmp(val, "1") == 0 ||
4874 strcasecmp(val, "Enable") == 0) {
4875 /* Enable AMSDU Aggregation */
4876 send_resp(dut, conn, SIGMA_ERROR,
4877 "ErrorCode,AMSDU aggregation not supported");
4878 return 0;
4879 }
4880 break;
4881 }
4882 }
4883
4884 val = get_param(cmd, "STBC_RX");
4885 if (val) {
4886 switch (get_driver_type()) {
4887 case DRIVER_ATHEROS:
4888 ath_sta_set_stbc(dut, intf, val);
4889 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304890 case DRIVER_WCN:
4891 wcn_sta_set_stbc(dut, intf, val);
4892 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004893 default:
4894 send_resp(dut, conn, SIGMA_ERROR,
4895 "ErrorCode,STBC_RX not supported");
4896 return 0;
4897 }
4898 }
4899
4900 val = get_param(cmd, "WIDTH");
4901 if (val) {
4902 switch (get_driver_type()) {
4903 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004904 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004905 send_resp(dut, conn, SIGMA_ERROR,
4906 "ErrorCode,Failed to set WIDTH");
4907 return 0;
4908 }
4909 break;
4910 case DRIVER_ATHEROS:
4911 if (ath_set_width(dut, conn, intf, val) < 0)
4912 return 0;
4913 break;
4914 default:
4915 sigma_dut_print(dut, DUT_MSG_ERROR,
4916 "Setting WIDTH not supported");
4917 break;
4918 }
4919 }
4920
4921 val = get_param(cmd, "SMPS");
4922 if (val) {
4923 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4924 send_resp(dut, conn, SIGMA_ERROR,
4925 "ErrorCode,SMPS not supported");
4926 return 0;
4927 }
4928
4929 val = get_param(cmd, "TXSP_STREAM");
4930 if (val) {
4931 switch (get_driver_type()) {
4932 case DRIVER_WCN:
4933 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4934 send_resp(dut, conn, SIGMA_ERROR,
4935 "ErrorCode,Failed to set TXSP_STREAM");
4936 return 0;
4937 }
4938 break;
4939 case DRIVER_ATHEROS:
4940 ath_sta_set_txsp_stream(dut, intf, val);
4941 break;
4942 default:
4943 sigma_dut_print(dut, DUT_MSG_ERROR,
4944 "Setting TXSP_STREAM not supported");
4945 break;
4946 }
4947 }
4948
4949 val = get_param(cmd, "RXSP_STREAM");
4950 if (val) {
4951 switch (get_driver_type()) {
4952 case DRIVER_WCN:
4953 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4954 send_resp(dut, conn, SIGMA_ERROR,
4955 "ErrorCode,Failed to set RXSP_STREAM");
4956 return 0;
4957 }
4958 break;
4959 case DRIVER_ATHEROS:
4960 ath_sta_set_rxsp_stream(dut, intf, val);
4961 break;
4962 default:
4963 sigma_dut_print(dut, DUT_MSG_ERROR,
4964 "Setting RXSP_STREAM not supported");
4965 break;
4966 }
4967 }
4968
4969 val = get_param(cmd, "DYN_BW_SGNL");
4970 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004971 switch (get_driver_type()) {
4972 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004973 if (strcasecmp(val, "enable") == 0) {
4974 snprintf(buf, sizeof(buf),
4975 "iwpriv %s cwmenable 1", intf);
4976 if (system(buf) != 0) {
4977 sigma_dut_print(dut, DUT_MSG_ERROR,
4978 "iwpriv cwmenable 1 failed");
4979 return 0;
4980 }
4981 } else if (strcasecmp(val, "disable") == 0) {
4982 snprintf(buf, sizeof(buf),
4983 "iwpriv %s cwmenable 0", intf);
4984 if (system(buf) != 0) {
4985 sigma_dut_print(dut, DUT_MSG_ERROR,
4986 "iwpriv cwmenable 0 failed");
4987 return 0;
4988 }
4989 } else {
4990 sigma_dut_print(dut, DUT_MSG_ERROR,
4991 "Unsupported DYN_BW_SGL");
4992 }
4993
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004994 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4995 if (system(buf) != 0) {
4996 sigma_dut_print(dut, DUT_MSG_ERROR,
4997 "Failed to set cts_cbw in DYN_BW_SGNL");
4998 return 0;
4999 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005000 break;
5001 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005002 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08005003 ath_config_dyn_bw_sig(dut, intf, val);
5004 break;
5005 default:
5006 sigma_dut_print(dut, DUT_MSG_ERROR,
5007 "Failed to set DYN_BW_SGNL");
5008 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005009 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005010 }
5011
5012 val = get_param(cmd, "RTS_FORCE");
5013 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08005014 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005015 if (strcasecmp(val, "Enable") == 0) {
5016 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005017 if (system(buf) != 0) {
5018 sigma_dut_print(dut, DUT_MSG_ERROR,
5019 "Failed to set RTS_FORCE 64");
5020 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08005021 snprintf(buf, sizeof(buf),
5022 "wifitool %s beeliner_fw_test 100 1", intf);
5023 if (system(buf) != 0) {
5024 sigma_dut_print(dut, DUT_MSG_ERROR,
5025 "wifitool beeliner_fw_test 100 1 failed");
5026 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005027 } else if (strcasecmp(val, "Disable") == 0) {
5028 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
5029 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02005030 if (system(buf) != 0) {
5031 sigma_dut_print(dut, DUT_MSG_ERROR,
5032 "Failed to set RTS_FORCE 2347");
5033 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005034 } else {
5035 send_resp(dut, conn, SIGMA_ERROR,
5036 "ErrorCode,RTS_FORCE value not supported");
5037 return 0;
5038 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005039 }
5040
5041 val = get_param(cmd, "CTS_WIDTH");
5042 if (val) {
5043 switch (get_driver_type()) {
5044 case DRIVER_WCN:
5045 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
5046 send_resp(dut, conn, SIGMA_ERROR,
5047 "ErrorCode,Failed to set CTS_WIDTH");
5048 return 0;
5049 }
5050 break;
5051 case DRIVER_ATHEROS:
5052 ath_set_cts_width(dut, intf, val);
5053 break;
5054 default:
5055 sigma_dut_print(dut, DUT_MSG_ERROR,
5056 "Setting CTS_WIDTH not supported");
5057 break;
5058 }
5059 }
5060
5061 val = get_param(cmd, "BW_SGNL");
5062 if (val) {
5063 if (strcasecmp(val, "Enable") == 0) {
5064 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
5065 intf);
5066 } else if (strcasecmp(val, "Disable") == 0) {
5067 /* TODO: Disable */
5068 buf[0] = '\0';
5069 } else {
5070 send_resp(dut, conn, SIGMA_ERROR,
5071 "ErrorCode,BW_SGNL value not supported");
5072 return 0;
5073 }
5074
5075 if (buf[0] != '\0' && system(buf) != 0) {
5076 sigma_dut_print(dut, DUT_MSG_ERROR,
5077 "Failed to set BW_SGNL");
5078 }
5079 }
5080
5081 val = get_param(cmd, "Band");
5082 if (val) {
5083 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
5084 /* STA supports all bands by default */
5085 } else {
5086 send_resp(dut, conn, SIGMA_ERROR,
5087 "ErrorCode,Unsupported Band");
5088 return 0;
5089 }
5090 }
5091
5092 val = get_param(cmd, "zero_crc");
5093 if (val) {
5094 switch (get_driver_type()) {
5095 case DRIVER_ATHEROS:
5096 ath_set_zero_crc(dut, val);
5097 break;
5098 default:
5099 break;
5100 }
5101 }
5102
5103 return 1;
5104}
5105
5106
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005107static int sta_set_force_mcs(struct sigma_dut *dut, int force, int mcs)
5108{
5109 switch (get_driver_type()) {
5110#ifdef __linux__
5111 case DRIVER_WIL6210:
5112 return wil6210_set_force_mcs(dut, force, mcs);
5113#endif /* __linux__ */
5114 default:
5115 sigma_dut_print(dut, DUT_MSG_ERROR,
5116 "Unsupported sta_set_force_mcs with the current driver");
5117 return -1;
5118 }
5119}
5120
5121
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02005122static int sta_60g_force_rsn_ie(struct sigma_dut *dut, int state)
5123{
5124 switch (get_driver_type()) {
5125#ifdef __linux__
5126 case DRIVER_WIL6210:
5127 return wil6210_force_rsn_ie(dut, state);
5128#endif /* __linux__ */
5129 default:
5130 sigma_dut_print(dut, DUT_MSG_ERROR,
5131 "Unsupported sta_60g_force_rsn_ie with the current driver");
5132 return -1;
5133 }
5134}
5135
5136
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005137static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
5138 struct sigma_cmd *cmd)
5139{
5140 const char *val;
5141 char buf[100];
5142
5143 val = get_param(cmd, "MSDUSize");
5144 if (val) {
5145 int mtu;
5146
5147 dut->amsdu_size = atoi(val);
5148 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
5149 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
5150 sigma_dut_print(dut, DUT_MSG_ERROR,
5151 "MSDUSize %d is above max %d or below min %d",
5152 dut->amsdu_size,
5153 IEEE80211_MAX_DATA_LEN_DMG,
5154 IEEE80211_SNAP_LEN_DMG);
5155 dut->amsdu_size = 0;
5156 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5157 }
5158
5159 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
5160 sigma_dut_print(dut, DUT_MSG_DEBUG,
5161 "Setting amsdu_size to %d", mtu);
5162 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
5163 get_station_ifname(), mtu);
5164
5165 if (system(buf) != 0) {
5166 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
5167 buf);
5168 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5169 }
5170 }
5171
5172 val = get_param(cmd, "BAckRcvBuf");
5173 if (val) {
5174 dut->back_rcv_buf = atoi(val);
5175 if (dut->back_rcv_buf == 0) {
5176 sigma_dut_print(dut, DUT_MSG_ERROR,
5177 "Failed to convert %s or value is 0",
5178 val);
5179 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5180 }
5181
5182 sigma_dut_print(dut, DUT_MSG_DEBUG,
5183 "Setting BAckRcvBuf to %s", val);
5184 }
5185
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005186 val = get_param(cmd, "MCS_FixedRate");
5187 if (val) {
5188 if (sta_set_force_mcs(dut, 1, atoi(val))) {
5189 sigma_dut_print(dut, DUT_MSG_ERROR,
5190 "Failed to force MCS");
5191 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5192 }
5193 }
5194
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005195 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
5196}
5197
5198
5199static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
5200 struct sigma_cmd *cmd)
5201{
5202 int net_id;
5203 char *ifname;
5204 const char *val;
5205 char buf[100];
5206
5207 dut->mode = SIGMA_MODE_STATION;
5208 ifname = get_main_ifname();
5209 if (wpa_command(ifname, "PING") != 0) {
5210 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
5211 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5212 }
5213
5214 wpa_command(ifname, "FLUSH");
5215 net_id = add_network_common(dut, conn, ifname, cmd);
5216 if (net_id < 0) {
5217 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
5218 return net_id;
5219 }
5220
5221 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
5222 if (set_network(ifname, net_id, "mode", "2") < 0) {
5223 sigma_dut_print(dut, DUT_MSG_ERROR,
5224 "Failed to set supplicant network mode");
5225 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5226 }
5227
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +02005228 if (set_network(ifname, net_id, "pbss", "1") < 0)
5229 return -2;
5230
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005231 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005232 "Supplicant set network with mode 2. network_id %d",
5233 net_id);
5234
5235 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
5236 sigma_dut_print(dut, DUT_MSG_INFO,
5237 "Failed to set supplicant to WPS ENABLE");
5238 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5239 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005240
5241 val = get_param(cmd, "Security");
5242 if (val && strcasecmp(val, "OPEN") == 0) {
5243 dut->ap_key_mgmt = AP_OPEN;
5244 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
5245 sigma_dut_print(dut, DUT_MSG_ERROR,
5246 "Failed to set supplicant to %s security",
5247 val);
5248 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5249 }
5250 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
5251 dut->ap_key_mgmt = AP_WPA2_PSK;
5252 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
5253 sigma_dut_print(dut, DUT_MSG_ERROR,
5254 "Failed to set supplicant to %s security",
5255 val);
5256 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5257 }
5258
5259 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
5260 sigma_dut_print(dut, DUT_MSG_ERROR,
5261 "Failed to set supplicant to proto RSN");
5262 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5263 }
5264 } else if (val) {
5265 sigma_dut_print(dut, DUT_MSG_ERROR,
5266 "Requested Security %s is not supported on 60GHz",
5267 val);
5268 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
5269 }
5270
5271 val = get_param(cmd, "Encrypt");
5272 if (val && strcasecmp(val, "AES-GCMP") == 0) {
5273 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
5274 sigma_dut_print(dut, DUT_MSG_ERROR,
5275 "Failed to set supplicant to pairwise GCMP");
5276 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5277 }
5278 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
5279 sigma_dut_print(dut, DUT_MSG_ERROR,
5280 "Failed to set supplicant to group GCMP");
5281 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5282 }
5283 } else if (val) {
5284 sigma_dut_print(dut, DUT_MSG_ERROR,
5285 "Requested Encrypt %s is not supported on 60 GHz",
5286 val);
5287 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
5288 }
5289
5290 val = get_param(cmd, "PSK");
5291 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
5292 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
5293 val);
5294 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5295 }
5296
5297 /* Convert 60G channel to freq */
5298 switch (dut->ap_channel) {
5299 case 1:
5300 val = "58320";
5301 break;
5302 case 2:
5303 val = "60480";
5304 break;
5305 case 3:
5306 val = "62640";
5307 break;
5308 default:
5309 sigma_dut_print(dut, DUT_MSG_ERROR,
5310 "Failed to configure channel %d. Not supported",
5311 dut->ap_channel);
5312 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5313 }
5314
5315 if (set_network(ifname, net_id, "frequency", val) < 0) {
5316 sigma_dut_print(dut, DUT_MSG_ERROR,
5317 "Failed to set supplicant network frequency");
5318 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5319 }
5320
5321 sigma_dut_print(dut, DUT_MSG_DEBUG,
5322 "Supplicant set network with frequency");
5323
5324 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5325 if (wpa_command(ifname, buf) < 0) {
5326 sigma_dut_print(dut, DUT_MSG_INFO,
5327 "Failed to select network id %d on %s",
5328 net_id, ifname);
5329 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5330 }
5331
5332 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5333
5334 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
5335}
5336
5337
Lior David67543f52017-01-03 19:04:22 +02005338static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5339{
5340 char buf[128], fname[128];
5341 FILE *f;
5342
5343 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5344 sigma_dut_print(dut, DUT_MSG_ERROR,
5345 "failed to get wil6210 debugfs dir");
5346 return -1;
5347 }
5348
5349 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5350 f = fopen(fname, "w");
5351 if (!f) {
5352 sigma_dut_print(dut, DUT_MSG_ERROR,
5353 "failed to open: %s", fname);
5354 return -1;
5355 }
5356
5357 fprintf(f, "%d\n", abft_len);
5358 fclose(f);
5359
5360 return 0;
5361}
5362
5363
5364static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5365 int abft_len)
5366{
5367 switch (get_driver_type()) {
5368 case DRIVER_WIL6210:
5369 return wil6210_set_abft_len(dut, abft_len);
5370 default:
5371 sigma_dut_print(dut, DUT_MSG_ERROR,
5372 "set abft_len not supported");
5373 return -1;
5374 }
5375}
5376
5377
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005378static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5379 struct sigma_cmd *cmd)
5380{
5381 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005382 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005383
5384 if (dut->dev_role != DEVROLE_PCP) {
5385 send_resp(dut, conn, SIGMA_INVALID,
5386 "ErrorCode,Invalid DevRole");
5387 return 0;
5388 }
5389
5390 val = get_param(cmd, "SSID");
5391 if (val) {
5392 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5393 send_resp(dut, conn, SIGMA_INVALID,
5394 "ErrorCode,Invalid SSID");
5395 return -1;
5396 }
5397
Peng Xub8fc5cc2017-05-10 17:27:28 -07005398 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005399 }
5400
5401 val = get_param(cmd, "CHANNEL");
5402 if (val) {
5403 const char *pos;
5404
5405 dut->ap_channel = atoi(val);
5406 pos = strchr(val, ';');
5407 if (pos) {
5408 pos++;
5409 dut->ap_channel_1 = atoi(pos);
5410 }
5411 }
5412
5413 switch (dut->ap_channel) {
5414 case 1:
5415 case 2:
5416 case 3:
5417 break;
5418 default:
5419 sigma_dut_print(dut, DUT_MSG_ERROR,
5420 "Channel %d is not supported", dut->ap_channel);
5421 send_resp(dut, conn, SIGMA_ERROR,
5422 "Requested channel is not supported");
5423 return -1;
5424 }
5425
5426 val = get_param(cmd, "BCNINT");
5427 if (val)
5428 dut->ap_bcnint = atoi(val);
5429
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005430 val = get_param(cmd, "AllocType");
5431 if (val) {
5432 send_resp(dut, conn, SIGMA_ERROR,
5433 "ErrorCode,AllocType is not supported yet");
5434 return -1;
5435 }
5436
5437 val = get_param(cmd, "PercentBI");
5438 if (val) {
5439 send_resp(dut, conn, SIGMA_ERROR,
5440 "ErrorCode,PercentBI is not supported yet");
5441 return -1;
5442 }
5443
5444 val = get_param(cmd, "CBAPOnly");
5445 if (val) {
5446 send_resp(dut, conn, SIGMA_ERROR,
5447 "ErrorCode,CBAPOnly is not supported yet");
5448 return -1;
5449 }
5450
5451 val = get_param(cmd, "AMPDU");
5452 if (val) {
5453 if (strcasecmp(val, "Enable") == 0)
5454 dut->ap_ampdu = 1;
5455 else if (strcasecmp(val, "Disable") == 0)
5456 dut->ap_ampdu = 2;
5457 else {
5458 send_resp(dut, conn, SIGMA_ERROR,
5459 "ErrorCode,AMPDU value is not Enable nor Disabled");
5460 return -1;
5461 }
5462 }
5463
5464 val = get_param(cmd, "AMSDU");
5465 if (val) {
5466 if (strcasecmp(val, "Enable") == 0)
5467 dut->ap_amsdu = 1;
5468 else if (strcasecmp(val, "Disable") == 0)
5469 dut->ap_amsdu = 2;
5470 }
5471
5472 val = get_param(cmd, "NumMSDU");
5473 if (val) {
5474 send_resp(dut, conn, SIGMA_ERROR,
5475 "ErrorCode, NumMSDU is not supported yet");
5476 return -1;
5477 }
5478
5479 val = get_param(cmd, "ABFTLRang");
5480 if (val) {
5481 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005482 "ABFTLRang parameter %s", val);
5483 if (strcmp(val, "Gt1") == 0)
5484 abft_len = 2; /* 2 slots in this case */
5485 }
5486
5487 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5488 send_resp(dut, conn, SIGMA_ERROR,
5489 "ErrorCode, Can't set ABFT length");
5490 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005491 }
5492
5493 if (sta_pcp_start(dut, conn, cmd) < 0) {
5494 send_resp(dut, conn, SIGMA_ERROR,
5495 "ErrorCode, Can't start PCP role");
5496 return -1;
5497 }
5498
5499 return sta_set_60g_common(dut, conn, cmd);
5500}
5501
5502
5503static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5504 struct sigma_cmd *cmd)
5505{
5506 const char *val = get_param(cmd, "DiscoveryMode");
5507
5508 if (dut->dev_role != DEVROLE_STA) {
5509 send_resp(dut, conn, SIGMA_INVALID,
5510 "ErrorCode,Invalid DevRole");
5511 return 0;
5512 }
5513
5514 if (val) {
5515 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5516 /* Ignore Discovery mode till Driver expose API. */
5517#if 0
5518 if (strcasecmp(val, "1") == 0) {
5519 send_resp(dut, conn, SIGMA_INVALID,
5520 "ErrorCode,DiscoveryMode 1 not supported");
5521 return 0;
5522 }
5523
5524 if (strcasecmp(val, "0") == 0) {
5525 /* OK */
5526 } else {
5527 send_resp(dut, conn, SIGMA_INVALID,
5528 "ErrorCode,DiscoveryMode not supported");
5529 return 0;
5530 }
5531#endif
5532 }
5533
5534 if (start_sta_mode(dut) != 0)
5535 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5536 return sta_set_60g_common(dut, conn, cmd);
5537}
5538
5539
5540static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5541 struct sigma_cmd *cmd)
5542{
5543 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005544 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305545
Jouni Malinened77e672018-01-10 16:45:13 +02005546 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005547 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005548 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305549 wpa_command(intf, "DISCONNECT");
5550 return 1;
5551 }
5552
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005553 disconnect_station(dut);
5554 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5555 * due to cached results. */
5556 wpa_command(intf, "SET ignore_old_scan_res 1");
5557 wpa_command(intf, "BSS_FLUSH");
5558 return 1;
5559}
5560
5561
5562static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5563 struct sigma_cmd *cmd)
5564{
5565 const char *intf = get_param(cmd, "Interface");
5566 const char *bssid = get_param(cmd, "bssid");
5567 const char *val = get_param(cmd, "CHANNEL");
5568 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305569 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305570 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005571 int res;
5572 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305573 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305574 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005575
5576 if (bssid == NULL) {
5577 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5578 "argument");
5579 return 0;
5580 }
5581
5582 if (val)
5583 chan = atoi(val);
5584
5585 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5586 /* The current network may be from sta_associate or
5587 * sta_hs2_associate
5588 */
5589 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5590 0 ||
5591 set_network(intf, 0, "bssid", bssid) < 0)
5592 return -2;
5593 }
5594
5595 ctrl = open_wpa_mon(intf);
5596 if (ctrl == NULL) {
5597 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5598 "wpa_supplicant monitor connection");
5599 return -1;
5600 }
5601
Sunil Duttd30ce092018-01-11 23:56:29 +05305602 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5603 sizeof(result)) < 0 ||
5604 strncmp(result, "COMPLETED", 9) != 0) {
5605 sigma_dut_print(dut, DUT_MSG_DEBUG,
5606 "sta_reassoc: Not connected");
5607 fastreassoc = 0;
5608 }
5609
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305610 if (dut->rsne_override) {
5611#ifdef NL80211_SUPPORT
5612 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5613 sta_config_rsnie(dut, 1);
5614 dut->config_rsnie = 1;
5615 }
5616#endif /* NL80211_SUPPORT */
5617 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5618 dut->rsne_override);
5619 if (wpa_command(intf, buf) < 0) {
5620 send_resp(dut, conn, SIGMA_ERROR,
5621 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5622 return 0;
5623 }
5624 }
5625
Sunil Duttd30ce092018-01-11 23:56:29 +05305626 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005627#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305628 if (chan) {
5629 unsigned int freq;
5630
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02005631 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305632 if (!freq) {
5633 sigma_dut_print(dut, DUT_MSG_ERROR,
5634 "Invalid channel number provided: %d",
5635 chan);
5636 send_resp(dut, conn, SIGMA_INVALID,
5637 "ErrorCode,Invalid channel number");
5638 goto close_mon_conn;
5639 }
5640 res = snprintf(buf, sizeof(buf),
5641 "SCAN TYPE=ONLY freq=%d", freq);
5642 } else {
5643 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5644 }
5645 if (res < 0 || res >= (int) sizeof(buf)) {
5646 send_resp(dut, conn, SIGMA_ERROR,
5647 "ErrorCode,snprintf failed");
5648 goto close_mon_conn;
5649 }
5650 if (wpa_command(intf, buf) < 0) {
5651 sigma_dut_print(dut, DUT_MSG_INFO,
5652 "Failed to start scan");
5653 send_resp(dut, conn, SIGMA_ERROR,
5654 "ErrorCode,scan failed");
5655 goto close_mon_conn;
5656 }
5657
5658 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5659 buf, sizeof(buf));
5660 if (res < 0) {
5661 sigma_dut_print(dut, DUT_MSG_INFO,
5662 "Scan did not complete");
5663 send_resp(dut, conn, SIGMA_ERROR,
5664 "ErrorCode,scan did not complete");
5665 goto close_mon_conn;
5666 }
5667
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005668 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5669 < 0) {
5670 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5671 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305672 status = -2;
5673 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005674 }
5675 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5676 bssid, chan);
5677 if (res > 0 && res < (int) sizeof(buf))
5678 res = wpa_command(intf, buf);
5679
5680 if (res < 0 || res >= (int) sizeof(buf)) {
5681 send_resp(dut, conn, SIGMA_ERROR,
5682 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305683 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005684 }
5685#else /* ANDROID */
5686 sigma_dut_print(dut, DUT_MSG_DEBUG,
5687 "Reassoc using iwpriv - skip chan=%d info",
5688 chan);
5689 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5690 if (system(buf) != 0) {
5691 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305692 status = -2;
5693 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005694 }
5695#endif /* ANDROID */
5696 sigma_dut_print(dut, DUT_MSG_INFO,
5697 "sta_reassoc: Run %s successful", buf);
5698 } else if (wpa_command(intf, "REASSOCIATE")) {
5699 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5700 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305701 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005702 }
5703
5704 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5705 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305706 if (res < 0) {
5707 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5708 status = -1;
5709 goto close_mon_conn;
5710 }
5711 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005712
Ashwini Patil467efef2017-05-25 12:18:27 +05305713close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005714 wpa_ctrl_detach(ctrl);
5715 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305716 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005717}
5718
5719
5720static void hs2_clear_credentials(const char *intf)
5721{
5722 wpa_command(intf, "REMOVE_CRED all");
5723}
5724
5725
Lior Davidcc88b562017-01-03 18:52:09 +02005726#ifdef __linux__
5727static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5728 unsigned int *aid)
5729{
Lior David0fe101e2017-03-09 16:09:50 +02005730 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005731
Lior David0fe101e2017-03-09 16:09:50 +02005732 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005733}
5734#endif /* __linux__ */
5735
5736
5737static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5738 unsigned int *aid)
5739{
5740 switch (get_driver_type()) {
5741#ifdef __linux__
5742 case DRIVER_WIL6210:
5743 return wil6210_get_aid(dut, bssid, aid);
5744#endif /* __linux__ */
5745 default:
5746 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5747 return -1;
5748 }
5749}
5750
5751
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005752static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5753 struct sigma_cmd *cmd)
5754{
5755 char buf[MAX_CMD_LEN];
5756 char bss_list[MAX_CMD_LEN];
5757 const char *parameter = get_param(cmd, "Parameter");
5758
5759 if (parameter == NULL)
5760 return -1;
5761
Lior Davidcc88b562017-01-03 18:52:09 +02005762 if (strcasecmp(parameter, "AID") == 0) {
5763 unsigned int aid = 0;
5764 char bssid[20];
5765
5766 if (get_wpa_status(get_station_ifname(), "bssid",
5767 bssid, sizeof(bssid)) < 0) {
5768 sigma_dut_print(dut, DUT_MSG_ERROR,
5769 "could not get bssid");
5770 return -2;
5771 }
5772
5773 if (sta_get_aid_60g(dut, bssid, &aid))
5774 return -2;
5775
5776 snprintf(buf, sizeof(buf), "aid,%d", aid);
5777 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5778 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5779 return 0;
5780 }
5781
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005782 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5783 char *bss_line;
5784 char *bss_id = NULL;
5785 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305786 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005787
5788 if (ifname == NULL) {
5789 sigma_dut_print(dut, DUT_MSG_INFO,
5790 "For get DiscoveredDevList need Interface name.");
5791 return -1;
5792 }
5793
5794 /*
5795 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5796 * of BSSIDs in "bssid=<BSSID>\n"
5797 */
5798 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5799 bss_list,
5800 sizeof(bss_list)) < 0) {
5801 sigma_dut_print(dut, DUT_MSG_ERROR,
5802 "Failed to get bss list");
5803 return -1;
5804 }
5805
5806 sigma_dut_print(dut, DUT_MSG_DEBUG,
5807 "bss list for ifname:%s is:%s",
5808 ifname, bss_list);
5809
5810 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305811 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005812 while (bss_line) {
5813 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5814 bss_id) {
5815 int len;
5816
5817 len = snprintf(buf + strlen(buf),
5818 sizeof(buf) - strlen(buf),
5819 ",%s", bss_id);
5820 free(bss_id);
5821 bss_id = NULL;
5822 if (len < 0) {
5823 sigma_dut_print(dut,
5824 DUT_MSG_ERROR,
5825 "Failed to read BSSID");
5826 send_resp(dut, conn, SIGMA_ERROR,
5827 "ErrorCode,Failed to read BSS ID");
5828 return 0;
5829 }
5830
5831 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5832 sigma_dut_print(dut,
5833 DUT_MSG_ERROR,
5834 "Response buf too small for list");
5835 send_resp(dut, conn,
5836 SIGMA_ERROR,
5837 "ErrorCode,Response buf too small for list");
5838 return 0;
5839 }
5840 }
5841
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305842 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005843 }
5844
5845 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5846 buf);
5847 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5848 return 0;
5849 }
5850
5851 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5852 return 0;
5853}
5854
5855
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07005856static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
5857 struct sigma_cmd *cmd)
5858{
5859 char buf[MAX_CMD_LEN];
5860 const char *parameter = get_param(cmd, "Parameter");
5861
5862 if (!parameter)
5863 return -1;
5864
5865 if (strcasecmp(parameter, "RSSI") == 0) {
5866 char rssi[10];
5867
5868 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
5869 rssi, sizeof(rssi)) < 0) {
5870 sigma_dut_print(dut, DUT_MSG_ERROR,
5871 "Could not get RSSI");
5872 return -2;
5873 }
5874
5875 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
5876 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
5877 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5878 return 0;
5879 }
5880
5881 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5882 return 0;
5883}
5884
5885
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005886static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5887 struct sigma_cmd *cmd)
5888{
5889 const char *program = get_param(cmd, "Program");
5890
5891 if (program == NULL)
5892 return -1;
5893
5894 if (strcasecmp(program, "P2PNFC") == 0)
5895 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5896
5897 if (strcasecmp(program, "60ghz") == 0)
5898 return sta_get_parameter_60g(dut, conn, cmd);
5899
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07005900 if (strcasecmp(program, "he") == 0)
5901 return sta_get_parameter_he(dut, conn, cmd);
5902
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005903#ifdef ANDROID_NAN
5904 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005905 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005906#endif /* ANDROID_NAN */
5907
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005908#ifdef MIRACAST
5909 if (strcasecmp(program, "WFD") == 0 ||
5910 strcasecmp(program, "DisplayR2") == 0)
5911 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5912#endif /* MIRACAST */
5913
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005914 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5915 return 0;
5916}
5917
5918
5919static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5920 const char *type)
5921{
5922 char buf[100];
5923
5924 if (dut->program == PROGRAM_VHT) {
5925 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5926 if (system(buf) != 0) {
5927 sigma_dut_print(dut, DUT_MSG_ERROR,
5928 "iwpriv %s chwidth failed", intf);
5929 }
5930
5931 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5932 if (system(buf) != 0) {
5933 sigma_dut_print(dut, DUT_MSG_ERROR,
5934 "iwpriv %s mode 11ACVHT80 failed",
5935 intf);
5936 }
5937
5938 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5939 if (system(buf) != 0) {
5940 sigma_dut_print(dut, DUT_MSG_ERROR,
5941 "iwpriv %s vhtmcs -1 failed", intf);
5942 }
5943 }
5944
5945 if (dut->program == PROGRAM_HT) {
5946 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5947 if (system(buf) != 0) {
5948 sigma_dut_print(dut, DUT_MSG_ERROR,
5949 "iwpriv %s chwidth failed", intf);
5950 }
5951
5952 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5953 if (system(buf) != 0) {
5954 sigma_dut_print(dut, DUT_MSG_ERROR,
5955 "iwpriv %s mode 11naht40 failed",
5956 intf);
5957 }
5958
5959 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5960 if (system(buf) != 0) {
5961 sigma_dut_print(dut, DUT_MSG_ERROR,
5962 "iwpriv set11NRates failed");
5963 }
5964 }
5965
5966 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5967 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5968 if (system(buf) != 0) {
5969 sigma_dut_print(dut, DUT_MSG_ERROR,
5970 "disabling powersave failed");
5971 }
5972
5973 /* Reset CTS width */
5974 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5975 intf);
5976 if (system(buf) != 0) {
5977 sigma_dut_print(dut, DUT_MSG_ERROR,
5978 "wifitool %s beeliner_fw_test 54 0 failed",
5979 intf);
5980 }
5981
5982 /* Enable Dynamic Bandwidth signalling by default */
5983 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5984 if (system(buf) != 0) {
5985 sigma_dut_print(dut, DUT_MSG_ERROR,
5986 "iwpriv %s cwmenable 1 failed", intf);
5987 }
5988
5989 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5990 if (system(buf) != 0) {
5991 sigma_dut_print(dut, DUT_MSG_ERROR,
5992 "iwpriv rts failed");
5993 }
5994 }
5995
5996 if (type && strcasecmp(type, "Testbed") == 0) {
5997 dut->testbed_flag_txsp = 1;
5998 dut->testbed_flag_rxsp = 1;
5999 /* STA has to set spatial stream to 2 per Appendix H */
6000 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
6001 if (system(buf) != 0) {
6002 sigma_dut_print(dut, DUT_MSG_ERROR,
6003 "iwpriv vht_mcsmap failed");
6004 }
6005
6006 /* Disable LDPC per Appendix H */
6007 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
6008 if (system(buf) != 0) {
6009 sigma_dut_print(dut, DUT_MSG_ERROR,
6010 "iwpriv %s ldpc 0 failed", intf);
6011 }
6012
6013 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
6014 if (system(buf) != 0) {
6015 sigma_dut_print(dut, DUT_MSG_ERROR,
6016 "iwpriv amsdu failed");
6017 }
6018
6019 /* TODO: Disable STBC 2x1 transmit and receive */
6020 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
6021 if (system(buf) != 0) {
6022 sigma_dut_print(dut, DUT_MSG_ERROR,
6023 "Disable tx_stbc 0 failed");
6024 }
6025
6026 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
6027 if (system(buf) != 0) {
6028 sigma_dut_print(dut, DUT_MSG_ERROR,
6029 "Disable rx_stbc 0 failed");
6030 }
6031
6032 /* STA has to disable Short GI per Appendix H */
6033 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
6034 if (system(buf) != 0) {
6035 sigma_dut_print(dut, DUT_MSG_ERROR,
6036 "iwpriv %s shortgi 0 failed", intf);
6037 }
6038 }
6039
6040 if (type && strcasecmp(type, "DUT") == 0) {
6041 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
6042 if (system(buf) != 0) {
6043 sigma_dut_print(dut, DUT_MSG_ERROR,
6044 "iwpriv %s nss 3 failed", intf);
6045 }
Arif Hussainac6c5112018-05-25 17:34:00 -07006046 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006047
6048 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
6049 if (system(buf) != 0) {
6050 sigma_dut_print(dut, DUT_MSG_ERROR,
6051 "iwpriv %s shortgi 1 failed", intf);
6052 }
6053 }
6054}
6055
6056
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006057#ifdef NL80211_SUPPORT
6058static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
6059 enum he_mcs_config mcs)
6060{
6061 struct nl_msg *msg;
6062 int ret = 0;
6063 struct nlattr *params;
6064 int ifindex;
6065
6066 ifindex = if_nametoindex(intf);
6067 if (ifindex == 0) {
6068 sigma_dut_print(dut, DUT_MSG_ERROR,
6069 "%s: Index for interface %s failed",
6070 __func__, intf);
6071 return -1;
6072 }
6073
6074 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6075 NL80211_CMD_VENDOR)) ||
6076 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6077 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6078 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6079 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6080 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6081 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
6082 mcs)) {
6083 sigma_dut_print(dut, DUT_MSG_ERROR,
6084 "%s: err in adding vendor_cmd and vendor_data",
6085 __func__);
6086 nlmsg_free(msg);
6087 return -1;
6088 }
6089 nla_nest_end(msg, params);
6090
6091 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6092 if (ret) {
6093 sigma_dut_print(dut, DUT_MSG_ERROR,
6094 "%s: err in send_and_recv_msgs, ret=%d",
6095 __func__, ret);
6096 }
6097 return ret;
6098}
6099#endif /* NL80211_SUPPORT */
6100
6101
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006102static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
6103 const char *intf, int enable)
6104{
6105#ifdef NL80211_SUPPORT
6106 struct nl_msg *msg;
6107 int ret = 0;
6108 struct nlattr *params;
6109 int ifindex;
6110
6111 ifindex = if_nametoindex(intf);
6112 if (ifindex == 0) {
6113 sigma_dut_print(dut, DUT_MSG_ERROR,
6114 "%s: Index for interface %s failed",
6115 __func__, intf);
6116 return -1;
6117 }
6118
6119 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6120 NL80211_CMD_VENDOR)) ||
6121 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6122 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6123 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6124 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6125 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6126 nla_put_u8(msg,
6127 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
6128 enable)) {
6129 sigma_dut_print(dut, DUT_MSG_ERROR,
6130 "%s: err in adding vendor_cmd and vendor_data",
6131 __func__);
6132 nlmsg_free(msg);
6133 return -1;
6134 }
6135 nla_nest_end(msg, params);
6136
6137 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6138 if (ret) {
6139 sigma_dut_print(dut, DUT_MSG_ERROR,
6140 "%s: err in send_and_recv_msgs, ret=%d",
6141 __func__, ret);
6142 }
6143 return ret;
6144#else /* NL80211_SUPPORT */
6145 sigma_dut_print(dut, DUT_MSG_ERROR,
6146 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
6147 return -1;
6148#endif /* NL80211_SUPPORT */
6149}
6150
6151
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006152static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
6153 const char *intf, int enable)
6154{
6155#ifdef NL80211_SUPPORT
6156 struct nl_msg *msg;
6157 int ret = 0;
6158 struct nlattr *params;
6159 int ifindex;
6160
6161 ifindex = if_nametoindex(intf);
6162 if (ifindex == 0) {
6163 sigma_dut_print(dut, DUT_MSG_ERROR,
6164 "%s: Index for interface %s failed",
6165 __func__, intf);
6166 return -1;
6167 }
6168
6169 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6170 NL80211_CMD_VENDOR)) ||
6171 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6172 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6173 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6174 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6175 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6176 nla_put_u8(msg,
6177 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
6178 enable)) {
6179 sigma_dut_print(dut, DUT_MSG_ERROR,
6180 "%s: err in adding vendor_cmd and vendor_data",
6181 __func__);
6182 nlmsg_free(msg);
6183 return -1;
6184 }
6185 nla_nest_end(msg, params);
6186
6187 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6188 if (ret) {
6189 sigma_dut_print(dut, DUT_MSG_ERROR,
6190 "%s: err in send_and_recv_msgs, ret=%d",
6191 __func__, ret);
6192 }
6193 return ret;
6194#else /* NL80211_SUPPORT */
6195 sigma_dut_print(dut, DUT_MSG_ERROR,
6196 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
6197 return -1;
6198#endif /* NL80211_SUPPORT */
6199}
6200
6201
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006202static int sta_set_addba_buf_size(struct sigma_dut *dut,
6203 const char *intf, int bufsize)
6204{
6205#ifdef NL80211_SUPPORT
6206 struct nl_msg *msg;
6207 int ret = 0;
6208 struct nlattr *params;
6209 int ifindex;
6210
6211 ifindex = if_nametoindex(intf);
6212 if (ifindex == 0) {
6213 sigma_dut_print(dut, DUT_MSG_ERROR,
6214 "%s: Index for interface %s failed",
6215 __func__, intf);
6216 return -1;
6217 }
6218
6219 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6220 NL80211_CMD_VENDOR)) ||
6221 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6222 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6223 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6224 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6225 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07006226 nla_put_u16(msg,
6227 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
6228 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006229 sigma_dut_print(dut, DUT_MSG_ERROR,
6230 "%s: err in adding vendor_cmd and vendor_data",
6231 __func__);
6232 nlmsg_free(msg);
6233 return -1;
6234 }
6235 nla_nest_end(msg, params);
6236
6237 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6238 if (ret) {
6239 sigma_dut_print(dut, DUT_MSG_ERROR,
6240 "%s: err in send_and_recv_msgs, ret=%d",
6241 __func__, ret);
6242 }
6243 return ret;
6244#else /* NL80211_SUPPORT */
6245 sigma_dut_print(dut, DUT_MSG_ERROR,
6246 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
6247 return -1;
6248#endif /* NL80211_SUPPORT */
6249}
6250
6251
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006252static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
6253 int enable)
6254{
6255#ifdef NL80211_SUPPORT
6256 struct nl_msg *msg;
6257 int ret = 0;
6258 struct nlattr *params;
6259 int ifindex;
6260
6261 ifindex = if_nametoindex(intf);
6262 if (ifindex == 0) {
6263 sigma_dut_print(dut, DUT_MSG_ERROR,
6264 "%s: Index for interface %s failed",
6265 __func__, intf);
6266 return -1;
6267 }
6268
6269 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6270 NL80211_CMD_VENDOR)) ||
6271 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6272 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6273 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6274 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6275 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6276 nla_put_u8(msg,
6277 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
6278 enable)) {
6279 sigma_dut_print(dut, DUT_MSG_ERROR,
6280 "%s: err in adding vendor_cmd and vendor_data",
6281 __func__);
6282 nlmsg_free(msg);
6283 return -1;
6284 }
6285 nla_nest_end(msg, params);
6286
6287 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6288 if (ret) {
6289 sigma_dut_print(dut, DUT_MSG_ERROR,
6290 "%s: err in send_and_recv_msgs, ret=%d",
6291 __func__, ret);
6292 }
6293 return ret;
6294#else /* NL80211_SUPPORT */
6295 sigma_dut_print(dut, DUT_MSG_ERROR,
6296 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
6297 return -1;
6298#endif /* NL80211_SUPPORT */
6299}
6300
6301
Arif Hussain9765f7d2018-07-03 08:28:26 -07006302static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
6303 int val)
6304{
6305#ifdef NL80211_SUPPORT
6306 struct nl_msg *msg;
6307 int ret = 0;
6308 struct nlattr *params;
6309 int ifindex;
6310
6311 ifindex = if_nametoindex(intf);
6312 if (ifindex == 0) {
6313 sigma_dut_print(dut, DUT_MSG_ERROR,
6314 "%s: Index for interface %s failed, val:%d",
6315 __func__, intf, val);
6316 return -1;
6317 }
6318
6319 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6320 NL80211_CMD_VENDOR)) ||
6321 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6322 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6323 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6324 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6325 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6326 nla_put_u8(msg,
6327 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
6328 val)) {
6329 sigma_dut_print(dut, DUT_MSG_ERROR,
6330 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6331 __func__, val);
6332 nlmsg_free(msg);
6333 return -1;
6334 }
6335 nla_nest_end(msg, params);
6336
6337 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6338 if (ret) {
6339 sigma_dut_print(dut, DUT_MSG_ERROR,
6340 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6341 __func__, ret, val);
6342 }
6343 return ret;
6344#else /* NL80211_SUPPORT */
6345 sigma_dut_print(dut, DUT_MSG_ERROR,
6346 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
6347 return -1;
6348#endif /* NL80211_SUPPORT */
6349}
6350
6351
Arif Hussain68d23f52018-07-11 13:39:08 -07006352#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006353static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
6354 enum qca_wlan_he_mac_padding_dur val)
6355{
Arif Hussain68d23f52018-07-11 13:39:08 -07006356 struct nl_msg *msg;
6357 int ret = 0;
6358 struct nlattr *params;
6359 int ifindex;
6360
6361 ifindex = if_nametoindex(intf);
6362 if (ifindex == 0) {
6363 sigma_dut_print(dut, DUT_MSG_ERROR,
6364 "%s: Index for interface %s failed, val:%d",
6365 __func__, intf, val);
6366 return -1;
6367 }
6368
6369 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6370 NL80211_CMD_VENDOR)) ||
6371 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6372 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6373 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6374 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6375 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6376 nla_put_u8(msg,
6377 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
6378 val)) {
6379 sigma_dut_print(dut, DUT_MSG_ERROR,
6380 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6381 __func__, val);
6382 nlmsg_free(msg);
6383 return -1;
6384 }
6385 nla_nest_end(msg, params);
6386
6387 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6388 if (ret) {
6389 sigma_dut_print(dut, DUT_MSG_ERROR,
6390 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6391 __func__, ret, val);
6392 }
6393 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07006394}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006395#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07006396
6397
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006398static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
6399 int val)
6400{
6401#ifdef NL80211_SUPPORT
6402 struct nl_msg *msg;
6403 int ret = 0;
6404 struct nlattr *params;
6405 int ifindex;
6406
6407 ifindex = if_nametoindex(intf);
6408 if (ifindex == 0) {
6409 sigma_dut_print(dut, DUT_MSG_ERROR,
6410 "%s: Index for interface %s failed, val:%d",
6411 __func__, intf, val);
6412 return -1;
6413 }
6414
6415 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6416 NL80211_CMD_VENDOR)) ||
6417 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6418 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6419 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6420 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6421 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6422 nla_put_u8(msg,
6423 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
6424 val)) {
6425 sigma_dut_print(dut, DUT_MSG_ERROR,
6426 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6427 __func__, val);
6428 nlmsg_free(msg);
6429 return -1;
6430 }
6431 nla_nest_end(msg, params);
6432
6433 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6434 if (ret) {
6435 sigma_dut_print(dut, DUT_MSG_ERROR,
6436 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6437 __func__, ret, val);
6438 }
6439 return ret;
6440#else /* NL80211_SUPPORT */
6441 sigma_dut_print(dut, DUT_MSG_ERROR,
6442 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
6443 return -1;
6444#endif /* NL80211_SUPPORT */
6445}
6446
6447
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006448static int sta_set_he_om_ctrl_nss(struct sigma_dut *dut, const char *intf,
6449 int val)
6450{
6451#ifdef NL80211_SUPPORT
6452 struct nl_msg *msg;
6453 int ret = 0;
6454 struct nlattr *params;
6455 int ifindex;
6456
6457 ifindex = if_nametoindex(intf);
6458 if (ifindex == 0) {
6459 sigma_dut_print(dut, DUT_MSG_ERROR,
6460 "%s: Index for interface %s failed, val:%d",
6461 __func__, intf, val);
6462 return -1;
6463 }
6464
6465 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6466 NL80211_CMD_VENDOR)) ||
6467 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6468 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6469 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6470 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6471 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6472 nla_put_u8(msg,
6473 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_NSS,
6474 val)) {
6475 sigma_dut_print(dut, DUT_MSG_ERROR,
6476 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6477 __func__, val);
6478 nlmsg_free(msg);
6479 return -1;
6480 }
6481 nla_nest_end(msg, params);
6482
6483 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6484 if (ret) {
6485 sigma_dut_print(dut, DUT_MSG_ERROR,
6486 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6487 __func__, ret, val);
6488 }
6489 return ret;
6490#else /* NL80211_SUPPORT */
6491 sigma_dut_print(dut, DUT_MSG_ERROR,
6492 "OM CTRL NSS cannot be set without NL80211_SUPPORT defined");
6493 return -1;
6494#endif /* NL80211_SUPPORT */
6495}
6496
6497
6498static int sta_set_he_om_ctrl_bw(struct sigma_dut *dut, const char *intf,
6499 enum qca_wlan_he_om_ctrl_ch_bw val)
6500{
6501#ifdef NL80211_SUPPORT
6502 struct nl_msg *msg;
6503 int ret = 0;
6504 struct nlattr *params;
6505 int ifindex;
6506
6507 ifindex = if_nametoindex(intf);
6508 if (ifindex == 0) {
6509 sigma_dut_print(dut, DUT_MSG_ERROR,
6510 "%s: Index for interface %s failed, val:%d",
6511 __func__, intf, val);
6512 return -1;
6513 }
6514
6515 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6516 NL80211_CMD_VENDOR)) ||
6517 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6518 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6519 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6520 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6521 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6522 nla_put_u8(msg,
6523 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_BW,
6524 val)) {
6525 sigma_dut_print(dut, DUT_MSG_ERROR,
6526 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6527 __func__, val);
6528 nlmsg_free(msg);
6529 return -1;
6530 }
6531 nla_nest_end(msg, params);
6532
6533 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6534 if (ret) {
6535 sigma_dut_print(dut, DUT_MSG_ERROR,
6536 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6537 __func__, ret, val);
6538 }
6539 return ret;
6540#else /* NL80211_SUPPORT */
6541 sigma_dut_print(dut, DUT_MSG_ERROR,
6542 "OM CTRL BW cannot be set without NL80211_SUPPORT defined");
6543 return -1;
6544#endif /* NL80211_SUPPORT */
6545}
6546
6547
6548#ifdef NL80211_SUPPORT
6549static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
6550{
6551 struct nl_msg *msg;
6552 int ret = 0;
6553 struct nlattr *params;
6554 int ifindex;
6555
6556 ifindex = if_nametoindex(intf);
6557 if (ifindex == 0) {
6558 sigma_dut_print(dut, DUT_MSG_ERROR,
6559 "%s: Index for interface %s failed",
6560 __func__, intf);
6561 return -1;
6562 }
6563
6564 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6565 NL80211_CMD_VENDOR)) ||
6566 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6567 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6568 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6569 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6570 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6571 nla_put_flag(msg,
6572 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
6573 sigma_dut_print(dut, DUT_MSG_ERROR,
6574 "%s: err in adding vendor_cmd and vendor_data",
6575 __func__);
6576 nlmsg_free(msg);
6577 return -1;
6578 }
6579 nla_nest_end(msg, params);
6580
6581 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6582 if (ret) {
6583 sigma_dut_print(dut, DUT_MSG_ERROR,
6584 "%s: err in send_and_recv_msgs, ret=%d",
6585 __func__, ret);
6586 }
6587 return ret;
6588}
6589#endif /* NL80211_SUPPORT */
6590
6591
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006592static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
6593 int val)
6594{
6595#ifdef NL80211_SUPPORT
6596 struct nl_msg *msg;
6597 int ret = 0;
6598 struct nlattr *params;
6599 int ifindex;
6600
6601 ifindex = if_nametoindex(intf);
6602 if (ifindex == 0) {
6603 sigma_dut_print(dut, DUT_MSG_ERROR,
6604 "%s: Index for interface %s failed, val:%d",
6605 __func__, intf, val);
6606 return -1;
6607 }
6608
6609 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6610 NL80211_CMD_VENDOR)) ||
6611 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6612 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6613 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6614 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6615 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6616 nla_put_u8(msg,
6617 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
6618 val)) {
6619 sigma_dut_print(dut, DUT_MSG_ERROR,
6620 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6621 __func__, val);
6622 nlmsg_free(msg);
6623 return -1;
6624 }
6625 nla_nest_end(msg, params);
6626
6627 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6628 if (ret) {
6629 sigma_dut_print(dut, DUT_MSG_ERROR,
6630 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6631 __func__, ret, val);
6632 }
6633 return ret;
6634#else /* NL80211_SUPPORT */
6635 sigma_dut_print(dut, DUT_MSG_ERROR,
6636 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
6637 return -1;
6638#endif /* NL80211_SUPPORT */
6639}
6640
6641
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006642static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
6643 int val)
6644{
6645#ifdef NL80211_SUPPORT
6646 struct nl_msg *msg;
6647 int ret = 0;
6648 struct nlattr *params;
6649 int ifindex;
6650
6651 ifindex = if_nametoindex(intf);
6652 if (ifindex == 0) {
6653 sigma_dut_print(dut, DUT_MSG_ERROR,
6654 "%s: Index for interface %s failed, val:%d",
6655 __func__, intf, val);
6656 return -1;
6657 }
6658
6659 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6660 NL80211_CMD_VENDOR)) ||
6661 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6662 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6663 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6664 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6665 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6666 nla_put_u8(msg,
6667 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
6668 val)) {
6669 sigma_dut_print(dut, DUT_MSG_ERROR,
6670 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6671 __func__, val);
6672 nlmsg_free(msg);
6673 return -1;
6674 }
6675 nla_nest_end(msg, params);
6676
6677 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6678 if (ret) {
6679 sigma_dut_print(dut, DUT_MSG_ERROR,
6680 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6681 __func__, ret, val);
6682 }
6683 return ret;
6684#else /* NL80211_SUPPORT */
6685 sigma_dut_print(dut, DUT_MSG_ERROR,
6686 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
6687 return -1;
6688#endif /* NL80211_SUPPORT */
6689}
6690
6691
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006692static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
6693 const char *type)
6694{
6695 char buf[60];
6696
6697 if (dut->program == PROGRAM_HE) {
6698 /* resetting phymode to auto in case of HE program */
6699 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
6700 if (system(buf) != 0) {
6701 sigma_dut_print(dut, DUT_MSG_ERROR,
6702 "iwpriv %s setphymode failed", intf);
6703 }
6704
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07006705 /* reset the rate to Auto rate */
6706 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
6707 intf);
6708 if (system(buf) != 0) {
6709 sigma_dut_print(dut, DUT_MSG_ERROR,
6710 "iwpriv %s set_11ax_rate 0xff failed",
6711 intf);
6712 }
6713
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07006714 /* reset the LDPC setting */
6715 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
6716 if (system(buf) != 0) {
6717 sigma_dut_print(dut, DUT_MSG_ERROR,
6718 "iwpriv %s ldpc 1 failed", intf);
6719 }
6720
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08006721 /* reset the power save setting */
6722 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
6723 if (system(buf) != 0) {
6724 sigma_dut_print(dut, DUT_MSG_ERROR,
6725 "iwpriv %s setPower 2 failed", intf);
6726 }
6727
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006728 /* remove all network profiles */
6729 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006730
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006731 /* Configure ADDBA Req/Rsp buffer size to be 64 */
6732 sta_set_addba_buf_size(dut, intf, 64);
6733
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08006734#ifdef NL80211_SUPPORT
6735 /* Disable noackpolicy for all AC */
6736 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
6737 sigma_dut_print(dut, DUT_MSG_ERROR,
6738 "Disable of noackpolicy for all AC failed");
6739 }
6740#endif /* NL80211_SUPPORT */
6741
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08006742 /* Enable WMM by default */
6743 if (wcn_sta_set_wmm(dut, intf, "on")) {
6744 sigma_dut_print(dut, DUT_MSG_ERROR,
6745 "Enable of WMM in sta_reset_default_wcn failed");
6746 }
6747
6748 /* Disable ADDBA_REJECT by default */
6749 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
6750 sigma_dut_print(dut, DUT_MSG_ERROR,
6751 "Disable of addba_reject in sta_reset_default_wcn failed");
6752 }
6753
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006754 /* Enable sending of ADDBA by default */
6755 if (nlvendor_config_send_addba(dut, intf, 1)) {
6756 sigma_dut_print(dut, DUT_MSG_ERROR,
6757 "Enable sending of ADDBA in sta_reset_default_wcn failed");
6758 }
6759
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08006760 /* Enable AMPDU by default */
6761 iwpriv_sta_set_ampdu(dut, intf, 1);
6762
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006763#ifdef NL80211_SUPPORT
6764 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
6765 sigma_dut_print(dut, DUT_MSG_ERROR,
6766 "Set LTF config to default in sta_reset_default_wcn failed");
6767 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07006768
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08006769 /* set the beamformee NSTS(maximum number of
6770 * space-time streams) to default DUT config
6771 */
6772 if (sta_set_beamformee_sts(dut, intf, 7)) {
Arif Hussain9765f7d2018-07-03 08:28:26 -07006773 sigma_dut_print(dut, DUT_MSG_ERROR,
6774 "Failed to set BeamformeeSTS");
6775 }
Arif Hussain68d23f52018-07-11 13:39:08 -07006776
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006777 if (sta_set_mac_padding_duration(
6778 dut, intf,
6779 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07006780 sigma_dut_print(dut, DUT_MSG_ERROR,
6781 "Failed to set MAC padding duration");
6782 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006783
6784 if (sta_set_mu_edca_override(dut, intf, 0)) {
6785 sigma_dut_print(dut, DUT_MSG_ERROR,
6786 "ErrorCode,Failed to set MU EDCA override disable");
6787 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006788
6789 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
6790 sigma_dut_print(dut, DUT_MSG_ERROR,
6791 "Failed to set OM ctrl supp");
6792 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006793
6794 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
6795 sigma_dut_print(dut, DUT_MSG_ERROR,
6796 "Failed to set Tx SU PPDU enable");
6797 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006798
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006799 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
6800 sigma_dut_print(dut, DUT_MSG_ERROR,
6801 "failed to send TB PPDU Tx cfg");
6802 }
6803
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006804 if (sta_set_he_om_ctrl_reset(dut, intf)) {
6805 sigma_dut_print(dut, DUT_MSG_ERROR,
6806 "Failed to set OM ctrl reset");
6807 }
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08006808
6809 /* +HTC-HE support default on */
6810 if (sta_set_he_htc_supp(dut, intf, 1)) {
6811 sigma_dut_print(dut, DUT_MSG_ERROR,
6812 "Setting of +HTC-HE support failed");
6813 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006814#endif /* NL80211_SUPPORT */
6815
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006816 if (sta_set_tx_beamformee(dut, intf, 1)) {
6817 sigma_dut_print(dut, DUT_MSG_ERROR,
6818 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
6819 }
6820
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006821 /* Set nss to 1 and MCS 0-7 in case of testbed */
6822 if (type && strcasecmp(type, "Testbed") == 0) {
6823#ifdef NL80211_SUPPORT
6824 int ret;
6825#endif /* NL80211_SUPPORT */
6826
6827 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
6828 if (system(buf) != 0) {
6829 sigma_dut_print(dut, DUT_MSG_ERROR,
6830 "iwpriv %s nss failed", intf);
6831 }
6832
6833#ifdef NL80211_SUPPORT
6834 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
6835 if (ret) {
6836 sigma_dut_print(dut, DUT_MSG_ERROR,
6837 "Setting of MCS failed, ret:%d",
6838 ret);
6839 }
6840#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08006841
6842 /* Disable STBC as default */
6843 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006844
6845 /* Disable AMSDU as default */
6846 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08006847
6848#ifdef NL80211_SUPPORT
6849 /* HE fragmentation default off */
6850 if (sta_set_he_fragmentation(dut, intf,
6851 HE_FRAG_DISABLE)) {
6852 sigma_dut_print(dut, DUT_MSG_ERROR,
6853 "Setting of HE fragmentation failed");
6854 }
Kiran Kumar Lokerebad51122018-12-12 19:03:36 -08006855
6856 /* set the beamformee NSTS(maximum number of
6857 * space-time streams) to default testbed config
6858 */
6859 if (sta_set_beamformee_sts(dut, intf, 3)) {
6860 sigma_dut_print(dut, DUT_MSG_ERROR,
6861 "Failed to set BeamformeeSTS");
6862 }
6863
Kiran Kumar Lokeree5ed4422018-12-18 18:25:02 -08006864 /* +HTC-HE support default off */
6865 if (sta_set_he_htc_supp(dut, intf, 0)) {
6866 sigma_dut_print(dut, DUT_MSG_ERROR,
6867 "Setting of +HTC-HE support failed");
6868 }
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08006869#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006870
6871 /* Enable WEP/TKIP with HE capability in testbed */
6872 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
6873 sigma_dut_print(dut, DUT_MSG_ERROR,
6874 "Enabling HE config with WEP/TKIP failed");
6875 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006876 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006877
6878 /* Defaults in case of DUT */
6879 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07006880 /* Enable STBC by default */
6881 wcn_sta_set_stbc(dut, intf, "1");
6882
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006883 /* set nss to 2 */
6884 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
6885 if (system(buf) != 0) {
6886 sigma_dut_print(dut, DUT_MSG_ERROR,
6887 "iwpriv %s nss 2 failed", intf);
6888 }
Arif Hussainac6c5112018-05-25 17:34:00 -07006889 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006890
6891#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07006892 /* Set HE_MCS to 0-11 */
6893 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006894 sigma_dut_print(dut, DUT_MSG_ERROR,
6895 "Setting of MCS failed");
6896 }
6897#endif /* NL80211_SUPPORT */
6898
6899 /* Disable WEP/TKIP with HE capability in DUT */
6900 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
6901 sigma_dut_print(dut, DUT_MSG_ERROR,
6902 "Enabling HE config with WEP/TKIP failed");
6903 }
6904 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006905 }
6906}
6907
6908
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006909static int cmd_sta_reset_default(struct sigma_dut *dut,
6910 struct sigma_conn *conn,
6911 struct sigma_cmd *cmd)
6912{
6913 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
6914 struct sigma_cmd *cmd);
6915 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02006916 const char *band = get_param(cmd, "band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006917 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006918 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306919 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006920
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006921 if (!program)
6922 program = get_param(cmd, "prog");
6923 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006924 dut->device_type = STA_unknown;
6925 type = get_param(cmd, "type");
6926 if (type && strcasecmp(type, "Testbed") == 0)
6927 dut->device_type = STA_testbed;
6928 if (type && strcasecmp(type, "DUT") == 0)
6929 dut->device_type = STA_dut;
6930
6931 if (dut->program == PROGRAM_TDLS) {
6932 /* Clear TDLS testing mode */
6933 wpa_command(intf, "SET tdls_disabled 0");
6934 wpa_command(intf, "SET tdls_testing 0");
6935 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05306936 if (get_driver_type() == DRIVER_WCN) {
6937 /* Enable the WCN driver in TDLS Explicit trigger mode
6938 */
6939 wpa_command(intf, "SET tdls_external_control 0");
6940 wpa_command(intf, "SET tdls_trigger_control 0");
6941 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006942 }
6943
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006944#ifdef MIRACAST
6945 if (dut->program == PROGRAM_WFD ||
6946 dut->program == PROGRAM_DISPLAYR2)
6947 miracast_sta_reset_default(dut, conn, cmd);
6948#endif /* MIRACAST */
6949
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006950 switch (get_driver_type()) {
6951 case DRIVER_ATHEROS:
6952 sta_reset_default_ath(dut, intf, type);
6953 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006954 case DRIVER_WCN:
6955 sta_reset_default_wcn(dut, intf, type);
6956 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006957 default:
6958 break;
6959 }
6960
6961#ifdef ANDROID_NAN
6962 if (dut->program == PROGRAM_NAN)
6963 nan_cmd_sta_reset_default(dut, conn, cmd);
6964#endif /* ANDROID_NAN */
6965
Jouni Malinenba630452018-06-22 11:49:59 +03006966 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006967 unlink("SP/wi-fi.org/pps.xml");
6968 if (system("rm -r SP/*") != 0) {
6969 }
6970 unlink("next-client-cert.pem");
6971 unlink("next-client-key.pem");
6972 }
6973
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02006974 /* For WPS program of the 60 GHz band the band type needs to be saved */
6975 if (dut->program == PROGRAM_WPS) {
6976 if (band && strcasecmp(band, "60GHz") == 0) {
6977 dut->band = WPS_BAND_60G;
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02006978 /* For 60 GHz enable WPS for WPS TCs */
6979 dut->wps_disable = 0;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02006980 } else {
6981 dut->band = WPS_BAND_NON_60G;
6982 }
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02006983 } else if (dut->program == PROGRAM_60GHZ) {
6984 /* For 60 GHz MAC/PHY TCs WPS must be disabled */
6985 dut->wps_disable = 1;
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02006986 }
6987
Alexei Avshalom Lazar157ba062018-12-23 16:15:26 +02006988 if (is_60g_sigma_dut(dut)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006989 const char *dev_role = get_param(cmd, "DevRole");
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02006990 char buf[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006991
Alexei Avshalom Lazareee9ab02018-12-24 16:27:48 +02006992 sigma_dut_print(dut, DUT_MSG_INFO,
6993 "WPS 60 GHz program, wps_disable = %d",
6994 dut->wps_disable);
6995
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006996 if (!dev_role) {
6997 send_resp(dut, conn, SIGMA_ERROR,
6998 "errorCode,Missing DevRole argument");
6999 return 0;
7000 }
7001
7002 if (strcasecmp(dev_role, "STA") == 0)
7003 dut->dev_role = DEVROLE_STA;
7004 else if (strcasecmp(dev_role, "PCP") == 0)
7005 dut->dev_role = DEVROLE_PCP;
7006 else {
7007 send_resp(dut, conn, SIGMA_ERROR,
7008 "errorCode,Unknown DevRole");
7009 return 0;
7010 }
7011
7012 if (dut->device_type == STA_unknown) {
7013 sigma_dut_print(dut, DUT_MSG_ERROR,
7014 "Device type is not STA testbed or DUT");
7015 send_resp(dut, conn, SIGMA_ERROR,
7016 "errorCode,Unknown device type");
7017 return 0;
7018 }
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007019
7020 sigma_dut_print(dut, DUT_MSG_DEBUG,
7021 "Setting msdu_size to MAX: 7912");
7022 snprintf(buf, sizeof(buf), "ifconfig %s mtu 7912",
7023 get_station_ifname());
7024
7025 if (system(buf) != 0) {
7026 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
7027 buf);
7028 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
7029 }
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007030
7031 if (sta_set_force_mcs(dut, 0, 1)) {
7032 sigma_dut_print(dut, DUT_MSG_ERROR,
7033 "Failed to reset force MCS");
7034 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
7035 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007036 }
7037
7038 wpa_command(intf, "WPS_ER_STOP");
7039 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05307040 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007041 wpa_command(intf, "SET radio_disabled 0");
7042
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007043 if (dut->wsc_fragment) {
7044 dut->wsc_fragment = 0;
7045 wpa_command(intf, "SET device_name Test client");
7046 wpa_command(intf, "SET manufacturer ");
7047 wpa_command(intf, "SET model_name ");
7048 wpa_command(intf, "SET model_number ");
7049 wpa_command(intf, "SET serial_number ");
7050 }
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +02007051 if (is_60g_sigma_dut(dut) && dut->force_rsn_ie) {
7052 dut->force_rsn_ie = FORCE_RSN_IE_NONE;
7053 sta_60g_force_rsn_ie(dut, FORCE_RSN_IE_NONE);
7054 }
Alexei Avshalom Lazar33f700c2018-12-18 16:00:39 +02007055
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007056 if (dut->tmp_mac_addr && dut->set_macaddr) {
7057 dut->tmp_mac_addr = 0;
7058 if (system(dut->set_macaddr) != 0) {
7059 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
7060 "temporary MAC address");
7061 }
7062 }
7063
7064 set_ps(intf, dut, 0);
7065
Jouni Malinenba630452018-06-22 11:49:59 +03007066 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
7067 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007068 wpa_command(intf, "SET interworking 1");
7069 wpa_command(intf, "SET hs20 1");
7070 }
7071
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007072 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03007073 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08007074 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007075 wpa_command(intf, "SET pmf 1");
7076 } else {
7077 wpa_command(intf, "SET pmf 0");
7078 }
7079
7080 hs2_clear_credentials(intf);
7081 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
7082 wpa_command(intf, "SET access_network_type 15");
7083
7084 static_ip_file(0, NULL, NULL, NULL);
7085 kill_dhcp_client(dut, intf);
7086 clear_ip_addr(dut, intf);
7087
7088 dut->er_oper_performed = 0;
7089 dut->er_oper_bssid[0] = '\0';
7090
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07007091 if (dut->program == PROGRAM_LOC) {
7092 /* Disable Interworking by default */
7093 wpa_command(get_station_ifname(), "SET interworking 0");
7094 }
7095
Ashwini Patil00402582017-04-13 12:29:39 +05307096 if (dut->program == PROGRAM_MBO) {
7097 free(dut->non_pref_ch_list);
7098 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05307099 free(dut->btm_query_cand_list);
7100 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05307101 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05307102 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05307103 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05307104 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05307105 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05307106 }
7107
Jouni Malinen3c367e82017-06-23 17:01:47 +03007108 free(dut->rsne_override);
7109 dut->rsne_override = NULL;
7110
Jouni Malinen68143132017-09-02 02:34:08 +03007111 free(dut->sae_commit_override);
7112 dut->sae_commit_override = NULL;
7113
Jouni Malinend86e5822017-08-29 03:55:32 +03007114 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02007115 free(dut->dpp_peer_uri);
7116 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02007117 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02007118 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03007119
Jouni Malinenfac9cad2017-10-10 18:35:55 +03007120 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
7121
vamsi krishnaa2799492017-12-05 14:28:01 +05307122 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307123 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05307124 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05307125 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
7126 dut->fils_hlp = 0;
7127#ifdef ANDROID
7128 hlp_thread_cleanup(dut);
7129#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05307130 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05307131
Sunil Dutt076081f2018-02-05 19:45:50 +05307132#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05307133 if (get_driver_type() == DRIVER_WCN &&
7134 dut->config_rsnie == 1) {
7135 dut->config_rsnie = 0;
7136 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05307137 }
7138#endif /* NL80211_SUPPORT */
7139
Sunil Duttfebf8a82018-02-09 18:50:13 +05307140 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
7141 dut->dev_role = DEVROLE_STA_CFON;
7142 return sta_cfon_reset_default(dut, conn, cmd);
7143 }
7144
Jouni Malinen439352d2018-09-13 03:42:23 +03007145 wpa_command(intf, "SET setband AUTO");
7146
Sunil Duttfebf8a82018-02-09 18:50:13 +05307147 if (dut->program != PROGRAM_VHT)
7148 return cmd_sta_p2p_reset(dut, conn, cmd);
7149
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08007150 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007151}
7152
7153
7154static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
7155 struct sigma_cmd *cmd)
7156{
7157 const char *program = get_param(cmd, "Program");
7158
7159 if (program == NULL)
7160 return -1;
7161#ifdef ANDROID_NAN
7162 if (strcasecmp(program, "NAN") == 0)
7163 return nan_cmd_sta_get_events(dut, conn, cmd);
7164#endif /* ANDROID_NAN */
7165 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7166 return 0;
7167}
7168
7169
Jouni Malinen82905202018-04-29 17:20:10 +03007170static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
7171 struct sigma_cmd *cmd)
7172{
7173 const char *url = get_param(cmd, "url");
7174 const char *method = get_param(cmd, "method");
7175 pid_t pid;
7176 int status;
7177
7178 if (!url || !method)
7179 return -1;
7180
7181 /* TODO: Add support for method,post */
7182 if (strcasecmp(method, "get") != 0) {
7183 send_resp(dut, conn, SIGMA_ERROR,
7184 "ErrorCode,Unsupported method");
7185 return 0;
7186 }
7187
7188 pid = fork();
7189 if (pid < 0) {
7190 perror("fork");
7191 return -1;
7192 }
7193
7194 if (pid == 0) {
7195 char * argv[5] = { "wget", "-O", "/dev/null",
7196 (char *) url, NULL };
7197
7198 execv("/usr/bin/wget", argv);
7199 perror("execv");
7200 exit(0);
7201 return -1;
7202 }
7203
7204 if (waitpid(pid, &status, 0) < 0) {
7205 perror("waitpid");
7206 return -1;
7207 }
7208
7209 if (WIFEXITED(status)) {
7210 const char *errmsg;
7211
7212 if (WEXITSTATUS(status) == 0)
7213 return 1;
7214 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
7215 WEXITSTATUS(status));
7216 switch (WEXITSTATUS(status)) {
7217 case 4:
7218 errmsg = "errmsg,Network failure";
7219 break;
7220 case 8:
7221 errmsg = "errmsg,Server issued an error response";
7222 break;
7223 default:
7224 errmsg = "errmsg,Unknown failure from wget";
7225 break;
7226 }
7227 send_resp(dut, conn, SIGMA_ERROR, errmsg);
7228 return 0;
7229 }
7230
7231 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
7232 return 0;
7233}
7234
7235
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007236static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
7237 struct sigma_cmd *cmd)
7238{
7239 const char *program = get_param(cmd, "Prog");
7240
Jouni Malinen82905202018-04-29 17:20:10 +03007241 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007242 return -1;
7243#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03007244 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007245 return nan_cmd_sta_exec_action(dut, conn, cmd);
7246#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03007247
7248 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07007249 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03007250
7251 if (get_param(cmd, "url"))
7252 return sta_exec_action_url(dut, conn, cmd);
7253
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007254 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
7255 return 0;
7256}
7257
7258
7259static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
7260 struct sigma_cmd *cmd)
7261{
7262 const char *intf = get_param(cmd, "Interface");
7263 const char *val, *mcs32, *rate;
7264
7265 val = get_param(cmd, "GREENFIELD");
7266 if (val) {
7267 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
7268 /* Enable GD */
7269 send_resp(dut, conn, SIGMA_ERROR,
7270 "ErrorCode,GF not supported");
7271 return 0;
7272 }
7273 }
7274
7275 val = get_param(cmd, "SGI20");
7276 if (val) {
7277 switch (get_driver_type()) {
7278 case DRIVER_ATHEROS:
7279 ath_sta_set_sgi(dut, intf, val);
7280 break;
7281 default:
7282 send_resp(dut, conn, SIGMA_ERROR,
7283 "ErrorCode,SGI20 not supported");
7284 return 0;
7285 }
7286 }
7287
7288 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
7289 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
7290 if (mcs32 && rate) {
7291 /* TODO */
7292 send_resp(dut, conn, SIGMA_ERROR,
7293 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
7294 return 0;
7295 } else if (mcs32 && !rate) {
7296 /* TODO */
7297 send_resp(dut, conn, SIGMA_ERROR,
7298 "ErrorCode,MCS32 not supported");
7299 return 0;
7300 } else if (!mcs32 && rate) {
7301 switch (get_driver_type()) {
7302 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08007303 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007304 ath_sta_set_11nrates(dut, intf, rate);
7305 break;
7306 default:
7307 send_resp(dut, conn, SIGMA_ERROR,
7308 "ErrorCode,MCS32_FIXEDRATE not supported");
7309 return 0;
7310 }
7311 }
7312
7313 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7314}
7315
7316
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007317static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
7318 int mcs_config)
7319{
7320#ifdef NL80211_SUPPORT
7321 int ret;
7322
7323 switch (mcs_config) {
7324 case HE_80_MCS0_7:
7325 case HE_80_MCS0_9:
7326 case HE_80_MCS0_11:
7327 ret = sta_set_he_mcs(dut, intf, mcs_config);
7328 if (ret) {
7329 sigma_dut_print(dut, DUT_MSG_ERROR,
7330 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
7331 mcs_config, ret);
7332 }
7333 break;
7334 default:
7335 sigma_dut_print(dut, DUT_MSG_ERROR,
7336 "cmd_set_max_he_mcs: Invalid mcs %d",
7337 mcs_config);
7338 break;
7339 }
7340#else /* NL80211_SUPPORT */
7341 sigma_dut_print(dut, DUT_MSG_ERROR,
7342 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
7343#endif /* NL80211_SUPPORT */
7344}
7345
7346
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007347static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
7348 struct sigma_conn *conn,
7349 struct sigma_cmd *cmd)
7350{
7351 const char *intf = get_param(cmd, "Interface");
7352 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07007353 const char *program;
Arif Hussaind13d6952018-07-02 16:23:47 -07007354 char buf[60];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007355 int tkip = -1;
7356 int wep = -1;
7357
Arif Hussaina37e9552018-06-20 17:05:59 -07007358 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007359 val = get_param(cmd, "SGI80");
7360 if (val) {
7361 int sgi80;
7362
7363 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7364 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
7365 if (system(buf) != 0) {
7366 sigma_dut_print(dut, DUT_MSG_ERROR,
7367 "iwpriv shortgi failed");
7368 }
7369 }
7370
7371 val = get_param(cmd, "TxBF");
7372 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07007373 switch (get_driver_type()) {
7374 case DRIVER_WCN:
7375 if (sta_set_tx_beamformee(dut, intf, 1)) {
7376 send_resp(dut, conn, SIGMA_ERROR,
7377 "ErrorCode,Failed to set TX beamformee enable");
7378 return 0;
7379 }
7380 break;
7381 case DRIVER_ATHEROS:
7382 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1",
7383 intf);
7384 if (system(buf) != 0) {
7385 send_resp(dut, conn, SIGMA_ERROR,
7386 "ErrorCode,Setting vhtsubfee failed");
7387 return 0;
7388 }
7389
7390 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1",
7391 intf);
7392 if (system(buf) != 0) {
7393 send_resp(dut, conn, SIGMA_ERROR,
7394 "ErrorCode,Setting vhtsubfer failed");
7395 return 0;
7396 }
7397 break;
7398 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007399 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07007400 "Unsupported driver type");
7401 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007402 }
7403 }
7404
7405 val = get_param(cmd, "MU_TxBF");
7406 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
7407 switch (get_driver_type()) {
7408 case DRIVER_ATHEROS:
7409 ath_sta_set_txsp_stream(dut, intf, "1SS");
7410 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Sunil Duttae9e5d12018-06-29 11:50:47 +05307411 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1",
7412 intf);
7413 if (system(buf) != 0) {
7414 sigma_dut_print(dut, DUT_MSG_ERROR,
7415 "iwpriv vhtmubfee failed");
7416 }
7417 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1",
7418 intf);
7419 if (system(buf) != 0) {
7420 sigma_dut_print(dut, DUT_MSG_ERROR,
7421 "iwpriv vhtmubfer failed");
7422 }
7423 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007424 case DRIVER_WCN:
7425 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
7426 send_resp(dut, conn, SIGMA_ERROR,
7427 "ErrorCode,Failed to set RX/TXSP_STREAM");
7428 return 0;
7429 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05307430 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007431 default:
7432 sigma_dut_print(dut, DUT_MSG_ERROR,
7433 "Setting SP_STREAM not supported");
7434 break;
7435 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007436 }
7437
7438 val = get_param(cmd, "LDPC");
7439 if (val) {
7440 int ldpc;
7441
7442 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7443 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
7444 if (system(buf) != 0) {
7445 sigma_dut_print(dut, DUT_MSG_ERROR,
7446 "iwpriv ldpc failed");
7447 }
7448 }
7449
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08007450 val = get_param(cmd, "BCC");
7451 if (val) {
7452 int bcc;
7453
7454 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7455 /* use LDPC iwpriv itself to set bcc coding, bcc coding
7456 * is mutually exclusive to bcc */
7457 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
7458 if (system(buf) != 0) {
7459 sigma_dut_print(dut, DUT_MSG_ERROR,
7460 "Enabling/Disabling of BCC failed");
7461 }
7462 }
7463
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007464 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
7465 if (val && dut->sta_nss == 1)
7466 cmd_set_max_he_mcs(dut, intf, atoi(val));
7467
7468 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
7469 if (val && dut->sta_nss == 2)
7470 cmd_set_max_he_mcs(dut, intf, atoi(val));
7471
Arif Hussainac6c5112018-05-25 17:34:00 -07007472 val = get_param(cmd, "MCS_FixedRate");
7473 if (val) {
7474#ifdef NL80211_SUPPORT
7475 int mcs, ratecode = 0;
7476 enum he_mcs_config mcs_config;
7477 int ret;
7478
7479 ratecode = (0x07 & dut->sta_nss) << 5;
7480 mcs = atoi(val);
7481 /* Add the MCS to the ratecode */
7482 if (mcs >= 0 && mcs <= 11) {
7483 ratecode += mcs;
7484 if (dut->device_type == STA_testbed &&
7485 mcs > 7 && mcs <= 11) {
7486 if (mcs <= 9)
7487 mcs_config = HE_80_MCS0_9;
7488 else
7489 mcs_config = HE_80_MCS0_11;
7490 ret = sta_set_he_mcs(dut, intf, mcs_config);
7491 if (ret) {
7492 sigma_dut_print(dut, DUT_MSG_ERROR,
7493 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
7494 mcs, mcs_config, ret);
7495 }
7496 }
7497 snprintf(buf, sizeof(buf),
7498 "iwpriv %s set_11ax_rate 0x%03x",
7499 intf, ratecode);
7500 if (system(buf) != 0) {
7501 sigma_dut_print(dut, DUT_MSG_ERROR,
7502 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
7503 ratecode);
7504 }
7505 } else {
7506 sigma_dut_print(dut, DUT_MSG_ERROR,
7507 "MCS_FixedRate: HE MCS %d not supported",
7508 mcs);
7509 }
7510#else /* NL80211_SUPPORT */
7511 sigma_dut_print(dut, DUT_MSG_ERROR,
7512 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
7513#endif /* NL80211_SUPPORT */
7514 }
7515
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007516 val = get_param(cmd, "opt_md_notif_ie");
7517 if (val) {
7518 char *result = NULL;
7519 char delim[] = ";";
7520 char token[30];
7521 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307522 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007523
Peng Xub8fc5cc2017-05-10 17:27:28 -07007524 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307525 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007526
7527 /* Extract the NSS information */
7528 if (result) {
7529 value = atoi(result);
7530 switch (value) {
7531 case 1:
7532 config_val = 1;
7533 break;
7534 case 2:
7535 config_val = 3;
7536 break;
7537 case 3:
7538 config_val = 7;
7539 break;
7540 case 4:
7541 config_val = 15;
7542 break;
7543 default:
7544 config_val = 3;
7545 break;
7546 }
7547
7548 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
7549 intf, config_val);
7550 if (system(buf) != 0) {
7551 sigma_dut_print(dut, DUT_MSG_ERROR,
7552 "iwpriv rxchainmask failed");
7553 }
7554
7555 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
7556 intf, config_val);
7557 if (system(buf) != 0) {
7558 sigma_dut_print(dut, DUT_MSG_ERROR,
7559 "iwpriv txchainmask failed");
7560 }
7561 }
7562
7563 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307564 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007565 if (result) {
7566 value = atoi(result);
7567 switch (value) {
7568 case 20:
7569 config_val = 0;
7570 break;
7571 case 40:
7572 config_val = 1;
7573 break;
7574 case 80:
7575 config_val = 2;
7576 break;
7577 case 160:
7578 config_val = 3;
7579 break;
7580 default:
7581 config_val = 2;
7582 break;
7583 }
7584
7585 dut->chwidth = config_val;
7586
7587 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7588 intf, config_val);
7589 if (system(buf) != 0) {
7590 sigma_dut_print(dut, DUT_MSG_ERROR,
7591 "iwpriv chwidth failed");
7592 }
7593 }
7594
7595 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
7596 if (system(buf) != 0) {
7597 sigma_dut_print(dut, DUT_MSG_ERROR,
7598 "iwpriv opmode_notify failed");
7599 }
7600 }
7601
7602 val = get_param(cmd, "nss_mcs_cap");
7603 if (val) {
7604 int nss, mcs;
7605 char token[20];
7606 char *result = NULL;
7607 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307608 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007609
Peng Xub8fc5cc2017-05-10 17:27:28 -07007610 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307611 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307612 if (!result) {
7613 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007614 "NSS not specified");
7615 send_resp(dut, conn, SIGMA_ERROR,
7616 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307617 return 0;
7618 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007619 nss = atoi(result);
7620
7621 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
7622 if (system(buf) != 0) {
7623 sigma_dut_print(dut, DUT_MSG_ERROR,
7624 "iwpriv nss failed");
7625 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007626 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007627
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307628 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007629 if (result == NULL) {
7630 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007631 "MCS not specified");
7632 send_resp(dut, conn, SIGMA_ERROR,
7633 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007634 return 0;
7635 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307636 result = strtok_r(result, "-", &saveptr);
7637 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307638 if (!result) {
7639 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007640 "MCS not specified");
7641 send_resp(dut, conn, SIGMA_ERROR,
7642 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307643 return 0;
7644 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007645 mcs = atoi(result);
7646
Arif Hussaina37e9552018-06-20 17:05:59 -07007647 if (program && strcasecmp(program, "HE") == 0) {
7648#ifdef NL80211_SUPPORT
7649 enum he_mcs_config mcs_config;
7650 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007651
Arif Hussaina37e9552018-06-20 17:05:59 -07007652 if (mcs >= 0 && mcs <= 7) {
7653 mcs_config = HE_80_MCS0_7;
7654 } else if (mcs > 7 && mcs <= 9) {
7655 mcs_config = HE_80_MCS0_9;
7656 } else if (mcs > 9 && mcs <= 11) {
7657 mcs_config = HE_80_MCS0_11;
7658 } else {
7659 sigma_dut_print(dut, DUT_MSG_ERROR,
7660 "nss_mcs_cap: HE: Invalid mcs: %d",
7661 mcs);
7662 send_resp(dut, conn, SIGMA_ERROR,
7663 "errorCode,Invalid MCS");
7664 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007665 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007666
7667 ret = sta_set_he_mcs(dut, intf, mcs_config);
7668 if (ret) {
7669 sigma_dut_print(dut, DUT_MSG_ERROR,
7670 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
7671 mcs_config, ret);
7672 send_resp(dut, conn, SIGMA_ERROR,
7673 "errorCode,Failed to set MCS");
7674 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007675 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007676#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007677 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007678 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
7679#endif /* NL80211_SUPPORT */
7680 } else {
7681 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
7682 intf, mcs);
7683 if (system(buf) != 0) {
7684 sigma_dut_print(dut, DUT_MSG_ERROR,
7685 "iwpriv mcs failed");
7686 }
7687
7688 switch (nss) {
7689 case 1:
7690 switch (mcs) {
7691 case 7:
7692 vht_mcsmap = 0xfffc;
7693 break;
7694 case 8:
7695 vht_mcsmap = 0xfffd;
7696 break;
7697 case 9:
7698 vht_mcsmap = 0xfffe;
7699 break;
7700 default:
7701 vht_mcsmap = 0xfffe;
7702 break;
7703 }
7704 break;
7705 case 2:
7706 switch (mcs) {
7707 case 7:
7708 vht_mcsmap = 0xfff0;
7709 break;
7710 case 8:
7711 vht_mcsmap = 0xfff5;
7712 break;
7713 case 9:
7714 vht_mcsmap = 0xfffa;
7715 break;
7716 default:
7717 vht_mcsmap = 0xfffa;
7718 break;
7719 }
7720 break;
7721 case 3:
7722 switch (mcs) {
7723 case 7:
7724 vht_mcsmap = 0xffc0;
7725 break;
7726 case 8:
7727 vht_mcsmap = 0xffd5;
7728 break;
7729 case 9:
7730 vht_mcsmap = 0xffea;
7731 break;
7732 default:
7733 vht_mcsmap = 0xffea;
7734 break;
7735 }
7736 break;
7737 default:
7738 vht_mcsmap = 0xffea;
7739 break;
7740 }
7741 snprintf(buf, sizeof(buf),
7742 "iwpriv %s vht_mcsmap 0x%04x",
7743 intf, vht_mcsmap);
7744 if (system(buf) != 0) {
7745 sigma_dut_print(dut, DUT_MSG_ERROR,
7746 "iwpriv vht_mcsmap failed");
7747 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007748 }
7749 }
7750
7751 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
7752
7753 val = get_param(cmd, "Vht_tkip");
7754 if (val)
7755 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7756
7757 val = get_param(cmd, "Vht_wep");
7758 if (val)
7759 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7760
7761 if (tkip != -1 || wep != -1) {
7762 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
7763 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
7764 intf);
7765 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
7766 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
7767 intf);
7768 } else {
7769 sigma_dut_print(dut, DUT_MSG_ERROR,
7770 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
7771 return 0;
7772 }
7773
7774 if (system(buf) != 0) {
7775 sigma_dut_print(dut, DUT_MSG_ERROR,
7776 "iwpriv htweptkip failed");
7777 }
7778 }
7779
Arif Hussain55f00da2018-07-03 08:28:26 -07007780 val = get_param(cmd, "txBandwidth");
7781 if (val) {
7782 switch (get_driver_type()) {
7783 case DRIVER_WCN:
7784 if (wcn_sta_set_width(dut, intf, val) < 0) {
7785 send_resp(dut, conn, SIGMA_ERROR,
7786 "ErrorCode,Failed to set txBandwidth");
7787 return 0;
7788 }
7789 break;
7790 case DRIVER_ATHEROS:
7791 if (ath_set_width(dut, conn, intf, val) < 0) {
7792 send_resp(dut, conn, SIGMA_ERROR,
7793 "ErrorCode,Failed to set txBandwidth");
7794 return 0;
7795 }
7796 break;
7797 default:
7798 sigma_dut_print(dut, DUT_MSG_ERROR,
7799 "Setting txBandwidth not supported");
7800 break;
7801 }
7802 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007803
Arif Hussain9765f7d2018-07-03 08:28:26 -07007804 val = get_param(cmd, "BeamformeeSTS");
7805 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07007806 if (sta_set_tx_beamformee(dut, intf, 1)) {
7807 send_resp(dut, conn, SIGMA_ERROR,
7808 "ErrorCode,Failed to set TX beamformee enable");
7809 return 0;
7810 }
7811
Arif Hussain9765f7d2018-07-03 08:28:26 -07007812 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
7813 send_resp(dut, conn, SIGMA_ERROR,
7814 "ErrorCode,Failed to set BeamformeeSTS");
7815 return 0;
7816 }
7817 }
7818
Arif Hussain68d23f52018-07-11 13:39:08 -07007819 val = get_param(cmd, "Trig_MAC_Padding_Dur");
7820 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007821#ifdef NL80211_SUPPORT
7822 enum qca_wlan_he_mac_padding_dur set_val;
7823
7824 switch (atoi(val)) {
7825 case 16:
7826 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
7827 break;
7828 case 8:
7829 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
7830 break;
7831 default:
7832 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
7833 break;
7834 }
7835 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007836 send_resp(dut, conn, SIGMA_ERROR,
7837 "ErrorCode,Failed to set MAC padding duration");
7838 return 0;
7839 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007840#else /* NL80211_SUPPORT */
7841 sigma_dut_print(dut, DUT_MSG_ERROR,
7842 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
7843#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007844 }
7845
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007846 val = get_param(cmd, "MU_EDCA");
7847 if (val && (strcasecmp(val, "Override") == 0)) {
7848 if (sta_set_mu_edca_override(dut, intf, 1)) {
7849 send_resp(dut, conn, SIGMA_ERROR,
7850 "ErrorCode,Failed to set MU EDCA override");
7851 return 0;
7852 }
7853 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007854
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007855 val = get_param(cmd, "OMControl");
7856 if (val) {
7857 int set_val = 1;
7858
7859 if (strcasecmp(val, "Enable") == 0)
7860 set_val = 1;
7861 else if (strcasecmp(val, "Disable") == 0)
7862 set_val = 0;
7863
7864 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
7865 send_resp(dut, conn, SIGMA_ERROR,
7866 "ErrorCode,Failed to set OM ctrl supp");
7867 return 0;
7868 }
7869 }
7870
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007871 val = get_param(cmd, "ADDBAResp_BufSize");
7872 if (val) {
7873 int buf_size;
7874
7875 if (strcasecmp(val, "gt64") == 0)
7876 buf_size = 256;
7877 else
7878 buf_size = 64;
7879 if (get_driver_type() == DRIVER_WCN &&
7880 sta_set_addba_buf_size(dut, intf, buf_size)) {
7881 send_resp(dut, conn, SIGMA_ERROR,
7882 "ErrorCode,set addbaresp_buff_size failed");
7883 return 0;
7884 }
7885 }
7886
7887 val = get_param(cmd, "ADDBAReq_BufSize");
7888 if (val) {
7889 int buf_size;
7890
7891 if (strcasecmp(val, "gt64") == 0)
7892 buf_size = 256;
7893 else
7894 buf_size = 64;
7895 if (get_driver_type() == DRIVER_WCN &&
7896 sta_set_addba_buf_size(dut, intf, buf_size)) {
7897 send_resp(dut, conn, SIGMA_ERROR,
7898 "ErrorCode,set addbareq_buff_size failed");
7899 return 0;
7900 }
7901 }
7902
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007903 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7904}
7905
7906
7907static int sta_set_wireless_60g(struct sigma_dut *dut,
7908 struct sigma_conn *conn,
7909 struct sigma_cmd *cmd)
7910{
7911 const char *dev_role = get_param(cmd, "DevRole");
7912
7913 if (!dev_role) {
7914 send_resp(dut, conn, SIGMA_INVALID,
7915 "ErrorCode,DevRole not specified");
7916 return 0;
7917 }
7918
7919 if (strcasecmp(dev_role, "PCP") == 0)
7920 return sta_set_60g_pcp(dut, conn, cmd);
7921 if (strcasecmp(dev_role, "STA") == 0)
7922 return sta_set_60g_sta(dut, conn, cmd);
7923 send_resp(dut, conn, SIGMA_INVALID,
7924 "ErrorCode,DevRole not supported");
7925 return 0;
7926}
7927
7928
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307929static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
7930 struct sigma_cmd *cmd)
7931{
7932 int status;
7933 const char *intf = get_param(cmd, "Interface");
7934 const char *val = get_param(cmd, "DevRole");
7935
7936 if (val && strcasecmp(val, "STA-CFON") == 0) {
7937 status = sta_cfon_set_wireless(dut, conn, cmd);
7938 if (status)
7939 return status;
7940 }
7941 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7942}
7943
7944
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007945static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
7946 struct sigma_cmd *cmd)
7947{
7948 const char *val;
7949
7950 val = get_param(cmd, "Program");
7951 if (val) {
7952 if (strcasecmp(val, "11n") == 0)
7953 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08007954 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007955 return cmd_sta_set_wireless_vht(dut, conn, cmd);
7956 if (strcasecmp(val, "60ghz") == 0)
7957 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307958 if (strcasecmp(val, "OCE") == 0)
7959 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007960 send_resp(dut, conn, SIGMA_ERROR,
7961 "ErrorCode,Program value not supported");
7962 } else {
7963 send_resp(dut, conn, SIGMA_ERROR,
7964 "ErrorCode,Program argument not available");
7965 }
7966
7967 return 0;
7968}
7969
7970
7971static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
7972 int tid)
7973{
7974 char buf[100];
7975 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
7976
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05307977 if (tid < 0 ||
7978 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
7979 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
7980 return;
7981 }
7982
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007983 /*
7984 * Two ways to ensure that addba request with a
7985 * non zero TID could be sent out. EV 117296
7986 */
7987 snprintf(buf, sizeof(buf),
7988 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
7989 tid);
7990 if (system(buf) != 0) {
7991 sigma_dut_print(dut, DUT_MSG_ERROR,
7992 "Ping did not send out");
7993 }
7994
7995 snprintf(buf, sizeof(buf),
7996 "iwconfig %s | grep Access | awk '{print $6}' > %s",
7997 intf, VI_QOS_TMP_FILE);
7998 if (system(buf) != 0)
7999 return;
8000
8001 snprintf(buf, sizeof(buf),
8002 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8003 intf, VI_QOS_TMP_FILE);
8004 if (system(buf) != 0)
8005 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8006
8007 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8008 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8009 if (system(buf) != 0) {
8010 sigma_dut_print(dut, DUT_MSG_ERROR,
8011 "VI_QOS_TEMP_FILE generation error failed");
8012 }
8013 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8014 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8015 if (system(buf) != 0) {
8016 sigma_dut_print(dut, DUT_MSG_ERROR,
8017 "VI_QOS_FILE generation failed");
8018 }
8019
8020 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8021 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8022 if (system(buf) != 0) {
8023 sigma_dut_print(dut, DUT_MSG_ERROR,
8024 "VI_QOS_FILE generation failed");
8025 }
8026
8027 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8028 if (system(buf) != 0) {
8029 }
8030}
8031
8032
8033static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8034 struct sigma_cmd *cmd)
8035{
8036 const char *intf = get_param(cmd, "Interface");
8037 const char *val;
8038 int tid = 0;
8039 char buf[100];
8040
8041 val = get_param(cmd, "TID");
8042 if (val) {
8043 tid = atoi(val);
8044 if (tid)
8045 ath_sta_inject_frame(dut, intf, tid);
8046 }
8047
8048 /* Command sequence for ADDBA request on Peregrine based devices */
8049 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
8050 if (system(buf) != 0) {
8051 sigma_dut_print(dut, DUT_MSG_ERROR,
8052 "iwpriv setaddbaoper failed");
8053 }
8054
8055 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8056 if (system(buf) != 0) {
8057 sigma_dut_print(dut, DUT_MSG_ERROR,
8058 "wifitool senddelba failed");
8059 }
8060
8061 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8062 if (system(buf) != 0) {
8063 sigma_dut_print(dut, DUT_MSG_ERROR,
8064 "wifitool sendaddba failed");
8065 }
8066
8067 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8068
8069 return 1;
8070}
8071
8072
Lior David9981b512017-01-20 13:16:40 +02008073#ifdef __linux__
8074
8075static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
8076 int agg_size)
8077{
8078 char dir[128], buf[128];
8079 FILE *f;
8080 regex_t re;
8081 regmatch_t m[2];
8082 int rc, ret = -1, vring_id, found;
8083
8084 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
8085 sigma_dut_print(dut, DUT_MSG_ERROR,
8086 "failed to get wil6210 debugfs dir");
8087 return -1;
8088 }
8089
8090 snprintf(buf, sizeof(buf), "%s/vrings", dir);
8091 f = fopen(buf, "r");
8092 if (!f) {
8093 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008094 /* newer wil6210 driver renamed file to "rings" */
8095 snprintf(buf, sizeof(buf), "%s/rings", dir);
8096 f = fopen(buf, "r");
8097 if (!f) {
8098 sigma_dut_print(dut, DUT_MSG_ERROR,
8099 "failed to open: %s", buf);
8100 return -1;
8101 }
Lior David9981b512017-01-20 13:16:40 +02008102 }
8103
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008104 /* can be either VRING tx... or RING... */
8105 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02008106 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
8107 goto out;
8108 }
8109
8110 /* find TX VRING for the mac address */
8111 found = 0;
8112 while (fgets(buf, sizeof(buf), f)) {
8113 if (strcasestr(buf, dest_mac)) {
8114 found = 1;
8115 break;
8116 }
8117 }
8118
8119 if (!found) {
8120 sigma_dut_print(dut, DUT_MSG_ERROR,
8121 "no TX VRING for %s", dest_mac);
8122 goto out;
8123 }
8124
8125 /* extract VRING ID, "VRING tx_<id> = {" */
8126 if (!fgets(buf, sizeof(buf), f)) {
8127 sigma_dut_print(dut, DUT_MSG_ERROR,
8128 "no VRING start line for %s", dest_mac);
8129 goto out;
8130 }
8131
8132 rc = regexec(&re, buf, 2, m, 0);
8133 regfree(&re);
8134 if (rc || m[1].rm_so < 0) {
8135 sigma_dut_print(dut, DUT_MSG_ERROR,
8136 "no VRING TX ID for %s", dest_mac);
8137 goto out;
8138 }
8139 buf[m[1].rm_eo] = 0;
8140 vring_id = atoi(&buf[m[1].rm_so]);
8141
8142 /* send the addba command */
8143 fclose(f);
8144 snprintf(buf, sizeof(buf), "%s/back", dir);
8145 f = fopen(buf, "w");
8146 if (!f) {
8147 sigma_dut_print(dut, DUT_MSG_ERROR,
8148 "failed to open: %s", buf);
8149 return -1;
8150 }
8151
8152 fprintf(f, "add %d %d\n", vring_id, agg_size);
8153
8154 ret = 0;
8155
8156out:
8157 fclose(f);
8158
8159 return ret;
8160}
8161
8162
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008163int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8164 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008165{
8166 const char *val;
8167 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008168
8169 val = get_param(cmd, "TID");
8170 if (val) {
8171 tid = atoi(val);
8172 if (tid != 0) {
8173 sigma_dut_print(dut, DUT_MSG_ERROR,
8174 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
8175 tid);
8176 }
8177 }
8178
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008179 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008180 if (!val) {
8181 sigma_dut_print(dut, DUT_MSG_ERROR,
8182 "Currently not supporting addba for 60G without Dest_mac");
8183 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
8184 }
8185
Lior David9981b512017-01-20 13:16:40 +02008186 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008187 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008188
8189 return 1;
8190}
8191
Lior David9981b512017-01-20 13:16:40 +02008192#endif /* __linux__ */
8193
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008194
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008195static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8196 struct sigma_cmd *cmd)
8197{
8198#ifdef NL80211_SUPPORT
8199 const char *intf = get_param(cmd, "Interface");
8200 const char *val;
8201 int tid = -1;
8202 int bufsize = 64;
8203 struct nl_msg *msg;
8204 int ret = 0;
8205 struct nlattr *params;
8206 int ifindex;
8207
8208 val = get_param(cmd, "TID");
8209 if (val)
8210 tid = atoi(val);
8211
8212 if (tid == -1) {
8213 send_resp(dut, conn, SIGMA_ERROR,
8214 "ErrorCode,sta_send_addba tid invalid");
8215 return 0;
8216 }
8217
8218 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8219
8220 ifindex = if_nametoindex(intf);
8221 if (ifindex == 0) {
8222 sigma_dut_print(dut, DUT_MSG_ERROR,
8223 "%s: Index for interface %s failed",
8224 __func__, intf);
8225 send_resp(dut, conn, SIGMA_ERROR,
8226 "ErrorCode,sta_send_addba interface invalid");
8227 return 0;
8228 }
8229
8230 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8231 NL80211_CMD_VENDOR)) ||
8232 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8233 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8234 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8235 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8236 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8237 nla_put_u8(msg,
8238 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
8239 QCA_WLAN_ADD_BA) ||
8240 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
8241 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07008242 nla_put_u16(msg,
8243 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
8244 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008245 sigma_dut_print(dut, DUT_MSG_ERROR,
8246 "%s: err in adding vendor_cmd and vendor_data",
8247 __func__);
8248 nlmsg_free(msg);
8249 send_resp(dut, conn, SIGMA_ERROR,
8250 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
8251 return 0;
8252 }
8253 nla_nest_end(msg, params);
8254
8255 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8256 if (ret) {
8257 sigma_dut_print(dut, DUT_MSG_ERROR,
8258 "%s: err in send_and_recv_msgs, ret=%d",
8259 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05308260 if (ret == -EOPNOTSUPP)
8261 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008262 send_resp(dut, conn, SIGMA_ERROR,
8263 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
8264 return 0;
8265 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008266#else /* NL80211_SUPPORT */
8267 sigma_dut_print(dut, DUT_MSG_ERROR,
8268 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008269#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05308270
8271 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008272}
8273
8274
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008275static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8276 struct sigma_cmd *cmd)
8277{
8278 switch (get_driver_type()) {
8279 case DRIVER_ATHEROS:
8280 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008281 case DRIVER_WCN:
8282 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02008283#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008284 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008285 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02008286#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008287 default:
8288 /*
8289 * There is no driver specific implementation for other drivers.
8290 * Ignore the command and report COMPLETE since the following
8291 * throughput test operation will end up sending ADDBA anyway.
8292 */
8293 return 1;
8294 }
8295}
8296
8297
8298int inject_eth_frame(int s, const void *data, size_t len,
8299 unsigned short ethtype, char *dst, char *src)
8300{
8301 struct iovec iov[4] = {
8302 {
8303 .iov_base = dst,
8304 .iov_len = ETH_ALEN,
8305 },
8306 {
8307 .iov_base = src,
8308 .iov_len = ETH_ALEN,
8309 },
8310 {
8311 .iov_base = &ethtype,
8312 .iov_len = sizeof(unsigned short),
8313 },
8314 {
8315 .iov_base = (void *) data,
8316 .iov_len = len,
8317 }
8318 };
8319 struct msghdr msg = {
8320 .msg_name = NULL,
8321 .msg_namelen = 0,
8322 .msg_iov = iov,
8323 .msg_iovlen = 4,
8324 .msg_control = NULL,
8325 .msg_controllen = 0,
8326 .msg_flags = 0,
8327 };
8328
8329 return sendmsg(s, &msg, 0);
8330}
8331
8332#if defined(__linux__) || defined(__QNXNTO__)
8333
8334int inject_frame(int s, const void *data, size_t len, int encrypt)
8335{
8336#define IEEE80211_RADIOTAP_F_WEP 0x04
8337#define IEEE80211_RADIOTAP_F_FRAG 0x08
8338 unsigned char rtap_hdr[] = {
8339 0x00, 0x00, /* radiotap version */
8340 0x0e, 0x00, /* radiotap length */
8341 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
8342 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
8343 0x00, /* padding */
8344 0x00, 0x00, /* RX and TX flags to indicate that */
8345 0x00, 0x00, /* this is the injected frame directly */
8346 };
8347 struct iovec iov[2] = {
8348 {
8349 .iov_base = &rtap_hdr,
8350 .iov_len = sizeof(rtap_hdr),
8351 },
8352 {
8353 .iov_base = (void *) data,
8354 .iov_len = len,
8355 }
8356 };
8357 struct msghdr msg = {
8358 .msg_name = NULL,
8359 .msg_namelen = 0,
8360 .msg_iov = iov,
8361 .msg_iovlen = 2,
8362 .msg_control = NULL,
8363 .msg_controllen = 0,
8364 .msg_flags = 0,
8365 };
8366
8367 if (encrypt)
8368 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
8369
8370 return sendmsg(s, &msg, 0);
8371}
8372
8373
8374int open_monitor(const char *ifname)
8375{
8376#ifdef __QNXNTO__
8377 struct sockaddr_dl ll;
8378 int s;
8379
8380 memset(&ll, 0, sizeof(ll));
8381 ll.sdl_family = AF_LINK;
8382 ll.sdl_index = if_nametoindex(ifname);
8383 if (ll.sdl_index == 0) {
8384 perror("if_nametoindex");
8385 return -1;
8386 }
8387 s = socket(PF_INET, SOCK_RAW, 0);
8388#else /* __QNXNTO__ */
8389 struct sockaddr_ll ll;
8390 int s;
8391
8392 memset(&ll, 0, sizeof(ll));
8393 ll.sll_family = AF_PACKET;
8394 ll.sll_ifindex = if_nametoindex(ifname);
8395 if (ll.sll_ifindex == 0) {
8396 perror("if_nametoindex");
8397 return -1;
8398 }
8399 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
8400#endif /* __QNXNTO__ */
8401 if (s < 0) {
8402 perror("socket[PF_PACKET,SOCK_RAW]");
8403 return -1;
8404 }
8405
8406 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
8407 perror("monitor socket bind");
8408 close(s);
8409 return -1;
8410 }
8411
8412 return s;
8413}
8414
8415
8416static int hex2num(char c)
8417{
8418 if (c >= '0' && c <= '9')
8419 return c - '0';
8420 if (c >= 'a' && c <= 'f')
8421 return c - 'a' + 10;
8422 if (c >= 'A' && c <= 'F')
8423 return c - 'A' + 10;
8424 return -1;
8425}
8426
8427
8428int hwaddr_aton(const char *txt, unsigned char *addr)
8429{
8430 int i;
8431
8432 for (i = 0; i < 6; i++) {
8433 int a, b;
8434
8435 a = hex2num(*txt++);
8436 if (a < 0)
8437 return -1;
8438 b = hex2num(*txt++);
8439 if (b < 0)
8440 return -1;
8441 *addr++ = (a << 4) | b;
8442 if (i < 5 && *txt++ != ':')
8443 return -1;
8444 }
8445
8446 return 0;
8447}
8448
8449#endif /* defined(__linux__) || defined(__QNXNTO__) */
8450
8451enum send_frame_type {
8452 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
8453};
8454enum send_frame_protection {
8455 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8456};
8457
8458
8459static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8460 enum send_frame_type frame,
8461 enum send_frame_protection protected,
8462 const char *dest)
8463{
8464#ifdef __linux__
8465 unsigned char buf[1000], *pos;
8466 int s, res;
8467 char bssid[20], addr[20];
8468 char result[32], ssid[100];
8469 size_t ssid_len;
8470
8471 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
8472 sizeof(result)) < 0 ||
8473 strncmp(result, "COMPLETED", 9) != 0) {
8474 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
8475 return 0;
8476 }
8477
8478 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
8479 < 0) {
8480 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8481 "current BSSID");
8482 return 0;
8483 }
8484
8485 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
8486 < 0) {
8487 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8488 "own MAC address");
8489 return 0;
8490 }
8491
8492 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
8493 < 0) {
8494 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8495 "current SSID");
8496 return 0;
8497 }
8498 ssid_len = strlen(ssid);
8499
8500 pos = buf;
8501
8502 /* Frame Control */
8503 switch (frame) {
8504 case DISASSOC:
8505 *pos++ = 0xa0;
8506 break;
8507 case DEAUTH:
8508 *pos++ = 0xc0;
8509 break;
8510 case SAQUERY:
8511 *pos++ = 0xd0;
8512 break;
8513 case AUTH:
8514 *pos++ = 0xb0;
8515 break;
8516 case ASSOCREQ:
8517 *pos++ = 0x00;
8518 break;
8519 case REASSOCREQ:
8520 *pos++ = 0x20;
8521 break;
8522 case DLS_REQ:
8523 *pos++ = 0xd0;
8524 break;
8525 }
8526
8527 if (protected == INCORRECT_KEY)
8528 *pos++ = 0x40; /* Set Protected field to 1 */
8529 else
8530 *pos++ = 0x00;
8531
8532 /* Duration */
8533 *pos++ = 0x00;
8534 *pos++ = 0x00;
8535
8536 /* addr1 = DA (current AP) */
8537 hwaddr_aton(bssid, pos);
8538 pos += 6;
8539 /* addr2 = SA (own address) */
8540 hwaddr_aton(addr, pos);
8541 pos += 6;
8542 /* addr3 = BSSID (current AP) */
8543 hwaddr_aton(bssid, pos);
8544 pos += 6;
8545
8546 /* Seq# (to be filled by driver/mac80211) */
8547 *pos++ = 0x00;
8548 *pos++ = 0x00;
8549
8550 if (protected == INCORRECT_KEY) {
8551 /* CCMP parameters */
8552 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8553 pos += 8;
8554 }
8555
8556 if (protected == INCORRECT_KEY) {
8557 switch (frame) {
8558 case DEAUTH:
8559 /* Reason code (encrypted) */
8560 memcpy(pos, "\xa7\x39", 2);
8561 pos += 2;
8562 break;
8563 case DISASSOC:
8564 /* Reason code (encrypted) */
8565 memcpy(pos, "\xa7\x39", 2);
8566 pos += 2;
8567 break;
8568 case SAQUERY:
8569 /* Category|Action|TransID (encrypted) */
8570 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8571 pos += 4;
8572 break;
8573 default:
8574 return -1;
8575 }
8576
8577 /* CCMP MIC */
8578 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8579 pos += 8;
8580 } else {
8581 switch (frame) {
8582 case DEAUTH:
8583 /* reason code = 8 */
8584 *pos++ = 0x08;
8585 *pos++ = 0x00;
8586 break;
8587 case DISASSOC:
8588 /* reason code = 8 */
8589 *pos++ = 0x08;
8590 *pos++ = 0x00;
8591 break;
8592 case SAQUERY:
8593 /* Category - SA Query */
8594 *pos++ = 0x08;
8595 /* SA query Action - Request */
8596 *pos++ = 0x00;
8597 /* Transaction ID */
8598 *pos++ = 0x12;
8599 *pos++ = 0x34;
8600 break;
8601 case AUTH:
8602 /* Auth Alg (Open) */
8603 *pos++ = 0x00;
8604 *pos++ = 0x00;
8605 /* Seq# */
8606 *pos++ = 0x01;
8607 *pos++ = 0x00;
8608 /* Status code */
8609 *pos++ = 0x00;
8610 *pos++ = 0x00;
8611 break;
8612 case ASSOCREQ:
8613 /* Capability Information */
8614 *pos++ = 0x31;
8615 *pos++ = 0x04;
8616 /* Listen Interval */
8617 *pos++ = 0x0a;
8618 *pos++ = 0x00;
8619 /* SSID */
8620 *pos++ = 0x00;
8621 *pos++ = ssid_len;
8622 memcpy(pos, ssid, ssid_len);
8623 pos += ssid_len;
8624 /* Supported Rates */
8625 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8626 10);
8627 pos += 10;
8628 /* Extended Supported Rates */
8629 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8630 pos += 6;
8631 /* RSN */
8632 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8633 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8634 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8635 pos += 28;
8636 break;
8637 case REASSOCREQ:
8638 /* Capability Information */
8639 *pos++ = 0x31;
8640 *pos++ = 0x04;
8641 /* Listen Interval */
8642 *pos++ = 0x0a;
8643 *pos++ = 0x00;
8644 /* Current AP */
8645 hwaddr_aton(bssid, pos);
8646 pos += 6;
8647 /* SSID */
8648 *pos++ = 0x00;
8649 *pos++ = ssid_len;
8650 memcpy(pos, ssid, ssid_len);
8651 pos += ssid_len;
8652 /* Supported Rates */
8653 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8654 10);
8655 pos += 10;
8656 /* Extended Supported Rates */
8657 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8658 pos += 6;
8659 /* RSN */
8660 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8661 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8662 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8663 pos += 28;
8664 break;
8665 case DLS_REQ:
8666 /* Category - DLS */
8667 *pos++ = 0x02;
8668 /* DLS Action - Request */
8669 *pos++ = 0x00;
8670 /* Destination MACAddress */
8671 if (dest)
8672 hwaddr_aton(dest, pos);
8673 else
8674 memset(pos, 0, 6);
8675 pos += 6;
8676 /* Source MACAddress */
8677 hwaddr_aton(addr, pos);
8678 pos += 6;
8679 /* Capability Information */
8680 *pos++ = 0x10; /* Privacy */
8681 *pos++ = 0x06; /* QoS */
8682 /* DLS Timeout Value */
8683 *pos++ = 0x00;
8684 *pos++ = 0x01;
8685 /* Supported rates */
8686 *pos++ = 0x01;
8687 *pos++ = 0x08;
8688 *pos++ = 0x0c; /* 6 Mbps */
8689 *pos++ = 0x12; /* 9 Mbps */
8690 *pos++ = 0x18; /* 12 Mbps */
8691 *pos++ = 0x24; /* 18 Mbps */
8692 *pos++ = 0x30; /* 24 Mbps */
8693 *pos++ = 0x48; /* 36 Mbps */
8694 *pos++ = 0x60; /* 48 Mbps */
8695 *pos++ = 0x6c; /* 54 Mbps */
8696 /* TODO: Extended Supported Rates */
8697 /* TODO: HT Capabilities */
8698 break;
8699 }
8700 }
8701
8702 s = open_monitor("sigmadut");
8703 if (s < 0) {
8704 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8705 "monitor socket");
8706 return 0;
8707 }
8708
8709 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8710 if (res < 0) {
8711 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8712 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308713 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008714 return 0;
8715 }
8716 if (res < pos - buf) {
8717 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8718 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308719 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008720 return 0;
8721 }
8722
8723 close(s);
8724
8725 return 1;
8726#else /* __linux__ */
8727 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
8728 "yet supported");
8729 return 0;
8730#endif /* __linux__ */
8731}
8732
8733
8734static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
8735 struct sigma_conn *conn,
8736 struct sigma_cmd *cmd)
8737{
8738 const char *intf = get_param(cmd, "Interface");
8739 const char *sta, *val;
8740 unsigned char addr[ETH_ALEN];
8741 char buf[100];
8742
8743 sta = get_param(cmd, "peer");
8744 if (sta == NULL)
8745 sta = get_param(cmd, "station");
8746 if (sta == NULL) {
8747 send_resp(dut, conn, SIGMA_ERROR,
8748 "ErrorCode,Missing peer address");
8749 return 0;
8750 }
8751 if (hwaddr_aton(sta, addr) < 0) {
8752 send_resp(dut, conn, SIGMA_ERROR,
8753 "ErrorCode,Invalid peer address");
8754 return 0;
8755 }
8756
8757 val = get_param(cmd, "type");
8758 if (val == NULL)
8759 return -1;
8760
8761 if (strcasecmp(val, "DISCOVERY") == 0) {
8762 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
8763 if (wpa_command(intf, buf) < 0) {
8764 send_resp(dut, conn, SIGMA_ERROR,
8765 "ErrorCode,Failed to send TDLS discovery");
8766 return 0;
8767 }
8768 return 1;
8769 }
8770
8771 if (strcasecmp(val, "SETUP") == 0) {
8772 int status = 0, timeout = 0;
8773
8774 val = get_param(cmd, "Status");
8775 if (val)
8776 status = atoi(val);
8777
8778 val = get_param(cmd, "Timeout");
8779 if (val)
8780 timeout = atoi(val);
8781
8782 if (status != 0 && status != 37) {
8783 send_resp(dut, conn, SIGMA_ERROR,
8784 "ErrorCode,Unsupported status value");
8785 return 0;
8786 }
8787
8788 if (timeout != 0 && timeout != 301) {
8789 send_resp(dut, conn, SIGMA_ERROR,
8790 "ErrorCode,Unsupported timeout value");
8791 return 0;
8792 }
8793
8794 if (status && timeout) {
8795 send_resp(dut, conn, SIGMA_ERROR,
8796 "ErrorCode,Unsupported timeout+status "
8797 "combination");
8798 return 0;
8799 }
8800
8801 if (status == 37 &&
8802 wpa_command(intf, "SET tdls_testing 0x200")) {
8803 send_resp(dut, conn, SIGMA_ERROR,
8804 "ErrorCode,Failed to enable "
8805 "decline setup response test mode");
8806 return 0;
8807 }
8808
8809 if (timeout == 301) {
8810 int res;
8811 if (dut->no_tpk_expiration)
8812 res = wpa_command(intf,
8813 "SET tdls_testing 0x108");
8814 else
8815 res = wpa_command(intf,
8816 "SET tdls_testing 0x8");
8817 if (res) {
8818 send_resp(dut, conn, SIGMA_ERROR,
8819 "ErrorCode,Failed to set short TPK "
8820 "lifetime");
8821 return 0;
8822 }
8823 }
8824
8825 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
8826 if (wpa_command(intf, buf) < 0) {
8827 send_resp(dut, conn, SIGMA_ERROR,
8828 "ErrorCode,Failed to send TDLS setup");
8829 return 0;
8830 }
8831 return 1;
8832 }
8833
8834 if (strcasecmp(val, "TEARDOWN") == 0) {
8835 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
8836 if (wpa_command(intf, buf) < 0) {
8837 send_resp(dut, conn, SIGMA_ERROR,
8838 "ErrorCode,Failed to send TDLS teardown");
8839 return 0;
8840 }
8841 return 1;
8842 }
8843
8844 send_resp(dut, conn, SIGMA_ERROR,
8845 "ErrorCode,Unsupported TDLS frame");
8846 return 0;
8847}
8848
8849
8850static int sta_ap_known(const char *ifname, const char *bssid)
8851{
8852 char buf[4096];
8853
Jouni Malinendd32f192018-09-15 02:55:19 +03008854 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008855 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
8856 return 0;
8857 if (strncmp(buf, "id=", 3) != 0)
8858 return 0;
8859 return 1;
8860}
8861
8862
8863static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
8864 const char *bssid)
8865{
8866 int res;
8867 struct wpa_ctrl *ctrl;
8868 char buf[256];
8869
8870 if (sta_ap_known(ifname, bssid))
8871 return 0;
8872 sigma_dut_print(dut, DUT_MSG_DEBUG,
8873 "AP not in BSS table - start scan");
8874
8875 ctrl = open_wpa_mon(ifname);
8876 if (ctrl == NULL) {
8877 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8878 "wpa_supplicant monitor connection");
8879 return -1;
8880 }
8881
8882 if (wpa_command(ifname, "SCAN") < 0) {
8883 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
8884 wpa_ctrl_detach(ctrl);
8885 wpa_ctrl_close(ctrl);
8886 return -1;
8887 }
8888
8889 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
8890 buf, sizeof(buf));
8891
8892 wpa_ctrl_detach(ctrl);
8893 wpa_ctrl_close(ctrl);
8894
8895 if (res < 0) {
8896 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
8897 return -1;
8898 }
8899
8900 if (sta_ap_known(ifname, bssid))
8901 return 0;
8902 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
8903 return -1;
8904}
8905
8906
8907static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
8908 struct sigma_conn *conn,
8909 struct sigma_cmd *cmd,
8910 const char *intf)
8911{
8912 char buf[200];
8913
8914 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
8915 if (system(buf) != 0) {
8916 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
8917 "ndsend");
8918 return 0;
8919 }
8920
8921 return 1;
8922}
8923
8924
8925static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
8926 struct sigma_conn *conn,
8927 struct sigma_cmd *cmd,
8928 const char *intf)
8929{
8930 char buf[200];
8931 const char *ip = get_param(cmd, "SenderIP");
8932
Peng Xu26b356d2017-10-04 17:58:16 -07008933 if (!ip)
8934 return 0;
8935
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008936 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
8937 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8938 if (system(buf) == 0) {
8939 sigma_dut_print(dut, DUT_MSG_INFO,
8940 "Neighbor Solicitation got a response "
8941 "for %s@%s", ip, intf);
8942 }
8943
8944 return 1;
8945}
8946
8947
8948static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
8949 struct sigma_conn *conn,
8950 struct sigma_cmd *cmd,
8951 const char *ifname)
8952{
8953 char buf[200];
8954 const char *ip = get_param(cmd, "SenderIP");
8955
8956 if (ip == NULL) {
8957 send_resp(dut, conn, SIGMA_ERROR,
8958 "ErrorCode,Missing SenderIP parameter");
8959 return 0;
8960 }
8961 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
8962 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8963 if (system(buf) != 0) {
8964 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
8965 "for %s@%s", ip, ifname);
8966 }
8967
8968 return 1;
8969}
8970
8971
8972static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
8973 struct sigma_conn *conn,
8974 struct sigma_cmd *cmd,
8975 const char *ifname)
8976{
8977 char buf[200];
8978 char ip[16];
8979 int s;
Peng Xub3756882017-10-04 14:39:09 -07008980 struct ifreq ifr;
8981 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008982
8983 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07008984 if (s < 0) {
8985 perror("socket");
8986 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008987 }
8988
Peng Xub3756882017-10-04 14:39:09 -07008989 memset(&ifr, 0, sizeof(ifr));
8990 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
8991 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
8992 sigma_dut_print(dut, DUT_MSG_INFO,
8993 "Failed to get %s IP address: %s",
8994 ifname, strerror(errno));
8995 close(s);
8996 return -1;
8997 }
8998 close(s);
8999
9000 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9001 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9002
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009003 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9004 ip);
9005 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9006 if (system(buf) != 0) {
9007 }
9008
9009 return 1;
9010}
9011
9012
9013static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9014 struct sigma_conn *conn,
9015 struct sigma_cmd *cmd,
9016 const char *ifname)
9017{
9018 char buf[200], addr[20];
9019 char dst[ETH_ALEN], src[ETH_ALEN];
9020 short ethtype = htons(ETH_P_ARP);
9021 char *pos;
9022 int s, res;
9023 const char *val;
9024 struct sockaddr_in taddr;
9025
9026 val = get_param(cmd, "dest");
9027 if (val)
9028 hwaddr_aton(val, (unsigned char *) dst);
9029
9030 val = get_param(cmd, "DestIP");
9031 if (val)
9032 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009033 else
9034 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009035
9036 if (get_wpa_status(get_station_ifname(), "address", addr,
9037 sizeof(addr)) < 0)
9038 return -2;
9039 hwaddr_aton(addr, (unsigned char *) src);
9040
9041 pos = buf;
9042 *pos++ = 0x00;
9043 *pos++ = 0x01;
9044 *pos++ = 0x08;
9045 *pos++ = 0x00;
9046 *pos++ = 0x06;
9047 *pos++ = 0x04;
9048 *pos++ = 0x00;
9049 *pos++ = 0x02;
9050 memcpy(pos, src, ETH_ALEN);
9051 pos += ETH_ALEN;
9052 memcpy(pos, &taddr.sin_addr, 4);
9053 pos += 4;
9054 memcpy(pos, dst, ETH_ALEN);
9055 pos += ETH_ALEN;
9056 memcpy(pos, &taddr.sin_addr, 4);
9057 pos += 4;
9058
9059 s = open_monitor(get_station_ifname());
9060 if (s < 0) {
9061 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9062 "monitor socket");
9063 return 0;
9064 }
9065
9066 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
9067 if (res < 0) {
9068 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9069 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309070 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009071 return 0;
9072 }
9073
9074 close(s);
9075
9076 return 1;
9077}
9078
9079
9080static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
9081 struct sigma_conn *conn,
9082 struct sigma_cmd *cmd,
9083 const char *intf, const char *dest)
9084{
9085 char buf[100];
9086
9087 if (if_nametoindex("sigmadut") == 0) {
9088 snprintf(buf, sizeof(buf),
9089 "iw dev %s interface add sigmadut type monitor",
9090 get_station_ifname());
9091 if (system(buf) != 0 ||
9092 if_nametoindex("sigmadut") == 0) {
9093 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9094 "monitor interface with '%s'", buf);
9095 return -2;
9096 }
9097 }
9098
9099 if (system("ifconfig sigmadut up") != 0) {
9100 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9101 "monitor interface up");
9102 return -2;
9103 }
9104
9105 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
9106}
9107
9108
9109static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
9110 struct sigma_conn *conn,
9111 struct sigma_cmd *cmd)
9112{
9113 const char *intf = get_param(cmd, "Interface");
9114 const char *dest = get_param(cmd, "Dest");
9115 const char *type = get_param(cmd, "FrameName");
9116 const char *val;
9117 char buf[200], *pos, *end;
9118 int count, count2;
9119
9120 if (type == NULL)
9121 type = get_param(cmd, "Type");
9122
9123 if (intf == NULL || dest == NULL || type == NULL)
9124 return -1;
9125
9126 if (strcasecmp(type, "NeighAdv") == 0)
9127 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
9128
9129 if (strcasecmp(type, "NeighSolicitReq") == 0)
9130 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
9131
9132 if (strcasecmp(type, "ARPProbe") == 0)
9133 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
9134
9135 if (strcasecmp(type, "ARPAnnounce") == 0)
9136 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
9137
9138 if (strcasecmp(type, "ARPReply") == 0)
9139 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
9140
9141 if (strcasecmp(type, "DLS-request") == 0 ||
9142 strcasecmp(type, "DLSrequest") == 0)
9143 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
9144 dest);
9145
9146 if (strcasecmp(type, "ANQPQuery") != 0 &&
9147 strcasecmp(type, "Query") != 0) {
9148 send_resp(dut, conn, SIGMA_ERROR,
9149 "ErrorCode,Unsupported HS 2.0 send frame type");
9150 return 0;
9151 }
9152
9153 if (sta_scan_ap(dut, intf, dest) < 0) {
9154 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
9155 "the requested AP");
9156 return 0;
9157 }
9158
9159 pos = buf;
9160 end = buf + sizeof(buf);
9161 count = 0;
9162 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
9163
9164 val = get_param(cmd, "ANQP_CAP_LIST");
9165 if (val && atoi(val)) {
9166 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
9167 count++;
9168 }
9169
9170 val = get_param(cmd, "VENUE_NAME");
9171 if (val && atoi(val)) {
9172 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
9173 count++;
9174 }
9175
9176 val = get_param(cmd, "NETWORK_AUTH_TYPE");
9177 if (val && atoi(val)) {
9178 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
9179 count++;
9180 }
9181
9182 val = get_param(cmd, "ROAMING_CONS");
9183 if (val && atoi(val)) {
9184 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
9185 count++;
9186 }
9187
9188 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
9189 if (val && atoi(val)) {
9190 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
9191 count++;
9192 }
9193
9194 val = get_param(cmd, "NAI_REALM_LIST");
9195 if (val && atoi(val)) {
9196 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
9197 count++;
9198 }
9199
9200 val = get_param(cmd, "3GPP_INFO");
9201 if (val && atoi(val)) {
9202 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
9203 count++;
9204 }
9205
9206 val = get_param(cmd, "DOMAIN_LIST");
9207 if (val && atoi(val)) {
9208 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
9209 count++;
9210 }
9211
Jouni Malinen34cf9532018-04-29 19:26:33 +03009212 val = get_param(cmd, "Venue_URL");
9213 if (val && atoi(val)) {
9214 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
9215 count++;
9216 }
9217
Jouni Malinend3bca5d2018-04-29 17:25:23 +03009218 val = get_param(cmd, "Advice_Of_Charge");
9219 if (val && atoi(val)) {
9220 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
9221 count++;
9222 }
9223
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009224 if (count && wpa_command(intf, buf)) {
9225 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
9226 return 0;
9227 }
9228
9229 pos = buf;
9230 end = buf + sizeof(buf);
9231 count2 = 0;
9232 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
9233
9234 val = get_param(cmd, "HS_CAP_LIST");
9235 if (val && atoi(val)) {
9236 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
9237 count2++;
9238 }
9239
9240 val = get_param(cmd, "OPER_NAME");
9241 if (val && atoi(val)) {
9242 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
9243 count2++;
9244 }
9245
9246 val = get_param(cmd, "WAN_METRICS");
9247 if (!val)
9248 val = get_param(cmd, "WAN_MAT");
9249 if (!val)
9250 val = get_param(cmd, "WAN_MET");
9251 if (val && atoi(val)) {
9252 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
9253 count2++;
9254 }
9255
9256 val = get_param(cmd, "CONNECTION_CAPABILITY");
9257 if (val && atoi(val)) {
9258 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
9259 count2++;
9260 }
9261
9262 val = get_param(cmd, "OP_CLASS");
9263 if (val && atoi(val)) {
9264 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
9265 count2++;
9266 }
9267
9268 val = get_param(cmd, "OSU_PROVIDER_LIST");
9269 if (val && atoi(val)) {
9270 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
9271 count2++;
9272 }
9273
Jouni Malinenf67afec2018-04-29 19:24:58 +03009274 val = get_param(cmd, "OPER_ICON_METADATA");
9275 if (!val)
9276 val = get_param(cmd, "OPERATOR_ICON_METADATA");
9277 if (val && atoi(val)) {
9278 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
9279 count2++;
9280 }
9281
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009282 if (count && count2) {
9283 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
9284 "second query");
9285 sleep(1);
9286 }
9287
9288 if (count2 && wpa_command(intf, buf)) {
9289 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
9290 "failed");
9291 return 0;
9292 }
9293
9294 val = get_param(cmd, "NAI_HOME_REALM_LIST");
9295 if (val) {
9296 if (count || count2) {
9297 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9298 "sending out second query");
9299 sleep(1);
9300 }
9301
9302 if (strcmp(val, "1") == 0)
9303 val = "mail.example.com";
9304 snprintf(buf, end - pos,
9305 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
9306 dest, val);
9307 if (wpa_command(intf, buf)) {
9308 send_resp(dut, conn, SIGMA_ERROR,
9309 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
9310 "failed");
9311 return 0;
9312 }
9313 }
9314
9315 val = get_param(cmd, "ICON_REQUEST");
9316 if (val) {
9317 if (count || count2) {
9318 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9319 "sending out second query");
9320 sleep(1);
9321 }
9322
9323 snprintf(buf, end - pos,
9324 "HS20_ICON_REQUEST %s %s", dest, val);
9325 if (wpa_command(intf, buf)) {
9326 send_resp(dut, conn, SIGMA_ERROR,
9327 "ErrorCode,HS20_ICON_REQUEST failed");
9328 return 0;
9329 }
9330 }
9331
9332 return 1;
9333}
9334
9335
9336static int ath_sta_send_frame_vht(struct sigma_dut *dut,
9337 struct sigma_conn *conn,
9338 struct sigma_cmd *cmd)
9339{
9340 const char *val;
9341 char *ifname;
9342 char buf[100];
9343 int chwidth, nss;
9344
9345 val = get_param(cmd, "framename");
9346 if (!val)
9347 return -1;
9348 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9349
9350 /* Command sequence to generate Op mode notification */
9351 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
9352 ifname = get_station_ifname();
9353
9354 /* Disable STBC */
9355 snprintf(buf, sizeof(buf),
9356 "iwpriv %s tx_stbc 0", ifname);
9357 if (system(buf) != 0) {
9358 sigma_dut_print(dut, DUT_MSG_ERROR,
9359 "iwpriv tx_stbc 0 failed!");
9360 }
9361
9362 /* Extract Channel width */
9363 val = get_param(cmd, "Channel_width");
9364 if (val) {
9365 switch (atoi(val)) {
9366 case 20:
9367 chwidth = 0;
9368 break;
9369 case 40:
9370 chwidth = 1;
9371 break;
9372 case 80:
9373 chwidth = 2;
9374 break;
9375 case 160:
9376 chwidth = 3;
9377 break;
9378 default:
9379 chwidth = 2;
9380 break;
9381 }
9382
9383 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9384 ifname, chwidth);
9385 if (system(buf) != 0) {
9386 sigma_dut_print(dut, DUT_MSG_ERROR,
9387 "iwpriv chwidth failed!");
9388 }
9389 }
9390
9391 /* Extract NSS */
9392 val = get_param(cmd, "NSS");
9393 if (val) {
9394 switch (atoi(val)) {
9395 case 1:
9396 nss = 1;
9397 break;
9398 case 2:
9399 nss = 3;
9400 break;
9401 case 3:
9402 nss = 7;
9403 break;
9404 default:
9405 /* We do not support NSS > 3 */
9406 nss = 3;
9407 break;
9408 }
9409 snprintf(buf, sizeof(buf),
9410 "iwpriv %s rxchainmask %d", ifname, nss);
9411 if (system(buf) != 0) {
9412 sigma_dut_print(dut, DUT_MSG_ERROR,
9413 "iwpriv rxchainmask failed!");
9414 }
9415 }
9416
9417 /* Opmode notify */
9418 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
9419 if (system(buf) != 0) {
9420 sigma_dut_print(dut, DUT_MSG_ERROR,
9421 "iwpriv opmode_notify failed!");
9422 } else {
9423 sigma_dut_print(dut, DUT_MSG_INFO,
9424 "Sent out the notify frame!");
9425 }
9426 }
9427
9428 return 1;
9429}
9430
9431
9432static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
9433 struct sigma_conn *conn,
9434 struct sigma_cmd *cmd)
9435{
9436 switch (get_driver_type()) {
9437 case DRIVER_ATHEROS:
9438 return ath_sta_send_frame_vht(dut, conn, cmd);
9439 default:
9440 send_resp(dut, conn, SIGMA_ERROR,
9441 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
9442 return 0;
9443 }
9444}
9445
9446
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009447static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
9448 struct sigma_cmd *cmd)
9449{
9450 const char *val;
9451 const char *intf = get_param(cmd, "Interface");
9452
9453 val = get_param(cmd, "framename");
9454 if (!val)
9455 return -1;
9456 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9457
9458 /* Command sequence to generate Op mode notification */
9459 if (val && strcasecmp(val, "action") == 0) {
9460 val = get_param(cmd, "PPDUTxType");
9461 if (val && strcasecmp(val, "TB") == 0) {
9462 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
9463 sigma_dut_print(dut, DUT_MSG_ERROR,
9464 "failed to send TB PPDU Tx cfg");
9465 send_resp(dut, conn, SIGMA_ERROR,
9466 "ErrorCode,set TB PPDU Tx cfg failed");
9467 return 0;
9468 }
9469 return 1;
9470 }
9471
9472 sigma_dut_print(dut, DUT_MSG_ERROR,
9473 "Action Tx type is not defined");
9474 }
9475
9476 return 1;
9477}
9478
9479
9480static int cmd_sta_send_frame_he(struct sigma_dut *dut,
9481 struct sigma_conn *conn,
9482 struct sigma_cmd *cmd)
9483{
9484 switch (get_driver_type()) {
9485 case DRIVER_WCN:
9486 return wcn_sta_send_frame_he(dut, conn, cmd);
9487 default:
9488 send_resp(dut, conn, SIGMA_ERROR,
9489 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
9490 return 0;
9491 }
9492}
9493
9494
Lior David0fe101e2017-03-09 16:09:50 +02009495#ifdef __linux__
9496int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9497 struct sigma_cmd *cmd)
9498{
9499 const char *frame_name = get_param(cmd, "framename");
9500 const char *mac = get_param(cmd, "dest_mac");
9501
9502 if (!frame_name || !mac) {
9503 sigma_dut_print(dut, DUT_MSG_ERROR,
9504 "framename and dest_mac must be provided");
9505 return -1;
9506 }
9507
9508 if (strcasecmp(frame_name, "brp") == 0) {
9509 const char *l_rx = get_param(cmd, "L-RX");
9510 int l_rx_i;
9511
9512 if (!l_rx) {
9513 sigma_dut_print(dut, DUT_MSG_ERROR,
9514 "L-RX must be provided");
9515 return -1;
9516 }
9517 l_rx_i = atoi(l_rx);
9518
9519 sigma_dut_print(dut, DUT_MSG_INFO,
9520 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
9521 mac, l_rx);
9522 if (l_rx_i != 16) {
9523 sigma_dut_print(dut, DUT_MSG_ERROR,
9524 "unsupported L-RX: %s", l_rx);
9525 return -1;
9526 }
9527
9528 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
9529 return -1;
9530 } else if (strcasecmp(frame_name, "ssw") == 0) {
9531 sigma_dut_print(dut, DUT_MSG_INFO,
9532 "dev_send_frame: SLS, dest_mac %s", mac);
9533 if (wil6210_send_sls(dut, mac))
9534 return -1;
9535 } else {
9536 sigma_dut_print(dut, DUT_MSG_ERROR,
9537 "unsupported frame type: %s", frame_name);
9538 return -1;
9539 }
9540
9541 return 1;
9542}
9543#endif /* __linux__ */
9544
9545
9546static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
9547 struct sigma_conn *conn,
9548 struct sigma_cmd *cmd)
9549{
9550 switch (get_driver_type()) {
9551#ifdef __linux__
9552 case DRIVER_WIL6210:
9553 return wil6210_send_frame_60g(dut, conn, cmd);
9554#endif /* __linux__ */
9555 default:
9556 send_resp(dut, conn, SIGMA_ERROR,
9557 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9558 return 0;
9559 }
9560}
9561
9562
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309563static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
9564 const char *intf, struct sigma_cmd *cmd)
9565{
9566 const char *val, *addr;
9567 char buf[100];
9568
9569 addr = get_param(cmd, "DestMac");
9570 if (!addr) {
9571 send_resp(dut, conn, SIGMA_INVALID,
9572 "ErrorCode,AP MAC address is missing");
9573 return 0;
9574 }
9575
9576 val = get_param(cmd, "ANQPQuery_ID");
9577 if (!val) {
9578 send_resp(dut, conn, SIGMA_INVALID,
9579 "ErrorCode,Missing ANQPQuery_ID");
9580 return 0;
9581 }
9582
9583 if (strcasecmp(val, "NeighborReportReq") == 0) {
9584 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
9585 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
9586 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
9587 } else {
9588 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
9589 val);
9590 send_resp(dut, conn, SIGMA_INVALID,
9591 "ErrorCode,Invalid ANQPQuery_ID");
9592 return 0;
9593 }
9594
Ashwini Patild174f2c2017-04-13 16:49:46 +05309595 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
9596 * (Address3 = Wildcard BSSID when sent to not-associated AP;
9597 * if associated, AP BSSID).
9598 */
9599 if (wpa_command(intf, "SET gas_address3 1") < 0) {
9600 send_resp(dut, conn, SIGMA_ERROR,
9601 "ErrorCode,Failed to set gas_address3");
9602 return 0;
9603 }
9604
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309605 if (wpa_command(intf, buf) < 0) {
9606 send_resp(dut, conn, SIGMA_ERROR,
9607 "ErrorCode,Failed to send ANQP query");
9608 return 0;
9609 }
9610
9611 return 1;
9612}
9613
9614
9615static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
9616 struct sigma_conn *conn,
9617 const char *intf,
9618 struct sigma_cmd *cmd)
9619{
9620 const char *val = get_param(cmd, "FrameName");
9621
9622 if (val && strcasecmp(val, "ANQPQuery") == 0)
9623 return mbo_send_anqp_query(dut, conn, intf, cmd);
9624
9625 return 2;
9626}
9627
9628
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009629int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9630 struct sigma_cmd *cmd)
9631{
9632 const char *intf = get_param(cmd, "Interface");
9633 const char *val;
9634 enum send_frame_type frame;
9635 enum send_frame_protection protected;
9636 char buf[100];
9637 unsigned char addr[ETH_ALEN];
9638 int res;
9639
9640 val = get_param(cmd, "program");
9641 if (val == NULL)
9642 val = get_param(cmd, "frame");
9643 if (val && strcasecmp(val, "TDLS") == 0)
9644 return cmd_sta_send_frame_tdls(dut, conn, cmd);
9645 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009646 strcasecmp(val, "HS2-R2") == 0 ||
9647 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009648 return cmd_sta_send_frame_hs2(dut, conn, cmd);
9649 if (val && strcasecmp(val, "VHT") == 0)
9650 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009651 if (val && strcasecmp(val, "HE") == 0)
9652 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009653 if (val && strcasecmp(val, "LOC") == 0)
9654 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009655 if (val && strcasecmp(val, "60GHz") == 0)
9656 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309657 if (val && strcasecmp(val, "MBO") == 0) {
9658 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
9659 if (res != 2)
9660 return res;
9661 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009662
9663 val = get_param(cmd, "TD_DISC");
9664 if (val) {
9665 if (hwaddr_aton(val, addr) < 0)
9666 return -1;
9667 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
9668 if (wpa_command(intf, buf) < 0) {
9669 send_resp(dut, conn, SIGMA_ERROR,
9670 "ErrorCode,Failed to send TDLS discovery");
9671 return 0;
9672 }
9673 return 1;
9674 }
9675
9676 val = get_param(cmd, "TD_Setup");
9677 if (val) {
9678 if (hwaddr_aton(val, addr) < 0)
9679 return -1;
9680 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
9681 if (wpa_command(intf, buf) < 0) {
9682 send_resp(dut, conn, SIGMA_ERROR,
9683 "ErrorCode,Failed to start TDLS setup");
9684 return 0;
9685 }
9686 return 1;
9687 }
9688
9689 val = get_param(cmd, "TD_TearDown");
9690 if (val) {
9691 if (hwaddr_aton(val, addr) < 0)
9692 return -1;
9693 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
9694 if (wpa_command(intf, buf) < 0) {
9695 send_resp(dut, conn, SIGMA_ERROR,
9696 "ErrorCode,Failed to tear down TDLS link");
9697 return 0;
9698 }
9699 return 1;
9700 }
9701
9702 val = get_param(cmd, "TD_ChannelSwitch");
9703 if (val) {
9704 /* TODO */
9705 send_resp(dut, conn, SIGMA_ERROR,
9706 "ErrorCode,TD_ChannelSwitch not yet supported");
9707 return 0;
9708 }
9709
9710 val = get_param(cmd, "TD_NF");
9711 if (val) {
9712 /* TODO */
9713 send_resp(dut, conn, SIGMA_ERROR,
9714 "ErrorCode,TD_NF not yet supported");
9715 return 0;
9716 }
9717
9718 val = get_param(cmd, "PMFFrameType");
9719 if (val == NULL)
9720 val = get_param(cmd, "FrameName");
9721 if (val == NULL)
9722 val = get_param(cmd, "Type");
9723 if (val == NULL)
9724 return -1;
9725 if (strcasecmp(val, "disassoc") == 0)
9726 frame = DISASSOC;
9727 else if (strcasecmp(val, "deauth") == 0)
9728 frame = DEAUTH;
9729 else if (strcasecmp(val, "saquery") == 0)
9730 frame = SAQUERY;
9731 else if (strcasecmp(val, "auth") == 0)
9732 frame = AUTH;
9733 else if (strcasecmp(val, "assocreq") == 0)
9734 frame = ASSOCREQ;
9735 else if (strcasecmp(val, "reassocreq") == 0)
9736 frame = REASSOCREQ;
9737 else if (strcasecmp(val, "neigreq") == 0) {
9738 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
9739
9740 val = get_param(cmd, "ssid");
9741 if (val == NULL)
9742 return -1;
9743
9744 res = send_neighbor_request(dut, intf, val);
9745 if (res) {
9746 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9747 "Failed to send neighbor report request");
9748 return 0;
9749 }
9750
9751 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05309752 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
9753 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009754 sigma_dut_print(dut, DUT_MSG_DEBUG,
9755 "Got Transition Management Query");
9756
Ashwini Patil5acd7382017-04-13 15:55:04 +05309757 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009758 if (res) {
9759 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9760 "Failed to send Transition Management Query");
9761 return 0;
9762 }
9763
9764 return 1;
9765 } else {
9766 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9767 "PMFFrameType");
9768 return 0;
9769 }
9770
9771 val = get_param(cmd, "PMFProtected");
9772 if (val == NULL)
9773 val = get_param(cmd, "Protected");
9774 if (val == NULL)
9775 return -1;
9776 if (strcasecmp(val, "Correct-key") == 0 ||
9777 strcasecmp(val, "CorrectKey") == 0)
9778 protected = CORRECT_KEY;
9779 else if (strcasecmp(val, "IncorrectKey") == 0)
9780 protected = INCORRECT_KEY;
9781 else if (strcasecmp(val, "Unprotected") == 0)
9782 protected = UNPROTECTED;
9783 else {
9784 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9785 "PMFProtected");
9786 return 0;
9787 }
9788
9789 if (protected != UNPROTECTED &&
9790 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
9791 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
9792 "PMFProtected for auth/assocreq/reassocreq");
9793 return 0;
9794 }
9795
9796 if (if_nametoindex("sigmadut") == 0) {
9797 snprintf(buf, sizeof(buf),
9798 "iw dev %s interface add sigmadut type monitor",
9799 get_station_ifname());
9800 if (system(buf) != 0 ||
9801 if_nametoindex("sigmadut") == 0) {
9802 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9803 "monitor interface with '%s'", buf);
9804 return -2;
9805 }
9806 }
9807
9808 if (system("ifconfig sigmadut up") != 0) {
9809 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9810 "monitor interface up");
9811 return -2;
9812 }
9813
9814 return sta_inject_frame(dut, conn, frame, protected, NULL);
9815}
9816
9817
9818static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
9819 struct sigma_conn *conn,
9820 struct sigma_cmd *cmd,
9821 const char *ifname)
9822{
9823 char buf[200];
9824 const char *val;
9825
9826 val = get_param(cmd, "ClearARP");
9827 if (val && atoi(val) == 1) {
9828 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
9829 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9830 if (system(buf) != 0) {
9831 send_resp(dut, conn, SIGMA_ERROR,
9832 "errorCode,Failed to clear ARP cache");
9833 return 0;
9834 }
9835 }
9836
9837 return 1;
9838}
9839
9840
9841int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
9842 struct sigma_cmd *cmd)
9843{
9844 const char *intf = get_param(cmd, "Interface");
9845 const char *val;
9846
9847 if (intf == NULL)
9848 return -1;
9849
9850 val = get_param(cmd, "program");
9851 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009852 strcasecmp(val, "HS2-R2") == 0 ||
9853 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009854 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
9855
9856 return -1;
9857}
9858
9859
9860static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
9861 struct sigma_cmd *cmd)
9862{
9863 const char *intf = get_param(cmd, "Interface");
9864 const char *mac = get_param(cmd, "MAC");
9865
9866 if (intf == NULL || mac == NULL)
9867 return -1;
9868
9869 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
9870 "interface %s to %s", intf, mac);
9871
9872 if (dut->set_macaddr) {
9873 char buf[128];
9874 int res;
9875 if (strcasecmp(mac, "default") == 0) {
9876 res = snprintf(buf, sizeof(buf), "%s",
9877 dut->set_macaddr);
9878 dut->tmp_mac_addr = 0;
9879 } else {
9880 res = snprintf(buf, sizeof(buf), "%s %s",
9881 dut->set_macaddr, mac);
9882 dut->tmp_mac_addr = 1;
9883 }
9884 if (res < 0 || res >= (int) sizeof(buf))
9885 return -1;
9886 if (system(buf) != 0) {
9887 send_resp(dut, conn, SIGMA_ERROR,
9888 "errorCode,Failed to set MAC "
9889 "address");
9890 return 0;
9891 }
9892 return 1;
9893 }
9894
9895 if (strcasecmp(mac, "default") == 0)
9896 return 1;
9897
9898 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9899 "command");
9900 return 0;
9901}
9902
9903
9904static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
9905 struct sigma_conn *conn, const char *intf,
9906 int val)
9907{
9908 char buf[200];
9909 int res;
9910
9911 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
9912 intf, val);
9913 if (res < 0 || res >= (int) sizeof(buf))
9914 return -1;
9915 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9916 if (system(buf) != 0) {
9917 send_resp(dut, conn, SIGMA_ERROR,
9918 "errorCode,Failed to configure offchannel mode");
9919 return 0;
9920 }
9921
9922 return 1;
9923}
9924
9925
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009926static int off_chan_val(enum sec_ch_offset off)
9927{
9928 switch (off) {
9929 case SEC_CH_NO:
9930 return 0;
9931 case SEC_CH_40ABOVE:
9932 return 40;
9933 case SEC_CH_40BELOW:
9934 return -40;
9935 }
9936
9937 return 0;
9938}
9939
9940
9941static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
9942 const char *intf, int off_ch_num,
9943 enum sec_ch_offset sec)
9944{
9945 char buf[200];
9946 int res;
9947
9948 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
9949 intf, off_ch_num);
9950 if (res < 0 || res >= (int) sizeof(buf))
9951 return -1;
9952 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9953 if (system(buf) != 0) {
9954 send_resp(dut, conn, SIGMA_ERROR,
9955 "errorCode,Failed to set offchan");
9956 return 0;
9957 }
9958
9959 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
9960 intf, off_chan_val(sec));
9961 if (res < 0 || res >= (int) sizeof(buf))
9962 return -1;
9963 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9964 if (system(buf) != 0) {
9965 send_resp(dut, conn, SIGMA_ERROR,
9966 "errorCode,Failed to set sec chan offset");
9967 return 0;
9968 }
9969
9970 return 1;
9971}
9972
9973
9974static int tdls_set_offchannel_offset(struct sigma_dut *dut,
9975 struct sigma_conn *conn,
9976 const char *intf, int off_ch_num,
9977 enum sec_ch_offset sec)
9978{
9979 char buf[200];
9980 int res;
9981
9982 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
9983 off_ch_num);
9984 if (res < 0 || res >= (int) sizeof(buf))
9985 return -1;
9986 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9987
9988 if (wpa_command(intf, buf) < 0) {
9989 send_resp(dut, conn, SIGMA_ERROR,
9990 "ErrorCode,Failed to set offchan");
9991 return 0;
9992 }
9993 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
9994 off_chan_val(sec));
9995 if (res < 0 || res >= (int) sizeof(buf))
9996 return -1;
9997
9998 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9999
10000 if (wpa_command(intf, buf) < 0) {
10001 send_resp(dut, conn, SIGMA_ERROR,
10002 "ErrorCode,Failed to set sec chan offset");
10003 return 0;
10004 }
10005
10006 return 1;
10007}
10008
10009
10010static int tdls_set_offchannel_mode(struct sigma_dut *dut,
10011 struct sigma_conn *conn,
10012 const char *intf, int val)
10013{
10014 char buf[200];
10015 int res;
10016
10017 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
10018 val);
10019 if (res < 0 || res >= (int) sizeof(buf))
10020 return -1;
10021 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10022
10023 if (wpa_command(intf, buf) < 0) {
10024 send_resp(dut, conn, SIGMA_ERROR,
10025 "ErrorCode,Failed to configure offchannel mode");
10026 return 0;
10027 }
10028
10029 return 1;
10030}
10031
10032
10033static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
10034 struct sigma_conn *conn,
10035 struct sigma_cmd *cmd)
10036{
10037 const char *val;
10038 enum {
10039 CHSM_NOT_SET,
10040 CHSM_ENABLE,
10041 CHSM_DISABLE,
10042 CHSM_REJREQ,
10043 CHSM_UNSOLRESP
10044 } chsm = CHSM_NOT_SET;
10045 int off_ch_num = -1;
10046 enum sec_ch_offset sec_ch = SEC_CH_NO;
10047 int res;
10048
10049 val = get_param(cmd, "Uapsd");
10050 if (val) {
10051 char buf[100];
10052 if (strcasecmp(val, "Enable") == 0)
10053 snprintf(buf, sizeof(buf), "SET ps 99");
10054 else if (strcasecmp(val, "Disable") == 0)
10055 snprintf(buf, sizeof(buf), "SET ps 98");
10056 else {
10057 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10058 "Unsupported uapsd parameter value");
10059 return 0;
10060 }
10061 if (wpa_command(intf, buf)) {
10062 send_resp(dut, conn, SIGMA_ERROR,
10063 "ErrorCode,Failed to change U-APSD "
10064 "powersave mode");
10065 return 0;
10066 }
10067 }
10068
10069 val = get_param(cmd, "TPKTIMER");
10070 if (val && strcasecmp(val, "DISABLE") == 0) {
10071 if (wpa_command(intf, "SET tdls_testing 0x100")) {
10072 send_resp(dut, conn, SIGMA_ERROR,
10073 "ErrorCode,Failed to enable no TPK "
10074 "expiration test mode");
10075 return 0;
10076 }
10077 dut->no_tpk_expiration = 1;
10078 }
10079
10080 val = get_param(cmd, "ChSwitchMode");
10081 if (val) {
10082 if (strcasecmp(val, "Enable") == 0 ||
10083 strcasecmp(val, "Initiate") == 0)
10084 chsm = CHSM_ENABLE;
10085 else if (strcasecmp(val, "Disable") == 0 ||
10086 strcasecmp(val, "passive") == 0)
10087 chsm = CHSM_DISABLE;
10088 else if (strcasecmp(val, "RejReq") == 0)
10089 chsm = CHSM_REJREQ;
10090 else if (strcasecmp(val, "UnSolResp") == 0)
10091 chsm = CHSM_UNSOLRESP;
10092 else {
10093 send_resp(dut, conn, SIGMA_ERROR,
10094 "ErrorCode,Unknown ChSwitchMode value");
10095 return 0;
10096 }
10097 }
10098
10099 val = get_param(cmd, "OffChNum");
10100 if (val) {
10101 off_ch_num = atoi(val);
10102 if (off_ch_num == 0) {
10103 send_resp(dut, conn, SIGMA_ERROR,
10104 "ErrorCode,Invalid OffChNum");
10105 return 0;
10106 }
10107 }
10108
10109 val = get_param(cmd, "SecChOffset");
10110 if (val) {
10111 if (strcmp(val, "20") == 0)
10112 sec_ch = SEC_CH_NO;
10113 else if (strcasecmp(val, "40above") == 0)
10114 sec_ch = SEC_CH_40ABOVE;
10115 else if (strcasecmp(val, "40below") == 0)
10116 sec_ch = SEC_CH_40BELOW;
10117 else {
10118 send_resp(dut, conn, SIGMA_ERROR,
10119 "ErrorCode,Unknown SecChOffset value");
10120 return 0;
10121 }
10122 }
10123
10124 if (chsm == CHSM_NOT_SET) {
10125 /* no offchannel changes requested */
10126 return 1;
10127 }
10128
10129 if (strcmp(intf, get_main_ifname()) != 0 &&
10130 strcmp(intf, get_station_ifname()) != 0) {
10131 send_resp(dut, conn, SIGMA_ERROR,
10132 "ErrorCode,Unknown interface");
10133 return 0;
10134 }
10135
10136 switch (chsm) {
10137 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030010138 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010139 break;
10140 case CHSM_ENABLE:
10141 if (off_ch_num < 0) {
10142 send_resp(dut, conn, SIGMA_ERROR,
10143 "ErrorCode,Missing OffChNum argument");
10144 return 0;
10145 }
10146 if (wifi_chip_type == DRIVER_WCN) {
10147 res = tdls_set_offchannel_offset(dut, conn, intf,
10148 off_ch_num, sec_ch);
10149 } else {
10150 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10151 sec_ch);
10152 }
10153 if (res != 1)
10154 return res;
10155 if (wifi_chip_type == DRIVER_WCN)
10156 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
10157 else
10158 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
10159 break;
10160 case CHSM_DISABLE:
10161 if (wifi_chip_type == DRIVER_WCN)
10162 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
10163 else
10164 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
10165 break;
10166 case CHSM_REJREQ:
10167 if (wifi_chip_type == DRIVER_WCN)
10168 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
10169 else
10170 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
10171 break;
10172 case CHSM_UNSOLRESP:
10173 if (off_ch_num < 0) {
10174 send_resp(dut, conn, SIGMA_ERROR,
10175 "ErrorCode,Missing OffChNum argument");
10176 return 0;
10177 }
10178 if (wifi_chip_type == DRIVER_WCN) {
10179 res = tdls_set_offchannel_offset(dut, conn, intf,
10180 off_ch_num, sec_ch);
10181 } else {
10182 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10183 sec_ch);
10184 }
10185 if (res != 1)
10186 return res;
10187 if (wifi_chip_type == DRIVER_WCN)
10188 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
10189 else
10190 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
10191 break;
10192 }
10193
10194 return res;
10195}
10196
10197
10198static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
10199 struct sigma_conn *conn,
10200 struct sigma_cmd *cmd)
10201{
10202 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053010203 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010204
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080010205 novap_reset(dut, intf);
10206
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010207 val = get_param(cmd, "nss_mcs_opt");
10208 if (val) {
10209 /* String (nss_operating_mode; mcs_operating_mode) */
10210 int nss, mcs;
10211 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010212 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010213
10214 token = strdup(val);
10215 if (!token)
10216 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010217 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010218 if (!result) {
10219 sigma_dut_print(dut, DUT_MSG_ERROR,
10220 "VHT NSS not specified");
10221 goto failed;
10222 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010223 if (strcasecmp(result, "def") != 0) {
10224 nss = atoi(result);
10225 if (nss == 4)
10226 ath_disable_txbf(dut, intf);
10227 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
10228 intf, nss);
10229 if (system(buf) != 0) {
10230 sigma_dut_print(dut, DUT_MSG_ERROR,
10231 "iwpriv nss failed");
10232 goto failed;
10233 }
10234 }
10235
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010236 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010237 if (!result) {
10238 sigma_dut_print(dut, DUT_MSG_ERROR,
10239 "VHT MCS not specified");
10240 goto failed;
10241 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010242 if (strcasecmp(result, "def") == 0) {
10243 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
10244 intf);
10245 if (system(buf) != 0) {
10246 sigma_dut_print(dut, DUT_MSG_ERROR,
10247 "iwpriv set11NRates failed");
10248 goto failed;
10249 }
10250
10251 } else {
10252 mcs = atoi(result);
10253 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
10254 intf, mcs);
10255 if (system(buf) != 0) {
10256 sigma_dut_print(dut, DUT_MSG_ERROR,
10257 "iwpriv vhtmcs failed");
10258 goto failed;
10259 }
10260 }
10261 /* Channel width gets messed up, fix this */
10262 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
10263 intf, dut->chwidth);
10264 if (system(buf) != 0) {
10265 sigma_dut_print(dut, DUT_MSG_ERROR,
10266 "iwpriv chwidth failed");
10267 }
10268 }
10269
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053010270 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010271 return 1;
10272failed:
10273 free(token);
10274 return 0;
10275}
10276
10277
10278static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
10279 struct sigma_conn *conn,
10280 struct sigma_cmd *cmd)
10281{
10282 switch (get_driver_type()) {
10283 case DRIVER_ATHEROS:
10284 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
10285 default:
10286 send_resp(dut, conn, SIGMA_ERROR,
10287 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
10288 return 0;
10289 }
10290}
10291
10292
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010293static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
10294 struct sigma_conn *conn,
10295 struct sigma_cmd *cmd)
10296{
10297 const char *val;
10298 char *token = NULL, *result;
10299 char buf[60];
10300
10301 val = get_param(cmd, "nss_mcs_opt");
10302 if (val) {
10303 /* String (nss_operating_mode; mcs_operating_mode) */
10304 int nss, mcs, ratecode;
10305 char *saveptr;
10306
10307 token = strdup(val);
10308 if (!token)
10309 return -2;
10310
10311 result = strtok_r(token, ";", &saveptr);
10312 if (!result) {
10313 sigma_dut_print(dut, DUT_MSG_ERROR,
10314 "HE NSS not specified");
10315 goto failed;
10316 }
10317 nss = 1;
10318 if (strcasecmp(result, "def") != 0)
10319 nss = atoi(result);
10320
10321 result = strtok_r(NULL, ";", &saveptr);
10322 if (!result) {
10323 sigma_dut_print(dut, DUT_MSG_ERROR,
10324 "HE MCS not specified");
10325 goto failed;
10326 }
10327 mcs = 7;
10328 if (strcasecmp(result, "def") != 0)
10329 mcs = atoi(result);
10330
Arif Hussain557bf412018-05-25 17:29:36 -070010331 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010332 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070010333 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010334 } else if (nss > 2) {
10335 sigma_dut_print(dut, DUT_MSG_ERROR,
10336 "HE NSS %d not supported", nss);
10337 goto failed;
10338 }
10339
Arif Hussain557bf412018-05-25 17:29:36 -070010340 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
10341 if (system(buf) != 0) {
10342 sigma_dut_print(dut, DUT_MSG_ERROR,
10343 "nss_mcs_opt: iwpriv %s nss %d failed",
10344 intf, nss);
10345 goto failed;
10346 }
Arif Hussainac6c5112018-05-25 17:34:00 -070010347 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070010348
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010349 /* Add the MCS to the ratecode */
10350 if (mcs >= 0 && mcs <= 11) {
10351 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070010352#ifdef NL80211_SUPPORT
10353 if (dut->device_type == STA_testbed) {
10354 enum he_mcs_config mcs_config;
10355 int ret;
10356
10357 if (mcs <= 7)
10358 mcs_config = HE_80_MCS0_7;
10359 else if (mcs <= 9)
10360 mcs_config = HE_80_MCS0_9;
10361 else
10362 mcs_config = HE_80_MCS0_11;
10363 ret = sta_set_he_mcs(dut, intf, mcs_config);
10364 if (ret) {
10365 sigma_dut_print(dut, DUT_MSG_ERROR,
10366 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10367 mcs, mcs_config, ret);
10368 goto failed;
10369 }
10370 }
10371#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010372 } else {
10373 sigma_dut_print(dut, DUT_MSG_ERROR,
10374 "HE MCS %d not supported", mcs);
10375 goto failed;
10376 }
10377 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
10378 intf, ratecode);
10379 if (system(buf) != 0) {
10380 sigma_dut_print(dut, DUT_MSG_ERROR,
10381 "iwpriv setting of 11ax rates failed");
10382 goto failed;
10383 }
10384 free(token);
10385 }
10386
10387 val = get_param(cmd, "GI");
10388 if (val) {
10389 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010390 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010391 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010392 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
10393 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010394 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010395 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
10396 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010397 } else {
10398 send_resp(dut, conn, SIGMA_ERROR,
10399 "errorCode,GI value not supported");
10400 return 0;
10401 }
10402 if (system(buf) != 0) {
10403 send_resp(dut, conn, SIGMA_ERROR,
10404 "errorCode,Failed to set shortgi");
10405 return 0;
10406 }
10407 }
10408
Subhani Shaik8e7a3052018-04-24 14:03:00 -070010409 val = get_param(cmd, "LTF");
10410 if (val) {
10411#ifdef NL80211_SUPPORT
10412 if (strcmp(val, "3.2") == 0) {
10413 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
10414 } if (strcmp(val, "6.4") == 0) {
10415 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
10416 } else if (strcmp(val, "12.8") == 0) {
10417 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
10418 } else {
10419 send_resp(dut, conn, SIGMA_ERROR,
10420 "errorCode, LTF value not supported");
10421 return 0;
10422 }
10423#else /* NL80211_SUPPORT */
10424 sigma_dut_print(dut, DUT_MSG_ERROR,
10425 "LTF cannot be set without NL80211_SUPPORT defined");
10426 return -2;
10427#endif /* NL80211_SUPPORT */
10428 }
10429
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070010430 val = get_param(cmd, "TxSUPPDU");
10431 if (val) {
10432 int set_val = 1;
10433
10434 if (strcasecmp(val, "Enable") == 0)
10435 set_val = 1;
10436 else if (strcasecmp(val, "Disable") == 0)
10437 set_val = 0;
10438
10439 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
10440 send_resp(dut, conn, SIGMA_ERROR,
10441 "ErrorCode,Failed to set Tx SU PPDU config");
10442 return 0;
10443 }
10444 }
10445
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070010446 val = get_param(cmd, "OMCtrl_RxNSS");
10447 if (val) {
10448 /*
10449 * OMCtrl_RxNSS uses the IEEE 802.11 standard values for Nss,
10450 * i.e., 0 for 1Nss, 1 for Nss 2, etc. The driver checks for
10451 * the actual Nss value hence add 1 to the set value.
10452 */
10453 int set_val = atoi(val) + 1;
10454
10455 if (sta_set_he_om_ctrl_nss(dut, intf, set_val)) {
10456 send_resp(dut, conn, SIGMA_ERROR,
10457 "ErrorCode,Failed to set OM ctrl NSS config");
10458 return 0;
10459 }
10460 }
10461
10462 val = get_param(cmd, "OMCtrl_ChnlWidth");
10463 if (val) {
10464 int set_val = atoi(val);
10465
10466 if (sta_set_he_om_ctrl_bw(dut, intf,
10467 (enum qca_wlan_he_om_ctrl_ch_bw)
10468 set_val)) {
10469 send_resp(dut, conn, SIGMA_ERROR,
10470 "ErrorCode,Failed to set OM ctrl BW config");
10471 return 0;
10472 }
10473 }
10474
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080010475 val = get_param(cmd, "Powersave");
10476 if (val) {
10477 char buf[60];
10478
10479 if (strcasecmp(val, "off") == 0) {
10480 snprintf(buf, sizeof(buf),
10481 "iwpriv %s setPower 2", intf);
10482 if (system(buf) != 0) {
10483 sigma_dut_print(dut, DUT_MSG_ERROR,
10484 "iwpriv setPower 2 failed");
10485 return 0;
10486 }
10487 } else if (strcasecmp(val, "on") == 0) {
10488 snprintf(buf, sizeof(buf),
10489 "iwpriv %s setPower 1", intf);
10490 if (system(buf) != 0) {
10491 sigma_dut_print(dut, DUT_MSG_ERROR,
10492 "iwpriv setPower 1 failed");
10493 return 0;
10494 }
10495 } else {
10496 sigma_dut_print(dut, DUT_MSG_ERROR,
10497 "Unsupported Powersave value '%s'",
10498 val);
10499 return -1;
10500 }
10501 }
10502
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010503 return 1;
10504
10505failed:
10506 free(token);
10507 return -2;
10508}
10509
10510
10511static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
10512 struct sigma_conn *conn,
10513 struct sigma_cmd *cmd)
10514{
10515 switch (get_driver_type()) {
10516 case DRIVER_WCN:
10517 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
10518 default:
10519 send_resp(dut, conn, SIGMA_ERROR,
10520 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
10521 return 0;
10522 }
10523}
10524
10525
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010526static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
10527 struct sigma_conn *conn,
10528 struct sigma_cmd *cmd)
10529{
10530 const char *val;
10531
10532 val = get_param(cmd, "powersave");
10533 if (val) {
10534 char buf[60];
10535
10536 if (strcasecmp(val, "off") == 0) {
10537 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
10538 intf);
10539 if (system(buf) != 0) {
10540 sigma_dut_print(dut, DUT_MSG_ERROR,
10541 "iwpriv setPower 2 failed");
10542 return 0;
10543 }
10544 } else if (strcasecmp(val, "on") == 0) {
10545 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
10546 intf);
10547 if (system(buf) != 0) {
10548 sigma_dut_print(dut, DUT_MSG_ERROR,
10549 "iwpriv setPower 1 failed");
10550 return 0;
10551 }
10552 } else {
10553 sigma_dut_print(dut, DUT_MSG_ERROR,
10554 "Unsupported power save config");
10555 return -1;
10556 }
10557 return 1;
10558 }
10559
10560 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
10561
10562 return 0;
10563}
10564
10565
Ashwini Patil5acd7382017-04-13 15:55:04 +053010566static int btm_query_candidate_list(struct sigma_dut *dut,
10567 struct sigma_conn *conn,
10568 struct sigma_cmd *cmd)
10569{
10570 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
10571 int len, ret;
10572 char buf[10];
10573
10574 /*
10575 * Neighbor Report elements format:
10576 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
10577 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
10578 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
10579 */
10580
10581 bssid = get_param(cmd, "Nebor_BSSID");
10582 if (!bssid) {
10583 send_resp(dut, conn, SIGMA_INVALID,
10584 "errorCode,Nebor_BSSID is missing");
10585 return 0;
10586 }
10587
10588 info = get_param(cmd, "Nebor_Bssid_Info");
10589 if (!info) {
10590 sigma_dut_print(dut, DUT_MSG_INFO,
10591 "Using default value for Nebor_Bssid_Info: %s",
10592 DEFAULT_NEIGHBOR_BSSID_INFO);
10593 info = DEFAULT_NEIGHBOR_BSSID_INFO;
10594 }
10595
10596 op_class = get_param(cmd, "Nebor_Op_Class");
10597 if (!op_class) {
10598 send_resp(dut, conn, SIGMA_INVALID,
10599 "errorCode,Nebor_Op_Class is missing");
10600 return 0;
10601 }
10602
10603 ch = get_param(cmd, "Nebor_Op_Ch");
10604 if (!ch) {
10605 send_resp(dut, conn, SIGMA_INVALID,
10606 "errorCode,Nebor_Op_Ch is missing");
10607 return 0;
10608 }
10609
10610 phy_type = get_param(cmd, "Nebor_Phy_Type");
10611 if (!phy_type) {
10612 sigma_dut_print(dut, DUT_MSG_INFO,
10613 "Using default value for Nebor_Phy_Type: %s",
10614 DEFAULT_NEIGHBOR_PHY_TYPE);
10615 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
10616 }
10617
10618 /* Parse optional subelements */
10619 buf[0] = '\0';
10620 pref = get_param(cmd, "Nebor_Pref");
10621 if (pref) {
10622 /* hexdump for preferrence subelement */
10623 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
10624 if (ret < 0 || ret >= (int) sizeof(buf)) {
10625 sigma_dut_print(dut, DUT_MSG_ERROR,
10626 "snprintf failed for optional subelement ret: %d",
10627 ret);
10628 send_resp(dut, conn, SIGMA_ERROR,
10629 "errorCode,snprintf failed for subelement");
10630 return 0;
10631 }
10632 }
10633
10634 if (!dut->btm_query_cand_list) {
10635 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
10636 if (!dut->btm_query_cand_list) {
10637 send_resp(dut, conn, SIGMA_ERROR,
10638 "errorCode,Failed to allocate memory for btm_query_cand_list");
10639 return 0;
10640 }
10641 }
10642
10643 len = strlen(dut->btm_query_cand_list);
10644 ret = snprintf(dut->btm_query_cand_list + len,
10645 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
10646 bssid, info, op_class, ch, phy_type, buf);
10647 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
10648 sigma_dut_print(dut, DUT_MSG_ERROR,
10649 "snprintf failed for neighbor report list ret: %d",
10650 ret);
10651 send_resp(dut, conn, SIGMA_ERROR,
10652 "errorCode,snprintf failed for neighbor report");
10653 free(dut->btm_query_cand_list);
10654 dut->btm_query_cand_list = NULL;
10655 return 0;
10656 }
10657
10658 return 1;
10659}
10660
10661
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010662static int cmd_sta_set_power_save(struct sigma_dut *dut,
10663 struct sigma_conn *conn,
10664 struct sigma_cmd *cmd)
10665{
10666 const char *intf = get_param(cmd, "interface");
10667 const char *prog = get_param(cmd, "program");
10668
10669 if (!intf || !prog)
10670 return -1;
10671
10672 if ((get_driver_type() == DRIVER_WCN) && (strcasecmp(prog, "HE") == 0))
10673 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
10674
10675 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10676 return 0;
10677}
10678
10679
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010680int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
10681 struct sigma_ese_alloc *allocs, int *allocs_size)
10682{
10683 int max_count = *allocs_size;
10684 int count = 0, i;
10685 const char *val;
10686
10687 do {
10688 val = get_param_indexed(cmd, "AllocID", count);
10689 if (val)
10690 count++;
10691 } while (val);
10692
10693 if (count == 0 || count > max_count) {
10694 sigma_dut_print(dut, DUT_MSG_ERROR,
10695 "Invalid number of allocations(%d)", count);
10696 return -1;
10697 }
10698
10699 for (i = 0; i < count; i++) {
10700 val = get_param_indexed(cmd, "PercentBI", i);
10701 if (!val) {
10702 sigma_dut_print(dut, DUT_MSG_ERROR,
10703 "Missing PercentBI parameter at index %d",
10704 i);
10705 return -1;
10706 }
10707 allocs[i].percent_bi = atoi(val);
10708
10709 val = get_param_indexed(cmd, "SrcAID", i);
10710 if (val)
10711 allocs[i].src_aid = strtol(val, NULL, 0);
10712 else
10713 allocs[i].src_aid = ESE_BCAST_AID;
10714
10715 val = get_param_indexed(cmd, "DestAID", i);
10716 if (val)
10717 allocs[i].dst_aid = strtol(val, NULL, 0);
10718 else
10719 allocs[i].dst_aid = ESE_BCAST_AID;
10720
10721 allocs[i].type = ESE_CBAP;
10722 sigma_dut_print(dut, DUT_MSG_INFO,
10723 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
10724 i, allocs[i].percent_bi, allocs[i].src_aid,
10725 allocs[i].dst_aid);
10726 }
10727
10728 *allocs_size = count;
10729 return 0;
10730}
10731
10732
10733static int sta_set_60g_ese(struct sigma_dut *dut, int count,
10734 struct sigma_ese_alloc *allocs)
10735{
10736 switch (get_driver_type()) {
10737#ifdef __linux__
10738 case DRIVER_WIL6210:
10739 if (wil6210_set_ese(dut, count, allocs))
10740 return -1;
10741 return 1;
10742#endif /* __linux__ */
10743 default:
10744 sigma_dut_print(dut, DUT_MSG_ERROR,
10745 "Unsupported sta_set_60g_ese with the current driver");
10746 return -1;
10747 }
10748}
10749
10750
10751static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
10752 struct sigma_conn *conn,
10753 struct sigma_cmd *cmd)
10754{
10755 const char *val;
10756
10757 val = get_param(cmd, "ExtSchIE");
10758 if (val && !strcasecmp(val, "Enable")) {
10759 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
10760 int count = MAX_ESE_ALLOCS;
10761
10762 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
10763 return -1;
10764 return sta_set_60g_ese(dut, count, allocs);
10765 }
10766
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020010767 val = get_param(cmd, "MCS_FixedRate");
10768 if (val) {
10769 int sta_mcs = atoi(val);
10770
10771 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
10772 sta_mcs);
10773 wil6210_set_force_mcs(dut, 1, sta_mcs);
10774
10775 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
10776 }
10777
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010778 send_resp(dut, conn, SIGMA_ERROR,
10779 "errorCode,Invalid sta_set_rfeature(60G)");
10780 return SIGMA_DUT_SUCCESS_STATUS_SENT;
10781}
10782
10783
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010784static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10785 struct sigma_cmd *cmd)
10786{
10787 const char *intf = get_param(cmd, "Interface");
10788 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010789 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010790
10791 if (intf == NULL || prog == NULL)
10792 return -1;
10793
Ashwini Patil5acd7382017-04-13 15:55:04 +053010794 /* BSS Transition candidate list for BTM query */
10795 val = get_param(cmd, "Nebor_BSSID");
10796 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
10797 return 0;
10798
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010799 if (strcasecmp(prog, "TDLS") == 0)
10800 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
10801
10802 if (strcasecmp(prog, "VHT") == 0)
10803 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
10804
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010805 if (strcasecmp(prog, "HE") == 0)
10806 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
10807
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010808 if (strcasecmp(prog, "MBO") == 0) {
10809 val = get_param(cmd, "Cellular_Data_Cap");
10810 if (val &&
10811 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
10812 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053010813
10814 val = get_param(cmd, "Ch_Pref");
10815 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
10816 return 0;
10817
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010818 return 1;
10819 }
10820
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010821 if (strcasecmp(prog, "60GHz") == 0)
10822 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
10823
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010824 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10825 return 0;
10826}
10827
10828
10829static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
10830 struct sigma_cmd *cmd)
10831{
10832 const char *intf = get_param(cmd, "Interface");
10833 const char *mode = get_param(cmd, "Mode");
10834 int res;
10835
10836 if (intf == NULL || mode == NULL)
10837 return -1;
10838
10839 if (strcasecmp(mode, "On") == 0)
10840 res = wpa_command(intf, "SET radio_disabled 0");
10841 else if (strcasecmp(mode, "Off") == 0)
10842 res = wpa_command(intf, "SET radio_disabled 1");
10843 else
10844 return -1;
10845
10846 if (res) {
10847 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10848 "radio mode");
10849 return 0;
10850 }
10851
10852 return 1;
10853}
10854
10855
10856static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
10857 struct sigma_cmd *cmd)
10858{
10859 const char *intf = get_param(cmd, "Interface");
10860 const char *mode = get_param(cmd, "Mode");
10861 int res;
10862
10863 if (intf == NULL || mode == NULL)
10864 return -1;
10865
10866 if (strcasecmp(mode, "On") == 0)
10867 res = set_ps(intf, dut, 1);
10868 else if (strcasecmp(mode, "Off") == 0)
10869 res = set_ps(intf, dut, 0);
10870 else
10871 return -1;
10872
10873 if (res) {
10874 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10875 "power save mode");
10876 return 0;
10877 }
10878
10879 return 1;
10880}
10881
10882
10883static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
10884 struct sigma_cmd *cmd)
10885{
10886 const char *intf = get_param(cmd, "Interface");
10887 const char *val, *bssid;
10888 int res;
10889 char *buf;
10890 size_t buf_len;
10891
10892 val = get_param(cmd, "BSSID_FILTER");
10893 if (val == NULL)
10894 return -1;
10895
10896 bssid = get_param(cmd, "BSSID_List");
10897 if (atoi(val) == 0 || bssid == NULL) {
10898 /* Disable BSSID filter */
10899 if (wpa_command(intf, "SET bssid_filter ")) {
10900 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
10901 "to disable BSSID filter");
10902 return 0;
10903 }
10904
10905 return 1;
10906 }
10907
10908 buf_len = 100 + strlen(bssid);
10909 buf = malloc(buf_len);
10910 if (buf == NULL)
10911 return -1;
10912
10913 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
10914 res = wpa_command(intf, buf);
10915 free(buf);
10916 if (res) {
10917 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
10918 "BSSID filter");
10919 return 0;
10920 }
10921
10922 return 1;
10923}
10924
10925
10926static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
10927 struct sigma_cmd *cmd)
10928{
10929 const char *intf = get_param(cmd, "Interface");
10930 const char *val;
10931
10932 /* TODO: ARP */
10933
10934 val = get_param(cmd, "HS2_CACHE_PROFILE");
10935 if (val && strcasecmp(val, "All") == 0)
10936 hs2_clear_credentials(intf);
10937
10938 return 1;
10939}
10940
10941
10942static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
10943 struct sigma_cmd *cmd)
10944{
10945 const char *intf = get_param(cmd, "Interface");
10946 const char *key_type = get_param(cmd, "KeyType");
10947 char buf[100], resp[200];
10948
10949 if (key_type == NULL)
10950 return -1;
10951
10952 if (strcasecmp(key_type, "GTK") == 0) {
10953 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
10954 strncmp(buf, "FAIL", 4) == 0) {
10955 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10956 "not fetch current GTK");
10957 return 0;
10958 }
10959 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
10960 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10961 return 0;
10962 } else {
10963 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10964 "KeyType");
10965 return 0;
10966 }
10967
10968 return 1;
10969}
10970
10971
10972static int hs2_set_policy(struct sigma_dut *dut)
10973{
10974#ifdef ANDROID
10975 system("ip rule del prio 23000");
10976 if (system("ip rule add from all lookup main prio 23000") != 0) {
10977 sigma_dut_print(dut, DUT_MSG_ERROR,
10978 "Failed to run:ip rule add from all lookup main prio");
10979 return -1;
10980 }
10981 if (system("ip route flush cache") != 0) {
10982 sigma_dut_print(dut, DUT_MSG_ERROR,
10983 "Failed to run ip route flush cache");
10984 return -1;
10985 }
10986 return 1;
10987#else /* ANDROID */
10988 return 0;
10989#endif /* ANDROID */
10990}
10991
10992
10993static int cmd_sta_hs2_associate(struct sigma_dut *dut,
10994 struct sigma_conn *conn,
10995 struct sigma_cmd *cmd)
10996{
10997 const char *intf = get_param(cmd, "Interface");
10998 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030010999 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011000 struct wpa_ctrl *ctrl;
11001 int res;
11002 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
11003 int tries = 0;
11004 int ignore_blacklist = 0;
11005 const char *events[] = {
11006 "CTRL-EVENT-CONNECTED",
11007 "INTERWORKING-BLACKLISTED",
11008 "INTERWORKING-NO-MATCH",
11009 NULL
11010 };
11011
11012 start_sta_mode(dut);
11013
Jouni Malinen439352d2018-09-13 03:42:23 +030011014 if (band) {
11015 if (strcmp(band, "2.4") == 0) {
11016 wpa_command(intf, "SET setband 2G");
11017 } else if (strcmp(band, "5") == 0) {
11018 wpa_command(intf, "SET setband 5G");
11019 } else {
11020 send_resp(dut, conn, SIGMA_ERROR,
11021 "errorCode,Unsupported band");
11022 return 0;
11023 }
11024 }
11025
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011026 blacklisted[0] = '\0';
11027 if (val && atoi(val))
11028 ignore_blacklist = 1;
11029
11030try_again:
11031 ctrl = open_wpa_mon(intf);
11032 if (ctrl == NULL) {
11033 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11034 "wpa_supplicant monitor connection");
11035 return -2;
11036 }
11037
11038 tries++;
11039 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
11040 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
11041 "Interworking connection");
11042 wpa_ctrl_detach(ctrl);
11043 wpa_ctrl_close(ctrl);
11044 return 0;
11045 }
11046
11047 buf[0] = '\0';
11048 while (1) {
11049 char *pos;
11050 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11051 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
11052 if (!pos)
11053 break;
11054 pos += 25;
11055 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
11056 pos);
11057 if (!blacklisted[0])
11058 memcpy(blacklisted, pos, strlen(pos) + 1);
11059 }
11060
11061 if (ignore_blacklist && blacklisted[0]) {
11062 char *end;
11063 end = strchr(blacklisted, ' ');
11064 if (end)
11065 *end = '\0';
11066 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
11067 blacklisted);
11068 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
11069 blacklisted);
11070 if (wpa_command(intf, buf)) {
11071 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
11072 wpa_ctrl_detach(ctrl);
11073 wpa_ctrl_close(ctrl);
11074 return 0;
11075 }
11076 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11077 buf, sizeof(buf));
11078 }
11079
11080 wpa_ctrl_detach(ctrl);
11081 wpa_ctrl_close(ctrl);
11082
11083 if (res < 0) {
11084 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11085 "connect");
11086 return 0;
11087 }
11088
11089 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
11090 strstr(buf, "INTERWORKING-BLACKLISTED")) {
11091 if (tries < 2) {
11092 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
11093 goto try_again;
11094 }
11095 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
11096 "matching credentials found");
11097 return 0;
11098 }
11099
11100 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11101 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11102 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11103 "get current BSSID/SSID");
11104 return 0;
11105 }
11106
11107 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
11108 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11109 hs2_set_policy(dut);
11110 return 0;
11111}
11112
11113
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011114static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
11115 struct sigma_conn *conn,
11116 struct sigma_cmd *cmd)
11117{
11118 const char *intf = get_param(cmd, "Interface");
11119 const char *display = get_param(cmd, "Display");
11120 struct wpa_ctrl *ctrl;
11121 char buf[300], params[400], *pos;
11122 char bssid[20];
11123 int info_avail = 0;
11124 unsigned int old_timeout;
11125 int res;
11126
11127 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
11128 send_resp(dut, conn, SIGMA_ERROR,
11129 "ErrorCode,Could not get current BSSID");
11130 return 0;
11131 }
11132 ctrl = open_wpa_mon(intf);
11133 if (!ctrl) {
11134 sigma_dut_print(dut, DUT_MSG_ERROR,
11135 "Failed to open wpa_supplicant monitor connection");
11136 return -2;
11137 }
11138
11139 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
11140 wpa_command(intf, buf);
11141
11142 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
11143 if (res < 0) {
11144 send_resp(dut, conn, SIGMA_ERROR,
11145 "ErrorCode,Could not complete GAS query");
11146 goto fail;
11147 }
11148
11149 old_timeout = dut->default_timeout;
11150 dut->default_timeout = 2;
11151 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
11152 dut->default_timeout = old_timeout;
11153 if (res < 0)
11154 goto done;
11155 pos = strchr(buf, ' ');
11156 if (!pos)
11157 goto done;
11158 pos++;
11159 pos = strchr(pos, ' ');
11160 if (!pos)
11161 goto done;
11162 pos++;
11163 info_avail = 1;
11164 snprintf(params, sizeof(params), "browser %s", pos);
11165
11166 if (display && strcasecmp(display, "Yes") == 0) {
11167 pid_t pid;
11168
11169 pid = fork();
11170 if (pid < 0) {
11171 perror("fork");
11172 return -1;
11173 }
11174
11175 if (pid == 0) {
11176 run_hs20_osu(dut, params);
11177 exit(0);
11178 }
11179 }
11180
11181done:
11182 snprintf(buf, sizeof(buf), "Info_available,%s",
11183 info_avail ? "Yes" : "No");
11184 send_resp(dut, conn, SIGMA_COMPLETE, buf);
11185fail:
11186 wpa_ctrl_detach(ctrl);
11187 wpa_ctrl_close(ctrl);
11188 return 0;
11189}
11190
11191
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011192static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
11193 struct sigma_conn *conn,
11194 const char *ifname,
11195 struct sigma_cmd *cmd)
11196{
11197 const char *val;
11198 int id;
11199
11200 id = add_cred(ifname);
11201 if (id < 0)
11202 return -2;
11203 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11204
11205 val = get_param(cmd, "prefer");
11206 if (val && atoi(val) > 0)
11207 set_cred(ifname, id, "priority", "1");
11208
11209 val = get_param(cmd, "REALM");
11210 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
11211 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11212 "realm");
11213 return 0;
11214 }
11215
11216 val = get_param(cmd, "HOME_FQDN");
11217 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
11218 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11219 "home_fqdn");
11220 return 0;
11221 }
11222
11223 val = get_param(cmd, "Username");
11224 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
11225 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11226 "username");
11227 return 0;
11228 }
11229
11230 val = get_param(cmd, "Password");
11231 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
11232 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11233 "password");
11234 return 0;
11235 }
11236
11237 val = get_param(cmd, "ROOT_CA");
11238 if (val) {
11239 char fname[200];
11240 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11241#ifdef __linux__
11242 if (!file_exists(fname)) {
11243 char msg[300];
11244 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
11245 "file (%s) not found", fname);
11246 send_resp(dut, conn, SIGMA_ERROR, msg);
11247 return 0;
11248 }
11249#endif /* __linux__ */
11250 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
11251 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11252 "not set root CA");
11253 return 0;
11254 }
11255 }
11256
11257 return 1;
11258}
11259
11260
11261static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
11262{
11263 FILE *in, *out;
11264 char buf[500];
11265 int found = 0;
11266
11267 in = fopen("devdetail.xml", "r");
11268 if (in == NULL)
11269 return -1;
11270 out = fopen("devdetail.xml.tmp", "w");
11271 if (out == NULL) {
11272 fclose(in);
11273 return -1;
11274 }
11275
11276 while (fgets(buf, sizeof(buf), in)) {
11277 char *pos = strstr(buf, "<IMSI>");
11278 if (pos) {
11279 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
11280 imsi);
11281 pos += 6;
11282 *pos = '\0';
11283 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
11284 found++;
11285 } else {
11286 fprintf(out, "%s", buf);
11287 }
11288 }
11289
11290 fclose(out);
11291 fclose(in);
11292 if (found)
11293 rename("devdetail.xml.tmp", "devdetail.xml");
11294 else
11295 unlink("devdetail.xml.tmp");
11296
11297 return 0;
11298}
11299
11300
11301static int sta_add_credential_sim(struct sigma_dut *dut,
11302 struct sigma_conn *conn,
11303 const char *ifname, struct sigma_cmd *cmd)
11304{
11305 const char *val, *imsi = NULL;
11306 int id;
11307 char buf[200];
11308 int res;
11309 const char *pos;
11310 size_t mnc_len;
11311 char plmn_mcc[4];
11312 char plmn_mnc[4];
11313
11314 id = add_cred(ifname);
11315 if (id < 0)
11316 return -2;
11317 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11318
11319 val = get_param(cmd, "prefer");
11320 if (val && atoi(val) > 0)
11321 set_cred(ifname, id, "priority", "1");
11322
11323 val = get_param(cmd, "PLMN_MCC");
11324 if (val == NULL) {
11325 send_resp(dut, conn, SIGMA_ERROR,
11326 "errorCode,Missing PLMN_MCC");
11327 return 0;
11328 }
11329 if (strlen(val) != 3) {
11330 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
11331 return 0;
11332 }
11333 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
11334
11335 val = get_param(cmd, "PLMN_MNC");
11336 if (val == NULL) {
11337 send_resp(dut, conn, SIGMA_ERROR,
11338 "errorCode,Missing PLMN_MNC");
11339 return 0;
11340 }
11341 if (strlen(val) != 2 && strlen(val) != 3) {
11342 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
11343 return 0;
11344 }
11345 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
11346
11347 val = get_param(cmd, "IMSI");
11348 if (val == NULL) {
11349 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
11350 "IMSI");
11351 return 0;
11352 }
11353
11354 imsi = pos = val;
11355
11356 if (strncmp(plmn_mcc, pos, 3) != 0) {
11357 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
11358 return 0;
11359 }
11360 pos += 3;
11361
11362 mnc_len = strlen(plmn_mnc);
11363 if (mnc_len < 2) {
11364 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
11365 return 0;
11366 }
11367
11368 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
11369 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
11370 return 0;
11371 }
11372 pos += mnc_len;
11373
11374 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
11375 if (res < 0 || res >= (int) sizeof(buf))
11376 return -1;
11377 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
11378 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11379 "not set IMSI");
11380 return 0;
11381 }
11382
11383 val = get_param(cmd, "Password");
11384 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
11385 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11386 "not set password");
11387 return 0;
11388 }
11389
Jouni Malinenba630452018-06-22 11:49:59 +030011390 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011391 /*
11392 * Set provisioning_sp for the test cases where SIM/USIM
11393 * provisioning is used.
11394 */
11395 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
11396 "wi-fi.org") < 0) {
11397 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11398 "not set provisioning_sp");
11399 return 0;
11400 }
11401
11402 update_devdetail_imsi(dut, imsi);
11403 }
11404
11405 return 1;
11406}
11407
11408
11409static int sta_add_credential_cert(struct sigma_dut *dut,
11410 struct sigma_conn *conn,
11411 const char *ifname,
11412 struct sigma_cmd *cmd)
11413{
11414 const char *val;
11415 int id;
11416
11417 id = add_cred(ifname);
11418 if (id < 0)
11419 return -2;
11420 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11421
11422 val = get_param(cmd, "prefer");
11423 if (val && atoi(val) > 0)
11424 set_cred(ifname, id, "priority", "1");
11425
11426 val = get_param(cmd, "REALM");
11427 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
11428 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11429 "realm");
11430 return 0;
11431 }
11432
11433 val = get_param(cmd, "HOME_FQDN");
11434 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
11435 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11436 "home_fqdn");
11437 return 0;
11438 }
11439
11440 val = get_param(cmd, "Username");
11441 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
11442 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11443 "username");
11444 return 0;
11445 }
11446
11447 val = get_param(cmd, "clientCertificate");
11448 if (val) {
11449 char fname[200];
11450 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11451#ifdef __linux__
11452 if (!file_exists(fname)) {
11453 char msg[300];
11454 snprintf(msg, sizeof(msg),
11455 "ErrorCode,clientCertificate "
11456 "file (%s) not found", fname);
11457 send_resp(dut, conn, SIGMA_ERROR, msg);
11458 return 0;
11459 }
11460#endif /* __linux__ */
11461 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
11462 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11463 "not set client_cert");
11464 return 0;
11465 }
11466 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
11467 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11468 "not set private_key");
11469 return 0;
11470 }
11471 }
11472
11473 val = get_param(cmd, "ROOT_CA");
11474 if (val) {
11475 char fname[200];
11476 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11477#ifdef __linux__
11478 if (!file_exists(fname)) {
11479 char msg[300];
11480 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
11481 "file (%s) not found", fname);
11482 send_resp(dut, conn, SIGMA_ERROR, msg);
11483 return 0;
11484 }
11485#endif /* __linux__ */
11486 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
11487 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11488 "not set root CA");
11489 return 0;
11490 }
11491 }
11492
11493 return 1;
11494}
11495
11496
11497static int cmd_sta_add_credential(struct sigma_dut *dut,
11498 struct sigma_conn *conn,
11499 struct sigma_cmd *cmd)
11500{
11501 const char *intf = get_param(cmd, "Interface");
11502 const char *type;
11503
11504 start_sta_mode(dut);
11505
11506 type = get_param(cmd, "Type");
11507 if (!type)
11508 return -1;
11509
11510 if (strcasecmp(type, "uname_pwd") == 0)
11511 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
11512
11513 if (strcasecmp(type, "sim") == 0)
11514 return sta_add_credential_sim(dut, conn, intf, cmd);
11515
11516 if (strcasecmp(type, "cert") == 0)
11517 return sta_add_credential_cert(dut, conn, intf, cmd);
11518
11519 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
11520 "type");
11521 return 0;
11522}
11523
11524
11525static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
11526 struct sigma_cmd *cmd)
11527{
11528 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053011529 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011530 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +053011531 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011532 int res;
11533
11534 val = get_param(cmd, "HESSID");
11535 if (val) {
11536 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
11537 if (res < 0 || res >= (int) sizeof(buf))
11538 return -1;
11539 wpa_command(intf, buf);
11540 }
11541
11542 val = get_param(cmd, "ACCS_NET_TYPE");
11543 if (val) {
11544 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
11545 val);
11546 if (res < 0 || res >= (int) sizeof(buf))
11547 return -1;
11548 wpa_command(intf, buf);
11549 }
11550
vamsi krishna89ad8c62017-09-19 12:51:18 +053011551 bssid = get_param(cmd, "Bssid");
11552 ssid = get_param(cmd, "Ssid");
11553
11554 if (ssid) {
11555 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
11556 send_resp(dut, conn, SIGMA_ERROR,
11557 "ErrorCode,Too long SSID");
11558 return 0;
11559 }
11560 ascii2hexstr(ssid, ssid_hex);
11561 }
11562
11563 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
11564 bssid ? " bssid=": "",
11565 bssid ? bssid : "",
11566 ssid ? " ssid " : "",
11567 ssid ? ssid_hex : "");
11568 if (res < 0 || res >= (int) sizeof(buf))
11569 return -1;
11570
11571 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011572 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
11573 "scan");
11574 return 0;
11575 }
11576
11577 return 1;
11578}
11579
11580
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011581static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
11582 struct sigma_cmd *cmd)
11583{
11584 const char *intf = get_param(cmd, "Interface");
11585 const char *bssid;
11586 char buf[4096], *pos;
11587 int freq, chan;
11588 char *ssid;
11589 char resp[100];
11590 int res;
11591 struct wpa_ctrl *ctrl;
11592
11593 bssid = get_param(cmd, "BSSID");
11594 if (!bssid) {
11595 send_resp(dut, conn, SIGMA_INVALID,
11596 "errorCode,BSSID argument is missing");
11597 return 0;
11598 }
11599
11600 ctrl = open_wpa_mon(intf);
11601 if (!ctrl) {
11602 sigma_dut_print(dut, DUT_MSG_ERROR,
11603 "Failed to open wpa_supplicant monitor connection");
11604 return -1;
11605 }
11606
11607 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
11608 send_resp(dut, conn, SIGMA_ERROR,
11609 "errorCode,Could not start scan");
11610 wpa_ctrl_detach(ctrl);
11611 wpa_ctrl_close(ctrl);
11612 return 0;
11613 }
11614
11615 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11616 buf, sizeof(buf));
11617
11618 wpa_ctrl_detach(ctrl);
11619 wpa_ctrl_close(ctrl);
11620
11621 if (res < 0) {
11622 send_resp(dut, conn, SIGMA_ERROR,
11623 "errorCode,Scan did not complete");
11624 return 0;
11625 }
11626
11627 snprintf(buf, sizeof(buf), "BSS %s", bssid);
11628 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
11629 strncmp(buf, "id=", 3) != 0) {
11630 send_resp(dut, conn, SIGMA_ERROR,
11631 "errorCode,Specified BSSID not found");
11632 return 0;
11633 }
11634
11635 pos = strstr(buf, "\nfreq=");
11636 if (!pos) {
11637 send_resp(dut, conn, SIGMA_ERROR,
11638 "errorCode,Channel not found");
11639 return 0;
11640 }
11641 freq = atoi(pos + 6);
11642 chan = freq_to_channel(freq);
11643
11644 pos = strstr(buf, "\nssid=");
11645 if (!pos) {
11646 send_resp(dut, conn, SIGMA_ERROR,
11647 "errorCode,SSID not found");
11648 return 0;
11649 }
11650 ssid = pos + 6;
11651 pos = strchr(ssid, '\n');
11652 if (pos)
11653 *pos = '\0';
11654 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
11655 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11656 return 0;
11657}
11658
11659
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011660static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
11661 struct sigma_cmd *cmd)
11662{
11663#ifdef __linux__
11664 struct timeval tv;
11665 struct tm tm;
11666 time_t t;
11667 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011668 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011669
11670 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
11671
11672 memset(&tm, 0, sizeof(tm));
11673 val = get_param(cmd, "seconds");
11674 if (val)
11675 tm.tm_sec = atoi(val);
11676 val = get_param(cmd, "minutes");
11677 if (val)
11678 tm.tm_min = atoi(val);
11679 val = get_param(cmd, "hours");
11680 if (val)
11681 tm.tm_hour = atoi(val);
11682 val = get_param(cmd, "date");
11683 if (val)
11684 tm.tm_mday = atoi(val);
11685 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011686 if (val) {
11687 v = atoi(val);
11688 if (v < 1 || v > 12) {
11689 send_resp(dut, conn, SIGMA_INVALID,
11690 "errorCode,Invalid month");
11691 return 0;
11692 }
11693 tm.tm_mon = v - 1;
11694 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011695 val = get_param(cmd, "year");
11696 if (val) {
11697 int year = atoi(val);
11698#ifdef ANDROID
11699 if (year > 2035)
11700 year = 2035; /* years beyond 2035 not supported */
11701#endif /* ANDROID */
11702 tm.tm_year = year - 1900;
11703 }
11704 t = mktime(&tm);
11705 if (t == (time_t) -1) {
11706 send_resp(dut, conn, SIGMA_ERROR,
11707 "errorCode,Invalid date or time");
11708 return 0;
11709 }
11710
11711 memset(&tv, 0, sizeof(tv));
11712 tv.tv_sec = t;
11713
11714 if (settimeofday(&tv, NULL) < 0) {
11715 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
11716 strerror(errno));
11717 send_resp(dut, conn, SIGMA_ERROR,
11718 "errorCode,Failed to set time");
11719 return 0;
11720 }
11721
11722 return 1;
11723#endif /* __linux__ */
11724
11725 return -1;
11726}
11727
11728
11729static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
11730 struct sigma_cmd *cmd)
11731{
11732 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011733 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011734 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011735 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011736 int res;
11737 struct wpa_ctrl *ctrl;
11738
11739 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011740 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011741
11742 val = get_param(cmd, "ProdESSAssoc");
11743 if (val)
11744 prod_ess_assoc = atoi(val);
11745
11746 kill_dhcp_client(dut, intf);
11747 if (start_dhcp_client(dut, intf) < 0)
11748 return -2;
11749
11750 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
11751 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11752 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011753 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011754 prod_ess_assoc ? "" : "-N",
11755 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011756 name ? "'" : "",
11757 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
11758 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011759
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053011760 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011761 if (run_hs20_osu(dut, buf) < 0) {
11762 FILE *f;
11763
11764 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
11765
11766 f = fopen("hs20-osu-client.res", "r");
11767 if (f) {
11768 char resp[400], res[300], *pos;
11769 if (!fgets(res, sizeof(res), f))
11770 res[0] = '\0';
11771 pos = strchr(res, '\n');
11772 if (pos)
11773 *pos = '\0';
11774 fclose(f);
11775 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
11776 res);
11777 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
11778 if (system(resp) != 0) {
11779 }
11780 snprintf(resp, sizeof(resp),
11781 "SSID,,BSSID,,failureReason,%s", res);
11782 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11783 return 0;
11784 }
11785
11786 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11787 return 0;
11788 }
11789
11790 if (!prod_ess_assoc)
11791 goto report;
11792
11793 ctrl = open_wpa_mon(intf);
11794 if (ctrl == NULL) {
11795 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11796 "wpa_supplicant monitor connection");
11797 return -1;
11798 }
11799
11800 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11801 buf, sizeof(buf));
11802
11803 wpa_ctrl_detach(ctrl);
11804 wpa_ctrl_close(ctrl);
11805
11806 if (res < 0) {
11807 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
11808 "network after OSU");
11809 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11810 return 0;
11811 }
11812
11813report:
11814 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11815 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11816 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
11817 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11818 return 0;
11819 }
11820
11821 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
11822 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011823 return 0;
11824}
11825
11826
11827static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
11828 struct sigma_cmd *cmd)
11829{
11830 const char *val;
11831 int timeout = 120;
11832
11833 val = get_param(cmd, "PolicyUpdate");
11834 if (val == NULL || atoi(val) == 0)
11835 return 1; /* No operation requested */
11836
11837 val = get_param(cmd, "Timeout");
11838 if (val)
11839 timeout = atoi(val);
11840
11841 if (timeout) {
11842 /* TODO: time out the command and return
11843 * PolicyUpdateStatus,TIMEOUT if needed. */
11844 }
11845
11846 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
11847 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11848 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
11849 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
11850 return 0;
11851 }
11852
11853 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
11854 return 0;
11855}
11856
11857
11858static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
11859 struct sigma_cmd *cmd)
11860{
11861 struct wpa_ctrl *ctrl;
11862 const char *intf = get_param(cmd, "Interface");
11863 const char *bssid = get_param(cmd, "Bssid");
11864 const char *ssid = get_param(cmd, "SSID");
11865 const char *security = get_param(cmd, "Security");
11866 const char *passphrase = get_param(cmd, "Passphrase");
11867 const char *pin = get_param(cmd, "PIN");
11868 char buf[1000];
11869 char ssid_hex[200], passphrase_hex[200];
11870 const char *keymgmt, *cipher;
11871
11872 if (intf == NULL)
11873 intf = get_main_ifname();
11874
11875 if (!bssid) {
11876 send_resp(dut, conn, SIGMA_ERROR,
11877 "ErrorCode,Missing Bssid argument");
11878 return 0;
11879 }
11880
11881 if (!ssid) {
11882 send_resp(dut, conn, SIGMA_ERROR,
11883 "ErrorCode,Missing SSID argument");
11884 return 0;
11885 }
11886
11887 if (!security) {
11888 send_resp(dut, conn, SIGMA_ERROR,
11889 "ErrorCode,Missing Security argument");
11890 return 0;
11891 }
11892
11893 if (!passphrase) {
11894 send_resp(dut, conn, SIGMA_ERROR,
11895 "ErrorCode,Missing Passphrase argument");
11896 return 0;
11897 }
11898
11899 if (!pin) {
11900 send_resp(dut, conn, SIGMA_ERROR,
11901 "ErrorCode,Missing PIN argument");
11902 return 0;
11903 }
11904
vamsi krishna8c9c1562017-05-12 15:51:46 +053011905 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
11906 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011907 send_resp(dut, conn, SIGMA_ERROR,
11908 "ErrorCode,Too long SSID/passphrase");
11909 return 0;
11910 }
11911
11912 ctrl = open_wpa_mon(intf);
11913 if (ctrl == NULL) {
11914 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11915 "wpa_supplicant monitor connection");
11916 return -2;
11917 }
11918
11919 if (strcasecmp(security, "wpa2-psk") == 0) {
11920 keymgmt = "WPA2PSK";
11921 cipher = "CCMP";
11922 } else {
11923 wpa_ctrl_detach(ctrl);
11924 wpa_ctrl_close(ctrl);
11925 send_resp(dut, conn, SIGMA_ERROR,
11926 "ErrorCode,Unsupported Security value");
11927 return 0;
11928 }
11929
11930 ascii2hexstr(ssid, ssid_hex);
11931 ascii2hexstr(passphrase, passphrase_hex);
11932 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
11933 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
11934
11935 if (wpa_command(intf, buf) < 0) {
11936 wpa_ctrl_detach(ctrl);
11937 wpa_ctrl_close(ctrl);
11938 send_resp(dut, conn, SIGMA_ERROR,
11939 "ErrorCode,Failed to start registrar");
11940 return 0;
11941 }
11942
11943 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
11944 dut->er_oper_performed = 1;
11945
11946 return wps_connection_event(dut, conn, ctrl, intf, 0);
11947}
11948
11949
11950static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
11951 struct sigma_conn *conn,
11952 struct sigma_cmd *cmd)
11953{
11954 struct wpa_ctrl *ctrl;
11955 const char *intf = get_param(cmd, "Interface");
11956 const char *bssid = get_param(cmd, "Bssid");
11957 char buf[100];
11958
11959 if (!bssid) {
11960 send_resp(dut, conn, SIGMA_ERROR,
11961 "ErrorCode,Missing Bssid argument");
11962 return 0;
11963 }
11964
11965 ctrl = open_wpa_mon(intf);
11966 if (ctrl == NULL) {
11967 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11968 "wpa_supplicant monitor connection");
11969 return -2;
11970 }
11971
11972 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
11973
11974 if (wpa_command(intf, buf) < 0) {
11975 wpa_ctrl_detach(ctrl);
11976 wpa_ctrl_close(ctrl);
11977 send_resp(dut, conn, SIGMA_ERROR,
11978 "ErrorCode,Failed to start registrar");
11979 return 0;
11980 }
11981
11982 return wps_connection_event(dut, conn, ctrl, intf, 0);
11983}
11984
11985
vamsi krishna9b144002017-09-20 13:28:13 +053011986static int cmd_start_wps_registration(struct sigma_dut *dut,
11987 struct sigma_conn *conn,
11988 struct sigma_cmd *cmd)
11989{
11990 struct wpa_ctrl *ctrl;
11991 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020011992 const char *network_mode = get_param(cmd, "network_mode");
vamsi krishna9b144002017-09-20 13:28:13 +053011993 const char *role, *method;
11994 int res;
11995 char buf[256];
11996 const char *events[] = {
11997 "CTRL-EVENT-CONNECTED",
11998 "WPS-OVERLAP-DETECTED",
11999 "WPS-TIMEOUT",
12000 "WPS-FAIL",
12001 NULL
12002 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012003 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053012004
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012005 /* 60G WPS tests do not pass Interface parameter */
12006 if (!intf)
12007 intf = get_main_ifname();
12008
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012009 if (dut->band == WPS_BAND_60G && network_mode &&
12010 strcasecmp(network_mode, "PBSS") == 0) {
12011 sigma_dut_print(dut, DUT_MSG_DEBUG,
12012 "Set PBSS network mode, network id %d", id);
12013 if (set_network(get_station_ifname(), id, "pbss", "1") < 0)
12014 return -2;
12015 }
12016
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012017 if (dut->force_rsn_ie) {
12018 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
12019 dut->force_rsn_ie);
12020 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
12021 sigma_dut_print(dut, DUT_MSG_INFO,
12022 "Failed to force RSN_IE");
12023 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
12024 }
12025 }
12026
vamsi krishna9b144002017-09-20 13:28:13 +053012027 ctrl = open_wpa_mon(intf);
12028 if (!ctrl) {
12029 sigma_dut_print(dut, DUT_MSG_ERROR,
12030 "Failed to open wpa_supplicant monitor connection");
12031 return -2;
12032 }
12033
12034 role = get_param(cmd, "WpsRole");
12035 if (!role) {
12036 send_resp(dut, conn, SIGMA_INVALID,
12037 "ErrorCode,WpsRole not provided");
12038 goto fail;
12039 }
12040
12041 if (strcasecmp(role, "Enrollee") == 0) {
12042 method = get_param(cmd, "WpsConfigMethod");
12043 if (!method) {
12044 send_resp(dut, conn, SIGMA_INVALID,
12045 "ErrorCode,WpsConfigMethod not provided");
12046 goto fail;
12047 }
12048 if (strcasecmp(method, "PBC") == 0) {
12049 if (wpa_command(intf, "WPS_PBC") < 0) {
12050 send_resp(dut, conn, SIGMA_ERROR,
12051 "ErrorCode,Failed to enable PBC");
12052 goto fail;
12053 }
12054 } else {
12055 /* TODO: PIN method */
12056 send_resp(dut, conn, SIGMA_ERROR,
12057 "ErrorCode,Unsupported WpsConfigMethod value");
12058 goto fail;
12059 }
12060 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12061 if (res < 0) {
12062 send_resp(dut, conn, SIGMA_ERROR,
12063 "ErrorCode,WPS connection did not complete");
12064 goto fail;
12065 }
12066 if (strstr(buf, "WPS-TIMEOUT")) {
12067 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
12068 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
12069 send_resp(dut, conn, SIGMA_ERROR,
12070 "ErrorCode,OverlapSession");
12071 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
12072 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
12073 } else {
12074 send_resp(dut, conn, SIGMA_ERROR,
12075 "ErrorCode,WPS operation failed");
12076 }
12077 } else {
12078 /* TODO: Registrar role */
12079 send_resp(dut, conn, SIGMA_ERROR,
12080 "ErrorCode,Unsupported WpsRole value");
12081 }
12082
12083fail:
12084 wpa_ctrl_detach(ctrl);
12085 wpa_ctrl_close(ctrl);
12086 return 0;
12087}
12088
12089
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012090static int req_intf(struct sigma_cmd *cmd)
12091{
12092 return get_param(cmd, "interface") == NULL ? -1 : 0;
12093}
12094
12095
12096void sta_register_cmds(void)
12097{
12098 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
12099 cmd_sta_get_ip_config);
12100 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
12101 cmd_sta_set_ip_config);
12102 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
12103 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
12104 cmd_sta_get_mac_address);
12105 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
12106 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
12107 cmd_sta_verify_ip_connection);
12108 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
12109 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
12110 cmd_sta_set_encryption);
12111 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
12112 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
12113 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
12114 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
12115 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
12116 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
12117 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
12118 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
12119 cmd_sta_set_eapakaprime);
12120 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
12121 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
12122 /* TODO: sta_set_ibss */
12123 /* TODO: sta_set_mode */
12124 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
12125 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
12126 /* TODO: sta_up_load */
12127 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
12128 cmd_sta_preset_testparameters);
12129 /* TODO: sta_set_system */
12130 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
12131 /* TODO: sta_set_rifs_test */
12132 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
12133 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
12134 /* TODO: sta_send_coexist_mgmt */
12135 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
12136 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
12137 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
12138 sigma_dut_reg_cmd("sta_reset_default", req_intf,
12139 cmd_sta_reset_default);
12140 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
12141 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
12142 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
12143 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
12144 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
12145 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
12146 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
12147 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
12148 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
12149 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012150 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
12151 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012152 sigma_dut_reg_cmd("sta_add_credential", req_intf,
12153 cmd_sta_add_credential);
12154 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012155 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012156 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
12157 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
12158 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
12159 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
12160 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
12161 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030012162 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012163 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
12164 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012165 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053012166 cmd_start_wps_registration);
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012167 sigma_dut_reg_cmd("sta_set_power_save", req_intf,
12168 cmd_sta_set_power_save);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012169}