blob: 9dabda860e4b113330ac459bce403371b4d942d7 [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
65#define WIL_WMI_BF_TRIG_CMDID 0x83a
66
67struct wil_wmi_header {
68 uint8_t mid;
69 uint8_t reserved;
70 uint16_t cmd;
71 uint32_t ts;
72} __attribute__((packed));
73
74enum wil_wmi_bf_trig_type {
75 WIL_WMI_SLS,
76 WIL_WMI_BRP_RX,
77 WIL_WMI_BRP_TX,
78};
79
80struct wil_wmi_bf_trig_cmd {
81 /* enum wil_wmi_bf_trig_type */
82 uint32_t bf_type;
83 /* cid when type == WMI_BRP_RX */
84 uint32_t sta_id;
85 uint32_t reserved;
86 /* mac address when type = WIL_WMI_SLS */
87 uint8_t dest_mac[6];
88} __attribute__((packed));
89#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020090
91#ifdef ANDROID
92
93static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
94
95#define ANDROID_KEYSTORE_GET 'g'
96#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
97
98static int android_keystore_get(char cmd, const char *key, unsigned char *val)
99{
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200100 /* Android 4.3 changed keystore design, so need to use keystore_get() */
101#ifndef KEYSTORE_MESSAGE_SIZE
102#define KEYSTORE_MESSAGE_SIZE 65535
103#endif /* KEYSTORE_MESSAGE_SIZE */
104
105 ssize_t len;
106 uint8_t *value = NULL;
107
108 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
109 "keystore command '%c' key '%s' --> keystore_get",
110 cmd, key);
111
112 len = keystore_get(key, strlen(key), &value);
113 if (len < 0) {
114 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
115 "keystore_get() failed");
116 return -1;
117 }
118
119 if (len > KEYSTORE_MESSAGE_SIZE)
120 len = KEYSTORE_MESSAGE_SIZE;
121 memcpy(val, value, len);
122 free(value);
123 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200124}
125#endif /* ANDROID */
126
127
128int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
129{
130#ifdef __linux__
131 char buf[100];
132
133 if (wifi_chip_type == DRIVER_WCN) {
134 if (enabled) {
135 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530136 if (system(buf) != 0)
137 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200138 } else {
139 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530140 if (system(buf) != 0)
141 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200142 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530143 if (system(buf) != 0)
144 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200145 }
146
147 return 0;
148 }
149
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530150set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200151 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
152 intf, enabled ? "on" : "off");
153 if (system(buf) != 0) {
154 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
155 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530156 if (system(buf) != 0) {
157 sigma_dut_print(dut, DUT_MSG_ERROR,
158 "Failed to set power save %s",
159 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200160 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530161 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200162 }
163
164 return 0;
165#else /* __linux__ */
166 return -1;
167#endif /* __linux__ */
168}
169
170
Lior Davidcc88b562017-01-03 18:52:09 +0200171#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200172
Lior Davidcc88b562017-01-03 18:52:09 +0200173static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
174 size_t len)
175{
176 DIR *dir, *wil_dir;
177 struct dirent *entry;
178 int ret = -1;
179 const char *root_path = "/sys/kernel/debug/ieee80211";
180
181 dir = opendir(root_path);
182 if (!dir)
183 return -2;
184
185 while ((entry = readdir(dir))) {
186 if (strcmp(entry->d_name, ".") == 0 ||
187 strcmp(entry->d_name, "..") == 0)
188 continue;
189
190 if (snprintf(path, len, "%s/%s/wil6210",
191 root_path, entry->d_name) >= (int) len) {
192 ret = -3;
193 break;
194 }
195
196 wil_dir = opendir(path);
197 if (wil_dir) {
198 closedir(wil_dir);
199 ret = 0;
200 break;
201 }
202 }
203
204 closedir(dir);
205 return ret;
206}
Lior David0fe101e2017-03-09 16:09:50 +0200207
208
209static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
210 void *payload, uint16_t length)
211{
212 struct {
213 struct wil_wmi_header hdr;
214 char payload[WIL_WMI_MAX_PAYLOAD];
215 } __attribute__((packed)) cmd;
216 char buf[128], fname[128];
217 size_t towrite, written;
218 FILE *f;
219
220 if (length > WIL_WMI_MAX_PAYLOAD) {
221 sigma_dut_print(dut, DUT_MSG_ERROR,
222 "payload too large(%u, max %u)",
223 length, WIL_WMI_MAX_PAYLOAD);
224 return -1;
225 }
226
227 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
228 cmd.hdr.cmd = command;
229 memcpy(cmd.payload, payload, length);
230
231 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
232 sigma_dut_print(dut, DUT_MSG_ERROR,
233 "failed to get wil6210 debugfs dir");
234 return -1;
235 }
236
237 snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
238 f = fopen(fname, "wb");
239 if (!f) {
240 sigma_dut_print(dut, DUT_MSG_ERROR,
241 "failed to open: %s", fname);
242 return -1;
243 }
244
245 towrite = sizeof(cmd.hdr) + length;
246 written = fwrite(&cmd, 1, towrite, f);
247 fclose(f);
248 if (written != towrite) {
249 sigma_dut_print(dut, DUT_MSG_ERROR,
250 "failed to send wmi %u", command);
251 return -1;
252 }
253
254 return 0;
255}
256
257
258static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
259 const char *pattern, unsigned int *field)
260{
261 char buf[128], fname[128];
262 FILE *f;
263 regex_t re;
264 regmatch_t m[2];
265 int rc, ret = -1;
266
267 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
268 sigma_dut_print(dut, DUT_MSG_ERROR,
269 "failed to get wil6210 debugfs dir");
270 return -1;
271 }
272
273 snprintf(fname, sizeof(fname), "%s/stations", buf);
274 f = fopen(fname, "r");
275 if (!f) {
276 sigma_dut_print(dut, DUT_MSG_ERROR,
277 "failed to open: %s", fname);
278 return -1;
279 }
280
281 if (regcomp(&re, pattern, REG_EXTENDED)) {
282 sigma_dut_print(dut, DUT_MSG_ERROR,
283 "regcomp failed: %s", pattern);
284 goto out;
285 }
286
287 /*
288 * find the entry for the mac address
289 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
290 */
291 while (fgets(buf, sizeof(buf), f)) {
292 if (strcasestr(buf, bssid)) {
293 /* extract the field (CID/AID/state) */
294 rc = regexec(&re, buf, 2, m, 0);
295 if (!rc && (m[1].rm_so >= 0)) {
296 buf[m[1].rm_eo] = 0;
297 *field = atoi(&buf[m[1].rm_so]);
298 ret = 0;
299 break;
300 }
301 }
302 }
303
304 regfree(&re);
305 if (ret)
306 sigma_dut_print(dut, DUT_MSG_ERROR,
307 "could not extract field");
308
309out:
310 fclose(f);
311
312 return ret;
313}
314
315
316static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
317 unsigned int *cid)
318{
319 const char *pattern = "\\[([0-9]+)\\]";
320
321 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
322}
323
324
325static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
326 int l_rx)
327{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700328 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200329 unsigned int cid;
330
Rakesh Sunki556237d2017-03-30 14:49:31 -0700331 memset(&cmd, 0, sizeof(cmd));
332
Lior David0fe101e2017-03-09 16:09:50 +0200333 if (wil6210_get_cid(dut, mac, &cid))
334 return -1;
335
336 cmd.bf_type = WIL_WMI_BRP_RX;
337 cmd.sta_id = cid;
338 /* training length (l_rx) is ignored, FW always uses length 16 */
339 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
340 &cmd, sizeof(cmd));
341}
342
343
344static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
345{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700346 struct wil_wmi_bf_trig_cmd cmd;
347
348 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200349
350 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
351 return -1;
352
353 cmd.bf_type = WIL_WMI_SLS;
354 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
355 &cmd, sizeof(cmd));
356}
357
Lior Davidcc88b562017-01-03 18:52:09 +0200358#endif /* __linux__ */
359
360
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200361static void static_ip_file(int proto, const char *addr, const char *mask,
362 const char *gw)
363{
364 if (proto) {
365 FILE *f = fopen("static-ip", "w");
366 if (f) {
367 fprintf(f, "%d %s %s %s\n", proto, addr,
368 mask ? mask : "N/A",
369 gw ? gw : "N/A");
370 fclose(f);
371 }
372 } else {
373 unlink("static-ip");
374 }
375}
376
377
378static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
379 const char *ssid)
380{
381#ifdef __linux__
382 char buf[100];
383
384 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
385 intf, ssid);
386 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
387
388 if (system(buf) != 0) {
389 sigma_dut_print(dut, DUT_MSG_ERROR,
390 "iwpriv neighbor request failed");
391 return -1;
392 }
393
394 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
395
396 return 0;
397#else /* __linux__ */
398 return -1;
399#endif /* __linux__ */
400}
401
402
403static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
Ashwini Patil5acd7382017-04-13 15:55:04 +0530404 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200405{
Ashwini Patil5acd7382017-04-13 15:55:04 +0530406 const char *val;
407 int reason_code = 0;
408 char buf[1024];
409
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200410 /*
411 * In the earlier builds we used WNM_QUERY and in later
412 * builds used WNM_BSS_QUERY.
413 */
414
Ashwini Patil5acd7382017-04-13 15:55:04 +0530415 val = get_param(cmd, "BTMQuery_Reason_Code");
416 if (val)
417 reason_code = atoi(val);
418
419 val = get_param(cmd, "Cand_List");
420 if (val && atoi(val) == 1 && dut->btm_query_cand_list) {
421 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d%s", reason_code,
422 dut->btm_query_cand_list);
423 free(dut->btm_query_cand_list);
424 dut->btm_query_cand_list = NULL;
425 } else {
426 snprintf(buf, sizeof(buf), "WNM_BSS_QUERY %d", reason_code);
427 }
428
429 if (wpa_command(intf, buf) != 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200430 sigma_dut_print(dut, DUT_MSG_ERROR,
431 "transition management query failed");
432 return -1;
433 }
434
435 sigma_dut_print(dut, DUT_MSG_DEBUG,
436 "transition management query sent");
437
438 return 0;
439}
440
441
442int is_ip_addr(const char *str)
443{
444 const char *pos = str;
445 struct in_addr addr;
446
447 while (*pos) {
448 if (*pos != '.' && (*pos < '0' || *pos > '9'))
449 return 0;
450 pos++;
451 }
452
453 return inet_aton(str, &addr);
454}
455
456
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200457int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
458 size_t buf_len)
459{
vamsi krishnaa11d0732018-05-16 12:19:48 +0530460 char tmp[256];
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200461 char ip[16], mask[15], dns[16], sec_dns[16];
462 int is_dhcp = 0;
463 int s;
464#ifdef ANDROID
465 char prop[PROPERTY_VALUE_MAX];
vamsi krishnaa11d0732018-05-16 12:19:48 +0530466#else /* ANDROID */
467 FILE *f;
468#ifdef __linux__
469 const char *str_ps;
470#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200471#endif /* ANDROID */
472
473 ip[0] = '\0';
474 mask[0] = '\0';
475 dns[0] = '\0';
476 sec_dns[0] = '\0';
477
478 s = socket(PF_INET, SOCK_DGRAM, 0);
479 if (s >= 0) {
480 struct ifreq ifr;
481 struct sockaddr_in saddr;
482
483 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700484 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200485 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
486 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
487 "%s IP address: %s",
488 ifname, strerror(errno));
489 } else {
490 memcpy(&saddr, &ifr.ifr_addr,
491 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700492 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200493 }
494
495 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
496 memcpy(&saddr, &ifr.ifr_addr,
497 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -0700498 strlcpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200499 }
500 close(s);
501 }
502
503#ifdef ANDROID
504 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
505 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
506 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
507 if (property_get(tmp, prop, NULL) != 0 &&
508 strcmp(prop, "ok") == 0) {
509 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
510 ifname);
511 if (property_get(tmp, prop, NULL) != 0 &&
512 strcmp(ip, prop) == 0)
513 is_dhcp = 1;
514 }
515 }
516
517 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700518 if (property_get(tmp, prop, NULL) != 0)
519 strlcpy(dns, prop, sizeof(dns));
520 else if (property_get("net.dns1", prop, NULL) != 0)
521 strlcpy(dns, prop, sizeof(dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200522
523 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
Peng Xub8fc5cc2017-05-10 17:27:28 -0700524 if (property_get(tmp, prop, NULL) != 0)
525 strlcpy(sec_dns, prop, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200526#else /* ANDROID */
527#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530528 if (get_driver_type() == DRIVER_OPENWRT)
529 str_ps = "ps -w";
530 else
531 str_ps = "ps ax";
532 snprintf(tmp, sizeof(tmp),
533 "%s | grep dhclient | grep -v grep | grep -q %s",
534 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200535 if (system(tmp) == 0)
536 is_dhcp = 1;
537 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530538 snprintf(tmp, sizeof(tmp),
539 "%s | grep udhcpc | grep -v grep | grep -q %s",
540 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200541 if (system(tmp) == 0)
542 is_dhcp = 1;
543 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530544 snprintf(tmp, sizeof(tmp),
545 "%s | grep dhcpcd | grep -v grep | grep -q %s",
546 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200547 if (system(tmp) == 0)
548 is_dhcp = 1;
549 }
550 }
551#endif /* __linux__ */
552
553 f = fopen("/etc/resolv.conf", "r");
554 if (f) {
vamsi krishnaa11d0732018-05-16 12:19:48 +0530555 char *pos, *pos2;
556
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200557 while (fgets(tmp, sizeof(tmp), f)) {
558 if (strncmp(tmp, "nameserver", 10) != 0)
559 continue;
560 pos = tmp + 10;
561 while (*pos == ' ' || *pos == '\t')
562 pos++;
563 pos2 = pos;
564 while (*pos2) {
565 if (*pos2 == '\n' || *pos2 == '\r') {
566 *pos2 = '\0';
567 break;
568 }
569 pos2++;
570 }
Peng Xub8fc5cc2017-05-10 17:27:28 -0700571 if (!dns[0])
572 strlcpy(dns, pos, sizeof(dns));
573 else if (!sec_dns[0])
574 strlcpy(sec_dns, pos, sizeof(sec_dns));
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200575 }
576 fclose(f);
577 }
578#endif /* ANDROID */
579
580 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
581 is_dhcp, ip, mask, dns);
582 buf[buf_len - 1] = '\0';
583
584 return 0;
585}
586
587
588
589
590int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
591 size_t buf_len)
592{
593#ifdef __linux__
594#ifdef ANDROID
595 char cmd[200], result[1000], *pos, *end;
596 FILE *f;
597 size_t len;
598
599 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
600 f = popen(cmd, "r");
601 if (f == NULL)
602 return -1;
603 len = fread(result, 1, sizeof(result) - 1, f);
604 pclose(f);
605 if (len == 0)
606 return -1;
607 result[len] = '\0';
608 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
609
610 pos = strstr(result, "inet6 ");
611 if (pos == NULL)
612 return -1;
613 pos += 6;
614 end = strchr(pos, ' ');
615 if (end)
616 *end = '\0';
617 end = strchr(pos, '/');
618 if (end)
619 *end = '\0';
620 snprintf(buf, buf_len, "ip,%s", pos);
621 buf[buf_len - 1] = '\0';
622 return 0;
623#else /* ANDROID */
624 struct ifaddrs *ifaddr, *ifa;
625 int res, found = 0;
626 char host[NI_MAXHOST];
627
628 if (getifaddrs(&ifaddr) < 0) {
629 perror("getifaddrs");
630 return -1;
631 }
632
633 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
634 if (strcasecmp(ifname, ifa->ifa_name) != 0)
635 continue;
636 if (ifa->ifa_addr == NULL ||
637 ifa->ifa_addr->sa_family != AF_INET6)
638 continue;
639
640 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
641 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
642 if (res != 0) {
643 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
644 gai_strerror(res));
645 continue;
646 }
647 if (strncmp(host, "fe80::", 6) == 0)
648 continue; /* skip link-local */
649
650 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
651 found = 1;
652 break;
653 }
654
655 freeifaddrs(ifaddr);
656
657 if (found) {
658 char *pos;
659 pos = strchr(host, '%');
660 if (pos)
661 *pos = '\0';
662 snprintf(buf, buf_len, "ip,%s", host);
663 buf[buf_len - 1] = '\0';
664 return 0;
665 }
666
667#endif /* ANDROID */
668#endif /* __linux__ */
669 return -1;
670}
671
672
673static int cmd_sta_get_ip_config(struct sigma_dut *dut,
674 struct sigma_conn *conn,
675 struct sigma_cmd *cmd)
676{
677 const char *intf = get_param(cmd, "Interface");
678 const char *ifname;
679 char buf[200];
680 const char *val;
681 int type = 1;
682
683 if (intf == NULL)
684 return -1;
685
686 if (strcmp(intf, get_main_ifname()) == 0)
687 ifname = get_station_ifname();
688 else
689 ifname = intf;
690
691 /*
692 * UCC may assume the IP address to be available immediately after
693 * association without trying to run sta_get_ip_config multiple times.
694 * Sigma CAPI does not specify this command as a block command that
695 * would wait for the address to become available, but to pass tests
696 * more reliably, it looks like such a wait may be needed here.
697 */
698 if (wait_ip_addr(dut, ifname, 15) < 0) {
699 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
700 "for sta_get_ip_config");
701 /*
702 * Try to continue anyway since many UCC tests do not really
703 * care about the return value from here..
704 */
705 }
706
707 val = get_param(cmd, "Type");
708 if (val)
709 type = atoi(val);
710 if (type == 2 || dut->last_set_ip_config_ipv6) {
711 int i;
712
713 /*
714 * Since we do not have proper wait for IPv6 addresses, use a
715 * fixed two second delay here as a workaround for UCC script
716 * assuming IPv6 address is available when this command returns.
717 * Some scripts did not use Type,2 properly for IPv6, so include
718 * also the cases where the previous sta_set_ip_config indicated
719 * use of IPv6.
720 */
721 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
722 for (i = 0; i < 10; i++) {
723 sleep(1);
724 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
725 {
726 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
727 send_resp(dut, conn, SIGMA_COMPLETE, buf);
728#ifdef ANDROID
729 sigma_dut_print(dut, DUT_MSG_INFO,
730 "Adding IPv6 rule on Android");
731 add_ipv6_rule(dut, intf);
732#endif /* ANDROID */
733
734 return 0;
735 }
736 }
737 }
738 if (type == 1) {
739 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
740 return -2;
741 } else if (type == 2) {
742 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
743 return -2;
744 } else {
745 send_resp(dut, conn, SIGMA_ERROR,
746 "errorCode,Unsupported address type");
747 return 0;
748 }
749
750 send_resp(dut, conn, SIGMA_COMPLETE, buf);
751 return 0;
752}
753
754
755static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
756{
757#ifdef __linux__
758 char buf[200];
759 char path[128];
760 struct stat s;
761
762#ifdef ANDROID
763 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
764#else /* ANDROID */
765 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
766#endif /* ANDROID */
767 if (stat(path, &s) == 0) {
768 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
769 sigma_dut_print(dut, DUT_MSG_INFO,
770 "Kill previous DHCP client: %s", buf);
771 if (system(buf) != 0)
772 sigma_dut_print(dut, DUT_MSG_INFO,
773 "Failed to kill DHCP client");
774 unlink(path);
775 sleep(1);
776 } else {
777 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
778
779 if (stat(path, &s) == 0) {
780 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
781 sigma_dut_print(dut, DUT_MSG_INFO,
782 "Kill previous DHCP client: %s", buf);
783 if (system(buf) != 0)
784 sigma_dut_print(dut, DUT_MSG_INFO,
785 "Failed to kill DHCP client");
786 unlink(path);
787 sleep(1);
788 }
789 }
790#endif /* __linux__ */
791}
792
793
794static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
795{
796#ifdef __linux__
797 char buf[200];
798
799#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +0530800 if (access("/system/bin/dhcpcd", F_OK) != -1) {
801 snprintf(buf, sizeof(buf),
802 "/system/bin/dhcpcd -b %s", ifname);
803 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
804 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
805 } else {
806 sigma_dut_print(dut, DUT_MSG_ERROR,
807 "DHCP client program missing");
808 return 0;
809 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200810#else /* ANDROID */
811 snprintf(buf, sizeof(buf),
812 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
813 ifname, ifname);
814#endif /* ANDROID */
815 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
816 if (system(buf) != 0) {
817 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
818 if (system(buf) != 0) {
819 sigma_dut_print(dut, DUT_MSG_INFO,
820 "Failed to start DHCP client");
821#ifndef ANDROID
822 return -1;
823#endif /* ANDROID */
824 }
825 }
826#endif /* __linux__ */
827
828 return 0;
829}
830
831
832static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
833{
834#ifdef __linux__
835 char buf[200];
836
837 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
838 if (system(buf) != 0) {
839 sigma_dut_print(dut, DUT_MSG_INFO,
840 "Failed to clear IP addresses");
841 return -1;
842 }
843#endif /* __linux__ */
844
845 return 0;
846}
847
848
849#ifdef ANDROID
850static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
851{
852 char cmd[200], *result, *pos;
853 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530854 int tableid;
855 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200856
857 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
858 ifname);
859 fp = popen(cmd, "r");
860 if (fp == NULL)
861 return -1;
862
863 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530864 if (result == NULL) {
865 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200866 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530867 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200868
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530869 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200870 fclose(fp);
871
872 if (len == 0) {
873 free(result);
874 return -1;
875 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530876 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200877
878 pos = strstr(result, "table ");
879 if (pos == NULL) {
880 free(result);
881 return -1;
882 }
883
884 pos += strlen("table ");
885 tableid = atoi(pos);
886 if (tableid != 0) {
887 if (system("ip -6 rule del prio 22000") != 0) {
888 /* ignore any error */
889 }
890 snprintf(cmd, sizeof(cmd),
891 "ip -6 rule add from all lookup %d prio 22000",
892 tableid);
893 if (system(cmd) != 0) {
894 sigma_dut_print(dut, DUT_MSG_INFO,
895 "Failed to run %s", cmd);
896 free(result);
897 return -1;
898 }
899 } else {
900 sigma_dut_print(dut, DUT_MSG_INFO,
901 "No Valid Table Id found %s", pos);
902 free(result);
903 return -1;
904 }
905 free(result);
906
907 return 0;
908}
909#endif /* ANDROID */
910
911
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530912int set_ipv4_addr(struct sigma_dut *dut, const char *ifname,
913 const char *ip, const char *mask)
914{
915 char buf[200];
916
917 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
918 ifname, ip, mask);
919 return system(buf) == 0;
920}
921
922
923int set_ipv4_gw(struct sigma_dut *dut, const char *gw)
924{
925 char buf[200];
926
927 if (!is_ip_addr(gw)) {
928 sigma_dut_print(dut, DUT_MSG_DEBUG, "Invalid gw addr - %s", gw);
929 return -1;
930 }
931
932 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
933 if (!dut->no_ip_addr_set && system(buf) != 0) {
934 snprintf(buf, sizeof(buf), "ip ro re default via %s",
935 gw);
936 if (system(buf) != 0)
937 return 0;
938 }
939
940 return 1;
941}
942
943
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200944static int cmd_sta_set_ip_config(struct sigma_dut *dut,
945 struct sigma_conn *conn,
946 struct sigma_cmd *cmd)
947{
948 const char *intf = get_param(cmd, "Interface");
949 const char *ifname;
950 char buf[200];
951 const char *val, *ip, *mask, *gw;
952 int type = 1;
953
954 if (intf == NULL)
955 return -1;
956
957 if (strcmp(intf, get_main_ifname()) == 0)
958 ifname = get_station_ifname();
959 else
960 ifname = intf;
961
962 if (if_nametoindex(ifname) == 0) {
963 send_resp(dut, conn, SIGMA_ERROR,
964 "ErrorCode,Unknown interface");
965 return 0;
966 }
967
968 val = get_param(cmd, "Type");
969 if (val) {
970 type = atoi(val);
Ankita Bajaj1bde7942018-01-09 19:15:01 +0530971 if (type < 1 || type > 3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200972 send_resp(dut, conn, SIGMA_ERROR,
973 "ErrorCode,Unsupported address type");
974 return 0;
975 }
976 }
977
978 dut->last_set_ip_config_ipv6 = 0;
979
980 val = get_param(cmd, "dhcp");
981 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
982 static_ip_file(0, NULL, NULL, NULL);
983#ifdef __linux__
984 if (type == 2) {
985 dut->last_set_ip_config_ipv6 = 1;
986 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
987 "stateless address autoconfiguration");
988#ifdef ANDROID
989 /*
990 * This sleep is required as the assignment in case of
991 * Android is taking time and is done by the kernel.
992 * The subsequent ping for IPv6 is impacting HS20 test
993 * case.
994 */
995 sleep(2);
996 add_ipv6_rule(dut, intf);
997#endif /* ANDROID */
998 /* Assume this happens by default */
999 return 1;
1000 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301001 if (type != 3) {
1002 kill_dhcp_client(dut, ifname);
1003 if (start_dhcp_client(dut, ifname) < 0)
1004 return -2;
1005 } else {
1006 sigma_dut_print(dut, DUT_MSG_DEBUG,
1007 "Using FILS HLP DHCPv4 Rapid Commit");
1008 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001009
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001010 return 1;
1011#endif /* __linux__ */
1012 return -2;
1013 }
1014
1015 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301016 if (!ip) {
1017 send_resp(dut, conn, SIGMA_INVALID,
1018 "ErrorCode,Missing IP address");
1019 return 0;
1020 }
1021
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001022 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301023 if (!mask) {
1024 send_resp(dut, conn, SIGMA_INVALID,
1025 "ErrorCode,Missing subnet mask");
1026 return 0;
1027 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001028
1029 if (type == 2) {
1030 int net = atoi(mask);
1031
1032 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
1033 return -1;
1034
1035 if (dut->no_ip_addr_set) {
1036 snprintf(buf, sizeof(buf),
1037 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
1038 ifname);
1039 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1040 if (system(buf) != 0) {
1041 sigma_dut_print(dut, DUT_MSG_DEBUG,
1042 "Failed to disable IPv6 address before association");
1043 }
1044 } else {
1045 snprintf(buf, sizeof(buf),
1046 "ip -6 addr del %s/%s dev %s",
1047 ip, mask, ifname);
1048 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1049 if (system(buf) != 0) {
1050 /*
1051 * This command may fail if the address being
1052 * deleted does not exist. Inaction here is
1053 * intentional.
1054 */
1055 }
1056
1057 snprintf(buf, sizeof(buf),
1058 "ip -6 addr add %s/%s dev %s",
1059 ip, mask, ifname);
1060 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1061 if (system(buf) != 0) {
1062 send_resp(dut, conn, SIGMA_ERROR,
1063 "ErrorCode,Failed to set IPv6 address");
1064 return 0;
1065 }
1066 }
1067
1068 dut->last_set_ip_config_ipv6 = 1;
1069 static_ip_file(6, ip, mask, NULL);
1070 return 1;
1071 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301072 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001073 return -1;
1074 }
1075
1076 kill_dhcp_client(dut, ifname);
1077
1078 if (!dut->no_ip_addr_set) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301079 if (!set_ipv4_addr(dut, ifname, ip, mask)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001080 send_resp(dut, conn, SIGMA_ERROR,
1081 "ErrorCode,Failed to set IP address");
1082 return 0;
1083 }
1084 }
1085
1086 gw = get_param(cmd, "defaultGateway");
1087 if (gw) {
Ankita Bajaj1bde7942018-01-09 19:15:01 +05301088 if (set_ipv4_gw(dut, gw) < 1) {
1089 send_resp(dut, conn, SIGMA_ERROR,
1090 "ErrorCode,Failed to set default gateway");
1091 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001092 }
1093 }
1094
1095 val = get_param(cmd, "primary-dns");
1096 if (val) {
1097 /* TODO */
1098 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1099 "setting", val);
1100 }
1101
1102 val = get_param(cmd, "secondary-dns");
1103 if (val) {
1104 /* TODO */
1105 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1106 "setting", val);
1107 }
1108
1109 static_ip_file(4, ip, mask, gw);
1110
1111 return 1;
1112}
1113
1114
1115static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1116 struct sigma_cmd *cmd)
1117{
1118 /* const char *intf = get_param(cmd, "Interface"); */
1119 /* TODO: could report more details here */
1120 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1121 return 0;
1122}
1123
1124
1125static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1126 struct sigma_conn *conn,
1127 struct sigma_cmd *cmd)
1128{
1129 /* const char *intf = get_param(cmd, "Interface"); */
1130 char addr[20], resp[50];
1131
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05301132 if (dut->dev_role == DEVROLE_STA_CFON)
1133 return sta_cfon_get_mac_address(dut, conn, cmd);
1134
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001135 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1136 < 0)
1137 return -2;
1138
1139 snprintf(resp, sizeof(resp), "mac,%s", addr);
1140 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1141 return 0;
1142}
1143
1144
1145static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1146 struct sigma_cmd *cmd)
1147{
1148 /* const char *intf = get_param(cmd, "Interface"); */
1149 int connected = 0;
1150 char result[32];
1151 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1152 sizeof(result)) < 0) {
1153 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1154 "%s status", get_station_ifname());
1155 return -2;
1156 }
1157
1158 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1159 if (strncmp(result, "COMPLETED", 9) == 0)
1160 connected = 1;
1161
1162 if (connected)
1163 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1164 else
1165 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1166
1167 return 0;
1168}
1169
1170
1171static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1172 struct sigma_conn *conn,
1173 struct sigma_cmd *cmd)
1174{
1175 /* const char *intf = get_param(cmd, "Interface"); */
1176 const char *dst, *timeout;
1177 int wait_time = 90;
1178 char buf[100];
1179 int res;
1180
1181 dst = get_param(cmd, "destination");
1182 if (dst == NULL || !is_ip_addr(dst))
1183 return -1;
1184
1185 timeout = get_param(cmd, "timeout");
1186 if (timeout) {
1187 wait_time = atoi(timeout);
1188 if (wait_time < 1)
1189 wait_time = 1;
1190 }
1191
1192 /* TODO: force renewal of IP lease if DHCP is enabled */
1193
1194 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1195 res = system(buf);
1196 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1197 if (res == 0)
1198 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1199 else if (res == 256)
1200 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1201 else
1202 return -2;
1203
1204 return 0;
1205}
1206
1207
1208static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1209 struct sigma_cmd *cmd)
1210{
1211 /* const char *intf = get_param(cmd, "Interface"); */
1212 char bssid[20], resp[50];
1213
1214 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1215 < 0)
Peng Xub8fc5cc2017-05-10 17:27:28 -07001216 strlcpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001217
1218 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1219 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1220 return 0;
1221}
1222
1223
1224#ifdef __SAMSUNG__
1225static int add_use_network(const char *ifname)
1226{
1227 char buf[100];
1228
1229 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1230 wpa_command(ifname, buf);
1231 return 0;
1232}
1233#endif /* __SAMSUNG__ */
1234
1235
1236static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1237 const char *ifname, struct sigma_cmd *cmd)
1238{
1239 const char *ssid = get_param(cmd, "ssid");
1240 int id;
1241 const char *val;
1242
1243 if (ssid == NULL)
1244 return -1;
1245
1246 start_sta_mode(dut);
1247
1248#ifdef __SAMSUNG__
1249 add_use_network(ifname);
1250#endif /* __SAMSUNG__ */
1251
1252 id = add_network(ifname);
1253 if (id < 0)
1254 return -2;
1255 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1256
1257 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1258 return -2;
1259
1260 dut->infra_network_id = id;
1261 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1262
1263 val = get_param(cmd, "program");
1264 if (!val)
1265 val = get_param(cmd, "prog");
1266 if (val && strcasecmp(val, "hs2") == 0) {
1267 char buf[100];
1268 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1269 wpa_command(ifname, buf);
1270
1271 val = get_param(cmd, "prefer");
1272 if (val && atoi(val) > 0)
1273 set_network(ifname, id, "priority", "1");
1274 }
1275
1276 return id;
1277}
1278
1279
1280static int cmd_sta_set_encryption(struct sigma_dut *dut,
1281 struct sigma_conn *conn,
1282 struct sigma_cmd *cmd)
1283{
1284 const char *intf = get_param(cmd, "Interface");
1285 const char *ssid = get_param(cmd, "ssid");
1286 const char *type = get_param(cmd, "encpType");
1287 const char *ifname;
1288 char buf[200];
1289 int id;
1290
1291 if (intf == NULL || ssid == NULL)
1292 return -1;
1293
1294 if (strcmp(intf, get_main_ifname()) == 0)
1295 ifname = get_station_ifname();
1296 else
1297 ifname = intf;
1298
1299 id = add_network_common(dut, conn, ifname, cmd);
1300 if (id < 0)
1301 return id;
1302
1303 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1304 return -2;
1305
1306 if (type && strcasecmp(type, "wep") == 0) {
1307 const char *val;
1308 int i;
1309
1310 val = get_param(cmd, "activeKey");
1311 if (val) {
1312 int keyid;
1313 keyid = atoi(val);
1314 if (keyid < 1 || keyid > 4)
1315 return -1;
1316 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1317 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1318 return -2;
1319 }
1320
1321 for (i = 0; i < 4; i++) {
1322 snprintf(buf, sizeof(buf), "key%d", i + 1);
1323 val = get_param(cmd, buf);
1324 if (val == NULL)
1325 continue;
1326 snprintf(buf, sizeof(buf), "wep_key%d", i);
1327 if (set_network(ifname, id, buf, val) < 0)
1328 return -2;
1329 }
1330 }
1331
1332 return 1;
1333}
1334
1335
1336static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1337 const char *ifname, struct sigma_cmd *cmd)
1338{
1339 const char *val;
1340 int id;
Jouni Malinenad395a22017-09-01 21:13:46 +03001341 int cipher_set = 0;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001342 int owe;
Sunil Duttc75a1e62018-01-11 20:47:50 +05301343 int suite_b = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001344
1345 id = add_network_common(dut, conn, ifname, cmd);
1346 if (id < 0)
1347 return id;
1348
Jouni Malinen47dcc952017-10-09 16:43:24 +03001349 val = get_param(cmd, "Type");
1350 owe = val && strcasecmp(val, "OWE") == 0;
1351
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001352 val = get_param(cmd, "keyMgmtType");
Jouni Malinen47dcc952017-10-09 16:43:24 +03001353 if (!val && owe)
1354 val = "OWE";
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001355 if (val == NULL) {
1356 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1357 return 0;
1358 }
1359 if (strcasecmp(val, "wpa") == 0 ||
1360 strcasecmp(val, "wpa-psk") == 0) {
1361 if (set_network(ifname, id, "proto", "WPA") < 0)
1362 return -2;
1363 } else if (strcasecmp(val, "wpa2") == 0 ||
1364 strcasecmp(val, "wpa2-psk") == 0 ||
1365 strcasecmp(val, "wpa2-ft") == 0 ||
1366 strcasecmp(val, "wpa2-sha256") == 0) {
1367 if (set_network(ifname, id, "proto", "WPA2") < 0)
1368 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301369 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1370 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001371 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1372 return -2;
Jouni Malinenad395a22017-09-01 21:13:46 +03001373 } else if (strcasecmp(val, "SuiteB") == 0) {
Sunil Duttc75a1e62018-01-11 20:47:50 +05301374 suite_b = 1;
Jouni Malinenad395a22017-09-01 21:13:46 +03001375 if (set_network(ifname, id, "proto", "WPA2") < 0)
1376 return -2;
Jouni Malinen47dcc952017-10-09 16:43:24 +03001377 } else if (strcasecmp(val, "OWE") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001378 } else {
1379 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1380 return 0;
1381 }
1382
1383 val = get_param(cmd, "encpType");
Jouni Malinenad395a22017-09-01 21:13:46 +03001384 if (val) {
1385 cipher_set = 1;
1386 if (strcasecmp(val, "tkip") == 0) {
1387 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1388 return -2;
1389 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1390 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1391 return -2;
1392 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1393 if (set_network(ifname, id, "pairwise",
1394 "CCMP TKIP") < 0)
1395 return -2;
1396 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1397 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1398 return -2;
1399 if (set_network(ifname, id, "group", "GCMP") < 0)
1400 return -2;
1401 } else {
1402 send_resp(dut, conn, SIGMA_ERROR,
1403 "errorCode,Unrecognized encpType value");
1404 return 0;
1405 }
1406 }
1407
1408 val = get_param(cmd, "PairwiseCipher");
1409 if (val) {
1410 cipher_set = 1;
1411 /* TODO: Support space separated list */
1412 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1413 if (set_network(ifname, id, "pairwise", "GCMP-256") < 0)
1414 return -2;
1415 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1416 if (set_network(ifname, id, "pairwise",
1417 "CCMP-256") < 0)
1418 return -2;
1419 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1420 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1421 return -2;
1422 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1423 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1424 return -2;
1425 } else {
1426 send_resp(dut, conn, SIGMA_ERROR,
1427 "errorCode,Unrecognized PairwiseCipher value");
1428 return 0;
1429 }
1430 }
1431
Jouni Malinen47dcc952017-10-09 16:43:24 +03001432 if (!cipher_set && !owe) {
Jouni Malinenad395a22017-09-01 21:13:46 +03001433 send_resp(dut, conn, SIGMA_ERROR,
1434 "errorCode,Missing encpType and PairwiseCipher");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001435 return 0;
1436 }
Jouni Malinenad395a22017-09-01 21:13:46 +03001437
1438 val = get_param(cmd, "GroupCipher");
1439 if (val) {
1440 if (strcasecmp(val, "AES-GCMP-256") == 0) {
1441 if (set_network(ifname, id, "group", "GCMP-256") < 0)
1442 return -2;
1443 } else if (strcasecmp(val, "AES-CCMP-256") == 0) {
1444 if (set_network(ifname, id, "group", "CCMP-256") < 0)
1445 return -2;
1446 } else if (strcasecmp(val, "AES-GCMP-128") == 0) {
1447 if (set_network(ifname, id, "group", "GCMP") < 0)
1448 return -2;
1449 } else if (strcasecmp(val, "AES-CCMP-128") == 0) {
1450 if (set_network(ifname, id, "group", "CCMP") < 0)
1451 return -2;
1452 } else {
1453 send_resp(dut, conn, SIGMA_ERROR,
1454 "errorCode,Unrecognized GroupCipher value");
1455 return 0;
1456 }
1457 }
1458
Jouni Malinen7b239522017-09-14 21:37:18 +03001459 val = get_param(cmd, "GroupMgntCipher");
Jouni Malinenad395a22017-09-01 21:13:46 +03001460 if (val) {
Jouni Malinene8898cb2017-09-26 17:55:26 +03001461 const char *cipher;
1462
1463 if (strcasecmp(val, "BIP-GMAC-256") == 0) {
1464 cipher = "BIP-GMAC-256";
1465 } else if (strcasecmp(val, "BIP-CMAC-256") == 0) {
1466 cipher = "BIP-CMAC-256";
1467 } else if (strcasecmp(val, "BIP-GMAC-128") == 0) {
1468 cipher = "BIP-GMAC-128";
1469 } else if (strcasecmp(val, "BIP-CMAC-128") == 0) {
1470 cipher = "AES-128-CMAC";
1471 } else {
1472 send_resp(dut, conn, SIGMA_INVALID,
1473 "errorCode,Unsupported GroupMgntCipher");
1474 return 0;
1475 }
1476 if (set_network(ifname, id, "group_mgmt", cipher) < 0) {
1477 send_resp(dut, conn, SIGMA_INVALID,
1478 "errorCode,Failed to set GroupMgntCipher");
1479 return 0;
1480 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001481 }
1482
1483 dut->sta_pmf = STA_PMF_DISABLED;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301484
1485 if (dut->program == PROGRAM_OCE) {
1486 dut->sta_pmf = STA_PMF_OPTIONAL;
1487 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1488 return -2;
1489 }
1490
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001491 val = get_param(cmd, "PMF");
1492 if (val) {
1493 if (strcasecmp(val, "Required") == 0 ||
1494 strcasecmp(val, "Forced_Required") == 0) {
1495 dut->sta_pmf = STA_PMF_REQUIRED;
1496 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1497 return -2;
1498 } else if (strcasecmp(val, "Optional") == 0) {
1499 dut->sta_pmf = STA_PMF_OPTIONAL;
1500 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1501 return -2;
1502 } else if (strcasecmp(val, "Disabled") == 0 ||
1503 strcasecmp(val, "Forced_Disabled") == 0) {
1504 dut->sta_pmf = STA_PMF_DISABLED;
1505 } else {
1506 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1507 return 0;
1508 }
Sunil Duttc75a1e62018-01-11 20:47:50 +05301509 } else if (owe || suite_b) {
Jouni Malinen1287cd72018-01-04 17:08:01 +02001510 dut->sta_pmf = STA_PMF_REQUIRED;
1511 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1512 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001513 }
1514
1515 return id;
1516}
1517
1518
1519static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1520 struct sigma_cmd *cmd)
1521{
1522 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03001523 const char *type = get_param(cmd, "Type");
Jouni Malinen1287cd72018-01-04 17:08:01 +02001524 const char *pmf = get_param(cmd, "PMF");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001525 const char *ifname, *val, *alg;
1526 int id;
1527
1528 if (intf == NULL)
1529 return -1;
1530
1531 if (strcmp(intf, get_main_ifname()) == 0)
1532 ifname = get_station_ifname();
1533 else
1534 ifname = intf;
1535
1536 id = set_wpa_common(dut, conn, ifname, cmd);
1537 if (id < 0)
1538 return id;
1539
1540 val = get_param(cmd, "keyMgmtType");
1541 alg = get_param(cmd, "micAlg");
1542
Jouni Malinen992a81e2017-08-22 13:57:47 +03001543 if (type && strcasecmp(type, "SAE") == 0) {
1544 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1545 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
1546 return -2;
1547 } else {
1548 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
1549 return -2;
1550 }
1551 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1552 sigma_dut_print(dut, DUT_MSG_ERROR,
1553 "Failed to clear sae_groups to default");
1554 return -2;
1555 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001556 if (!pmf) {
1557 dut->sta_pmf = STA_PMF_REQUIRED;
1558 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1559 return -2;
1560 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001561 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
1562 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1563 if (set_network(ifname, id, "key_mgmt",
1564 "FT-SAE FT-PSK") < 0)
1565 return -2;
1566 } else {
1567 if (set_network(ifname, id, "key_mgmt",
1568 "SAE WPA-PSK") < 0)
1569 return -2;
1570 }
1571 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1572 sigma_dut_print(dut, DUT_MSG_ERROR,
1573 "Failed to clear sae_groups to default");
1574 return -2;
1575 }
Jouni Malinen1287cd72018-01-04 17:08:01 +02001576 if (!pmf) {
1577 dut->sta_pmf = STA_PMF_OPTIONAL;
1578 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1579 return -2;
1580 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03001581 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001582 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1583 return -2;
1584 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1585 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1586 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05301587 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1588 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
1589 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001590 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1591 dut->sta_pmf == STA_PMF_REQUIRED) {
1592 if (set_network(ifname, id, "key_mgmt",
1593 "WPA-PSK WPA-PSK-SHA256") < 0)
1594 return -2;
1595 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1596 if (set_network(ifname, id, "key_mgmt",
1597 "WPA-PSK WPA-PSK-SHA256") < 0)
1598 return -2;
1599 } else {
1600 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1601 return -2;
1602 }
1603
1604 val = get_param(cmd, "passPhrase");
1605 if (val == NULL)
1606 return -1;
Jouni Malinen2126f422017-10-11 23:24:33 +03001607 if (type && strcasecmp(type, "SAE") == 0) {
1608 if (set_network_quoted(ifname, id, "sae_password", val) < 0)
1609 return -2;
1610 } else {
1611 if (set_network_quoted(ifname, id, "psk", val) < 0)
1612 return -2;
1613 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001614
Jouni Malinen992a81e2017-08-22 13:57:47 +03001615 val = get_param(cmd, "ECGroupID");
1616 if (val) {
1617 char buf[50];
1618
1619 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
1620 if (wpa_command(ifname, buf) != 0) {
1621 sigma_dut_print(dut, DUT_MSG_ERROR,
1622 "Failed to clear sae_groups");
1623 return -2;
1624 }
1625 }
1626
Jouni Malinen68143132017-09-02 02:34:08 +03001627 val = get_param(cmd, "InvalidSAEElement");
1628 if (val) {
1629 free(dut->sae_commit_override);
1630 dut->sae_commit_override = strdup(val);
1631 }
1632
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001633 return 1;
1634}
1635
1636
1637static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301638 const char *ifname, int username_identity,
1639 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001640{
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301641 const char *val, *alg, *akm;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001642 int id;
1643 char buf[200];
1644#ifdef ANDROID
1645 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1646 int length;
1647#endif /* ANDROID */
1648
1649 id = set_wpa_common(dut, conn, ifname, cmd);
1650 if (id < 0)
1651 return id;
1652
1653 val = get_param(cmd, "keyMgmtType");
1654 alg = get_param(cmd, "micAlg");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301655 akm = get_param(cmd, "AKMSuiteType");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001656
Jouni Malinenad395a22017-09-01 21:13:46 +03001657 if (val && strcasecmp(val, "SuiteB") == 0) {
1658 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SUITE-B-192") <
1659 0)
1660 return -2;
1661 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001662 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1663 return -2;
1664 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1665 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1666 return -2;
1667 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1668 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1669 return -2;
1670 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1671 dut->sta_pmf == STA_PMF_REQUIRED) {
1672 if (set_network(ifname, id, "key_mgmt",
1673 "WPA-EAP WPA-EAP-SHA256") < 0)
1674 return -2;
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05301675 } else if (akm && atoi(akm) == 14) {
1676 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1677 dut->sta_pmf == STA_PMF_REQUIRED) {
1678 if (set_network(ifname, id, "key_mgmt",
1679 "WPA-EAP-SHA256 FILS-SHA256") < 0)
1680 return -2;
1681 } else {
1682 if (set_network(ifname, id, "key_mgmt",
1683 "WPA-EAP FILS-SHA256") < 0)
1684 return -2;
1685 }
1686
1687 if (set_network(ifname, id, "erp", "1") < 0)
1688 return -2;
1689 } else if (akm && atoi(akm) == 15) {
1690 if (dut->sta_pmf == STA_PMF_OPTIONAL ||
1691 dut->sta_pmf == STA_PMF_REQUIRED) {
1692 if (set_network(ifname, id, "key_mgmt",
1693 "WPA-EAP-SHA256 FILS-SHA384") < 0)
1694 return -2;
1695 } else {
1696 if (set_network(ifname, id, "key_mgmt",
1697 "WPA-EAP FILS-SHA384") < 0)
1698 return -2;
1699 }
1700
1701 if (set_network(ifname, id, "erp", "1") < 0)
1702 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001703 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1704 if (set_network(ifname, id, "key_mgmt",
1705 "WPA-EAP WPA-EAP-SHA256") < 0)
1706 return -2;
1707 } else {
1708 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1709 return -2;
1710 }
1711
1712 val = get_param(cmd, "trustedRootCA");
1713 if (val) {
1714#ifdef ANDROID
1715 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1716 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1717 kvalue);
1718 if (length > 0) {
1719 sigma_dut_print(dut, DUT_MSG_INFO,
1720 "Use Android keystore [%s]", buf);
1721 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1722 val);
1723 goto ca_cert_selected;
1724 }
1725#endif /* ANDROID */
1726
1727 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1728#ifdef __linux__
1729 if (!file_exists(buf)) {
1730 char msg[300];
1731 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1732 "file (%s) not found", buf);
1733 send_resp(dut, conn, SIGMA_ERROR, msg);
1734 return -3;
1735 }
1736#endif /* __linux__ */
1737#ifdef ANDROID
1738ca_cert_selected:
1739#endif /* ANDROID */
1740 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1741 return -2;
1742 }
1743
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301744 if (username_identity) {
1745 val = get_param(cmd, "username");
1746 if (val) {
1747 if (set_network_quoted(ifname, id, "identity", val) < 0)
1748 return -2;
1749 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001750
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301751 val = get_param(cmd, "password");
1752 if (val) {
1753 if (set_network_quoted(ifname, id, "password", val) < 0)
1754 return -2;
1755 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001756 }
1757
1758 return id;
1759}
1760
1761
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001762static int set_tls_cipher(const char *ifname, int id, const char *cipher)
1763{
1764 const char *val;
1765
1766 if (!cipher)
1767 return 0;
1768
1769 if (strcasecmp(cipher, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384") == 0)
1770 val = "ECDHE-ECDSA-AES256-GCM-SHA384";
1771 else if (strcasecmp(cipher,
1772 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1773 val = "ECDHE-RSA-AES256-GCM-SHA384";
1774 else if (strcasecmp(cipher, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384") == 0)
1775 val = "DHE-RSA-AES256-GCM-SHA384";
1776 else if (strcasecmp(cipher,
1777 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256") == 0)
1778 val = "ECDHE-ECDSA-AES128-GCM-SHA256";
1779 else
1780 return -1;
1781
1782 /* Need to clear phase1="tls_suiteb=1" to allow cipher enforcement */
1783 set_network_quoted(ifname, id, "phase1", "");
1784
1785 return set_network_quoted(ifname, id, "openssl_ciphers", val);
1786}
1787
1788
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001789static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1790 struct sigma_cmd *cmd)
1791{
1792 const char *intf = get_param(cmd, "Interface");
1793 const char *ifname, *val;
1794 int id;
1795 char buf[200];
1796#ifdef ANDROID
1797 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1798 int length;
1799 int jb_or_newer = 0;
1800 char prop[PROPERTY_VALUE_MAX];
1801#endif /* ANDROID */
1802
1803 if (intf == NULL)
1804 return -1;
1805
1806 if (strcmp(intf, get_main_ifname()) == 0)
1807 ifname = get_station_ifname();
1808 else
1809 ifname = intf;
1810
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301811 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001812 if (id < 0)
1813 return id;
1814
1815 if (set_network(ifname, id, "eap", "TLS") < 0)
1816 return -2;
1817
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301818 if (!get_param(cmd, "username") &&
1819 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001820 "wifi-user@wifilabs.local") < 0)
1821 return -2;
1822
1823 val = get_param(cmd, "clientCertificate");
1824 if (val == NULL)
1825 return -1;
1826#ifdef ANDROID
1827 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1828 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1829 if (length < 0) {
1830 /*
1831 * JB started reporting keystore type mismatches, so retry with
1832 * the GET_PUBKEY command if the generic GET fails.
1833 */
1834 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1835 buf, kvalue);
1836 }
1837
1838 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1839 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1840 if (strncmp(prop, "4.0", 3) != 0)
1841 jb_or_newer = 1;
1842 } else
1843 jb_or_newer = 1; /* assume newer */
1844
1845 if (jb_or_newer && length > 0) {
1846 sigma_dut_print(dut, DUT_MSG_INFO,
1847 "Use Android keystore [%s]", buf);
1848 if (set_network(ifname, id, "engine", "1") < 0)
1849 return -2;
1850 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
1851 return -2;
1852 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1853 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
1854 return -2;
1855 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1856 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1857 return -2;
1858 return 1;
1859 } else if (length > 0) {
1860 sigma_dut_print(dut, DUT_MSG_INFO,
1861 "Use Android keystore [%s]", buf);
1862 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
1863 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1864 return -2;
1865 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1866 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1867 return -2;
1868 return 1;
1869 }
1870#endif /* ANDROID */
1871
1872 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1873#ifdef __linux__
1874 if (!file_exists(buf)) {
1875 char msg[300];
1876 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
1877 "(%s) not found", buf);
1878 send_resp(dut, conn, SIGMA_ERROR, msg);
1879 return -3;
1880 }
1881#endif /* __linux__ */
1882 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1883 return -2;
1884 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1885 return -2;
1886
1887 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
1888 return -2;
1889
Jouni Malinen5eabb2a2017-10-03 18:17:30 +03001890 val = get_param(cmd, "keyMgmtType");
1891 if (val && strcasecmp(val, "SuiteB") == 0) {
1892 val = get_param(cmd, "CertType");
1893 if (val && strcasecmp(val, "RSA") == 0) {
1894 if (set_network_quoted(ifname, id, "phase1",
1895 "tls_suiteb=1") < 0)
1896 return -2;
1897 } else {
1898 if (set_network_quoted(ifname, id, "openssl_ciphers",
1899 "SUITEB192") < 0)
1900 return -2;
1901 }
1902
1903 val = get_param(cmd, "TLSCipher");
1904 if (set_tls_cipher(ifname, id, val) < 0) {
1905 send_resp(dut, conn, SIGMA_ERROR,
1906 "ErrorCode,Unsupported TLSCipher value");
1907 return -3;
1908 }
1909 }
1910
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001911 return 1;
1912}
1913
1914
1915static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
1916 struct sigma_cmd *cmd)
1917{
1918 const char *intf = get_param(cmd, "Interface");
1919 const char *ifname;
1920 int id;
1921
1922 if (intf == NULL)
1923 return -1;
1924
1925 if (strcmp(intf, get_main_ifname()) == 0)
1926 ifname = get_station_ifname();
1927 else
1928 ifname = intf;
1929
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301930 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001931 if (id < 0)
1932 return id;
1933
1934 if (set_network(ifname, id, "eap", "TTLS") < 0) {
1935 send_resp(dut, conn, SIGMA_ERROR,
1936 "errorCode,Failed to set TTLS method");
1937 return 0;
1938 }
1939
1940 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
1941 send_resp(dut, conn, SIGMA_ERROR,
1942 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
1943 return 0;
1944 }
1945
1946 return 1;
1947}
1948
1949
1950static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
1951 struct sigma_cmd *cmd)
1952{
1953 const char *intf = get_param(cmd, "Interface");
1954 const char *ifname;
1955 int id;
1956
1957 if (intf == NULL)
1958 return -1;
1959
1960 if (strcmp(intf, get_main_ifname()) == 0)
1961 ifname = get_station_ifname();
1962 else
1963 ifname = intf;
1964
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301965 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001966 if (id < 0)
1967 return id;
1968
1969 if (set_network(ifname, id, "eap", "SIM") < 0)
1970 return -2;
1971
1972 return 1;
1973}
1974
1975
1976static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
1977 struct sigma_cmd *cmd)
1978{
1979 const char *intf = get_param(cmd, "Interface");
1980 const char *ifname, *val;
1981 int id;
1982 char buf[100];
1983
1984 if (intf == NULL)
1985 return -1;
1986
1987 if (strcmp(intf, get_main_ifname()) == 0)
1988 ifname = get_station_ifname();
1989 else
1990 ifname = intf;
1991
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301992 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001993 if (id < 0)
1994 return id;
1995
1996 if (set_network(ifname, id, "eap", "PEAP") < 0)
1997 return -2;
1998
1999 val = get_param(cmd, "innerEAP");
2000 if (val) {
2001 if (strcasecmp(val, "MSCHAPv2") == 0) {
2002 if (set_network_quoted(ifname, id, "phase2",
2003 "auth=MSCHAPV2") < 0)
2004 return -2;
2005 } else if (strcasecmp(val, "GTC") == 0) {
2006 if (set_network_quoted(ifname, id, "phase2",
2007 "auth=GTC") < 0)
2008 return -2;
2009 } else
2010 return -1;
2011 }
2012
2013 val = get_param(cmd, "peapVersion");
2014 if (val) {
2015 int ver = atoi(val);
2016 if (ver < 0 || ver > 1)
2017 return -1;
2018 snprintf(buf, sizeof(buf), "peapver=%d", ver);
2019 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
2020 return -2;
2021 }
2022
2023 return 1;
2024}
2025
2026
2027static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
2028 struct sigma_cmd *cmd)
2029{
2030 const char *intf = get_param(cmd, "Interface");
2031 const char *ifname, *val;
2032 int id;
2033 char buf[100];
2034
2035 if (intf == NULL)
2036 return -1;
2037
2038 if (strcmp(intf, get_main_ifname()) == 0)
2039 ifname = get_station_ifname();
2040 else
2041 ifname = intf;
2042
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302043 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002044 if (id < 0)
2045 return id;
2046
2047 if (set_network(ifname, id, "eap", "FAST") < 0)
2048 return -2;
2049
2050 val = get_param(cmd, "innerEAP");
2051 if (val) {
2052 if (strcasecmp(val, "MSCHAPV2") == 0) {
2053 if (set_network_quoted(ifname, id, "phase2",
2054 "auth=MSCHAPV2") < 0)
2055 return -2;
2056 } else if (strcasecmp(val, "GTC") == 0) {
2057 if (set_network_quoted(ifname, id, "phase2",
2058 "auth=GTC") < 0)
2059 return -2;
2060 } else
2061 return -1;
2062 }
2063
2064 val = get_param(cmd, "validateServer");
2065 if (val) {
2066 /* TODO */
2067 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
2068 "validateServer=%s", val);
2069 }
2070
2071 val = get_param(cmd, "pacFile");
2072 if (val) {
2073 snprintf(buf, sizeof(buf), "blob://%s", val);
2074 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
2075 return -2;
2076 }
2077
2078 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
2079 0)
2080 return -2;
2081
2082 return 1;
2083}
2084
2085
2086static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
2087 struct sigma_cmd *cmd)
2088{
2089 const char *intf = get_param(cmd, "Interface");
2090 const char *ifname;
2091 int id;
2092
2093 if (intf == NULL)
2094 return -1;
2095
2096 if (strcmp(intf, get_main_ifname()) == 0)
2097 ifname = get_station_ifname();
2098 else
2099 ifname = intf;
2100
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302101 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002102 if (id < 0)
2103 return id;
2104
2105 if (set_network(ifname, id, "eap", "AKA") < 0)
2106 return -2;
2107
2108 return 1;
2109}
2110
2111
2112static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
2113 struct sigma_conn *conn,
2114 struct sigma_cmd *cmd)
2115{
2116 const char *intf = get_param(cmd, "Interface");
2117 const char *ifname;
2118 int id;
2119
2120 if (intf == NULL)
2121 return -1;
2122
2123 if (strcmp(intf, get_main_ifname()) == 0)
2124 ifname = get_station_ifname();
2125 else
2126 ifname = intf;
2127
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05302128 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002129 if (id < 0)
2130 return id;
2131
2132 if (set_network(ifname, id, "eap", "AKA'") < 0)
2133 return -2;
2134
2135 return 1;
2136}
2137
2138
2139static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
2140 struct sigma_cmd *cmd)
2141{
2142 const char *intf = get_param(cmd, "Interface");
2143 const char *ifname;
2144 int id;
2145
2146 if (strcmp(intf, get_main_ifname()) == 0)
2147 ifname = get_station_ifname();
2148 else
2149 ifname = intf;
2150
2151 id = add_network_common(dut, conn, ifname, cmd);
2152 if (id < 0)
2153 return id;
2154
2155 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
2156 return -2;
2157
2158 return 1;
2159}
2160
2161
Jouni Malinen47dcc952017-10-09 16:43:24 +03002162static int sta_set_owe(struct sigma_dut *dut, struct sigma_conn *conn,
2163 struct sigma_cmd *cmd)
2164{
2165 const char *intf = get_param(cmd, "Interface");
2166 const char *ifname, *val;
2167 int id;
2168
2169 if (intf == NULL)
2170 return -1;
2171
2172 if (strcmp(intf, get_main_ifname()) == 0)
2173 ifname = get_station_ifname();
2174 else
2175 ifname = intf;
2176
2177 id = set_wpa_common(dut, conn, ifname, cmd);
2178 if (id < 0)
2179 return id;
2180
2181 if (set_network(ifname, id, "key_mgmt", "OWE") < 0)
2182 return -2;
2183
2184 val = get_param(cmd, "ECGroupID");
Jouni Malinenfac9cad2017-10-10 18:35:55 +03002185 if (val && strcmp(val, "0") == 0) {
2186 if (wpa_command(ifname,
2187 "VENDOR_ELEM_ADD 13 ff23200000783590fb7440e03d5b3b33911f86affdcc6b4411b707846ac4ff08ddc8831ccd") != 0) {
2188 sigma_dut_print(dut, DUT_MSG_ERROR,
2189 "Failed to set OWE DH Param element override");
2190 return -2;
2191 }
2192 } else if (val && set_network(ifname, id, "owe_group", val) < 0) {
Jouni Malinen47dcc952017-10-09 16:43:24 +03002193 sigma_dut_print(dut, DUT_MSG_ERROR,
2194 "Failed to clear owe_group");
2195 return -2;
2196 }
2197
2198 return 1;
2199}
2200
2201
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002202static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
2203 struct sigma_cmd *cmd)
2204{
2205 const char *type = get_param(cmd, "Type");
2206
2207 if (type == NULL) {
2208 send_resp(dut, conn, SIGMA_ERROR,
2209 "ErrorCode,Missing Type argument");
2210 return 0;
2211 }
2212
2213 if (strcasecmp(type, "OPEN") == 0)
2214 return sta_set_open(dut, conn, cmd);
Jouni Malinen47dcc952017-10-09 16:43:24 +03002215 if (strcasecmp(type, "OWE") == 0)
2216 return sta_set_owe(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03002217 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03002218 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03002219 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002220 return cmd_sta_set_psk(dut, conn, cmd);
2221 if (strcasecmp(type, "EAPTLS") == 0)
2222 return cmd_sta_set_eaptls(dut, conn, cmd);
2223 if (strcasecmp(type, "EAPTTLS") == 0)
2224 return cmd_sta_set_eapttls(dut, conn, cmd);
2225 if (strcasecmp(type, "EAPPEAP") == 0)
2226 return cmd_sta_set_peap(dut, conn, cmd);
2227 if (strcasecmp(type, "EAPSIM") == 0)
2228 return cmd_sta_set_eapsim(dut, conn, cmd);
2229 if (strcasecmp(type, "EAPFAST") == 0)
2230 return cmd_sta_set_eapfast(dut, conn, cmd);
2231 if (strcasecmp(type, "EAPAKA") == 0)
2232 return cmd_sta_set_eapaka(dut, conn, cmd);
2233 if (strcasecmp(type, "EAPAKAPRIME") == 0)
2234 return cmd_sta_set_eapakaprime(dut, conn, cmd);
Amarnath Hullur Subramanyam81b11cd2018-01-30 19:07:17 -08002235 if (strcasecmp(type, "wep") == 0)
2236 return cmd_sta_set_encryption(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002237
2238 send_resp(dut, conn, SIGMA_ERROR,
2239 "ErrorCode,Unsupported Type value");
2240 return 0;
2241}
2242
2243
2244int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
2245{
2246#ifdef __linux__
2247 /* special handling for ath6kl */
2248 char path[128], fname[128], *pos;
2249 ssize_t res;
2250 FILE *f;
2251
2252 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
2253 res = readlink(path, path, sizeof(path));
2254 if (res < 0)
2255 return 0; /* not ath6kl */
2256
2257 if (res >= (int) sizeof(path))
2258 res = sizeof(path) - 1;
2259 path[res] = '\0';
2260 pos = strrchr(path, '/');
2261 if (pos == NULL)
2262 pos = path;
2263 else
2264 pos++;
2265 snprintf(fname, sizeof(fname),
2266 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2267 "create_qos", pos);
2268 if (!file_exists(fname))
2269 return 0; /* not ath6kl */
2270
2271 if (uapsd) {
2272 f = fopen(fname, "w");
2273 if (f == NULL)
2274 return -1;
2275
2276 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2277 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2278 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2279 "20000 0\n");
2280 fclose(f);
2281 } else {
2282 snprintf(fname, sizeof(fname),
2283 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2284 "delete_qos", pos);
2285
2286 f = fopen(fname, "w");
2287 if (f == NULL)
2288 return -1;
2289
2290 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2291 fprintf(f, "2 4\n");
2292 fclose(f);
2293 }
2294#endif /* __linux__ */
2295
2296 return 0;
2297}
2298
2299
2300static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2301 struct sigma_cmd *cmd)
2302{
2303 const char *intf = get_param(cmd, "Interface");
2304 /* const char *ssid = get_param(cmd, "ssid"); */
2305 const char *val;
2306 int max_sp_len = 4;
2307 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2308 char buf[100];
2309 int ret1, ret2;
2310
2311 val = get_param(cmd, "maxSPLength");
2312 if (val) {
2313 max_sp_len = atoi(val);
2314 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2315 max_sp_len != 4)
2316 return -1;
2317 }
2318
2319 val = get_param(cmd, "acBE");
2320 if (val)
2321 ac_be = atoi(val);
2322
2323 val = get_param(cmd, "acBK");
2324 if (val)
2325 ac_bk = atoi(val);
2326
2327 val = get_param(cmd, "acVI");
2328 if (val)
2329 ac_vi = atoi(val);
2330
2331 val = get_param(cmd, "acVO");
2332 if (val)
2333 ac_vo = atoi(val);
2334
2335 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2336
2337 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2338 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2339 ret1 = wpa_command(intf, buf);
2340
2341 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2342 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2343 ret2 = wpa_command(intf, buf);
2344
2345 if (ret1 && ret2) {
2346 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2347 "UAPSD parameters.");
2348 return -2;
2349 }
2350
2351 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2352 send_resp(dut, conn, SIGMA_ERROR,
2353 "ErrorCode,Failed to set ath6kl QoS parameters");
2354 return 0;
2355 }
2356
2357 return 1;
2358}
2359
2360
2361static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2362 struct sigma_cmd *cmd)
2363{
2364 char buf[1000];
2365 const char *intf = get_param(cmd, "Interface");
2366 const char *grp = get_param(cmd, "Group");
2367 const char *act = get_param(cmd, "Action");
2368 const char *tid = get_param(cmd, "Tid");
2369 const char *dir = get_param(cmd, "Direction");
2370 const char *psb = get_param(cmd, "Psb");
2371 const char *up = get_param(cmd, "Up");
2372 const char *fixed = get_param(cmd, "Fixed");
2373 const char *size = get_param(cmd, "Size");
2374 const char *msize = get_param(cmd, "Maxsize");
2375 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2376 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2377 const char *inact = get_param(cmd, "Inactivity");
2378 const char *sus = get_param(cmd, "Suspension");
2379 const char *mindr = get_param(cmd, "Mindatarate");
2380 const char *meandr = get_param(cmd, "Meandatarate");
2381 const char *peakdr = get_param(cmd, "Peakdatarate");
2382 const char *phyrate = get_param(cmd, "Phyrate");
2383 const char *burstsize = get_param(cmd, "Burstsize");
2384 const char *sba = get_param(cmd, "Sba");
2385 int direction;
2386 int handle;
Peng Xu93319622017-10-04 17:58:16 -07002387 float sba_fv = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002388 int fixed_int;
2389 int psb_ts;
2390
2391 if (intf == NULL || grp == NULL || act == NULL )
2392 return -1;
2393
2394 if (strcasecmp(act, "addts") == 0) {
2395 if (tid == NULL || dir == NULL || psb == NULL ||
2396 up == NULL || fixed == NULL || size == NULL)
2397 return -1;
2398
2399 /*
2400 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2401 * possible values, but WMM-AC and V-E test scripts use "UP,
2402 * "DOWN", and "BIDI".
2403 */
2404 if (strcasecmp(dir, "uplink") == 0 ||
2405 strcasecmp(dir, "up") == 0) {
2406 direction = 0;
2407 } else if (strcasecmp(dir, "downlink") == 0 ||
2408 strcasecmp(dir, "down") == 0) {
2409 direction = 1;
2410 } else if (strcasecmp(dir, "bidi") == 0) {
2411 direction = 2;
2412 } else {
2413 sigma_dut_print(dut, DUT_MSG_ERROR,
2414 "Direction %s not supported", dir);
2415 return -1;
2416 }
2417
2418 if (strcasecmp(psb, "legacy") == 0) {
2419 psb_ts = 0;
2420 } else if (strcasecmp(psb, "uapsd") == 0) {
2421 psb_ts = 1;
2422 } else {
2423 sigma_dut_print(dut, DUT_MSG_ERROR,
2424 "PSB %s not supported", psb);
2425 return -1;
2426 }
2427
2428 if (atoi(tid) < 0 || atoi(tid) > 7) {
2429 sigma_dut_print(dut, DUT_MSG_ERROR,
2430 "TID %s not supported", tid);
2431 return -1;
2432 }
2433
2434 if (strcasecmp(fixed, "true") == 0) {
2435 fixed_int = 1;
2436 } else {
2437 fixed_int = 0;
2438 }
2439
Peng Xu93319622017-10-04 17:58:16 -07002440 if (sba)
2441 sba_fv = atof(sba);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002442
2443 dut->dialog_token++;
2444 handle = 7000 + dut->dialog_token;
2445
2446 /*
2447 * size: convert to hex
2448 * maxsi: convert to hex
2449 * mindr: convert to hex
2450 * meandr: convert to hex
2451 * peakdr: convert to hex
2452 * burstsize: convert to hex
2453 * phyrate: convert to hex
2454 * sba: convert to hex with modification
2455 * minsi: convert to integer
2456 * sus: convert to integer
2457 * inact: convert to integer
2458 * maxsi: convert to integer
2459 */
2460
2461 /*
2462 * The Nominal MSDU Size field is 2 octets long and contains an
2463 * unsigned integer that specifies the nominal size, in octets,
2464 * of MSDUs belonging to the traffic under this traffic
2465 * specification and is defined in Figure 16. If the Fixed
2466 * subfield is set to 1, then the size of the MSDU is fixed and
2467 * is indicated by the Size Subfield. If the Fixed subfield is
2468 * set to 0, then the size of the MSDU might not be fixed and
2469 * the Size indicates the nominal MSDU size.
2470 *
2471 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2472 * and specifies the excess allocation of time (and bandwidth)
2473 * over and above the stated rates required to transport an MSDU
2474 * belonging to the traffic in this TSPEC. This field is
2475 * represented as an unsigned binary number with an implicit
2476 * binary point after the leftmost 3 bits. For example, an SBA
2477 * of 1.75 is represented as 0x3800. This field is included to
2478 * account for retransmissions. As such, the value of this field
2479 * must be greater than unity.
2480 */
2481
2482 snprintf(buf, sizeof(buf),
2483 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2484 " 0x%X 0x%X 0x%X"
2485 " 0x%X 0x%X 0x%X"
2486 " 0x%X %d %d %d %d"
2487 " %d %d",
2488 intf, handle, tid, direction, psb_ts, up,
2489 (unsigned int) ((fixed_int << 15) | atoi(size)),
2490 msize ? atoi(msize) : 0,
2491 mindr ? atoi(mindr) : 0,
2492 meandr ? atoi(meandr) : 0,
2493 peakdr ? atoi(peakdr) : 0,
2494 burstsize ? atoi(burstsize) : 0,
2495 phyrate ? atoi(phyrate) : 0,
2496 sba ? ((unsigned int) (((int) sba_fv << 13) |
2497 (int)((sba_fv - (int) sba_fv) *
2498 8192))) : 0,
2499 minsi ? atoi(minsi) : 0,
2500 sus ? atoi(sus) : 0,
2501 0, 0,
2502 inact ? atoi(inact) : 0,
2503 maxsi ? atoi(maxsi) : 0);
2504
2505 if (system(buf) != 0) {
2506 sigma_dut_print(dut, DUT_MSG_ERROR,
2507 "iwpriv addtspec request failed");
2508 send_resp(dut, conn, SIGMA_ERROR,
2509 "errorCode,Failed to execute addTspec command");
2510 return 0;
2511 }
2512
2513 sigma_dut_print(dut, DUT_MSG_INFO,
2514 "iwpriv addtspec request send");
2515
2516 /* Mapping handle to a TID */
2517 dut->tid_to_handle[atoi(tid)] = handle;
2518 } else if (strcasecmp(act, "delts") == 0) {
2519 if (tid == NULL)
2520 return -1;
2521
2522 if (atoi(tid) < 0 || atoi(tid) > 7) {
2523 sigma_dut_print(dut, DUT_MSG_ERROR,
2524 "TID %s not supported", tid);
2525 send_resp(dut, conn, SIGMA_ERROR,
2526 "errorCode,Unsupported TID");
2527 return 0;
2528 }
2529
2530 handle = dut->tid_to_handle[atoi(tid)];
2531
2532 if (handle < 7000 || handle > 7255) {
2533 /* Invalid handle ie no mapping for that TID */
2534 sigma_dut_print(dut, DUT_MSG_ERROR,
2535 "handle-> %d not found", handle);
2536 }
2537
2538 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2539 intf, handle);
2540
2541 if (system(buf) != 0) {
2542 sigma_dut_print(dut, DUT_MSG_ERROR,
2543 "iwpriv deltspec request failed");
2544 send_resp(dut, conn, SIGMA_ERROR,
2545 "errorCode,Failed to execute delTspec command");
2546 return 0;
2547 }
2548
2549 sigma_dut_print(dut, DUT_MSG_INFO,
2550 "iwpriv deltspec request send");
2551
2552 dut->tid_to_handle[atoi(tid)] = 0;
2553 } else {
2554 sigma_dut_print(dut, DUT_MSG_ERROR,
2555 "Action type %s not supported", act);
2556 send_resp(dut, conn, SIGMA_ERROR,
2557 "errorCode,Unsupported Action");
2558 return 0;
2559 }
2560
2561 return 1;
2562}
2563
2564
vamsi krishna52e16f92017-08-29 12:37:34 +05302565static int find_network(struct sigma_dut *dut, const char *ssid)
2566{
2567 char list[4096];
2568 char *pos;
2569
2570 sigma_dut_print(dut, DUT_MSG_DEBUG,
2571 "Search for profile based on SSID: '%s'", ssid);
2572 if (wpa_command_resp(get_station_ifname(), "LIST_NETWORKS",
2573 list, sizeof(list)) < 0)
2574 return -1;
2575 pos = strstr(list, ssid);
2576 if (!pos || pos == list || pos[-1] != '\t' || pos[strlen(ssid)] != '\t')
2577 return -1;
2578
2579 while (pos > list && pos[-1] != '\n')
2580 pos--;
2581 dut->infra_network_id = atoi(pos);
2582 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
2583 return 0;
2584}
2585
2586
Sunil Dutt44595082018-02-12 19:41:45 +05302587#ifdef NL80211_SUPPORT
2588static int sta_config_rsnie(struct sigma_dut *dut, int val)
2589{
2590 struct nl_msg *msg;
2591 int ret;
2592 struct nlattr *params;
2593 int ifindex;
2594
2595 ifindex = if_nametoindex("wlan0");
2596 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
2597 NL80211_CMD_VENDOR)) ||
2598 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
2599 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
2600 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
2601 QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) ||
2602 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
2603 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_RSN_IE, val)) {
2604 sigma_dut_print(dut, DUT_MSG_ERROR,
2605 "%s: err in adding vendor_cmd and vendor_data",
2606 __func__);
2607 nlmsg_free(msg);
2608 return -1;
2609 }
2610 nla_nest_end(msg, params);
2611
2612 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
2613 if (ret) {
2614 sigma_dut_print(dut, DUT_MSG_ERROR,
2615 "%s: err in send_and_recv_msgs, ret=%d",
2616 __func__, ret);
2617 return ret;
2618 }
2619
2620 return 0;
2621}
2622#endif /* NL80211_SUPPORT */
2623
2624
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002625static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2626 struct sigma_cmd *cmd)
2627{
2628 /* const char *intf = get_param(cmd, "Interface"); */
2629 const char *ssid = get_param(cmd, "ssid");
2630 const char *wps_param = get_param(cmd, "WPS");
2631 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03002632 const char *chan = get_param(cmd, "channel");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002633 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03002634 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002635
2636 if (ssid == NULL)
2637 return -1;
2638
Jouni Malinen3c367e82017-06-23 17:01:47 +03002639 if (dut->rsne_override) {
Sunil Dutt44595082018-02-12 19:41:45 +05302640#ifdef NL80211_SUPPORT
2641 if (get_driver_type() == DRIVER_WCN) {
2642 sta_config_rsnie(dut, 1);
2643 dut->config_rsnie = 1;
2644 }
2645#endif /* NL80211_SUPPORT */
Jouni Malinen3c367e82017-06-23 17:01:47 +03002646 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
2647 dut->rsne_override);
2648 if (wpa_command(get_station_ifname(), buf) < 0) {
2649 send_resp(dut, conn, SIGMA_ERROR,
2650 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
2651 return 0;
2652 }
2653 }
2654
Jouni Malinen68143132017-09-02 02:34:08 +03002655 if (dut->sae_commit_override) {
2656 snprintf(buf, sizeof(buf), "SET sae_commit_override %s",
2657 dut->sae_commit_override);
2658 if (wpa_command(get_station_ifname(), buf) < 0) {
2659 send_resp(dut, conn, SIGMA_ERROR,
2660 "ErrorCode,Failed to set SAE commit override");
2661 return 0;
2662 }
2663 }
Ankita Bajaj1bde7942018-01-09 19:15:01 +05302664#ifdef ANDROID
2665 if (dut->fils_hlp)
2666 process_fils_hlp(dut);
2667#endif /* ANDROID */
Jouni Malinen68143132017-09-02 02:34:08 +03002668
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002669 if (wps_param &&
2670 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2671 wps = 1;
2672
2673 if (wps) {
2674 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2675 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2676 "parameters not yet set");
2677 return 0;
2678 }
2679 if (dut->wps_method == WFA_CS_WPS_PBC) {
2680 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2681 return -2;
2682 } else {
2683 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2684 dut->wps_pin);
2685 if (wpa_command(get_station_ifname(), buf) < 0)
2686 return -2;
2687 }
2688 } else {
vamsi krishna52e16f92017-08-29 12:37:34 +05302689 if (strcmp(ssid, dut->infra_ssid) == 0) {
2690 sigma_dut_print(dut, DUT_MSG_DEBUG,
2691 "sta_associate for the most recently added network");
2692 } else if (find_network(dut, ssid) < 0) {
2693 sigma_dut_print(dut, DUT_MSG_DEBUG,
2694 "sta_associate for a previously stored network profile");
2695 send_resp(dut, conn, SIGMA_ERROR,
2696 "ErrorCode,Profile not found");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002697 return 0;
2698 }
2699
2700 if (bssid &&
2701 set_network(get_station_ifname(), dut->infra_network_id,
2702 "bssid", bssid) < 0) {
2703 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2704 "Invalid bssid argument");
2705 return 0;
2706 }
2707
Jouni Malinen46a19b62017-06-23 14:31:27 +03002708 extra[0] = '\0';
2709 if (chan)
2710 snprintf(extra, sizeof(extra), " freq=%u",
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02002711 channel_to_freq(dut, atoi(chan)));
Jouni Malinen46a19b62017-06-23 14:31:27 +03002712 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
2713 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002714 if (wpa_command(get_station_ifname(), buf) < 0) {
2715 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2716 "network id %d on %s",
2717 dut->infra_network_id,
2718 get_station_ifname());
2719 return -2;
2720 }
2721 }
2722
2723 return 1;
2724}
2725
2726
2727static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2728{
2729 char buf[500], cmd[200];
2730 int res;
2731
2732 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2733 * default path */
2734 res = snprintf(cmd, sizeof(cmd),
2735 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2736 file_exists("./hs20-osu-client") ?
2737 "./hs20-osu-client" : "hs20-osu-client",
2738 sigma_wpas_ctrl,
2739 dut->summary_log ? "-s " : "",
2740 dut->summary_log ? dut->summary_log : "");
2741 if (res < 0 || res >= (int) sizeof(cmd))
2742 return -1;
2743
2744 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2745 if (res < 0 || res >= (int) sizeof(buf))
2746 return -1;
2747 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2748
2749 if (system(buf) != 0) {
2750 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2751 return -1;
2752 }
2753 sigma_dut_print(dut, DUT_MSG_DEBUG,
2754 "Completed hs20-osu-client operation");
2755
2756 return 0;
2757}
2758
2759
2760static int download_ppsmo(struct sigma_dut *dut,
2761 struct sigma_conn *conn,
2762 const char *intf,
2763 struct sigma_cmd *cmd)
2764{
2765 const char *name, *path, *val;
2766 char url[500], buf[600], fbuf[100];
2767 char *fqdn = NULL;
2768
2769 name = get_param(cmd, "FileName");
2770 path = get_param(cmd, "FilePath");
2771 if (name == NULL || path == NULL)
2772 return -1;
2773
2774 if (strcasecmp(path, "VendorSpecific") == 0) {
2775 snprintf(url, sizeof(url), "PPS/%s", name);
2776 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2777 "from the device (%s)", url);
2778 if (!file_exists(url)) {
2779 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2780 "PPS MO file does not exist");
2781 return 0;
2782 }
2783 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2784 if (system(buf) != 0) {
2785 send_resp(dut, conn, SIGMA_ERROR,
2786 "errorCode,Failed to copy PPS MO");
2787 return 0;
2788 }
2789 } else if (strncasecmp(path, "http:", 5) != 0 &&
2790 strncasecmp(path, "https:", 6) != 0) {
2791 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2792 "Unsupported FilePath value");
2793 return 0;
2794 } else {
2795 snprintf(url, sizeof(url), "%s/%s", path, name);
2796 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2797 url);
2798 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2799 remove("pps-tnds.xml");
2800 if (system(buf) != 0) {
2801 send_resp(dut, conn, SIGMA_ERROR,
2802 "errorCode,Failed to download PPS MO");
2803 return 0;
2804 }
2805 }
2806
2807 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2808 send_resp(dut, conn, SIGMA_ERROR,
2809 "errorCode,Failed to parse downloaded PPSMO");
2810 return 0;
2811 }
2812 unlink("pps-tnds.xml");
2813
2814 val = get_param(cmd, "managementTreeURI");
2815 if (val) {
2816 const char *pos, *end;
2817 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2818 val);
2819 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2820 send_resp(dut, conn, SIGMA_ERROR,
2821 "errorCode,Invalid managementTreeURI prefix");
2822 return 0;
2823 }
2824 pos = val + 8;
2825 end = strchr(pos, '/');
2826 if (end == NULL ||
2827 strcmp(end, "/PerProviderSubscription") != 0) {
2828 send_resp(dut, conn, SIGMA_ERROR,
2829 "errorCode,Invalid managementTreeURI postfix");
2830 return 0;
2831 }
2832 if (end - pos >= (int) sizeof(fbuf)) {
2833 send_resp(dut, conn, SIGMA_ERROR,
2834 "errorCode,Too long FQDN in managementTreeURI");
2835 return 0;
2836 }
2837 memcpy(fbuf, pos, end - pos);
2838 fbuf[end - pos] = '\0';
2839 fqdn = fbuf;
2840 sigma_dut_print(dut, DUT_MSG_INFO,
2841 "FQDN from managementTreeURI: %s", fqdn);
2842 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
2843 FILE *f = fopen("pps-fqdn", "r");
2844 if (f) {
2845 if (fgets(fbuf, sizeof(fbuf), f)) {
2846 fbuf[sizeof(fbuf) - 1] = '\0';
2847 fqdn = fbuf;
2848 sigma_dut_print(dut, DUT_MSG_DEBUG,
2849 "Use FQDN %s", fqdn);
2850 }
2851 fclose(f);
2852 }
2853 }
2854
2855 if (fqdn == NULL) {
2856 send_resp(dut, conn, SIGMA_ERROR,
2857 "errorCode,No FQDN specified");
2858 return 0;
2859 }
2860
2861 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2862 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
2863 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2864
2865 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
2866 if (rename("pps.xml", buf) < 0) {
2867 send_resp(dut, conn, SIGMA_ERROR,
2868 "errorCode,Could not move PPS MO");
2869 return 0;
2870 }
2871
2872 if (strcasecmp(path, "VendorSpecific") == 0) {
2873 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
2874 fqdn);
2875 if (system(buf)) {
2876 send_resp(dut, conn, SIGMA_ERROR,
2877 "errorCode,Failed to copy OSU CA cert");
2878 return 0;
2879 }
2880
2881 snprintf(buf, sizeof(buf),
2882 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
2883 fqdn);
2884 if (system(buf)) {
2885 send_resp(dut, conn, SIGMA_ERROR,
2886 "errorCode,Failed to copy AAA CA cert");
2887 return 0;
2888 }
2889 } else {
2890 snprintf(buf, sizeof(buf),
2891 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
2892 fqdn, fqdn);
2893 if (run_hs20_osu(dut, buf) < 0) {
2894 send_resp(dut, conn, SIGMA_ERROR,
2895 "errorCode,Failed to download OSU CA cert");
2896 return 0;
2897 }
2898
2899 snprintf(buf, sizeof(buf),
2900 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
2901 fqdn, fqdn);
2902 if (run_hs20_osu(dut, buf) < 0) {
2903 sigma_dut_print(dut, DUT_MSG_INFO,
2904 "Failed to download AAA CA cert");
2905 }
2906 }
2907
2908 if (file_exists("next-client-cert.pem")) {
2909 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
2910 if (rename("next-client-cert.pem", buf) < 0) {
2911 send_resp(dut, conn, SIGMA_ERROR,
2912 "errorCode,Could not move client certificate");
2913 return 0;
2914 }
2915 }
2916
2917 if (file_exists("next-client-key.pem")) {
2918 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
2919 if (rename("next-client-key.pem", buf) < 0) {
2920 send_resp(dut, conn, SIGMA_ERROR,
2921 "errorCode,Could not move client key");
2922 return 0;
2923 }
2924 }
2925
2926 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
2927 if (run_hs20_osu(dut, buf) < 0) {
2928 send_resp(dut, conn, SIGMA_ERROR,
2929 "errorCode,Failed to configure credential from "
2930 "PPSMO");
2931 return 0;
2932 }
2933
2934 return 1;
2935}
2936
2937
2938static int download_cert(struct sigma_dut *dut,
2939 struct sigma_conn *conn,
2940 const char *intf,
2941 struct sigma_cmd *cmd)
2942{
2943 const char *name, *path;
2944 char url[500], buf[600];
2945
2946 name = get_param(cmd, "FileName");
2947 path = get_param(cmd, "FilePath");
2948 if (name == NULL || path == NULL)
2949 return -1;
2950
2951 if (strcasecmp(path, "VendorSpecific") == 0) {
2952 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
2953 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2954 "certificate from the device (%s)", url);
2955 if (!file_exists(url)) {
2956 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2957 "certificate file does not exist");
2958 return 0;
2959 }
2960 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
2961 if (system(buf) != 0) {
2962 send_resp(dut, conn, SIGMA_ERROR,
2963 "errorCode,Failed to copy client "
2964 "certificate");
2965 return 0;
2966 }
2967
2968 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
2969 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2970 "private key from the device (%s)", url);
2971 if (!file_exists(url)) {
2972 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2973 "private key file does not exist");
2974 return 0;
2975 }
2976 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
2977 if (system(buf) != 0) {
2978 send_resp(dut, conn, SIGMA_ERROR,
2979 "errorCode,Failed to copy client key");
2980 return 0;
2981 }
2982 } else if (strncasecmp(path, "http:", 5) != 0 &&
2983 strncasecmp(path, "https:", 6) != 0) {
2984 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2985 "Unsupported FilePath value");
2986 return 0;
2987 } else {
2988 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
2989 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
2990 "certificate/key from %s", url);
2991 snprintf(buf, sizeof(buf),
2992 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
2993 if (system(buf) != 0) {
2994 send_resp(dut, conn, SIGMA_ERROR,
2995 "errorCode,Failed to download client "
2996 "certificate");
2997 return 0;
2998 }
2999
3000 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
3001 {
3002 send_resp(dut, conn, SIGMA_ERROR,
3003 "errorCode,Failed to copy client key");
3004 return 0;
3005 }
3006 }
3007
3008 return 1;
3009}
3010
3011
3012static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
3013 struct sigma_conn *conn,
3014 const char *intf,
3015 struct sigma_cmd *cmd)
3016{
3017 const char *val;
3018
3019 val = get_param(cmd, "FileType");
3020 if (val && strcasecmp(val, "PPSMO") == 0)
3021 return download_ppsmo(dut, conn, intf, cmd);
3022 if (val && strcasecmp(val, "CERT") == 0)
3023 return download_cert(dut, conn, intf, cmd);
3024 if (val) {
3025 send_resp(dut, conn, SIGMA_ERROR,
3026 "ErrorCode,Unsupported FileType");
3027 return 0;
3028 }
3029
3030 return 1;
3031}
3032
3033
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303034static int cmd_sta_preset_testparameters_oce(struct sigma_dut *dut,
3035 struct sigma_conn *conn,
3036 const char *intf,
3037 struct sigma_cmd *cmd)
3038{
3039 const char *val;
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303040 char buf[1000];
3041 char text[20];
3042 unsigned char addr[ETH_ALEN];
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303043
3044 val = get_param(cmd, "OCESupport");
3045 if (val && strcasecmp(val, "Disable") == 0) {
3046 if (wpa_command(intf, "SET oce 0") < 0) {
3047 send_resp(dut, conn, SIGMA_ERROR,
3048 "ErrorCode,Failed to disable OCE");
3049 return 0;
3050 }
3051 } else if (val && strcasecmp(val, "Enable") == 0) {
3052 if (wpa_command(intf, "SET oce 1") < 0) {
3053 send_resp(dut, conn, SIGMA_ERROR,
3054 "ErrorCode,Failed to enable OCE");
3055 return 0;
3056 }
3057 }
3058
vamsi krishnaa2799492017-12-05 14:28:01 +05303059 val = get_param(cmd, "FILScap");
3060 if (val && (atoi(val) == 1)) {
3061 if (wpa_command(intf, "SET disable_fils 0") < 0) {
3062 send_resp(dut, conn, SIGMA_ERROR,
3063 "ErrorCode,Failed to enable FILS");
3064 return 0;
3065 }
3066 } else if (val && (atoi(val) == 0)) {
3067 if (wpa_command(intf, "SET disable_fils 1") < 0) {
3068 send_resp(dut, conn, SIGMA_ERROR,
3069 "ErrorCode,Failed to disable FILS");
3070 return 0;
3071 }
3072 }
3073
Ankita Bajaj1bde7942018-01-09 19:15:01 +05303074 val = get_param(cmd, "FILSHLP");
3075 if (val && strcasecmp(val, "Enable") == 0) {
3076 if (get_wpa_status(get_station_ifname(), "address", text,
3077 sizeof(text)) < 0)
3078 return -2;
3079 hwaddr_aton(text, addr);
3080 snprintf(buf, sizeof(buf),
3081 "FILS_HLP_REQ_ADD ff:ff:ff:ff:ff:ff "
3082 "080045100140000040004011399e00000000ffffffff00440043"
3083 "012cb30001010600fd4f46410000000000000000000000000000"
3084 "000000000000"
3085 "%02x%02x%02x%02x%02x%02x"
3086 "0000000000000000000000000000000000000000000000000000"
3087 "0000000000000000000000000000000000000000000000000000"
3088 "0000000000000000000000000000000000000000000000000000"
3089 "0000000000000000000000000000000000000000000000000000"
3090 "0000000000000000000000000000000000000000000000000000"
3091 "0000000000000000000000000000000000000000000000000000"
3092 "0000000000000000000000000000000000000000000000000000"
3093 "0000000000000000000000000000000000000000638253633501"
3094 "013d0701000af549d29b390205dc3c12616e64726f69642d6468"
3095 "63702d382e302e30370a0103060f1a1c333a3b2b5000ff00",
3096 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
3097 if (wpa_command(intf, buf)) {
3098 send_resp(dut, conn, SIGMA_ERROR,
3099 "ErrorCode,Failed to add HLP");
3100 return 0;
3101 }
3102 dut->fils_hlp = 1;
3103 }
3104
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303105 return 1;
3106}
3107
3108
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003109static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
3110 const char *val)
3111{
3112 int counter = 0;
3113 char token[50];
3114 char *result;
3115 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303116 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003117
Peng Xub8fc5cc2017-05-10 17:27:28 -07003118 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003119 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303120 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003121 while (result) {
3122 if (strcmp(result, "disable") == 0) {
3123 snprintf(buf, sizeof(buf),
3124 "iwpriv %s noackpolicy %d 1 0",
3125 intf, counter);
3126 } else {
3127 snprintf(buf, sizeof(buf),
3128 "iwpriv %s noackpolicy %d 1 1",
3129 intf, counter);
3130 }
3131 if (system(buf) != 0) {
3132 sigma_dut_print(dut, DUT_MSG_ERROR,
3133 "iwpriv noackpolicy failed");
3134 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05303135 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003136 counter++;
3137 }
3138}
3139
3140
3141static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
3142 const char *val)
3143{
3144 char buf[100];
3145
3146 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
3147 if (system(buf) != 0) {
3148 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
3149 }
3150}
3151
3152
3153static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3154 const char *val)
3155{
3156 char buf[100];
3157
3158 if (strcasecmp(val, "off") == 0) {
3159 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
3160 if (system(buf) != 0) {
3161 sigma_dut_print(dut, DUT_MSG_ERROR,
3162 "Failed to turn off WMM");
3163 }
3164 }
3165}
3166
3167
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003168static int wcn_sta_set_wmm(struct sigma_dut *dut, const char *intf,
3169 const char *val)
3170{
3171#ifdef NL80211_SUPPORT
3172 struct nl_msg *msg;
3173 int ret = 0;
3174 struct nlattr *params;
3175 int ifindex;
3176 int wmmenable = 1;
3177
3178 if (val &&
3179 (strcasecmp(val, "off") == 0 || strcmp(val, "0") == 0))
3180 wmmenable = 0;
3181
3182 ifindex = if_nametoindex(intf);
3183 if (ifindex == 0) {
3184 sigma_dut_print(dut, DUT_MSG_ERROR,
3185 "%s: Index for interface %s failed",
3186 __func__, intf);
3187 return -1;
3188 }
3189
3190 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3191 NL80211_CMD_VENDOR)) ||
3192 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3193 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3194 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3195 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3196 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3197 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WMM_ENABLE,
3198 wmmenable)) {
3199 sigma_dut_print(dut, DUT_MSG_ERROR,
3200 "%s: err in adding vendor_cmd and vendor_data",
3201 __func__);
3202 nlmsg_free(msg);
3203 return -1;
3204 }
3205 nla_nest_end(msg, params);
3206
3207 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3208 if (ret) {
3209 sigma_dut_print(dut, DUT_MSG_ERROR,
3210 "%s: err in send_and_recv_msgs, ret=%d",
3211 __func__, ret);
3212 }
3213 return ret;
3214#else /* NL80211_SUPPORT */
3215 sigma_dut_print(dut, DUT_MSG_ERROR,
3216 "WMM cannot be changed without NL80211_SUPPORT defined");
3217 return -1;
3218#endif /* NL80211_SUPPORT */
3219}
3220
3221
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003222static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
3223 const char *val)
3224{
3225 char buf[100];
3226 int sgi20;
3227
3228 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
3229
3230 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
3231 if (system(buf) != 0)
3232 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
3233}
3234
3235
3236static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
3237 const char *val)
3238{
3239 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303240 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003241
3242 /* Disable Tx Beam forming when using a fixed rate */
3243 ath_disable_txbf(dut, intf);
3244
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05303245 v = atoi(val);
3246 if (v < 0 || v > 32) {
3247 sigma_dut_print(dut, DUT_MSG_ERROR,
3248 "Invalid Fixed MCS rate: %d", v);
3249 return;
3250 }
3251 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003252
3253 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
3254 intf, rate_code);
3255 if (system(buf) != 0) {
3256 sigma_dut_print(dut, DUT_MSG_ERROR,
3257 "iwpriv set11NRates failed");
3258 }
3259
3260 /* Channel width gets messed up, fix this */
3261 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
3262 if (system(buf) != 0)
3263 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
3264}
3265
3266
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08003267static void iwpriv_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
3268 const char *val)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003269{
3270 char buf[60];
3271
3272 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
3273 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
3274 else
3275 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
3276
3277 if (system(buf) != 0)
3278 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
3279}
3280
3281
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003282static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
3283 int ampdu)
3284{
3285 char buf[60];
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003286 int maxaggregation = 63;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003287
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08003288 if (ampdu)
3289 ampdu = maxaggregation;
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003290 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
3291 if (system(buf) != 0) {
3292 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
3293 return -1;
3294 }
3295
3296 return 0;
3297}
3298
3299
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003300static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3301 const char *val)
3302{
3303 char buf[60];
3304
3305 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3306 if (system(buf) != 0) {
3307 sigma_dut_print(dut, DUT_MSG_ERROR,
3308 "iwpriv tx_stbc failed");
3309 }
3310
3311 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3312 if (system(buf) != 0) {
3313 sigma_dut_print(dut, DUT_MSG_ERROR,
3314 "iwpriv rx_stbc failed");
3315 }
3316}
3317
3318
3319static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
3320 const char *val)
3321{
3322 char buf[60];
3323
Peng Xucc317ed2017-05-18 16:44:37 -07003324 if (strcmp(val, "160") == 0) {
3325 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
3326 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003327 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3328 } else if (strcmp(val, "40") == 0) {
3329 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
3330 } else if (strcmp(val, "20") == 0) {
3331 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
3332 } else if (strcasecmp(val, "Auto") == 0) {
3333 buf[0] = '\0';
3334 } else {
3335 sigma_dut_print(dut, DUT_MSG_ERROR,
3336 "WIDTH/CTS_WIDTH value not supported");
3337 return -1;
3338 }
3339
3340 if (buf[0] != '\0' && system(buf) != 0) {
3341 sigma_dut_print(dut, DUT_MSG_ERROR,
3342 "Failed to set WIDTH/CTS_WIDTH");
3343 return -1;
3344 }
3345
3346 return 0;
3347}
3348
3349
3350int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
3351 const char *intf, const char *val)
3352{
3353 char buf[60];
3354
3355 if (strcasecmp(val, "Auto") == 0) {
3356 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3357 dut->chwidth = 0;
3358 } else if (strcasecmp(val, "20") == 0) {
3359 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
3360 dut->chwidth = 0;
3361 } else if (strcasecmp(val, "40") == 0) {
3362 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
3363 dut->chwidth = 1;
3364 } else if (strcasecmp(val, "80") == 0) {
3365 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
3366 dut->chwidth = 2;
3367 } else if (strcasecmp(val, "160") == 0) {
3368 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
3369 dut->chwidth = 3;
3370 } else {
3371 send_resp(dut, conn, SIGMA_ERROR,
3372 "ErrorCode,WIDTH not supported");
3373 return -1;
3374 }
3375
3376 if (system(buf) != 0) {
3377 sigma_dut_print(dut, DUT_MSG_ERROR,
3378 "iwpriv chwidth failed");
3379 }
3380
3381 return 0;
3382}
3383
3384
3385static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
3386 const char *val)
3387{
3388 char buf[60];
Arif Hussainac6c5112018-05-25 17:34:00 -07003389 int sta_nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003390
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003391 if (strcmp(val, "1SS") == 0 || strcmp(val, "1") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003392 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003393 sta_nss = 1;
Amarnath Hullur Subramanyamd5374fa2018-02-25 19:00:24 -08003394 } else if (strcmp(val, "2SS") == 0 || strcmp(val, "2") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003395 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
Arif Hussainac6c5112018-05-25 17:34:00 -07003396 sta_nss = 2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003397 } else {
3398 sigma_dut_print(dut, DUT_MSG_ERROR,
3399 "SP_STREAM value not supported");
3400 return -1;
3401 }
3402
3403 if (system(buf) != 0) {
3404 sigma_dut_print(dut, DUT_MSG_ERROR,
3405 "Failed to set SP_STREAM");
3406 return -1;
3407 }
3408
Arif Hussainac6c5112018-05-25 17:34:00 -07003409 dut->sta_nss = sta_nss;
3410
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003411 return 0;
3412}
3413
3414
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303415static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
3416 const char *val)
3417{
3418 char buf[60];
3419
3420 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
3421 if (system(buf) != 0)
3422 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
3423
3424 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
3425 if (system(buf) != 0)
3426 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
3427}
3428
3429
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303430static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
3431 struct sigma_conn *conn,
3432 const char *intf, int capa)
3433{
3434 char buf[32];
3435
3436 if (capa > 0 && capa < 4) {
3437 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
3438 if (wpa_command(intf, buf) < 0) {
3439 send_resp(dut, conn, SIGMA_ERROR,
3440 "ErrorCode, Failed to set cellular data capability");
3441 return 0;
3442 }
3443 return 1;
3444 }
3445
3446 sigma_dut_print(dut, DUT_MSG_ERROR,
3447 "Invalid Cellular data capability: %d", capa);
3448 send_resp(dut, conn, SIGMA_INVALID,
3449 "ErrorCode,Invalid cellular data capability");
3450 return 0;
3451}
3452
3453
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303454static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
3455 const char *intf, const char *val)
3456{
3457 if (strcasecmp(val, "Disable") == 0) {
3458 if (wpa_command(intf, "SET roaming 0") < 0) {
3459 send_resp(dut, conn, SIGMA_ERROR,
3460 "ErrorCode,Failed to disable roaming");
3461 return 0;
3462 }
3463 return 1;
3464 }
3465
3466 if (strcasecmp(val, "Enable") == 0) {
3467 if (wpa_command(intf, "SET roaming 1") < 0) {
3468 send_resp(dut, conn, SIGMA_ERROR,
3469 "ErrorCode,Failed to enable roaming");
3470 return 0;
3471 }
3472 return 1;
3473 }
3474
3475 sigma_dut_print(dut, DUT_MSG_ERROR,
3476 "Invalid value provided for roaming: %s", val);
3477 send_resp(dut, conn, SIGMA_INVALID,
3478 "ErrorCode,Unknown value provided for Roaming");
3479 return 0;
3480}
3481
3482
Ashwini Patila75de5a2017-04-13 16:35:05 +05303483static int mbo_set_assoc_disallow(struct sigma_dut *dut,
3484 struct sigma_conn *conn,
3485 const char *intf, const char *val)
3486{
3487 if (strcasecmp(val, "Disable") == 0) {
3488 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
3489 send_resp(dut, conn, SIGMA_ERROR,
3490 "ErrorCode,Failed to disable Assoc_disallow");
3491 return 0;
3492 }
3493 return 1;
3494 }
3495
3496 if (strcasecmp(val, "Enable") == 0) {
3497 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3498 send_resp(dut, conn, SIGMA_ERROR,
3499 "ErrorCode,Failed to enable Assoc_disallow");
3500 return 0;
3501 }
3502 return 1;
3503 }
3504
3505 sigma_dut_print(dut, DUT_MSG_ERROR,
3506 "Invalid value provided for Assoc_disallow: %s", val);
3507 send_resp(dut, conn, SIGMA_INVALID,
3508 "ErrorCode,Unknown value provided for Assoc_disallow");
3509 return 0;
3510}
3511
3512
Ashwini Patilc63161e2017-04-13 16:30:23 +05303513static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3514 const char *intf, const char *val)
3515{
3516 if (strcasecmp(val, "Reject") == 0) {
3517 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3518 send_resp(dut, conn, SIGMA_ERROR,
3519 "ErrorCode,Failed to Reject BTM Request");
3520 return 0;
3521 }
3522 return 1;
3523 }
3524
3525 if (strcasecmp(val, "Accept") == 0) {
3526 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3527 send_resp(dut, conn, SIGMA_ERROR,
3528 "ErrorCode,Failed to Accept BTM Request");
3529 return 0;
3530 }
3531 return 1;
3532 }
3533
3534 sigma_dut_print(dut, DUT_MSG_ERROR,
3535 "Invalid value provided for BSS_Transition: %s", val);
3536 send_resp(dut, conn, SIGMA_INVALID,
3537 "ErrorCode,Unknown value provided for BSS_Transition");
3538 return 0;
3539}
3540
3541
Ashwini Patil00402582017-04-13 12:29:39 +05303542static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3543 struct sigma_conn *conn,
3544 const char *intf,
3545 struct sigma_cmd *cmd)
3546{
3547 const char *ch, *pref, *op_class, *reason;
3548 char buf[120];
3549 int len, ret;
3550
3551 pref = get_param(cmd, "Ch_Pref");
3552 if (!pref)
3553 return 1;
3554
3555 if (strcasecmp(pref, "clear") == 0) {
3556 free(dut->non_pref_ch_list);
3557 dut->non_pref_ch_list = NULL;
3558 } else {
3559 op_class = get_param(cmd, "Ch_Op_Class");
3560 if (!op_class) {
3561 send_resp(dut, conn, SIGMA_INVALID,
3562 "ErrorCode,Ch_Op_Class not provided");
3563 return 0;
3564 }
3565
3566 ch = get_param(cmd, "Ch_Pref_Num");
3567 if (!ch) {
3568 send_resp(dut, conn, SIGMA_INVALID,
3569 "ErrorCode,Ch_Pref_Num not provided");
3570 return 0;
3571 }
3572
3573 reason = get_param(cmd, "Ch_Reason_Code");
3574 if (!reason) {
3575 send_resp(dut, conn, SIGMA_INVALID,
3576 "ErrorCode,Ch_Reason_Code not provided");
3577 return 0;
3578 }
3579
3580 if (!dut->non_pref_ch_list) {
3581 dut->non_pref_ch_list =
3582 calloc(1, NON_PREF_CH_LIST_SIZE);
3583 if (!dut->non_pref_ch_list) {
3584 send_resp(dut, conn, SIGMA_ERROR,
3585 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3586 return 0;
3587 }
3588 }
3589 len = strlen(dut->non_pref_ch_list);
3590 ret = snprintf(dut->non_pref_ch_list + len,
3591 NON_PREF_CH_LIST_SIZE - len,
3592 " %s:%s:%s:%s", op_class, ch, pref, reason);
3593 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3594 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3595 dut->non_pref_ch_list);
3596 } else {
3597 sigma_dut_print(dut, DUT_MSG_ERROR,
3598 "snprintf failed for non_pref_list, ret = %d",
3599 ret);
3600 send_resp(dut, conn, SIGMA_ERROR,
3601 "ErrorCode,snprintf failed");
3602 free(dut->non_pref_ch_list);
3603 dut->non_pref_ch_list = NULL;
3604 return 0;
3605 }
3606 }
3607
3608 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3609 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3610 if (ret < 0 || ret >= (int) sizeof(buf)) {
3611 sigma_dut_print(dut, DUT_MSG_DEBUG,
3612 "snprintf failed for set non_pref_chan, ret: %d",
3613 ret);
3614 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3615 return 0;
3616 }
3617
3618 if (wpa_command(intf, buf) < 0) {
3619 send_resp(dut, conn, SIGMA_ERROR,
3620 "ErrorCode,Failed to set non-preferred channel list");
3621 return 0;
3622 }
3623
3624 return 1;
3625}
3626
3627
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003628#ifdef NL80211_SUPPORT
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003629
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003630static int sta_set_he_fragmentation(struct sigma_dut *dut, const char *intf,
3631 enum he_fragmentation_val frag)
3632{
3633 struct nl_msg *msg;
3634 int ret = 0;
3635 struct nlattr *params;
3636 int ifindex;
3637
3638 ifindex = if_nametoindex(intf);
3639 if (ifindex == 0) {
3640 sigma_dut_print(dut, DUT_MSG_ERROR,
3641 "%s: Index for interface %s failed",
3642 __func__, intf);
3643 return -1;
3644 }
3645
3646 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3647 NL80211_CMD_VENDOR)) ||
3648 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3649 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3650 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3651 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3652 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3653 nla_put_u8(msg,
3654 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_FRAGMENTATION,
3655 frag)) {
3656 sigma_dut_print(dut, DUT_MSG_ERROR,
3657 "%s: err in adding vendor_cmd and vendor_data",
3658 __func__);
3659 nlmsg_free(msg);
3660 return -1;
3661 }
3662 nla_nest_end(msg, params);
3663
3664 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3665 if (ret) {
3666 sigma_dut_print(dut, DUT_MSG_ERROR,
3667 "%s: err in send_and_recv_msgs, ret=%d",
3668 __func__, ret);
3669 }
3670 return ret;
3671}
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003672
3673
Subhani Shaik8e7a3052018-04-24 14:03:00 -07003674static int sta_set_he_ltf(struct sigma_dut *dut, const char *intf,
3675 enum qca_wlan_he_ltf_cfg ltf)
3676{
3677 struct nl_msg *msg;
3678 int ret = 0;
3679 struct nlattr *params;
3680 int ifindex;
3681
3682 ifindex = if_nametoindex(intf);
3683 if (ifindex == 0) {
3684 sigma_dut_print(dut, DUT_MSG_ERROR,
3685 "%s: Index for interface %s failed",
3686 __func__, intf);
3687 return -1;
3688 }
3689
3690 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3691 NL80211_CMD_VENDOR)) ||
3692 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3693 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3694 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3695 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3696 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3697 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_LTF,
3698 ltf)) {
3699 sigma_dut_print(dut, DUT_MSG_ERROR,
3700 "%s: err in adding vendor_cmd and vendor_data",
3701 __func__);
3702 nlmsg_free(msg);
3703 return -1;
3704 }
3705 nla_nest_end(msg, params);
3706
3707 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3708 if (ret) {
3709 sigma_dut_print(dut, DUT_MSG_ERROR,
3710 "%s: err in send_and_recv_msgs, ret=%d",
3711 __func__, ret);
3712 }
3713 return ret;
3714}
3715
3716
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08003717static int nlvendor_sta_set_noack(struct sigma_dut *dut, const char *intf,
3718 int noack, enum qca_wlan_ac_type ac)
3719{
3720 struct nl_msg *msg;
3721 int ret = 0;
3722 struct nlattr *params;
3723 int ifindex;
3724
3725 ifindex = if_nametoindex(intf);
3726 if (ifindex == 0) {
3727 sigma_dut_print(dut, DUT_MSG_ERROR,
3728 "%s: Index for interface %s failed",
3729 __func__, intf);
3730 return -1;
3731 }
3732
3733 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
3734 NL80211_CMD_VENDOR)) ||
3735 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
3736 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
3737 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
3738 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
3739 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
3740 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_NO_ACK,
3741 noack) ||
3742 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_NO_ACK_AC,
3743 ac)) {
3744 sigma_dut_print(dut, DUT_MSG_ERROR,
3745 "%s: err in adding vendor_cmd and vendor_data",
3746 __func__);
3747 nlmsg_free(msg);
3748 return -1;
3749 }
3750 nla_nest_end(msg, params);
3751
3752 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
3753 if (ret) {
3754 sigma_dut_print(dut, DUT_MSG_ERROR,
3755 "%s: err in send_and_recv_msgs, ret=%d",
3756 __func__, ret);
3757 }
3758 return ret;
3759}
3760
3761
3762static void wcn_sta_set_noack(struct sigma_dut *dut, const char *intf,
3763 const char *val)
3764{
3765 int noack, ret;
3766 char token[100];
3767 char *result;
3768 char *saveptr;
3769 enum qca_wlan_ac_type ac = QCA_WLAN_AC_BE;
3770
3771 strlcpy(token, val, sizeof(token));
3772 token[sizeof(token) - 1] = '\0';
3773 result = strtok_r(token, ":", &saveptr);
3774 while (result) {
3775 noack = strcasecmp(result, "Disable") != 0;
3776 ret = nlvendor_sta_set_noack(dut, intf, noack, ac);
3777 if (ret) {
3778 sigma_dut_print(dut, DUT_MSG_ERROR,
3779 "nlvendor_sta_set_noack failed for ac:%d, ret:%d",
3780 ac, ret);
3781 }
3782 result = strtok_r(NULL, ":", &saveptr);
3783 ac++;
3784 }
3785}
3786
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08003787#endif /* NL80211_SUPPORT */
3788
3789
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003790static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3791 struct sigma_conn *conn,
3792 struct sigma_cmd *cmd)
3793{
3794 const char *intf = get_param(cmd, "Interface");
3795 const char *val;
3796
3797 val = get_param(cmd, "Program");
Jouni Malinen1f6ae642018-06-07 23:56:13 +03003798 if (val && (strcasecmp(val, "HS2-R2") == 0 ||
3799 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003800 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3801 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003802
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003803 if (val && strcasecmp(val, "LOC") == 0)
3804 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3805
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003806#ifdef ANDROID_NAN
3807 if (val && strcasecmp(val, "NAN") == 0)
3808 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3809#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003810#ifdef MIRACAST
3811 if (val && (strcasecmp(val, "WFD") == 0 ||
3812 strcasecmp(val, "DisplayR2") == 0))
3813 return miracast_preset_testparameters(dut, conn, cmd);
3814#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003815
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303816 if (val && strcasecmp(val, "MBO") == 0) {
3817 val = get_param(cmd, "Cellular_Data_Cap");
3818 if (val &&
3819 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3820 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303821
3822 val = get_param(cmd, "Ch_Pref");
3823 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3824 return 0;
3825
Ashwini Patilc63161e2017-04-13 16:30:23 +05303826 val = get_param(cmd, "BSS_Transition");
3827 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3828 return 0;
3829
Ashwini Patila75de5a2017-04-13 16:35:05 +05303830 val = get_param(cmd, "Assoc_Disallow");
3831 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3832 return 0;
3833
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303834 val = get_param(cmd, "Roaming");
3835 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3836 return 0;
3837
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303838 return 1;
3839 }
3840
Ankita Bajaja2cb5672017-10-25 16:08:28 +05303841 if (val && strcasecmp(val, "OCE") == 0)
3842 return cmd_sta_preset_testparameters_oce(dut, conn, intf, cmd);
3843
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003844#if 0
3845 val = get_param(cmd, "Supplicant");
3846 if (val && strcasecmp(val, "Default") != 0) {
3847 send_resp(dut, conn, SIGMA_ERROR,
3848 "ErrorCode,Only default(Vendor) supplicant "
3849 "supported");
3850 return 0;
3851 }
3852#endif
3853
3854 val = get_param(cmd, "RTS");
3855 if (val) {
3856 switch (get_driver_type()) {
3857 case DRIVER_ATHEROS:
3858 ath_sta_set_rts(dut, intf, val);
3859 break;
3860 default:
3861#if 0
3862 send_resp(dut, conn, SIGMA_ERROR,
3863 "ErrorCode,Setting RTS not supported");
3864 return 0;
3865#else
3866 sigma_dut_print(dut, DUT_MSG_DEBUG,
3867 "Setting RTS not supported");
3868 break;
3869#endif
3870 }
3871 }
3872
3873#if 0
3874 val = get_param(cmd, "FRGMNT");
3875 if (val) {
3876 /* TODO */
3877 send_resp(dut, conn, SIGMA_ERROR,
3878 "ErrorCode,Setting FRGMNT not supported");
3879 return 0;
3880 }
3881#endif
3882
3883#if 0
3884 val = get_param(cmd, "Preamble");
3885 if (val) {
3886 /* TODO: Long/Short */
3887 send_resp(dut, conn, SIGMA_ERROR,
3888 "ErrorCode,Setting Preamble not supported");
3889 return 0;
3890 }
3891#endif
3892
3893 val = get_param(cmd, "Mode");
3894 if (val) {
3895 if (strcmp(val, "11b") == 0 ||
3896 strcmp(val, "11g") == 0 ||
3897 strcmp(val, "11a") == 0 ||
3898 strcmp(val, "11n") == 0 ||
3899 strcmp(val, "11ng") == 0 ||
3900 strcmp(val, "11nl") == 0 ||
3901 strcmp(val, "11nl(nabg)") == 0 ||
3902 strcmp(val, "AC") == 0 ||
3903 strcmp(val, "11AC") == 0 ||
3904 strcmp(val, "11ac") == 0 ||
3905 strcmp(val, "11na") == 0 ||
Amarnath Hullur Subramanyamb0db2712018-01-30 19:40:35 -08003906 strcmp(val, "11an") == 0 ||
3907 strcmp(val, "11ax") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003908 /* STA supports all modes by default */
3909 } else {
3910 send_resp(dut, conn, SIGMA_ERROR,
3911 "ErrorCode,Setting Mode not supported");
3912 return 0;
3913 }
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003914
3915 /* Change the mode only in case of testbed for HE program
3916 * and for 11a and 11g modes only. */
3917 if (dut->program == PROGRAM_HE &&
3918 dut->device_type == STA_testbed) {
3919 int phymode;
3920 char buf[60];
3921
3922 if (strcmp(val, "11a") == 0) {
Amarnath Hullur Subramanyam94dfaf02018-03-02 19:26:57 -08003923 phymode = 1; /* IEEE80211_MODE_11A */
3924 } else if (strcmp(val, "11g") == 0) {
3925 phymode = 3; /* IEEE80211_MODE_11G */
3926 } else if (strcmp(val, "11b") == 0) {
3927 phymode = 2; /* IEEE80211_MODE_11B */
3928 } else if (strcmp(val, "11n") == 0 ||
3929 strcmp(val, "11nl") == 0 ||
3930 strcmp(val, "11nl(nabg)") == 0) {
3931 phymode = 22; /* IEEE80211_MODE_11AGN */
3932 } else if (strcmp(val, "11ng") == 0) {
3933 phymode = 13; /* IEEE80211_MODE_11NG_HT40 */
3934 } else if (strcmp(val, "AC") == 0 ||
3935 strcasecmp(val, "11AC") == 0) {
3936 phymode = 19; /* IEEE80211_MODE_11AC_VHT80 */
3937 } else if (strcmp(val, "11na") == 0 ||
3938 strcasecmp(val, "11an") == 0) {
3939 phymode = 14; /* IEEE80211_MODE_11NA_HT40 */
3940 } else if (strcmp(val, "11ax") == 0) {
3941 phymode = 0; /* IEEE80211_MODE_AUTO */
Amarnath Hullur Subramanyam97d0e532018-01-31 02:53:02 -08003942 } else {
3943 sigma_dut_print(dut, DUT_MSG_DEBUG,
3944 "Ignoring mode change for mode: %s",
3945 val);
3946 phymode = -1;
3947 }
3948 if (phymode != -1) {
3949 snprintf(buf, sizeof(buf),
3950 "iwpriv %s setphymode %d",
3951 intf, phymode);
3952 if (system(buf) != 0) {
3953 sigma_dut_print(dut, DUT_MSG_ERROR,
3954 "iwpriv setting of phymode failed");
3955 }
3956 }
3957 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003958 }
3959
3960 val = get_param(cmd, "wmm");
3961 if (val) {
3962 switch (get_driver_type()) {
3963 case DRIVER_ATHEROS:
3964 ath_sta_set_wmm(dut, intf, val);
3965 break;
Amarnath Hullur Subramanyam75214d22018-02-04 19:17:11 -08003966 case DRIVER_WCN:
3967 wcn_sta_set_wmm(dut, intf, val);
3968 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003969 default:
3970 sigma_dut_print(dut, DUT_MSG_DEBUG,
3971 "Setting wmm not supported");
3972 break;
3973 }
3974 }
3975
3976 val = get_param(cmd, "Powersave");
3977 if (val) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08003978 char buf[60];
3979
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003980 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08003981 if (get_driver_type() == DRIVER_WCN) {
3982 snprintf(buf, sizeof(buf),
3983 "iwpriv %s setPower 2", intf);
3984 if (system(buf) != 0) {
3985 sigma_dut_print(dut, DUT_MSG_ERROR,
3986 "iwpriv setPower 2 failed");
3987 return 0;
3988 }
3989 }
3990
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003991 if (wpa_command(get_station_ifname(),
3992 "P2P_SET ps 0") < 0)
3993 return -2;
3994 /* Make sure test modes are disabled */
3995 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3996 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3997 } else if (strcmp(val, "1") == 0 ||
3998 strcasecmp(val, "PSPoll") == 0 ||
3999 strcasecmp(val, "on") == 0) {
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08004000 if (get_driver_type() == DRIVER_WCN) {
4001 snprintf(buf, sizeof(buf),
4002 "iwpriv %s setPower 1", intf);
4003 if (system(buf) != 0) {
4004 sigma_dut_print(dut, DUT_MSG_ERROR,
4005 "iwpriv setPower 1 failed");
4006 return 0;
4007 }
4008 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004009 /* Disable default power save mode */
4010 wpa_command(get_station_ifname(), "P2P_SET ps 0");
4011 /* Enable PS-Poll test mode */
4012 if (wpa_command(get_station_ifname(),
4013 "P2P_SET ps 97") < 0 ||
4014 wpa_command(get_station_ifname(),
4015 "P2P_SET ps 99") < 0)
4016 return -2;
4017 } else if (strcmp(val, "2") == 0 ||
4018 strcasecmp(val, "Fast") == 0) {
4019 /* TODO */
4020 send_resp(dut, conn, SIGMA_ERROR,
4021 "ErrorCode,Powersave=Fast not supported");
4022 return 0;
4023 } else if (strcmp(val, "3") == 0 ||
4024 strcasecmp(val, "PSNonPoll") == 0) {
4025 /* Make sure test modes are disabled */
4026 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4027 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4028
4029 /* Enable default power save mode */
4030 if (wpa_command(get_station_ifname(),
4031 "P2P_SET ps 1") < 0)
4032 return -2;
4033 } else
4034 return -1;
4035 }
4036
4037 val = get_param(cmd, "NoAck");
4038 if (val) {
4039 switch (get_driver_type()) {
4040 case DRIVER_ATHEROS:
4041 ath_sta_set_noack(dut, intf, val);
4042 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004043#ifdef NL80211_SUPPORT
4044 case DRIVER_WCN:
4045 wcn_sta_set_noack(dut, intf, val);
4046 break;
4047#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004048 default:
4049 send_resp(dut, conn, SIGMA_ERROR,
4050 "ErrorCode,Setting NoAck not supported");
4051 return 0;
4052 }
4053 }
4054
4055 val = get_param(cmd, "IgnoreChswitchProhibit");
4056 if (val) {
4057 /* TODO: Enabled/disabled */
4058 if (strcasecmp(val, "Enabled") == 0) {
4059 send_resp(dut, conn, SIGMA_ERROR,
4060 "ErrorCode,Enabling IgnoreChswitchProhibit "
4061 "not supported");
4062 return 0;
4063 }
4064 }
4065
4066 val = get_param(cmd, "TDLS");
4067 if (val) {
4068 if (strcasecmp(val, "Disabled") == 0) {
4069 if (wpa_command(intf, "SET tdls_disabled 1")) {
4070 send_resp(dut, conn, SIGMA_ERROR,
4071 "ErrorCode,Failed to disable TDLS");
4072 return 0;
4073 }
4074 } else if (strcasecmp(val, "Enabled") == 0) {
4075 if (wpa_command(intf, "SET tdls_disabled 0")) {
4076 send_resp(dut, conn, SIGMA_ERROR,
4077 "ErrorCode,Failed to enable TDLS");
4078 return 0;
4079 }
4080 } else {
4081 send_resp(dut, conn, SIGMA_ERROR,
4082 "ErrorCode,Unsupported TDLS value");
4083 return 0;
4084 }
4085 }
4086
4087 val = get_param(cmd, "TDLSmode");
4088 if (val) {
4089 if (strcasecmp(val, "Default") == 0) {
4090 wpa_command(intf, "SET tdls_testing 0");
4091 } else if (strcasecmp(val, "APProhibit") == 0) {
4092 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4093 send_resp(dut, conn, SIGMA_ERROR,
4094 "ErrorCode,Failed to enable ignore "
4095 "APProhibit TDLS mode");
4096 return 0;
4097 }
4098 } else if (strcasecmp(val, "HiLoMac") == 0) {
4099 /* STA should respond with TDLS setup req for a TDLS
4100 * setup req */
4101 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4102 send_resp(dut, conn, SIGMA_ERROR,
4103 "ErrorCode,Failed to enable HiLoMac "
4104 "TDLS mode");
4105 return 0;
4106 }
4107 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4108 /*
4109 * Since all security modes are enabled by default when
4110 * Sigma control is used, there is no need to do
4111 * anything here.
4112 */
4113 } else if (strcasecmp(val, "ExistLink") == 0) {
4114 /*
4115 * Since we allow new TDLS Setup Request even if there
4116 * is an existing link, nothing needs to be done for
4117 * this.
4118 */
4119 } else {
4120 /* TODO:
4121 * ExistLink: STA should send TDLS setup req even if
4122 * direct link already exists
4123 */
4124 send_resp(dut, conn, SIGMA_ERROR,
4125 "ErrorCode,Unsupported TDLSmode value");
4126 return 0;
4127 }
4128 }
4129
4130 val = get_param(cmd, "FakePubKey");
4131 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4132 send_resp(dut, conn, SIGMA_ERROR,
4133 "ErrorCode,Failed to enable FakePubKey");
4134 return 0;
4135 }
4136
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004137#ifdef NL80211_SUPPORT
4138 val = get_param(cmd, "FrgmntSupport");
4139 if (val) {
4140 if (strcasecmp(val, "Enable") == 0) {
4141 if (sta_set_he_fragmentation(dut, intf,
4142 HE_FRAG_LEVEL1)) {
4143 send_resp(dut, conn, SIGMA_ERROR,
4144 "ErrorCode,Failed to enable HE Fragmentation");
4145 return 0;
4146 }
4147 } else if (strcasecmp(val, "Disable") == 0) {
4148 if (sta_set_he_fragmentation(dut, intf,
4149 HE_FRAG_DISABLE)) {
4150 send_resp(dut, conn, SIGMA_ERROR,
4151 "ErrorCode,Failed to disable HE Fragmentation");
4152 return 0;
4153 }
4154 }
4155 }
4156#endif /* NL80211_SUPPORT */
4157
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004158 return 1;
4159}
4160
4161
4162static const char * ath_get_radio_name(const char *radio_name)
4163{
4164 if (radio_name == NULL)
4165 return "wifi0";
4166 if (strcmp(radio_name, "wifi1") == 0)
4167 return "wifi1";
4168 if (strcmp(radio_name, "wifi2") == 0)
4169 return "wifi2";
4170 return "wifi0";
4171}
4172
4173
4174static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4175 const char *val)
4176{
4177 char buf[60];
4178 unsigned int vht_mcsmap = 0;
4179 int txchainmask = 0;
4180 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4181
4182 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4183 if (dut->testbed_flag_txsp == 1) {
4184 vht_mcsmap = 0xfffc;
4185 dut->testbed_flag_txsp = 0;
4186 } else {
4187 vht_mcsmap = 0xfffe;
4188 }
4189 txchainmask = 1;
4190 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4191 if (dut->testbed_flag_txsp == 1) {
4192 vht_mcsmap = 0xfff0;
4193 dut->testbed_flag_txsp = 0;
4194 } else {
4195 vht_mcsmap = 0xfffa;
4196 }
4197 txchainmask = 3;
4198 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4199 if (dut->testbed_flag_txsp == 1) {
4200 vht_mcsmap = 0xffc0;
4201 dut->testbed_flag_txsp = 0;
4202 } else {
4203 vht_mcsmap = 0xffea;
4204 }
4205 txchainmask = 7;
4206 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4207 if (dut->testbed_flag_txsp == 1) {
4208 vht_mcsmap = 0xff00;
4209 dut->testbed_flag_txsp = 0;
4210 } else {
4211 vht_mcsmap = 0xffaa;
4212 }
4213 txchainmask = 15;
4214 } else {
4215 if (dut->testbed_flag_txsp == 1) {
4216 vht_mcsmap = 0xffc0;
4217 dut->testbed_flag_txsp = 0;
4218 } else {
4219 vht_mcsmap = 0xffea;
4220 }
4221 }
4222
4223 if (txchainmask) {
4224 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4225 basedev, txchainmask);
4226 if (system(buf) != 0) {
4227 sigma_dut_print(dut, DUT_MSG_ERROR,
4228 "iwpriv txchainmask failed");
4229 }
4230 }
4231
4232 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4233 intf, vht_mcsmap);
4234 if (system(buf) != 0) {
4235 sigma_dut_print(dut, DUT_MSG_ERROR,
4236 "iwpriv %s vht_mcsmap 0x%04x failed",
4237 intf, vht_mcsmap);
4238 }
4239}
4240
4241
4242static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4243 const char *val)
4244{
4245 char buf[60];
4246 unsigned int vht_mcsmap = 0;
4247 int rxchainmask = 0;
4248 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4249
4250 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4251 if (dut->testbed_flag_rxsp == 1) {
4252 vht_mcsmap = 0xfffc;
4253 dut->testbed_flag_rxsp = 0;
4254 } else {
4255 vht_mcsmap = 0xfffe;
4256 }
4257 rxchainmask = 1;
4258 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4259 if (dut->testbed_flag_rxsp == 1) {
4260 vht_mcsmap = 0xfff0;
4261 dut->testbed_flag_rxsp = 0;
4262 } else {
4263 vht_mcsmap = 0xfffa;
4264 }
4265 rxchainmask = 3;
4266 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4267 if (dut->testbed_flag_rxsp == 1) {
4268 vht_mcsmap = 0xffc0;
4269 dut->testbed_flag_rxsp = 0;
4270 } else {
4271 vht_mcsmap = 0xffea;
4272 }
4273 rxchainmask = 7;
4274 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4275 if (dut->testbed_flag_rxsp == 1) {
4276 vht_mcsmap = 0xff00;
4277 dut->testbed_flag_rxsp = 0;
4278 } else {
4279 vht_mcsmap = 0xffaa;
4280 }
4281 rxchainmask = 15;
4282 } else {
4283 if (dut->testbed_flag_rxsp == 1) {
4284 vht_mcsmap = 0xffc0;
4285 dut->testbed_flag_rxsp = 0;
4286 } else {
4287 vht_mcsmap = 0xffea;
4288 }
4289 }
4290
4291 if (rxchainmask) {
4292 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4293 basedev, rxchainmask);
4294 if (system(buf) != 0) {
4295 sigma_dut_print(dut, DUT_MSG_ERROR,
4296 "iwpriv rxchainmask failed");
4297 }
4298 }
4299
4300 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4301 intf, vht_mcsmap);
4302 if (system(buf) != 0) {
4303 sigma_dut_print(dut, DUT_MSG_ERROR,
4304 "iwpriv %s vht_mcsmap 0x%04x",
4305 intf, vht_mcsmap);
4306 }
4307}
4308
4309
4310void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4311{
4312 if (strcasecmp(val, "enable") == 0) {
4313 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4314 != 0) {
4315 sigma_dut_print(dut, DUT_MSG_ERROR,
4316 "Disable BB_VHTSIGB_CRC_CALC failed");
4317 }
4318
4319 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4320 != 0) {
4321 sigma_dut_print(dut, DUT_MSG_ERROR,
4322 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4323 }
4324 } else {
4325 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4326 != 0) {
4327 sigma_dut_print(dut, DUT_MSG_ERROR,
4328 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4329 }
4330
4331 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4332 != 0) {
4333 sigma_dut_print(dut, DUT_MSG_ERROR,
4334 "Enable BB_VHTSIGB_CRC_CALC failed");
4335 }
4336 }
4337}
4338
4339
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004340static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4341 const char *val)
4342{
4343 char buf[60];
4344
4345 if (strcmp(val, "20") == 0) {
4346 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4347 dut->chwidth = 0;
4348 } else if (strcmp(val, "40") == 0) {
4349 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4350 dut->chwidth = 1;
4351 } else if (strcmp(val, "80") == 0) {
4352 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4353 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05304354 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004355 buf[0] = '\0';
4356 } else {
4357 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4358 val);
4359 return -1;
4360 }
4361
4362 if (buf[0] != '\0' && system(buf) != 0) {
4363 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4364 return -1;
4365 }
4366
4367 return 0;
4368}
4369
4370
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004371static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4372 const char *intf, int addbareject)
4373{
4374#ifdef NL80211_SUPPORT
4375 struct nl_msg *msg;
4376 int ret = 0;
4377 struct nlattr *params;
4378 int ifindex;
4379
4380 ifindex = if_nametoindex(intf);
4381 if (ifindex == 0) {
4382 sigma_dut_print(dut, DUT_MSG_ERROR,
4383 "%s: Index for interface %s failed",
4384 __func__, intf);
4385 return -1;
4386 }
4387
4388 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4389 NL80211_CMD_VENDOR)) ||
4390 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4391 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4392 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4393 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4394 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4395 nla_put_u8(msg,
4396 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4397 !addbareject)) {
4398 sigma_dut_print(dut, DUT_MSG_ERROR,
4399 "%s: err in adding vendor_cmd and vendor_data",
4400 __func__);
4401 nlmsg_free(msg);
4402 return -1;
4403 }
4404 nla_nest_end(msg, params);
4405
4406 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4407 if (ret) {
4408 sigma_dut_print(dut, DUT_MSG_ERROR,
4409 "%s: err in send_and_recv_msgs, ret=%d",
4410 __func__, ret);
4411 }
4412 return ret;
4413#else /* NL80211_SUPPORT */
4414 sigma_dut_print(dut, DUT_MSG_ERROR,
4415 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4416 return -1;
4417#endif /* NL80211_SUPPORT */
4418}
4419
4420
4421static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4422 int addbareject)
4423{
4424 int ret;
4425
4426 switch (get_driver_type()) {
4427 case DRIVER_WCN:
4428 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4429 if (ret) {
4430 sigma_dut_print(dut, DUT_MSG_ERROR,
4431 "nlvendor_sta_set_addba_reject failed, ret:%d",
4432 ret);
4433 return ret;
4434 }
4435 break;
4436 default:
4437 sigma_dut_print(dut, DUT_MSG_ERROR,
4438 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4439 ret = -1;
4440 break;
4441 }
4442
4443 return ret;
4444}
4445
4446
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004447static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
4448 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004449{
4450#ifdef NL80211_SUPPORT
4451 struct nl_msg *msg;
4452 int ret = 0;
4453 struct nlattr *params;
4454 int ifindex;
4455
4456 ifindex = if_nametoindex(intf);
4457 if (ifindex == 0) {
4458 sigma_dut_print(dut, DUT_MSG_ERROR,
4459 "%s: Index for interface %s failed",
4460 __func__, intf);
4461 return -1;
4462 }
4463
4464 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4465 NL80211_CMD_VENDOR)) ||
4466 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4467 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4468 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4469 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4470 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4471 nla_put_u8(msg,
4472 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004473 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004474 sigma_dut_print(dut, DUT_MSG_ERROR,
4475 "%s: err in adding vendor_cmd and vendor_data",
4476 __func__);
4477 nlmsg_free(msg);
4478 return -1;
4479 }
4480 nla_nest_end(msg, params);
4481
4482 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4483 if (ret) {
4484 sigma_dut_print(dut, DUT_MSG_ERROR,
4485 "%s: err in send_and_recv_msgs, ret=%d",
4486 __func__, ret);
4487 }
4488 return ret;
4489#else /* NL80211_SUPPORT */
4490 sigma_dut_print(dut, DUT_MSG_ERROR,
4491 "Disable addba not possible without NL80211_SUPPORT defined");
4492 return -1;
4493#endif /* NL80211_SUPPORT */
4494}
4495
4496
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004497static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4498 struct sigma_conn *conn,
4499 struct sigma_cmd *cmd)
4500{
4501 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004502 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004503 char buf[30];
4504
4505 val = get_param(cmd, "40_INTOLERANT");
4506 if (val) {
4507 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4508 /* TODO: iwpriv ht40intol through wpa_supplicant */
4509 send_resp(dut, conn, SIGMA_ERROR,
4510 "ErrorCode,40_INTOLERANT not supported");
4511 return 0;
4512 }
4513 }
4514
4515 val = get_param(cmd, "ADDBA_REJECT");
4516 if (val) {
4517 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4518 /* reject any ADDBA with status "decline" */
4519 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004520 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004521 } else {
4522 /* accept ADDBA */
4523 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004524 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004525 }
4526 }
4527
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004528 if (addbareject >= 0 &&
4529 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4530 send_resp(dut, conn, SIGMA_ERROR,
4531 "ErrorCode,set addba_reject failed");
4532 return 0;
4533 }
4534
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004535 val = get_param(cmd, "AMPDU");
4536 if (val) {
4537 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4538 /* enable AMPDU Aggregation */
4539 if (ampdu == 0) {
4540 send_resp(dut, conn, SIGMA_ERROR,
4541 "ErrorCode,Mismatch in "
4542 "addba_reject/ampdu - "
4543 "not supported");
4544 return 0;
4545 }
4546 ampdu = 1;
4547 } else {
4548 /* disable AMPDU Aggregation */
4549 if (ampdu == 1) {
4550 send_resp(dut, conn, SIGMA_ERROR,
4551 "ErrorCode,Mismatch in "
4552 "addba_reject/ampdu - "
4553 "not supported");
4554 return 0;
4555 }
4556 ampdu = 0;
4557 }
4558 }
4559
4560 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004561 int ret;
4562
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004563 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4564 ampdu ? "Enabling" : "Disabling");
4565 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004566 if (wpa_command(intf, buf) < 0 &&
4567 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004568 send_resp(dut, conn, SIGMA_ERROR,
4569 "ErrorCode,set aggr failed");
4570 return 0;
4571 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004572
4573 if (ampdu == 0) {
4574 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004575 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004576 if (ret) {
4577 sigma_dut_print(dut, DUT_MSG_ERROR,
4578 "Failed to disable addba, ret:%d",
4579 ret);
4580 }
4581 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004582 }
4583
4584 val = get_param(cmd, "AMSDU");
4585 if (val) {
4586 switch (get_driver_type()) {
4587 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004588 case DRIVER_WCN:
4589 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004590 break;
4591 default:
4592 if (strcmp(val, "1") == 0 ||
4593 strcasecmp(val, "Enable") == 0) {
4594 /* Enable AMSDU Aggregation */
4595 send_resp(dut, conn, SIGMA_ERROR,
4596 "ErrorCode,AMSDU aggregation not supported");
4597 return 0;
4598 }
4599 break;
4600 }
4601 }
4602
4603 val = get_param(cmd, "STBC_RX");
4604 if (val) {
4605 switch (get_driver_type()) {
4606 case DRIVER_ATHEROS:
4607 ath_sta_set_stbc(dut, intf, val);
4608 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304609 case DRIVER_WCN:
4610 wcn_sta_set_stbc(dut, intf, val);
4611 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004612 default:
4613 send_resp(dut, conn, SIGMA_ERROR,
4614 "ErrorCode,STBC_RX not supported");
4615 return 0;
4616 }
4617 }
4618
4619 val = get_param(cmd, "WIDTH");
4620 if (val) {
4621 switch (get_driver_type()) {
4622 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004623 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004624 send_resp(dut, conn, SIGMA_ERROR,
4625 "ErrorCode,Failed to set WIDTH");
4626 return 0;
4627 }
4628 break;
4629 case DRIVER_ATHEROS:
4630 if (ath_set_width(dut, conn, intf, val) < 0)
4631 return 0;
4632 break;
4633 default:
4634 sigma_dut_print(dut, DUT_MSG_ERROR,
4635 "Setting WIDTH not supported");
4636 break;
4637 }
4638 }
4639
4640 val = get_param(cmd, "SMPS");
4641 if (val) {
4642 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4643 send_resp(dut, conn, SIGMA_ERROR,
4644 "ErrorCode,SMPS not supported");
4645 return 0;
4646 }
4647
4648 val = get_param(cmd, "TXSP_STREAM");
4649 if (val) {
4650 switch (get_driver_type()) {
4651 case DRIVER_WCN:
4652 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4653 send_resp(dut, conn, SIGMA_ERROR,
4654 "ErrorCode,Failed to set TXSP_STREAM");
4655 return 0;
4656 }
4657 break;
4658 case DRIVER_ATHEROS:
4659 ath_sta_set_txsp_stream(dut, intf, val);
4660 break;
4661 default:
4662 sigma_dut_print(dut, DUT_MSG_ERROR,
4663 "Setting TXSP_STREAM not supported");
4664 break;
4665 }
4666 }
4667
4668 val = get_param(cmd, "RXSP_STREAM");
4669 if (val) {
4670 switch (get_driver_type()) {
4671 case DRIVER_WCN:
4672 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4673 send_resp(dut, conn, SIGMA_ERROR,
4674 "ErrorCode,Failed to set RXSP_STREAM");
4675 return 0;
4676 }
4677 break;
4678 case DRIVER_ATHEROS:
4679 ath_sta_set_rxsp_stream(dut, intf, val);
4680 break;
4681 default:
4682 sigma_dut_print(dut, DUT_MSG_ERROR,
4683 "Setting RXSP_STREAM not supported");
4684 break;
4685 }
4686 }
4687
4688 val = get_param(cmd, "DYN_BW_SGNL");
4689 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004690 switch (get_driver_type()) {
4691 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004692 if (strcasecmp(val, "enable") == 0) {
4693 snprintf(buf, sizeof(buf),
4694 "iwpriv %s cwmenable 1", intf);
4695 if (system(buf) != 0) {
4696 sigma_dut_print(dut, DUT_MSG_ERROR,
4697 "iwpriv cwmenable 1 failed");
4698 return 0;
4699 }
4700 } else if (strcasecmp(val, "disable") == 0) {
4701 snprintf(buf, sizeof(buf),
4702 "iwpriv %s cwmenable 0", intf);
4703 if (system(buf) != 0) {
4704 sigma_dut_print(dut, DUT_MSG_ERROR,
4705 "iwpriv cwmenable 0 failed");
4706 return 0;
4707 }
4708 } else {
4709 sigma_dut_print(dut, DUT_MSG_ERROR,
4710 "Unsupported DYN_BW_SGL");
4711 }
4712
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004713 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4714 if (system(buf) != 0) {
4715 sigma_dut_print(dut, DUT_MSG_ERROR,
4716 "Failed to set cts_cbw in DYN_BW_SGNL");
4717 return 0;
4718 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004719 break;
4720 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004721 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004722 ath_config_dyn_bw_sig(dut, intf, val);
4723 break;
4724 default:
4725 sigma_dut_print(dut, DUT_MSG_ERROR,
4726 "Failed to set DYN_BW_SGNL");
4727 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004728 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004729 }
4730
4731 val = get_param(cmd, "RTS_FORCE");
4732 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004733 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004734 if (strcasecmp(val, "Enable") == 0) {
4735 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004736 if (system(buf) != 0) {
4737 sigma_dut_print(dut, DUT_MSG_ERROR,
4738 "Failed to set RTS_FORCE 64");
4739 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004740 snprintf(buf, sizeof(buf),
4741 "wifitool %s beeliner_fw_test 100 1", intf);
4742 if (system(buf) != 0) {
4743 sigma_dut_print(dut, DUT_MSG_ERROR,
4744 "wifitool beeliner_fw_test 100 1 failed");
4745 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004746 } else if (strcasecmp(val, "Disable") == 0) {
4747 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4748 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004749 if (system(buf) != 0) {
4750 sigma_dut_print(dut, DUT_MSG_ERROR,
4751 "Failed to set RTS_FORCE 2347");
4752 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004753 } else {
4754 send_resp(dut, conn, SIGMA_ERROR,
4755 "ErrorCode,RTS_FORCE value not supported");
4756 return 0;
4757 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004758 }
4759
4760 val = get_param(cmd, "CTS_WIDTH");
4761 if (val) {
4762 switch (get_driver_type()) {
4763 case DRIVER_WCN:
4764 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4765 send_resp(dut, conn, SIGMA_ERROR,
4766 "ErrorCode,Failed to set CTS_WIDTH");
4767 return 0;
4768 }
4769 break;
4770 case DRIVER_ATHEROS:
4771 ath_set_cts_width(dut, intf, val);
4772 break;
4773 default:
4774 sigma_dut_print(dut, DUT_MSG_ERROR,
4775 "Setting CTS_WIDTH not supported");
4776 break;
4777 }
4778 }
4779
4780 val = get_param(cmd, "BW_SGNL");
4781 if (val) {
4782 if (strcasecmp(val, "Enable") == 0) {
4783 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4784 intf);
4785 } else if (strcasecmp(val, "Disable") == 0) {
4786 /* TODO: Disable */
4787 buf[0] = '\0';
4788 } else {
4789 send_resp(dut, conn, SIGMA_ERROR,
4790 "ErrorCode,BW_SGNL value not supported");
4791 return 0;
4792 }
4793
4794 if (buf[0] != '\0' && system(buf) != 0) {
4795 sigma_dut_print(dut, DUT_MSG_ERROR,
4796 "Failed to set BW_SGNL");
4797 }
4798 }
4799
4800 val = get_param(cmd, "Band");
4801 if (val) {
4802 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4803 /* STA supports all bands by default */
4804 } else {
4805 send_resp(dut, conn, SIGMA_ERROR,
4806 "ErrorCode,Unsupported Band");
4807 return 0;
4808 }
4809 }
4810
4811 val = get_param(cmd, "zero_crc");
4812 if (val) {
4813 switch (get_driver_type()) {
4814 case DRIVER_ATHEROS:
4815 ath_set_zero_crc(dut, val);
4816 break;
4817 default:
4818 break;
4819 }
4820 }
4821
4822 return 1;
4823}
4824
4825
4826static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4827 struct sigma_cmd *cmd)
4828{
4829 const char *val;
4830 char buf[100];
4831
4832 val = get_param(cmd, "MSDUSize");
4833 if (val) {
4834 int mtu;
4835
4836 dut->amsdu_size = atoi(val);
4837 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4838 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4839 sigma_dut_print(dut, DUT_MSG_ERROR,
4840 "MSDUSize %d is above max %d or below min %d",
4841 dut->amsdu_size,
4842 IEEE80211_MAX_DATA_LEN_DMG,
4843 IEEE80211_SNAP_LEN_DMG);
4844 dut->amsdu_size = 0;
4845 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4846 }
4847
4848 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4849 sigma_dut_print(dut, DUT_MSG_DEBUG,
4850 "Setting amsdu_size to %d", mtu);
4851 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4852 get_station_ifname(), mtu);
4853
4854 if (system(buf) != 0) {
4855 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4856 buf);
4857 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4858 }
4859 }
4860
4861 val = get_param(cmd, "BAckRcvBuf");
4862 if (val) {
4863 dut->back_rcv_buf = atoi(val);
4864 if (dut->back_rcv_buf == 0) {
4865 sigma_dut_print(dut, DUT_MSG_ERROR,
4866 "Failed to convert %s or value is 0",
4867 val);
4868 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4869 }
4870
4871 sigma_dut_print(dut, DUT_MSG_DEBUG,
4872 "Setting BAckRcvBuf to %s", val);
4873 }
4874
4875 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4876}
4877
4878
4879static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4880 struct sigma_cmd *cmd)
4881{
4882 int net_id;
4883 char *ifname;
4884 const char *val;
4885 char buf[100];
4886
4887 dut->mode = SIGMA_MODE_STATION;
4888 ifname = get_main_ifname();
4889 if (wpa_command(ifname, "PING") != 0) {
4890 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4891 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4892 }
4893
4894 wpa_command(ifname, "FLUSH");
4895 net_id = add_network_common(dut, conn, ifname, cmd);
4896 if (net_id < 0) {
4897 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4898 return net_id;
4899 }
4900
4901 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4902 if (set_network(ifname, net_id, "mode", "2") < 0) {
4903 sigma_dut_print(dut, DUT_MSG_ERROR,
4904 "Failed to set supplicant network mode");
4905 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4906 }
4907
4908 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02004909 "Supplicant set network with mode 2. network_id %d",
4910 net_id);
4911
4912 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
4913 sigma_dut_print(dut, DUT_MSG_INFO,
4914 "Failed to set supplicant to WPS ENABLE");
4915 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4916 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004917
4918 val = get_param(cmd, "Security");
4919 if (val && strcasecmp(val, "OPEN") == 0) {
4920 dut->ap_key_mgmt = AP_OPEN;
4921 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4922 sigma_dut_print(dut, DUT_MSG_ERROR,
4923 "Failed to set supplicant to %s security",
4924 val);
4925 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4926 }
4927 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4928 dut->ap_key_mgmt = AP_WPA2_PSK;
4929 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4930 sigma_dut_print(dut, DUT_MSG_ERROR,
4931 "Failed to set supplicant to %s security",
4932 val);
4933 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4934 }
4935
4936 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4937 sigma_dut_print(dut, DUT_MSG_ERROR,
4938 "Failed to set supplicant to proto RSN");
4939 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4940 }
4941 } else if (val) {
4942 sigma_dut_print(dut, DUT_MSG_ERROR,
4943 "Requested Security %s is not supported on 60GHz",
4944 val);
4945 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4946 }
4947
4948 val = get_param(cmd, "Encrypt");
4949 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4950 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4951 sigma_dut_print(dut, DUT_MSG_ERROR,
4952 "Failed to set supplicant to pairwise GCMP");
4953 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4954 }
4955 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4956 sigma_dut_print(dut, DUT_MSG_ERROR,
4957 "Failed to set supplicant to group GCMP");
4958 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4959 }
4960 } else if (val) {
4961 sigma_dut_print(dut, DUT_MSG_ERROR,
4962 "Requested Encrypt %s is not supported on 60 GHz",
4963 val);
4964 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4965 }
4966
4967 val = get_param(cmd, "PSK");
4968 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4969 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4970 val);
4971 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4972 }
4973
4974 /* Convert 60G channel to freq */
4975 switch (dut->ap_channel) {
4976 case 1:
4977 val = "58320";
4978 break;
4979 case 2:
4980 val = "60480";
4981 break;
4982 case 3:
4983 val = "62640";
4984 break;
4985 default:
4986 sigma_dut_print(dut, DUT_MSG_ERROR,
4987 "Failed to configure channel %d. Not supported",
4988 dut->ap_channel);
4989 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4990 }
4991
4992 if (set_network(ifname, net_id, "frequency", val) < 0) {
4993 sigma_dut_print(dut, DUT_MSG_ERROR,
4994 "Failed to set supplicant network frequency");
4995 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4996 }
4997
4998 sigma_dut_print(dut, DUT_MSG_DEBUG,
4999 "Supplicant set network with frequency");
5000
5001 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
5002 if (wpa_command(ifname, buf) < 0) {
5003 sigma_dut_print(dut, DUT_MSG_INFO,
5004 "Failed to select network id %d on %s",
5005 net_id, ifname);
5006 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5007 }
5008
5009 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
5010
5011 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
5012}
5013
5014
Lior David67543f52017-01-03 19:04:22 +02005015static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
5016{
5017 char buf[128], fname[128];
5018 FILE *f;
5019
5020 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5021 sigma_dut_print(dut, DUT_MSG_ERROR,
5022 "failed to get wil6210 debugfs dir");
5023 return -1;
5024 }
5025
5026 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5027 f = fopen(fname, "w");
5028 if (!f) {
5029 sigma_dut_print(dut, DUT_MSG_ERROR,
5030 "failed to open: %s", fname);
5031 return -1;
5032 }
5033
5034 fprintf(f, "%d\n", abft_len);
5035 fclose(f);
5036
5037 return 0;
5038}
5039
5040
5041static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5042 int abft_len)
5043{
5044 switch (get_driver_type()) {
5045 case DRIVER_WIL6210:
5046 return wil6210_set_abft_len(dut, abft_len);
5047 default:
5048 sigma_dut_print(dut, DUT_MSG_ERROR,
5049 "set abft_len not supported");
5050 return -1;
5051 }
5052}
5053
5054
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005055static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5056 struct sigma_cmd *cmd)
5057{
5058 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005059 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005060
5061 if (dut->dev_role != DEVROLE_PCP) {
5062 send_resp(dut, conn, SIGMA_INVALID,
5063 "ErrorCode,Invalid DevRole");
5064 return 0;
5065 }
5066
5067 val = get_param(cmd, "SSID");
5068 if (val) {
5069 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5070 send_resp(dut, conn, SIGMA_INVALID,
5071 "ErrorCode,Invalid SSID");
5072 return -1;
5073 }
5074
Peng Xub8fc5cc2017-05-10 17:27:28 -07005075 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005076 }
5077
5078 val = get_param(cmd, "CHANNEL");
5079 if (val) {
5080 const char *pos;
5081
5082 dut->ap_channel = atoi(val);
5083 pos = strchr(val, ';');
5084 if (pos) {
5085 pos++;
5086 dut->ap_channel_1 = atoi(pos);
5087 }
5088 }
5089
5090 switch (dut->ap_channel) {
5091 case 1:
5092 case 2:
5093 case 3:
5094 break;
5095 default:
5096 sigma_dut_print(dut, DUT_MSG_ERROR,
5097 "Channel %d is not supported", dut->ap_channel);
5098 send_resp(dut, conn, SIGMA_ERROR,
5099 "Requested channel is not supported");
5100 return -1;
5101 }
5102
5103 val = get_param(cmd, "BCNINT");
5104 if (val)
5105 dut->ap_bcnint = atoi(val);
5106
5107
5108 val = get_param(cmd, "ExtSchIE");
5109 if (val) {
5110 send_resp(dut, conn, SIGMA_ERROR,
5111 "ErrorCode,ExtSchIE is not supported yet");
5112 return -1;
5113 }
5114
5115 val = get_param(cmd, "AllocType");
5116 if (val) {
5117 send_resp(dut, conn, SIGMA_ERROR,
5118 "ErrorCode,AllocType is not supported yet");
5119 return -1;
5120 }
5121
5122 val = get_param(cmd, "PercentBI");
5123 if (val) {
5124 send_resp(dut, conn, SIGMA_ERROR,
5125 "ErrorCode,PercentBI is not supported yet");
5126 return -1;
5127 }
5128
5129 val = get_param(cmd, "CBAPOnly");
5130 if (val) {
5131 send_resp(dut, conn, SIGMA_ERROR,
5132 "ErrorCode,CBAPOnly is not supported yet");
5133 return -1;
5134 }
5135
5136 val = get_param(cmd, "AMPDU");
5137 if (val) {
5138 if (strcasecmp(val, "Enable") == 0)
5139 dut->ap_ampdu = 1;
5140 else if (strcasecmp(val, "Disable") == 0)
5141 dut->ap_ampdu = 2;
5142 else {
5143 send_resp(dut, conn, SIGMA_ERROR,
5144 "ErrorCode,AMPDU value is not Enable nor Disabled");
5145 return -1;
5146 }
5147 }
5148
5149 val = get_param(cmd, "AMSDU");
5150 if (val) {
5151 if (strcasecmp(val, "Enable") == 0)
5152 dut->ap_amsdu = 1;
5153 else if (strcasecmp(val, "Disable") == 0)
5154 dut->ap_amsdu = 2;
5155 }
5156
5157 val = get_param(cmd, "NumMSDU");
5158 if (val) {
5159 send_resp(dut, conn, SIGMA_ERROR,
5160 "ErrorCode, NumMSDU is not supported yet");
5161 return -1;
5162 }
5163
5164 val = get_param(cmd, "ABFTLRang");
5165 if (val) {
5166 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005167 "ABFTLRang parameter %s", val);
5168 if (strcmp(val, "Gt1") == 0)
5169 abft_len = 2; /* 2 slots in this case */
5170 }
5171
5172 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5173 send_resp(dut, conn, SIGMA_ERROR,
5174 "ErrorCode, Can't set ABFT length");
5175 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005176 }
5177
5178 if (sta_pcp_start(dut, conn, cmd) < 0) {
5179 send_resp(dut, conn, SIGMA_ERROR,
5180 "ErrorCode, Can't start PCP role");
5181 return -1;
5182 }
5183
5184 return sta_set_60g_common(dut, conn, cmd);
5185}
5186
5187
5188static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5189 struct sigma_cmd *cmd)
5190{
5191 const char *val = get_param(cmd, "DiscoveryMode");
5192
5193 if (dut->dev_role != DEVROLE_STA) {
5194 send_resp(dut, conn, SIGMA_INVALID,
5195 "ErrorCode,Invalid DevRole");
5196 return 0;
5197 }
5198
5199 if (val) {
5200 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5201 /* Ignore Discovery mode till Driver expose API. */
5202#if 0
5203 if (strcasecmp(val, "1") == 0) {
5204 send_resp(dut, conn, SIGMA_INVALID,
5205 "ErrorCode,DiscoveryMode 1 not supported");
5206 return 0;
5207 }
5208
5209 if (strcasecmp(val, "0") == 0) {
5210 /* OK */
5211 } else {
5212 send_resp(dut, conn, SIGMA_INVALID,
5213 "ErrorCode,DiscoveryMode not supported");
5214 return 0;
5215 }
5216#endif
5217 }
5218
5219 if (start_sta_mode(dut) != 0)
5220 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5221 return sta_set_60g_common(dut, conn, cmd);
5222}
5223
5224
5225static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5226 struct sigma_cmd *cmd)
5227{
5228 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005229 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305230
Jouni Malinened77e672018-01-10 16:45:13 +02005231 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005232 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005233 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305234 wpa_command(intf, "DISCONNECT");
5235 return 1;
5236 }
5237
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005238 disconnect_station(dut);
5239 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5240 * due to cached results. */
5241 wpa_command(intf, "SET ignore_old_scan_res 1");
5242 wpa_command(intf, "BSS_FLUSH");
5243 return 1;
5244}
5245
5246
5247static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5248 struct sigma_cmd *cmd)
5249{
5250 const char *intf = get_param(cmd, "Interface");
5251 const char *bssid = get_param(cmd, "bssid");
5252 const char *val = get_param(cmd, "CHANNEL");
5253 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305254 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305255 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005256 int res;
5257 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305258 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305259 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005260
5261 if (bssid == NULL) {
5262 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5263 "argument");
5264 return 0;
5265 }
5266
5267 if (val)
5268 chan = atoi(val);
5269
5270 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5271 /* The current network may be from sta_associate or
5272 * sta_hs2_associate
5273 */
5274 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5275 0 ||
5276 set_network(intf, 0, "bssid", bssid) < 0)
5277 return -2;
5278 }
5279
5280 ctrl = open_wpa_mon(intf);
5281 if (ctrl == NULL) {
5282 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5283 "wpa_supplicant monitor connection");
5284 return -1;
5285 }
5286
Sunil Duttd30ce092018-01-11 23:56:29 +05305287 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5288 sizeof(result)) < 0 ||
5289 strncmp(result, "COMPLETED", 9) != 0) {
5290 sigma_dut_print(dut, DUT_MSG_DEBUG,
5291 "sta_reassoc: Not connected");
5292 fastreassoc = 0;
5293 }
5294
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305295 if (dut->rsne_override) {
5296#ifdef NL80211_SUPPORT
5297 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5298 sta_config_rsnie(dut, 1);
5299 dut->config_rsnie = 1;
5300 }
5301#endif /* NL80211_SUPPORT */
5302 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5303 dut->rsne_override);
5304 if (wpa_command(intf, buf) < 0) {
5305 send_resp(dut, conn, SIGMA_ERROR,
5306 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5307 return 0;
5308 }
5309 }
5310
Sunil Duttd30ce092018-01-11 23:56:29 +05305311 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005312#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305313 if (chan) {
5314 unsigned int freq;
5315
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02005316 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305317 if (!freq) {
5318 sigma_dut_print(dut, DUT_MSG_ERROR,
5319 "Invalid channel number provided: %d",
5320 chan);
5321 send_resp(dut, conn, SIGMA_INVALID,
5322 "ErrorCode,Invalid channel number");
5323 goto close_mon_conn;
5324 }
5325 res = snprintf(buf, sizeof(buf),
5326 "SCAN TYPE=ONLY freq=%d", freq);
5327 } else {
5328 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5329 }
5330 if (res < 0 || res >= (int) sizeof(buf)) {
5331 send_resp(dut, conn, SIGMA_ERROR,
5332 "ErrorCode,snprintf failed");
5333 goto close_mon_conn;
5334 }
5335 if (wpa_command(intf, buf) < 0) {
5336 sigma_dut_print(dut, DUT_MSG_INFO,
5337 "Failed to start scan");
5338 send_resp(dut, conn, SIGMA_ERROR,
5339 "ErrorCode,scan failed");
5340 goto close_mon_conn;
5341 }
5342
5343 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5344 buf, sizeof(buf));
5345 if (res < 0) {
5346 sigma_dut_print(dut, DUT_MSG_INFO,
5347 "Scan did not complete");
5348 send_resp(dut, conn, SIGMA_ERROR,
5349 "ErrorCode,scan did not complete");
5350 goto close_mon_conn;
5351 }
5352
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005353 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5354 < 0) {
5355 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5356 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305357 status = -2;
5358 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005359 }
5360 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5361 bssid, chan);
5362 if (res > 0 && res < (int) sizeof(buf))
5363 res = wpa_command(intf, buf);
5364
5365 if (res < 0 || res >= (int) sizeof(buf)) {
5366 send_resp(dut, conn, SIGMA_ERROR,
5367 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305368 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005369 }
5370#else /* ANDROID */
5371 sigma_dut_print(dut, DUT_MSG_DEBUG,
5372 "Reassoc using iwpriv - skip chan=%d info",
5373 chan);
5374 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5375 if (system(buf) != 0) {
5376 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305377 status = -2;
5378 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005379 }
5380#endif /* ANDROID */
5381 sigma_dut_print(dut, DUT_MSG_INFO,
5382 "sta_reassoc: Run %s successful", buf);
5383 } else if (wpa_command(intf, "REASSOCIATE")) {
5384 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5385 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305386 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005387 }
5388
5389 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5390 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305391 if (res < 0) {
5392 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5393 status = -1;
5394 goto close_mon_conn;
5395 }
5396 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005397
Ashwini Patil467efef2017-05-25 12:18:27 +05305398close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005399 wpa_ctrl_detach(ctrl);
5400 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305401 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005402}
5403
5404
5405static void hs2_clear_credentials(const char *intf)
5406{
5407 wpa_command(intf, "REMOVE_CRED all");
5408}
5409
5410
Lior Davidcc88b562017-01-03 18:52:09 +02005411#ifdef __linux__
5412static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5413 unsigned int *aid)
5414{
Lior David0fe101e2017-03-09 16:09:50 +02005415 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005416
Lior David0fe101e2017-03-09 16:09:50 +02005417 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005418}
5419#endif /* __linux__ */
5420
5421
5422static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5423 unsigned int *aid)
5424{
5425 switch (get_driver_type()) {
5426#ifdef __linux__
5427 case DRIVER_WIL6210:
5428 return wil6210_get_aid(dut, bssid, aid);
5429#endif /* __linux__ */
5430 default:
5431 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5432 return -1;
5433 }
5434}
5435
5436
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005437static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5438 struct sigma_cmd *cmd)
5439{
5440 char buf[MAX_CMD_LEN];
5441 char bss_list[MAX_CMD_LEN];
5442 const char *parameter = get_param(cmd, "Parameter");
5443
5444 if (parameter == NULL)
5445 return -1;
5446
Lior Davidcc88b562017-01-03 18:52:09 +02005447 if (strcasecmp(parameter, "AID") == 0) {
5448 unsigned int aid = 0;
5449 char bssid[20];
5450
5451 if (get_wpa_status(get_station_ifname(), "bssid",
5452 bssid, sizeof(bssid)) < 0) {
5453 sigma_dut_print(dut, DUT_MSG_ERROR,
5454 "could not get bssid");
5455 return -2;
5456 }
5457
5458 if (sta_get_aid_60g(dut, bssid, &aid))
5459 return -2;
5460
5461 snprintf(buf, sizeof(buf), "aid,%d", aid);
5462 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5463 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5464 return 0;
5465 }
5466
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005467 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5468 char *bss_line;
5469 char *bss_id = NULL;
5470 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305471 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005472
5473 if (ifname == NULL) {
5474 sigma_dut_print(dut, DUT_MSG_INFO,
5475 "For get DiscoveredDevList need Interface name.");
5476 return -1;
5477 }
5478
5479 /*
5480 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5481 * of BSSIDs in "bssid=<BSSID>\n"
5482 */
5483 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5484 bss_list,
5485 sizeof(bss_list)) < 0) {
5486 sigma_dut_print(dut, DUT_MSG_ERROR,
5487 "Failed to get bss list");
5488 return -1;
5489 }
5490
5491 sigma_dut_print(dut, DUT_MSG_DEBUG,
5492 "bss list for ifname:%s is:%s",
5493 ifname, bss_list);
5494
5495 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305496 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005497 while (bss_line) {
5498 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5499 bss_id) {
5500 int len;
5501
5502 len = snprintf(buf + strlen(buf),
5503 sizeof(buf) - strlen(buf),
5504 ",%s", bss_id);
5505 free(bss_id);
5506 bss_id = NULL;
5507 if (len < 0) {
5508 sigma_dut_print(dut,
5509 DUT_MSG_ERROR,
5510 "Failed to read BSSID");
5511 send_resp(dut, conn, SIGMA_ERROR,
5512 "ErrorCode,Failed to read BSS ID");
5513 return 0;
5514 }
5515
5516 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5517 sigma_dut_print(dut,
5518 DUT_MSG_ERROR,
5519 "Response buf too small for list");
5520 send_resp(dut, conn,
5521 SIGMA_ERROR,
5522 "ErrorCode,Response buf too small for list");
5523 return 0;
5524 }
5525 }
5526
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305527 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005528 }
5529
5530 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5531 buf);
5532 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5533 return 0;
5534 }
5535
5536 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5537 return 0;
5538}
5539
5540
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07005541static int sta_get_parameter_he(struct sigma_dut *dut, struct sigma_conn *conn,
5542 struct sigma_cmd *cmd)
5543{
5544 char buf[MAX_CMD_LEN];
5545 const char *parameter = get_param(cmd, "Parameter");
5546
5547 if (!parameter)
5548 return -1;
5549
5550 if (strcasecmp(parameter, "RSSI") == 0) {
5551 char rssi[10];
5552
5553 if (get_wpa_signal_poll(dut, get_station_ifname(), "RSSI",
5554 rssi, sizeof(rssi)) < 0) {
5555 sigma_dut_print(dut, DUT_MSG_ERROR,
5556 "Could not get RSSI");
5557 return -2;
5558 }
5559
5560 snprintf(buf, sizeof(buf), "rssi,%s", rssi);
5561 sigma_dut_print(dut, DUT_MSG_INFO, "RSSI %s", buf);
5562 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5563 return 0;
5564 }
5565
5566 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5567 return 0;
5568}
5569
5570
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005571static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5572 struct sigma_cmd *cmd)
5573{
5574 const char *program = get_param(cmd, "Program");
5575
5576 if (program == NULL)
5577 return -1;
5578
5579 if (strcasecmp(program, "P2PNFC") == 0)
5580 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5581
5582 if (strcasecmp(program, "60ghz") == 0)
5583 return sta_get_parameter_60g(dut, conn, cmd);
5584
Kiran Kumar Lokerec86d8022018-10-11 13:57:12 -07005585 if (strcasecmp(program, "he") == 0)
5586 return sta_get_parameter_he(dut, conn, cmd);
5587
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005588#ifdef ANDROID_NAN
5589 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005590 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005591#endif /* ANDROID_NAN */
5592
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005593#ifdef MIRACAST
5594 if (strcasecmp(program, "WFD") == 0 ||
5595 strcasecmp(program, "DisplayR2") == 0)
5596 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5597#endif /* MIRACAST */
5598
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005599 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5600 return 0;
5601}
5602
5603
5604static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5605 const char *type)
5606{
5607 char buf[100];
5608
5609 if (dut->program == PROGRAM_VHT) {
5610 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5611 if (system(buf) != 0) {
5612 sigma_dut_print(dut, DUT_MSG_ERROR,
5613 "iwpriv %s chwidth failed", intf);
5614 }
5615
5616 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5617 if (system(buf) != 0) {
5618 sigma_dut_print(dut, DUT_MSG_ERROR,
5619 "iwpriv %s mode 11ACVHT80 failed",
5620 intf);
5621 }
5622
5623 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5624 if (system(buf) != 0) {
5625 sigma_dut_print(dut, DUT_MSG_ERROR,
5626 "iwpriv %s vhtmcs -1 failed", intf);
5627 }
5628 }
5629
5630 if (dut->program == PROGRAM_HT) {
5631 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5632 if (system(buf) != 0) {
5633 sigma_dut_print(dut, DUT_MSG_ERROR,
5634 "iwpriv %s chwidth failed", intf);
5635 }
5636
5637 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5638 if (system(buf) != 0) {
5639 sigma_dut_print(dut, DUT_MSG_ERROR,
5640 "iwpriv %s mode 11naht40 failed",
5641 intf);
5642 }
5643
5644 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5645 if (system(buf) != 0) {
5646 sigma_dut_print(dut, DUT_MSG_ERROR,
5647 "iwpriv set11NRates failed");
5648 }
5649 }
5650
5651 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5652 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5653 if (system(buf) != 0) {
5654 sigma_dut_print(dut, DUT_MSG_ERROR,
5655 "disabling powersave failed");
5656 }
5657
5658 /* Reset CTS width */
5659 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5660 intf);
5661 if (system(buf) != 0) {
5662 sigma_dut_print(dut, DUT_MSG_ERROR,
5663 "wifitool %s beeliner_fw_test 54 0 failed",
5664 intf);
5665 }
5666
5667 /* Enable Dynamic Bandwidth signalling by default */
5668 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5669 if (system(buf) != 0) {
5670 sigma_dut_print(dut, DUT_MSG_ERROR,
5671 "iwpriv %s cwmenable 1 failed", intf);
5672 }
5673
5674 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5675 if (system(buf) != 0) {
5676 sigma_dut_print(dut, DUT_MSG_ERROR,
5677 "iwpriv rts failed");
5678 }
5679 }
5680
5681 if (type && strcasecmp(type, "Testbed") == 0) {
5682 dut->testbed_flag_txsp = 1;
5683 dut->testbed_flag_rxsp = 1;
5684 /* STA has to set spatial stream to 2 per Appendix H */
5685 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5686 if (system(buf) != 0) {
5687 sigma_dut_print(dut, DUT_MSG_ERROR,
5688 "iwpriv vht_mcsmap failed");
5689 }
5690
5691 /* Disable LDPC per Appendix H */
5692 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5693 if (system(buf) != 0) {
5694 sigma_dut_print(dut, DUT_MSG_ERROR,
5695 "iwpriv %s ldpc 0 failed", intf);
5696 }
5697
5698 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5699 if (system(buf) != 0) {
5700 sigma_dut_print(dut, DUT_MSG_ERROR,
5701 "iwpriv amsdu failed");
5702 }
5703
5704 /* TODO: Disable STBC 2x1 transmit and receive */
5705 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5706 if (system(buf) != 0) {
5707 sigma_dut_print(dut, DUT_MSG_ERROR,
5708 "Disable tx_stbc 0 failed");
5709 }
5710
5711 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5712 if (system(buf) != 0) {
5713 sigma_dut_print(dut, DUT_MSG_ERROR,
5714 "Disable rx_stbc 0 failed");
5715 }
5716
5717 /* STA has to disable Short GI per Appendix H */
5718 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5719 if (system(buf) != 0) {
5720 sigma_dut_print(dut, DUT_MSG_ERROR,
5721 "iwpriv %s shortgi 0 failed", intf);
5722 }
5723 }
5724
5725 if (type && strcasecmp(type, "DUT") == 0) {
5726 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5727 if (system(buf) != 0) {
5728 sigma_dut_print(dut, DUT_MSG_ERROR,
5729 "iwpriv %s nss 3 failed", intf);
5730 }
Arif Hussainac6c5112018-05-25 17:34:00 -07005731 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005732
5733 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5734 if (system(buf) != 0) {
5735 sigma_dut_print(dut, DUT_MSG_ERROR,
5736 "iwpriv %s shortgi 1 failed", intf);
5737 }
5738 }
5739}
5740
5741
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005742#ifdef NL80211_SUPPORT
5743static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5744 enum he_mcs_config mcs)
5745{
5746 struct nl_msg *msg;
5747 int ret = 0;
5748 struct nlattr *params;
5749 int ifindex;
5750
5751 ifindex = if_nametoindex(intf);
5752 if (ifindex == 0) {
5753 sigma_dut_print(dut, DUT_MSG_ERROR,
5754 "%s: Index for interface %s failed",
5755 __func__, intf);
5756 return -1;
5757 }
5758
5759 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5760 NL80211_CMD_VENDOR)) ||
5761 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5762 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5763 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5764 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5765 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5766 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5767 mcs)) {
5768 sigma_dut_print(dut, DUT_MSG_ERROR,
5769 "%s: err in adding vendor_cmd and vendor_data",
5770 __func__);
5771 nlmsg_free(msg);
5772 return -1;
5773 }
5774 nla_nest_end(msg, params);
5775
5776 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5777 if (ret) {
5778 sigma_dut_print(dut, DUT_MSG_ERROR,
5779 "%s: err in send_and_recv_msgs, ret=%d",
5780 __func__, ret);
5781 }
5782 return ret;
5783}
5784#endif /* NL80211_SUPPORT */
5785
5786
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07005787static int sta_set_action_tx_in_he_tb_ppdu(struct sigma_dut *dut,
5788 const char *intf, int enable)
5789{
5790#ifdef NL80211_SUPPORT
5791 struct nl_msg *msg;
5792 int ret = 0;
5793 struct nlattr *params;
5794 int ifindex;
5795
5796 ifindex = if_nametoindex(intf);
5797 if (ifindex == 0) {
5798 sigma_dut_print(dut, DUT_MSG_ERROR,
5799 "%s: Index for interface %s failed",
5800 __func__, intf);
5801 return -1;
5802 }
5803
5804 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5805 NL80211_CMD_VENDOR)) ||
5806 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5807 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5808 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5809 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5810 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5811 nla_put_u8(msg,
5812 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_ACTION_TX_TB_PPDU,
5813 enable)) {
5814 sigma_dut_print(dut, DUT_MSG_ERROR,
5815 "%s: err in adding vendor_cmd and vendor_data",
5816 __func__);
5817 nlmsg_free(msg);
5818 return -1;
5819 }
5820 nla_nest_end(msg, params);
5821
5822 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5823 if (ret) {
5824 sigma_dut_print(dut, DUT_MSG_ERROR,
5825 "%s: err in send_and_recv_msgs, ret=%d",
5826 __func__, ret);
5827 }
5828 return ret;
5829#else /* NL80211_SUPPORT */
5830 sigma_dut_print(dut, DUT_MSG_ERROR,
5831 "HE action Tx TB PPDU cannot be set without NL80211_SUPPORT defined");
5832 return -1;
5833#endif /* NL80211_SUPPORT */
5834}
5835
5836
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005837static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
5838 const char *intf, int enable)
5839{
5840#ifdef NL80211_SUPPORT
5841 struct nl_msg *msg;
5842 int ret = 0;
5843 struct nlattr *params;
5844 int ifindex;
5845
5846 ifindex = if_nametoindex(intf);
5847 if (ifindex == 0) {
5848 sigma_dut_print(dut, DUT_MSG_ERROR,
5849 "%s: Index for interface %s failed",
5850 __func__, intf);
5851 return -1;
5852 }
5853
5854 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5855 NL80211_CMD_VENDOR)) ||
5856 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5857 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5858 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5859 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5860 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5861 nla_put_u8(msg,
5862 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
5863 enable)) {
5864 sigma_dut_print(dut, DUT_MSG_ERROR,
5865 "%s: err in adding vendor_cmd and vendor_data",
5866 __func__);
5867 nlmsg_free(msg);
5868 return -1;
5869 }
5870 nla_nest_end(msg, params);
5871
5872 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5873 if (ret) {
5874 sigma_dut_print(dut, DUT_MSG_ERROR,
5875 "%s: err in send_and_recv_msgs, ret=%d",
5876 __func__, ret);
5877 }
5878 return ret;
5879#else /* NL80211_SUPPORT */
5880 sigma_dut_print(dut, DUT_MSG_ERROR,
5881 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
5882 return -1;
5883#endif /* NL80211_SUPPORT */
5884}
5885
5886
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005887static int sta_set_addba_buf_size(struct sigma_dut *dut,
5888 const char *intf, int bufsize)
5889{
5890#ifdef NL80211_SUPPORT
5891 struct nl_msg *msg;
5892 int ret = 0;
5893 struct nlattr *params;
5894 int ifindex;
5895
5896 ifindex = if_nametoindex(intf);
5897 if (ifindex == 0) {
5898 sigma_dut_print(dut, DUT_MSG_ERROR,
5899 "%s: Index for interface %s failed",
5900 __func__, intf);
5901 return -1;
5902 }
5903
5904 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5905 NL80211_CMD_VENDOR)) ||
5906 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5907 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5908 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5909 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5910 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07005911 nla_put_u16(msg,
5912 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
5913 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005914 sigma_dut_print(dut, DUT_MSG_ERROR,
5915 "%s: err in adding vendor_cmd and vendor_data",
5916 __func__);
5917 nlmsg_free(msg);
5918 return -1;
5919 }
5920 nla_nest_end(msg, params);
5921
5922 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5923 if (ret) {
5924 sigma_dut_print(dut, DUT_MSG_ERROR,
5925 "%s: err in send_and_recv_msgs, ret=%d",
5926 __func__, ret);
5927 }
5928 return ret;
5929#else /* NL80211_SUPPORT */
5930 sigma_dut_print(dut, DUT_MSG_ERROR,
5931 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
5932 return -1;
5933#endif /* NL80211_SUPPORT */
5934}
5935
5936
Arif Hussain8d5b27b2018-05-14 14:31:03 -07005937static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
5938 int enable)
5939{
5940#ifdef NL80211_SUPPORT
5941 struct nl_msg *msg;
5942 int ret = 0;
5943 struct nlattr *params;
5944 int ifindex;
5945
5946 ifindex = if_nametoindex(intf);
5947 if (ifindex == 0) {
5948 sigma_dut_print(dut, DUT_MSG_ERROR,
5949 "%s: Index for interface %s failed",
5950 __func__, intf);
5951 return -1;
5952 }
5953
5954 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5955 NL80211_CMD_VENDOR)) ||
5956 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5957 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5958 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5959 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5960 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5961 nla_put_u8(msg,
5962 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
5963 enable)) {
5964 sigma_dut_print(dut, DUT_MSG_ERROR,
5965 "%s: err in adding vendor_cmd and vendor_data",
5966 __func__);
5967 nlmsg_free(msg);
5968 return -1;
5969 }
5970 nla_nest_end(msg, params);
5971
5972 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5973 if (ret) {
5974 sigma_dut_print(dut, DUT_MSG_ERROR,
5975 "%s: err in send_and_recv_msgs, ret=%d",
5976 __func__, ret);
5977 }
5978 return ret;
5979#else /* NL80211_SUPPORT */
5980 sigma_dut_print(dut, DUT_MSG_ERROR,
5981 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
5982 return -1;
5983#endif /* NL80211_SUPPORT */
5984}
5985
5986
Arif Hussain9765f7d2018-07-03 08:28:26 -07005987static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
5988 int val)
5989{
5990#ifdef NL80211_SUPPORT
5991 struct nl_msg *msg;
5992 int ret = 0;
5993 struct nlattr *params;
5994 int ifindex;
5995
5996 ifindex = if_nametoindex(intf);
5997 if (ifindex == 0) {
5998 sigma_dut_print(dut, DUT_MSG_ERROR,
5999 "%s: Index for interface %s failed, val:%d",
6000 __func__, intf, val);
6001 return -1;
6002 }
6003
6004 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6005 NL80211_CMD_VENDOR)) ||
6006 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6007 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6008 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6009 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6010 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6011 nla_put_u8(msg,
6012 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
6013 val)) {
6014 sigma_dut_print(dut, DUT_MSG_ERROR,
6015 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6016 __func__, val);
6017 nlmsg_free(msg);
6018 return -1;
6019 }
6020 nla_nest_end(msg, params);
6021
6022 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6023 if (ret) {
6024 sigma_dut_print(dut, DUT_MSG_ERROR,
6025 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6026 __func__, ret, val);
6027 }
6028 return ret;
6029#else /* NL80211_SUPPORT */
6030 sigma_dut_print(dut, DUT_MSG_ERROR,
6031 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
6032 return -1;
6033#endif /* NL80211_SUPPORT */
6034}
6035
6036
Arif Hussain68d23f52018-07-11 13:39:08 -07006037#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006038static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
6039 enum qca_wlan_he_mac_padding_dur val)
6040{
Arif Hussain68d23f52018-07-11 13:39:08 -07006041 struct nl_msg *msg;
6042 int ret = 0;
6043 struct nlattr *params;
6044 int ifindex;
6045
6046 ifindex = if_nametoindex(intf);
6047 if (ifindex == 0) {
6048 sigma_dut_print(dut, DUT_MSG_ERROR,
6049 "%s: Index for interface %s failed, val:%d",
6050 __func__, intf, val);
6051 return -1;
6052 }
6053
6054 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6055 NL80211_CMD_VENDOR)) ||
6056 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6057 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6058 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6059 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6060 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6061 nla_put_u8(msg,
6062 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
6063 val)) {
6064 sigma_dut_print(dut, DUT_MSG_ERROR,
6065 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6066 __func__, val);
6067 nlmsg_free(msg);
6068 return -1;
6069 }
6070 nla_nest_end(msg, params);
6071
6072 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6073 if (ret) {
6074 sigma_dut_print(dut, DUT_MSG_ERROR,
6075 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6076 __func__, ret, val);
6077 }
6078 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07006079}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006080#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07006081
6082
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006083static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
6084 int val)
6085{
6086#ifdef NL80211_SUPPORT
6087 struct nl_msg *msg;
6088 int ret = 0;
6089 struct nlattr *params;
6090 int ifindex;
6091
6092 ifindex = if_nametoindex(intf);
6093 if (ifindex == 0) {
6094 sigma_dut_print(dut, DUT_MSG_ERROR,
6095 "%s: Index for interface %s failed, val:%d",
6096 __func__, intf, val);
6097 return -1;
6098 }
6099
6100 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6101 NL80211_CMD_VENDOR)) ||
6102 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6103 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6104 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6105 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6106 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6107 nla_put_u8(msg,
6108 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
6109 val)) {
6110 sigma_dut_print(dut, DUT_MSG_ERROR,
6111 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6112 __func__, val);
6113 nlmsg_free(msg);
6114 return -1;
6115 }
6116 nla_nest_end(msg, params);
6117
6118 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6119 if (ret) {
6120 sigma_dut_print(dut, DUT_MSG_ERROR,
6121 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6122 __func__, ret, val);
6123 }
6124 return ret;
6125#else /* NL80211_SUPPORT */
6126 sigma_dut_print(dut, DUT_MSG_ERROR,
6127 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
6128 return -1;
6129#endif /* NL80211_SUPPORT */
6130}
6131
6132
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006133static int sta_set_he_om_ctrl_nss(struct sigma_dut *dut, const char *intf,
6134 int val)
6135{
6136#ifdef NL80211_SUPPORT
6137 struct nl_msg *msg;
6138 int ret = 0;
6139 struct nlattr *params;
6140 int ifindex;
6141
6142 ifindex = if_nametoindex(intf);
6143 if (ifindex == 0) {
6144 sigma_dut_print(dut, DUT_MSG_ERROR,
6145 "%s: Index for interface %s failed, val:%d",
6146 __func__, intf, val);
6147 return -1;
6148 }
6149
6150 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6151 NL80211_CMD_VENDOR)) ||
6152 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6153 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6154 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6155 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6156 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6157 nla_put_u8(msg,
6158 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_NSS,
6159 val)) {
6160 sigma_dut_print(dut, DUT_MSG_ERROR,
6161 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6162 __func__, val);
6163 nlmsg_free(msg);
6164 return -1;
6165 }
6166 nla_nest_end(msg, params);
6167
6168 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6169 if (ret) {
6170 sigma_dut_print(dut, DUT_MSG_ERROR,
6171 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6172 __func__, ret, val);
6173 }
6174 return ret;
6175#else /* NL80211_SUPPORT */
6176 sigma_dut_print(dut, DUT_MSG_ERROR,
6177 "OM CTRL NSS cannot be set without NL80211_SUPPORT defined");
6178 return -1;
6179#endif /* NL80211_SUPPORT */
6180}
6181
6182
6183static int sta_set_he_om_ctrl_bw(struct sigma_dut *dut, const char *intf,
6184 enum qca_wlan_he_om_ctrl_ch_bw val)
6185{
6186#ifdef NL80211_SUPPORT
6187 struct nl_msg *msg;
6188 int ret = 0;
6189 struct nlattr *params;
6190 int ifindex;
6191
6192 ifindex = if_nametoindex(intf);
6193 if (ifindex == 0) {
6194 sigma_dut_print(dut, DUT_MSG_ERROR,
6195 "%s: Index for interface %s failed, val:%d",
6196 __func__, intf, val);
6197 return -1;
6198 }
6199
6200 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6201 NL80211_CMD_VENDOR)) ||
6202 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6203 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6204 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6205 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6206 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6207 nla_put_u8(msg,
6208 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_BW,
6209 val)) {
6210 sigma_dut_print(dut, DUT_MSG_ERROR,
6211 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6212 __func__, val);
6213 nlmsg_free(msg);
6214 return -1;
6215 }
6216 nla_nest_end(msg, params);
6217
6218 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6219 if (ret) {
6220 sigma_dut_print(dut, DUT_MSG_ERROR,
6221 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6222 __func__, ret, val);
6223 }
6224 return ret;
6225#else /* NL80211_SUPPORT */
6226 sigma_dut_print(dut, DUT_MSG_ERROR,
6227 "OM CTRL BW cannot be set without NL80211_SUPPORT defined");
6228 return -1;
6229#endif /* NL80211_SUPPORT */
6230}
6231
6232
6233#ifdef NL80211_SUPPORT
6234static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
6235{
6236 struct nl_msg *msg;
6237 int ret = 0;
6238 struct nlattr *params;
6239 int ifindex;
6240
6241 ifindex = if_nametoindex(intf);
6242 if (ifindex == 0) {
6243 sigma_dut_print(dut, DUT_MSG_ERROR,
6244 "%s: Index for interface %s failed",
6245 __func__, intf);
6246 return -1;
6247 }
6248
6249 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6250 NL80211_CMD_VENDOR)) ||
6251 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6252 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6253 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6254 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6255 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6256 nla_put_flag(msg,
6257 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
6258 sigma_dut_print(dut, DUT_MSG_ERROR,
6259 "%s: err in adding vendor_cmd and vendor_data",
6260 __func__);
6261 nlmsg_free(msg);
6262 return -1;
6263 }
6264 nla_nest_end(msg, params);
6265
6266 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6267 if (ret) {
6268 sigma_dut_print(dut, DUT_MSG_ERROR,
6269 "%s: err in send_and_recv_msgs, ret=%d",
6270 __func__, ret);
6271 }
6272 return ret;
6273}
6274#endif /* NL80211_SUPPORT */
6275
6276
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006277static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
6278 int val)
6279{
6280#ifdef NL80211_SUPPORT
6281 struct nl_msg *msg;
6282 int ret = 0;
6283 struct nlattr *params;
6284 int ifindex;
6285
6286 ifindex = if_nametoindex(intf);
6287 if (ifindex == 0) {
6288 sigma_dut_print(dut, DUT_MSG_ERROR,
6289 "%s: Index for interface %s failed, val:%d",
6290 __func__, intf, val);
6291 return -1;
6292 }
6293
6294 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6295 NL80211_CMD_VENDOR)) ||
6296 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6297 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6298 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6299 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6300 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6301 nla_put_u8(msg,
6302 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
6303 val)) {
6304 sigma_dut_print(dut, DUT_MSG_ERROR,
6305 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6306 __func__, val);
6307 nlmsg_free(msg);
6308 return -1;
6309 }
6310 nla_nest_end(msg, params);
6311
6312 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6313 if (ret) {
6314 sigma_dut_print(dut, DUT_MSG_ERROR,
6315 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6316 __func__, ret, val);
6317 }
6318 return ret;
6319#else /* NL80211_SUPPORT */
6320 sigma_dut_print(dut, DUT_MSG_ERROR,
6321 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
6322 return -1;
6323#endif /* NL80211_SUPPORT */
6324}
6325
6326
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006327static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
6328 int val)
6329{
6330#ifdef NL80211_SUPPORT
6331 struct nl_msg *msg;
6332 int ret = 0;
6333 struct nlattr *params;
6334 int ifindex;
6335
6336 ifindex = if_nametoindex(intf);
6337 if (ifindex == 0) {
6338 sigma_dut_print(dut, DUT_MSG_ERROR,
6339 "%s: Index for interface %s failed, val:%d",
6340 __func__, intf, val);
6341 return -1;
6342 }
6343
6344 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6345 NL80211_CMD_VENDOR)) ||
6346 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6347 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6348 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6349 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6350 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6351 nla_put_u8(msg,
6352 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
6353 val)) {
6354 sigma_dut_print(dut, DUT_MSG_ERROR,
6355 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6356 __func__, val);
6357 nlmsg_free(msg);
6358 return -1;
6359 }
6360 nla_nest_end(msg, params);
6361
6362 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6363 if (ret) {
6364 sigma_dut_print(dut, DUT_MSG_ERROR,
6365 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6366 __func__, ret, val);
6367 }
6368 return ret;
6369#else /* NL80211_SUPPORT */
6370 sigma_dut_print(dut, DUT_MSG_ERROR,
6371 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
6372 return -1;
6373#endif /* NL80211_SUPPORT */
6374}
6375
6376
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006377static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
6378 const char *type)
6379{
6380 char buf[60];
6381
6382 if (dut->program == PROGRAM_HE) {
6383 /* resetting phymode to auto in case of HE program */
6384 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
6385 if (system(buf) != 0) {
6386 sigma_dut_print(dut, DUT_MSG_ERROR,
6387 "iwpriv %s setphymode failed", intf);
6388 }
6389
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07006390 /* reset the rate to Auto rate */
6391 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
6392 intf);
6393 if (system(buf) != 0) {
6394 sigma_dut_print(dut, DUT_MSG_ERROR,
6395 "iwpriv %s set_11ax_rate 0xff failed",
6396 intf);
6397 }
6398
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07006399 /* reset the LDPC setting */
6400 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
6401 if (system(buf) != 0) {
6402 sigma_dut_print(dut, DUT_MSG_ERROR,
6403 "iwpriv %s ldpc 1 failed", intf);
6404 }
6405
Kiran Kumar Lokered6149ff2018-12-05 20:20:41 -08006406 /* reset the power save setting */
6407 snprintf(buf, sizeof(buf), "iwpriv %s setPower 2", intf);
6408 if (system(buf) != 0) {
6409 sigma_dut_print(dut, DUT_MSG_ERROR,
6410 "iwpriv %s setPower 2 failed", intf);
6411 }
6412
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006413 /* remove all network profiles */
6414 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006415
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006416 /* Configure ADDBA Req/Rsp buffer size to be 64 */
6417 sta_set_addba_buf_size(dut, intf, 64);
6418
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08006419#ifdef NL80211_SUPPORT
6420 /* Disable noackpolicy for all AC */
6421 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
6422 sigma_dut_print(dut, DUT_MSG_ERROR,
6423 "Disable of noackpolicy for all AC failed");
6424 }
6425#endif /* NL80211_SUPPORT */
6426
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08006427 /* Enable WMM by default */
6428 if (wcn_sta_set_wmm(dut, intf, "on")) {
6429 sigma_dut_print(dut, DUT_MSG_ERROR,
6430 "Enable of WMM in sta_reset_default_wcn failed");
6431 }
6432
6433 /* Disable ADDBA_REJECT by default */
6434 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
6435 sigma_dut_print(dut, DUT_MSG_ERROR,
6436 "Disable of addba_reject in sta_reset_default_wcn failed");
6437 }
6438
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006439 /* Enable sending of ADDBA by default */
6440 if (nlvendor_config_send_addba(dut, intf, 1)) {
6441 sigma_dut_print(dut, DUT_MSG_ERROR,
6442 "Enable sending of ADDBA in sta_reset_default_wcn failed");
6443 }
6444
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08006445 /* Enable AMPDU by default */
6446 iwpriv_sta_set_ampdu(dut, intf, 1);
6447
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006448#ifdef NL80211_SUPPORT
6449 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
6450 sigma_dut_print(dut, DUT_MSG_ERROR,
6451 "Set LTF config to default in sta_reset_default_wcn failed");
6452 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07006453
6454 if (sta_set_beamformee_sts(dut, intf, 0)) {
6455 sigma_dut_print(dut, DUT_MSG_ERROR,
6456 "Failed to set BeamformeeSTS");
6457 }
Arif Hussain68d23f52018-07-11 13:39:08 -07006458
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006459 if (sta_set_mac_padding_duration(
6460 dut, intf,
6461 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07006462 sigma_dut_print(dut, DUT_MSG_ERROR,
6463 "Failed to set MAC padding duration");
6464 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006465
6466 if (sta_set_mu_edca_override(dut, intf, 0)) {
6467 sigma_dut_print(dut, DUT_MSG_ERROR,
6468 "ErrorCode,Failed to set MU EDCA override disable");
6469 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006470
6471 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
6472 sigma_dut_print(dut, DUT_MSG_ERROR,
6473 "Failed to set OM ctrl supp");
6474 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006475
6476 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
6477 sigma_dut_print(dut, DUT_MSG_ERROR,
6478 "Failed to set Tx SU PPDU enable");
6479 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006480
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07006481 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 0)) {
6482 sigma_dut_print(dut, DUT_MSG_ERROR,
6483 "failed to send TB PPDU Tx cfg");
6484 }
6485
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006486 if (sta_set_he_om_ctrl_reset(dut, intf)) {
6487 sigma_dut_print(dut, DUT_MSG_ERROR,
6488 "Failed to set OM ctrl reset");
6489 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006490#endif /* NL80211_SUPPORT */
6491
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006492 if (sta_set_tx_beamformee(dut, intf, 1)) {
6493 sigma_dut_print(dut, DUT_MSG_ERROR,
6494 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
6495 }
6496
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006497 /* Set nss to 1 and MCS 0-7 in case of testbed */
6498 if (type && strcasecmp(type, "Testbed") == 0) {
6499#ifdef NL80211_SUPPORT
6500 int ret;
6501#endif /* NL80211_SUPPORT */
6502
6503 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
6504 if (system(buf) != 0) {
6505 sigma_dut_print(dut, DUT_MSG_ERROR,
6506 "iwpriv %s nss failed", intf);
6507 }
6508
6509#ifdef NL80211_SUPPORT
6510 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
6511 if (ret) {
6512 sigma_dut_print(dut, DUT_MSG_ERROR,
6513 "Setting of MCS failed, ret:%d",
6514 ret);
6515 }
6516#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08006517
6518 /* Disable STBC as default */
6519 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006520
6521 /* Disable AMSDU as default */
6522 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08006523
6524#ifdef NL80211_SUPPORT
6525 /* HE fragmentation default off */
6526 if (sta_set_he_fragmentation(dut, intf,
6527 HE_FRAG_DISABLE)) {
6528 sigma_dut_print(dut, DUT_MSG_ERROR,
6529 "Setting of HE fragmentation failed");
6530 }
6531#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006532
6533 /* Enable WEP/TKIP with HE capability in testbed */
6534 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
6535 sigma_dut_print(dut, DUT_MSG_ERROR,
6536 "Enabling HE config with WEP/TKIP failed");
6537 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006538 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006539
6540 /* Defaults in case of DUT */
6541 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07006542 /* Enable STBC by default */
6543 wcn_sta_set_stbc(dut, intf, "1");
6544
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006545 /* set nss to 2 */
6546 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
6547 if (system(buf) != 0) {
6548 sigma_dut_print(dut, DUT_MSG_ERROR,
6549 "iwpriv %s nss 2 failed", intf);
6550 }
Arif Hussainac6c5112018-05-25 17:34:00 -07006551 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006552
6553#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07006554 /* Set HE_MCS to 0-11 */
6555 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006556 sigma_dut_print(dut, DUT_MSG_ERROR,
6557 "Setting of MCS failed");
6558 }
6559#endif /* NL80211_SUPPORT */
6560
6561 /* Disable WEP/TKIP with HE capability in DUT */
6562 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
6563 sigma_dut_print(dut, DUT_MSG_ERROR,
6564 "Enabling HE config with WEP/TKIP failed");
6565 }
6566 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006567 }
6568}
6569
6570
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006571static int cmd_sta_reset_default(struct sigma_dut *dut,
6572 struct sigma_conn *conn,
6573 struct sigma_cmd *cmd)
6574{
6575 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
6576 struct sigma_cmd *cmd);
6577 const char *intf = get_param(cmd, "Interface");
6578 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006579 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306580 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006581
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006582 if (!program)
6583 program = get_param(cmd, "prog");
6584 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006585 dut->device_type = STA_unknown;
6586 type = get_param(cmd, "type");
6587 if (type && strcasecmp(type, "Testbed") == 0)
6588 dut->device_type = STA_testbed;
6589 if (type && strcasecmp(type, "DUT") == 0)
6590 dut->device_type = STA_dut;
6591
6592 if (dut->program == PROGRAM_TDLS) {
6593 /* Clear TDLS testing mode */
6594 wpa_command(intf, "SET tdls_disabled 0");
6595 wpa_command(intf, "SET tdls_testing 0");
6596 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05306597 if (get_driver_type() == DRIVER_WCN) {
6598 /* Enable the WCN driver in TDLS Explicit trigger mode
6599 */
6600 wpa_command(intf, "SET tdls_external_control 0");
6601 wpa_command(intf, "SET tdls_trigger_control 0");
6602 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006603 }
6604
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006605#ifdef MIRACAST
6606 if (dut->program == PROGRAM_WFD ||
6607 dut->program == PROGRAM_DISPLAYR2)
6608 miracast_sta_reset_default(dut, conn, cmd);
6609#endif /* MIRACAST */
6610
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006611 switch (get_driver_type()) {
6612 case DRIVER_ATHEROS:
6613 sta_reset_default_ath(dut, intf, type);
6614 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006615 case DRIVER_WCN:
6616 sta_reset_default_wcn(dut, intf, type);
6617 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006618 default:
6619 break;
6620 }
6621
6622#ifdef ANDROID_NAN
6623 if (dut->program == PROGRAM_NAN)
6624 nan_cmd_sta_reset_default(dut, conn, cmd);
6625#endif /* ANDROID_NAN */
6626
Jouni Malinenba630452018-06-22 11:49:59 +03006627 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006628 unlink("SP/wi-fi.org/pps.xml");
6629 if (system("rm -r SP/*") != 0) {
6630 }
6631 unlink("next-client-cert.pem");
6632 unlink("next-client-key.pem");
6633 }
6634
6635 if (dut->program == PROGRAM_60GHZ) {
6636 const char *dev_role = get_param(cmd, "DevRole");
6637
6638 if (!dev_role) {
6639 send_resp(dut, conn, SIGMA_ERROR,
6640 "errorCode,Missing DevRole argument");
6641 return 0;
6642 }
6643
6644 if (strcasecmp(dev_role, "STA") == 0)
6645 dut->dev_role = DEVROLE_STA;
6646 else if (strcasecmp(dev_role, "PCP") == 0)
6647 dut->dev_role = DEVROLE_PCP;
6648 else {
6649 send_resp(dut, conn, SIGMA_ERROR,
6650 "errorCode,Unknown DevRole");
6651 return 0;
6652 }
6653
6654 if (dut->device_type == STA_unknown) {
6655 sigma_dut_print(dut, DUT_MSG_ERROR,
6656 "Device type is not STA testbed or DUT");
6657 send_resp(dut, conn, SIGMA_ERROR,
6658 "errorCode,Unknown device type");
6659 return 0;
6660 }
6661 }
6662
6663 wpa_command(intf, "WPS_ER_STOP");
6664 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05306665 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006666 wpa_command(intf, "SET radio_disabled 0");
6667
6668 if (dut->tmp_mac_addr && dut->set_macaddr) {
6669 dut->tmp_mac_addr = 0;
6670 if (system(dut->set_macaddr) != 0) {
6671 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
6672 "temporary MAC address");
6673 }
6674 }
6675
6676 set_ps(intf, dut, 0);
6677
Jouni Malinenba630452018-06-22 11:49:59 +03006678 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
6679 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006680 wpa_command(intf, "SET interworking 1");
6681 wpa_command(intf, "SET hs20 1");
6682 }
6683
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006684 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03006685 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006686 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006687 wpa_command(intf, "SET pmf 1");
6688 } else {
6689 wpa_command(intf, "SET pmf 0");
6690 }
6691
6692 hs2_clear_credentials(intf);
6693 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
6694 wpa_command(intf, "SET access_network_type 15");
6695
6696 static_ip_file(0, NULL, NULL, NULL);
6697 kill_dhcp_client(dut, intf);
6698 clear_ip_addr(dut, intf);
6699
6700 dut->er_oper_performed = 0;
6701 dut->er_oper_bssid[0] = '\0';
6702
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07006703 if (dut->program == PROGRAM_LOC) {
6704 /* Disable Interworking by default */
6705 wpa_command(get_station_ifname(), "SET interworking 0");
6706 }
6707
Ashwini Patil00402582017-04-13 12:29:39 +05306708 if (dut->program == PROGRAM_MBO) {
6709 free(dut->non_pref_ch_list);
6710 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05306711 free(dut->btm_query_cand_list);
6712 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05306713 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05306714 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05306715 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05306716 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05306717 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05306718 }
6719
Jouni Malinen3c367e82017-06-23 17:01:47 +03006720 free(dut->rsne_override);
6721 dut->rsne_override = NULL;
6722
Jouni Malinen68143132017-09-02 02:34:08 +03006723 free(dut->sae_commit_override);
6724 dut->sae_commit_override = NULL;
6725
Jouni Malinend86e5822017-08-29 03:55:32 +03006726 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02006727 free(dut->dpp_peer_uri);
6728 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02006729 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02006730 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03006731
Jouni Malinenfac9cad2017-10-10 18:35:55 +03006732 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
6733
vamsi krishnaa2799492017-12-05 14:28:01 +05306734 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306735 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05306736 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05306737 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
6738 dut->fils_hlp = 0;
6739#ifdef ANDROID
6740 hlp_thread_cleanup(dut);
6741#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05306742 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306743
Sunil Dutt076081f2018-02-05 19:45:50 +05306744#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05306745 if (get_driver_type() == DRIVER_WCN &&
6746 dut->config_rsnie == 1) {
6747 dut->config_rsnie = 0;
6748 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05306749 }
6750#endif /* NL80211_SUPPORT */
6751
Sunil Duttfebf8a82018-02-09 18:50:13 +05306752 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
6753 dut->dev_role = DEVROLE_STA_CFON;
6754 return sta_cfon_reset_default(dut, conn, cmd);
6755 }
6756
Jouni Malinen439352d2018-09-13 03:42:23 +03006757 wpa_command(intf, "SET setband AUTO");
6758
Sunil Duttfebf8a82018-02-09 18:50:13 +05306759 if (dut->program != PROGRAM_VHT)
6760 return cmd_sta_p2p_reset(dut, conn, cmd);
6761
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08006762 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006763}
6764
6765
6766static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
6767 struct sigma_cmd *cmd)
6768{
6769 const char *program = get_param(cmd, "Program");
6770
6771 if (program == NULL)
6772 return -1;
6773#ifdef ANDROID_NAN
6774 if (strcasecmp(program, "NAN") == 0)
6775 return nan_cmd_sta_get_events(dut, conn, cmd);
6776#endif /* ANDROID_NAN */
6777 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6778 return 0;
6779}
6780
6781
Jouni Malinen82905202018-04-29 17:20:10 +03006782static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
6783 struct sigma_cmd *cmd)
6784{
6785 const char *url = get_param(cmd, "url");
6786 const char *method = get_param(cmd, "method");
6787 pid_t pid;
6788 int status;
6789
6790 if (!url || !method)
6791 return -1;
6792
6793 /* TODO: Add support for method,post */
6794 if (strcasecmp(method, "get") != 0) {
6795 send_resp(dut, conn, SIGMA_ERROR,
6796 "ErrorCode,Unsupported method");
6797 return 0;
6798 }
6799
6800 pid = fork();
6801 if (pid < 0) {
6802 perror("fork");
6803 return -1;
6804 }
6805
6806 if (pid == 0) {
6807 char * argv[5] = { "wget", "-O", "/dev/null",
6808 (char *) url, NULL };
6809
6810 execv("/usr/bin/wget", argv);
6811 perror("execv");
6812 exit(0);
6813 return -1;
6814 }
6815
6816 if (waitpid(pid, &status, 0) < 0) {
6817 perror("waitpid");
6818 return -1;
6819 }
6820
6821 if (WIFEXITED(status)) {
6822 const char *errmsg;
6823
6824 if (WEXITSTATUS(status) == 0)
6825 return 1;
6826 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
6827 WEXITSTATUS(status));
6828 switch (WEXITSTATUS(status)) {
6829 case 4:
6830 errmsg = "errmsg,Network failure";
6831 break;
6832 case 8:
6833 errmsg = "errmsg,Server issued an error response";
6834 break;
6835 default:
6836 errmsg = "errmsg,Unknown failure from wget";
6837 break;
6838 }
6839 send_resp(dut, conn, SIGMA_ERROR, errmsg);
6840 return 0;
6841 }
6842
6843 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
6844 return 0;
6845}
6846
6847
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006848static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
6849 struct sigma_cmd *cmd)
6850{
6851 const char *program = get_param(cmd, "Prog");
6852
Jouni Malinen82905202018-04-29 17:20:10 +03006853 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006854 return -1;
6855#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03006856 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006857 return nan_cmd_sta_exec_action(dut, conn, cmd);
6858#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03006859
6860 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006861 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03006862
6863 if (get_param(cmd, "url"))
6864 return sta_exec_action_url(dut, conn, cmd);
6865
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006866 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6867 return 0;
6868}
6869
6870
6871static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
6872 struct sigma_cmd *cmd)
6873{
6874 const char *intf = get_param(cmd, "Interface");
6875 const char *val, *mcs32, *rate;
6876
6877 val = get_param(cmd, "GREENFIELD");
6878 if (val) {
6879 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6880 /* Enable GD */
6881 send_resp(dut, conn, SIGMA_ERROR,
6882 "ErrorCode,GF not supported");
6883 return 0;
6884 }
6885 }
6886
6887 val = get_param(cmd, "SGI20");
6888 if (val) {
6889 switch (get_driver_type()) {
6890 case DRIVER_ATHEROS:
6891 ath_sta_set_sgi(dut, intf, val);
6892 break;
6893 default:
6894 send_resp(dut, conn, SIGMA_ERROR,
6895 "ErrorCode,SGI20 not supported");
6896 return 0;
6897 }
6898 }
6899
6900 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
6901 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
6902 if (mcs32 && rate) {
6903 /* TODO */
6904 send_resp(dut, conn, SIGMA_ERROR,
6905 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
6906 return 0;
6907 } else if (mcs32 && !rate) {
6908 /* TODO */
6909 send_resp(dut, conn, SIGMA_ERROR,
6910 "ErrorCode,MCS32 not supported");
6911 return 0;
6912 } else if (!mcs32 && rate) {
6913 switch (get_driver_type()) {
6914 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006915 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006916 ath_sta_set_11nrates(dut, intf, rate);
6917 break;
6918 default:
6919 send_resp(dut, conn, SIGMA_ERROR,
6920 "ErrorCode,MCS32_FIXEDRATE not supported");
6921 return 0;
6922 }
6923 }
6924
6925 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6926}
6927
6928
Arif Hussain7b47d2d2018-05-09 10:44:02 -07006929static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
6930 int mcs_config)
6931{
6932#ifdef NL80211_SUPPORT
6933 int ret;
6934
6935 switch (mcs_config) {
6936 case HE_80_MCS0_7:
6937 case HE_80_MCS0_9:
6938 case HE_80_MCS0_11:
6939 ret = sta_set_he_mcs(dut, intf, mcs_config);
6940 if (ret) {
6941 sigma_dut_print(dut, DUT_MSG_ERROR,
6942 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
6943 mcs_config, ret);
6944 }
6945 break;
6946 default:
6947 sigma_dut_print(dut, DUT_MSG_ERROR,
6948 "cmd_set_max_he_mcs: Invalid mcs %d",
6949 mcs_config);
6950 break;
6951 }
6952#else /* NL80211_SUPPORT */
6953 sigma_dut_print(dut, DUT_MSG_ERROR,
6954 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
6955#endif /* NL80211_SUPPORT */
6956}
6957
6958
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006959static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
6960 struct sigma_conn *conn,
6961 struct sigma_cmd *cmd)
6962{
6963 const char *intf = get_param(cmd, "Interface");
6964 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07006965 const char *program;
Arif Hussaind13d6952018-07-02 16:23:47 -07006966 char buf[60];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006967 int tkip = -1;
6968 int wep = -1;
6969
Arif Hussaina37e9552018-06-20 17:05:59 -07006970 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006971 val = get_param(cmd, "SGI80");
6972 if (val) {
6973 int sgi80;
6974
6975 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6976 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
6977 if (system(buf) != 0) {
6978 sigma_dut_print(dut, DUT_MSG_ERROR,
6979 "iwpriv shortgi failed");
6980 }
6981 }
6982
6983 val = get_param(cmd, "TxBF");
6984 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07006985 switch (get_driver_type()) {
6986 case DRIVER_WCN:
6987 if (sta_set_tx_beamformee(dut, intf, 1)) {
6988 send_resp(dut, conn, SIGMA_ERROR,
6989 "ErrorCode,Failed to set TX beamformee enable");
6990 return 0;
6991 }
6992 break;
6993 case DRIVER_ATHEROS:
6994 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1",
6995 intf);
6996 if (system(buf) != 0) {
6997 send_resp(dut, conn, SIGMA_ERROR,
6998 "ErrorCode,Setting vhtsubfee failed");
6999 return 0;
7000 }
7001
7002 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1",
7003 intf);
7004 if (system(buf) != 0) {
7005 send_resp(dut, conn, SIGMA_ERROR,
7006 "ErrorCode,Setting vhtsubfer failed");
7007 return 0;
7008 }
7009 break;
7010 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007011 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07007012 "Unsupported driver type");
7013 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007014 }
7015 }
7016
7017 val = get_param(cmd, "MU_TxBF");
7018 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
7019 switch (get_driver_type()) {
7020 case DRIVER_ATHEROS:
7021 ath_sta_set_txsp_stream(dut, intf, "1SS");
7022 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Sunil Duttae9e5d12018-06-29 11:50:47 +05307023 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1",
7024 intf);
7025 if (system(buf) != 0) {
7026 sigma_dut_print(dut, DUT_MSG_ERROR,
7027 "iwpriv vhtmubfee failed");
7028 }
7029 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1",
7030 intf);
7031 if (system(buf) != 0) {
7032 sigma_dut_print(dut, DUT_MSG_ERROR,
7033 "iwpriv vhtmubfer failed");
7034 }
7035 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007036 case DRIVER_WCN:
7037 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
7038 send_resp(dut, conn, SIGMA_ERROR,
7039 "ErrorCode,Failed to set RX/TXSP_STREAM");
7040 return 0;
7041 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05307042 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007043 default:
7044 sigma_dut_print(dut, DUT_MSG_ERROR,
7045 "Setting SP_STREAM not supported");
7046 break;
7047 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007048 }
7049
7050 val = get_param(cmd, "LDPC");
7051 if (val) {
7052 int ldpc;
7053
7054 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7055 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
7056 if (system(buf) != 0) {
7057 sigma_dut_print(dut, DUT_MSG_ERROR,
7058 "iwpriv ldpc failed");
7059 }
7060 }
7061
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08007062 val = get_param(cmd, "BCC");
7063 if (val) {
7064 int bcc;
7065
7066 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7067 /* use LDPC iwpriv itself to set bcc coding, bcc coding
7068 * is mutually exclusive to bcc */
7069 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
7070 if (system(buf) != 0) {
7071 sigma_dut_print(dut, DUT_MSG_ERROR,
7072 "Enabling/Disabling of BCC failed");
7073 }
7074 }
7075
Arif Hussain7b47d2d2018-05-09 10:44:02 -07007076 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
7077 if (val && dut->sta_nss == 1)
7078 cmd_set_max_he_mcs(dut, intf, atoi(val));
7079
7080 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
7081 if (val && dut->sta_nss == 2)
7082 cmd_set_max_he_mcs(dut, intf, atoi(val));
7083
Arif Hussainac6c5112018-05-25 17:34:00 -07007084 val = get_param(cmd, "MCS_FixedRate");
7085 if (val) {
7086#ifdef NL80211_SUPPORT
7087 int mcs, ratecode = 0;
7088 enum he_mcs_config mcs_config;
7089 int ret;
7090
7091 ratecode = (0x07 & dut->sta_nss) << 5;
7092 mcs = atoi(val);
7093 /* Add the MCS to the ratecode */
7094 if (mcs >= 0 && mcs <= 11) {
7095 ratecode += mcs;
7096 if (dut->device_type == STA_testbed &&
7097 mcs > 7 && mcs <= 11) {
7098 if (mcs <= 9)
7099 mcs_config = HE_80_MCS0_9;
7100 else
7101 mcs_config = HE_80_MCS0_11;
7102 ret = sta_set_he_mcs(dut, intf, mcs_config);
7103 if (ret) {
7104 sigma_dut_print(dut, DUT_MSG_ERROR,
7105 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
7106 mcs, mcs_config, ret);
7107 }
7108 }
7109 snprintf(buf, sizeof(buf),
7110 "iwpriv %s set_11ax_rate 0x%03x",
7111 intf, ratecode);
7112 if (system(buf) != 0) {
7113 sigma_dut_print(dut, DUT_MSG_ERROR,
7114 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
7115 ratecode);
7116 }
7117 } else {
7118 sigma_dut_print(dut, DUT_MSG_ERROR,
7119 "MCS_FixedRate: HE MCS %d not supported",
7120 mcs);
7121 }
7122#else /* NL80211_SUPPORT */
7123 sigma_dut_print(dut, DUT_MSG_ERROR,
7124 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
7125#endif /* NL80211_SUPPORT */
7126 }
7127
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007128 val = get_param(cmd, "opt_md_notif_ie");
7129 if (val) {
7130 char *result = NULL;
7131 char delim[] = ";";
7132 char token[30];
7133 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307134 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007135
Peng Xub8fc5cc2017-05-10 17:27:28 -07007136 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307137 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007138
7139 /* Extract the NSS information */
7140 if (result) {
7141 value = atoi(result);
7142 switch (value) {
7143 case 1:
7144 config_val = 1;
7145 break;
7146 case 2:
7147 config_val = 3;
7148 break;
7149 case 3:
7150 config_val = 7;
7151 break;
7152 case 4:
7153 config_val = 15;
7154 break;
7155 default:
7156 config_val = 3;
7157 break;
7158 }
7159
7160 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
7161 intf, config_val);
7162 if (system(buf) != 0) {
7163 sigma_dut_print(dut, DUT_MSG_ERROR,
7164 "iwpriv rxchainmask failed");
7165 }
7166
7167 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
7168 intf, config_val);
7169 if (system(buf) != 0) {
7170 sigma_dut_print(dut, DUT_MSG_ERROR,
7171 "iwpriv txchainmask failed");
7172 }
7173 }
7174
7175 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307176 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007177 if (result) {
7178 value = atoi(result);
7179 switch (value) {
7180 case 20:
7181 config_val = 0;
7182 break;
7183 case 40:
7184 config_val = 1;
7185 break;
7186 case 80:
7187 config_val = 2;
7188 break;
7189 case 160:
7190 config_val = 3;
7191 break;
7192 default:
7193 config_val = 2;
7194 break;
7195 }
7196
7197 dut->chwidth = config_val;
7198
7199 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7200 intf, config_val);
7201 if (system(buf) != 0) {
7202 sigma_dut_print(dut, DUT_MSG_ERROR,
7203 "iwpriv chwidth failed");
7204 }
7205 }
7206
7207 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
7208 if (system(buf) != 0) {
7209 sigma_dut_print(dut, DUT_MSG_ERROR,
7210 "iwpriv opmode_notify failed");
7211 }
7212 }
7213
7214 val = get_param(cmd, "nss_mcs_cap");
7215 if (val) {
7216 int nss, mcs;
7217 char token[20];
7218 char *result = NULL;
7219 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307220 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007221
Peng Xub8fc5cc2017-05-10 17:27:28 -07007222 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307223 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307224 if (!result) {
7225 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007226 "NSS not specified");
7227 send_resp(dut, conn, SIGMA_ERROR,
7228 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307229 return 0;
7230 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007231 nss = atoi(result);
7232
7233 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
7234 if (system(buf) != 0) {
7235 sigma_dut_print(dut, DUT_MSG_ERROR,
7236 "iwpriv nss failed");
7237 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007238 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007239
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307240 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007241 if (result == NULL) {
7242 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007243 "MCS not specified");
7244 send_resp(dut, conn, SIGMA_ERROR,
7245 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007246 return 0;
7247 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307248 result = strtok_r(result, "-", &saveptr);
7249 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307250 if (!result) {
7251 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007252 "MCS not specified");
7253 send_resp(dut, conn, SIGMA_ERROR,
7254 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307255 return 0;
7256 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007257 mcs = atoi(result);
7258
Arif Hussaina37e9552018-06-20 17:05:59 -07007259 if (program && strcasecmp(program, "HE") == 0) {
7260#ifdef NL80211_SUPPORT
7261 enum he_mcs_config mcs_config;
7262 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007263
Arif Hussaina37e9552018-06-20 17:05:59 -07007264 if (mcs >= 0 && mcs <= 7) {
7265 mcs_config = HE_80_MCS0_7;
7266 } else if (mcs > 7 && mcs <= 9) {
7267 mcs_config = HE_80_MCS0_9;
7268 } else if (mcs > 9 && mcs <= 11) {
7269 mcs_config = HE_80_MCS0_11;
7270 } else {
7271 sigma_dut_print(dut, DUT_MSG_ERROR,
7272 "nss_mcs_cap: HE: Invalid mcs: %d",
7273 mcs);
7274 send_resp(dut, conn, SIGMA_ERROR,
7275 "errorCode,Invalid MCS");
7276 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007277 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007278
7279 ret = sta_set_he_mcs(dut, intf, mcs_config);
7280 if (ret) {
7281 sigma_dut_print(dut, DUT_MSG_ERROR,
7282 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
7283 mcs_config, ret);
7284 send_resp(dut, conn, SIGMA_ERROR,
7285 "errorCode,Failed to set MCS");
7286 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007287 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007288#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007289 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007290 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
7291#endif /* NL80211_SUPPORT */
7292 } else {
7293 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
7294 intf, mcs);
7295 if (system(buf) != 0) {
7296 sigma_dut_print(dut, DUT_MSG_ERROR,
7297 "iwpriv mcs failed");
7298 }
7299
7300 switch (nss) {
7301 case 1:
7302 switch (mcs) {
7303 case 7:
7304 vht_mcsmap = 0xfffc;
7305 break;
7306 case 8:
7307 vht_mcsmap = 0xfffd;
7308 break;
7309 case 9:
7310 vht_mcsmap = 0xfffe;
7311 break;
7312 default:
7313 vht_mcsmap = 0xfffe;
7314 break;
7315 }
7316 break;
7317 case 2:
7318 switch (mcs) {
7319 case 7:
7320 vht_mcsmap = 0xfff0;
7321 break;
7322 case 8:
7323 vht_mcsmap = 0xfff5;
7324 break;
7325 case 9:
7326 vht_mcsmap = 0xfffa;
7327 break;
7328 default:
7329 vht_mcsmap = 0xfffa;
7330 break;
7331 }
7332 break;
7333 case 3:
7334 switch (mcs) {
7335 case 7:
7336 vht_mcsmap = 0xffc0;
7337 break;
7338 case 8:
7339 vht_mcsmap = 0xffd5;
7340 break;
7341 case 9:
7342 vht_mcsmap = 0xffea;
7343 break;
7344 default:
7345 vht_mcsmap = 0xffea;
7346 break;
7347 }
7348 break;
7349 default:
7350 vht_mcsmap = 0xffea;
7351 break;
7352 }
7353 snprintf(buf, sizeof(buf),
7354 "iwpriv %s vht_mcsmap 0x%04x",
7355 intf, vht_mcsmap);
7356 if (system(buf) != 0) {
7357 sigma_dut_print(dut, DUT_MSG_ERROR,
7358 "iwpriv vht_mcsmap failed");
7359 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007360 }
7361 }
7362
7363 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
7364
7365 val = get_param(cmd, "Vht_tkip");
7366 if (val)
7367 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7368
7369 val = get_param(cmd, "Vht_wep");
7370 if (val)
7371 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7372
7373 if (tkip != -1 || wep != -1) {
7374 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
7375 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
7376 intf);
7377 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
7378 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
7379 intf);
7380 } else {
7381 sigma_dut_print(dut, DUT_MSG_ERROR,
7382 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
7383 return 0;
7384 }
7385
7386 if (system(buf) != 0) {
7387 sigma_dut_print(dut, DUT_MSG_ERROR,
7388 "iwpriv htweptkip failed");
7389 }
7390 }
7391
Arif Hussain55f00da2018-07-03 08:28:26 -07007392 val = get_param(cmd, "txBandwidth");
7393 if (val) {
7394 switch (get_driver_type()) {
7395 case DRIVER_WCN:
7396 if (wcn_sta_set_width(dut, intf, val) < 0) {
7397 send_resp(dut, conn, SIGMA_ERROR,
7398 "ErrorCode,Failed to set txBandwidth");
7399 return 0;
7400 }
7401 break;
7402 case DRIVER_ATHEROS:
7403 if (ath_set_width(dut, conn, intf, val) < 0) {
7404 send_resp(dut, conn, SIGMA_ERROR,
7405 "ErrorCode,Failed to set txBandwidth");
7406 return 0;
7407 }
7408 break;
7409 default:
7410 sigma_dut_print(dut, DUT_MSG_ERROR,
7411 "Setting txBandwidth not supported");
7412 break;
7413 }
7414 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007415
Arif Hussain9765f7d2018-07-03 08:28:26 -07007416 val = get_param(cmd, "BeamformeeSTS");
7417 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07007418 if (sta_set_tx_beamformee(dut, intf, 1)) {
7419 send_resp(dut, conn, SIGMA_ERROR,
7420 "ErrorCode,Failed to set TX beamformee enable");
7421 return 0;
7422 }
7423
Arif Hussain9765f7d2018-07-03 08:28:26 -07007424 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
7425 send_resp(dut, conn, SIGMA_ERROR,
7426 "ErrorCode,Failed to set BeamformeeSTS");
7427 return 0;
7428 }
7429 }
7430
Arif Hussain68d23f52018-07-11 13:39:08 -07007431 val = get_param(cmd, "Trig_MAC_Padding_Dur");
7432 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007433#ifdef NL80211_SUPPORT
7434 enum qca_wlan_he_mac_padding_dur set_val;
7435
7436 switch (atoi(val)) {
7437 case 16:
7438 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
7439 break;
7440 case 8:
7441 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
7442 break;
7443 default:
7444 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
7445 break;
7446 }
7447 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007448 send_resp(dut, conn, SIGMA_ERROR,
7449 "ErrorCode,Failed to set MAC padding duration");
7450 return 0;
7451 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007452#else /* NL80211_SUPPORT */
7453 sigma_dut_print(dut, DUT_MSG_ERROR,
7454 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
7455#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007456 }
7457
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007458 val = get_param(cmd, "MU_EDCA");
7459 if (val && (strcasecmp(val, "Override") == 0)) {
7460 if (sta_set_mu_edca_override(dut, intf, 1)) {
7461 send_resp(dut, conn, SIGMA_ERROR,
7462 "ErrorCode,Failed to set MU EDCA override");
7463 return 0;
7464 }
7465 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007466
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007467 val = get_param(cmd, "OMControl");
7468 if (val) {
7469 int set_val = 1;
7470
7471 if (strcasecmp(val, "Enable") == 0)
7472 set_val = 1;
7473 else if (strcasecmp(val, "Disable") == 0)
7474 set_val = 0;
7475
7476 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
7477 send_resp(dut, conn, SIGMA_ERROR,
7478 "ErrorCode,Failed to set OM ctrl supp");
7479 return 0;
7480 }
7481 }
7482
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007483 val = get_param(cmd, "ADDBAResp_BufSize");
7484 if (val) {
7485 int buf_size;
7486
7487 if (strcasecmp(val, "gt64") == 0)
7488 buf_size = 256;
7489 else
7490 buf_size = 64;
7491 if (get_driver_type() == DRIVER_WCN &&
7492 sta_set_addba_buf_size(dut, intf, buf_size)) {
7493 send_resp(dut, conn, SIGMA_ERROR,
7494 "ErrorCode,set addbaresp_buff_size failed");
7495 return 0;
7496 }
7497 }
7498
7499 val = get_param(cmd, "ADDBAReq_BufSize");
7500 if (val) {
7501 int buf_size;
7502
7503 if (strcasecmp(val, "gt64") == 0)
7504 buf_size = 256;
7505 else
7506 buf_size = 64;
7507 if (get_driver_type() == DRIVER_WCN &&
7508 sta_set_addba_buf_size(dut, intf, buf_size)) {
7509 send_resp(dut, conn, SIGMA_ERROR,
7510 "ErrorCode,set addbareq_buff_size failed");
7511 return 0;
7512 }
7513 }
7514
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007515 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7516}
7517
7518
7519static int sta_set_wireless_60g(struct sigma_dut *dut,
7520 struct sigma_conn *conn,
7521 struct sigma_cmd *cmd)
7522{
7523 const char *dev_role = get_param(cmd, "DevRole");
7524
7525 if (!dev_role) {
7526 send_resp(dut, conn, SIGMA_INVALID,
7527 "ErrorCode,DevRole not specified");
7528 return 0;
7529 }
7530
7531 if (strcasecmp(dev_role, "PCP") == 0)
7532 return sta_set_60g_pcp(dut, conn, cmd);
7533 if (strcasecmp(dev_role, "STA") == 0)
7534 return sta_set_60g_sta(dut, conn, cmd);
7535 send_resp(dut, conn, SIGMA_INVALID,
7536 "ErrorCode,DevRole not supported");
7537 return 0;
7538}
7539
7540
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307541static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
7542 struct sigma_cmd *cmd)
7543{
7544 int status;
7545 const char *intf = get_param(cmd, "Interface");
7546 const char *val = get_param(cmd, "DevRole");
7547
7548 if (val && strcasecmp(val, "STA-CFON") == 0) {
7549 status = sta_cfon_set_wireless(dut, conn, cmd);
7550 if (status)
7551 return status;
7552 }
7553 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7554}
7555
7556
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007557static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
7558 struct sigma_cmd *cmd)
7559{
7560 const char *val;
7561
7562 val = get_param(cmd, "Program");
7563 if (val) {
7564 if (strcasecmp(val, "11n") == 0)
7565 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08007566 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007567 return cmd_sta_set_wireless_vht(dut, conn, cmd);
7568 if (strcasecmp(val, "60ghz") == 0)
7569 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307570 if (strcasecmp(val, "OCE") == 0)
7571 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007572 send_resp(dut, conn, SIGMA_ERROR,
7573 "ErrorCode,Program value not supported");
7574 } else {
7575 send_resp(dut, conn, SIGMA_ERROR,
7576 "ErrorCode,Program argument not available");
7577 }
7578
7579 return 0;
7580}
7581
7582
7583static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
7584 int tid)
7585{
7586 char buf[100];
7587 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
7588
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05307589 if (tid < 0 ||
7590 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
7591 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
7592 return;
7593 }
7594
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007595 /*
7596 * Two ways to ensure that addba request with a
7597 * non zero TID could be sent out. EV 117296
7598 */
7599 snprintf(buf, sizeof(buf),
7600 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
7601 tid);
7602 if (system(buf) != 0) {
7603 sigma_dut_print(dut, DUT_MSG_ERROR,
7604 "Ping did not send out");
7605 }
7606
7607 snprintf(buf, sizeof(buf),
7608 "iwconfig %s | grep Access | awk '{print $6}' > %s",
7609 intf, VI_QOS_TMP_FILE);
7610 if (system(buf) != 0)
7611 return;
7612
7613 snprintf(buf, sizeof(buf),
7614 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
7615 intf, VI_QOS_TMP_FILE);
7616 if (system(buf) != 0)
7617 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
7618
7619 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
7620 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
7621 if (system(buf) != 0) {
7622 sigma_dut_print(dut, DUT_MSG_ERROR,
7623 "VI_QOS_TEMP_FILE generation error failed");
7624 }
7625 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7626 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7627 if (system(buf) != 0) {
7628 sigma_dut_print(dut, DUT_MSG_ERROR,
7629 "VI_QOS_FILE generation failed");
7630 }
7631
7632 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7633 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7634 if (system(buf) != 0) {
7635 sigma_dut_print(dut, DUT_MSG_ERROR,
7636 "VI_QOS_FILE generation failed");
7637 }
7638
7639 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
7640 if (system(buf) != 0) {
7641 }
7642}
7643
7644
7645static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7646 struct sigma_cmd *cmd)
7647{
7648 const char *intf = get_param(cmd, "Interface");
7649 const char *val;
7650 int tid = 0;
7651 char buf[100];
7652
7653 val = get_param(cmd, "TID");
7654 if (val) {
7655 tid = atoi(val);
7656 if (tid)
7657 ath_sta_inject_frame(dut, intf, tid);
7658 }
7659
7660 /* Command sequence for ADDBA request on Peregrine based devices */
7661 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
7662 if (system(buf) != 0) {
7663 sigma_dut_print(dut, DUT_MSG_ERROR,
7664 "iwpriv setaddbaoper failed");
7665 }
7666
7667 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
7668 if (system(buf) != 0) {
7669 sigma_dut_print(dut, DUT_MSG_ERROR,
7670 "wifitool senddelba failed");
7671 }
7672
7673 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
7674 if (system(buf) != 0) {
7675 sigma_dut_print(dut, DUT_MSG_ERROR,
7676 "wifitool sendaddba failed");
7677 }
7678
7679 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7680
7681 return 1;
7682}
7683
7684
Lior David9981b512017-01-20 13:16:40 +02007685#ifdef __linux__
7686
7687static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
7688 int agg_size)
7689{
7690 char dir[128], buf[128];
7691 FILE *f;
7692 regex_t re;
7693 regmatch_t m[2];
7694 int rc, ret = -1, vring_id, found;
7695
7696 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
7697 sigma_dut_print(dut, DUT_MSG_ERROR,
7698 "failed to get wil6210 debugfs dir");
7699 return -1;
7700 }
7701
7702 snprintf(buf, sizeof(buf), "%s/vrings", dir);
7703 f = fopen(buf, "r");
7704 if (!f) {
7705 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007706 /* newer wil6210 driver renamed file to "rings" */
7707 snprintf(buf, sizeof(buf), "%s/rings", dir);
7708 f = fopen(buf, "r");
7709 if (!f) {
7710 sigma_dut_print(dut, DUT_MSG_ERROR,
7711 "failed to open: %s", buf);
7712 return -1;
7713 }
Lior David9981b512017-01-20 13:16:40 +02007714 }
7715
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007716 /* can be either VRING tx... or RING... */
7717 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02007718 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
7719 goto out;
7720 }
7721
7722 /* find TX VRING for the mac address */
7723 found = 0;
7724 while (fgets(buf, sizeof(buf), f)) {
7725 if (strcasestr(buf, dest_mac)) {
7726 found = 1;
7727 break;
7728 }
7729 }
7730
7731 if (!found) {
7732 sigma_dut_print(dut, DUT_MSG_ERROR,
7733 "no TX VRING for %s", dest_mac);
7734 goto out;
7735 }
7736
7737 /* extract VRING ID, "VRING tx_<id> = {" */
7738 if (!fgets(buf, sizeof(buf), f)) {
7739 sigma_dut_print(dut, DUT_MSG_ERROR,
7740 "no VRING start line for %s", dest_mac);
7741 goto out;
7742 }
7743
7744 rc = regexec(&re, buf, 2, m, 0);
7745 regfree(&re);
7746 if (rc || m[1].rm_so < 0) {
7747 sigma_dut_print(dut, DUT_MSG_ERROR,
7748 "no VRING TX ID for %s", dest_mac);
7749 goto out;
7750 }
7751 buf[m[1].rm_eo] = 0;
7752 vring_id = atoi(&buf[m[1].rm_so]);
7753
7754 /* send the addba command */
7755 fclose(f);
7756 snprintf(buf, sizeof(buf), "%s/back", dir);
7757 f = fopen(buf, "w");
7758 if (!f) {
7759 sigma_dut_print(dut, DUT_MSG_ERROR,
7760 "failed to open: %s", buf);
7761 return -1;
7762 }
7763
7764 fprintf(f, "add %d %d\n", vring_id, agg_size);
7765
7766 ret = 0;
7767
7768out:
7769 fclose(f);
7770
7771 return ret;
7772}
7773
7774
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007775static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7776 struct sigma_cmd *cmd)
7777{
7778 const char *val;
7779 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007780
7781 val = get_param(cmd, "TID");
7782 if (val) {
7783 tid = atoi(val);
7784 if (tid != 0) {
7785 sigma_dut_print(dut, DUT_MSG_ERROR,
7786 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
7787 tid);
7788 }
7789 }
7790
7791 val = get_param(cmd, "Dest_mac");
7792 if (!val) {
7793 sigma_dut_print(dut, DUT_MSG_ERROR,
7794 "Currently not supporting addba for 60G without Dest_mac");
7795 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
7796 }
7797
Lior David9981b512017-01-20 13:16:40 +02007798 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007799 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007800
7801 return 1;
7802}
7803
Lior David9981b512017-01-20 13:16:40 +02007804#endif /* __linux__ */
7805
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007806
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007807static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7808 struct sigma_cmd *cmd)
7809{
7810#ifdef NL80211_SUPPORT
7811 const char *intf = get_param(cmd, "Interface");
7812 const char *val;
7813 int tid = -1;
7814 int bufsize = 64;
7815 struct nl_msg *msg;
7816 int ret = 0;
7817 struct nlattr *params;
7818 int ifindex;
7819
7820 val = get_param(cmd, "TID");
7821 if (val)
7822 tid = atoi(val);
7823
7824 if (tid == -1) {
7825 send_resp(dut, conn, SIGMA_ERROR,
7826 "ErrorCode,sta_send_addba tid invalid");
7827 return 0;
7828 }
7829
7830 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7831
7832 ifindex = if_nametoindex(intf);
7833 if (ifindex == 0) {
7834 sigma_dut_print(dut, DUT_MSG_ERROR,
7835 "%s: Index for interface %s failed",
7836 __func__, intf);
7837 send_resp(dut, conn, SIGMA_ERROR,
7838 "ErrorCode,sta_send_addba interface invalid");
7839 return 0;
7840 }
7841
7842 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7843 NL80211_CMD_VENDOR)) ||
7844 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7845 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7846 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7847 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7848 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7849 nla_put_u8(msg,
7850 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
7851 QCA_WLAN_ADD_BA) ||
7852 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
7853 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007854 nla_put_u16(msg,
7855 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7856 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007857 sigma_dut_print(dut, DUT_MSG_ERROR,
7858 "%s: err in adding vendor_cmd and vendor_data",
7859 __func__);
7860 nlmsg_free(msg);
7861 send_resp(dut, conn, SIGMA_ERROR,
7862 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
7863 return 0;
7864 }
7865 nla_nest_end(msg, params);
7866
7867 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7868 if (ret) {
7869 sigma_dut_print(dut, DUT_MSG_ERROR,
7870 "%s: err in send_and_recv_msgs, ret=%d",
7871 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05307872 if (ret == -EOPNOTSUPP)
7873 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007874 send_resp(dut, conn, SIGMA_ERROR,
7875 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
7876 return 0;
7877 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007878#else /* NL80211_SUPPORT */
7879 sigma_dut_print(dut, DUT_MSG_ERROR,
7880 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007881#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05307882
7883 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007884}
7885
7886
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007887static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7888 struct sigma_cmd *cmd)
7889{
7890 switch (get_driver_type()) {
7891 case DRIVER_ATHEROS:
7892 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007893 case DRIVER_WCN:
7894 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007895#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007896 case DRIVER_WIL6210:
7897 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007898#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007899 default:
7900 /*
7901 * There is no driver specific implementation for other drivers.
7902 * Ignore the command and report COMPLETE since the following
7903 * throughput test operation will end up sending ADDBA anyway.
7904 */
7905 return 1;
7906 }
7907}
7908
7909
7910int inject_eth_frame(int s, const void *data, size_t len,
7911 unsigned short ethtype, char *dst, char *src)
7912{
7913 struct iovec iov[4] = {
7914 {
7915 .iov_base = dst,
7916 .iov_len = ETH_ALEN,
7917 },
7918 {
7919 .iov_base = src,
7920 .iov_len = ETH_ALEN,
7921 },
7922 {
7923 .iov_base = &ethtype,
7924 .iov_len = sizeof(unsigned short),
7925 },
7926 {
7927 .iov_base = (void *) data,
7928 .iov_len = len,
7929 }
7930 };
7931 struct msghdr msg = {
7932 .msg_name = NULL,
7933 .msg_namelen = 0,
7934 .msg_iov = iov,
7935 .msg_iovlen = 4,
7936 .msg_control = NULL,
7937 .msg_controllen = 0,
7938 .msg_flags = 0,
7939 };
7940
7941 return sendmsg(s, &msg, 0);
7942}
7943
7944#if defined(__linux__) || defined(__QNXNTO__)
7945
7946int inject_frame(int s, const void *data, size_t len, int encrypt)
7947{
7948#define IEEE80211_RADIOTAP_F_WEP 0x04
7949#define IEEE80211_RADIOTAP_F_FRAG 0x08
7950 unsigned char rtap_hdr[] = {
7951 0x00, 0x00, /* radiotap version */
7952 0x0e, 0x00, /* radiotap length */
7953 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
7954 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
7955 0x00, /* padding */
7956 0x00, 0x00, /* RX and TX flags to indicate that */
7957 0x00, 0x00, /* this is the injected frame directly */
7958 };
7959 struct iovec iov[2] = {
7960 {
7961 .iov_base = &rtap_hdr,
7962 .iov_len = sizeof(rtap_hdr),
7963 },
7964 {
7965 .iov_base = (void *) data,
7966 .iov_len = len,
7967 }
7968 };
7969 struct msghdr msg = {
7970 .msg_name = NULL,
7971 .msg_namelen = 0,
7972 .msg_iov = iov,
7973 .msg_iovlen = 2,
7974 .msg_control = NULL,
7975 .msg_controllen = 0,
7976 .msg_flags = 0,
7977 };
7978
7979 if (encrypt)
7980 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
7981
7982 return sendmsg(s, &msg, 0);
7983}
7984
7985
7986int open_monitor(const char *ifname)
7987{
7988#ifdef __QNXNTO__
7989 struct sockaddr_dl ll;
7990 int s;
7991
7992 memset(&ll, 0, sizeof(ll));
7993 ll.sdl_family = AF_LINK;
7994 ll.sdl_index = if_nametoindex(ifname);
7995 if (ll.sdl_index == 0) {
7996 perror("if_nametoindex");
7997 return -1;
7998 }
7999 s = socket(PF_INET, SOCK_RAW, 0);
8000#else /* __QNXNTO__ */
8001 struct sockaddr_ll ll;
8002 int s;
8003
8004 memset(&ll, 0, sizeof(ll));
8005 ll.sll_family = AF_PACKET;
8006 ll.sll_ifindex = if_nametoindex(ifname);
8007 if (ll.sll_ifindex == 0) {
8008 perror("if_nametoindex");
8009 return -1;
8010 }
8011 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
8012#endif /* __QNXNTO__ */
8013 if (s < 0) {
8014 perror("socket[PF_PACKET,SOCK_RAW]");
8015 return -1;
8016 }
8017
8018 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
8019 perror("monitor socket bind");
8020 close(s);
8021 return -1;
8022 }
8023
8024 return s;
8025}
8026
8027
8028static int hex2num(char c)
8029{
8030 if (c >= '0' && c <= '9')
8031 return c - '0';
8032 if (c >= 'a' && c <= 'f')
8033 return c - 'a' + 10;
8034 if (c >= 'A' && c <= 'F')
8035 return c - 'A' + 10;
8036 return -1;
8037}
8038
8039
8040int hwaddr_aton(const char *txt, unsigned char *addr)
8041{
8042 int i;
8043
8044 for (i = 0; i < 6; i++) {
8045 int a, b;
8046
8047 a = hex2num(*txt++);
8048 if (a < 0)
8049 return -1;
8050 b = hex2num(*txt++);
8051 if (b < 0)
8052 return -1;
8053 *addr++ = (a << 4) | b;
8054 if (i < 5 && *txt++ != ':')
8055 return -1;
8056 }
8057
8058 return 0;
8059}
8060
8061#endif /* defined(__linux__) || defined(__QNXNTO__) */
8062
8063enum send_frame_type {
8064 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
8065};
8066enum send_frame_protection {
8067 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
8068};
8069
8070
8071static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
8072 enum send_frame_type frame,
8073 enum send_frame_protection protected,
8074 const char *dest)
8075{
8076#ifdef __linux__
8077 unsigned char buf[1000], *pos;
8078 int s, res;
8079 char bssid[20], addr[20];
8080 char result[32], ssid[100];
8081 size_t ssid_len;
8082
8083 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
8084 sizeof(result)) < 0 ||
8085 strncmp(result, "COMPLETED", 9) != 0) {
8086 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
8087 return 0;
8088 }
8089
8090 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
8091 < 0) {
8092 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8093 "current BSSID");
8094 return 0;
8095 }
8096
8097 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
8098 < 0) {
8099 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8100 "own MAC address");
8101 return 0;
8102 }
8103
8104 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
8105 < 0) {
8106 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
8107 "current SSID");
8108 return 0;
8109 }
8110 ssid_len = strlen(ssid);
8111
8112 pos = buf;
8113
8114 /* Frame Control */
8115 switch (frame) {
8116 case DISASSOC:
8117 *pos++ = 0xa0;
8118 break;
8119 case DEAUTH:
8120 *pos++ = 0xc0;
8121 break;
8122 case SAQUERY:
8123 *pos++ = 0xd0;
8124 break;
8125 case AUTH:
8126 *pos++ = 0xb0;
8127 break;
8128 case ASSOCREQ:
8129 *pos++ = 0x00;
8130 break;
8131 case REASSOCREQ:
8132 *pos++ = 0x20;
8133 break;
8134 case DLS_REQ:
8135 *pos++ = 0xd0;
8136 break;
8137 }
8138
8139 if (protected == INCORRECT_KEY)
8140 *pos++ = 0x40; /* Set Protected field to 1 */
8141 else
8142 *pos++ = 0x00;
8143
8144 /* Duration */
8145 *pos++ = 0x00;
8146 *pos++ = 0x00;
8147
8148 /* addr1 = DA (current AP) */
8149 hwaddr_aton(bssid, pos);
8150 pos += 6;
8151 /* addr2 = SA (own address) */
8152 hwaddr_aton(addr, pos);
8153 pos += 6;
8154 /* addr3 = BSSID (current AP) */
8155 hwaddr_aton(bssid, pos);
8156 pos += 6;
8157
8158 /* Seq# (to be filled by driver/mac80211) */
8159 *pos++ = 0x00;
8160 *pos++ = 0x00;
8161
8162 if (protected == INCORRECT_KEY) {
8163 /* CCMP parameters */
8164 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8165 pos += 8;
8166 }
8167
8168 if (protected == INCORRECT_KEY) {
8169 switch (frame) {
8170 case DEAUTH:
8171 /* Reason code (encrypted) */
8172 memcpy(pos, "\xa7\x39", 2);
8173 pos += 2;
8174 break;
8175 case DISASSOC:
8176 /* Reason code (encrypted) */
8177 memcpy(pos, "\xa7\x39", 2);
8178 pos += 2;
8179 break;
8180 case SAQUERY:
8181 /* Category|Action|TransID (encrypted) */
8182 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8183 pos += 4;
8184 break;
8185 default:
8186 return -1;
8187 }
8188
8189 /* CCMP MIC */
8190 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8191 pos += 8;
8192 } else {
8193 switch (frame) {
8194 case DEAUTH:
8195 /* reason code = 8 */
8196 *pos++ = 0x08;
8197 *pos++ = 0x00;
8198 break;
8199 case DISASSOC:
8200 /* reason code = 8 */
8201 *pos++ = 0x08;
8202 *pos++ = 0x00;
8203 break;
8204 case SAQUERY:
8205 /* Category - SA Query */
8206 *pos++ = 0x08;
8207 /* SA query Action - Request */
8208 *pos++ = 0x00;
8209 /* Transaction ID */
8210 *pos++ = 0x12;
8211 *pos++ = 0x34;
8212 break;
8213 case AUTH:
8214 /* Auth Alg (Open) */
8215 *pos++ = 0x00;
8216 *pos++ = 0x00;
8217 /* Seq# */
8218 *pos++ = 0x01;
8219 *pos++ = 0x00;
8220 /* Status code */
8221 *pos++ = 0x00;
8222 *pos++ = 0x00;
8223 break;
8224 case ASSOCREQ:
8225 /* Capability Information */
8226 *pos++ = 0x31;
8227 *pos++ = 0x04;
8228 /* Listen Interval */
8229 *pos++ = 0x0a;
8230 *pos++ = 0x00;
8231 /* SSID */
8232 *pos++ = 0x00;
8233 *pos++ = ssid_len;
8234 memcpy(pos, ssid, ssid_len);
8235 pos += ssid_len;
8236 /* Supported Rates */
8237 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8238 10);
8239 pos += 10;
8240 /* Extended Supported Rates */
8241 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8242 pos += 6;
8243 /* RSN */
8244 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8245 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8246 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8247 pos += 28;
8248 break;
8249 case REASSOCREQ:
8250 /* Capability Information */
8251 *pos++ = 0x31;
8252 *pos++ = 0x04;
8253 /* Listen Interval */
8254 *pos++ = 0x0a;
8255 *pos++ = 0x00;
8256 /* Current AP */
8257 hwaddr_aton(bssid, pos);
8258 pos += 6;
8259 /* SSID */
8260 *pos++ = 0x00;
8261 *pos++ = ssid_len;
8262 memcpy(pos, ssid, ssid_len);
8263 pos += ssid_len;
8264 /* Supported Rates */
8265 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8266 10);
8267 pos += 10;
8268 /* Extended Supported Rates */
8269 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8270 pos += 6;
8271 /* RSN */
8272 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8273 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8274 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8275 pos += 28;
8276 break;
8277 case DLS_REQ:
8278 /* Category - DLS */
8279 *pos++ = 0x02;
8280 /* DLS Action - Request */
8281 *pos++ = 0x00;
8282 /* Destination MACAddress */
8283 if (dest)
8284 hwaddr_aton(dest, pos);
8285 else
8286 memset(pos, 0, 6);
8287 pos += 6;
8288 /* Source MACAddress */
8289 hwaddr_aton(addr, pos);
8290 pos += 6;
8291 /* Capability Information */
8292 *pos++ = 0x10; /* Privacy */
8293 *pos++ = 0x06; /* QoS */
8294 /* DLS Timeout Value */
8295 *pos++ = 0x00;
8296 *pos++ = 0x01;
8297 /* Supported rates */
8298 *pos++ = 0x01;
8299 *pos++ = 0x08;
8300 *pos++ = 0x0c; /* 6 Mbps */
8301 *pos++ = 0x12; /* 9 Mbps */
8302 *pos++ = 0x18; /* 12 Mbps */
8303 *pos++ = 0x24; /* 18 Mbps */
8304 *pos++ = 0x30; /* 24 Mbps */
8305 *pos++ = 0x48; /* 36 Mbps */
8306 *pos++ = 0x60; /* 48 Mbps */
8307 *pos++ = 0x6c; /* 54 Mbps */
8308 /* TODO: Extended Supported Rates */
8309 /* TODO: HT Capabilities */
8310 break;
8311 }
8312 }
8313
8314 s = open_monitor("sigmadut");
8315 if (s < 0) {
8316 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8317 "monitor socket");
8318 return 0;
8319 }
8320
8321 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8322 if (res < 0) {
8323 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8324 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308325 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008326 return 0;
8327 }
8328 if (res < pos - buf) {
8329 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8330 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308331 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008332 return 0;
8333 }
8334
8335 close(s);
8336
8337 return 1;
8338#else /* __linux__ */
8339 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
8340 "yet supported");
8341 return 0;
8342#endif /* __linux__ */
8343}
8344
8345
8346static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
8347 struct sigma_conn *conn,
8348 struct sigma_cmd *cmd)
8349{
8350 const char *intf = get_param(cmd, "Interface");
8351 const char *sta, *val;
8352 unsigned char addr[ETH_ALEN];
8353 char buf[100];
8354
8355 sta = get_param(cmd, "peer");
8356 if (sta == NULL)
8357 sta = get_param(cmd, "station");
8358 if (sta == NULL) {
8359 send_resp(dut, conn, SIGMA_ERROR,
8360 "ErrorCode,Missing peer address");
8361 return 0;
8362 }
8363 if (hwaddr_aton(sta, addr) < 0) {
8364 send_resp(dut, conn, SIGMA_ERROR,
8365 "ErrorCode,Invalid peer address");
8366 return 0;
8367 }
8368
8369 val = get_param(cmd, "type");
8370 if (val == NULL)
8371 return -1;
8372
8373 if (strcasecmp(val, "DISCOVERY") == 0) {
8374 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
8375 if (wpa_command(intf, buf) < 0) {
8376 send_resp(dut, conn, SIGMA_ERROR,
8377 "ErrorCode,Failed to send TDLS discovery");
8378 return 0;
8379 }
8380 return 1;
8381 }
8382
8383 if (strcasecmp(val, "SETUP") == 0) {
8384 int status = 0, timeout = 0;
8385
8386 val = get_param(cmd, "Status");
8387 if (val)
8388 status = atoi(val);
8389
8390 val = get_param(cmd, "Timeout");
8391 if (val)
8392 timeout = atoi(val);
8393
8394 if (status != 0 && status != 37) {
8395 send_resp(dut, conn, SIGMA_ERROR,
8396 "ErrorCode,Unsupported status value");
8397 return 0;
8398 }
8399
8400 if (timeout != 0 && timeout != 301) {
8401 send_resp(dut, conn, SIGMA_ERROR,
8402 "ErrorCode,Unsupported timeout value");
8403 return 0;
8404 }
8405
8406 if (status && timeout) {
8407 send_resp(dut, conn, SIGMA_ERROR,
8408 "ErrorCode,Unsupported timeout+status "
8409 "combination");
8410 return 0;
8411 }
8412
8413 if (status == 37 &&
8414 wpa_command(intf, "SET tdls_testing 0x200")) {
8415 send_resp(dut, conn, SIGMA_ERROR,
8416 "ErrorCode,Failed to enable "
8417 "decline setup response test mode");
8418 return 0;
8419 }
8420
8421 if (timeout == 301) {
8422 int res;
8423 if (dut->no_tpk_expiration)
8424 res = wpa_command(intf,
8425 "SET tdls_testing 0x108");
8426 else
8427 res = wpa_command(intf,
8428 "SET tdls_testing 0x8");
8429 if (res) {
8430 send_resp(dut, conn, SIGMA_ERROR,
8431 "ErrorCode,Failed to set short TPK "
8432 "lifetime");
8433 return 0;
8434 }
8435 }
8436
8437 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
8438 if (wpa_command(intf, buf) < 0) {
8439 send_resp(dut, conn, SIGMA_ERROR,
8440 "ErrorCode,Failed to send TDLS setup");
8441 return 0;
8442 }
8443 return 1;
8444 }
8445
8446 if (strcasecmp(val, "TEARDOWN") == 0) {
8447 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
8448 if (wpa_command(intf, buf) < 0) {
8449 send_resp(dut, conn, SIGMA_ERROR,
8450 "ErrorCode,Failed to send TDLS teardown");
8451 return 0;
8452 }
8453 return 1;
8454 }
8455
8456 send_resp(dut, conn, SIGMA_ERROR,
8457 "ErrorCode,Unsupported TDLS frame");
8458 return 0;
8459}
8460
8461
8462static int sta_ap_known(const char *ifname, const char *bssid)
8463{
8464 char buf[4096];
8465
Jouni Malinendd32f192018-09-15 02:55:19 +03008466 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008467 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
8468 return 0;
8469 if (strncmp(buf, "id=", 3) != 0)
8470 return 0;
8471 return 1;
8472}
8473
8474
8475static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
8476 const char *bssid)
8477{
8478 int res;
8479 struct wpa_ctrl *ctrl;
8480 char buf[256];
8481
8482 if (sta_ap_known(ifname, bssid))
8483 return 0;
8484 sigma_dut_print(dut, DUT_MSG_DEBUG,
8485 "AP not in BSS table - start scan");
8486
8487 ctrl = open_wpa_mon(ifname);
8488 if (ctrl == NULL) {
8489 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8490 "wpa_supplicant monitor connection");
8491 return -1;
8492 }
8493
8494 if (wpa_command(ifname, "SCAN") < 0) {
8495 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
8496 wpa_ctrl_detach(ctrl);
8497 wpa_ctrl_close(ctrl);
8498 return -1;
8499 }
8500
8501 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
8502 buf, sizeof(buf));
8503
8504 wpa_ctrl_detach(ctrl);
8505 wpa_ctrl_close(ctrl);
8506
8507 if (res < 0) {
8508 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
8509 return -1;
8510 }
8511
8512 if (sta_ap_known(ifname, bssid))
8513 return 0;
8514 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
8515 return -1;
8516}
8517
8518
8519static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
8520 struct sigma_conn *conn,
8521 struct sigma_cmd *cmd,
8522 const char *intf)
8523{
8524 char buf[200];
8525
8526 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
8527 if (system(buf) != 0) {
8528 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
8529 "ndsend");
8530 return 0;
8531 }
8532
8533 return 1;
8534}
8535
8536
8537static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
8538 struct sigma_conn *conn,
8539 struct sigma_cmd *cmd,
8540 const char *intf)
8541{
8542 char buf[200];
8543 const char *ip = get_param(cmd, "SenderIP");
8544
Peng Xu26b356d2017-10-04 17:58:16 -07008545 if (!ip)
8546 return 0;
8547
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008548 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
8549 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8550 if (system(buf) == 0) {
8551 sigma_dut_print(dut, DUT_MSG_INFO,
8552 "Neighbor Solicitation got a response "
8553 "for %s@%s", ip, intf);
8554 }
8555
8556 return 1;
8557}
8558
8559
8560static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
8561 struct sigma_conn *conn,
8562 struct sigma_cmd *cmd,
8563 const char *ifname)
8564{
8565 char buf[200];
8566 const char *ip = get_param(cmd, "SenderIP");
8567
8568 if (ip == NULL) {
8569 send_resp(dut, conn, SIGMA_ERROR,
8570 "ErrorCode,Missing SenderIP parameter");
8571 return 0;
8572 }
8573 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
8574 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8575 if (system(buf) != 0) {
8576 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
8577 "for %s@%s", ip, ifname);
8578 }
8579
8580 return 1;
8581}
8582
8583
8584static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
8585 struct sigma_conn *conn,
8586 struct sigma_cmd *cmd,
8587 const char *ifname)
8588{
8589 char buf[200];
8590 char ip[16];
8591 int s;
Peng Xub3756882017-10-04 14:39:09 -07008592 struct ifreq ifr;
8593 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008594
8595 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07008596 if (s < 0) {
8597 perror("socket");
8598 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008599 }
8600
Peng Xub3756882017-10-04 14:39:09 -07008601 memset(&ifr, 0, sizeof(ifr));
8602 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
8603 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
8604 sigma_dut_print(dut, DUT_MSG_INFO,
8605 "Failed to get %s IP address: %s",
8606 ifname, strerror(errno));
8607 close(s);
8608 return -1;
8609 }
8610 close(s);
8611
8612 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
8613 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
8614
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008615 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
8616 ip);
8617 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8618 if (system(buf) != 0) {
8619 }
8620
8621 return 1;
8622}
8623
8624
8625static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
8626 struct sigma_conn *conn,
8627 struct sigma_cmd *cmd,
8628 const char *ifname)
8629{
8630 char buf[200], addr[20];
8631 char dst[ETH_ALEN], src[ETH_ALEN];
8632 short ethtype = htons(ETH_P_ARP);
8633 char *pos;
8634 int s, res;
8635 const char *val;
8636 struct sockaddr_in taddr;
8637
8638 val = get_param(cmd, "dest");
8639 if (val)
8640 hwaddr_aton(val, (unsigned char *) dst);
8641
8642 val = get_param(cmd, "DestIP");
8643 if (val)
8644 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07008645 else
8646 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008647
8648 if (get_wpa_status(get_station_ifname(), "address", addr,
8649 sizeof(addr)) < 0)
8650 return -2;
8651 hwaddr_aton(addr, (unsigned char *) src);
8652
8653 pos = buf;
8654 *pos++ = 0x00;
8655 *pos++ = 0x01;
8656 *pos++ = 0x08;
8657 *pos++ = 0x00;
8658 *pos++ = 0x06;
8659 *pos++ = 0x04;
8660 *pos++ = 0x00;
8661 *pos++ = 0x02;
8662 memcpy(pos, src, ETH_ALEN);
8663 pos += ETH_ALEN;
8664 memcpy(pos, &taddr.sin_addr, 4);
8665 pos += 4;
8666 memcpy(pos, dst, ETH_ALEN);
8667 pos += ETH_ALEN;
8668 memcpy(pos, &taddr.sin_addr, 4);
8669 pos += 4;
8670
8671 s = open_monitor(get_station_ifname());
8672 if (s < 0) {
8673 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8674 "monitor socket");
8675 return 0;
8676 }
8677
8678 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
8679 if (res < 0) {
8680 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8681 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308682 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008683 return 0;
8684 }
8685
8686 close(s);
8687
8688 return 1;
8689}
8690
8691
8692static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
8693 struct sigma_conn *conn,
8694 struct sigma_cmd *cmd,
8695 const char *intf, const char *dest)
8696{
8697 char buf[100];
8698
8699 if (if_nametoindex("sigmadut") == 0) {
8700 snprintf(buf, sizeof(buf),
8701 "iw dev %s interface add sigmadut type monitor",
8702 get_station_ifname());
8703 if (system(buf) != 0 ||
8704 if_nametoindex("sigmadut") == 0) {
8705 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8706 "monitor interface with '%s'", buf);
8707 return -2;
8708 }
8709 }
8710
8711 if (system("ifconfig sigmadut up") != 0) {
8712 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8713 "monitor interface up");
8714 return -2;
8715 }
8716
8717 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
8718}
8719
8720
8721static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
8722 struct sigma_conn *conn,
8723 struct sigma_cmd *cmd)
8724{
8725 const char *intf = get_param(cmd, "Interface");
8726 const char *dest = get_param(cmd, "Dest");
8727 const char *type = get_param(cmd, "FrameName");
8728 const char *val;
8729 char buf[200], *pos, *end;
8730 int count, count2;
8731
8732 if (type == NULL)
8733 type = get_param(cmd, "Type");
8734
8735 if (intf == NULL || dest == NULL || type == NULL)
8736 return -1;
8737
8738 if (strcasecmp(type, "NeighAdv") == 0)
8739 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
8740
8741 if (strcasecmp(type, "NeighSolicitReq") == 0)
8742 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
8743
8744 if (strcasecmp(type, "ARPProbe") == 0)
8745 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
8746
8747 if (strcasecmp(type, "ARPAnnounce") == 0)
8748 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
8749
8750 if (strcasecmp(type, "ARPReply") == 0)
8751 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
8752
8753 if (strcasecmp(type, "DLS-request") == 0 ||
8754 strcasecmp(type, "DLSrequest") == 0)
8755 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
8756 dest);
8757
8758 if (strcasecmp(type, "ANQPQuery") != 0 &&
8759 strcasecmp(type, "Query") != 0) {
8760 send_resp(dut, conn, SIGMA_ERROR,
8761 "ErrorCode,Unsupported HS 2.0 send frame type");
8762 return 0;
8763 }
8764
8765 if (sta_scan_ap(dut, intf, dest) < 0) {
8766 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
8767 "the requested AP");
8768 return 0;
8769 }
8770
8771 pos = buf;
8772 end = buf + sizeof(buf);
8773 count = 0;
8774 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
8775
8776 val = get_param(cmd, "ANQP_CAP_LIST");
8777 if (val && atoi(val)) {
8778 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
8779 count++;
8780 }
8781
8782 val = get_param(cmd, "VENUE_NAME");
8783 if (val && atoi(val)) {
8784 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
8785 count++;
8786 }
8787
8788 val = get_param(cmd, "NETWORK_AUTH_TYPE");
8789 if (val && atoi(val)) {
8790 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
8791 count++;
8792 }
8793
8794 val = get_param(cmd, "ROAMING_CONS");
8795 if (val && atoi(val)) {
8796 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
8797 count++;
8798 }
8799
8800 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
8801 if (val && atoi(val)) {
8802 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
8803 count++;
8804 }
8805
8806 val = get_param(cmd, "NAI_REALM_LIST");
8807 if (val && atoi(val)) {
8808 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
8809 count++;
8810 }
8811
8812 val = get_param(cmd, "3GPP_INFO");
8813 if (val && atoi(val)) {
8814 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
8815 count++;
8816 }
8817
8818 val = get_param(cmd, "DOMAIN_LIST");
8819 if (val && atoi(val)) {
8820 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
8821 count++;
8822 }
8823
Jouni Malinen34cf9532018-04-29 19:26:33 +03008824 val = get_param(cmd, "Venue_URL");
8825 if (val && atoi(val)) {
8826 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
8827 count++;
8828 }
8829
Jouni Malinend3bca5d2018-04-29 17:25:23 +03008830 val = get_param(cmd, "Advice_Of_Charge");
8831 if (val && atoi(val)) {
8832 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
8833 count++;
8834 }
8835
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008836 if (count && wpa_command(intf, buf)) {
8837 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
8838 return 0;
8839 }
8840
8841 pos = buf;
8842 end = buf + sizeof(buf);
8843 count2 = 0;
8844 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
8845
8846 val = get_param(cmd, "HS_CAP_LIST");
8847 if (val && atoi(val)) {
8848 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
8849 count2++;
8850 }
8851
8852 val = get_param(cmd, "OPER_NAME");
8853 if (val && atoi(val)) {
8854 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
8855 count2++;
8856 }
8857
8858 val = get_param(cmd, "WAN_METRICS");
8859 if (!val)
8860 val = get_param(cmd, "WAN_MAT");
8861 if (!val)
8862 val = get_param(cmd, "WAN_MET");
8863 if (val && atoi(val)) {
8864 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
8865 count2++;
8866 }
8867
8868 val = get_param(cmd, "CONNECTION_CAPABILITY");
8869 if (val && atoi(val)) {
8870 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
8871 count2++;
8872 }
8873
8874 val = get_param(cmd, "OP_CLASS");
8875 if (val && atoi(val)) {
8876 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
8877 count2++;
8878 }
8879
8880 val = get_param(cmd, "OSU_PROVIDER_LIST");
8881 if (val && atoi(val)) {
8882 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
8883 count2++;
8884 }
8885
Jouni Malinenf67afec2018-04-29 19:24:58 +03008886 val = get_param(cmd, "OPER_ICON_METADATA");
8887 if (!val)
8888 val = get_param(cmd, "OPERATOR_ICON_METADATA");
8889 if (val && atoi(val)) {
8890 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
8891 count2++;
8892 }
8893
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008894 if (count && count2) {
8895 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
8896 "second query");
8897 sleep(1);
8898 }
8899
8900 if (count2 && wpa_command(intf, buf)) {
8901 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
8902 "failed");
8903 return 0;
8904 }
8905
8906 val = get_param(cmd, "NAI_HOME_REALM_LIST");
8907 if (val) {
8908 if (count || count2) {
8909 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8910 "sending out second query");
8911 sleep(1);
8912 }
8913
8914 if (strcmp(val, "1") == 0)
8915 val = "mail.example.com";
8916 snprintf(buf, end - pos,
8917 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
8918 dest, val);
8919 if (wpa_command(intf, buf)) {
8920 send_resp(dut, conn, SIGMA_ERROR,
8921 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
8922 "failed");
8923 return 0;
8924 }
8925 }
8926
8927 val = get_param(cmd, "ICON_REQUEST");
8928 if (val) {
8929 if (count || count2) {
8930 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8931 "sending out second query");
8932 sleep(1);
8933 }
8934
8935 snprintf(buf, end - pos,
8936 "HS20_ICON_REQUEST %s %s", dest, val);
8937 if (wpa_command(intf, buf)) {
8938 send_resp(dut, conn, SIGMA_ERROR,
8939 "ErrorCode,HS20_ICON_REQUEST failed");
8940 return 0;
8941 }
8942 }
8943
8944 return 1;
8945}
8946
8947
8948static int ath_sta_send_frame_vht(struct sigma_dut *dut,
8949 struct sigma_conn *conn,
8950 struct sigma_cmd *cmd)
8951{
8952 const char *val;
8953 char *ifname;
8954 char buf[100];
8955 int chwidth, nss;
8956
8957 val = get_param(cmd, "framename");
8958 if (!val)
8959 return -1;
8960 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
8961
8962 /* Command sequence to generate Op mode notification */
8963 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
8964 ifname = get_station_ifname();
8965
8966 /* Disable STBC */
8967 snprintf(buf, sizeof(buf),
8968 "iwpriv %s tx_stbc 0", ifname);
8969 if (system(buf) != 0) {
8970 sigma_dut_print(dut, DUT_MSG_ERROR,
8971 "iwpriv tx_stbc 0 failed!");
8972 }
8973
8974 /* Extract Channel width */
8975 val = get_param(cmd, "Channel_width");
8976 if (val) {
8977 switch (atoi(val)) {
8978 case 20:
8979 chwidth = 0;
8980 break;
8981 case 40:
8982 chwidth = 1;
8983 break;
8984 case 80:
8985 chwidth = 2;
8986 break;
8987 case 160:
8988 chwidth = 3;
8989 break;
8990 default:
8991 chwidth = 2;
8992 break;
8993 }
8994
8995 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8996 ifname, chwidth);
8997 if (system(buf) != 0) {
8998 sigma_dut_print(dut, DUT_MSG_ERROR,
8999 "iwpriv chwidth failed!");
9000 }
9001 }
9002
9003 /* Extract NSS */
9004 val = get_param(cmd, "NSS");
9005 if (val) {
9006 switch (atoi(val)) {
9007 case 1:
9008 nss = 1;
9009 break;
9010 case 2:
9011 nss = 3;
9012 break;
9013 case 3:
9014 nss = 7;
9015 break;
9016 default:
9017 /* We do not support NSS > 3 */
9018 nss = 3;
9019 break;
9020 }
9021 snprintf(buf, sizeof(buf),
9022 "iwpriv %s rxchainmask %d", ifname, nss);
9023 if (system(buf) != 0) {
9024 sigma_dut_print(dut, DUT_MSG_ERROR,
9025 "iwpriv rxchainmask failed!");
9026 }
9027 }
9028
9029 /* Opmode notify */
9030 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
9031 if (system(buf) != 0) {
9032 sigma_dut_print(dut, DUT_MSG_ERROR,
9033 "iwpriv opmode_notify failed!");
9034 } else {
9035 sigma_dut_print(dut, DUT_MSG_INFO,
9036 "Sent out the notify frame!");
9037 }
9038 }
9039
9040 return 1;
9041}
9042
9043
9044static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
9045 struct sigma_conn *conn,
9046 struct sigma_cmd *cmd)
9047{
9048 switch (get_driver_type()) {
9049 case DRIVER_ATHEROS:
9050 return ath_sta_send_frame_vht(dut, conn, cmd);
9051 default:
9052 send_resp(dut, conn, SIGMA_ERROR,
9053 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
9054 return 0;
9055 }
9056}
9057
9058
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009059static int wcn_sta_send_frame_he(struct sigma_dut *dut, struct sigma_conn *conn,
9060 struct sigma_cmd *cmd)
9061{
9062 const char *val;
9063 const char *intf = get_param(cmd, "Interface");
9064
9065 val = get_param(cmd, "framename");
9066 if (!val)
9067 return -1;
9068 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
9069
9070 /* Command sequence to generate Op mode notification */
9071 if (val && strcasecmp(val, "action") == 0) {
9072 val = get_param(cmd, "PPDUTxType");
9073 if (val && strcasecmp(val, "TB") == 0) {
9074 if (sta_set_action_tx_in_he_tb_ppdu(dut, intf, 1)) {
9075 sigma_dut_print(dut, DUT_MSG_ERROR,
9076 "failed to send TB PPDU Tx cfg");
9077 send_resp(dut, conn, SIGMA_ERROR,
9078 "ErrorCode,set TB PPDU Tx cfg failed");
9079 return 0;
9080 }
9081 return 1;
9082 }
9083
9084 sigma_dut_print(dut, DUT_MSG_ERROR,
9085 "Action Tx type is not defined");
9086 }
9087
9088 return 1;
9089}
9090
9091
9092static int cmd_sta_send_frame_he(struct sigma_dut *dut,
9093 struct sigma_conn *conn,
9094 struct sigma_cmd *cmd)
9095{
9096 switch (get_driver_type()) {
9097 case DRIVER_WCN:
9098 return wcn_sta_send_frame_he(dut, conn, cmd);
9099 default:
9100 send_resp(dut, conn, SIGMA_ERROR,
9101 "errorCode,Unsupported sta_set_frame(HE) with the current driver");
9102 return 0;
9103 }
9104}
9105
9106
Lior David0fe101e2017-03-09 16:09:50 +02009107#ifdef __linux__
9108int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
9109 struct sigma_cmd *cmd)
9110{
9111 const char *frame_name = get_param(cmd, "framename");
9112 const char *mac = get_param(cmd, "dest_mac");
9113
9114 if (!frame_name || !mac) {
9115 sigma_dut_print(dut, DUT_MSG_ERROR,
9116 "framename and dest_mac must be provided");
9117 return -1;
9118 }
9119
9120 if (strcasecmp(frame_name, "brp") == 0) {
9121 const char *l_rx = get_param(cmd, "L-RX");
9122 int l_rx_i;
9123
9124 if (!l_rx) {
9125 sigma_dut_print(dut, DUT_MSG_ERROR,
9126 "L-RX must be provided");
9127 return -1;
9128 }
9129 l_rx_i = atoi(l_rx);
9130
9131 sigma_dut_print(dut, DUT_MSG_INFO,
9132 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
9133 mac, l_rx);
9134 if (l_rx_i != 16) {
9135 sigma_dut_print(dut, DUT_MSG_ERROR,
9136 "unsupported L-RX: %s", l_rx);
9137 return -1;
9138 }
9139
9140 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
9141 return -1;
9142 } else if (strcasecmp(frame_name, "ssw") == 0) {
9143 sigma_dut_print(dut, DUT_MSG_INFO,
9144 "dev_send_frame: SLS, dest_mac %s", mac);
9145 if (wil6210_send_sls(dut, mac))
9146 return -1;
9147 } else {
9148 sigma_dut_print(dut, DUT_MSG_ERROR,
9149 "unsupported frame type: %s", frame_name);
9150 return -1;
9151 }
9152
9153 return 1;
9154}
9155#endif /* __linux__ */
9156
9157
9158static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
9159 struct sigma_conn *conn,
9160 struct sigma_cmd *cmd)
9161{
9162 switch (get_driver_type()) {
9163#ifdef __linux__
9164 case DRIVER_WIL6210:
9165 return wil6210_send_frame_60g(dut, conn, cmd);
9166#endif /* __linux__ */
9167 default:
9168 send_resp(dut, conn, SIGMA_ERROR,
9169 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9170 return 0;
9171 }
9172}
9173
9174
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309175static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
9176 const char *intf, struct sigma_cmd *cmd)
9177{
9178 const char *val, *addr;
9179 char buf[100];
9180
9181 addr = get_param(cmd, "DestMac");
9182 if (!addr) {
9183 send_resp(dut, conn, SIGMA_INVALID,
9184 "ErrorCode,AP MAC address is missing");
9185 return 0;
9186 }
9187
9188 val = get_param(cmd, "ANQPQuery_ID");
9189 if (!val) {
9190 send_resp(dut, conn, SIGMA_INVALID,
9191 "ErrorCode,Missing ANQPQuery_ID");
9192 return 0;
9193 }
9194
9195 if (strcasecmp(val, "NeighborReportReq") == 0) {
9196 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
9197 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
9198 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
9199 } else {
9200 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
9201 val);
9202 send_resp(dut, conn, SIGMA_INVALID,
9203 "ErrorCode,Invalid ANQPQuery_ID");
9204 return 0;
9205 }
9206
Ashwini Patild174f2c2017-04-13 16:49:46 +05309207 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
9208 * (Address3 = Wildcard BSSID when sent to not-associated AP;
9209 * if associated, AP BSSID).
9210 */
9211 if (wpa_command(intf, "SET gas_address3 1") < 0) {
9212 send_resp(dut, conn, SIGMA_ERROR,
9213 "ErrorCode,Failed to set gas_address3");
9214 return 0;
9215 }
9216
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309217 if (wpa_command(intf, buf) < 0) {
9218 send_resp(dut, conn, SIGMA_ERROR,
9219 "ErrorCode,Failed to send ANQP query");
9220 return 0;
9221 }
9222
9223 return 1;
9224}
9225
9226
9227static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
9228 struct sigma_conn *conn,
9229 const char *intf,
9230 struct sigma_cmd *cmd)
9231{
9232 const char *val = get_param(cmd, "FrameName");
9233
9234 if (val && strcasecmp(val, "ANQPQuery") == 0)
9235 return mbo_send_anqp_query(dut, conn, intf, cmd);
9236
9237 return 2;
9238}
9239
9240
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009241int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9242 struct sigma_cmd *cmd)
9243{
9244 const char *intf = get_param(cmd, "Interface");
9245 const char *val;
9246 enum send_frame_type frame;
9247 enum send_frame_protection protected;
9248 char buf[100];
9249 unsigned char addr[ETH_ALEN];
9250 int res;
9251
9252 val = get_param(cmd, "program");
9253 if (val == NULL)
9254 val = get_param(cmd, "frame");
9255 if (val && strcasecmp(val, "TDLS") == 0)
9256 return cmd_sta_send_frame_tdls(dut, conn, cmd);
9257 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009258 strcasecmp(val, "HS2-R2") == 0 ||
9259 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009260 return cmd_sta_send_frame_hs2(dut, conn, cmd);
9261 if (val && strcasecmp(val, "VHT") == 0)
9262 return cmd_sta_send_frame_vht(dut, conn, cmd);
Kiran Kumar Lokere419f6962018-10-24 19:03:04 -07009263 if (val && strcasecmp(val, "HE") == 0)
9264 return cmd_sta_send_frame_he(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009265 if (val && strcasecmp(val, "LOC") == 0)
9266 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009267 if (val && strcasecmp(val, "60GHz") == 0)
9268 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309269 if (val && strcasecmp(val, "MBO") == 0) {
9270 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
9271 if (res != 2)
9272 return res;
9273 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009274
9275 val = get_param(cmd, "TD_DISC");
9276 if (val) {
9277 if (hwaddr_aton(val, addr) < 0)
9278 return -1;
9279 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
9280 if (wpa_command(intf, buf) < 0) {
9281 send_resp(dut, conn, SIGMA_ERROR,
9282 "ErrorCode,Failed to send TDLS discovery");
9283 return 0;
9284 }
9285 return 1;
9286 }
9287
9288 val = get_param(cmd, "TD_Setup");
9289 if (val) {
9290 if (hwaddr_aton(val, addr) < 0)
9291 return -1;
9292 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
9293 if (wpa_command(intf, buf) < 0) {
9294 send_resp(dut, conn, SIGMA_ERROR,
9295 "ErrorCode,Failed to start TDLS setup");
9296 return 0;
9297 }
9298 return 1;
9299 }
9300
9301 val = get_param(cmd, "TD_TearDown");
9302 if (val) {
9303 if (hwaddr_aton(val, addr) < 0)
9304 return -1;
9305 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
9306 if (wpa_command(intf, buf) < 0) {
9307 send_resp(dut, conn, SIGMA_ERROR,
9308 "ErrorCode,Failed to tear down TDLS link");
9309 return 0;
9310 }
9311 return 1;
9312 }
9313
9314 val = get_param(cmd, "TD_ChannelSwitch");
9315 if (val) {
9316 /* TODO */
9317 send_resp(dut, conn, SIGMA_ERROR,
9318 "ErrorCode,TD_ChannelSwitch not yet supported");
9319 return 0;
9320 }
9321
9322 val = get_param(cmd, "TD_NF");
9323 if (val) {
9324 /* TODO */
9325 send_resp(dut, conn, SIGMA_ERROR,
9326 "ErrorCode,TD_NF not yet supported");
9327 return 0;
9328 }
9329
9330 val = get_param(cmd, "PMFFrameType");
9331 if (val == NULL)
9332 val = get_param(cmd, "FrameName");
9333 if (val == NULL)
9334 val = get_param(cmd, "Type");
9335 if (val == NULL)
9336 return -1;
9337 if (strcasecmp(val, "disassoc") == 0)
9338 frame = DISASSOC;
9339 else if (strcasecmp(val, "deauth") == 0)
9340 frame = DEAUTH;
9341 else if (strcasecmp(val, "saquery") == 0)
9342 frame = SAQUERY;
9343 else if (strcasecmp(val, "auth") == 0)
9344 frame = AUTH;
9345 else if (strcasecmp(val, "assocreq") == 0)
9346 frame = ASSOCREQ;
9347 else if (strcasecmp(val, "reassocreq") == 0)
9348 frame = REASSOCREQ;
9349 else if (strcasecmp(val, "neigreq") == 0) {
9350 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
9351
9352 val = get_param(cmd, "ssid");
9353 if (val == NULL)
9354 return -1;
9355
9356 res = send_neighbor_request(dut, intf, val);
9357 if (res) {
9358 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9359 "Failed to send neighbor report request");
9360 return 0;
9361 }
9362
9363 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05309364 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
9365 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009366 sigma_dut_print(dut, DUT_MSG_DEBUG,
9367 "Got Transition Management Query");
9368
Ashwini Patil5acd7382017-04-13 15:55:04 +05309369 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009370 if (res) {
9371 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9372 "Failed to send Transition Management Query");
9373 return 0;
9374 }
9375
9376 return 1;
9377 } else {
9378 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9379 "PMFFrameType");
9380 return 0;
9381 }
9382
9383 val = get_param(cmd, "PMFProtected");
9384 if (val == NULL)
9385 val = get_param(cmd, "Protected");
9386 if (val == NULL)
9387 return -1;
9388 if (strcasecmp(val, "Correct-key") == 0 ||
9389 strcasecmp(val, "CorrectKey") == 0)
9390 protected = CORRECT_KEY;
9391 else if (strcasecmp(val, "IncorrectKey") == 0)
9392 protected = INCORRECT_KEY;
9393 else if (strcasecmp(val, "Unprotected") == 0)
9394 protected = UNPROTECTED;
9395 else {
9396 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9397 "PMFProtected");
9398 return 0;
9399 }
9400
9401 if (protected != UNPROTECTED &&
9402 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
9403 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
9404 "PMFProtected for auth/assocreq/reassocreq");
9405 return 0;
9406 }
9407
9408 if (if_nametoindex("sigmadut") == 0) {
9409 snprintf(buf, sizeof(buf),
9410 "iw dev %s interface add sigmadut type monitor",
9411 get_station_ifname());
9412 if (system(buf) != 0 ||
9413 if_nametoindex("sigmadut") == 0) {
9414 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9415 "monitor interface with '%s'", buf);
9416 return -2;
9417 }
9418 }
9419
9420 if (system("ifconfig sigmadut up") != 0) {
9421 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9422 "monitor interface up");
9423 return -2;
9424 }
9425
9426 return sta_inject_frame(dut, conn, frame, protected, NULL);
9427}
9428
9429
9430static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
9431 struct sigma_conn *conn,
9432 struct sigma_cmd *cmd,
9433 const char *ifname)
9434{
9435 char buf[200];
9436 const char *val;
9437
9438 val = get_param(cmd, "ClearARP");
9439 if (val && atoi(val) == 1) {
9440 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
9441 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9442 if (system(buf) != 0) {
9443 send_resp(dut, conn, SIGMA_ERROR,
9444 "errorCode,Failed to clear ARP cache");
9445 return 0;
9446 }
9447 }
9448
9449 return 1;
9450}
9451
9452
9453int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
9454 struct sigma_cmd *cmd)
9455{
9456 const char *intf = get_param(cmd, "Interface");
9457 const char *val;
9458
9459 if (intf == NULL)
9460 return -1;
9461
9462 val = get_param(cmd, "program");
9463 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009464 strcasecmp(val, "HS2-R2") == 0 ||
9465 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009466 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
9467
9468 return -1;
9469}
9470
9471
9472static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
9473 struct sigma_cmd *cmd)
9474{
9475 const char *intf = get_param(cmd, "Interface");
9476 const char *mac = get_param(cmd, "MAC");
9477
9478 if (intf == NULL || mac == NULL)
9479 return -1;
9480
9481 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
9482 "interface %s to %s", intf, mac);
9483
9484 if (dut->set_macaddr) {
9485 char buf[128];
9486 int res;
9487 if (strcasecmp(mac, "default") == 0) {
9488 res = snprintf(buf, sizeof(buf), "%s",
9489 dut->set_macaddr);
9490 dut->tmp_mac_addr = 0;
9491 } else {
9492 res = snprintf(buf, sizeof(buf), "%s %s",
9493 dut->set_macaddr, mac);
9494 dut->tmp_mac_addr = 1;
9495 }
9496 if (res < 0 || res >= (int) sizeof(buf))
9497 return -1;
9498 if (system(buf) != 0) {
9499 send_resp(dut, conn, SIGMA_ERROR,
9500 "errorCode,Failed to set MAC "
9501 "address");
9502 return 0;
9503 }
9504 return 1;
9505 }
9506
9507 if (strcasecmp(mac, "default") == 0)
9508 return 1;
9509
9510 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9511 "command");
9512 return 0;
9513}
9514
9515
9516static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
9517 struct sigma_conn *conn, const char *intf,
9518 int val)
9519{
9520 char buf[200];
9521 int res;
9522
9523 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
9524 intf, val);
9525 if (res < 0 || res >= (int) sizeof(buf))
9526 return -1;
9527 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9528 if (system(buf) != 0) {
9529 send_resp(dut, conn, SIGMA_ERROR,
9530 "errorCode,Failed to configure offchannel mode");
9531 return 0;
9532 }
9533
9534 return 1;
9535}
9536
9537
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009538static int off_chan_val(enum sec_ch_offset off)
9539{
9540 switch (off) {
9541 case SEC_CH_NO:
9542 return 0;
9543 case SEC_CH_40ABOVE:
9544 return 40;
9545 case SEC_CH_40BELOW:
9546 return -40;
9547 }
9548
9549 return 0;
9550}
9551
9552
9553static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
9554 const char *intf, int off_ch_num,
9555 enum sec_ch_offset sec)
9556{
9557 char buf[200];
9558 int res;
9559
9560 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
9561 intf, off_ch_num);
9562 if (res < 0 || res >= (int) sizeof(buf))
9563 return -1;
9564 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9565 if (system(buf) != 0) {
9566 send_resp(dut, conn, SIGMA_ERROR,
9567 "errorCode,Failed to set offchan");
9568 return 0;
9569 }
9570
9571 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
9572 intf, off_chan_val(sec));
9573 if (res < 0 || res >= (int) sizeof(buf))
9574 return -1;
9575 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9576 if (system(buf) != 0) {
9577 send_resp(dut, conn, SIGMA_ERROR,
9578 "errorCode,Failed to set sec chan offset");
9579 return 0;
9580 }
9581
9582 return 1;
9583}
9584
9585
9586static int tdls_set_offchannel_offset(struct sigma_dut *dut,
9587 struct sigma_conn *conn,
9588 const char *intf, int off_ch_num,
9589 enum sec_ch_offset sec)
9590{
9591 char buf[200];
9592 int res;
9593
9594 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
9595 off_ch_num);
9596 if (res < 0 || res >= (int) sizeof(buf))
9597 return -1;
9598 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9599
9600 if (wpa_command(intf, buf) < 0) {
9601 send_resp(dut, conn, SIGMA_ERROR,
9602 "ErrorCode,Failed to set offchan");
9603 return 0;
9604 }
9605 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
9606 off_chan_val(sec));
9607 if (res < 0 || res >= (int) sizeof(buf))
9608 return -1;
9609
9610 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9611
9612 if (wpa_command(intf, buf) < 0) {
9613 send_resp(dut, conn, SIGMA_ERROR,
9614 "ErrorCode,Failed to set sec chan offset");
9615 return 0;
9616 }
9617
9618 return 1;
9619}
9620
9621
9622static int tdls_set_offchannel_mode(struct sigma_dut *dut,
9623 struct sigma_conn *conn,
9624 const char *intf, int val)
9625{
9626 char buf[200];
9627 int res;
9628
9629 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
9630 val);
9631 if (res < 0 || res >= (int) sizeof(buf))
9632 return -1;
9633 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9634
9635 if (wpa_command(intf, buf) < 0) {
9636 send_resp(dut, conn, SIGMA_ERROR,
9637 "ErrorCode,Failed to configure offchannel mode");
9638 return 0;
9639 }
9640
9641 return 1;
9642}
9643
9644
9645static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
9646 struct sigma_conn *conn,
9647 struct sigma_cmd *cmd)
9648{
9649 const char *val;
9650 enum {
9651 CHSM_NOT_SET,
9652 CHSM_ENABLE,
9653 CHSM_DISABLE,
9654 CHSM_REJREQ,
9655 CHSM_UNSOLRESP
9656 } chsm = CHSM_NOT_SET;
9657 int off_ch_num = -1;
9658 enum sec_ch_offset sec_ch = SEC_CH_NO;
9659 int res;
9660
9661 val = get_param(cmd, "Uapsd");
9662 if (val) {
9663 char buf[100];
9664 if (strcasecmp(val, "Enable") == 0)
9665 snprintf(buf, sizeof(buf), "SET ps 99");
9666 else if (strcasecmp(val, "Disable") == 0)
9667 snprintf(buf, sizeof(buf), "SET ps 98");
9668 else {
9669 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9670 "Unsupported uapsd parameter value");
9671 return 0;
9672 }
9673 if (wpa_command(intf, buf)) {
9674 send_resp(dut, conn, SIGMA_ERROR,
9675 "ErrorCode,Failed to change U-APSD "
9676 "powersave mode");
9677 return 0;
9678 }
9679 }
9680
9681 val = get_param(cmd, "TPKTIMER");
9682 if (val && strcasecmp(val, "DISABLE") == 0) {
9683 if (wpa_command(intf, "SET tdls_testing 0x100")) {
9684 send_resp(dut, conn, SIGMA_ERROR,
9685 "ErrorCode,Failed to enable no TPK "
9686 "expiration test mode");
9687 return 0;
9688 }
9689 dut->no_tpk_expiration = 1;
9690 }
9691
9692 val = get_param(cmd, "ChSwitchMode");
9693 if (val) {
9694 if (strcasecmp(val, "Enable") == 0 ||
9695 strcasecmp(val, "Initiate") == 0)
9696 chsm = CHSM_ENABLE;
9697 else if (strcasecmp(val, "Disable") == 0 ||
9698 strcasecmp(val, "passive") == 0)
9699 chsm = CHSM_DISABLE;
9700 else if (strcasecmp(val, "RejReq") == 0)
9701 chsm = CHSM_REJREQ;
9702 else if (strcasecmp(val, "UnSolResp") == 0)
9703 chsm = CHSM_UNSOLRESP;
9704 else {
9705 send_resp(dut, conn, SIGMA_ERROR,
9706 "ErrorCode,Unknown ChSwitchMode value");
9707 return 0;
9708 }
9709 }
9710
9711 val = get_param(cmd, "OffChNum");
9712 if (val) {
9713 off_ch_num = atoi(val);
9714 if (off_ch_num == 0) {
9715 send_resp(dut, conn, SIGMA_ERROR,
9716 "ErrorCode,Invalid OffChNum");
9717 return 0;
9718 }
9719 }
9720
9721 val = get_param(cmd, "SecChOffset");
9722 if (val) {
9723 if (strcmp(val, "20") == 0)
9724 sec_ch = SEC_CH_NO;
9725 else if (strcasecmp(val, "40above") == 0)
9726 sec_ch = SEC_CH_40ABOVE;
9727 else if (strcasecmp(val, "40below") == 0)
9728 sec_ch = SEC_CH_40BELOW;
9729 else {
9730 send_resp(dut, conn, SIGMA_ERROR,
9731 "ErrorCode,Unknown SecChOffset value");
9732 return 0;
9733 }
9734 }
9735
9736 if (chsm == CHSM_NOT_SET) {
9737 /* no offchannel changes requested */
9738 return 1;
9739 }
9740
9741 if (strcmp(intf, get_main_ifname()) != 0 &&
9742 strcmp(intf, get_station_ifname()) != 0) {
9743 send_resp(dut, conn, SIGMA_ERROR,
9744 "ErrorCode,Unknown interface");
9745 return 0;
9746 }
9747
9748 switch (chsm) {
9749 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03009750 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009751 break;
9752 case CHSM_ENABLE:
9753 if (off_ch_num < 0) {
9754 send_resp(dut, conn, SIGMA_ERROR,
9755 "ErrorCode,Missing OffChNum argument");
9756 return 0;
9757 }
9758 if (wifi_chip_type == DRIVER_WCN) {
9759 res = tdls_set_offchannel_offset(dut, conn, intf,
9760 off_ch_num, sec_ch);
9761 } else {
9762 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9763 sec_ch);
9764 }
9765 if (res != 1)
9766 return res;
9767 if (wifi_chip_type == DRIVER_WCN)
9768 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
9769 else
9770 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
9771 break;
9772 case CHSM_DISABLE:
9773 if (wifi_chip_type == DRIVER_WCN)
9774 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
9775 else
9776 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
9777 break;
9778 case CHSM_REJREQ:
9779 if (wifi_chip_type == DRIVER_WCN)
9780 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
9781 else
9782 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
9783 break;
9784 case CHSM_UNSOLRESP:
9785 if (off_ch_num < 0) {
9786 send_resp(dut, conn, SIGMA_ERROR,
9787 "ErrorCode,Missing OffChNum argument");
9788 return 0;
9789 }
9790 if (wifi_chip_type == DRIVER_WCN) {
9791 res = tdls_set_offchannel_offset(dut, conn, intf,
9792 off_ch_num, sec_ch);
9793 } else {
9794 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9795 sec_ch);
9796 }
9797 if (res != 1)
9798 return res;
9799 if (wifi_chip_type == DRIVER_WCN)
9800 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
9801 else
9802 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
9803 break;
9804 }
9805
9806 return res;
9807}
9808
9809
9810static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9811 struct sigma_conn *conn,
9812 struct sigma_cmd *cmd)
9813{
9814 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309815 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009816
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08009817 novap_reset(dut, intf);
9818
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009819 val = get_param(cmd, "nss_mcs_opt");
9820 if (val) {
9821 /* String (nss_operating_mode; mcs_operating_mode) */
9822 int nss, mcs;
9823 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309824 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009825
9826 token = strdup(val);
9827 if (!token)
9828 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309829 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309830 if (!result) {
9831 sigma_dut_print(dut, DUT_MSG_ERROR,
9832 "VHT NSS not specified");
9833 goto failed;
9834 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009835 if (strcasecmp(result, "def") != 0) {
9836 nss = atoi(result);
9837 if (nss == 4)
9838 ath_disable_txbf(dut, intf);
9839 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
9840 intf, nss);
9841 if (system(buf) != 0) {
9842 sigma_dut_print(dut, DUT_MSG_ERROR,
9843 "iwpriv nss failed");
9844 goto failed;
9845 }
9846 }
9847
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309848 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309849 if (!result) {
9850 sigma_dut_print(dut, DUT_MSG_ERROR,
9851 "VHT MCS not specified");
9852 goto failed;
9853 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009854 if (strcasecmp(result, "def") == 0) {
9855 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
9856 intf);
9857 if (system(buf) != 0) {
9858 sigma_dut_print(dut, DUT_MSG_ERROR,
9859 "iwpriv set11NRates failed");
9860 goto failed;
9861 }
9862
9863 } else {
9864 mcs = atoi(result);
9865 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
9866 intf, mcs);
9867 if (system(buf) != 0) {
9868 sigma_dut_print(dut, DUT_MSG_ERROR,
9869 "iwpriv vhtmcs failed");
9870 goto failed;
9871 }
9872 }
9873 /* Channel width gets messed up, fix this */
9874 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9875 intf, dut->chwidth);
9876 if (system(buf) != 0) {
9877 sigma_dut_print(dut, DUT_MSG_ERROR,
9878 "iwpriv chwidth failed");
9879 }
9880 }
9881
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309882 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009883 return 1;
9884failed:
9885 free(token);
9886 return 0;
9887}
9888
9889
9890static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9891 struct sigma_conn *conn,
9892 struct sigma_cmd *cmd)
9893{
9894 switch (get_driver_type()) {
9895 case DRIVER_ATHEROS:
9896 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
9897 default:
9898 send_resp(dut, conn, SIGMA_ERROR,
9899 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
9900 return 0;
9901 }
9902}
9903
9904
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009905static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9906 struct sigma_conn *conn,
9907 struct sigma_cmd *cmd)
9908{
9909 const char *val;
9910 char *token = NULL, *result;
9911 char buf[60];
9912
9913 val = get_param(cmd, "nss_mcs_opt");
9914 if (val) {
9915 /* String (nss_operating_mode; mcs_operating_mode) */
9916 int nss, mcs, ratecode;
9917 char *saveptr;
9918
9919 token = strdup(val);
9920 if (!token)
9921 return -2;
9922
9923 result = strtok_r(token, ";", &saveptr);
9924 if (!result) {
9925 sigma_dut_print(dut, DUT_MSG_ERROR,
9926 "HE NSS not specified");
9927 goto failed;
9928 }
9929 nss = 1;
9930 if (strcasecmp(result, "def") != 0)
9931 nss = atoi(result);
9932
9933 result = strtok_r(NULL, ";", &saveptr);
9934 if (!result) {
9935 sigma_dut_print(dut, DUT_MSG_ERROR,
9936 "HE MCS not specified");
9937 goto failed;
9938 }
9939 mcs = 7;
9940 if (strcasecmp(result, "def") != 0)
9941 mcs = atoi(result);
9942
Arif Hussain557bf412018-05-25 17:29:36 -07009943 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009944 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -07009945 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009946 } else if (nss > 2) {
9947 sigma_dut_print(dut, DUT_MSG_ERROR,
9948 "HE NSS %d not supported", nss);
9949 goto failed;
9950 }
9951
Arif Hussain557bf412018-05-25 17:29:36 -07009952 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
9953 if (system(buf) != 0) {
9954 sigma_dut_print(dut, DUT_MSG_ERROR,
9955 "nss_mcs_opt: iwpriv %s nss %d failed",
9956 intf, nss);
9957 goto failed;
9958 }
Arif Hussainac6c5112018-05-25 17:34:00 -07009959 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -07009960
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009961 /* Add the MCS to the ratecode */
9962 if (mcs >= 0 && mcs <= 11) {
9963 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -07009964#ifdef NL80211_SUPPORT
9965 if (dut->device_type == STA_testbed) {
9966 enum he_mcs_config mcs_config;
9967 int ret;
9968
9969 if (mcs <= 7)
9970 mcs_config = HE_80_MCS0_7;
9971 else if (mcs <= 9)
9972 mcs_config = HE_80_MCS0_9;
9973 else
9974 mcs_config = HE_80_MCS0_11;
9975 ret = sta_set_he_mcs(dut, intf, mcs_config);
9976 if (ret) {
9977 sigma_dut_print(dut, DUT_MSG_ERROR,
9978 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9979 mcs, mcs_config, ret);
9980 goto failed;
9981 }
9982 }
9983#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009984 } else {
9985 sigma_dut_print(dut, DUT_MSG_ERROR,
9986 "HE MCS %d not supported", mcs);
9987 goto failed;
9988 }
9989 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
9990 intf, ratecode);
9991 if (system(buf) != 0) {
9992 sigma_dut_print(dut, DUT_MSG_ERROR,
9993 "iwpriv setting of 11ax rates failed");
9994 goto failed;
9995 }
9996 free(token);
9997 }
9998
9999 val = get_param(cmd, "GI");
10000 if (val) {
10001 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010002 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010003 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010004 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
10005 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010006 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -070010007 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
10008 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010009 } else {
10010 send_resp(dut, conn, SIGMA_ERROR,
10011 "errorCode,GI value not supported");
10012 return 0;
10013 }
10014 if (system(buf) != 0) {
10015 send_resp(dut, conn, SIGMA_ERROR,
10016 "errorCode,Failed to set shortgi");
10017 return 0;
10018 }
10019 }
10020
Subhani Shaik8e7a3052018-04-24 14:03:00 -070010021 val = get_param(cmd, "LTF");
10022 if (val) {
10023#ifdef NL80211_SUPPORT
10024 if (strcmp(val, "3.2") == 0) {
10025 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
10026 } if (strcmp(val, "6.4") == 0) {
10027 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
10028 } else if (strcmp(val, "12.8") == 0) {
10029 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
10030 } else {
10031 send_resp(dut, conn, SIGMA_ERROR,
10032 "errorCode, LTF value not supported");
10033 return 0;
10034 }
10035#else /* NL80211_SUPPORT */
10036 sigma_dut_print(dut, DUT_MSG_ERROR,
10037 "LTF cannot be set without NL80211_SUPPORT defined");
10038 return -2;
10039#endif /* NL80211_SUPPORT */
10040 }
10041
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -070010042 val = get_param(cmd, "TxSUPPDU");
10043 if (val) {
10044 int set_val = 1;
10045
10046 if (strcasecmp(val, "Enable") == 0)
10047 set_val = 1;
10048 else if (strcasecmp(val, "Disable") == 0)
10049 set_val = 0;
10050
10051 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
10052 send_resp(dut, conn, SIGMA_ERROR,
10053 "ErrorCode,Failed to set Tx SU PPDU config");
10054 return 0;
10055 }
10056 }
10057
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -070010058 val = get_param(cmd, "OMCtrl_RxNSS");
10059 if (val) {
10060 /*
10061 * OMCtrl_RxNSS uses the IEEE 802.11 standard values for Nss,
10062 * i.e., 0 for 1Nss, 1 for Nss 2, etc. The driver checks for
10063 * the actual Nss value hence add 1 to the set value.
10064 */
10065 int set_val = atoi(val) + 1;
10066
10067 if (sta_set_he_om_ctrl_nss(dut, intf, set_val)) {
10068 send_resp(dut, conn, SIGMA_ERROR,
10069 "ErrorCode,Failed to set OM ctrl NSS config");
10070 return 0;
10071 }
10072 }
10073
10074 val = get_param(cmd, "OMCtrl_ChnlWidth");
10075 if (val) {
10076 int set_val = atoi(val);
10077
10078 if (sta_set_he_om_ctrl_bw(dut, intf,
10079 (enum qca_wlan_he_om_ctrl_ch_bw)
10080 set_val)) {
10081 send_resp(dut, conn, SIGMA_ERROR,
10082 "ErrorCode,Failed to set OM ctrl BW config");
10083 return 0;
10084 }
10085 }
10086
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010087 return 1;
10088
10089failed:
10090 free(token);
10091 return -2;
10092}
10093
10094
10095static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
10096 struct sigma_conn *conn,
10097 struct sigma_cmd *cmd)
10098{
10099 switch (get_driver_type()) {
10100 case DRIVER_WCN:
10101 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
10102 default:
10103 send_resp(dut, conn, SIGMA_ERROR,
10104 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
10105 return 0;
10106 }
10107}
10108
10109
Ashwini Patil5acd7382017-04-13 15:55:04 +053010110static int btm_query_candidate_list(struct sigma_dut *dut,
10111 struct sigma_conn *conn,
10112 struct sigma_cmd *cmd)
10113{
10114 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
10115 int len, ret;
10116 char buf[10];
10117
10118 /*
10119 * Neighbor Report elements format:
10120 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
10121 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
10122 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
10123 */
10124
10125 bssid = get_param(cmd, "Nebor_BSSID");
10126 if (!bssid) {
10127 send_resp(dut, conn, SIGMA_INVALID,
10128 "errorCode,Nebor_BSSID is missing");
10129 return 0;
10130 }
10131
10132 info = get_param(cmd, "Nebor_Bssid_Info");
10133 if (!info) {
10134 sigma_dut_print(dut, DUT_MSG_INFO,
10135 "Using default value for Nebor_Bssid_Info: %s",
10136 DEFAULT_NEIGHBOR_BSSID_INFO);
10137 info = DEFAULT_NEIGHBOR_BSSID_INFO;
10138 }
10139
10140 op_class = get_param(cmd, "Nebor_Op_Class");
10141 if (!op_class) {
10142 send_resp(dut, conn, SIGMA_INVALID,
10143 "errorCode,Nebor_Op_Class is missing");
10144 return 0;
10145 }
10146
10147 ch = get_param(cmd, "Nebor_Op_Ch");
10148 if (!ch) {
10149 send_resp(dut, conn, SIGMA_INVALID,
10150 "errorCode,Nebor_Op_Ch is missing");
10151 return 0;
10152 }
10153
10154 phy_type = get_param(cmd, "Nebor_Phy_Type");
10155 if (!phy_type) {
10156 sigma_dut_print(dut, DUT_MSG_INFO,
10157 "Using default value for Nebor_Phy_Type: %s",
10158 DEFAULT_NEIGHBOR_PHY_TYPE);
10159 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
10160 }
10161
10162 /* Parse optional subelements */
10163 buf[0] = '\0';
10164 pref = get_param(cmd, "Nebor_Pref");
10165 if (pref) {
10166 /* hexdump for preferrence subelement */
10167 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
10168 if (ret < 0 || ret >= (int) sizeof(buf)) {
10169 sigma_dut_print(dut, DUT_MSG_ERROR,
10170 "snprintf failed for optional subelement ret: %d",
10171 ret);
10172 send_resp(dut, conn, SIGMA_ERROR,
10173 "errorCode,snprintf failed for subelement");
10174 return 0;
10175 }
10176 }
10177
10178 if (!dut->btm_query_cand_list) {
10179 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
10180 if (!dut->btm_query_cand_list) {
10181 send_resp(dut, conn, SIGMA_ERROR,
10182 "errorCode,Failed to allocate memory for btm_query_cand_list");
10183 return 0;
10184 }
10185 }
10186
10187 len = strlen(dut->btm_query_cand_list);
10188 ret = snprintf(dut->btm_query_cand_list + len,
10189 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
10190 bssid, info, op_class, ch, phy_type, buf);
10191 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
10192 sigma_dut_print(dut, DUT_MSG_ERROR,
10193 "snprintf failed for neighbor report list ret: %d",
10194 ret);
10195 send_resp(dut, conn, SIGMA_ERROR,
10196 "errorCode,snprintf failed for neighbor report");
10197 free(dut->btm_query_cand_list);
10198 dut->btm_query_cand_list = NULL;
10199 return 0;
10200 }
10201
10202 return 1;
10203}
10204
10205
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010206static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10207 struct sigma_cmd *cmd)
10208{
10209 const char *intf = get_param(cmd, "Interface");
10210 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010211 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010212
10213 if (intf == NULL || prog == NULL)
10214 return -1;
10215
Ashwini Patil5acd7382017-04-13 15:55:04 +053010216 /* BSS Transition candidate list for BTM query */
10217 val = get_param(cmd, "Nebor_BSSID");
10218 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
10219 return 0;
10220
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010221 if (strcasecmp(prog, "TDLS") == 0)
10222 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
10223
10224 if (strcasecmp(prog, "VHT") == 0)
10225 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
10226
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010227 if (strcasecmp(prog, "HE") == 0)
10228 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
10229
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010230 if (strcasecmp(prog, "MBO") == 0) {
10231 val = get_param(cmd, "Cellular_Data_Cap");
10232 if (val &&
10233 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
10234 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053010235
10236 val = get_param(cmd, "Ch_Pref");
10237 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
10238 return 0;
10239
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010240 return 1;
10241 }
10242
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010243 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10244 return 0;
10245}
10246
10247
10248static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
10249 struct sigma_cmd *cmd)
10250{
10251 const char *intf = get_param(cmd, "Interface");
10252 const char *mode = get_param(cmd, "Mode");
10253 int res;
10254
10255 if (intf == NULL || mode == NULL)
10256 return -1;
10257
10258 if (strcasecmp(mode, "On") == 0)
10259 res = wpa_command(intf, "SET radio_disabled 0");
10260 else if (strcasecmp(mode, "Off") == 0)
10261 res = wpa_command(intf, "SET radio_disabled 1");
10262 else
10263 return -1;
10264
10265 if (res) {
10266 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10267 "radio mode");
10268 return 0;
10269 }
10270
10271 return 1;
10272}
10273
10274
10275static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
10276 struct sigma_cmd *cmd)
10277{
10278 const char *intf = get_param(cmd, "Interface");
10279 const char *mode = get_param(cmd, "Mode");
10280 int res;
10281
10282 if (intf == NULL || mode == NULL)
10283 return -1;
10284
10285 if (strcasecmp(mode, "On") == 0)
10286 res = set_ps(intf, dut, 1);
10287 else if (strcasecmp(mode, "Off") == 0)
10288 res = set_ps(intf, dut, 0);
10289 else
10290 return -1;
10291
10292 if (res) {
10293 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10294 "power save mode");
10295 return 0;
10296 }
10297
10298 return 1;
10299}
10300
10301
10302static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
10303 struct sigma_cmd *cmd)
10304{
10305 const char *intf = get_param(cmd, "Interface");
10306 const char *val, *bssid;
10307 int res;
10308 char *buf;
10309 size_t buf_len;
10310
10311 val = get_param(cmd, "BSSID_FILTER");
10312 if (val == NULL)
10313 return -1;
10314
10315 bssid = get_param(cmd, "BSSID_List");
10316 if (atoi(val) == 0 || bssid == NULL) {
10317 /* Disable BSSID filter */
10318 if (wpa_command(intf, "SET bssid_filter ")) {
10319 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
10320 "to disable BSSID filter");
10321 return 0;
10322 }
10323
10324 return 1;
10325 }
10326
10327 buf_len = 100 + strlen(bssid);
10328 buf = malloc(buf_len);
10329 if (buf == NULL)
10330 return -1;
10331
10332 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
10333 res = wpa_command(intf, buf);
10334 free(buf);
10335 if (res) {
10336 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
10337 "BSSID filter");
10338 return 0;
10339 }
10340
10341 return 1;
10342}
10343
10344
10345static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
10346 struct sigma_cmd *cmd)
10347{
10348 const char *intf = get_param(cmd, "Interface");
10349 const char *val;
10350
10351 /* TODO: ARP */
10352
10353 val = get_param(cmd, "HS2_CACHE_PROFILE");
10354 if (val && strcasecmp(val, "All") == 0)
10355 hs2_clear_credentials(intf);
10356
10357 return 1;
10358}
10359
10360
10361static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
10362 struct sigma_cmd *cmd)
10363{
10364 const char *intf = get_param(cmd, "Interface");
10365 const char *key_type = get_param(cmd, "KeyType");
10366 char buf[100], resp[200];
10367
10368 if (key_type == NULL)
10369 return -1;
10370
10371 if (strcasecmp(key_type, "GTK") == 0) {
10372 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
10373 strncmp(buf, "FAIL", 4) == 0) {
10374 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10375 "not fetch current GTK");
10376 return 0;
10377 }
10378 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
10379 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10380 return 0;
10381 } else {
10382 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10383 "KeyType");
10384 return 0;
10385 }
10386
10387 return 1;
10388}
10389
10390
10391static int hs2_set_policy(struct sigma_dut *dut)
10392{
10393#ifdef ANDROID
10394 system("ip rule del prio 23000");
10395 if (system("ip rule add from all lookup main prio 23000") != 0) {
10396 sigma_dut_print(dut, DUT_MSG_ERROR,
10397 "Failed to run:ip rule add from all lookup main prio");
10398 return -1;
10399 }
10400 if (system("ip route flush cache") != 0) {
10401 sigma_dut_print(dut, DUT_MSG_ERROR,
10402 "Failed to run ip route flush cache");
10403 return -1;
10404 }
10405 return 1;
10406#else /* ANDROID */
10407 return 0;
10408#endif /* ANDROID */
10409}
10410
10411
10412static int cmd_sta_hs2_associate(struct sigma_dut *dut,
10413 struct sigma_conn *conn,
10414 struct sigma_cmd *cmd)
10415{
10416 const char *intf = get_param(cmd, "Interface");
10417 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030010418 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010419 struct wpa_ctrl *ctrl;
10420 int res;
10421 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
10422 int tries = 0;
10423 int ignore_blacklist = 0;
10424 const char *events[] = {
10425 "CTRL-EVENT-CONNECTED",
10426 "INTERWORKING-BLACKLISTED",
10427 "INTERWORKING-NO-MATCH",
10428 NULL
10429 };
10430
10431 start_sta_mode(dut);
10432
Jouni Malinen439352d2018-09-13 03:42:23 +030010433 if (band) {
10434 if (strcmp(band, "2.4") == 0) {
10435 wpa_command(intf, "SET setband 2G");
10436 } else if (strcmp(band, "5") == 0) {
10437 wpa_command(intf, "SET setband 5G");
10438 } else {
10439 send_resp(dut, conn, SIGMA_ERROR,
10440 "errorCode,Unsupported band");
10441 return 0;
10442 }
10443 }
10444
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010445 blacklisted[0] = '\0';
10446 if (val && atoi(val))
10447 ignore_blacklist = 1;
10448
10449try_again:
10450 ctrl = open_wpa_mon(intf);
10451 if (ctrl == NULL) {
10452 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10453 "wpa_supplicant monitor connection");
10454 return -2;
10455 }
10456
10457 tries++;
10458 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
10459 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
10460 "Interworking connection");
10461 wpa_ctrl_detach(ctrl);
10462 wpa_ctrl_close(ctrl);
10463 return 0;
10464 }
10465
10466 buf[0] = '\0';
10467 while (1) {
10468 char *pos;
10469 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
10470 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
10471 if (!pos)
10472 break;
10473 pos += 25;
10474 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
10475 pos);
10476 if (!blacklisted[0])
10477 memcpy(blacklisted, pos, strlen(pos) + 1);
10478 }
10479
10480 if (ignore_blacklist && blacklisted[0]) {
10481 char *end;
10482 end = strchr(blacklisted, ' ');
10483 if (end)
10484 *end = '\0';
10485 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
10486 blacklisted);
10487 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
10488 blacklisted);
10489 if (wpa_command(intf, buf)) {
10490 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
10491 wpa_ctrl_detach(ctrl);
10492 wpa_ctrl_close(ctrl);
10493 return 0;
10494 }
10495 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
10496 buf, sizeof(buf));
10497 }
10498
10499 wpa_ctrl_detach(ctrl);
10500 wpa_ctrl_close(ctrl);
10501
10502 if (res < 0) {
10503 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10504 "connect");
10505 return 0;
10506 }
10507
10508 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
10509 strstr(buf, "INTERWORKING-BLACKLISTED")) {
10510 if (tries < 2) {
10511 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
10512 goto try_again;
10513 }
10514 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
10515 "matching credentials found");
10516 return 0;
10517 }
10518
10519 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
10520 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
10521 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10522 "get current BSSID/SSID");
10523 return 0;
10524 }
10525
10526 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
10527 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10528 hs2_set_policy(dut);
10529 return 0;
10530}
10531
10532
Jouni Malinenb639f1c2018-09-13 02:39:46 +030010533static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
10534 struct sigma_conn *conn,
10535 struct sigma_cmd *cmd)
10536{
10537 const char *intf = get_param(cmd, "Interface");
10538 const char *display = get_param(cmd, "Display");
10539 struct wpa_ctrl *ctrl;
10540 char buf[300], params[400], *pos;
10541 char bssid[20];
10542 int info_avail = 0;
10543 unsigned int old_timeout;
10544 int res;
10545
10546 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
10547 send_resp(dut, conn, SIGMA_ERROR,
10548 "ErrorCode,Could not get current BSSID");
10549 return 0;
10550 }
10551 ctrl = open_wpa_mon(intf);
10552 if (!ctrl) {
10553 sigma_dut_print(dut, DUT_MSG_ERROR,
10554 "Failed to open wpa_supplicant monitor connection");
10555 return -2;
10556 }
10557
10558 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
10559 wpa_command(intf, buf);
10560
10561 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
10562 if (res < 0) {
10563 send_resp(dut, conn, SIGMA_ERROR,
10564 "ErrorCode,Could not complete GAS query");
10565 goto fail;
10566 }
10567
10568 old_timeout = dut->default_timeout;
10569 dut->default_timeout = 2;
10570 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
10571 dut->default_timeout = old_timeout;
10572 if (res < 0)
10573 goto done;
10574 pos = strchr(buf, ' ');
10575 if (!pos)
10576 goto done;
10577 pos++;
10578 pos = strchr(pos, ' ');
10579 if (!pos)
10580 goto done;
10581 pos++;
10582 info_avail = 1;
10583 snprintf(params, sizeof(params), "browser %s", pos);
10584
10585 if (display && strcasecmp(display, "Yes") == 0) {
10586 pid_t pid;
10587
10588 pid = fork();
10589 if (pid < 0) {
10590 perror("fork");
10591 return -1;
10592 }
10593
10594 if (pid == 0) {
10595 run_hs20_osu(dut, params);
10596 exit(0);
10597 }
10598 }
10599
10600done:
10601 snprintf(buf, sizeof(buf), "Info_available,%s",
10602 info_avail ? "Yes" : "No");
10603 send_resp(dut, conn, SIGMA_COMPLETE, buf);
10604fail:
10605 wpa_ctrl_detach(ctrl);
10606 wpa_ctrl_close(ctrl);
10607 return 0;
10608}
10609
10610
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010611static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
10612 struct sigma_conn *conn,
10613 const char *ifname,
10614 struct sigma_cmd *cmd)
10615{
10616 const char *val;
10617 int id;
10618
10619 id = add_cred(ifname);
10620 if (id < 0)
10621 return -2;
10622 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10623
10624 val = get_param(cmd, "prefer");
10625 if (val && atoi(val) > 0)
10626 set_cred(ifname, id, "priority", "1");
10627
10628 val = get_param(cmd, "REALM");
10629 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10630 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10631 "realm");
10632 return 0;
10633 }
10634
10635 val = get_param(cmd, "HOME_FQDN");
10636 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10637 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10638 "home_fqdn");
10639 return 0;
10640 }
10641
10642 val = get_param(cmd, "Username");
10643 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10644 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10645 "username");
10646 return 0;
10647 }
10648
10649 val = get_param(cmd, "Password");
10650 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
10651 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10652 "password");
10653 return 0;
10654 }
10655
10656 val = get_param(cmd, "ROOT_CA");
10657 if (val) {
10658 char fname[200];
10659 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10660#ifdef __linux__
10661 if (!file_exists(fname)) {
10662 char msg[300];
10663 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10664 "file (%s) not found", fname);
10665 send_resp(dut, conn, SIGMA_ERROR, msg);
10666 return 0;
10667 }
10668#endif /* __linux__ */
10669 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10670 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10671 "not set root CA");
10672 return 0;
10673 }
10674 }
10675
10676 return 1;
10677}
10678
10679
10680static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
10681{
10682 FILE *in, *out;
10683 char buf[500];
10684 int found = 0;
10685
10686 in = fopen("devdetail.xml", "r");
10687 if (in == NULL)
10688 return -1;
10689 out = fopen("devdetail.xml.tmp", "w");
10690 if (out == NULL) {
10691 fclose(in);
10692 return -1;
10693 }
10694
10695 while (fgets(buf, sizeof(buf), in)) {
10696 char *pos = strstr(buf, "<IMSI>");
10697 if (pos) {
10698 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
10699 imsi);
10700 pos += 6;
10701 *pos = '\0';
10702 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
10703 found++;
10704 } else {
10705 fprintf(out, "%s", buf);
10706 }
10707 }
10708
10709 fclose(out);
10710 fclose(in);
10711 if (found)
10712 rename("devdetail.xml.tmp", "devdetail.xml");
10713 else
10714 unlink("devdetail.xml.tmp");
10715
10716 return 0;
10717}
10718
10719
10720static int sta_add_credential_sim(struct sigma_dut *dut,
10721 struct sigma_conn *conn,
10722 const char *ifname, struct sigma_cmd *cmd)
10723{
10724 const char *val, *imsi = NULL;
10725 int id;
10726 char buf[200];
10727 int res;
10728 const char *pos;
10729 size_t mnc_len;
10730 char plmn_mcc[4];
10731 char plmn_mnc[4];
10732
10733 id = add_cred(ifname);
10734 if (id < 0)
10735 return -2;
10736 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10737
10738 val = get_param(cmd, "prefer");
10739 if (val && atoi(val) > 0)
10740 set_cred(ifname, id, "priority", "1");
10741
10742 val = get_param(cmd, "PLMN_MCC");
10743 if (val == NULL) {
10744 send_resp(dut, conn, SIGMA_ERROR,
10745 "errorCode,Missing PLMN_MCC");
10746 return 0;
10747 }
10748 if (strlen(val) != 3) {
10749 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
10750 return 0;
10751 }
10752 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
10753
10754 val = get_param(cmd, "PLMN_MNC");
10755 if (val == NULL) {
10756 send_resp(dut, conn, SIGMA_ERROR,
10757 "errorCode,Missing PLMN_MNC");
10758 return 0;
10759 }
10760 if (strlen(val) != 2 && strlen(val) != 3) {
10761 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
10762 return 0;
10763 }
10764 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
10765
10766 val = get_param(cmd, "IMSI");
10767 if (val == NULL) {
10768 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
10769 "IMSI");
10770 return 0;
10771 }
10772
10773 imsi = pos = val;
10774
10775 if (strncmp(plmn_mcc, pos, 3) != 0) {
10776 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
10777 return 0;
10778 }
10779 pos += 3;
10780
10781 mnc_len = strlen(plmn_mnc);
10782 if (mnc_len < 2) {
10783 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
10784 return 0;
10785 }
10786
10787 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
10788 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
10789 return 0;
10790 }
10791 pos += mnc_len;
10792
10793 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
10794 if (res < 0 || res >= (int) sizeof(buf))
10795 return -1;
10796 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
10797 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10798 "not set IMSI");
10799 return 0;
10800 }
10801
10802 val = get_param(cmd, "Password");
10803 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
10804 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10805 "not set password");
10806 return 0;
10807 }
10808
Jouni Malinenba630452018-06-22 11:49:59 +030010809 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010810 /*
10811 * Set provisioning_sp for the test cases where SIM/USIM
10812 * provisioning is used.
10813 */
10814 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
10815 "wi-fi.org") < 0) {
10816 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10817 "not set provisioning_sp");
10818 return 0;
10819 }
10820
10821 update_devdetail_imsi(dut, imsi);
10822 }
10823
10824 return 1;
10825}
10826
10827
10828static int sta_add_credential_cert(struct sigma_dut *dut,
10829 struct sigma_conn *conn,
10830 const char *ifname,
10831 struct sigma_cmd *cmd)
10832{
10833 const char *val;
10834 int id;
10835
10836 id = add_cred(ifname);
10837 if (id < 0)
10838 return -2;
10839 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10840
10841 val = get_param(cmd, "prefer");
10842 if (val && atoi(val) > 0)
10843 set_cred(ifname, id, "priority", "1");
10844
10845 val = get_param(cmd, "REALM");
10846 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10847 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10848 "realm");
10849 return 0;
10850 }
10851
10852 val = get_param(cmd, "HOME_FQDN");
10853 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10854 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10855 "home_fqdn");
10856 return 0;
10857 }
10858
10859 val = get_param(cmd, "Username");
10860 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10861 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10862 "username");
10863 return 0;
10864 }
10865
10866 val = get_param(cmd, "clientCertificate");
10867 if (val) {
10868 char fname[200];
10869 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10870#ifdef __linux__
10871 if (!file_exists(fname)) {
10872 char msg[300];
10873 snprintf(msg, sizeof(msg),
10874 "ErrorCode,clientCertificate "
10875 "file (%s) not found", fname);
10876 send_resp(dut, conn, SIGMA_ERROR, msg);
10877 return 0;
10878 }
10879#endif /* __linux__ */
10880 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
10881 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10882 "not set client_cert");
10883 return 0;
10884 }
10885 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
10886 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10887 "not set private_key");
10888 return 0;
10889 }
10890 }
10891
10892 val = get_param(cmd, "ROOT_CA");
10893 if (val) {
10894 char fname[200];
10895 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10896#ifdef __linux__
10897 if (!file_exists(fname)) {
10898 char msg[300];
10899 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10900 "file (%s) not found", fname);
10901 send_resp(dut, conn, SIGMA_ERROR, msg);
10902 return 0;
10903 }
10904#endif /* __linux__ */
10905 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10906 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10907 "not set root CA");
10908 return 0;
10909 }
10910 }
10911
10912 return 1;
10913}
10914
10915
10916static int cmd_sta_add_credential(struct sigma_dut *dut,
10917 struct sigma_conn *conn,
10918 struct sigma_cmd *cmd)
10919{
10920 const char *intf = get_param(cmd, "Interface");
10921 const char *type;
10922
10923 start_sta_mode(dut);
10924
10925 type = get_param(cmd, "Type");
10926 if (!type)
10927 return -1;
10928
10929 if (strcasecmp(type, "uname_pwd") == 0)
10930 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
10931
10932 if (strcasecmp(type, "sim") == 0)
10933 return sta_add_credential_sim(dut, conn, intf, cmd);
10934
10935 if (strcasecmp(type, "cert") == 0)
10936 return sta_add_credential_cert(dut, conn, intf, cmd);
10937
10938 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
10939 "type");
10940 return 0;
10941}
10942
10943
10944static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
10945 struct sigma_cmd *cmd)
10946{
10947 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053010948 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010949 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +053010950 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010951 int res;
10952
10953 val = get_param(cmd, "HESSID");
10954 if (val) {
10955 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
10956 if (res < 0 || res >= (int) sizeof(buf))
10957 return -1;
10958 wpa_command(intf, buf);
10959 }
10960
10961 val = get_param(cmd, "ACCS_NET_TYPE");
10962 if (val) {
10963 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
10964 val);
10965 if (res < 0 || res >= (int) sizeof(buf))
10966 return -1;
10967 wpa_command(intf, buf);
10968 }
10969
vamsi krishna89ad8c62017-09-19 12:51:18 +053010970 bssid = get_param(cmd, "Bssid");
10971 ssid = get_param(cmd, "Ssid");
10972
10973 if (ssid) {
10974 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
10975 send_resp(dut, conn, SIGMA_ERROR,
10976 "ErrorCode,Too long SSID");
10977 return 0;
10978 }
10979 ascii2hexstr(ssid, ssid_hex);
10980 }
10981
10982 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
10983 bssid ? " bssid=": "",
10984 bssid ? bssid : "",
10985 ssid ? " ssid " : "",
10986 ssid ? ssid_hex : "");
10987 if (res < 0 || res >= (int) sizeof(buf))
10988 return -1;
10989
10990 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010991 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
10992 "scan");
10993 return 0;
10994 }
10995
10996 return 1;
10997}
10998
10999
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011000static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
11001 struct sigma_cmd *cmd)
11002{
11003 const char *intf = get_param(cmd, "Interface");
11004 const char *bssid;
11005 char buf[4096], *pos;
11006 int freq, chan;
11007 char *ssid;
11008 char resp[100];
11009 int res;
11010 struct wpa_ctrl *ctrl;
11011
11012 bssid = get_param(cmd, "BSSID");
11013 if (!bssid) {
11014 send_resp(dut, conn, SIGMA_INVALID,
11015 "errorCode,BSSID argument is missing");
11016 return 0;
11017 }
11018
11019 ctrl = open_wpa_mon(intf);
11020 if (!ctrl) {
11021 sigma_dut_print(dut, DUT_MSG_ERROR,
11022 "Failed to open wpa_supplicant monitor connection");
11023 return -1;
11024 }
11025
11026 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
11027 send_resp(dut, conn, SIGMA_ERROR,
11028 "errorCode,Could not start scan");
11029 wpa_ctrl_detach(ctrl);
11030 wpa_ctrl_close(ctrl);
11031 return 0;
11032 }
11033
11034 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
11035 buf, sizeof(buf));
11036
11037 wpa_ctrl_detach(ctrl);
11038 wpa_ctrl_close(ctrl);
11039
11040 if (res < 0) {
11041 send_resp(dut, conn, SIGMA_ERROR,
11042 "errorCode,Scan did not complete");
11043 return 0;
11044 }
11045
11046 snprintf(buf, sizeof(buf), "BSS %s", bssid);
11047 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
11048 strncmp(buf, "id=", 3) != 0) {
11049 send_resp(dut, conn, SIGMA_ERROR,
11050 "errorCode,Specified BSSID not found");
11051 return 0;
11052 }
11053
11054 pos = strstr(buf, "\nfreq=");
11055 if (!pos) {
11056 send_resp(dut, conn, SIGMA_ERROR,
11057 "errorCode,Channel not found");
11058 return 0;
11059 }
11060 freq = atoi(pos + 6);
11061 chan = freq_to_channel(freq);
11062
11063 pos = strstr(buf, "\nssid=");
11064 if (!pos) {
11065 send_resp(dut, conn, SIGMA_ERROR,
11066 "errorCode,SSID not found");
11067 return 0;
11068 }
11069 ssid = pos + 6;
11070 pos = strchr(ssid, '\n');
11071 if (pos)
11072 *pos = '\0';
11073 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
11074 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11075 return 0;
11076}
11077
11078
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011079static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
11080 struct sigma_cmd *cmd)
11081{
11082#ifdef __linux__
11083 struct timeval tv;
11084 struct tm tm;
11085 time_t t;
11086 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011087 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011088
11089 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
11090
11091 memset(&tm, 0, sizeof(tm));
11092 val = get_param(cmd, "seconds");
11093 if (val)
11094 tm.tm_sec = atoi(val);
11095 val = get_param(cmd, "minutes");
11096 if (val)
11097 tm.tm_min = atoi(val);
11098 val = get_param(cmd, "hours");
11099 if (val)
11100 tm.tm_hour = atoi(val);
11101 val = get_param(cmd, "date");
11102 if (val)
11103 tm.tm_mday = atoi(val);
11104 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053011105 if (val) {
11106 v = atoi(val);
11107 if (v < 1 || v > 12) {
11108 send_resp(dut, conn, SIGMA_INVALID,
11109 "errorCode,Invalid month");
11110 return 0;
11111 }
11112 tm.tm_mon = v - 1;
11113 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011114 val = get_param(cmd, "year");
11115 if (val) {
11116 int year = atoi(val);
11117#ifdef ANDROID
11118 if (year > 2035)
11119 year = 2035; /* years beyond 2035 not supported */
11120#endif /* ANDROID */
11121 tm.tm_year = year - 1900;
11122 }
11123 t = mktime(&tm);
11124 if (t == (time_t) -1) {
11125 send_resp(dut, conn, SIGMA_ERROR,
11126 "errorCode,Invalid date or time");
11127 return 0;
11128 }
11129
11130 memset(&tv, 0, sizeof(tv));
11131 tv.tv_sec = t;
11132
11133 if (settimeofday(&tv, NULL) < 0) {
11134 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
11135 strerror(errno));
11136 send_resp(dut, conn, SIGMA_ERROR,
11137 "errorCode,Failed to set time");
11138 return 0;
11139 }
11140
11141 return 1;
11142#endif /* __linux__ */
11143
11144 return -1;
11145}
11146
11147
11148static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
11149 struct sigma_cmd *cmd)
11150{
11151 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011152 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011153 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011154 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011155 int res;
11156 struct wpa_ctrl *ctrl;
11157
11158 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011159 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011160
11161 val = get_param(cmd, "ProdESSAssoc");
11162 if (val)
11163 prod_ess_assoc = atoi(val);
11164
11165 kill_dhcp_client(dut, intf);
11166 if (start_dhcp_client(dut, intf) < 0)
11167 return -2;
11168
11169 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
11170 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11171 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011172 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011173 prod_ess_assoc ? "" : "-N",
11174 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011175 name ? "'" : "",
11176 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
11177 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011178
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053011179 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011180 if (run_hs20_osu(dut, buf) < 0) {
11181 FILE *f;
11182
11183 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
11184
11185 f = fopen("hs20-osu-client.res", "r");
11186 if (f) {
11187 char resp[400], res[300], *pos;
11188 if (!fgets(res, sizeof(res), f))
11189 res[0] = '\0';
11190 pos = strchr(res, '\n');
11191 if (pos)
11192 *pos = '\0';
11193 fclose(f);
11194 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
11195 res);
11196 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
11197 if (system(resp) != 0) {
11198 }
11199 snprintf(resp, sizeof(resp),
11200 "SSID,,BSSID,,failureReason,%s", res);
11201 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11202 return 0;
11203 }
11204
11205 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11206 return 0;
11207 }
11208
11209 if (!prod_ess_assoc)
11210 goto report;
11211
11212 ctrl = open_wpa_mon(intf);
11213 if (ctrl == NULL) {
11214 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11215 "wpa_supplicant monitor connection");
11216 return -1;
11217 }
11218
11219 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11220 buf, sizeof(buf));
11221
11222 wpa_ctrl_detach(ctrl);
11223 wpa_ctrl_close(ctrl);
11224
11225 if (res < 0) {
11226 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
11227 "network after OSU");
11228 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11229 return 0;
11230 }
11231
11232report:
11233 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11234 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11235 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
11236 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11237 return 0;
11238 }
11239
11240 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
11241 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011242 return 0;
11243}
11244
11245
11246static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
11247 struct sigma_cmd *cmd)
11248{
11249 const char *val;
11250 int timeout = 120;
11251
11252 val = get_param(cmd, "PolicyUpdate");
11253 if (val == NULL || atoi(val) == 0)
11254 return 1; /* No operation requested */
11255
11256 val = get_param(cmd, "Timeout");
11257 if (val)
11258 timeout = atoi(val);
11259
11260 if (timeout) {
11261 /* TODO: time out the command and return
11262 * PolicyUpdateStatus,TIMEOUT if needed. */
11263 }
11264
11265 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
11266 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11267 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
11268 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
11269 return 0;
11270 }
11271
11272 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
11273 return 0;
11274}
11275
11276
11277static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
11278 struct sigma_cmd *cmd)
11279{
11280 struct wpa_ctrl *ctrl;
11281 const char *intf = get_param(cmd, "Interface");
11282 const char *bssid = get_param(cmd, "Bssid");
11283 const char *ssid = get_param(cmd, "SSID");
11284 const char *security = get_param(cmd, "Security");
11285 const char *passphrase = get_param(cmd, "Passphrase");
11286 const char *pin = get_param(cmd, "PIN");
11287 char buf[1000];
11288 char ssid_hex[200], passphrase_hex[200];
11289 const char *keymgmt, *cipher;
11290
11291 if (intf == NULL)
11292 intf = get_main_ifname();
11293
11294 if (!bssid) {
11295 send_resp(dut, conn, SIGMA_ERROR,
11296 "ErrorCode,Missing Bssid argument");
11297 return 0;
11298 }
11299
11300 if (!ssid) {
11301 send_resp(dut, conn, SIGMA_ERROR,
11302 "ErrorCode,Missing SSID argument");
11303 return 0;
11304 }
11305
11306 if (!security) {
11307 send_resp(dut, conn, SIGMA_ERROR,
11308 "ErrorCode,Missing Security argument");
11309 return 0;
11310 }
11311
11312 if (!passphrase) {
11313 send_resp(dut, conn, SIGMA_ERROR,
11314 "ErrorCode,Missing Passphrase argument");
11315 return 0;
11316 }
11317
11318 if (!pin) {
11319 send_resp(dut, conn, SIGMA_ERROR,
11320 "ErrorCode,Missing PIN argument");
11321 return 0;
11322 }
11323
vamsi krishna8c9c1562017-05-12 15:51:46 +053011324 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
11325 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011326 send_resp(dut, conn, SIGMA_ERROR,
11327 "ErrorCode,Too long SSID/passphrase");
11328 return 0;
11329 }
11330
11331 ctrl = open_wpa_mon(intf);
11332 if (ctrl == NULL) {
11333 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11334 "wpa_supplicant monitor connection");
11335 return -2;
11336 }
11337
11338 if (strcasecmp(security, "wpa2-psk") == 0) {
11339 keymgmt = "WPA2PSK";
11340 cipher = "CCMP";
11341 } else {
11342 wpa_ctrl_detach(ctrl);
11343 wpa_ctrl_close(ctrl);
11344 send_resp(dut, conn, SIGMA_ERROR,
11345 "ErrorCode,Unsupported Security value");
11346 return 0;
11347 }
11348
11349 ascii2hexstr(ssid, ssid_hex);
11350 ascii2hexstr(passphrase, passphrase_hex);
11351 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
11352 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
11353
11354 if (wpa_command(intf, buf) < 0) {
11355 wpa_ctrl_detach(ctrl);
11356 wpa_ctrl_close(ctrl);
11357 send_resp(dut, conn, SIGMA_ERROR,
11358 "ErrorCode,Failed to start registrar");
11359 return 0;
11360 }
11361
11362 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
11363 dut->er_oper_performed = 1;
11364
11365 return wps_connection_event(dut, conn, ctrl, intf, 0);
11366}
11367
11368
11369static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
11370 struct sigma_conn *conn,
11371 struct sigma_cmd *cmd)
11372{
11373 struct wpa_ctrl *ctrl;
11374 const char *intf = get_param(cmd, "Interface");
11375 const char *bssid = get_param(cmd, "Bssid");
11376 char buf[100];
11377
11378 if (!bssid) {
11379 send_resp(dut, conn, SIGMA_ERROR,
11380 "ErrorCode,Missing Bssid argument");
11381 return 0;
11382 }
11383
11384 ctrl = open_wpa_mon(intf);
11385 if (ctrl == NULL) {
11386 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11387 "wpa_supplicant monitor connection");
11388 return -2;
11389 }
11390
11391 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
11392
11393 if (wpa_command(intf, buf) < 0) {
11394 wpa_ctrl_detach(ctrl);
11395 wpa_ctrl_close(ctrl);
11396 send_resp(dut, conn, SIGMA_ERROR,
11397 "ErrorCode,Failed to start registrar");
11398 return 0;
11399 }
11400
11401 return wps_connection_event(dut, conn, ctrl, intf, 0);
11402}
11403
11404
vamsi krishna9b144002017-09-20 13:28:13 +053011405static int cmd_start_wps_registration(struct sigma_dut *dut,
11406 struct sigma_conn *conn,
11407 struct sigma_cmd *cmd)
11408{
11409 struct wpa_ctrl *ctrl;
11410 const char *intf = get_param(cmd, "Interface");
11411 const char *role, *method;
11412 int res;
11413 char buf[256];
11414 const char *events[] = {
11415 "CTRL-EVENT-CONNECTED",
11416 "WPS-OVERLAP-DETECTED",
11417 "WPS-TIMEOUT",
11418 "WPS-FAIL",
11419 NULL
11420 };
11421
11422 ctrl = open_wpa_mon(intf);
11423 if (!ctrl) {
11424 sigma_dut_print(dut, DUT_MSG_ERROR,
11425 "Failed to open wpa_supplicant monitor connection");
11426 return -2;
11427 }
11428
11429 role = get_param(cmd, "WpsRole");
11430 if (!role) {
11431 send_resp(dut, conn, SIGMA_INVALID,
11432 "ErrorCode,WpsRole not provided");
11433 goto fail;
11434 }
11435
11436 if (strcasecmp(role, "Enrollee") == 0) {
11437 method = get_param(cmd, "WpsConfigMethod");
11438 if (!method) {
11439 send_resp(dut, conn, SIGMA_INVALID,
11440 "ErrorCode,WpsConfigMethod not provided");
11441 goto fail;
11442 }
11443 if (strcasecmp(method, "PBC") == 0) {
11444 if (wpa_command(intf, "WPS_PBC") < 0) {
11445 send_resp(dut, conn, SIGMA_ERROR,
11446 "ErrorCode,Failed to enable PBC");
11447 goto fail;
11448 }
11449 } else {
11450 /* TODO: PIN method */
11451 send_resp(dut, conn, SIGMA_ERROR,
11452 "ErrorCode,Unsupported WpsConfigMethod value");
11453 goto fail;
11454 }
11455 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11456 if (res < 0) {
11457 send_resp(dut, conn, SIGMA_ERROR,
11458 "ErrorCode,WPS connection did not complete");
11459 goto fail;
11460 }
11461 if (strstr(buf, "WPS-TIMEOUT")) {
11462 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
11463 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
11464 send_resp(dut, conn, SIGMA_ERROR,
11465 "ErrorCode,OverlapSession");
11466 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
11467 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
11468 } else {
11469 send_resp(dut, conn, SIGMA_ERROR,
11470 "ErrorCode,WPS operation failed");
11471 }
11472 } else {
11473 /* TODO: Registrar role */
11474 send_resp(dut, conn, SIGMA_ERROR,
11475 "ErrorCode,Unsupported WpsRole value");
11476 }
11477
11478fail:
11479 wpa_ctrl_detach(ctrl);
11480 wpa_ctrl_close(ctrl);
11481 return 0;
11482}
11483
11484
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011485static int req_intf(struct sigma_cmd *cmd)
11486{
11487 return get_param(cmd, "interface") == NULL ? -1 : 0;
11488}
11489
11490
11491void sta_register_cmds(void)
11492{
11493 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
11494 cmd_sta_get_ip_config);
11495 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
11496 cmd_sta_set_ip_config);
11497 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
11498 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
11499 cmd_sta_get_mac_address);
11500 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
11501 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
11502 cmd_sta_verify_ip_connection);
11503 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
11504 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
11505 cmd_sta_set_encryption);
11506 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
11507 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
11508 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
11509 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
11510 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
11511 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
11512 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
11513 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
11514 cmd_sta_set_eapakaprime);
11515 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
11516 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
11517 /* TODO: sta_set_ibss */
11518 /* TODO: sta_set_mode */
11519 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
11520 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
11521 /* TODO: sta_up_load */
11522 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
11523 cmd_sta_preset_testparameters);
11524 /* TODO: sta_set_system */
11525 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
11526 /* TODO: sta_set_rifs_test */
11527 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
11528 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
11529 /* TODO: sta_send_coexist_mgmt */
11530 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
11531 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
11532 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
11533 sigma_dut_reg_cmd("sta_reset_default", req_intf,
11534 cmd_sta_reset_default);
11535 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
11536 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
11537 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
11538 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
11539 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
11540 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
11541 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
11542 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
11543 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
11544 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011545 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
11546 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011547 sigma_dut_reg_cmd("sta_add_credential", req_intf,
11548 cmd_sta_add_credential);
11549 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011550 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011551 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
11552 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
11553 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
11554 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
11555 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
11556 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030011557 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011558 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
11559 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +053011560 sigma_dut_reg_cmd("start_wps_registration", req_intf,
11561 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011562}