blob: 136a291c1ad93bc2b66c43d9404b99ce97d6a266 [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;
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005156 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005157 }
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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005168 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005169 }
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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005179 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005180 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005191 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02005192 }
5193 }
5194
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005195 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005196}
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005211 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005212 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005225 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005226 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005238 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02005239 }
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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005248 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005249 }
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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005256 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005257 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005262 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005263 }
5264 } else if (val) {
5265 sigma_dut_print(dut, DUT_MSG_ERROR,
5266 "Requested Security %s is not supported on 60GHz",
5267 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005268 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005269 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005276 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005277 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005281 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005282 }
5283 } else if (val) {
5284 sigma_dut_print(dut, DUT_MSG_ERROR,
5285 "Requested Encrypt %s is not supported on 60 GHz",
5286 val);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005287 return INVALID_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005288 }
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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005294 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005295 }
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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005312 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005313 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005318 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005319 }
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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005329 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005330 }
5331
5332 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5333
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005334 return SUCCESS_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005335}
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)
Jouni Malinen0e29cf22019-02-19 01:13:21 +02005535 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005536 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);
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007028 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarc2a5bb12018-12-23 16:12:06 +02007029 }
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");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02007034 return ERROR_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +02007035 }
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);
Alexei Avshalom Lazar66bb9972018-12-18 16:01:43 +02007960 /* sta_set_wireless in WPS program is only used for 60G */
7961 if (is_60g_sigma_dut(dut))
7962 return sta_set_wireless_60g(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007963 send_resp(dut, conn, SIGMA_ERROR,
7964 "ErrorCode,Program value not supported");
7965 } else {
7966 send_resp(dut, conn, SIGMA_ERROR,
7967 "ErrorCode,Program argument not available");
7968 }
7969
7970 return 0;
7971}
7972
7973
7974static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
7975 int tid)
7976{
7977 char buf[100];
7978 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
7979
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05307980 if (tid < 0 ||
7981 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
7982 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
7983 return;
7984 }
7985
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007986 /*
7987 * Two ways to ensure that addba request with a
7988 * non zero TID could be sent out. EV 117296
7989 */
7990 snprintf(buf, sizeof(buf),
7991 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
7992 tid);
7993 if (system(buf) != 0) {
7994 sigma_dut_print(dut, DUT_MSG_ERROR,
7995 "Ping did not send out");
7996 }
7997
7998 snprintf(buf, sizeof(buf),
7999 "iwconfig %s | grep Access | awk '{print $6}' > %s",
8000 intf, VI_QOS_TMP_FILE);
8001 if (system(buf) != 0)
8002 return;
8003
8004 snprintf(buf, sizeof(buf),
8005 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
8006 intf, VI_QOS_TMP_FILE);
8007 if (system(buf) != 0)
8008 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
8009
8010 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
8011 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
8012 if (system(buf) != 0) {
8013 sigma_dut_print(dut, DUT_MSG_ERROR,
8014 "VI_QOS_TEMP_FILE generation error failed");
8015 }
8016 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8017 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8018 if (system(buf) != 0) {
8019 sigma_dut_print(dut, DUT_MSG_ERROR,
8020 "VI_QOS_FILE generation failed");
8021 }
8022
8023 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
8024 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
8025 if (system(buf) != 0) {
8026 sigma_dut_print(dut, DUT_MSG_ERROR,
8027 "VI_QOS_FILE generation failed");
8028 }
8029
8030 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
8031 if (system(buf) != 0) {
8032 }
8033}
8034
8035
8036static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8037 struct sigma_cmd *cmd)
8038{
8039 const char *intf = get_param(cmd, "Interface");
8040 const char *val;
8041 int tid = 0;
8042 char buf[100];
8043
8044 val = get_param(cmd, "TID");
8045 if (val) {
8046 tid = atoi(val);
8047 if (tid)
8048 ath_sta_inject_frame(dut, intf, tid);
8049 }
8050
8051 /* Command sequence for ADDBA request on Peregrine based devices */
8052 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
8053 if (system(buf) != 0) {
8054 sigma_dut_print(dut, DUT_MSG_ERROR,
8055 "iwpriv setaddbaoper failed");
8056 }
8057
8058 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
8059 if (system(buf) != 0) {
8060 sigma_dut_print(dut, DUT_MSG_ERROR,
8061 "wifitool senddelba failed");
8062 }
8063
8064 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
8065 if (system(buf) != 0) {
8066 sigma_dut_print(dut, DUT_MSG_ERROR,
8067 "wifitool sendaddba failed");
8068 }
8069
8070 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8071
8072 return 1;
8073}
8074
8075
Lior David9981b512017-01-20 13:16:40 +02008076#ifdef __linux__
8077
8078static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
8079 int agg_size)
8080{
8081 char dir[128], buf[128];
8082 FILE *f;
8083 regex_t re;
8084 regmatch_t m[2];
8085 int rc, ret = -1, vring_id, found;
8086
8087 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
8088 sigma_dut_print(dut, DUT_MSG_ERROR,
8089 "failed to get wil6210 debugfs dir");
8090 return -1;
8091 }
8092
8093 snprintf(buf, sizeof(buf), "%s/vrings", dir);
8094 f = fopen(buf, "r");
8095 if (!f) {
8096 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008097 /* newer wil6210 driver renamed file to "rings" */
8098 snprintf(buf, sizeof(buf), "%s/rings", dir);
8099 f = fopen(buf, "r");
8100 if (!f) {
8101 sigma_dut_print(dut, DUT_MSG_ERROR,
8102 "failed to open: %s", buf);
8103 return -1;
8104 }
Lior David9981b512017-01-20 13:16:40 +02008105 }
8106
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02008107 /* can be either VRING tx... or RING... */
8108 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02008109 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
8110 goto out;
8111 }
8112
8113 /* find TX VRING for the mac address */
8114 found = 0;
8115 while (fgets(buf, sizeof(buf), f)) {
8116 if (strcasestr(buf, dest_mac)) {
8117 found = 1;
8118 break;
8119 }
8120 }
8121
8122 if (!found) {
8123 sigma_dut_print(dut, DUT_MSG_ERROR,
8124 "no TX VRING for %s", dest_mac);
8125 goto out;
8126 }
8127
8128 /* extract VRING ID, "VRING tx_<id> = {" */
8129 if (!fgets(buf, sizeof(buf), f)) {
8130 sigma_dut_print(dut, DUT_MSG_ERROR,
8131 "no VRING start line for %s", dest_mac);
8132 goto out;
8133 }
8134
8135 rc = regexec(&re, buf, 2, m, 0);
8136 regfree(&re);
8137 if (rc || m[1].rm_so < 0) {
8138 sigma_dut_print(dut, DUT_MSG_ERROR,
8139 "no VRING TX ID for %s", dest_mac);
8140 goto out;
8141 }
8142 buf[m[1].rm_eo] = 0;
8143 vring_id = atoi(&buf[m[1].rm_so]);
8144
8145 /* send the addba command */
8146 fclose(f);
8147 snprintf(buf, sizeof(buf), "%s/back", dir);
8148 f = fopen(buf, "w");
8149 if (!f) {
8150 sigma_dut_print(dut, DUT_MSG_ERROR,
8151 "failed to open: %s", buf);
8152 return -1;
8153 }
8154
8155 fprintf(f, "add %d %d\n", vring_id, agg_size);
8156
8157 ret = 0;
8158
8159out:
8160 fclose(f);
8161
8162 return ret;
8163}
8164
8165
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008166int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8167 struct sigma_cmd *cmd, const char *mac_param)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008168{
8169 const char *val;
8170 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008171
8172 val = get_param(cmd, "TID");
8173 if (val) {
8174 tid = atoi(val);
8175 if (tid != 0) {
8176 sigma_dut_print(dut, DUT_MSG_ERROR,
8177 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
8178 tid);
8179 }
8180 }
8181
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008182 val = get_param(cmd, mac_param);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008183 if (!val) {
8184 sigma_dut_print(dut, DUT_MSG_ERROR,
8185 "Currently not supporting addba for 60G without Dest_mac");
Jouni Malinen0e29cf22019-02-19 01:13:21 +02008186 return ERROR_SEND_STATUS;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008187 }
8188
Lior David9981b512017-01-20 13:16:40 +02008189 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008190 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008191
8192 return 1;
8193}
8194
Lior David9981b512017-01-20 13:16:40 +02008195#endif /* __linux__ */
8196
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008197
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008198static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8199 struct sigma_cmd *cmd)
8200{
8201#ifdef NL80211_SUPPORT
8202 const char *intf = get_param(cmd, "Interface");
8203 const char *val;
8204 int tid = -1;
8205 int bufsize = 64;
8206 struct nl_msg *msg;
8207 int ret = 0;
8208 struct nlattr *params;
8209 int ifindex;
8210
8211 val = get_param(cmd, "TID");
8212 if (val)
8213 tid = atoi(val);
8214
8215 if (tid == -1) {
8216 send_resp(dut, conn, SIGMA_ERROR,
8217 "ErrorCode,sta_send_addba tid invalid");
8218 return 0;
8219 }
8220
8221 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
8222
8223 ifindex = if_nametoindex(intf);
8224 if (ifindex == 0) {
8225 sigma_dut_print(dut, DUT_MSG_ERROR,
8226 "%s: Index for interface %s failed",
8227 __func__, intf);
8228 send_resp(dut, conn, SIGMA_ERROR,
8229 "ErrorCode,sta_send_addba interface invalid");
8230 return 0;
8231 }
8232
8233 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
8234 NL80211_CMD_VENDOR)) ||
8235 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
8236 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
8237 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
8238 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
8239 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
8240 nla_put_u8(msg,
8241 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
8242 QCA_WLAN_ADD_BA) ||
8243 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
8244 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07008245 nla_put_u16(msg,
8246 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
8247 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008248 sigma_dut_print(dut, DUT_MSG_ERROR,
8249 "%s: err in adding vendor_cmd and vendor_data",
8250 __func__);
8251 nlmsg_free(msg);
8252 send_resp(dut, conn, SIGMA_ERROR,
8253 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
8254 return 0;
8255 }
8256 nla_nest_end(msg, params);
8257
8258 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
8259 if (ret) {
8260 sigma_dut_print(dut, DUT_MSG_ERROR,
8261 "%s: err in send_and_recv_msgs, ret=%d",
8262 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05308263 if (ret == -EOPNOTSUPP)
8264 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008265 send_resp(dut, conn, SIGMA_ERROR,
8266 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
8267 return 0;
8268 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008269#else /* NL80211_SUPPORT */
8270 sigma_dut_print(dut, DUT_MSG_ERROR,
8271 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008272#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05308273
8274 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008275}
8276
8277
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008278static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
8279 struct sigma_cmd *cmd)
8280{
8281 switch (get_driver_type()) {
8282 case DRIVER_ATHEROS:
8283 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08008284 case DRIVER_WCN:
8285 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02008286#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008287 case DRIVER_WIL6210:
Alexei Avshalom Lazar79fa3fe2018-12-24 15:43:33 +02008288 return send_addba_60g(dut, conn, cmd, "Dest_mac");
Lior David9981b512017-01-20 13:16:40 +02008289#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008290 default:
8291 /*
8292 * There is no driver specific implementation for other drivers.
8293 * Ignore the command and report COMPLETE since the following
8294 * throughput test operation will end up sending ADDBA anyway.
8295 */
8296 return 1;
8297 }
8298}
8299
8300
8301int inject_eth_frame(int s, const void *data, size_t len,
8302 unsigned short ethtype, char *dst, char *src)
8303{
8304 struct iovec iov[4] = {
8305 {
8306 .iov_base = dst,
8307 .iov_len = ETH_ALEN,
8308 },
8309 {
8310 .iov_base = src,
8311 .iov_len = ETH_ALEN,
8312 },
8313 {
8314 .iov_base = &ethtype,
8315 .iov_len = sizeof(unsigned short),
8316 },
8317 {
8318 .iov_base = (void *) data,
8319 .iov_len = len,
8320 }
8321 };
8322 struct msghdr msg = {
8323 .msg_name = NULL,
8324 .msg_namelen = 0,
8325 .msg_iov = iov,
8326 .msg_iovlen = 4,
8327 .msg_control = NULL,
8328 .msg_controllen = 0,
8329 .msg_flags = 0,
8330 };
8331
8332 return sendmsg(s, &msg, 0);
8333}
8334
8335#if defined(__linux__) || defined(__QNXNTO__)
8336
8337int inject_frame(int s, const void *data, size_t len, int encrypt)
8338{
8339#define IEEE80211_RADIOTAP_F_WEP 0x04
8340#define IEEE80211_RADIOTAP_F_FRAG 0x08
8341 unsigned char rtap_hdr[] = {
8342 0x00, 0x00, /* radiotap version */
8343 0x0e, 0x00, /* radiotap length */
8344 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
8345 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
8346 0x00, /* padding */
8347 0x00, 0x00, /* RX and TX flags to indicate that */
8348 0x00, 0x00, /* this is the injected frame directly */
8349 };
8350 struct iovec iov[2] = {
8351 {
8352 .iov_base = &rtap_hdr,
8353 .iov_len = sizeof(rtap_hdr),
8354 },
8355 {
8356 .iov_base = (void *) data,
8357 .iov_len = len,
8358 }
8359 };
8360 struct msghdr msg = {
8361 .msg_name = NULL,
8362 .msg_namelen = 0,
8363 .msg_iov = iov,
8364 .msg_iovlen = 2,
8365 .msg_control = NULL,
8366 .msg_controllen = 0,
8367 .msg_flags = 0,
8368 };
8369
8370 if (encrypt)
8371 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
8372
8373 return sendmsg(s, &msg, 0);
8374}
8375
8376
8377int open_monitor(const char *ifname)
8378{
8379#ifdef __QNXNTO__
8380 struct sockaddr_dl ll;
8381 int s;
8382
8383 memset(&ll, 0, sizeof(ll));
8384 ll.sdl_family = AF_LINK;
8385 ll.sdl_index = if_nametoindex(ifname);
8386 if (ll.sdl_index == 0) {
8387 perror("if_nametoindex");
8388 return -1;
8389 }
8390 s = socket(PF_INET, SOCK_RAW, 0);
8391#else /* __QNXNTO__ */
8392 struct sockaddr_ll ll;
8393 int s;
8394
8395 memset(&ll, 0, sizeof(ll));
8396 ll.sll_family = AF_PACKET;
8397 ll.sll_ifindex = if_nametoindex(ifname);
8398 if (ll.sll_ifindex == 0) {
8399 perror("if_nametoindex");
8400 return -1;
8401 }
8402 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
8403#endif /* __QNXNTO__ */
8404 if (s < 0) {
8405 perror("socket[PF_PACKET,SOCK_RAW]");
8406 return -1;
8407 }
8408
8409 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
8410 perror("monitor socket bind");
8411 close(s);
8412 return -1;
8413 }
8414
8415 return s;
8416}
8417
8418
8419static int hex2num(char c)
8420{
8421 if (c >= '0' && c <= '9')
8422 return c - '0';
8423 if (c >= 'a' && c <= 'f')
8424 return c - 'a' + 10;
8425 if (c >= 'A' && c <= 'F')
8426 return c - 'A' + 10;
8427 return -1;
8428}
8429
8430
8431int hwaddr_aton(const char *txt, unsigned char *addr)
8432{
8433 int i;
8434
8435 for (i = 0; i < 6; i++) {
8436 int a, b;
8437
8438 a = hex2num(*txt++);
8439 if (a < 0)
8440 return -1;
8441 b = hex2num(*txt++);
8442 if (b < 0)
8443 return -1;
8444 *addr++ = (a << 4) | b;
8445 if (i < 5 && *txt++ != ':')
8446 return -1;
8447 }
8448
8449 return 0;
8450}
8451
8452#endif /* defined(__linux__) || defined(__QNXNTO__) */
8453
8454enum send_frame_type {
8455 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
8456};
8457enum send_frame_protection {
8458 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8459};
8460
8461
8462static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8463 enum send_frame_type frame,
8464 enum send_frame_protection protected,
8465 const char *dest)
8466{
8467#ifdef __linux__
8468 unsigned char buf[1000], *pos;
8469 int s, res;
8470 char bssid[20], addr[20];
8471 char result[32], ssid[100];
8472 size_t ssid_len;
8473
8474 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
8475 sizeof(result)) < 0 ||
8476 strncmp(result, "COMPLETED", 9) != 0) {
8477 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
8478 return 0;
8479 }
8480
8481 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
8482 < 0) {
8483 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8484 "current BSSID");
8485 return 0;
8486 }
8487
8488 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
8489 < 0) {
8490 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8491 "own MAC address");
8492 return 0;
8493 }
8494
8495 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
8496 < 0) {
8497 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8498 "current SSID");
8499 return 0;
8500 }
8501 ssid_len = strlen(ssid);
8502
8503 pos = buf;
8504
8505 /* Frame Control */
8506 switch (frame) {
8507 case DISASSOC:
8508 *pos++ = 0xa0;
8509 break;
8510 case DEAUTH:
8511 *pos++ = 0xc0;
8512 break;
8513 case SAQUERY:
8514 *pos++ = 0xd0;
8515 break;
8516 case AUTH:
8517 *pos++ = 0xb0;
8518 break;
8519 case ASSOCREQ:
8520 *pos++ = 0x00;
8521 break;
8522 case REASSOCREQ:
8523 *pos++ = 0x20;
8524 break;
8525 case DLS_REQ:
8526 *pos++ = 0xd0;
8527 break;
8528 }
8529
8530 if (protected == INCORRECT_KEY)
8531 *pos++ = 0x40; /* Set Protected field to 1 */
8532 else
8533 *pos++ = 0x00;
8534
8535 /* Duration */
8536 *pos++ = 0x00;
8537 *pos++ = 0x00;
8538
8539 /* addr1 = DA (current AP) */
8540 hwaddr_aton(bssid, pos);
8541 pos += 6;
8542 /* addr2 = SA (own address) */
8543 hwaddr_aton(addr, pos);
8544 pos += 6;
8545 /* addr3 = BSSID (current AP) */
8546 hwaddr_aton(bssid, pos);
8547 pos += 6;
8548
8549 /* Seq# (to be filled by driver/mac80211) */
8550 *pos++ = 0x00;
8551 *pos++ = 0x00;
8552
8553 if (protected == INCORRECT_KEY) {
8554 /* CCMP parameters */
8555 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8556 pos += 8;
8557 }
8558
8559 if (protected == INCORRECT_KEY) {
8560 switch (frame) {
8561 case DEAUTH:
8562 /* Reason code (encrypted) */
8563 memcpy(pos, "\xa7\x39", 2);
8564 pos += 2;
8565 break;
8566 case DISASSOC:
8567 /* Reason code (encrypted) */
8568 memcpy(pos, "\xa7\x39", 2);
8569 pos += 2;
8570 break;
8571 case SAQUERY:
8572 /* Category|Action|TransID (encrypted) */
8573 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8574 pos += 4;
8575 break;
8576 default:
8577 return -1;
8578 }
8579
8580 /* CCMP MIC */
8581 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8582 pos += 8;
8583 } else {
8584 switch (frame) {
8585 case DEAUTH:
8586 /* reason code = 8 */
8587 *pos++ = 0x08;
8588 *pos++ = 0x00;
8589 break;
8590 case DISASSOC:
8591 /* reason code = 8 */
8592 *pos++ = 0x08;
8593 *pos++ = 0x00;
8594 break;
8595 case SAQUERY:
8596 /* Category - SA Query */
8597 *pos++ = 0x08;
8598 /* SA query Action - Request */
8599 *pos++ = 0x00;
8600 /* Transaction ID */
8601 *pos++ = 0x12;
8602 *pos++ = 0x34;
8603 break;
8604 case AUTH:
8605 /* Auth Alg (Open) */
8606 *pos++ = 0x00;
8607 *pos++ = 0x00;
8608 /* Seq# */
8609 *pos++ = 0x01;
8610 *pos++ = 0x00;
8611 /* Status code */
8612 *pos++ = 0x00;
8613 *pos++ = 0x00;
8614 break;
8615 case ASSOCREQ:
8616 /* Capability Information */
8617 *pos++ = 0x31;
8618 *pos++ = 0x04;
8619 /* Listen Interval */
8620 *pos++ = 0x0a;
8621 *pos++ = 0x00;
8622 /* SSID */
8623 *pos++ = 0x00;
8624 *pos++ = ssid_len;
8625 memcpy(pos, ssid, ssid_len);
8626 pos += ssid_len;
8627 /* Supported Rates */
8628 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8629 10);
8630 pos += 10;
8631 /* Extended Supported Rates */
8632 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8633 pos += 6;
8634 /* RSN */
8635 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8636 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8637 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8638 pos += 28;
8639 break;
8640 case REASSOCREQ:
8641 /* Capability Information */
8642 *pos++ = 0x31;
8643 *pos++ = 0x04;
8644 /* Listen Interval */
8645 *pos++ = 0x0a;
8646 *pos++ = 0x00;
8647 /* Current AP */
8648 hwaddr_aton(bssid, pos);
8649 pos += 6;
8650 /* SSID */
8651 *pos++ = 0x00;
8652 *pos++ = ssid_len;
8653 memcpy(pos, ssid, ssid_len);
8654 pos += ssid_len;
8655 /* Supported Rates */
8656 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8657 10);
8658 pos += 10;
8659 /* Extended Supported Rates */
8660 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8661 pos += 6;
8662 /* RSN */
8663 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8664 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8665 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8666 pos += 28;
8667 break;
8668 case DLS_REQ:
8669 /* Category - DLS */
8670 *pos++ = 0x02;
8671 /* DLS Action - Request */
8672 *pos++ = 0x00;
8673 /* Destination MACAddress */
8674 if (dest)
8675 hwaddr_aton(dest, pos);
8676 else
8677 memset(pos, 0, 6);
8678 pos += 6;
8679 /* Source MACAddress */
8680 hwaddr_aton(addr, pos);
8681 pos += 6;
8682 /* Capability Information */
8683 *pos++ = 0x10; /* Privacy */
8684 *pos++ = 0x06; /* QoS */
8685 /* DLS Timeout Value */
8686 *pos++ = 0x00;
8687 *pos++ = 0x01;
8688 /* Supported rates */
8689 *pos++ = 0x01;
8690 *pos++ = 0x08;
8691 *pos++ = 0x0c; /* 6 Mbps */
8692 *pos++ = 0x12; /* 9 Mbps */
8693 *pos++ = 0x18; /* 12 Mbps */
8694 *pos++ = 0x24; /* 18 Mbps */
8695 *pos++ = 0x30; /* 24 Mbps */
8696 *pos++ = 0x48; /* 36 Mbps */
8697 *pos++ = 0x60; /* 48 Mbps */
8698 *pos++ = 0x6c; /* 54 Mbps */
8699 /* TODO: Extended Supported Rates */
8700 /* TODO: HT Capabilities */
8701 break;
8702 }
8703 }
8704
8705 s = open_monitor("sigmadut");
8706 if (s < 0) {
8707 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8708 "monitor socket");
8709 return 0;
8710 }
8711
8712 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8713 if (res < 0) {
8714 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8715 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308716 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008717 return 0;
8718 }
8719 if (res < pos - buf) {
8720 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8721 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308722 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008723 return 0;
8724 }
8725
8726 close(s);
8727
8728 return 1;
8729#else /* __linux__ */
8730 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
8731 "yet supported");
8732 return 0;
8733#endif /* __linux__ */
8734}
8735
8736
8737static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
8738 struct sigma_conn *conn,
8739 struct sigma_cmd *cmd)
8740{
8741 const char *intf = get_param(cmd, "Interface");
8742 const char *sta, *val;
8743 unsigned char addr[ETH_ALEN];
8744 char buf[100];
8745
8746 sta = get_param(cmd, "peer");
8747 if (sta == NULL)
8748 sta = get_param(cmd, "station");
8749 if (sta == NULL) {
8750 send_resp(dut, conn, SIGMA_ERROR,
8751 "ErrorCode,Missing peer address");
8752 return 0;
8753 }
8754 if (hwaddr_aton(sta, addr) < 0) {
8755 send_resp(dut, conn, SIGMA_ERROR,
8756 "ErrorCode,Invalid peer address");
8757 return 0;
8758 }
8759
8760 val = get_param(cmd, "type");
8761 if (val == NULL)
8762 return -1;
8763
8764 if (strcasecmp(val, "DISCOVERY") == 0) {
8765 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
8766 if (wpa_command(intf, buf) < 0) {
8767 send_resp(dut, conn, SIGMA_ERROR,
8768 "ErrorCode,Failed to send TDLS discovery");
8769 return 0;
8770 }
8771 return 1;
8772 }
8773
8774 if (strcasecmp(val, "SETUP") == 0) {
8775 int status = 0, timeout = 0;
8776
8777 val = get_param(cmd, "Status");
8778 if (val)
8779 status = atoi(val);
8780
8781 val = get_param(cmd, "Timeout");
8782 if (val)
8783 timeout = atoi(val);
8784
8785 if (status != 0 && status != 37) {
8786 send_resp(dut, conn, SIGMA_ERROR,
8787 "ErrorCode,Unsupported status value");
8788 return 0;
8789 }
8790
8791 if (timeout != 0 && timeout != 301) {
8792 send_resp(dut, conn, SIGMA_ERROR,
8793 "ErrorCode,Unsupported timeout value");
8794 return 0;
8795 }
8796
8797 if (status && timeout) {
8798 send_resp(dut, conn, SIGMA_ERROR,
8799 "ErrorCode,Unsupported timeout+status "
8800 "combination");
8801 return 0;
8802 }
8803
8804 if (status == 37 &&
8805 wpa_command(intf, "SET tdls_testing 0x200")) {
8806 send_resp(dut, conn, SIGMA_ERROR,
8807 "ErrorCode,Failed to enable "
8808 "decline setup response test mode");
8809 return 0;
8810 }
8811
8812 if (timeout == 301) {
8813 int res;
8814 if (dut->no_tpk_expiration)
8815 res = wpa_command(intf,
8816 "SET tdls_testing 0x108");
8817 else
8818 res = wpa_command(intf,
8819 "SET tdls_testing 0x8");
8820 if (res) {
8821 send_resp(dut, conn, SIGMA_ERROR,
8822 "ErrorCode,Failed to set short TPK "
8823 "lifetime");
8824 return 0;
8825 }
8826 }
8827
8828 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
8829 if (wpa_command(intf, buf) < 0) {
8830 send_resp(dut, conn, SIGMA_ERROR,
8831 "ErrorCode,Failed to send TDLS setup");
8832 return 0;
8833 }
8834 return 1;
8835 }
8836
8837 if (strcasecmp(val, "TEARDOWN") == 0) {
8838 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
8839 if (wpa_command(intf, buf) < 0) {
8840 send_resp(dut, conn, SIGMA_ERROR,
8841 "ErrorCode,Failed to send TDLS teardown");
8842 return 0;
8843 }
8844 return 1;
8845 }
8846
8847 send_resp(dut, conn, SIGMA_ERROR,
8848 "ErrorCode,Unsupported TDLS frame");
8849 return 0;
8850}
8851
8852
8853static int sta_ap_known(const char *ifname, const char *bssid)
8854{
8855 char buf[4096];
8856
Jouni Malinendd32f192018-09-15 02:55:19 +03008857 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008858 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
8859 return 0;
8860 if (strncmp(buf, "id=", 3) != 0)
8861 return 0;
8862 return 1;
8863}
8864
8865
8866static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
8867 const char *bssid)
8868{
8869 int res;
8870 struct wpa_ctrl *ctrl;
8871 char buf[256];
8872
8873 if (sta_ap_known(ifname, bssid))
8874 return 0;
8875 sigma_dut_print(dut, DUT_MSG_DEBUG,
8876 "AP not in BSS table - start scan");
8877
8878 ctrl = open_wpa_mon(ifname);
8879 if (ctrl == NULL) {
8880 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8881 "wpa_supplicant monitor connection");
8882 return -1;
8883 }
8884
8885 if (wpa_command(ifname, "SCAN") < 0) {
8886 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
8887 wpa_ctrl_detach(ctrl);
8888 wpa_ctrl_close(ctrl);
8889 return -1;
8890 }
8891
8892 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
8893 buf, sizeof(buf));
8894
8895 wpa_ctrl_detach(ctrl);
8896 wpa_ctrl_close(ctrl);
8897
8898 if (res < 0) {
8899 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
8900 return -1;
8901 }
8902
8903 if (sta_ap_known(ifname, bssid))
8904 return 0;
8905 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
8906 return -1;
8907}
8908
8909
8910static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
8911 struct sigma_conn *conn,
8912 struct sigma_cmd *cmd,
8913 const char *intf)
8914{
8915 char buf[200];
8916
8917 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
8918 if (system(buf) != 0) {
8919 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
8920 "ndsend");
8921 return 0;
8922 }
8923
8924 return 1;
8925}
8926
8927
8928static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
8929 struct sigma_conn *conn,
8930 struct sigma_cmd *cmd,
8931 const char *intf)
8932{
8933 char buf[200];
8934 const char *ip = get_param(cmd, "SenderIP");
8935
Peng Xu26b356d2017-10-04 17:58:16 -07008936 if (!ip)
8937 return 0;
8938
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008939 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
8940 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8941 if (system(buf) == 0) {
8942 sigma_dut_print(dut, DUT_MSG_INFO,
8943 "Neighbor Solicitation got a response "
8944 "for %s@%s", ip, intf);
8945 }
8946
8947 return 1;
8948}
8949
8950
8951static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
8952 struct sigma_conn *conn,
8953 struct sigma_cmd *cmd,
8954 const char *ifname)
8955{
8956 char buf[200];
8957 const char *ip = get_param(cmd, "SenderIP");
8958
8959 if (ip == NULL) {
8960 send_resp(dut, conn, SIGMA_ERROR,
8961 "ErrorCode,Missing SenderIP parameter");
8962 return 0;
8963 }
8964 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
8965 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8966 if (system(buf) != 0) {
8967 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
8968 "for %s@%s", ip, ifname);
8969 }
8970
8971 return 1;
8972}
8973
8974
8975static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
8976 struct sigma_conn *conn,
8977 struct sigma_cmd *cmd,
8978 const char *ifname)
8979{
8980 char buf[200];
8981 char ip[16];
8982 int s;
Peng Xub3756882017-10-04 14:39:09 -07008983 struct ifreq ifr;
8984 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008985
8986 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07008987 if (s < 0) {
8988 perror("socket");
8989 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008990 }
8991
Peng Xub3756882017-10-04 14:39:09 -07008992 memset(&ifr, 0, sizeof(ifr));
8993 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
8994 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
8995 sigma_dut_print(dut, DUT_MSG_INFO,
8996 "Failed to get %s IP address: %s",
8997 ifname, strerror(errno));
8998 close(s);
8999 return -1;
9000 }
9001 close(s);
9002
9003 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
9004 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
9005
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009006 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
9007 ip);
9008 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9009 if (system(buf) != 0) {
9010 }
9011
9012 return 1;
9013}
9014
9015
9016static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
9017 struct sigma_conn *conn,
9018 struct sigma_cmd *cmd,
9019 const char *ifname)
9020{
9021 char buf[200], addr[20];
9022 char dst[ETH_ALEN], src[ETH_ALEN];
9023 short ethtype = htons(ETH_P_ARP);
9024 char *pos;
9025 int s, res;
9026 const char *val;
9027 struct sockaddr_in taddr;
9028
9029 val = get_param(cmd, "dest");
9030 if (val)
9031 hwaddr_aton(val, (unsigned char *) dst);
9032
9033 val = get_param(cmd, "DestIP");
9034 if (val)
9035 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07009036 else
9037 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009038
9039 if (get_wpa_status(get_station_ifname(), "address", addr,
9040 sizeof(addr)) < 0)
9041 return -2;
9042 hwaddr_aton(addr, (unsigned char *) src);
9043
9044 pos = buf;
9045 *pos++ = 0x00;
9046 *pos++ = 0x01;
9047 *pos++ = 0x08;
9048 *pos++ = 0x00;
9049 *pos++ = 0x06;
9050 *pos++ = 0x04;
9051 *pos++ = 0x00;
9052 *pos++ = 0x02;
9053 memcpy(pos, src, ETH_ALEN);
9054 pos += ETH_ALEN;
9055 memcpy(pos, &taddr.sin_addr, 4);
9056 pos += 4;
9057 memcpy(pos, dst, ETH_ALEN);
9058 pos += ETH_ALEN;
9059 memcpy(pos, &taddr.sin_addr, 4);
9060 pos += 4;
9061
9062 s = open_monitor(get_station_ifname());
9063 if (s < 0) {
9064 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
9065 "monitor socket");
9066 return 0;
9067 }
9068
9069 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
9070 if (res < 0) {
9071 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
9072 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05309073 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009074 return 0;
9075 }
9076
9077 close(s);
9078
9079 return 1;
9080}
9081
9082
9083static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
9084 struct sigma_conn *conn,
9085 struct sigma_cmd *cmd,
9086 const char *intf, const char *dest)
9087{
9088 char buf[100];
9089
9090 if (if_nametoindex("sigmadut") == 0) {
9091 snprintf(buf, sizeof(buf),
9092 "iw dev %s interface add sigmadut type monitor",
9093 get_station_ifname());
9094 if (system(buf) != 0 ||
9095 if_nametoindex("sigmadut") == 0) {
9096 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9097 "monitor interface with '%s'", buf);
9098 return -2;
9099 }
9100 }
9101
9102 if (system("ifconfig sigmadut up") != 0) {
9103 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9104 "monitor interface up");
9105 return -2;
9106 }
9107
9108 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
9109}
9110
9111
9112static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
9113 struct sigma_conn *conn,
9114 struct sigma_cmd *cmd)
9115{
9116 const char *intf = get_param(cmd, "Interface");
9117 const char *dest = get_param(cmd, "Dest");
9118 const char *type = get_param(cmd, "FrameName");
9119 const char *val;
9120 char buf[200], *pos, *end;
9121 int count, count2;
9122
9123 if (type == NULL)
9124 type = get_param(cmd, "Type");
9125
9126 if (intf == NULL || dest == NULL || type == NULL)
9127 return -1;
9128
9129 if (strcasecmp(type, "NeighAdv") == 0)
9130 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
9131
9132 if (strcasecmp(type, "NeighSolicitReq") == 0)
9133 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
9134
9135 if (strcasecmp(type, "ARPProbe") == 0)
9136 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
9137
9138 if (strcasecmp(type, "ARPAnnounce") == 0)
9139 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
9140
9141 if (strcasecmp(type, "ARPReply") == 0)
9142 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
9143
9144 if (strcasecmp(type, "DLS-request") == 0 ||
9145 strcasecmp(type, "DLSrequest") == 0)
9146 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
9147 dest);
9148
9149 if (strcasecmp(type, "ANQPQuery") != 0 &&
9150 strcasecmp(type, "Query") != 0) {
9151 send_resp(dut, conn, SIGMA_ERROR,
9152 "ErrorCode,Unsupported HS 2.0 send frame type");
9153 return 0;
9154 }
9155
9156 if (sta_scan_ap(dut, intf, dest) < 0) {
9157 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
9158 "the requested AP");
9159 return 0;
9160 }
9161
9162 pos = buf;
9163 end = buf + sizeof(buf);
9164 count = 0;
9165 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
9166
9167 val = get_param(cmd, "ANQP_CAP_LIST");
9168 if (val && atoi(val)) {
9169 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
9170 count++;
9171 }
9172
9173 val = get_param(cmd, "VENUE_NAME");
9174 if (val && atoi(val)) {
9175 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
9176 count++;
9177 }
9178
9179 val = get_param(cmd, "NETWORK_AUTH_TYPE");
9180 if (val && atoi(val)) {
9181 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
9182 count++;
9183 }
9184
9185 val = get_param(cmd, "ROAMING_CONS");
9186 if (val && atoi(val)) {
9187 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
9188 count++;
9189 }
9190
9191 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
9192 if (val && atoi(val)) {
9193 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
9194 count++;
9195 }
9196
9197 val = get_param(cmd, "NAI_REALM_LIST");
9198 if (val && atoi(val)) {
9199 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
9200 count++;
9201 }
9202
9203 val = get_param(cmd, "3GPP_INFO");
9204 if (val && atoi(val)) {
9205 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
9206 count++;
9207 }
9208
9209 val = get_param(cmd, "DOMAIN_LIST");
9210 if (val && atoi(val)) {
9211 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
9212 count++;
9213 }
9214
Jouni Malinen34cf9532018-04-29 19:26:33 +03009215 val = get_param(cmd, "Venue_URL");
9216 if (val && atoi(val)) {
9217 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
9218 count++;
9219 }
9220
Jouni Malinend3bca5d2018-04-29 17:25:23 +03009221 val = get_param(cmd, "Advice_Of_Charge");
9222 if (val && atoi(val)) {
9223 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
9224 count++;
9225 }
9226
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009227 if (count && wpa_command(intf, buf)) {
9228 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
9229 return 0;
9230 }
9231
9232 pos = buf;
9233 end = buf + sizeof(buf);
9234 count2 = 0;
9235 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
9236
9237 val = get_param(cmd, "HS_CAP_LIST");
9238 if (val && atoi(val)) {
9239 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
9240 count2++;
9241 }
9242
9243 val = get_param(cmd, "OPER_NAME");
9244 if (val && atoi(val)) {
9245 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
9246 count2++;
9247 }
9248
9249 val = get_param(cmd, "WAN_METRICS");
9250 if (!val)
9251 val = get_param(cmd, "WAN_MAT");
9252 if (!val)
9253 val = get_param(cmd, "WAN_MET");
9254 if (val && atoi(val)) {
9255 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
9256 count2++;
9257 }
9258
9259 val = get_param(cmd, "CONNECTION_CAPABILITY");
9260 if (val && atoi(val)) {
9261 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
9262 count2++;
9263 }
9264
9265 val = get_param(cmd, "OP_CLASS");
9266 if (val && atoi(val)) {
9267 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
9268 count2++;
9269 }
9270
9271 val = get_param(cmd, "OSU_PROVIDER_LIST");
9272 if (val && atoi(val)) {
9273 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
9274 count2++;
9275 }
9276
Jouni Malinenf67afec2018-04-29 19:24:58 +03009277 val = get_param(cmd, "OPER_ICON_METADATA");
9278 if (!val)
9279 val = get_param(cmd, "OPERATOR_ICON_METADATA");
9280 if (val && atoi(val)) {
9281 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
9282 count2++;
9283 }
9284
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009285 if (count && count2) {
9286 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
9287 "second query");
9288 sleep(1);
9289 }
9290
9291 if (count2 && wpa_command(intf, buf)) {
9292 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
9293 "failed");
9294 return 0;
9295 }
9296
9297 val = get_param(cmd, "NAI_HOME_REALM_LIST");
9298 if (val) {
9299 if (count || count2) {
9300 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9301 "sending out second query");
9302 sleep(1);
9303 }
9304
9305 if (strcmp(val, "1") == 0)
9306 val = "mail.example.com";
9307 snprintf(buf, end - pos,
9308 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
9309 dest, val);
9310 if (wpa_command(intf, buf)) {
9311 send_resp(dut, conn, SIGMA_ERROR,
9312 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
9313 "failed");
9314 return 0;
9315 }
9316 }
9317
9318 val = get_param(cmd, "ICON_REQUEST");
9319 if (val) {
9320 if (count || count2) {
9321 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
9322 "sending out second query");
9323 sleep(1);
9324 }
9325
9326 snprintf(buf, end - pos,
9327 "HS20_ICON_REQUEST %s %s", dest, val);
9328 if (wpa_command(intf, buf)) {
9329 send_resp(dut, conn, SIGMA_ERROR,
9330 "ErrorCode,HS20_ICON_REQUEST failed");
9331 return 0;
9332 }
9333 }
9334
9335 return 1;
9336}
9337
9338
9339static int ath_sta_send_frame_vht(struct sigma_dut *dut,
9340 struct sigma_conn *conn,
9341 struct sigma_cmd *cmd)
9342{
9343 const char *val;
9344 char *ifname;
9345 char buf[100];
9346 int chwidth, nss;
9347
9348 val = get_param(cmd, "framename");
9349 if (!val)
9350 return -1;
9351 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9352
9353 /* Command sequence to generate Op mode notification */
9354 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
9355 ifname = get_station_ifname();
9356
9357 /* Disable STBC */
9358 snprintf(buf, sizeof(buf),
9359 "iwpriv %s tx_stbc 0", ifname);
9360 if (system(buf) != 0) {
9361 sigma_dut_print(dut, DUT_MSG_ERROR,
9362 "iwpriv tx_stbc 0 failed!");
9363 }
9364
9365 /* Extract Channel width */
9366 val = get_param(cmd, "Channel_width");
9367 if (val) {
9368 switch (atoi(val)) {
9369 case 20:
9370 chwidth = 0;
9371 break;
9372 case 40:
9373 chwidth = 1;
9374 break;
9375 case 80:
9376 chwidth = 2;
9377 break;
9378 case 160:
9379 chwidth = 3;
9380 break;
9381 default:
9382 chwidth = 2;
9383 break;
9384 }
9385
9386 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9387 ifname, chwidth);
9388 if (system(buf) != 0) {
9389 sigma_dut_print(dut, DUT_MSG_ERROR,
9390 "iwpriv chwidth failed!");
9391 }
9392 }
9393
9394 /* Extract NSS */
9395 val = get_param(cmd, "NSS");
9396 if (val) {
9397 switch (atoi(val)) {
9398 case 1:
9399 nss = 1;
9400 break;
9401 case 2:
9402 nss = 3;
9403 break;
9404 case 3:
9405 nss = 7;
9406 break;
9407 default:
9408 /* We do not support NSS > 3 */
9409 nss = 3;
9410 break;
9411 }
9412 snprintf(buf, sizeof(buf),
9413 "iwpriv %s rxchainmask %d", ifname, nss);
9414 if (system(buf) != 0) {
9415 sigma_dut_print(dut, DUT_MSG_ERROR,
9416 "iwpriv rxchainmask failed!");
9417 }
9418 }
9419
9420 /* Opmode notify */
9421 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
9422 if (system(buf) != 0) {
9423 sigma_dut_print(dut, DUT_MSG_ERROR,
9424 "iwpriv opmode_notify failed!");
9425 } else {
9426 sigma_dut_print(dut, DUT_MSG_INFO,
9427 "Sent out the notify frame!");
9428 }
9429 }
9430
9431 return 1;
9432}
9433
9434
9435static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
9436 struct sigma_conn *conn,
9437 struct sigma_cmd *cmd)
9438{
9439 switch (get_driver_type()) {
9440 case DRIVER_ATHEROS:
9441 return ath_sta_send_frame_vht(dut, conn, cmd);
9442 default:
9443 send_resp(dut, conn, SIGMA_ERROR,
9444 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
9445 return 0;
9446 }
9447}
9448
9449
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009450static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
9451 struct sigma_cmd *cmd)
9452{
9453 const char *val;
9454 const char *intf = get_param(cmd, "Interface");
9455
9456 val = get_param(cmd, "framename");
9457 if (!val)
9458 return -1;
9459 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9460
9461 /* Command sequence to generate Op mode notification */
9462 if (val && strcasecmp(val, "action") == 0) {
9463 val = get_param(cmd, "PPDUTxType");
9464 if (val && strcasecmp(val, "TB") == 0) {
9465 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
9466 sigma_dut_print(dut, DUT_MSG_ERROR,
9467 "failed to send TB PPDU Tx cfg");
9468 send_resp(dut, conn, SIGMA_ERROR,
9469 "ErrorCode,set TB PPDU Tx cfg failed");
9470 return 0;
9471 }
9472 return 1;
9473 }
9474
9475 sigma_dut_print(dut, DUT_MSG_ERROR,
9476 "Action Tx type is not defined");
9477 }
9478
9479 return 1;
9480}
9481
9482
9483static int cmd_sta_send_frame_he(struct sigma_dut *dut,
9484 struct sigma_conn *conn,
9485 struct sigma_cmd *cmd)
9486{
9487 switch (get_driver_type()) {
9488 case DRIVER_WCN:
9489 return wcn_sta_send_frame_he(dut, conn, cmd);
9490 default:
9491 send_resp(dut, conn, SIGMA_ERROR,
9492 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
9493 return 0;
9494 }
9495}
9496
9497
Lior David0fe101e2017-03-09 16:09:50 +02009498#ifdef __linux__
9499int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9500 struct sigma_cmd *cmd)
9501{
9502 const char *frame_name = get_param(cmd, "framename");
9503 const char *mac = get_param(cmd, "dest_mac");
9504
9505 if (!frame_name || !mac) {
9506 sigma_dut_print(dut, DUT_MSG_ERROR,
9507 "framename and dest_mac must be provided");
9508 return -1;
9509 }
9510
9511 if (strcasecmp(frame_name, "brp") == 0) {
9512 const char *l_rx = get_param(cmd, "L-RX");
9513 int l_rx_i;
9514
9515 if (!l_rx) {
9516 sigma_dut_print(dut, DUT_MSG_ERROR,
9517 "L-RX must be provided");
9518 return -1;
9519 }
9520 l_rx_i = atoi(l_rx);
9521
9522 sigma_dut_print(dut, DUT_MSG_INFO,
9523 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
9524 mac, l_rx);
9525 if (l_rx_i != 16) {
9526 sigma_dut_print(dut, DUT_MSG_ERROR,
9527 "unsupported L-RX: %s", l_rx);
9528 return -1;
9529 }
9530
9531 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
9532 return -1;
9533 } else if (strcasecmp(frame_name, "ssw") == 0) {
9534 sigma_dut_print(dut, DUT_MSG_INFO,
9535 "dev_send_frame: SLS, dest_mac %s", mac);
9536 if (wil6210_send_sls(dut, mac))
9537 return -1;
9538 } else {
9539 sigma_dut_print(dut, DUT_MSG_ERROR,
9540 "unsupported frame type: %s", frame_name);
9541 return -1;
9542 }
9543
9544 return 1;
9545}
9546#endif /* __linux__ */
9547
9548
9549static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
9550 struct sigma_conn *conn,
9551 struct sigma_cmd *cmd)
9552{
9553 switch (get_driver_type()) {
9554#ifdef __linux__
9555 case DRIVER_WIL6210:
9556 return wil6210_send_frame_60g(dut, conn, cmd);
9557#endif /* __linux__ */
9558 default:
9559 send_resp(dut, conn, SIGMA_ERROR,
9560 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9561 return 0;
9562 }
9563}
9564
9565
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309566static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
9567 const char *intf, struct sigma_cmd *cmd)
9568{
9569 const char *val, *addr;
9570 char buf[100];
9571
9572 addr = get_param(cmd, "DestMac");
9573 if (!addr) {
9574 send_resp(dut, conn, SIGMA_INVALID,
9575 "ErrorCode,AP MAC address is missing");
9576 return 0;
9577 }
9578
9579 val = get_param(cmd, "ANQPQuery_ID");
9580 if (!val) {
9581 send_resp(dut, conn, SIGMA_INVALID,
9582 "ErrorCode,Missing ANQPQuery_ID");
9583 return 0;
9584 }
9585
9586 if (strcasecmp(val, "NeighborReportReq") == 0) {
9587 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
9588 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
9589 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
9590 } else {
9591 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
9592 val);
9593 send_resp(dut, conn, SIGMA_INVALID,
9594 "ErrorCode,Invalid ANQPQuery_ID");
9595 return 0;
9596 }
9597
Ashwini Patild174f2c2017-04-13 16:49:46 +05309598 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
9599 * (Address3 = Wildcard BSSID when sent to not-associated AP;
9600 * if associated, AP BSSID).
9601 */
9602 if (wpa_command(intf, "SET gas_address3 1") < 0) {
9603 send_resp(dut, conn, SIGMA_ERROR,
9604 "ErrorCode,Failed to set gas_address3");
9605 return 0;
9606 }
9607
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309608 if (wpa_command(intf, buf) < 0) {
9609 send_resp(dut, conn, SIGMA_ERROR,
9610 "ErrorCode,Failed to send ANQP query");
9611 return 0;
9612 }
9613
9614 return 1;
9615}
9616
9617
9618static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
9619 struct sigma_conn *conn,
9620 const char *intf,
9621 struct sigma_cmd *cmd)
9622{
9623 const char *val = get_param(cmd, "FrameName");
9624
9625 if (val && strcasecmp(val, "ANQPQuery") == 0)
9626 return mbo_send_anqp_query(dut, conn, intf, cmd);
9627
9628 return 2;
9629}
9630
9631
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009632int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9633 struct sigma_cmd *cmd)
9634{
9635 const char *intf = get_param(cmd, "Interface");
9636 const char *val;
9637 enum send_frame_type frame;
9638 enum send_frame_protection protected;
9639 char buf[100];
9640 unsigned char addr[ETH_ALEN];
9641 int res;
9642
9643 val = get_param(cmd, "program");
9644 if (val == NULL)
9645 val = get_param(cmd, "frame");
9646 if (val && strcasecmp(val, "TDLS") == 0)
9647 return cmd_sta_send_frame_tdls(dut, conn, cmd);
9648 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009649 strcasecmp(val, "HS2-R2") == 0 ||
9650 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009651 return cmd_sta_send_frame_hs2(dut, conn, cmd);
9652 if (val && strcasecmp(val, "VHT") == 0)
9653 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009654 if (val && strcasecmp(val, "HE") == 0)
9655 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009656 if (val && strcasecmp(val, "LOC") == 0)
9657 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009658 if (val && strcasecmp(val, "60GHz") == 0)
9659 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309660 if (val && strcasecmp(val, "MBO") == 0) {
9661 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
9662 if (res != 2)
9663 return res;
9664 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009665
9666 val = get_param(cmd, "TD_DISC");
9667 if (val) {
9668 if (hwaddr_aton(val, addr) < 0)
9669 return -1;
9670 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
9671 if (wpa_command(intf, buf) < 0) {
9672 send_resp(dut, conn, SIGMA_ERROR,
9673 "ErrorCode,Failed to send TDLS discovery");
9674 return 0;
9675 }
9676 return 1;
9677 }
9678
9679 val = get_param(cmd, "TD_Setup");
9680 if (val) {
9681 if (hwaddr_aton(val, addr) < 0)
9682 return -1;
9683 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
9684 if (wpa_command(intf, buf) < 0) {
9685 send_resp(dut, conn, SIGMA_ERROR,
9686 "ErrorCode,Failed to start TDLS setup");
9687 return 0;
9688 }
9689 return 1;
9690 }
9691
9692 val = get_param(cmd, "TD_TearDown");
9693 if (val) {
9694 if (hwaddr_aton(val, addr) < 0)
9695 return -1;
9696 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
9697 if (wpa_command(intf, buf) < 0) {
9698 send_resp(dut, conn, SIGMA_ERROR,
9699 "ErrorCode,Failed to tear down TDLS link");
9700 return 0;
9701 }
9702 return 1;
9703 }
9704
9705 val = get_param(cmd, "TD_ChannelSwitch");
9706 if (val) {
9707 /* TODO */
9708 send_resp(dut, conn, SIGMA_ERROR,
9709 "ErrorCode,TD_ChannelSwitch not yet supported");
9710 return 0;
9711 }
9712
9713 val = get_param(cmd, "TD_NF");
9714 if (val) {
9715 /* TODO */
9716 send_resp(dut, conn, SIGMA_ERROR,
9717 "ErrorCode,TD_NF not yet supported");
9718 return 0;
9719 }
9720
9721 val = get_param(cmd, "PMFFrameType");
9722 if (val == NULL)
9723 val = get_param(cmd, "FrameName");
9724 if (val == NULL)
9725 val = get_param(cmd, "Type");
9726 if (val == NULL)
9727 return -1;
9728 if (strcasecmp(val, "disassoc") == 0)
9729 frame = DISASSOC;
9730 else if (strcasecmp(val, "deauth") == 0)
9731 frame = DEAUTH;
9732 else if (strcasecmp(val, "saquery") == 0)
9733 frame = SAQUERY;
9734 else if (strcasecmp(val, "auth") == 0)
9735 frame = AUTH;
9736 else if (strcasecmp(val, "assocreq") == 0)
9737 frame = ASSOCREQ;
9738 else if (strcasecmp(val, "reassocreq") == 0)
9739 frame = REASSOCREQ;
9740 else if (strcasecmp(val, "neigreq") == 0) {
9741 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
9742
9743 val = get_param(cmd, "ssid");
9744 if (val == NULL)
9745 return -1;
9746
9747 res = send_neighbor_request(dut, intf, val);
9748 if (res) {
9749 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9750 "Failed to send neighbor report request");
9751 return 0;
9752 }
9753
9754 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05309755 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
9756 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009757 sigma_dut_print(dut, DUT_MSG_DEBUG,
9758 "Got Transition Management Query");
9759
Ashwini Patil5acd7382017-04-13 15:55:04 +05309760 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009761 if (res) {
9762 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9763 "Failed to send Transition Management Query");
9764 return 0;
9765 }
9766
9767 return 1;
9768 } else {
9769 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9770 "PMFFrameType");
9771 return 0;
9772 }
9773
9774 val = get_param(cmd, "PMFProtected");
9775 if (val == NULL)
9776 val = get_param(cmd, "Protected");
9777 if (val == NULL)
9778 return -1;
9779 if (strcasecmp(val, "Correct-key") == 0 ||
9780 strcasecmp(val, "CorrectKey") == 0)
9781 protected = CORRECT_KEY;
9782 else if (strcasecmp(val, "IncorrectKey") == 0)
9783 protected = INCORRECT_KEY;
9784 else if (strcasecmp(val, "Unprotected") == 0)
9785 protected = UNPROTECTED;
9786 else {
9787 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9788 "PMFProtected");
9789 return 0;
9790 }
9791
9792 if (protected != UNPROTECTED &&
9793 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
9794 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
9795 "PMFProtected for auth/assocreq/reassocreq");
9796 return 0;
9797 }
9798
9799 if (if_nametoindex("sigmadut") == 0) {
9800 snprintf(buf, sizeof(buf),
9801 "iw dev %s interface add sigmadut type monitor",
9802 get_station_ifname());
9803 if (system(buf) != 0 ||
9804 if_nametoindex("sigmadut") == 0) {
9805 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9806 "monitor interface with '%s'", buf);
9807 return -2;
9808 }
9809 }
9810
9811 if (system("ifconfig sigmadut up") != 0) {
9812 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9813 "monitor interface up");
9814 return -2;
9815 }
9816
9817 return sta_inject_frame(dut, conn, frame, protected, NULL);
9818}
9819
9820
9821static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
9822 struct sigma_conn *conn,
9823 struct sigma_cmd *cmd,
9824 const char *ifname)
9825{
9826 char buf[200];
9827 const char *val;
9828
9829 val = get_param(cmd, "ClearARP");
9830 if (val && atoi(val) == 1) {
9831 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
9832 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9833 if (system(buf) != 0) {
9834 send_resp(dut, conn, SIGMA_ERROR,
9835 "errorCode,Failed to clear ARP cache");
9836 return 0;
9837 }
9838 }
9839
9840 return 1;
9841}
9842
9843
9844int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
9845 struct sigma_cmd *cmd)
9846{
9847 const char *intf = get_param(cmd, "Interface");
9848 const char *val;
9849
9850 if (intf == NULL)
9851 return -1;
9852
9853 val = get_param(cmd, "program");
9854 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009855 strcasecmp(val, "HS2-R2") == 0 ||
9856 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009857 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
9858
9859 return -1;
9860}
9861
9862
9863static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
9864 struct sigma_cmd *cmd)
9865{
9866 const char *intf = get_param(cmd, "Interface");
9867 const char *mac = get_param(cmd, "MAC");
9868
9869 if (intf == NULL || mac == NULL)
9870 return -1;
9871
9872 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
9873 "interface %s to %s", intf, mac);
9874
9875 if (dut->set_macaddr) {
9876 char buf[128];
9877 int res;
9878 if (strcasecmp(mac, "default") == 0) {
9879 res = snprintf(buf, sizeof(buf), "%s",
9880 dut->set_macaddr);
9881 dut->tmp_mac_addr = 0;
9882 } else {
9883 res = snprintf(buf, sizeof(buf), "%s %s",
9884 dut->set_macaddr, mac);
9885 dut->tmp_mac_addr = 1;
9886 }
9887 if (res < 0 || res >= (int) sizeof(buf))
9888 return -1;
9889 if (system(buf) != 0) {
9890 send_resp(dut, conn, SIGMA_ERROR,
9891 "errorCode,Failed to set MAC "
9892 "address");
9893 return 0;
9894 }
9895 return 1;
9896 }
9897
9898 if (strcasecmp(mac, "default") == 0)
9899 return 1;
9900
9901 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9902 "command");
9903 return 0;
9904}
9905
9906
9907static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
9908 struct sigma_conn *conn, const char *intf,
9909 int val)
9910{
9911 char buf[200];
9912 int res;
9913
9914 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
9915 intf, val);
9916 if (res < 0 || res >= (int) sizeof(buf))
9917 return -1;
9918 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9919 if (system(buf) != 0) {
9920 send_resp(dut, conn, SIGMA_ERROR,
9921 "errorCode,Failed to configure offchannel mode");
9922 return 0;
9923 }
9924
9925 return 1;
9926}
9927
9928
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009929static int off_chan_val(enum sec_ch_offset off)
9930{
9931 switch (off) {
9932 case SEC_CH_NO:
9933 return 0;
9934 case SEC_CH_40ABOVE:
9935 return 40;
9936 case SEC_CH_40BELOW:
9937 return -40;
9938 }
9939
9940 return 0;
9941}
9942
9943
9944static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
9945 const char *intf, int off_ch_num,
9946 enum sec_ch_offset sec)
9947{
9948 char buf[200];
9949 int res;
9950
9951 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
9952 intf, off_ch_num);
9953 if (res < 0 || res >= (int) sizeof(buf))
9954 return -1;
9955 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9956 if (system(buf) != 0) {
9957 send_resp(dut, conn, SIGMA_ERROR,
9958 "errorCode,Failed to set offchan");
9959 return 0;
9960 }
9961
9962 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
9963 intf, off_chan_val(sec));
9964 if (res < 0 || res >= (int) sizeof(buf))
9965 return -1;
9966 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9967 if (system(buf) != 0) {
9968 send_resp(dut, conn, SIGMA_ERROR,
9969 "errorCode,Failed to set sec chan offset");
9970 return 0;
9971 }
9972
9973 return 1;
9974}
9975
9976
9977static int tdls_set_offchannel_offset(struct sigma_dut *dut,
9978 struct sigma_conn *conn,
9979 const char *intf, int off_ch_num,
9980 enum sec_ch_offset sec)
9981{
9982 char buf[200];
9983 int res;
9984
9985 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
9986 off_ch_num);
9987 if (res < 0 || res >= (int) sizeof(buf))
9988 return -1;
9989 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9990
9991 if (wpa_command(intf, buf) < 0) {
9992 send_resp(dut, conn, SIGMA_ERROR,
9993 "ErrorCode,Failed to set offchan");
9994 return 0;
9995 }
9996 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
9997 off_chan_val(sec));
9998 if (res < 0 || res >= (int) sizeof(buf))
9999 return -1;
10000
10001 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10002
10003 if (wpa_command(intf, buf) < 0) {
10004 send_resp(dut, conn, SIGMA_ERROR,
10005 "ErrorCode,Failed to set sec chan offset");
10006 return 0;
10007 }
10008
10009 return 1;
10010}
10011
10012
10013static int tdls_set_offchannel_mode(struct sigma_dut *dut,
10014 struct sigma_conn *conn,
10015 const char *intf, int val)
10016{
10017 char buf[200];
10018 int res;
10019
10020 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
10021 val);
10022 if (res < 0 || res >= (int) sizeof(buf))
10023 return -1;
10024 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
10025
10026 if (wpa_command(intf, buf) < 0) {
10027 send_resp(dut, conn, SIGMA_ERROR,
10028 "ErrorCode,Failed to configure offchannel mode");
10029 return 0;
10030 }
10031
10032 return 1;
10033}
10034
10035
10036static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
10037 struct sigma_conn *conn,
10038 struct sigma_cmd *cmd)
10039{
10040 const char *val;
10041 enum {
10042 CHSM_NOT_SET,
10043 CHSM_ENABLE,
10044 CHSM_DISABLE,
10045 CHSM_REJREQ,
10046 CHSM_UNSOLRESP
10047 } chsm = CHSM_NOT_SET;
10048 int off_ch_num = -1;
10049 enum sec_ch_offset sec_ch = SEC_CH_NO;
10050 int res;
10051
10052 val = get_param(cmd, "Uapsd");
10053 if (val) {
10054 char buf[100];
10055 if (strcasecmp(val, "Enable") == 0)
10056 snprintf(buf, sizeof(buf), "SET ps 99");
10057 else if (strcasecmp(val, "Disable") == 0)
10058 snprintf(buf, sizeof(buf), "SET ps 98");
10059 else {
10060 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
10061 "Unsupported uapsd parameter value");
10062 return 0;
10063 }
10064 if (wpa_command(intf, buf)) {
10065 send_resp(dut, conn, SIGMA_ERROR,
10066 "ErrorCode,Failed to change U-APSD "
10067 "powersave mode");
10068 return 0;
10069 }
10070 }
10071
10072 val = get_param(cmd, "TPKTIMER");
10073 if (val && strcasecmp(val, "DISABLE") == 0) {
10074 if (wpa_command(intf, "SET tdls_testing 0x100")) {
10075 send_resp(dut, conn, SIGMA_ERROR,
10076 "ErrorCode,Failed to enable no TPK "
10077 "expiration test mode");
10078 return 0;
10079 }
10080 dut->no_tpk_expiration = 1;
10081 }
10082
10083 val = get_param(cmd, "ChSwitchMode");
10084 if (val) {
10085 if (strcasecmp(val, "Enable") == 0 ||
10086 strcasecmp(val, "Initiate") == 0)
10087 chsm = CHSM_ENABLE;
10088 else if (strcasecmp(val, "Disable") == 0 ||
10089 strcasecmp(val, "passive") == 0)
10090 chsm = CHSM_DISABLE;
10091 else if (strcasecmp(val, "RejReq") == 0)
10092 chsm = CHSM_REJREQ;
10093 else if (strcasecmp(val, "UnSolResp") == 0)
10094 chsm = CHSM_UNSOLRESP;
10095 else {
10096 send_resp(dut, conn, SIGMA_ERROR,
10097 "ErrorCode,Unknown ChSwitchMode value");
10098 return 0;
10099 }
10100 }
10101
10102 val = get_param(cmd, "OffChNum");
10103 if (val) {
10104 off_ch_num = atoi(val);
10105 if (off_ch_num == 0) {
10106 send_resp(dut, conn, SIGMA_ERROR,
10107 "ErrorCode,Invalid OffChNum");
10108 return 0;
10109 }
10110 }
10111
10112 val = get_param(cmd, "SecChOffset");
10113 if (val) {
10114 if (strcmp(val, "20") == 0)
10115 sec_ch = SEC_CH_NO;
10116 else if (strcasecmp(val, "40above") == 0)
10117 sec_ch = SEC_CH_40ABOVE;
10118 else if (strcasecmp(val, "40below") == 0)
10119 sec_ch = SEC_CH_40BELOW;
10120 else {
10121 send_resp(dut, conn, SIGMA_ERROR,
10122 "ErrorCode,Unknown SecChOffset value");
10123 return 0;
10124 }
10125 }
10126
10127 if (chsm == CHSM_NOT_SET) {
10128 /* no offchannel changes requested */
10129 return 1;
10130 }
10131
10132 if (strcmp(intf, get_main_ifname()) != 0 &&
10133 strcmp(intf, get_station_ifname()) != 0) {
10134 send_resp(dut, conn, SIGMA_ERROR,
10135 "ErrorCode,Unknown interface");
10136 return 0;
10137 }
10138
10139 switch (chsm) {
10140 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +030010141 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010142 break;
10143 case CHSM_ENABLE:
10144 if (off_ch_num < 0) {
10145 send_resp(dut, conn, SIGMA_ERROR,
10146 "ErrorCode,Missing OffChNum argument");
10147 return 0;
10148 }
10149 if (wifi_chip_type == DRIVER_WCN) {
10150 res = tdls_set_offchannel_offset(dut, conn, intf,
10151 off_ch_num, sec_ch);
10152 } else {
10153 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10154 sec_ch);
10155 }
10156 if (res != 1)
10157 return res;
10158 if (wifi_chip_type == DRIVER_WCN)
10159 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
10160 else
10161 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
10162 break;
10163 case CHSM_DISABLE:
10164 if (wifi_chip_type == DRIVER_WCN)
10165 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
10166 else
10167 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
10168 break;
10169 case CHSM_REJREQ:
10170 if (wifi_chip_type == DRIVER_WCN)
10171 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
10172 else
10173 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
10174 break;
10175 case CHSM_UNSOLRESP:
10176 if (off_ch_num < 0) {
10177 send_resp(dut, conn, SIGMA_ERROR,
10178 "ErrorCode,Missing OffChNum argument");
10179 return 0;
10180 }
10181 if (wifi_chip_type == DRIVER_WCN) {
10182 res = tdls_set_offchannel_offset(dut, conn, intf,
10183 off_ch_num, sec_ch);
10184 } else {
10185 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
10186 sec_ch);
10187 }
10188 if (res != 1)
10189 return res;
10190 if (wifi_chip_type == DRIVER_WCN)
10191 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
10192 else
10193 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
10194 break;
10195 }
10196
10197 return res;
10198}
10199
10200
10201static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
10202 struct sigma_conn *conn,
10203 struct sigma_cmd *cmd)
10204{
10205 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053010206 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010207
priyadharshini gowthamane5e25172015-12-08 14:53:48 -080010208 novap_reset(dut, intf);
10209
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010210 val = get_param(cmd, "nss_mcs_opt");
10211 if (val) {
10212 /* String (nss_operating_mode; mcs_operating_mode) */
10213 int nss, mcs;
10214 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010215 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010216
10217 token = strdup(val);
10218 if (!token)
10219 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010220 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010221 if (!result) {
10222 sigma_dut_print(dut, DUT_MSG_ERROR,
10223 "VHT NSS not specified");
10224 goto failed;
10225 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010226 if (strcasecmp(result, "def") != 0) {
10227 nss = atoi(result);
10228 if (nss == 4)
10229 ath_disable_txbf(dut, intf);
10230 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
10231 intf, nss);
10232 if (system(buf) != 0) {
10233 sigma_dut_print(dut, DUT_MSG_ERROR,
10234 "iwpriv nss failed");
10235 goto failed;
10236 }
10237 }
10238
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +053010239 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +053010240 if (!result) {
10241 sigma_dut_print(dut, DUT_MSG_ERROR,
10242 "VHT MCS not specified");
10243 goto failed;
10244 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010245 if (strcasecmp(result, "def") == 0) {
10246 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
10247 intf);
10248 if (system(buf) != 0) {
10249 sigma_dut_print(dut, DUT_MSG_ERROR,
10250 "iwpriv set11NRates failed");
10251 goto failed;
10252 }
10253
10254 } else {
10255 mcs = atoi(result);
10256 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
10257 intf, mcs);
10258 if (system(buf) != 0) {
10259 sigma_dut_print(dut, DUT_MSG_ERROR,
10260 "iwpriv vhtmcs failed");
10261 goto failed;
10262 }
10263 }
10264 /* Channel width gets messed up, fix this */
10265 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
10266 intf, dut->chwidth);
10267 if (system(buf) != 0) {
10268 sigma_dut_print(dut, DUT_MSG_ERROR,
10269 "iwpriv chwidth failed");
10270 }
10271 }
10272
Srikanth Marepalli5415acf2018-08-27 12:53:11 +053010273 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010274 return 1;
10275failed:
10276 free(token);
10277 return 0;
10278}
10279
10280
10281static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
10282 struct sigma_conn *conn,
10283 struct sigma_cmd *cmd)
10284{
10285 switch (get_driver_type()) {
10286 case DRIVER_ATHEROS:
10287 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
10288 default:
10289 send_resp(dut, conn, SIGMA_ERROR,
10290 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
10291 return 0;
10292 }
10293}
10294
10295
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010296static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
10297 struct sigma_conn *conn,
10298 struct sigma_cmd *cmd)
10299{
10300 const char *val;
10301 char *token = NULL, *result;
10302 char buf[60];
10303
10304 val = get_param(cmd, "nss_mcs_opt");
10305 if (val) {
10306 /* String (nss_operating_mode; mcs_operating_mode) */
10307 int nss, mcs, ratecode;
10308 char *saveptr;
10309
10310 token = strdup(val);
10311 if (!token)
10312 return -2;
10313
10314 result = strtok_r(token, ";", &saveptr);
10315 if (!result) {
10316 sigma_dut_print(dut, DUT_MSG_ERROR,
10317 "HE NSS not specified");
10318 goto failed;
10319 }
10320 nss = 1;
10321 if (strcasecmp(result, "def") != 0)
10322 nss = atoi(result);
10323
10324 result = strtok_r(NULL, ";", &saveptr);
10325 if (!result) {
10326 sigma_dut_print(dut, DUT_MSG_ERROR,
10327 "HE MCS not specified");
10328 goto failed;
10329 }
10330 mcs = 7;
10331 if (strcasecmp(result, "def") != 0)
10332 mcs = atoi(result);
10333
Arif Hussain557bf412018-05-25 17:29:36 -070010334 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010335 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -070010336 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010337 } else if (nss > 2) {
10338 sigma_dut_print(dut, DUT_MSG_ERROR,
10339 "HE NSS %d not supported", nss);
10340 goto failed;
10341 }
10342
Arif Hussain557bf412018-05-25 17:29:36 -070010343 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
10344 if (system(buf) != 0) {
10345 sigma_dut_print(dut, DUT_MSG_ERROR,
10346 "nss_mcs_opt: iwpriv %s nss %d failed",
10347 intf, nss);
10348 goto failed;
10349 }
Arif Hussainac6c5112018-05-25 17:34:00 -070010350 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -070010351
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010352 /* Add the MCS to the ratecode */
10353 if (mcs >= 0 && mcs <= 11) {
10354 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -070010355#ifdef NL80211_SUPPORT
10356 if (dut->device_type == STA_testbed) {
10357 enum he_mcs_config mcs_config;
10358 int ret;
10359
10360 if (mcs <= 7)
10361 mcs_config = HE_80_MCS0_7;
10362 else if (mcs <= 9)
10363 mcs_config = HE_80_MCS0_9;
10364 else
10365 mcs_config = HE_80_MCS0_11;
10366 ret = sta_set_he_mcs(dut, intf, mcs_config);
10367 if (ret) {
10368 sigma_dut_print(dut, DUT_MSG_ERROR,
10369 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
10370 mcs, mcs_config, ret);
10371 goto failed;
10372 }
10373 }
10374#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010375 } else {
10376 sigma_dut_print(dut, DUT_MSG_ERROR,
10377 "HE MCS %d not supported", mcs);
10378 goto failed;
10379 }
10380 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
10381 intf, ratecode);
10382 if (system(buf) != 0) {
10383 sigma_dut_print(dut, DUT_MSG_ERROR,
10384 "iwpriv setting of 11ax rates failed");
10385 goto failed;
10386 }
10387 free(token);
10388 }
10389
10390 val = get_param(cmd, "GI");
10391 if (val) {
10392 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010393 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010394 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010395 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
10396 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010397 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010398 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
10399 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010400 } else {
10401 send_resp(dut, conn, SIGMA_ERROR,
10402 "errorCode,GI value not supported");
10403 return 0;
10404 }
10405 if (system(buf) != 0) {
10406 send_resp(dut, conn, SIGMA_ERROR,
10407 "errorCode,Failed to set shortgi");
10408 return 0;
10409 }
10410 }
10411
Subhani Shaik8e7a3052018-04-24 14:03:00 -070010412 val = get_param(cmd, "LTF");
10413 if (val) {
10414#ifdef NL80211_SUPPORT
10415 if (strcmp(val, "3.2") == 0) {
10416 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
10417 } if (strcmp(val, "6.4") == 0) {
10418 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
10419 } else if (strcmp(val, "12.8") == 0) {
10420 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
10421 } else {
10422 send_resp(dut, conn, SIGMA_ERROR,
10423 "errorCode, LTF value not supported");
10424 return 0;
10425 }
10426#else /* NL80211_SUPPORT */
10427 sigma_dut_print(dut, DUT_MSG_ERROR,
10428 "LTF cannot be set without NL80211_SUPPORT defined");
10429 return -2;
10430#endif /* NL80211_SUPPORT */
10431 }
10432
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070010433 val = get_param(cmd, "TxSUPPDU");
10434 if (val) {
10435 int set_val = 1;
10436
10437 if (strcasecmp(val, "Enable") == 0)
10438 set_val = 1;
10439 else if (strcasecmp(val, "Disable") == 0)
10440 set_val = 0;
10441
10442 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
10443 send_resp(dut, conn, SIGMA_ERROR,
10444 "ErrorCode,Failed to set Tx SU PPDU config");
10445 return 0;
10446 }
10447 }
10448
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070010449 val = get_param(cmd, "OMCtrl_RxNSS");
10450 if (val) {
10451 /*
10452 * OMCtrl_RxNSS uses the IEEE 802.11 standard values for Nss,
10453 * i.e., 0 for 1Nss, 1 for Nss 2, etc. The driver checks for
10454 * the actual Nss value hence add 1 to the set value.
10455 */
10456 int set_val = atoi(val) + 1;
10457
10458 if (sta_set_he_om_ctrl_nss(dut, intf, set_val)) {
10459 send_resp(dut, conn, SIGMA_ERROR,
10460 "ErrorCode,Failed to set OM ctrl NSS config");
10461 return 0;
10462 }
10463 }
10464
10465 val = get_param(cmd, "OMCtrl_ChnlWidth");
10466 if (val) {
10467 int set_val = atoi(val);
10468
10469 if (sta_set_he_om_ctrl_bw(dut, intf,
10470 (enum qca_wlan_he_om_ctrl_ch_bw)
10471 set_val)) {
10472 send_resp(dut, conn, SIGMA_ERROR,
10473 "ErrorCode,Failed to set OM ctrl BW config");
10474 return 0;
10475 }
10476 }
10477
Kiran Kumar Lokerec310dcd2018-12-17 20:56:06 -080010478 val = get_param(cmd, "Powersave");
10479 if (val) {
10480 char buf[60];
10481
10482 if (strcasecmp(val, "off") == 0) {
10483 snprintf(buf, sizeof(buf),
10484 "iwpriv %s setPower 2", intf);
10485 if (system(buf) != 0) {
10486 sigma_dut_print(dut, DUT_MSG_ERROR,
10487 "iwpriv setPower 2 failed");
10488 return 0;
10489 }
10490 } else if (strcasecmp(val, "on") == 0) {
10491 snprintf(buf, sizeof(buf),
10492 "iwpriv %s setPower 1", intf);
10493 if (system(buf) != 0) {
10494 sigma_dut_print(dut, DUT_MSG_ERROR,
10495 "iwpriv setPower 1 failed");
10496 return 0;
10497 }
10498 } else {
10499 sigma_dut_print(dut, DUT_MSG_ERROR,
10500 "Unsupported Powersave value '%s'",
10501 val);
10502 return -1;
10503 }
10504 }
10505
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010506 return 1;
10507
10508failed:
10509 free(token);
10510 return -2;
10511}
10512
10513
10514static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
10515 struct sigma_conn *conn,
10516 struct sigma_cmd *cmd)
10517{
10518 switch (get_driver_type()) {
10519 case DRIVER_WCN:
10520 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
10521 default:
10522 send_resp(dut, conn, SIGMA_ERROR,
10523 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
10524 return 0;
10525 }
10526}
10527
10528
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010529static int cmd_sta_set_power_save_he(const char *intf, struct sigma_dut *dut,
10530 struct sigma_conn *conn,
10531 struct sigma_cmd *cmd)
10532{
10533 const char *val;
10534
10535 val = get_param(cmd, "powersave");
10536 if (val) {
10537 char buf[60];
10538
10539 if (strcasecmp(val, "off") == 0) {
10540 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2",
10541 intf);
10542 if (system(buf) != 0) {
10543 sigma_dut_print(dut, DUT_MSG_ERROR,
10544 "iwpriv setPower 2 failed");
10545 return 0;
10546 }
10547 } else if (strcasecmp(val, "on") == 0) {
10548 snprintf(buf, sizeof(buf), "iwpriv %s setPower 1",
10549 intf);
10550 if (system(buf) != 0) {
10551 sigma_dut_print(dut, DUT_MSG_ERROR,
10552 "iwpriv setPower 1 failed");
10553 return 0;
10554 }
10555 } else {
10556 sigma_dut_print(dut, DUT_MSG_ERROR,
10557 "Unsupported power save config");
10558 return -1;
10559 }
10560 return 1;
10561 }
10562
10563 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported command");
10564
10565 return 0;
10566}
10567
10568
Ashwini Patil5acd7382017-04-13 15:55:04 +053010569static int btm_query_candidate_list(struct sigma_dut *dut,
10570 struct sigma_conn *conn,
10571 struct sigma_cmd *cmd)
10572{
10573 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
10574 int len, ret;
10575 char buf[10];
10576
10577 /*
10578 * Neighbor Report elements format:
10579 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
10580 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
10581 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
10582 */
10583
10584 bssid = get_param(cmd, "Nebor_BSSID");
10585 if (!bssid) {
10586 send_resp(dut, conn, SIGMA_INVALID,
10587 "errorCode,Nebor_BSSID is missing");
10588 return 0;
10589 }
10590
10591 info = get_param(cmd, "Nebor_Bssid_Info");
10592 if (!info) {
10593 sigma_dut_print(dut, DUT_MSG_INFO,
10594 "Using default value for Nebor_Bssid_Info: %s",
10595 DEFAULT_NEIGHBOR_BSSID_INFO);
10596 info = DEFAULT_NEIGHBOR_BSSID_INFO;
10597 }
10598
10599 op_class = get_param(cmd, "Nebor_Op_Class");
10600 if (!op_class) {
10601 send_resp(dut, conn, SIGMA_INVALID,
10602 "errorCode,Nebor_Op_Class is missing");
10603 return 0;
10604 }
10605
10606 ch = get_param(cmd, "Nebor_Op_Ch");
10607 if (!ch) {
10608 send_resp(dut, conn, SIGMA_INVALID,
10609 "errorCode,Nebor_Op_Ch is missing");
10610 return 0;
10611 }
10612
10613 phy_type = get_param(cmd, "Nebor_Phy_Type");
10614 if (!phy_type) {
10615 sigma_dut_print(dut, DUT_MSG_INFO,
10616 "Using default value for Nebor_Phy_Type: %s",
10617 DEFAULT_NEIGHBOR_PHY_TYPE);
10618 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
10619 }
10620
10621 /* Parse optional subelements */
10622 buf[0] = '\0';
10623 pref = get_param(cmd, "Nebor_Pref");
10624 if (pref) {
10625 /* hexdump for preferrence subelement */
10626 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
10627 if (ret < 0 || ret >= (int) sizeof(buf)) {
10628 sigma_dut_print(dut, DUT_MSG_ERROR,
10629 "snprintf failed for optional subelement ret: %d",
10630 ret);
10631 send_resp(dut, conn, SIGMA_ERROR,
10632 "errorCode,snprintf failed for subelement");
10633 return 0;
10634 }
10635 }
10636
10637 if (!dut->btm_query_cand_list) {
10638 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
10639 if (!dut->btm_query_cand_list) {
10640 send_resp(dut, conn, SIGMA_ERROR,
10641 "errorCode,Failed to allocate memory for btm_query_cand_list");
10642 return 0;
10643 }
10644 }
10645
10646 len = strlen(dut->btm_query_cand_list);
10647 ret = snprintf(dut->btm_query_cand_list + len,
10648 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
10649 bssid, info, op_class, ch, phy_type, buf);
10650 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
10651 sigma_dut_print(dut, DUT_MSG_ERROR,
10652 "snprintf failed for neighbor report list ret: %d",
10653 ret);
10654 send_resp(dut, conn, SIGMA_ERROR,
10655 "errorCode,snprintf failed for neighbor report");
10656 free(dut->btm_query_cand_list);
10657 dut->btm_query_cand_list = NULL;
10658 return 0;
10659 }
10660
10661 return 1;
10662}
10663
10664
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080010665static int cmd_sta_set_power_save(struct sigma_dut *dut,
10666 struct sigma_conn *conn,
10667 struct sigma_cmd *cmd)
10668{
10669 const char *intf = get_param(cmd, "interface");
10670 const char *prog = get_param(cmd, "program");
10671
10672 if (!intf || !prog)
10673 return -1;
10674
10675 if ((get_driver_type() == DRIVER_WCN) && (strcasecmp(prog, "HE") == 0))
10676 return cmd_sta_set_power_save_he(intf, dut, conn, cmd);
10677
10678 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10679 return 0;
10680}
10681
10682
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010683int sta_extract_60g_ese(struct sigma_dut *dut, struct sigma_cmd *cmd,
10684 struct sigma_ese_alloc *allocs, int *allocs_size)
10685{
10686 int max_count = *allocs_size;
10687 int count = 0, i;
10688 const char *val;
10689
10690 do {
10691 val = get_param_indexed(cmd, "AllocID", count);
10692 if (val)
10693 count++;
10694 } while (val);
10695
10696 if (count == 0 || count > max_count) {
10697 sigma_dut_print(dut, DUT_MSG_ERROR,
10698 "Invalid number of allocations(%d)", count);
10699 return -1;
10700 }
10701
10702 for (i = 0; i < count; i++) {
10703 val = get_param_indexed(cmd, "PercentBI", i);
10704 if (!val) {
10705 sigma_dut_print(dut, DUT_MSG_ERROR,
10706 "Missing PercentBI parameter at index %d",
10707 i);
10708 return -1;
10709 }
10710 allocs[i].percent_bi = atoi(val);
10711
10712 val = get_param_indexed(cmd, "SrcAID", i);
10713 if (val)
10714 allocs[i].src_aid = strtol(val, NULL, 0);
10715 else
10716 allocs[i].src_aid = ESE_BCAST_AID;
10717
10718 val = get_param_indexed(cmd, "DestAID", i);
10719 if (val)
10720 allocs[i].dst_aid = strtol(val, NULL, 0);
10721 else
10722 allocs[i].dst_aid = ESE_BCAST_AID;
10723
10724 allocs[i].type = ESE_CBAP;
10725 sigma_dut_print(dut, DUT_MSG_INFO,
10726 "Alloc %d PercentBI %d SrcAID %d DstAID %d",
10727 i, allocs[i].percent_bi, allocs[i].src_aid,
10728 allocs[i].dst_aid);
10729 }
10730
10731 *allocs_size = count;
10732 return 0;
10733}
10734
10735
10736static int sta_set_60g_ese(struct sigma_dut *dut, int count,
10737 struct sigma_ese_alloc *allocs)
10738{
10739 switch (get_driver_type()) {
10740#ifdef __linux__
10741 case DRIVER_WIL6210:
10742 if (wil6210_set_ese(dut, count, allocs))
10743 return -1;
10744 return 1;
10745#endif /* __linux__ */
10746 default:
10747 sigma_dut_print(dut, DUT_MSG_ERROR,
10748 "Unsupported sta_set_60g_ese with the current driver");
10749 return -1;
10750 }
10751}
10752
10753
10754static int cmd_sta_set_rfeature_60g(const char *intf, struct sigma_dut *dut,
10755 struct sigma_conn *conn,
10756 struct sigma_cmd *cmd)
10757{
10758 const char *val;
10759
10760 val = get_param(cmd, "ExtSchIE");
10761 if (val && !strcasecmp(val, "Enable")) {
10762 struct sigma_ese_alloc allocs[MAX_ESE_ALLOCS];
10763 int count = MAX_ESE_ALLOCS;
10764
10765 if (sta_extract_60g_ese(dut, cmd, allocs, &count))
10766 return -1;
10767 return sta_set_60g_ese(dut, count, allocs);
10768 }
10769
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020010770 val = get_param(cmd, "MCS_FixedRate");
10771 if (val) {
10772 int sta_mcs = atoi(val);
10773
10774 sigma_dut_print(dut, DUT_MSG_INFO, "Force STA MCS to %d",
10775 sta_mcs);
10776 wil6210_set_force_mcs(dut, 1, sta_mcs);
10777
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010778 return SUCCESS_SEND_STATUS;
Alexei Avshalom Lazaraad97b02018-12-18 16:01:23 +020010779 }
10780
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010781 send_resp(dut, conn, SIGMA_ERROR,
10782 "errorCode,Invalid sta_set_rfeature(60G)");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020010783 return STATUS_SENT;
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010784}
10785
10786
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010787static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10788 struct sigma_cmd *cmd)
10789{
10790 const char *intf = get_param(cmd, "Interface");
10791 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010792 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010793
10794 if (intf == NULL || prog == NULL)
10795 return -1;
10796
Ashwini Patil5acd7382017-04-13 15:55:04 +053010797 /* BSS Transition candidate list for BTM query */
10798 val = get_param(cmd, "Nebor_BSSID");
10799 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
10800 return 0;
10801
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010802 if (strcasecmp(prog, "TDLS") == 0)
10803 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
10804
10805 if (strcasecmp(prog, "VHT") == 0)
10806 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
10807
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010808 if (strcasecmp(prog, "HE") == 0)
10809 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
10810
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010811 if (strcasecmp(prog, "MBO") == 0) {
10812 val = get_param(cmd, "Cellular_Data_Cap");
10813 if (val &&
10814 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
10815 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053010816
10817 val = get_param(cmd, "Ch_Pref");
10818 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
10819 return 0;
10820
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010821 return 1;
10822 }
10823
Alexei Avshalom Lazarbc180dc2018-12-18 16:01:14 +020010824 if (strcasecmp(prog, "60GHz") == 0)
10825 return cmd_sta_set_rfeature_60g(intf, dut, conn, cmd);
10826
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010827 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10828 return 0;
10829}
10830
10831
10832static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
10833 struct sigma_cmd *cmd)
10834{
10835 const char *intf = get_param(cmd, "Interface");
10836 const char *mode = get_param(cmd, "Mode");
10837 int res;
10838
10839 if (intf == NULL || mode == NULL)
10840 return -1;
10841
10842 if (strcasecmp(mode, "On") == 0)
10843 res = wpa_command(intf, "SET radio_disabled 0");
10844 else if (strcasecmp(mode, "Off") == 0)
10845 res = wpa_command(intf, "SET radio_disabled 1");
10846 else
10847 return -1;
10848
10849 if (res) {
10850 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10851 "radio mode");
10852 return 0;
10853 }
10854
10855 return 1;
10856}
10857
10858
10859static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
10860 struct sigma_cmd *cmd)
10861{
10862 const char *intf = get_param(cmd, "Interface");
10863 const char *mode = get_param(cmd, "Mode");
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020010864 const char *prog = get_param(cmd, "program");
10865 const char *powersave = get_param(cmd, "powersave");
10866 int res = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010867
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020010868 if (intf == NULL)
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010869 return -1;
10870
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020010871 if (prog && strcasecmp(prog, "60GHz") == 0) {
10872 /*
10873 * The CAPI mode parameter does not exist in 60G
10874 * unscheduled PS.
10875 */
10876 if (strcasecmp(powersave, "unscheduled") == 0)
10877 res = set_ps(intf, dut, 1);
10878 } else {
10879 if (mode == NULL)
10880 return -1;
10881
10882 if (strcasecmp(mode, "On") == 0)
10883 res = set_ps(intf, dut, 1);
10884 else if (strcasecmp(mode, "Off") == 0)
10885 res = set_ps(intf, dut, 0);
10886 else
10887 return -1;
10888 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010889
10890 if (res) {
10891 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10892 "power save mode");
10893 return 0;
10894 }
10895
10896 return 1;
10897}
10898
10899
10900static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
10901 struct sigma_cmd *cmd)
10902{
10903 const char *intf = get_param(cmd, "Interface");
10904 const char *val, *bssid;
10905 int res;
10906 char *buf;
10907 size_t buf_len;
10908
10909 val = get_param(cmd, "BSSID_FILTER");
10910 if (val == NULL)
10911 return -1;
10912
10913 bssid = get_param(cmd, "BSSID_List");
10914 if (atoi(val) == 0 || bssid == NULL) {
10915 /* Disable BSSID filter */
10916 if (wpa_command(intf, "SET bssid_filter ")) {
10917 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
10918 "to disable BSSID filter");
10919 return 0;
10920 }
10921
10922 return 1;
10923 }
10924
10925 buf_len = 100 + strlen(bssid);
10926 buf = malloc(buf_len);
10927 if (buf == NULL)
10928 return -1;
10929
10930 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
10931 res = wpa_command(intf, buf);
10932 free(buf);
10933 if (res) {
10934 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
10935 "BSSID filter");
10936 return 0;
10937 }
10938
10939 return 1;
10940}
10941
10942
10943static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
10944 struct sigma_cmd *cmd)
10945{
10946 const char *intf = get_param(cmd, "Interface");
10947 const char *val;
10948
10949 /* TODO: ARP */
10950
10951 val = get_param(cmd, "HS2_CACHE_PROFILE");
10952 if (val && strcasecmp(val, "All") == 0)
10953 hs2_clear_credentials(intf);
10954
10955 return 1;
10956}
10957
10958
10959static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
10960 struct sigma_cmd *cmd)
10961{
10962 const char *intf = get_param(cmd, "Interface");
10963 const char *key_type = get_param(cmd, "KeyType");
10964 char buf[100], resp[200];
10965
10966 if (key_type == NULL)
10967 return -1;
10968
10969 if (strcasecmp(key_type, "GTK") == 0) {
10970 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
10971 strncmp(buf, "FAIL", 4) == 0) {
10972 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10973 "not fetch current GTK");
10974 return 0;
10975 }
10976 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
10977 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10978 return 0;
10979 } else {
10980 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10981 "KeyType");
10982 return 0;
10983 }
10984
10985 return 1;
10986}
10987
10988
10989static int hs2_set_policy(struct sigma_dut *dut)
10990{
10991#ifdef ANDROID
10992 system("ip rule del prio 23000");
10993 if (system("ip rule add from all lookup main prio 23000") != 0) {
10994 sigma_dut_print(dut, DUT_MSG_ERROR,
10995 "Failed to run:ip rule add from all lookup main prio");
10996 return -1;
10997 }
10998 if (system("ip route flush cache") != 0) {
10999 sigma_dut_print(dut, DUT_MSG_ERROR,
11000 "Failed to run ip route flush cache");
11001 return -1;
11002 }
11003 return 1;
11004#else /* ANDROID */
11005 return 0;
11006#endif /* ANDROID */
11007}
11008
11009
11010static int cmd_sta_hs2_associate(struct sigma_dut *dut,
11011 struct sigma_conn *conn,
11012 struct sigma_cmd *cmd)
11013{
11014 const char *intf = get_param(cmd, "Interface");
11015 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030011016 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011017 struct wpa_ctrl *ctrl;
11018 int res;
11019 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
11020 int tries = 0;
11021 int ignore_blacklist = 0;
11022 const char *events[] = {
11023 "CTRL-EVENT-CONNECTED",
11024 "INTERWORKING-BLACKLISTED",
11025 "INTERWORKING-NO-MATCH",
11026 NULL
11027 };
11028
11029 start_sta_mode(dut);
11030
Jouni Malinen439352d2018-09-13 03:42:23 +030011031 if (band) {
11032 if (strcmp(band, "2.4") == 0) {
11033 wpa_command(intf, "SET setband 2G");
11034 } else if (strcmp(band, "5") == 0) {
11035 wpa_command(intf, "SET setband 5G");
11036 } else {
11037 send_resp(dut, conn, SIGMA_ERROR,
11038 "errorCode,Unsupported band");
11039 return 0;
11040 }
11041 }
11042
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011043 blacklisted[0] = '\0';
11044 if (val && atoi(val))
11045 ignore_blacklist = 1;
11046
11047try_again:
11048 ctrl = open_wpa_mon(intf);
11049 if (ctrl == NULL) {
11050 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11051 "wpa_supplicant monitor connection");
11052 return -2;
11053 }
11054
11055 tries++;
11056 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
11057 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
11058 "Interworking connection");
11059 wpa_ctrl_detach(ctrl);
11060 wpa_ctrl_close(ctrl);
11061 return 0;
11062 }
11063
11064 buf[0] = '\0';
11065 while (1) {
11066 char *pos;
11067 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11068 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
11069 if (!pos)
11070 break;
11071 pos += 25;
11072 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
11073 pos);
11074 if (!blacklisted[0])
11075 memcpy(blacklisted, pos, strlen(pos) + 1);
11076 }
11077
11078 if (ignore_blacklist && blacklisted[0]) {
11079 char *end;
11080 end = strchr(blacklisted, ' ');
11081 if (end)
11082 *end = '\0';
11083 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
11084 blacklisted);
11085 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
11086 blacklisted);
11087 if (wpa_command(intf, buf)) {
11088 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
11089 wpa_ctrl_detach(ctrl);
11090 wpa_ctrl_close(ctrl);
11091 return 0;
11092 }
11093 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11094 buf, sizeof(buf));
11095 }
11096
11097 wpa_ctrl_detach(ctrl);
11098 wpa_ctrl_close(ctrl);
11099
11100 if (res < 0) {
11101 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11102 "connect");
11103 return 0;
11104 }
11105
11106 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
11107 strstr(buf, "INTERWORKING-BLACKLISTED")) {
11108 if (tries < 2) {
11109 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
11110 goto try_again;
11111 }
11112 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
11113 "matching credentials found");
11114 return 0;
11115 }
11116
11117 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11118 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11119 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
11120 "get current BSSID/SSID");
11121 return 0;
11122 }
11123
11124 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
11125 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11126 hs2_set_policy(dut);
11127 return 0;
11128}
11129
11130
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011131static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
11132 struct sigma_conn *conn,
11133 struct sigma_cmd *cmd)
11134{
11135 const char *intf = get_param(cmd, "Interface");
11136 const char *display = get_param(cmd, "Display");
11137 struct wpa_ctrl *ctrl;
11138 char buf[300], params[400], *pos;
11139 char bssid[20];
11140 int info_avail = 0;
11141 unsigned int old_timeout;
11142 int res;
11143
11144 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
11145 send_resp(dut, conn, SIGMA_ERROR,
11146 "ErrorCode,Could not get current BSSID");
11147 return 0;
11148 }
11149 ctrl = open_wpa_mon(intf);
11150 if (!ctrl) {
11151 sigma_dut_print(dut, DUT_MSG_ERROR,
11152 "Failed to open wpa_supplicant monitor connection");
11153 return -2;
11154 }
11155
11156 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
11157 wpa_command(intf, buf);
11158
11159 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
11160 if (res < 0) {
11161 send_resp(dut, conn, SIGMA_ERROR,
11162 "ErrorCode,Could not complete GAS query");
11163 goto fail;
11164 }
11165
11166 old_timeout = dut->default_timeout;
11167 dut->default_timeout = 2;
11168 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
11169 dut->default_timeout = old_timeout;
11170 if (res < 0)
11171 goto done;
11172 pos = strchr(buf, ' ');
11173 if (!pos)
11174 goto done;
11175 pos++;
11176 pos = strchr(pos, ' ');
11177 if (!pos)
11178 goto done;
11179 pos++;
11180 info_avail = 1;
11181 snprintf(params, sizeof(params), "browser %s", pos);
11182
11183 if (display && strcasecmp(display, "Yes") == 0) {
11184 pid_t pid;
11185
11186 pid = fork();
11187 if (pid < 0) {
11188 perror("fork");
11189 return -1;
11190 }
11191
11192 if (pid == 0) {
11193 run_hs20_osu(dut, params);
11194 exit(0);
11195 }
11196 }
11197
11198done:
11199 snprintf(buf, sizeof(buf), "Info_available,%s",
11200 info_avail ? "Yes" : "No");
11201 send_resp(dut, conn, SIGMA_COMPLETE, buf);
11202fail:
11203 wpa_ctrl_detach(ctrl);
11204 wpa_ctrl_close(ctrl);
11205 return 0;
11206}
11207
11208
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011209static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
11210 struct sigma_conn *conn,
11211 const char *ifname,
11212 struct sigma_cmd *cmd)
11213{
11214 const char *val;
11215 int id;
11216
11217 id = add_cred(ifname);
11218 if (id < 0)
11219 return -2;
11220 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11221
11222 val = get_param(cmd, "prefer");
11223 if (val && atoi(val) > 0)
11224 set_cred(ifname, id, "priority", "1");
11225
11226 val = get_param(cmd, "REALM");
11227 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
11228 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11229 "realm");
11230 return 0;
11231 }
11232
11233 val = get_param(cmd, "HOME_FQDN");
11234 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
11235 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11236 "home_fqdn");
11237 return 0;
11238 }
11239
11240 val = get_param(cmd, "Username");
11241 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
11242 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11243 "username");
11244 return 0;
11245 }
11246
11247 val = get_param(cmd, "Password");
11248 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
11249 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11250 "password");
11251 return 0;
11252 }
11253
11254 val = get_param(cmd, "ROOT_CA");
11255 if (val) {
11256 char fname[200];
11257 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11258#ifdef __linux__
11259 if (!file_exists(fname)) {
11260 char msg[300];
11261 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
11262 "file (%s) not found", fname);
11263 send_resp(dut, conn, SIGMA_ERROR, msg);
11264 return 0;
11265 }
11266#endif /* __linux__ */
11267 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
11268 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11269 "not set root CA");
11270 return 0;
11271 }
11272 }
11273
11274 return 1;
11275}
11276
11277
11278static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
11279{
11280 FILE *in, *out;
11281 char buf[500];
11282 int found = 0;
11283
11284 in = fopen("devdetail.xml", "r");
11285 if (in == NULL)
11286 return -1;
11287 out = fopen("devdetail.xml.tmp", "w");
11288 if (out == NULL) {
11289 fclose(in);
11290 return -1;
11291 }
11292
11293 while (fgets(buf, sizeof(buf), in)) {
11294 char *pos = strstr(buf, "<IMSI>");
11295 if (pos) {
11296 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
11297 imsi);
11298 pos += 6;
11299 *pos = '\0';
11300 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
11301 found++;
11302 } else {
11303 fprintf(out, "%s", buf);
11304 }
11305 }
11306
11307 fclose(out);
11308 fclose(in);
11309 if (found)
11310 rename("devdetail.xml.tmp", "devdetail.xml");
11311 else
11312 unlink("devdetail.xml.tmp");
11313
11314 return 0;
11315}
11316
11317
11318static int sta_add_credential_sim(struct sigma_dut *dut,
11319 struct sigma_conn *conn,
11320 const char *ifname, struct sigma_cmd *cmd)
11321{
11322 const char *val, *imsi = NULL;
11323 int id;
11324 char buf[200];
11325 int res;
11326 const char *pos;
11327 size_t mnc_len;
11328 char plmn_mcc[4];
11329 char plmn_mnc[4];
11330
11331 id = add_cred(ifname);
11332 if (id < 0)
11333 return -2;
11334 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11335
11336 val = get_param(cmd, "prefer");
11337 if (val && atoi(val) > 0)
11338 set_cred(ifname, id, "priority", "1");
11339
11340 val = get_param(cmd, "PLMN_MCC");
11341 if (val == NULL) {
11342 send_resp(dut, conn, SIGMA_ERROR,
11343 "errorCode,Missing PLMN_MCC");
11344 return 0;
11345 }
11346 if (strlen(val) != 3) {
11347 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
11348 return 0;
11349 }
11350 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
11351
11352 val = get_param(cmd, "PLMN_MNC");
11353 if (val == NULL) {
11354 send_resp(dut, conn, SIGMA_ERROR,
11355 "errorCode,Missing PLMN_MNC");
11356 return 0;
11357 }
11358 if (strlen(val) != 2 && strlen(val) != 3) {
11359 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
11360 return 0;
11361 }
11362 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
11363
11364 val = get_param(cmd, "IMSI");
11365 if (val == NULL) {
11366 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
11367 "IMSI");
11368 return 0;
11369 }
11370
11371 imsi = pos = val;
11372
11373 if (strncmp(plmn_mcc, pos, 3) != 0) {
11374 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
11375 return 0;
11376 }
11377 pos += 3;
11378
11379 mnc_len = strlen(plmn_mnc);
11380 if (mnc_len < 2) {
11381 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
11382 return 0;
11383 }
11384
11385 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
11386 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
11387 return 0;
11388 }
11389 pos += mnc_len;
11390
11391 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
11392 if (res < 0 || res >= (int) sizeof(buf))
11393 return -1;
11394 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
11395 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11396 "not set IMSI");
11397 return 0;
11398 }
11399
11400 val = get_param(cmd, "Password");
11401 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
11402 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11403 "not set password");
11404 return 0;
11405 }
11406
Jouni Malinenba630452018-06-22 11:49:59 +030011407 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011408 /*
11409 * Set provisioning_sp for the test cases where SIM/USIM
11410 * provisioning is used.
11411 */
11412 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
11413 "wi-fi.org") < 0) {
11414 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11415 "not set provisioning_sp");
11416 return 0;
11417 }
11418
11419 update_devdetail_imsi(dut, imsi);
11420 }
11421
11422 return 1;
11423}
11424
11425
11426static int sta_add_credential_cert(struct sigma_dut *dut,
11427 struct sigma_conn *conn,
11428 const char *ifname,
11429 struct sigma_cmd *cmd)
11430{
11431 const char *val;
11432 int id;
11433
11434 id = add_cred(ifname);
11435 if (id < 0)
11436 return -2;
11437 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
11438
11439 val = get_param(cmd, "prefer");
11440 if (val && atoi(val) > 0)
11441 set_cred(ifname, id, "priority", "1");
11442
11443 val = get_param(cmd, "REALM");
11444 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
11445 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11446 "realm");
11447 return 0;
11448 }
11449
11450 val = get_param(cmd, "HOME_FQDN");
11451 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
11452 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11453 "home_fqdn");
11454 return 0;
11455 }
11456
11457 val = get_param(cmd, "Username");
11458 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
11459 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
11460 "username");
11461 return 0;
11462 }
11463
11464 val = get_param(cmd, "clientCertificate");
11465 if (val) {
11466 char fname[200];
11467 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11468#ifdef __linux__
11469 if (!file_exists(fname)) {
11470 char msg[300];
11471 snprintf(msg, sizeof(msg),
11472 "ErrorCode,clientCertificate "
11473 "file (%s) not found", fname);
11474 send_resp(dut, conn, SIGMA_ERROR, msg);
11475 return 0;
11476 }
11477#endif /* __linux__ */
11478 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
11479 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11480 "not set client_cert");
11481 return 0;
11482 }
11483 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
11484 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11485 "not set private_key");
11486 return 0;
11487 }
11488 }
11489
11490 val = get_param(cmd, "ROOT_CA");
11491 if (val) {
11492 char fname[200];
11493 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
11494#ifdef __linux__
11495 if (!file_exists(fname)) {
11496 char msg[300];
11497 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
11498 "file (%s) not found", fname);
11499 send_resp(dut, conn, SIGMA_ERROR, msg);
11500 return 0;
11501 }
11502#endif /* __linux__ */
11503 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
11504 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
11505 "not set root CA");
11506 return 0;
11507 }
11508 }
11509
11510 return 1;
11511}
11512
11513
11514static int cmd_sta_add_credential(struct sigma_dut *dut,
11515 struct sigma_conn *conn,
11516 struct sigma_cmd *cmd)
11517{
11518 const char *intf = get_param(cmd, "Interface");
11519 const char *type;
11520
11521 start_sta_mode(dut);
11522
11523 type = get_param(cmd, "Type");
11524 if (!type)
11525 return -1;
11526
11527 if (strcasecmp(type, "uname_pwd") == 0)
11528 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
11529
11530 if (strcasecmp(type, "sim") == 0)
11531 return sta_add_credential_sim(dut, conn, intf, cmd);
11532
11533 if (strcasecmp(type, "cert") == 0)
11534 return sta_add_credential_cert(dut, conn, intf, cmd);
11535
11536 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
11537 "type");
11538 return 0;
11539}
11540
11541
11542static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
11543 struct sigma_cmd *cmd)
11544{
11545 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053011546 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011547 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +053011548 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011549 int res;
11550
11551 val = get_param(cmd, "HESSID");
11552 if (val) {
11553 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
11554 if (res < 0 || res >= (int) sizeof(buf))
11555 return -1;
11556 wpa_command(intf, buf);
11557 }
11558
11559 val = get_param(cmd, "ACCS_NET_TYPE");
11560 if (val) {
11561 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
11562 val);
11563 if (res < 0 || res >= (int) sizeof(buf))
11564 return -1;
11565 wpa_command(intf, buf);
11566 }
11567
vamsi krishna89ad8c62017-09-19 12:51:18 +053011568 bssid = get_param(cmd, "Bssid");
11569 ssid = get_param(cmd, "Ssid");
11570
11571 if (ssid) {
11572 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
11573 send_resp(dut, conn, SIGMA_ERROR,
11574 "ErrorCode,Too long SSID");
11575 return 0;
11576 }
11577 ascii2hexstr(ssid, ssid_hex);
11578 }
11579
11580 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
11581 bssid ? " bssid=": "",
11582 bssid ? bssid : "",
11583 ssid ? " ssid " : "",
11584 ssid ? ssid_hex : "");
11585 if (res < 0 || res >= (int) sizeof(buf))
11586 return -1;
11587
11588 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011589 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
11590 "scan");
11591 return 0;
11592 }
11593
11594 return 1;
11595}
11596
11597
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011598static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
11599 struct sigma_cmd *cmd)
11600{
11601 const char *intf = get_param(cmd, "Interface");
11602 const char *bssid;
11603 char buf[4096], *pos;
11604 int freq, chan;
11605 char *ssid;
11606 char resp[100];
11607 int res;
11608 struct wpa_ctrl *ctrl;
11609
11610 bssid = get_param(cmd, "BSSID");
11611 if (!bssid) {
11612 send_resp(dut, conn, SIGMA_INVALID,
11613 "errorCode,BSSID argument is missing");
11614 return 0;
11615 }
11616
11617 ctrl = open_wpa_mon(intf);
11618 if (!ctrl) {
11619 sigma_dut_print(dut, DUT_MSG_ERROR,
11620 "Failed to open wpa_supplicant monitor connection");
11621 return -1;
11622 }
11623
11624 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
11625 send_resp(dut, conn, SIGMA_ERROR,
11626 "errorCode,Could not start scan");
11627 wpa_ctrl_detach(ctrl);
11628 wpa_ctrl_close(ctrl);
11629 return 0;
11630 }
11631
11632 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11633 buf, sizeof(buf));
11634
11635 wpa_ctrl_detach(ctrl);
11636 wpa_ctrl_close(ctrl);
11637
11638 if (res < 0) {
11639 send_resp(dut, conn, SIGMA_ERROR,
11640 "errorCode,Scan did not complete");
11641 return 0;
11642 }
11643
11644 snprintf(buf, sizeof(buf), "BSS %s", bssid);
11645 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
11646 strncmp(buf, "id=", 3) != 0) {
11647 send_resp(dut, conn, SIGMA_ERROR,
11648 "errorCode,Specified BSSID not found");
11649 return 0;
11650 }
11651
11652 pos = strstr(buf, "\nfreq=");
11653 if (!pos) {
11654 send_resp(dut, conn, SIGMA_ERROR,
11655 "errorCode,Channel not found");
11656 return 0;
11657 }
11658 freq = atoi(pos + 6);
11659 chan = freq_to_channel(freq);
11660
11661 pos = strstr(buf, "\nssid=");
11662 if (!pos) {
11663 send_resp(dut, conn, SIGMA_ERROR,
11664 "errorCode,SSID not found");
11665 return 0;
11666 }
11667 ssid = pos + 6;
11668 pos = strchr(ssid, '\n');
11669 if (pos)
11670 *pos = '\0';
11671 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
11672 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11673 return 0;
11674}
11675
11676
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011677static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
11678 struct sigma_cmd *cmd)
11679{
11680#ifdef __linux__
11681 struct timeval tv;
11682 struct tm tm;
11683 time_t t;
11684 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011685 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011686
11687 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
11688
11689 memset(&tm, 0, sizeof(tm));
11690 val = get_param(cmd, "seconds");
11691 if (val)
11692 tm.tm_sec = atoi(val);
11693 val = get_param(cmd, "minutes");
11694 if (val)
11695 tm.tm_min = atoi(val);
11696 val = get_param(cmd, "hours");
11697 if (val)
11698 tm.tm_hour = atoi(val);
11699 val = get_param(cmd, "date");
11700 if (val)
11701 tm.tm_mday = atoi(val);
11702 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011703 if (val) {
11704 v = atoi(val);
11705 if (v < 1 || v > 12) {
11706 send_resp(dut, conn, SIGMA_INVALID,
11707 "errorCode,Invalid month");
11708 return 0;
11709 }
11710 tm.tm_mon = v - 1;
11711 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011712 val = get_param(cmd, "year");
11713 if (val) {
11714 int year = atoi(val);
11715#ifdef ANDROID
11716 if (year > 2035)
11717 year = 2035; /* years beyond 2035 not supported */
11718#endif /* ANDROID */
11719 tm.tm_year = year - 1900;
11720 }
11721 t = mktime(&tm);
11722 if (t == (time_t) -1) {
11723 send_resp(dut, conn, SIGMA_ERROR,
11724 "errorCode,Invalid date or time");
11725 return 0;
11726 }
11727
11728 memset(&tv, 0, sizeof(tv));
11729 tv.tv_sec = t;
11730
11731 if (settimeofday(&tv, NULL) < 0) {
11732 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
11733 strerror(errno));
11734 send_resp(dut, conn, SIGMA_ERROR,
11735 "errorCode,Failed to set time");
11736 return 0;
11737 }
11738
11739 return 1;
11740#endif /* __linux__ */
11741
11742 return -1;
11743}
11744
11745
11746static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
11747 struct sigma_cmd *cmd)
11748{
11749 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011750 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011751 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011752 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011753 int res;
11754 struct wpa_ctrl *ctrl;
11755
11756 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011757 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011758
11759 val = get_param(cmd, "ProdESSAssoc");
11760 if (val)
11761 prod_ess_assoc = atoi(val);
11762
11763 kill_dhcp_client(dut, intf);
11764 if (start_dhcp_client(dut, intf) < 0)
11765 return -2;
11766
11767 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
11768 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11769 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011770 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011771 prod_ess_assoc ? "" : "-N",
11772 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011773 name ? "'" : "",
11774 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
11775 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011776
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053011777 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011778 if (run_hs20_osu(dut, buf) < 0) {
11779 FILE *f;
11780
11781 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
11782
11783 f = fopen("hs20-osu-client.res", "r");
11784 if (f) {
11785 char resp[400], res[300], *pos;
11786 if (!fgets(res, sizeof(res), f))
11787 res[0] = '\0';
11788 pos = strchr(res, '\n');
11789 if (pos)
11790 *pos = '\0';
11791 fclose(f);
11792 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
11793 res);
11794 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
11795 if (system(resp) != 0) {
11796 }
11797 snprintf(resp, sizeof(resp),
11798 "SSID,,BSSID,,failureReason,%s", res);
11799 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11800 return 0;
11801 }
11802
11803 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11804 return 0;
11805 }
11806
11807 if (!prod_ess_assoc)
11808 goto report;
11809
11810 ctrl = open_wpa_mon(intf);
11811 if (ctrl == NULL) {
11812 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11813 "wpa_supplicant monitor connection");
11814 return -1;
11815 }
11816
11817 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11818 buf, sizeof(buf));
11819
11820 wpa_ctrl_detach(ctrl);
11821 wpa_ctrl_close(ctrl);
11822
11823 if (res < 0) {
11824 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
11825 "network after OSU");
11826 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11827 return 0;
11828 }
11829
11830report:
11831 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11832 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11833 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
11834 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11835 return 0;
11836 }
11837
11838 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
11839 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011840 return 0;
11841}
11842
11843
11844static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
11845 struct sigma_cmd *cmd)
11846{
11847 const char *val;
11848 int timeout = 120;
11849
11850 val = get_param(cmd, "PolicyUpdate");
11851 if (val == NULL || atoi(val) == 0)
11852 return 1; /* No operation requested */
11853
11854 val = get_param(cmd, "Timeout");
11855 if (val)
11856 timeout = atoi(val);
11857
11858 if (timeout) {
11859 /* TODO: time out the command and return
11860 * PolicyUpdateStatus,TIMEOUT if needed. */
11861 }
11862
11863 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
11864 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11865 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
11866 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
11867 return 0;
11868 }
11869
11870 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
11871 return 0;
11872}
11873
11874
11875static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
11876 struct sigma_cmd *cmd)
11877{
11878 struct wpa_ctrl *ctrl;
11879 const char *intf = get_param(cmd, "Interface");
11880 const char *bssid = get_param(cmd, "Bssid");
11881 const char *ssid = get_param(cmd, "SSID");
11882 const char *security = get_param(cmd, "Security");
11883 const char *passphrase = get_param(cmd, "Passphrase");
11884 const char *pin = get_param(cmd, "PIN");
11885 char buf[1000];
11886 char ssid_hex[200], passphrase_hex[200];
11887 const char *keymgmt, *cipher;
11888
11889 if (intf == NULL)
11890 intf = get_main_ifname();
11891
11892 if (!bssid) {
11893 send_resp(dut, conn, SIGMA_ERROR,
11894 "ErrorCode,Missing Bssid argument");
11895 return 0;
11896 }
11897
11898 if (!ssid) {
11899 send_resp(dut, conn, SIGMA_ERROR,
11900 "ErrorCode,Missing SSID argument");
11901 return 0;
11902 }
11903
11904 if (!security) {
11905 send_resp(dut, conn, SIGMA_ERROR,
11906 "ErrorCode,Missing Security argument");
11907 return 0;
11908 }
11909
11910 if (!passphrase) {
11911 send_resp(dut, conn, SIGMA_ERROR,
11912 "ErrorCode,Missing Passphrase argument");
11913 return 0;
11914 }
11915
11916 if (!pin) {
11917 send_resp(dut, conn, SIGMA_ERROR,
11918 "ErrorCode,Missing PIN argument");
11919 return 0;
11920 }
11921
vamsi krishna8c9c1562017-05-12 15:51:46 +053011922 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
11923 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011924 send_resp(dut, conn, SIGMA_ERROR,
11925 "ErrorCode,Too long SSID/passphrase");
11926 return 0;
11927 }
11928
11929 ctrl = open_wpa_mon(intf);
11930 if (ctrl == NULL) {
11931 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11932 "wpa_supplicant monitor connection");
11933 return -2;
11934 }
11935
11936 if (strcasecmp(security, "wpa2-psk") == 0) {
11937 keymgmt = "WPA2PSK";
11938 cipher = "CCMP";
11939 } else {
11940 wpa_ctrl_detach(ctrl);
11941 wpa_ctrl_close(ctrl);
11942 send_resp(dut, conn, SIGMA_ERROR,
11943 "ErrorCode,Unsupported Security value");
11944 return 0;
11945 }
11946
11947 ascii2hexstr(ssid, ssid_hex);
11948 ascii2hexstr(passphrase, passphrase_hex);
11949 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
11950 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
11951
11952 if (wpa_command(intf, buf) < 0) {
11953 wpa_ctrl_detach(ctrl);
11954 wpa_ctrl_close(ctrl);
11955 send_resp(dut, conn, SIGMA_ERROR,
11956 "ErrorCode,Failed to start registrar");
11957 return 0;
11958 }
11959
11960 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
11961 dut->er_oper_performed = 1;
11962
11963 return wps_connection_event(dut, conn, ctrl, intf, 0);
11964}
11965
11966
11967static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
11968 struct sigma_conn *conn,
11969 struct sigma_cmd *cmd)
11970{
11971 struct wpa_ctrl *ctrl;
11972 const char *intf = get_param(cmd, "Interface");
11973 const char *bssid = get_param(cmd, "Bssid");
11974 char buf[100];
11975
11976 if (!bssid) {
11977 send_resp(dut, conn, SIGMA_ERROR,
11978 "ErrorCode,Missing Bssid argument");
11979 return 0;
11980 }
11981
11982 ctrl = open_wpa_mon(intf);
11983 if (ctrl == NULL) {
11984 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11985 "wpa_supplicant monitor connection");
11986 return -2;
11987 }
11988
11989 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
11990
11991 if (wpa_command(intf, buf) < 0) {
11992 wpa_ctrl_detach(ctrl);
11993 wpa_ctrl_close(ctrl);
11994 send_resp(dut, conn, SIGMA_ERROR,
11995 "ErrorCode,Failed to start registrar");
11996 return 0;
11997 }
11998
11999 return wps_connection_event(dut, conn, ctrl, intf, 0);
12000}
12001
12002
vamsi krishna9b144002017-09-20 13:28:13 +053012003static int cmd_start_wps_registration(struct sigma_dut *dut,
12004 struct sigma_conn *conn,
12005 struct sigma_cmd *cmd)
12006{
12007 struct wpa_ctrl *ctrl;
12008 const char *intf = get_param(cmd, "Interface");
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012009 const char *network_mode = get_param(cmd, "network_mode");
vamsi krishna9b144002017-09-20 13:28:13 +053012010 const char *role, *method;
12011 int res;
12012 char buf[256];
12013 const char *events[] = {
12014 "CTRL-EVENT-CONNECTED",
12015 "WPS-OVERLAP-DETECTED",
12016 "WPS-TIMEOUT",
12017 "WPS-FAIL",
12018 NULL
12019 };
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012020 int id = 0;
vamsi krishna9b144002017-09-20 13:28:13 +053012021
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012022 /* 60G WPS tests do not pass Interface parameter */
12023 if (!intf)
12024 intf = get_main_ifname();
12025
Alexei Avshalom Lazard596b512018-12-18 16:00:59 +020012026 if (dut->band == WPS_BAND_60G && network_mode &&
12027 strcasecmp(network_mode, "PBSS") == 0) {
12028 sigma_dut_print(dut, DUT_MSG_DEBUG,
12029 "Set PBSS network mode, network id %d", id);
12030 if (set_network(get_station_ifname(), id, "pbss", "1") < 0)
12031 return -2;
12032 }
12033
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012034 if (dut->force_rsn_ie) {
12035 sigma_dut_print(dut, DUT_MSG_DEBUG, "Force RSN_IE: %d",
12036 dut->force_rsn_ie);
12037 if (sta_60g_force_rsn_ie(dut, dut->force_rsn_ie) < 0) {
12038 sigma_dut_print(dut, DUT_MSG_INFO,
12039 "Failed to force RSN_IE");
Jouni Malinen0e29cf22019-02-19 01:13:21 +020012040 return ERROR_SEND_STATUS;
Alexei Avshalom Lazarb094bf02018-12-18 16:00:53 +020012041 }
12042 }
12043
vamsi krishna9b144002017-09-20 13:28:13 +053012044 ctrl = open_wpa_mon(intf);
12045 if (!ctrl) {
12046 sigma_dut_print(dut, DUT_MSG_ERROR,
12047 "Failed to open wpa_supplicant monitor connection");
12048 return -2;
12049 }
12050
12051 role = get_param(cmd, "WpsRole");
12052 if (!role) {
12053 send_resp(dut, conn, SIGMA_INVALID,
12054 "ErrorCode,WpsRole not provided");
12055 goto fail;
12056 }
12057
12058 if (strcasecmp(role, "Enrollee") == 0) {
12059 method = get_param(cmd, "WpsConfigMethod");
12060 if (!method) {
12061 send_resp(dut, conn, SIGMA_INVALID,
12062 "ErrorCode,WpsConfigMethod not provided");
12063 goto fail;
12064 }
12065 if (strcasecmp(method, "PBC") == 0) {
12066 if (wpa_command(intf, "WPS_PBC") < 0) {
12067 send_resp(dut, conn, SIGMA_ERROR,
12068 "ErrorCode,Failed to enable PBC");
12069 goto fail;
12070 }
12071 } else {
12072 /* TODO: PIN method */
12073 send_resp(dut, conn, SIGMA_ERROR,
12074 "ErrorCode,Unsupported WpsConfigMethod value");
12075 goto fail;
12076 }
12077 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
12078 if (res < 0) {
12079 send_resp(dut, conn, SIGMA_ERROR,
12080 "ErrorCode,WPS connection did not complete");
12081 goto fail;
12082 }
12083 if (strstr(buf, "WPS-TIMEOUT")) {
12084 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
12085 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
12086 send_resp(dut, conn, SIGMA_ERROR,
12087 "ErrorCode,OverlapSession");
12088 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
12089 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
12090 } else {
12091 send_resp(dut, conn, SIGMA_ERROR,
12092 "ErrorCode,WPS operation failed");
12093 }
12094 } else {
12095 /* TODO: Registrar role */
12096 send_resp(dut, conn, SIGMA_ERROR,
12097 "ErrorCode,Unsupported WpsRole value");
12098 }
12099
12100fail:
12101 wpa_ctrl_detach(ctrl);
12102 wpa_ctrl_close(ctrl);
12103 return 0;
12104}
12105
12106
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012107static int req_intf(struct sigma_cmd *cmd)
12108{
12109 return get_param(cmd, "interface") == NULL ? -1 : 0;
12110}
12111
12112
12113void sta_register_cmds(void)
12114{
12115 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
12116 cmd_sta_get_ip_config);
12117 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
12118 cmd_sta_set_ip_config);
12119 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
12120 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
12121 cmd_sta_get_mac_address);
12122 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
12123 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
12124 cmd_sta_verify_ip_connection);
12125 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
12126 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
12127 cmd_sta_set_encryption);
12128 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
12129 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
12130 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
12131 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
12132 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
12133 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
12134 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
12135 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
12136 cmd_sta_set_eapakaprime);
12137 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
12138 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
12139 /* TODO: sta_set_ibss */
12140 /* TODO: sta_set_mode */
12141 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
12142 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
12143 /* TODO: sta_up_load */
12144 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
12145 cmd_sta_preset_testparameters);
12146 /* TODO: sta_set_system */
12147 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
12148 /* TODO: sta_set_rifs_test */
12149 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
12150 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
12151 /* TODO: sta_send_coexist_mgmt */
12152 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
12153 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
12154 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
12155 sigma_dut_reg_cmd("sta_reset_default", req_intf,
12156 cmd_sta_reset_default);
12157 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
12158 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
12159 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
12160 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
12161 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
Alexei Avshalom Lazare49e3872018-12-23 17:26:57 +020012162 sigma_dut_reg_cmd("sta_set_power_save", req_intf, cmd_sta_set_pwrsave);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012163 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
12164 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
12165 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
12166 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
12167 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030012168 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
12169 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012170 sigma_dut_reg_cmd("sta_add_credential", req_intf,
12171 cmd_sta_add_credential);
12172 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020012173 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012174 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
12175 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
12176 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
12177 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
12178 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
12179 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030012180 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012181 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
12182 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
Alexei Avshalom Lazar35ab3832018-12-23 16:49:49 +020012183 sigma_dut_reg_cmd("start_wps_registration", NULL,
vamsi krishna9b144002017-09-20 13:28:13 +053012184 cmd_start_wps_registration);
Kiran Kumar Lokeree580c012019-01-03 17:08:53 -080012185 sigma_dut_reg_cmd("sta_set_power_save", req_intf,
12186 cmd_sta_set_power_save);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020012187}