blob: 8a82357481dc6b8fe6bf8228a93d8c6597d5494d [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) {
3978 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3979 if (wpa_command(get_station_ifname(),
3980 "P2P_SET ps 0") < 0)
3981 return -2;
3982 /* Make sure test modes are disabled */
3983 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3984 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3985 } else if (strcmp(val, "1") == 0 ||
3986 strcasecmp(val, "PSPoll") == 0 ||
3987 strcasecmp(val, "on") == 0) {
3988 /* Disable default power save mode */
3989 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3990 /* Enable PS-Poll test mode */
3991 if (wpa_command(get_station_ifname(),
3992 "P2P_SET ps 97") < 0 ||
3993 wpa_command(get_station_ifname(),
3994 "P2P_SET ps 99") < 0)
3995 return -2;
3996 } else if (strcmp(val, "2") == 0 ||
3997 strcasecmp(val, "Fast") == 0) {
3998 /* TODO */
3999 send_resp(dut, conn, SIGMA_ERROR,
4000 "ErrorCode,Powersave=Fast not supported");
4001 return 0;
4002 } else if (strcmp(val, "3") == 0 ||
4003 strcasecmp(val, "PSNonPoll") == 0) {
4004 /* Make sure test modes are disabled */
4005 wpa_command(get_station_ifname(), "P2P_SET ps 98");
4006 wpa_command(get_station_ifname(), "P2P_SET ps 96");
4007
4008 /* Enable default power save mode */
4009 if (wpa_command(get_station_ifname(),
4010 "P2P_SET ps 1") < 0)
4011 return -2;
4012 } else
4013 return -1;
4014 }
4015
4016 val = get_param(cmd, "NoAck");
4017 if (val) {
4018 switch (get_driver_type()) {
4019 case DRIVER_ATHEROS:
4020 ath_sta_set_noack(dut, intf, val);
4021 break;
Amarnath Hullur Subramanyamae8a2d92018-03-01 06:32:21 -08004022#ifdef NL80211_SUPPORT
4023 case DRIVER_WCN:
4024 wcn_sta_set_noack(dut, intf, val);
4025 break;
4026#endif /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004027 default:
4028 send_resp(dut, conn, SIGMA_ERROR,
4029 "ErrorCode,Setting NoAck not supported");
4030 return 0;
4031 }
4032 }
4033
4034 val = get_param(cmd, "IgnoreChswitchProhibit");
4035 if (val) {
4036 /* TODO: Enabled/disabled */
4037 if (strcasecmp(val, "Enabled") == 0) {
4038 send_resp(dut, conn, SIGMA_ERROR,
4039 "ErrorCode,Enabling IgnoreChswitchProhibit "
4040 "not supported");
4041 return 0;
4042 }
4043 }
4044
4045 val = get_param(cmd, "TDLS");
4046 if (val) {
4047 if (strcasecmp(val, "Disabled") == 0) {
4048 if (wpa_command(intf, "SET tdls_disabled 1")) {
4049 send_resp(dut, conn, SIGMA_ERROR,
4050 "ErrorCode,Failed to disable TDLS");
4051 return 0;
4052 }
4053 } else if (strcasecmp(val, "Enabled") == 0) {
4054 if (wpa_command(intf, "SET tdls_disabled 0")) {
4055 send_resp(dut, conn, SIGMA_ERROR,
4056 "ErrorCode,Failed to enable TDLS");
4057 return 0;
4058 }
4059 } else {
4060 send_resp(dut, conn, SIGMA_ERROR,
4061 "ErrorCode,Unsupported TDLS value");
4062 return 0;
4063 }
4064 }
4065
4066 val = get_param(cmd, "TDLSmode");
4067 if (val) {
4068 if (strcasecmp(val, "Default") == 0) {
4069 wpa_command(intf, "SET tdls_testing 0");
4070 } else if (strcasecmp(val, "APProhibit") == 0) {
4071 if (wpa_command(intf, "SET tdls_testing 0x400")) {
4072 send_resp(dut, conn, SIGMA_ERROR,
4073 "ErrorCode,Failed to enable ignore "
4074 "APProhibit TDLS mode");
4075 return 0;
4076 }
4077 } else if (strcasecmp(val, "HiLoMac") == 0) {
4078 /* STA should respond with TDLS setup req for a TDLS
4079 * setup req */
4080 if (wpa_command(intf, "SET tdls_testing 0x80")) {
4081 send_resp(dut, conn, SIGMA_ERROR,
4082 "ErrorCode,Failed to enable HiLoMac "
4083 "TDLS mode");
4084 return 0;
4085 }
4086 } else if (strcasecmp(val, "WeakSecurity") == 0) {
4087 /*
4088 * Since all security modes are enabled by default when
4089 * Sigma control is used, there is no need to do
4090 * anything here.
4091 */
4092 } else if (strcasecmp(val, "ExistLink") == 0) {
4093 /*
4094 * Since we allow new TDLS Setup Request even if there
4095 * is an existing link, nothing needs to be done for
4096 * this.
4097 */
4098 } else {
4099 /* TODO:
4100 * ExistLink: STA should send TDLS setup req even if
4101 * direct link already exists
4102 */
4103 send_resp(dut, conn, SIGMA_ERROR,
4104 "ErrorCode,Unsupported TDLSmode value");
4105 return 0;
4106 }
4107 }
4108
4109 val = get_param(cmd, "FakePubKey");
4110 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
4111 send_resp(dut, conn, SIGMA_ERROR,
4112 "ErrorCode,Failed to enable FakePubKey");
4113 return 0;
4114 }
4115
Amarnath Hullur Subramanyamae1042b2018-02-22 21:52:52 -08004116#ifdef NL80211_SUPPORT
4117 val = get_param(cmd, "FrgmntSupport");
4118 if (val) {
4119 if (strcasecmp(val, "Enable") == 0) {
4120 if (sta_set_he_fragmentation(dut, intf,
4121 HE_FRAG_LEVEL1)) {
4122 send_resp(dut, conn, SIGMA_ERROR,
4123 "ErrorCode,Failed to enable HE Fragmentation");
4124 return 0;
4125 }
4126 } else if (strcasecmp(val, "Disable") == 0) {
4127 if (sta_set_he_fragmentation(dut, intf,
4128 HE_FRAG_DISABLE)) {
4129 send_resp(dut, conn, SIGMA_ERROR,
4130 "ErrorCode,Failed to disable HE Fragmentation");
4131 return 0;
4132 }
4133 }
4134 }
4135#endif /* NL80211_SUPPORT */
4136
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004137 return 1;
4138}
4139
4140
4141static const char * ath_get_radio_name(const char *radio_name)
4142{
4143 if (radio_name == NULL)
4144 return "wifi0";
4145 if (strcmp(radio_name, "wifi1") == 0)
4146 return "wifi1";
4147 if (strcmp(radio_name, "wifi2") == 0)
4148 return "wifi2";
4149 return "wifi0";
4150}
4151
4152
4153static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
4154 const char *val)
4155{
4156 char buf[60];
4157 unsigned int vht_mcsmap = 0;
4158 int txchainmask = 0;
4159 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4160
4161 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4162 if (dut->testbed_flag_txsp == 1) {
4163 vht_mcsmap = 0xfffc;
4164 dut->testbed_flag_txsp = 0;
4165 } else {
4166 vht_mcsmap = 0xfffe;
4167 }
4168 txchainmask = 1;
4169 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4170 if (dut->testbed_flag_txsp == 1) {
4171 vht_mcsmap = 0xfff0;
4172 dut->testbed_flag_txsp = 0;
4173 } else {
4174 vht_mcsmap = 0xfffa;
4175 }
4176 txchainmask = 3;
4177 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4178 if (dut->testbed_flag_txsp == 1) {
4179 vht_mcsmap = 0xffc0;
4180 dut->testbed_flag_txsp = 0;
4181 } else {
4182 vht_mcsmap = 0xffea;
4183 }
4184 txchainmask = 7;
4185 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4186 if (dut->testbed_flag_txsp == 1) {
4187 vht_mcsmap = 0xff00;
4188 dut->testbed_flag_txsp = 0;
4189 } else {
4190 vht_mcsmap = 0xffaa;
4191 }
4192 txchainmask = 15;
4193 } else {
4194 if (dut->testbed_flag_txsp == 1) {
4195 vht_mcsmap = 0xffc0;
4196 dut->testbed_flag_txsp = 0;
4197 } else {
4198 vht_mcsmap = 0xffea;
4199 }
4200 }
4201
4202 if (txchainmask) {
4203 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4204 basedev, txchainmask);
4205 if (system(buf) != 0) {
4206 sigma_dut_print(dut, DUT_MSG_ERROR,
4207 "iwpriv txchainmask failed");
4208 }
4209 }
4210
4211 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4212 intf, vht_mcsmap);
4213 if (system(buf) != 0) {
4214 sigma_dut_print(dut, DUT_MSG_ERROR,
4215 "iwpriv %s vht_mcsmap 0x%04x failed",
4216 intf, vht_mcsmap);
4217 }
4218}
4219
4220
4221static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
4222 const char *val)
4223{
4224 char buf[60];
4225 unsigned int vht_mcsmap = 0;
4226 int rxchainmask = 0;
4227 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
4228
4229 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
4230 if (dut->testbed_flag_rxsp == 1) {
4231 vht_mcsmap = 0xfffc;
4232 dut->testbed_flag_rxsp = 0;
4233 } else {
4234 vht_mcsmap = 0xfffe;
4235 }
4236 rxchainmask = 1;
4237 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
4238 if (dut->testbed_flag_rxsp == 1) {
4239 vht_mcsmap = 0xfff0;
4240 dut->testbed_flag_rxsp = 0;
4241 } else {
4242 vht_mcsmap = 0xfffa;
4243 }
4244 rxchainmask = 3;
4245 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
4246 if (dut->testbed_flag_rxsp == 1) {
4247 vht_mcsmap = 0xffc0;
4248 dut->testbed_flag_rxsp = 0;
4249 } else {
4250 vht_mcsmap = 0xffea;
4251 }
4252 rxchainmask = 7;
4253 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
4254 if (dut->testbed_flag_rxsp == 1) {
4255 vht_mcsmap = 0xff00;
4256 dut->testbed_flag_rxsp = 0;
4257 } else {
4258 vht_mcsmap = 0xffaa;
4259 }
4260 rxchainmask = 15;
4261 } else {
4262 if (dut->testbed_flag_rxsp == 1) {
4263 vht_mcsmap = 0xffc0;
4264 dut->testbed_flag_rxsp = 0;
4265 } else {
4266 vht_mcsmap = 0xffea;
4267 }
4268 }
4269
4270 if (rxchainmask) {
4271 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4272 basedev, rxchainmask);
4273 if (system(buf) != 0) {
4274 sigma_dut_print(dut, DUT_MSG_ERROR,
4275 "iwpriv rxchainmask failed");
4276 }
4277 }
4278
4279 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
4280 intf, vht_mcsmap);
4281 if (system(buf) != 0) {
4282 sigma_dut_print(dut, DUT_MSG_ERROR,
4283 "iwpriv %s vht_mcsmap 0x%04x",
4284 intf, vht_mcsmap);
4285 }
4286}
4287
4288
4289void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
4290{
4291 if (strcasecmp(val, "enable") == 0) {
4292 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
4293 != 0) {
4294 sigma_dut_print(dut, DUT_MSG_ERROR,
4295 "Disable BB_VHTSIGB_CRC_CALC failed");
4296 }
4297
4298 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
4299 != 0) {
4300 sigma_dut_print(dut, DUT_MSG_ERROR,
4301 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4302 }
4303 } else {
4304 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
4305 != 0) {
4306 sigma_dut_print(dut, DUT_MSG_ERROR,
4307 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
4308 }
4309
4310 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
4311 != 0) {
4312 sigma_dut_print(dut, DUT_MSG_ERROR,
4313 "Enable BB_VHTSIGB_CRC_CALC failed");
4314 }
4315 }
4316}
4317
4318
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004319static int wcn_sta_set_width(struct sigma_dut *dut, const char *intf,
4320 const char *val)
4321{
4322 char buf[60];
4323
4324 if (strcmp(val, "20") == 0) {
4325 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4326 dut->chwidth = 0;
4327 } else if (strcmp(val, "40") == 0) {
4328 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
4329 dut->chwidth = 1;
4330 } else if (strcmp(val, "80") == 0) {
4331 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4332 dut->chwidth = 2;
Sunil Duttb1cccac2018-05-22 21:03:12 +05304333 } else if (strcasecmp(val, "Auto") == 0) {
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004334 buf[0] = '\0';
4335 } else {
4336 sigma_dut_print(dut, DUT_MSG_ERROR, "WIDTH %s not supported",
4337 val);
4338 return -1;
4339 }
4340
4341 if (buf[0] != '\0' && system(buf) != 0) {
4342 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
4343 return -1;
4344 }
4345
4346 return 0;
4347}
4348
4349
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004350static int nlvendor_sta_set_addba_reject(struct sigma_dut *dut,
4351 const char *intf, int addbareject)
4352{
4353#ifdef NL80211_SUPPORT
4354 struct nl_msg *msg;
4355 int ret = 0;
4356 struct nlattr *params;
4357 int ifindex;
4358
4359 ifindex = if_nametoindex(intf);
4360 if (ifindex == 0) {
4361 sigma_dut_print(dut, DUT_MSG_ERROR,
4362 "%s: Index for interface %s failed",
4363 __func__, intf);
4364 return -1;
4365 }
4366
4367 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4368 NL80211_CMD_VENDOR)) ||
4369 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4370 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4371 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4372 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4373 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4374 nla_put_u8(msg,
4375 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ACCEPT_ADDBA_REQ,
4376 !addbareject)) {
4377 sigma_dut_print(dut, DUT_MSG_ERROR,
4378 "%s: err in adding vendor_cmd and vendor_data",
4379 __func__);
4380 nlmsg_free(msg);
4381 return -1;
4382 }
4383 nla_nest_end(msg, params);
4384
4385 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4386 if (ret) {
4387 sigma_dut_print(dut, DUT_MSG_ERROR,
4388 "%s: err in send_and_recv_msgs, ret=%d",
4389 __func__, ret);
4390 }
4391 return ret;
4392#else /* NL80211_SUPPORT */
4393 sigma_dut_print(dut, DUT_MSG_ERROR,
4394 "ADDBA_REJECT cannot be set without NL80211_SUPPORT defined");
4395 return -1;
4396#endif /* NL80211_SUPPORT */
4397}
4398
4399
4400static int sta_set_addba_reject(struct sigma_dut *dut, const char *intf,
4401 int addbareject)
4402{
4403 int ret;
4404
4405 switch (get_driver_type()) {
4406 case DRIVER_WCN:
4407 ret = nlvendor_sta_set_addba_reject(dut, intf, addbareject);
4408 if (ret) {
4409 sigma_dut_print(dut, DUT_MSG_ERROR,
4410 "nlvendor_sta_set_addba_reject failed, ret:%d",
4411 ret);
4412 return ret;
4413 }
4414 break;
4415 default:
4416 sigma_dut_print(dut, DUT_MSG_ERROR,
4417 "errorCode,Unsupported ADDBA_REJECT with the current driver");
4418 ret = -1;
4419 break;
4420 }
4421
4422 return ret;
4423}
4424
4425
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004426static int nlvendor_config_send_addba(struct sigma_dut *dut, const char *intf,
4427 int enable)
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004428{
4429#ifdef NL80211_SUPPORT
4430 struct nl_msg *msg;
4431 int ret = 0;
4432 struct nlattr *params;
4433 int ifindex;
4434
4435 ifindex = if_nametoindex(intf);
4436 if (ifindex == 0) {
4437 sigma_dut_print(dut, DUT_MSG_ERROR,
4438 "%s: Index for interface %s failed",
4439 __func__, intf);
4440 return -1;
4441 }
4442
4443 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
4444 NL80211_CMD_VENDOR)) ||
4445 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
4446 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
4447 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
4448 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
4449 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
4450 nla_put_u8(msg,
4451 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_SEND_ADDBA_REQ,
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004452 enable)) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004453 sigma_dut_print(dut, DUT_MSG_ERROR,
4454 "%s: err in adding vendor_cmd and vendor_data",
4455 __func__);
4456 nlmsg_free(msg);
4457 return -1;
4458 }
4459 nla_nest_end(msg, params);
4460
4461 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
4462 if (ret) {
4463 sigma_dut_print(dut, DUT_MSG_ERROR,
4464 "%s: err in send_and_recv_msgs, ret=%d",
4465 __func__, ret);
4466 }
4467 return ret;
4468#else /* NL80211_SUPPORT */
4469 sigma_dut_print(dut, DUT_MSG_ERROR,
4470 "Disable addba not possible without NL80211_SUPPORT defined");
4471 return -1;
4472#endif /* NL80211_SUPPORT */
4473}
4474
4475
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004476static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
4477 struct sigma_conn *conn,
4478 struct sigma_cmd *cmd)
4479{
4480 const char *val;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004481 int ampdu = -1, addbareject = -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004482 char buf[30];
4483
4484 val = get_param(cmd, "40_INTOLERANT");
4485 if (val) {
4486 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4487 /* TODO: iwpriv ht40intol through wpa_supplicant */
4488 send_resp(dut, conn, SIGMA_ERROR,
4489 "ErrorCode,40_INTOLERANT not supported");
4490 return 0;
4491 }
4492 }
4493
4494 val = get_param(cmd, "ADDBA_REJECT");
4495 if (val) {
4496 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4497 /* reject any ADDBA with status "decline" */
4498 ampdu = 0;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004499 addbareject = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004500 } else {
4501 /* accept ADDBA */
4502 ampdu = 1;
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004503 addbareject = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004504 }
4505 }
4506
Amarnath Hullur Subramanyamd8a9db92018-02-02 18:53:14 -08004507 if (addbareject >= 0 &&
4508 sta_set_addba_reject(dut, intf, addbareject) < 0) {
4509 send_resp(dut, conn, SIGMA_ERROR,
4510 "ErrorCode,set addba_reject failed");
4511 return 0;
4512 }
4513
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004514 val = get_param(cmd, "AMPDU");
4515 if (val) {
4516 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4517 /* enable AMPDU Aggregation */
4518 if (ampdu == 0) {
4519 send_resp(dut, conn, SIGMA_ERROR,
4520 "ErrorCode,Mismatch in "
4521 "addba_reject/ampdu - "
4522 "not supported");
4523 return 0;
4524 }
4525 ampdu = 1;
4526 } else {
4527 /* disable AMPDU Aggregation */
4528 if (ampdu == 1) {
4529 send_resp(dut, conn, SIGMA_ERROR,
4530 "ErrorCode,Mismatch in "
4531 "addba_reject/ampdu - "
4532 "not supported");
4533 return 0;
4534 }
4535 ampdu = 0;
4536 }
4537 }
4538
4539 if (ampdu >= 0) {
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004540 int ret;
4541
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004542 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
4543 ampdu ? "Enabling" : "Disabling");
4544 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07004545 if (wpa_command(intf, buf) < 0 &&
4546 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004547 send_resp(dut, conn, SIGMA_ERROR,
4548 "ErrorCode,set aggr failed");
4549 return 0;
4550 }
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004551
4552 if (ampdu == 0) {
4553 /* Disable sending of addba using nl vendor command */
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08004554 ret = nlvendor_config_send_addba(dut, intf, 0);
Amarnath Hullur Subramanyam9745b3c2018-02-04 21:27:57 -08004555 if (ret) {
4556 sigma_dut_print(dut, DUT_MSG_ERROR,
4557 "Failed to disable addba, ret:%d",
4558 ret);
4559 }
4560 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004561 }
4562
4563 val = get_param(cmd, "AMSDU");
4564 if (val) {
4565 switch (get_driver_type()) {
4566 case DRIVER_ATHEROS:
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08004567 case DRIVER_WCN:
4568 iwpriv_sta_set_amsdu(dut, intf, val);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004569 break;
4570 default:
4571 if (strcmp(val, "1") == 0 ||
4572 strcasecmp(val, "Enable") == 0) {
4573 /* Enable AMSDU Aggregation */
4574 send_resp(dut, conn, SIGMA_ERROR,
4575 "ErrorCode,AMSDU aggregation not supported");
4576 return 0;
4577 }
4578 break;
4579 }
4580 }
4581
4582 val = get_param(cmd, "STBC_RX");
4583 if (val) {
4584 switch (get_driver_type()) {
4585 case DRIVER_ATHEROS:
4586 ath_sta_set_stbc(dut, intf, val);
4587 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05304588 case DRIVER_WCN:
4589 wcn_sta_set_stbc(dut, intf, val);
4590 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004591 default:
4592 send_resp(dut, conn, SIGMA_ERROR,
4593 "ErrorCode,STBC_RX not supported");
4594 return 0;
4595 }
4596 }
4597
4598 val = get_param(cmd, "WIDTH");
4599 if (val) {
4600 switch (get_driver_type()) {
4601 case DRIVER_WCN:
Amarnath Hullur Subramanyamebfe6b62018-01-31 03:04:17 -08004602 if (wcn_sta_set_width(dut, intf, val) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004603 send_resp(dut, conn, SIGMA_ERROR,
4604 "ErrorCode,Failed to set WIDTH");
4605 return 0;
4606 }
4607 break;
4608 case DRIVER_ATHEROS:
4609 if (ath_set_width(dut, conn, intf, val) < 0)
4610 return 0;
4611 break;
4612 default:
4613 sigma_dut_print(dut, DUT_MSG_ERROR,
4614 "Setting WIDTH not supported");
4615 break;
4616 }
4617 }
4618
4619 val = get_param(cmd, "SMPS");
4620 if (val) {
4621 /* TODO: Dynamic/0, Static/1, No Limit/2 */
4622 send_resp(dut, conn, SIGMA_ERROR,
4623 "ErrorCode,SMPS not supported");
4624 return 0;
4625 }
4626
4627 val = get_param(cmd, "TXSP_STREAM");
4628 if (val) {
4629 switch (get_driver_type()) {
4630 case DRIVER_WCN:
4631 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4632 send_resp(dut, conn, SIGMA_ERROR,
4633 "ErrorCode,Failed to set TXSP_STREAM");
4634 return 0;
4635 }
4636 break;
4637 case DRIVER_ATHEROS:
4638 ath_sta_set_txsp_stream(dut, intf, val);
4639 break;
4640 default:
4641 sigma_dut_print(dut, DUT_MSG_ERROR,
4642 "Setting TXSP_STREAM not supported");
4643 break;
4644 }
4645 }
4646
4647 val = get_param(cmd, "RXSP_STREAM");
4648 if (val) {
4649 switch (get_driver_type()) {
4650 case DRIVER_WCN:
4651 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
4652 send_resp(dut, conn, SIGMA_ERROR,
4653 "ErrorCode,Failed to set RXSP_STREAM");
4654 return 0;
4655 }
4656 break;
4657 case DRIVER_ATHEROS:
4658 ath_sta_set_rxsp_stream(dut, intf, val);
4659 break;
4660 default:
4661 sigma_dut_print(dut, DUT_MSG_ERROR,
4662 "Setting RXSP_STREAM not supported");
4663 break;
4664 }
4665 }
4666
4667 val = get_param(cmd, "DYN_BW_SGNL");
4668 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004669 switch (get_driver_type()) {
4670 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08004671 if (strcasecmp(val, "enable") == 0) {
4672 snprintf(buf, sizeof(buf),
4673 "iwpriv %s cwmenable 1", intf);
4674 if (system(buf) != 0) {
4675 sigma_dut_print(dut, DUT_MSG_ERROR,
4676 "iwpriv cwmenable 1 failed");
4677 return 0;
4678 }
4679 } else if (strcasecmp(val, "disable") == 0) {
4680 snprintf(buf, sizeof(buf),
4681 "iwpriv %s cwmenable 0", intf);
4682 if (system(buf) != 0) {
4683 sigma_dut_print(dut, DUT_MSG_ERROR,
4684 "iwpriv cwmenable 0 failed");
4685 return 0;
4686 }
4687 } else {
4688 sigma_dut_print(dut, DUT_MSG_ERROR,
4689 "Unsupported DYN_BW_SGL");
4690 }
4691
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004692 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
4693 if (system(buf) != 0) {
4694 sigma_dut_print(dut, DUT_MSG_ERROR,
4695 "Failed to set cts_cbw in DYN_BW_SGNL");
4696 return 0;
4697 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004698 break;
4699 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004700 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08004701 ath_config_dyn_bw_sig(dut, intf, val);
4702 break;
4703 default:
4704 sigma_dut_print(dut, DUT_MSG_ERROR,
4705 "Failed to set DYN_BW_SGNL");
4706 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004707 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004708 }
4709
4710 val = get_param(cmd, "RTS_FORCE");
4711 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004712 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004713 if (strcasecmp(val, "Enable") == 0) {
4714 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004715 if (system(buf) != 0) {
4716 sigma_dut_print(dut, DUT_MSG_ERROR,
4717 "Failed to set RTS_FORCE 64");
4718 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08004719 snprintf(buf, sizeof(buf),
4720 "wifitool %s beeliner_fw_test 100 1", intf);
4721 if (system(buf) != 0) {
4722 sigma_dut_print(dut, DUT_MSG_ERROR,
4723 "wifitool beeliner_fw_test 100 1 failed");
4724 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004725 } else if (strcasecmp(val, "Disable") == 0) {
4726 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
4727 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02004728 if (system(buf) != 0) {
4729 sigma_dut_print(dut, DUT_MSG_ERROR,
4730 "Failed to set RTS_FORCE 2347");
4731 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004732 } else {
4733 send_resp(dut, conn, SIGMA_ERROR,
4734 "ErrorCode,RTS_FORCE value not supported");
4735 return 0;
4736 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004737 }
4738
4739 val = get_param(cmd, "CTS_WIDTH");
4740 if (val) {
4741 switch (get_driver_type()) {
4742 case DRIVER_WCN:
4743 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
4744 send_resp(dut, conn, SIGMA_ERROR,
4745 "ErrorCode,Failed to set CTS_WIDTH");
4746 return 0;
4747 }
4748 break;
4749 case DRIVER_ATHEROS:
4750 ath_set_cts_width(dut, intf, val);
4751 break;
4752 default:
4753 sigma_dut_print(dut, DUT_MSG_ERROR,
4754 "Setting CTS_WIDTH not supported");
4755 break;
4756 }
4757 }
4758
4759 val = get_param(cmd, "BW_SGNL");
4760 if (val) {
4761 if (strcasecmp(val, "Enable") == 0) {
4762 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
4763 intf);
4764 } else if (strcasecmp(val, "Disable") == 0) {
4765 /* TODO: Disable */
4766 buf[0] = '\0';
4767 } else {
4768 send_resp(dut, conn, SIGMA_ERROR,
4769 "ErrorCode,BW_SGNL value not supported");
4770 return 0;
4771 }
4772
4773 if (buf[0] != '\0' && system(buf) != 0) {
4774 sigma_dut_print(dut, DUT_MSG_ERROR,
4775 "Failed to set BW_SGNL");
4776 }
4777 }
4778
4779 val = get_param(cmd, "Band");
4780 if (val) {
4781 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
4782 /* STA supports all bands by default */
4783 } else {
4784 send_resp(dut, conn, SIGMA_ERROR,
4785 "ErrorCode,Unsupported Band");
4786 return 0;
4787 }
4788 }
4789
4790 val = get_param(cmd, "zero_crc");
4791 if (val) {
4792 switch (get_driver_type()) {
4793 case DRIVER_ATHEROS:
4794 ath_set_zero_crc(dut, val);
4795 break;
4796 default:
4797 break;
4798 }
4799 }
4800
4801 return 1;
4802}
4803
4804
4805static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
4806 struct sigma_cmd *cmd)
4807{
4808 const char *val;
4809 char buf[100];
4810
4811 val = get_param(cmd, "MSDUSize");
4812 if (val) {
4813 int mtu;
4814
4815 dut->amsdu_size = atoi(val);
4816 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
4817 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
4818 sigma_dut_print(dut, DUT_MSG_ERROR,
4819 "MSDUSize %d is above max %d or below min %d",
4820 dut->amsdu_size,
4821 IEEE80211_MAX_DATA_LEN_DMG,
4822 IEEE80211_SNAP_LEN_DMG);
4823 dut->amsdu_size = 0;
4824 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4825 }
4826
4827 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
4828 sigma_dut_print(dut, DUT_MSG_DEBUG,
4829 "Setting amsdu_size to %d", mtu);
4830 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
4831 get_station_ifname(), mtu);
4832
4833 if (system(buf) != 0) {
4834 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
4835 buf);
4836 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4837 }
4838 }
4839
4840 val = get_param(cmd, "BAckRcvBuf");
4841 if (val) {
4842 dut->back_rcv_buf = atoi(val);
4843 if (dut->back_rcv_buf == 0) {
4844 sigma_dut_print(dut, DUT_MSG_ERROR,
4845 "Failed to convert %s or value is 0",
4846 val);
4847 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4848 }
4849
4850 sigma_dut_print(dut, DUT_MSG_DEBUG,
4851 "Setting BAckRcvBuf to %s", val);
4852 }
4853
4854 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4855}
4856
4857
4858static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
4859 struct sigma_cmd *cmd)
4860{
4861 int net_id;
4862 char *ifname;
4863 const char *val;
4864 char buf[100];
4865
4866 dut->mode = SIGMA_MODE_STATION;
4867 ifname = get_main_ifname();
4868 if (wpa_command(ifname, "PING") != 0) {
4869 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
4870 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4871 }
4872
4873 wpa_command(ifname, "FLUSH");
4874 net_id = add_network_common(dut, conn, ifname, cmd);
4875 if (net_id < 0) {
4876 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
4877 return net_id;
4878 }
4879
4880 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
4881 if (set_network(ifname, net_id, "mode", "2") < 0) {
4882 sigma_dut_print(dut, DUT_MSG_ERROR,
4883 "Failed to set supplicant network mode");
4884 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4885 }
4886
4887 sigma_dut_print(dut, DUT_MSG_DEBUG,
Alexei Avshalom Lazarfd9f1352018-11-13 14:07:58 +02004888 "Supplicant set network with mode 2. network_id %d",
4889 net_id);
4890
4891 if (set_network(ifname, net_id, "wps_disabled", "0") < 0) {
4892 sigma_dut_print(dut, DUT_MSG_INFO,
4893 "Failed to set supplicant to WPS ENABLE");
4894 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4895 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004896
4897 val = get_param(cmd, "Security");
4898 if (val && strcasecmp(val, "OPEN") == 0) {
4899 dut->ap_key_mgmt = AP_OPEN;
4900 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
4901 sigma_dut_print(dut, DUT_MSG_ERROR,
4902 "Failed to set supplicant to %s security",
4903 val);
4904 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4905 }
4906 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
4907 dut->ap_key_mgmt = AP_WPA2_PSK;
4908 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
4909 sigma_dut_print(dut, DUT_MSG_ERROR,
4910 "Failed to set supplicant to %s security",
4911 val);
4912 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4913 }
4914
4915 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
4916 sigma_dut_print(dut, DUT_MSG_ERROR,
4917 "Failed to set supplicant to proto RSN");
4918 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4919 }
4920 } else if (val) {
4921 sigma_dut_print(dut, DUT_MSG_ERROR,
4922 "Requested Security %s is not supported on 60GHz",
4923 val);
4924 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4925 }
4926
4927 val = get_param(cmd, "Encrypt");
4928 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4929 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4930 sigma_dut_print(dut, DUT_MSG_ERROR,
4931 "Failed to set supplicant to pairwise GCMP");
4932 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4933 }
4934 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4935 sigma_dut_print(dut, DUT_MSG_ERROR,
4936 "Failed to set supplicant to group GCMP");
4937 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4938 }
4939 } else if (val) {
4940 sigma_dut_print(dut, DUT_MSG_ERROR,
4941 "Requested Encrypt %s is not supported on 60 GHz",
4942 val);
4943 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4944 }
4945
4946 val = get_param(cmd, "PSK");
4947 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4948 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4949 val);
4950 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4951 }
4952
4953 /* Convert 60G channel to freq */
4954 switch (dut->ap_channel) {
4955 case 1:
4956 val = "58320";
4957 break;
4958 case 2:
4959 val = "60480";
4960 break;
4961 case 3:
4962 val = "62640";
4963 break;
4964 default:
4965 sigma_dut_print(dut, DUT_MSG_ERROR,
4966 "Failed to configure channel %d. Not supported",
4967 dut->ap_channel);
4968 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4969 }
4970
4971 if (set_network(ifname, net_id, "frequency", val) < 0) {
4972 sigma_dut_print(dut, DUT_MSG_ERROR,
4973 "Failed to set supplicant network frequency");
4974 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4975 }
4976
4977 sigma_dut_print(dut, DUT_MSG_DEBUG,
4978 "Supplicant set network with frequency");
4979
4980 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4981 if (wpa_command(ifname, buf) < 0) {
4982 sigma_dut_print(dut, DUT_MSG_INFO,
4983 "Failed to select network id %d on %s",
4984 net_id, ifname);
4985 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4986 }
4987
4988 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4989
4990 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4991}
4992
4993
Lior David67543f52017-01-03 19:04:22 +02004994static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4995{
4996 char buf[128], fname[128];
4997 FILE *f;
4998
4999 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
5000 sigma_dut_print(dut, DUT_MSG_ERROR,
5001 "failed to get wil6210 debugfs dir");
5002 return -1;
5003 }
5004
5005 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
5006 f = fopen(fname, "w");
5007 if (!f) {
5008 sigma_dut_print(dut, DUT_MSG_ERROR,
5009 "failed to open: %s", fname);
5010 return -1;
5011 }
5012
5013 fprintf(f, "%d\n", abft_len);
5014 fclose(f);
5015
5016 return 0;
5017}
5018
5019
5020static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
5021 int abft_len)
5022{
5023 switch (get_driver_type()) {
5024 case DRIVER_WIL6210:
5025 return wil6210_set_abft_len(dut, abft_len);
5026 default:
5027 sigma_dut_print(dut, DUT_MSG_ERROR,
5028 "set abft_len not supported");
5029 return -1;
5030 }
5031}
5032
5033
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005034static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
5035 struct sigma_cmd *cmd)
5036{
5037 const char *val;
Lior David67543f52017-01-03 19:04:22 +02005038 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005039
5040 if (dut->dev_role != DEVROLE_PCP) {
5041 send_resp(dut, conn, SIGMA_INVALID,
5042 "ErrorCode,Invalid DevRole");
5043 return 0;
5044 }
5045
5046 val = get_param(cmd, "SSID");
5047 if (val) {
5048 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
5049 send_resp(dut, conn, SIGMA_INVALID,
5050 "ErrorCode,Invalid SSID");
5051 return -1;
5052 }
5053
Peng Xub8fc5cc2017-05-10 17:27:28 -07005054 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005055 }
5056
5057 val = get_param(cmd, "CHANNEL");
5058 if (val) {
5059 const char *pos;
5060
5061 dut->ap_channel = atoi(val);
5062 pos = strchr(val, ';');
5063 if (pos) {
5064 pos++;
5065 dut->ap_channel_1 = atoi(pos);
5066 }
5067 }
5068
5069 switch (dut->ap_channel) {
5070 case 1:
5071 case 2:
5072 case 3:
5073 break;
5074 default:
5075 sigma_dut_print(dut, DUT_MSG_ERROR,
5076 "Channel %d is not supported", dut->ap_channel);
5077 send_resp(dut, conn, SIGMA_ERROR,
5078 "Requested channel is not supported");
5079 return -1;
5080 }
5081
5082 val = get_param(cmd, "BCNINT");
5083 if (val)
5084 dut->ap_bcnint = atoi(val);
5085
5086
5087 val = get_param(cmd, "ExtSchIE");
5088 if (val) {
5089 send_resp(dut, conn, SIGMA_ERROR,
5090 "ErrorCode,ExtSchIE is not supported yet");
5091 return -1;
5092 }
5093
5094 val = get_param(cmd, "AllocType");
5095 if (val) {
5096 send_resp(dut, conn, SIGMA_ERROR,
5097 "ErrorCode,AllocType is not supported yet");
5098 return -1;
5099 }
5100
5101 val = get_param(cmd, "PercentBI");
5102 if (val) {
5103 send_resp(dut, conn, SIGMA_ERROR,
5104 "ErrorCode,PercentBI is not supported yet");
5105 return -1;
5106 }
5107
5108 val = get_param(cmd, "CBAPOnly");
5109 if (val) {
5110 send_resp(dut, conn, SIGMA_ERROR,
5111 "ErrorCode,CBAPOnly is not supported yet");
5112 return -1;
5113 }
5114
5115 val = get_param(cmd, "AMPDU");
5116 if (val) {
5117 if (strcasecmp(val, "Enable") == 0)
5118 dut->ap_ampdu = 1;
5119 else if (strcasecmp(val, "Disable") == 0)
5120 dut->ap_ampdu = 2;
5121 else {
5122 send_resp(dut, conn, SIGMA_ERROR,
5123 "ErrorCode,AMPDU value is not Enable nor Disabled");
5124 return -1;
5125 }
5126 }
5127
5128 val = get_param(cmd, "AMSDU");
5129 if (val) {
5130 if (strcasecmp(val, "Enable") == 0)
5131 dut->ap_amsdu = 1;
5132 else if (strcasecmp(val, "Disable") == 0)
5133 dut->ap_amsdu = 2;
5134 }
5135
5136 val = get_param(cmd, "NumMSDU");
5137 if (val) {
5138 send_resp(dut, conn, SIGMA_ERROR,
5139 "ErrorCode, NumMSDU is not supported yet");
5140 return -1;
5141 }
5142
5143 val = get_param(cmd, "ABFTLRang");
5144 if (val) {
5145 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02005146 "ABFTLRang parameter %s", val);
5147 if (strcmp(val, "Gt1") == 0)
5148 abft_len = 2; /* 2 slots in this case */
5149 }
5150
5151 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
5152 send_resp(dut, conn, SIGMA_ERROR,
5153 "ErrorCode, Can't set ABFT length");
5154 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005155 }
5156
5157 if (sta_pcp_start(dut, conn, cmd) < 0) {
5158 send_resp(dut, conn, SIGMA_ERROR,
5159 "ErrorCode, Can't start PCP role");
5160 return -1;
5161 }
5162
5163 return sta_set_60g_common(dut, conn, cmd);
5164}
5165
5166
5167static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
5168 struct sigma_cmd *cmd)
5169{
5170 const char *val = get_param(cmd, "DiscoveryMode");
5171
5172 if (dut->dev_role != DEVROLE_STA) {
5173 send_resp(dut, conn, SIGMA_INVALID,
5174 "ErrorCode,Invalid DevRole");
5175 return 0;
5176 }
5177
5178 if (val) {
5179 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
5180 /* Ignore Discovery mode till Driver expose API. */
5181#if 0
5182 if (strcasecmp(val, "1") == 0) {
5183 send_resp(dut, conn, SIGMA_INVALID,
5184 "ErrorCode,DiscoveryMode 1 not supported");
5185 return 0;
5186 }
5187
5188 if (strcasecmp(val, "0") == 0) {
5189 /* OK */
5190 } else {
5191 send_resp(dut, conn, SIGMA_INVALID,
5192 "ErrorCode,DiscoveryMode not supported");
5193 return 0;
5194 }
5195#endif
5196 }
5197
5198 if (start_sta_mode(dut) != 0)
5199 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5200 return sta_set_60g_common(dut, conn, cmd);
5201}
5202
5203
5204static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
5205 struct sigma_cmd *cmd)
5206{
5207 const char *intf = get_param(cmd, "Interface");
Jouni Malinened77e672018-01-10 16:45:13 +02005208 const char *val = get_param(cmd, "maintain_profile");
vamsi krishnad605c422017-09-20 14:56:31 +05305209
Jouni Malinened77e672018-01-10 16:45:13 +02005210 if (dut->program == PROGRAM_OCE ||
Amarnath Hullur Subramanyamebeda9e2018-01-31 03:21:48 -08005211 dut->program == PROGRAM_HE ||
Jouni Malinened77e672018-01-10 16:45:13 +02005212 (val && atoi(val) == 1)) {
vamsi krishnad605c422017-09-20 14:56:31 +05305213 wpa_command(intf, "DISCONNECT");
5214 return 1;
5215 }
5216
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005217 disconnect_station(dut);
5218 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
5219 * due to cached results. */
5220 wpa_command(intf, "SET ignore_old_scan_res 1");
5221 wpa_command(intf, "BSS_FLUSH");
5222 return 1;
5223}
5224
5225
5226static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
5227 struct sigma_cmd *cmd)
5228{
5229 const char *intf = get_param(cmd, "Interface");
5230 const char *bssid = get_param(cmd, "bssid");
5231 const char *val = get_param(cmd, "CHANNEL");
5232 struct wpa_ctrl *ctrl;
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305233 char buf[1000];
Sunil Duttd30ce092018-01-11 23:56:29 +05305234 char result[32];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005235 int res;
5236 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05305237 int status = 0;
Sunil Duttd30ce092018-01-11 23:56:29 +05305238 int fastreassoc = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005239
5240 if (bssid == NULL) {
5241 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
5242 "argument");
5243 return 0;
5244 }
5245
5246 if (val)
5247 chan = atoi(val);
5248
5249 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
5250 /* The current network may be from sta_associate or
5251 * sta_hs2_associate
5252 */
5253 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
5254 0 ||
5255 set_network(intf, 0, "bssid", bssid) < 0)
5256 return -2;
5257 }
5258
5259 ctrl = open_wpa_mon(intf);
5260 if (ctrl == NULL) {
5261 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5262 "wpa_supplicant monitor connection");
5263 return -1;
5264 }
5265
Sunil Duttd30ce092018-01-11 23:56:29 +05305266 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5267 sizeof(result)) < 0 ||
5268 strncmp(result, "COMPLETED", 9) != 0) {
5269 sigma_dut_print(dut, DUT_MSG_DEBUG,
5270 "sta_reassoc: Not connected");
5271 fastreassoc = 0;
5272 }
5273
Srinivas Dasari0ebedb12018-02-14 17:03:51 +05305274 if (dut->rsne_override) {
5275#ifdef NL80211_SUPPORT
5276 if (get_driver_type() == DRIVER_WCN && dut->config_rsnie == 0) {
5277 sta_config_rsnie(dut, 1);
5278 dut->config_rsnie = 1;
5279 }
5280#endif /* NL80211_SUPPORT */
5281 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
5282 dut->rsne_override);
5283 if (wpa_command(intf, buf) < 0) {
5284 send_resp(dut, conn, SIGMA_ERROR,
5285 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
5286 return 0;
5287 }
5288 }
5289
Sunil Duttd30ce092018-01-11 23:56:29 +05305290 if (wifi_chip_type == DRIVER_WCN && fastreassoc) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005291#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305292 if (chan) {
5293 unsigned int freq;
5294
Alexei Avshalom Lazar093569f2018-11-13 14:08:17 +02005295 freq = channel_to_freq(dut, chan);
Ashwini Patil4c8158f2017-05-25 12:49:21 +05305296 if (!freq) {
5297 sigma_dut_print(dut, DUT_MSG_ERROR,
5298 "Invalid channel number provided: %d",
5299 chan);
5300 send_resp(dut, conn, SIGMA_INVALID,
5301 "ErrorCode,Invalid channel number");
5302 goto close_mon_conn;
5303 }
5304 res = snprintf(buf, sizeof(buf),
5305 "SCAN TYPE=ONLY freq=%d", freq);
5306 } else {
5307 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
5308 }
5309 if (res < 0 || res >= (int) sizeof(buf)) {
5310 send_resp(dut, conn, SIGMA_ERROR,
5311 "ErrorCode,snprintf failed");
5312 goto close_mon_conn;
5313 }
5314 if (wpa_command(intf, buf) < 0) {
5315 sigma_dut_print(dut, DUT_MSG_INFO,
5316 "Failed to start scan");
5317 send_resp(dut, conn, SIGMA_ERROR,
5318 "ErrorCode,scan failed");
5319 goto close_mon_conn;
5320 }
5321
5322 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5323 buf, sizeof(buf));
5324 if (res < 0) {
5325 sigma_dut_print(dut, DUT_MSG_INFO,
5326 "Scan did not complete");
5327 send_resp(dut, conn, SIGMA_ERROR,
5328 "ErrorCode,scan did not complete");
5329 goto close_mon_conn;
5330 }
5331
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005332 if (set_network(intf, dut->infra_network_id, "bssid", "any")
5333 < 0) {
5334 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
5335 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305336 status = -2;
5337 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005338 }
5339 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
5340 bssid, chan);
5341 if (res > 0 && res < (int) sizeof(buf))
5342 res = wpa_command(intf, buf);
5343
5344 if (res < 0 || res >= (int) sizeof(buf)) {
5345 send_resp(dut, conn, SIGMA_ERROR,
5346 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05305347 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005348 }
5349#else /* ANDROID */
5350 sigma_dut_print(dut, DUT_MSG_DEBUG,
5351 "Reassoc using iwpriv - skip chan=%d info",
5352 chan);
5353 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
5354 if (system(buf) != 0) {
5355 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05305356 status = -2;
5357 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005358 }
5359#endif /* ANDROID */
5360 sigma_dut_print(dut, DUT_MSG_INFO,
5361 "sta_reassoc: Run %s successful", buf);
5362 } else if (wpa_command(intf, "REASSOCIATE")) {
5363 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5364 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05305365 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005366 }
5367
5368 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
5369 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05305370 if (res < 0) {
5371 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
5372 status = -1;
5373 goto close_mon_conn;
5374 }
5375 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005376
Ashwini Patil467efef2017-05-25 12:18:27 +05305377close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005378 wpa_ctrl_detach(ctrl);
5379 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05305380 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005381}
5382
5383
5384static void hs2_clear_credentials(const char *intf)
5385{
5386 wpa_command(intf, "REMOVE_CRED all");
5387}
5388
5389
Lior Davidcc88b562017-01-03 18:52:09 +02005390#ifdef __linux__
5391static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
5392 unsigned int *aid)
5393{
Lior David0fe101e2017-03-09 16:09:50 +02005394 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02005395
Lior David0fe101e2017-03-09 16:09:50 +02005396 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02005397}
5398#endif /* __linux__ */
5399
5400
5401static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
5402 unsigned int *aid)
5403{
5404 switch (get_driver_type()) {
5405#ifdef __linux__
5406 case DRIVER_WIL6210:
5407 return wil6210_get_aid(dut, bssid, aid);
5408#endif /* __linux__ */
5409 default:
5410 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
5411 return -1;
5412 }
5413}
5414
5415
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005416static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5417 struct sigma_cmd *cmd)
5418{
5419 char buf[MAX_CMD_LEN];
5420 char bss_list[MAX_CMD_LEN];
5421 const char *parameter = get_param(cmd, "Parameter");
5422
5423 if (parameter == NULL)
5424 return -1;
5425
Lior Davidcc88b562017-01-03 18:52:09 +02005426 if (strcasecmp(parameter, "AID") == 0) {
5427 unsigned int aid = 0;
5428 char bssid[20];
5429
5430 if (get_wpa_status(get_station_ifname(), "bssid",
5431 bssid, sizeof(bssid)) < 0) {
5432 sigma_dut_print(dut, DUT_MSG_ERROR,
5433 "could not get bssid");
5434 return -2;
5435 }
5436
5437 if (sta_get_aid_60g(dut, bssid, &aid))
5438 return -2;
5439
5440 snprintf(buf, sizeof(buf), "aid,%d", aid);
5441 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
5442 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5443 return 0;
5444 }
5445
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005446 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
5447 char *bss_line;
5448 char *bss_id = NULL;
5449 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305450 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005451
5452 if (ifname == NULL) {
5453 sigma_dut_print(dut, DUT_MSG_INFO,
5454 "For get DiscoveredDevList need Interface name.");
5455 return -1;
5456 }
5457
5458 /*
5459 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
5460 * of BSSIDs in "bssid=<BSSID>\n"
5461 */
5462 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
5463 bss_list,
5464 sizeof(bss_list)) < 0) {
5465 sigma_dut_print(dut, DUT_MSG_ERROR,
5466 "Failed to get bss list");
5467 return -1;
5468 }
5469
5470 sigma_dut_print(dut, DUT_MSG_DEBUG,
5471 "bss list for ifname:%s is:%s",
5472 ifname, bss_list);
5473
5474 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305475 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005476 while (bss_line) {
5477 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
5478 bss_id) {
5479 int len;
5480
5481 len = snprintf(buf + strlen(buf),
5482 sizeof(buf) - strlen(buf),
5483 ",%s", bss_id);
5484 free(bss_id);
5485 bss_id = NULL;
5486 if (len < 0) {
5487 sigma_dut_print(dut,
5488 DUT_MSG_ERROR,
5489 "Failed to read BSSID");
5490 send_resp(dut, conn, SIGMA_ERROR,
5491 "ErrorCode,Failed to read BSS ID");
5492 return 0;
5493 }
5494
5495 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
5496 sigma_dut_print(dut,
5497 DUT_MSG_ERROR,
5498 "Response buf too small for list");
5499 send_resp(dut, conn,
5500 SIGMA_ERROR,
5501 "ErrorCode,Response buf too small for list");
5502 return 0;
5503 }
5504 }
5505
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305506 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005507 }
5508
5509 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
5510 buf);
5511 send_resp(dut, conn, SIGMA_COMPLETE, buf);
5512 return 0;
5513 }
5514
5515 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5516 return 0;
5517}
5518
5519
5520static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
5521 struct sigma_cmd *cmd)
5522{
5523 const char *program = get_param(cmd, "Program");
5524
5525 if (program == NULL)
5526 return -1;
5527
5528 if (strcasecmp(program, "P2PNFC") == 0)
5529 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
5530
5531 if (strcasecmp(program, "60ghz") == 0)
5532 return sta_get_parameter_60g(dut, conn, cmd);
5533
5534#ifdef ANDROID_NAN
5535 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07005536 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005537#endif /* ANDROID_NAN */
5538
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07005539#ifdef MIRACAST
5540 if (strcasecmp(program, "WFD") == 0 ||
5541 strcasecmp(program, "DisplayR2") == 0)
5542 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
5543#endif /* MIRACAST */
5544
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005545 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
5546 return 0;
5547}
5548
5549
5550static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
5551 const char *type)
5552{
5553 char buf[100];
5554
5555 if (dut->program == PROGRAM_VHT) {
5556 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
5557 if (system(buf) != 0) {
5558 sigma_dut_print(dut, DUT_MSG_ERROR,
5559 "iwpriv %s chwidth failed", intf);
5560 }
5561
5562 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
5563 if (system(buf) != 0) {
5564 sigma_dut_print(dut, DUT_MSG_ERROR,
5565 "iwpriv %s mode 11ACVHT80 failed",
5566 intf);
5567 }
5568
5569 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
5570 if (system(buf) != 0) {
5571 sigma_dut_print(dut, DUT_MSG_ERROR,
5572 "iwpriv %s vhtmcs -1 failed", intf);
5573 }
5574 }
5575
5576 if (dut->program == PROGRAM_HT) {
5577 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
5578 if (system(buf) != 0) {
5579 sigma_dut_print(dut, DUT_MSG_ERROR,
5580 "iwpriv %s chwidth failed", intf);
5581 }
5582
5583 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
5584 if (system(buf) != 0) {
5585 sigma_dut_print(dut, DUT_MSG_ERROR,
5586 "iwpriv %s mode 11naht40 failed",
5587 intf);
5588 }
5589
5590 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
5591 if (system(buf) != 0) {
5592 sigma_dut_print(dut, DUT_MSG_ERROR,
5593 "iwpriv set11NRates failed");
5594 }
5595 }
5596
5597 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
5598 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
5599 if (system(buf) != 0) {
5600 sigma_dut_print(dut, DUT_MSG_ERROR,
5601 "disabling powersave failed");
5602 }
5603
5604 /* Reset CTS width */
5605 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
5606 intf);
5607 if (system(buf) != 0) {
5608 sigma_dut_print(dut, DUT_MSG_ERROR,
5609 "wifitool %s beeliner_fw_test 54 0 failed",
5610 intf);
5611 }
5612
5613 /* Enable Dynamic Bandwidth signalling by default */
5614 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
5615 if (system(buf) != 0) {
5616 sigma_dut_print(dut, DUT_MSG_ERROR,
5617 "iwpriv %s cwmenable 1 failed", intf);
5618 }
5619
5620 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
5621 if (system(buf) != 0) {
5622 sigma_dut_print(dut, DUT_MSG_ERROR,
5623 "iwpriv rts failed");
5624 }
5625 }
5626
5627 if (type && strcasecmp(type, "Testbed") == 0) {
5628 dut->testbed_flag_txsp = 1;
5629 dut->testbed_flag_rxsp = 1;
5630 /* STA has to set spatial stream to 2 per Appendix H */
5631 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
5632 if (system(buf) != 0) {
5633 sigma_dut_print(dut, DUT_MSG_ERROR,
5634 "iwpriv vht_mcsmap failed");
5635 }
5636
5637 /* Disable LDPC per Appendix H */
5638 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
5639 if (system(buf) != 0) {
5640 sigma_dut_print(dut, DUT_MSG_ERROR,
5641 "iwpriv %s ldpc 0 failed", intf);
5642 }
5643
5644 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
5645 if (system(buf) != 0) {
5646 sigma_dut_print(dut, DUT_MSG_ERROR,
5647 "iwpriv amsdu failed");
5648 }
5649
5650 /* TODO: Disable STBC 2x1 transmit and receive */
5651 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
5652 if (system(buf) != 0) {
5653 sigma_dut_print(dut, DUT_MSG_ERROR,
5654 "Disable tx_stbc 0 failed");
5655 }
5656
5657 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
5658 if (system(buf) != 0) {
5659 sigma_dut_print(dut, DUT_MSG_ERROR,
5660 "Disable rx_stbc 0 failed");
5661 }
5662
5663 /* STA has to disable Short GI per Appendix H */
5664 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
5665 if (system(buf) != 0) {
5666 sigma_dut_print(dut, DUT_MSG_ERROR,
5667 "iwpriv %s shortgi 0 failed", intf);
5668 }
5669 }
5670
5671 if (type && strcasecmp(type, "DUT") == 0) {
5672 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
5673 if (system(buf) != 0) {
5674 sigma_dut_print(dut, DUT_MSG_ERROR,
5675 "iwpriv %s nss 3 failed", intf);
5676 }
Arif Hussainac6c5112018-05-25 17:34:00 -07005677 dut->sta_nss = 3;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005678
5679 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
5680 if (system(buf) != 0) {
5681 sigma_dut_print(dut, DUT_MSG_ERROR,
5682 "iwpriv %s shortgi 1 failed", intf);
5683 }
5684 }
5685}
5686
5687
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08005688#ifdef NL80211_SUPPORT
5689static int sta_set_he_mcs(struct sigma_dut *dut, const char *intf,
5690 enum he_mcs_config mcs)
5691{
5692 struct nl_msg *msg;
5693 int ret = 0;
5694 struct nlattr *params;
5695 int ifindex;
5696
5697 ifindex = if_nametoindex(intf);
5698 if (ifindex == 0) {
5699 sigma_dut_print(dut, DUT_MSG_ERROR,
5700 "%s: Index for interface %s failed",
5701 __func__, intf);
5702 return -1;
5703 }
5704
5705 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5706 NL80211_CMD_VENDOR)) ||
5707 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5708 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5709 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5710 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5711 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5712 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MCS,
5713 mcs)) {
5714 sigma_dut_print(dut, DUT_MSG_ERROR,
5715 "%s: err in adding vendor_cmd and vendor_data",
5716 __func__);
5717 nlmsg_free(msg);
5718 return -1;
5719 }
5720 nla_nest_end(msg, params);
5721
5722 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5723 if (ret) {
5724 sigma_dut_print(dut, DUT_MSG_ERROR,
5725 "%s: err in send_and_recv_msgs, ret=%d",
5726 __func__, ret);
5727 }
5728 return ret;
5729}
5730#endif /* NL80211_SUPPORT */
5731
5732
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08005733static int sta_set_heconfig_and_wep_tkip(struct sigma_dut *dut,
5734 const char *intf, int enable)
5735{
5736#ifdef NL80211_SUPPORT
5737 struct nl_msg *msg;
5738 int ret = 0;
5739 struct nlattr *params;
5740 int ifindex;
5741
5742 ifindex = if_nametoindex(intf);
5743 if (ifindex == 0) {
5744 sigma_dut_print(dut, DUT_MSG_ERROR,
5745 "%s: Index for interface %s failed",
5746 __func__, intf);
5747 return -1;
5748 }
5749
5750 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5751 NL80211_CMD_VENDOR)) ||
5752 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5753 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5754 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5755 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5756 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5757 nla_put_u8(msg,
5758 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_WEP_TKIP_IN_HE,
5759 enable)) {
5760 sigma_dut_print(dut, DUT_MSG_ERROR,
5761 "%s: err in adding vendor_cmd and vendor_data",
5762 __func__);
5763 nlmsg_free(msg);
5764 return -1;
5765 }
5766 nla_nest_end(msg, params);
5767
5768 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5769 if (ret) {
5770 sigma_dut_print(dut, DUT_MSG_ERROR,
5771 "%s: err in send_and_recv_msgs, ret=%d",
5772 __func__, ret);
5773 }
5774 return ret;
5775#else /* NL80211_SUPPORT */
5776 sigma_dut_print(dut, DUT_MSG_ERROR,
5777 "HE config enablement cannot be changed without NL80211_SUPPORT defined");
5778 return -1;
5779#endif /* NL80211_SUPPORT */
5780}
5781
5782
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005783static int sta_set_addba_buf_size(struct sigma_dut *dut,
5784 const char *intf, int bufsize)
5785{
5786#ifdef NL80211_SUPPORT
5787 struct nl_msg *msg;
5788 int ret = 0;
5789 struct nlattr *params;
5790 int ifindex;
5791
5792 ifindex = if_nametoindex(intf);
5793 if (ifindex == 0) {
5794 sigma_dut_print(dut, DUT_MSG_ERROR,
5795 "%s: Index for interface %s failed",
5796 __func__, intf);
5797 return -1;
5798 }
5799
5800 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5801 NL80211_CMD_VENDOR)) ||
5802 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5803 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5804 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5805 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5806 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07005807 nla_put_u16(msg,
5808 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
5809 bufsize)) {
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08005810 sigma_dut_print(dut, DUT_MSG_ERROR,
5811 "%s: err in adding vendor_cmd and vendor_data",
5812 __func__);
5813 nlmsg_free(msg);
5814 return -1;
5815 }
5816 nla_nest_end(msg, params);
5817
5818 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5819 if (ret) {
5820 sigma_dut_print(dut, DUT_MSG_ERROR,
5821 "%s: err in send_and_recv_msgs, ret=%d",
5822 __func__, ret);
5823 }
5824 return ret;
5825#else /* NL80211_SUPPORT */
5826 sigma_dut_print(dut, DUT_MSG_ERROR,
5827 "AddBA bufsize cannot be changed without NL80211_SUPPORT defined");
5828 return -1;
5829#endif /* NL80211_SUPPORT */
5830}
5831
5832
Arif Hussain8d5b27b2018-05-14 14:31:03 -07005833static int sta_set_tx_beamformee(struct sigma_dut *dut, const char *intf,
5834 int enable)
5835{
5836#ifdef NL80211_SUPPORT
5837 struct nl_msg *msg;
5838 int ret = 0;
5839 struct nlattr *params;
5840 int ifindex;
5841
5842 ifindex = if_nametoindex(intf);
5843 if (ifindex == 0) {
5844 sigma_dut_print(dut, DUT_MSG_ERROR,
5845 "%s: Index for interface %s failed",
5846 __func__, intf);
5847 return -1;
5848 }
5849
5850 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5851 NL80211_CMD_VENDOR)) ||
5852 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5853 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5854 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5855 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5856 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5857 nla_put_u8(msg,
5858 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ENABLE_TX_BEAMFORMEE,
5859 enable)) {
5860 sigma_dut_print(dut, DUT_MSG_ERROR,
5861 "%s: err in adding vendor_cmd and vendor_data",
5862 __func__);
5863 nlmsg_free(msg);
5864 return -1;
5865 }
5866 nla_nest_end(msg, params);
5867
5868 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5869 if (ret) {
5870 sigma_dut_print(dut, DUT_MSG_ERROR,
5871 "%s: err in send_and_recv_msgs, ret=%d",
5872 __func__, ret);
5873 }
5874 return ret;
5875#else /* NL80211_SUPPORT */
5876 sigma_dut_print(dut, DUT_MSG_ERROR,
5877 "tx beamformee cannot be changed without NL80211_SUPPORT defined");
5878 return -1;
5879#endif /* NL80211_SUPPORT */
5880}
5881
5882
Arif Hussain9765f7d2018-07-03 08:28:26 -07005883static int sta_set_beamformee_sts(struct sigma_dut *dut, const char *intf,
5884 int val)
5885{
5886#ifdef NL80211_SUPPORT
5887 struct nl_msg *msg;
5888 int ret = 0;
5889 struct nlattr *params;
5890 int ifindex;
5891
5892 ifindex = if_nametoindex(intf);
5893 if (ifindex == 0) {
5894 sigma_dut_print(dut, DUT_MSG_ERROR,
5895 "%s: Index for interface %s failed, val:%d",
5896 __func__, intf, val);
5897 return -1;
5898 }
5899
5900 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5901 NL80211_CMD_VENDOR)) ||
5902 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5903 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5904 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5905 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5906 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5907 nla_put_u8(msg,
5908 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_BEAMFORMEE_NSTS,
5909 val)) {
5910 sigma_dut_print(dut, DUT_MSG_ERROR,
5911 "%s: err in adding vendor_cmd and vendor_data, val: %d",
5912 __func__, val);
5913 nlmsg_free(msg);
5914 return -1;
5915 }
5916 nla_nest_end(msg, params);
5917
5918 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5919 if (ret) {
5920 sigma_dut_print(dut, DUT_MSG_ERROR,
5921 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
5922 __func__, ret, val);
5923 }
5924 return ret;
5925#else /* NL80211_SUPPORT */
5926 sigma_dut_print(dut, DUT_MSG_ERROR,
5927 "beamformee sts cannot be changed without NL80211_SUPPORT defined");
5928 return -1;
5929#endif /* NL80211_SUPPORT */
5930}
5931
5932
Arif Hussain68d23f52018-07-11 13:39:08 -07005933#ifdef NL80211_SUPPORT
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07005934static int sta_set_mac_padding_duration(struct sigma_dut *dut, const char *intf,
5935 enum qca_wlan_he_mac_padding_dur val)
5936{
Arif Hussain68d23f52018-07-11 13:39:08 -07005937 struct nl_msg *msg;
5938 int ret = 0;
5939 struct nlattr *params;
5940 int ifindex;
5941
5942 ifindex = if_nametoindex(intf);
5943 if (ifindex == 0) {
5944 sigma_dut_print(dut, DUT_MSG_ERROR,
5945 "%s: Index for interface %s failed, val:%d",
5946 __func__, intf, val);
5947 return -1;
5948 }
5949
5950 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5951 NL80211_CMD_VENDOR)) ||
5952 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5953 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
5954 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
5955 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
5956 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
5957 nla_put_u8(msg,
5958 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_MAC_PADDING_DUR,
5959 val)) {
5960 sigma_dut_print(dut, DUT_MSG_ERROR,
5961 "%s: err in adding vendor_cmd and vendor_data, val: %d",
5962 __func__, val);
5963 nlmsg_free(msg);
5964 return -1;
5965 }
5966 nla_nest_end(msg, params);
5967
5968 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
5969 if (ret) {
5970 sigma_dut_print(dut, DUT_MSG_ERROR,
5971 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
5972 __func__, ret, val);
5973 }
5974 return ret;
Arif Hussain68d23f52018-07-11 13:39:08 -07005975}
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07005976#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07005977
5978
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07005979static int sta_set_tx_su_ppdu_cfg(struct sigma_dut *dut, const char *intf,
5980 int val)
5981{
5982#ifdef NL80211_SUPPORT
5983 struct nl_msg *msg;
5984 int ret = 0;
5985 struct nlattr *params;
5986 int ifindex;
5987
5988 ifindex = if_nametoindex(intf);
5989 if (ifindex == 0) {
5990 sigma_dut_print(dut, DUT_MSG_ERROR,
5991 "%s: Index for interface %s failed, val:%d",
5992 __func__, intf, val);
5993 return -1;
5994 }
5995
5996 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
5997 NL80211_CMD_VENDOR)) ||
5998 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
5999 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6000 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6001 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6002 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6003 nla_put_u8(msg,
6004 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_TX_SUPPDU,
6005 val)) {
6006 sigma_dut_print(dut, DUT_MSG_ERROR,
6007 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6008 __func__, val);
6009 nlmsg_free(msg);
6010 return -1;
6011 }
6012 nla_nest_end(msg, params);
6013
6014 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6015 if (ret) {
6016 sigma_dut_print(dut, DUT_MSG_ERROR,
6017 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6018 __func__, ret, val);
6019 }
6020 return ret;
6021#else /* NL80211_SUPPORT */
6022 sigma_dut_print(dut, DUT_MSG_ERROR,
6023 "Tx SU PPDU cannot be set without NL80211_SUPPORT defined");
6024 return -1;
6025#endif /* NL80211_SUPPORT */
6026}
6027
6028
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006029static int sta_set_he_om_ctrl_nss(struct sigma_dut *dut, const char *intf,
6030 int val)
6031{
6032#ifdef NL80211_SUPPORT
6033 struct nl_msg *msg;
6034 int ret = 0;
6035 struct nlattr *params;
6036 int ifindex;
6037
6038 ifindex = if_nametoindex(intf);
6039 if (ifindex == 0) {
6040 sigma_dut_print(dut, DUT_MSG_ERROR,
6041 "%s: Index for interface %s failed, val:%d",
6042 __func__, intf, val);
6043 return -1;
6044 }
6045
6046 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6047 NL80211_CMD_VENDOR)) ||
6048 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6049 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6050 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6051 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6052 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6053 nla_put_u8(msg,
6054 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_NSS,
6055 val)) {
6056 sigma_dut_print(dut, DUT_MSG_ERROR,
6057 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6058 __func__, val);
6059 nlmsg_free(msg);
6060 return -1;
6061 }
6062 nla_nest_end(msg, params);
6063
6064 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6065 if (ret) {
6066 sigma_dut_print(dut, DUT_MSG_ERROR,
6067 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6068 __func__, ret, val);
6069 }
6070 return ret;
6071#else /* NL80211_SUPPORT */
6072 sigma_dut_print(dut, DUT_MSG_ERROR,
6073 "OM CTRL NSS cannot be set without NL80211_SUPPORT defined");
6074 return -1;
6075#endif /* NL80211_SUPPORT */
6076}
6077
6078
6079static int sta_set_he_om_ctrl_bw(struct sigma_dut *dut, const char *intf,
6080 enum qca_wlan_he_om_ctrl_ch_bw val)
6081{
6082#ifdef NL80211_SUPPORT
6083 struct nl_msg *msg;
6084 int ret = 0;
6085 struct nlattr *params;
6086 int ifindex;
6087
6088 ifindex = if_nametoindex(intf);
6089 if (ifindex == 0) {
6090 sigma_dut_print(dut, DUT_MSG_ERROR,
6091 "%s: Index for interface %s failed, val:%d",
6092 __func__, intf, val);
6093 return -1;
6094 }
6095
6096 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6097 NL80211_CMD_VENDOR)) ||
6098 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6099 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6100 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6101 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6102 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6103 nla_put_u8(msg,
6104 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_BW,
6105 val)) {
6106 sigma_dut_print(dut, DUT_MSG_ERROR,
6107 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6108 __func__, val);
6109 nlmsg_free(msg);
6110 return -1;
6111 }
6112 nla_nest_end(msg, params);
6113
6114 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6115 if (ret) {
6116 sigma_dut_print(dut, DUT_MSG_ERROR,
6117 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6118 __func__, ret, val);
6119 }
6120 return ret;
6121#else /* NL80211_SUPPORT */
6122 sigma_dut_print(dut, DUT_MSG_ERROR,
6123 "OM CTRL BW cannot be set without NL80211_SUPPORT defined");
6124 return -1;
6125#endif /* NL80211_SUPPORT */
6126}
6127
6128
6129#ifdef NL80211_SUPPORT
6130static int sta_set_he_om_ctrl_reset(struct sigma_dut *dut, const char *intf)
6131{
6132 struct nl_msg *msg;
6133 int ret = 0;
6134 struct nlattr *params;
6135 int ifindex;
6136
6137 ifindex = if_nametoindex(intf);
6138 if (ifindex == 0) {
6139 sigma_dut_print(dut, DUT_MSG_ERROR,
6140 "%s: Index for interface %s failed",
6141 __func__, intf);
6142 return -1;
6143 }
6144
6145 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6146 NL80211_CMD_VENDOR)) ||
6147 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6148 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6149 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6150 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6151 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6152 nla_put_flag(msg,
6153 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_CLEAR_HE_OM_CTRL_CONFIG)) {
6154 sigma_dut_print(dut, DUT_MSG_ERROR,
6155 "%s: err in adding vendor_cmd and vendor_data",
6156 __func__);
6157 nlmsg_free(msg);
6158 return -1;
6159 }
6160 nla_nest_end(msg, params);
6161
6162 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6163 if (ret) {
6164 sigma_dut_print(dut, DUT_MSG_ERROR,
6165 "%s: err in send_and_recv_msgs, ret=%d",
6166 __func__, ret);
6167 }
6168 return ret;
6169}
6170#endif /* NL80211_SUPPORT */
6171
6172
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006173static int sta_set_mu_edca_override(struct sigma_dut *dut, const char *intf,
6174 int val)
6175{
6176#ifdef NL80211_SUPPORT
6177 struct nl_msg *msg;
6178 int ret = 0;
6179 struct nlattr *params;
6180 int ifindex;
6181
6182 ifindex = if_nametoindex(intf);
6183 if (ifindex == 0) {
6184 sigma_dut_print(dut, DUT_MSG_ERROR,
6185 "%s: Index for interface %s failed, val:%d",
6186 __func__, intf, val);
6187 return -1;
6188 }
6189
6190 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6191 NL80211_CMD_VENDOR)) ||
6192 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6193 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6194 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6195 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6196 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6197 nla_put_u8(msg,
6198 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_OVERRIDE_MU_EDCA,
6199 val)) {
6200 sigma_dut_print(dut, DUT_MSG_ERROR,
6201 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6202 __func__, val);
6203 nlmsg_free(msg);
6204 return -1;
6205 }
6206 nla_nest_end(msg, params);
6207
6208 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6209 if (ret) {
6210 sigma_dut_print(dut, DUT_MSG_ERROR,
6211 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6212 __func__, ret, val);
6213 }
6214 return ret;
6215#else /* NL80211_SUPPORT */
6216 sigma_dut_print(dut, DUT_MSG_ERROR,
6217 "MU EDCA override cannot be changed without NL80211_SUPPORT defined");
6218 return -1;
6219#endif /* NL80211_SUPPORT */
6220}
6221
6222
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006223static int sta_set_om_ctrl_supp(struct sigma_dut *dut, const char *intf,
6224 int val)
6225{
6226#ifdef NL80211_SUPPORT
6227 struct nl_msg *msg;
6228 int ret = 0;
6229 struct nlattr *params;
6230 int ifindex;
6231
6232 ifindex = if_nametoindex(intf);
6233 if (ifindex == 0) {
6234 sigma_dut_print(dut, DUT_MSG_ERROR,
6235 "%s: Index for interface %s failed, val:%d",
6236 __func__, intf, val);
6237 return -1;
6238 }
6239
6240 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
6241 NL80211_CMD_VENDOR)) ||
6242 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
6243 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
6244 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
6245 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
6246 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
6247 nla_put_u8(msg,
6248 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_HE_OM_CTRL_SUPP,
6249 val)) {
6250 sigma_dut_print(dut, DUT_MSG_ERROR,
6251 "%s: err in adding vendor_cmd and vendor_data, val: %d",
6252 __func__, val);
6253 nlmsg_free(msg);
6254 return -1;
6255 }
6256 nla_nest_end(msg, params);
6257
6258 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
6259 if (ret) {
6260 sigma_dut_print(dut, DUT_MSG_ERROR,
6261 "%s: err in send_and_recv_msgs, ret=%d, val=%d",
6262 __func__, ret, val);
6263 }
6264 return ret;
6265#else /* NL80211_SUPPORT */
6266 sigma_dut_print(dut, DUT_MSG_ERROR,
6267 "HE OM ctrl cannot be changed without NL80211_SUPPORT defined");
6268 return -1;
6269#endif /* NL80211_SUPPORT */
6270}
6271
6272
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006273static void sta_reset_default_wcn(struct sigma_dut *dut, const char *intf,
6274 const char *type)
6275{
6276 char buf[60];
6277
6278 if (dut->program == PROGRAM_HE) {
6279 /* resetting phymode to auto in case of HE program */
6280 snprintf(buf, sizeof(buf), "iwpriv %s setphymode 0", intf);
6281 if (system(buf) != 0) {
6282 sigma_dut_print(dut, DUT_MSG_ERROR,
6283 "iwpriv %s setphymode failed", intf);
6284 }
6285
Amarnath Hullur Subramanyam9cecb502018-04-25 13:26:30 -07006286 /* reset the rate to Auto rate */
6287 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0xff",
6288 intf);
6289 if (system(buf) != 0) {
6290 sigma_dut_print(dut, DUT_MSG_ERROR,
6291 "iwpriv %s set_11ax_rate 0xff failed",
6292 intf);
6293 }
6294
Kiran Kumar Lokere86cfe3a2018-06-01 11:55:15 -07006295 /* reset the LDPC setting */
6296 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 1", intf);
6297 if (system(buf) != 0) {
6298 sigma_dut_print(dut, DUT_MSG_ERROR,
6299 "iwpriv %s ldpc 1 failed", intf);
6300 }
6301
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006302 /* remove all network profiles */
6303 remove_wpa_networks(intf);
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006304
Amarnath Hullur Subramanyam13215de2018-02-27 14:12:55 -08006305 /* Configure ADDBA Req/Rsp buffer size to be 64 */
6306 sta_set_addba_buf_size(dut, intf, 64);
6307
Amarnath Hullur Subramanyam5f32d572018-03-02 00:02:33 -08006308#ifdef NL80211_SUPPORT
6309 /* Disable noackpolicy for all AC */
6310 if (nlvendor_sta_set_noack(dut, intf, 0, QCA_WLAN_AC_ALL)) {
6311 sigma_dut_print(dut, DUT_MSG_ERROR,
6312 "Disable of noackpolicy for all AC failed");
6313 }
6314#endif /* NL80211_SUPPORT */
6315
Amarnath Hullur Subramanyamb1724a52018-03-07 14:31:46 -08006316 /* Enable WMM by default */
6317 if (wcn_sta_set_wmm(dut, intf, "on")) {
6318 sigma_dut_print(dut, DUT_MSG_ERROR,
6319 "Enable of WMM in sta_reset_default_wcn failed");
6320 }
6321
6322 /* Disable ADDBA_REJECT by default */
6323 if (nlvendor_sta_set_addba_reject(dut, intf, 0)) {
6324 sigma_dut_print(dut, DUT_MSG_ERROR,
6325 "Disable of addba_reject in sta_reset_default_wcn failed");
6326 }
6327
Amarnath Hullur Subramanyam1f65a672018-03-07 14:50:29 -08006328 /* Enable sending of ADDBA by default */
6329 if (nlvendor_config_send_addba(dut, intf, 1)) {
6330 sigma_dut_print(dut, DUT_MSG_ERROR,
6331 "Enable sending of ADDBA in sta_reset_default_wcn failed");
6332 }
6333
Amarnath Hullur Subramanyam63c590a2018-03-07 15:26:21 -08006334 /* Enable AMPDU by default */
6335 iwpriv_sta_set_ampdu(dut, intf, 1);
6336
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006337#ifdef NL80211_SUPPORT
6338 if (sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_AUTO)) {
6339 sigma_dut_print(dut, DUT_MSG_ERROR,
6340 "Set LTF config to default in sta_reset_default_wcn failed");
6341 }
Arif Hussain9765f7d2018-07-03 08:28:26 -07006342
6343 if (sta_set_beamformee_sts(dut, intf, 0)) {
6344 sigma_dut_print(dut, DUT_MSG_ERROR,
6345 "Failed to set BeamformeeSTS");
6346 }
Arif Hussain68d23f52018-07-11 13:39:08 -07006347
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07006348 if (sta_set_mac_padding_duration(
6349 dut, intf,
6350 QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07006351 sigma_dut_print(dut, DUT_MSG_ERROR,
6352 "Failed to set MAC padding duration");
6353 }
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07006354
6355 if (sta_set_mu_edca_override(dut, intf, 0)) {
6356 sigma_dut_print(dut, DUT_MSG_ERROR,
6357 "ErrorCode,Failed to set MU EDCA override disable");
6358 }
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07006359
6360 if (sta_set_om_ctrl_supp(dut, intf, 1)) {
6361 sigma_dut_print(dut, DUT_MSG_ERROR,
6362 "Failed to set OM ctrl supp");
6363 }
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07006364
6365 if (sta_set_tx_su_ppdu_cfg(dut, intf, 1)) {
6366 sigma_dut_print(dut, DUT_MSG_ERROR,
6367 "Failed to set Tx SU PPDU enable");
6368 }
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07006369
6370 if (sta_set_he_om_ctrl_reset(dut, intf)) {
6371 sigma_dut_print(dut, DUT_MSG_ERROR,
6372 "Failed to set OM ctrl reset");
6373 }
Subhani Shaik8e7a3052018-04-24 14:03:00 -07006374#endif /* NL80211_SUPPORT */
6375
Arif Hussain8d5b27b2018-05-14 14:31:03 -07006376 if (sta_set_tx_beamformee(dut, intf, 1)) {
6377 sigma_dut_print(dut, DUT_MSG_ERROR,
6378 "Set tx beamformee enable by default in sta_reset_default_wcn failed");
6379 }
6380
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006381 /* Set nss to 1 and MCS 0-7 in case of testbed */
6382 if (type && strcasecmp(type, "Testbed") == 0) {
6383#ifdef NL80211_SUPPORT
6384 int ret;
6385#endif /* NL80211_SUPPORT */
6386
6387 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
6388 if (system(buf) != 0) {
6389 sigma_dut_print(dut, DUT_MSG_ERROR,
6390 "iwpriv %s nss failed", intf);
6391 }
6392
6393#ifdef NL80211_SUPPORT
6394 ret = sta_set_he_mcs(dut, intf, HE_80_MCS0_7);
6395 if (ret) {
6396 sigma_dut_print(dut, DUT_MSG_ERROR,
6397 "Setting of MCS failed, ret:%d",
6398 ret);
6399 }
6400#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyamc67621d2018-02-04 23:18:01 -08006401
6402 /* Disable STBC as default */
6403 wcn_sta_set_stbc(dut, intf, "0");
Amarnath Hullur Subramanyamd5bb5732018-02-22 15:50:38 -08006404
6405 /* Disable AMSDU as default */
6406 iwpriv_sta_set_amsdu(dut, intf, "0");
Amarnath Hullur Subramanyam474a17d2018-02-22 18:45:54 -08006407
6408#ifdef NL80211_SUPPORT
6409 /* HE fragmentation default off */
6410 if (sta_set_he_fragmentation(dut, intf,
6411 HE_FRAG_DISABLE)) {
6412 sigma_dut_print(dut, DUT_MSG_ERROR,
6413 "Setting of HE fragmentation failed");
6414 }
6415#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam4622a212018-02-23 12:12:14 -08006416
6417 /* Enable WEP/TKIP with HE capability in testbed */
6418 if (sta_set_heconfig_and_wep_tkip(dut, intf, 1)) {
6419 sigma_dut_print(dut, DUT_MSG_ERROR,
6420 "Enabling HE config with WEP/TKIP failed");
6421 }
Amarnath Hullur Subramanyam2538acc2018-02-02 16:15:25 -08006422 }
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006423
6424 /* Defaults in case of DUT */
6425 if (type && strcasecmp(type, "DUT") == 0) {
Arif Hussaind48fcc72018-05-01 18:34:18 -07006426 /* Enable STBC by default */
6427 wcn_sta_set_stbc(dut, intf, "1");
6428
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006429 /* set nss to 2 */
6430 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
6431 if (system(buf) != 0) {
6432 sigma_dut_print(dut, DUT_MSG_ERROR,
6433 "iwpriv %s nss 2 failed", intf);
6434 }
Arif Hussainac6c5112018-05-25 17:34:00 -07006435 dut->sta_nss = 2;
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006436
6437#ifdef NL80211_SUPPORT
Arif Hussainae239842018-05-01 18:20:05 -07006438 /* Set HE_MCS to 0-11 */
6439 if (sta_set_he_mcs(dut, intf, HE_80_MCS0_11)) {
Amarnath Hullur Subramanyam0acce2c2018-03-06 06:05:17 -08006440 sigma_dut_print(dut, DUT_MSG_ERROR,
6441 "Setting of MCS failed");
6442 }
6443#endif /* NL80211_SUPPORT */
6444
6445 /* Disable WEP/TKIP with HE capability in DUT */
6446 if (sta_set_heconfig_and_wep_tkip(dut, intf, 0)) {
6447 sigma_dut_print(dut, DUT_MSG_ERROR,
6448 "Enabling HE config with WEP/TKIP failed");
6449 }
6450 }
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006451 }
6452}
6453
6454
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006455static int cmd_sta_reset_default(struct sigma_dut *dut,
6456 struct sigma_conn *conn,
6457 struct sigma_cmd *cmd)
6458{
6459 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
6460 struct sigma_cmd *cmd);
6461 const char *intf = get_param(cmd, "Interface");
6462 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006463 const char *program = get_param(cmd, "program");
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05306464 const char *dev_role = get_param(cmd, "DevRole");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006465
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006466 if (!program)
6467 program = get_param(cmd, "prog");
6468 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006469 dut->device_type = STA_unknown;
6470 type = get_param(cmd, "type");
6471 if (type && strcasecmp(type, "Testbed") == 0)
6472 dut->device_type = STA_testbed;
6473 if (type && strcasecmp(type, "DUT") == 0)
6474 dut->device_type = STA_dut;
6475
6476 if (dut->program == PROGRAM_TDLS) {
6477 /* Clear TDLS testing mode */
6478 wpa_command(intf, "SET tdls_disabled 0");
6479 wpa_command(intf, "SET tdls_testing 0");
6480 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05306481 if (get_driver_type() == DRIVER_WCN) {
6482 /* Enable the WCN driver in TDLS Explicit trigger mode
6483 */
6484 wpa_command(intf, "SET tdls_external_control 0");
6485 wpa_command(intf, "SET tdls_trigger_control 0");
6486 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006487 }
6488
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07006489#ifdef MIRACAST
6490 if (dut->program == PROGRAM_WFD ||
6491 dut->program == PROGRAM_DISPLAYR2)
6492 miracast_sta_reset_default(dut, conn, cmd);
6493#endif /* MIRACAST */
6494
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006495 switch (get_driver_type()) {
6496 case DRIVER_ATHEROS:
6497 sta_reset_default_ath(dut, intf, type);
6498 break;
Amarnath Hullur Subramanyam58f2a6e2018-01-31 03:36:00 -08006499 case DRIVER_WCN:
6500 sta_reset_default_wcn(dut, intf, type);
6501 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006502 default:
6503 break;
6504 }
6505
6506#ifdef ANDROID_NAN
6507 if (dut->program == PROGRAM_NAN)
6508 nan_cmd_sta_reset_default(dut, conn, cmd);
6509#endif /* ANDROID_NAN */
6510
Jouni Malinenba630452018-06-22 11:49:59 +03006511 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006512 unlink("SP/wi-fi.org/pps.xml");
6513 if (system("rm -r SP/*") != 0) {
6514 }
6515 unlink("next-client-cert.pem");
6516 unlink("next-client-key.pem");
6517 }
6518
6519 if (dut->program == PROGRAM_60GHZ) {
6520 const char *dev_role = get_param(cmd, "DevRole");
6521
6522 if (!dev_role) {
6523 send_resp(dut, conn, SIGMA_ERROR,
6524 "errorCode,Missing DevRole argument");
6525 return 0;
6526 }
6527
6528 if (strcasecmp(dev_role, "STA") == 0)
6529 dut->dev_role = DEVROLE_STA;
6530 else if (strcasecmp(dev_role, "PCP") == 0)
6531 dut->dev_role = DEVROLE_PCP;
6532 else {
6533 send_resp(dut, conn, SIGMA_ERROR,
6534 "errorCode,Unknown DevRole");
6535 return 0;
6536 }
6537
6538 if (dut->device_type == STA_unknown) {
6539 sigma_dut_print(dut, DUT_MSG_ERROR,
6540 "Device type is not STA testbed or DUT");
6541 send_resp(dut, conn, SIGMA_ERROR,
6542 "errorCode,Unknown device type");
6543 return 0;
6544 }
6545 }
6546
6547 wpa_command(intf, "WPS_ER_STOP");
6548 wpa_command(intf, "FLUSH");
vamsi krishnaf39bc1e2017-08-23 17:37:53 +05306549 wpa_command(intf, "ERP_FLUSH");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006550 wpa_command(intf, "SET radio_disabled 0");
6551
6552 if (dut->tmp_mac_addr && dut->set_macaddr) {
6553 dut->tmp_mac_addr = 0;
6554 if (system(dut->set_macaddr) != 0) {
6555 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
6556 "temporary MAC address");
6557 }
6558 }
6559
6560 set_ps(intf, dut, 0);
6561
Jouni Malinenba630452018-06-22 11:49:59 +03006562 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2 ||
6563 dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006564 wpa_command(intf, "SET interworking 1");
6565 wpa_command(intf, "SET hs20 1");
6566 }
6567
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006568 if (dut->program == PROGRAM_HS2_R2 ||
Jouni Malinenba630452018-06-22 11:49:59 +03006569 dut->program == PROGRAM_HS2_R3 ||
Deepak Dhamdhere0fe0e452017-12-18 14:52:09 -08006570 dut->program == PROGRAM_OCE) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006571 wpa_command(intf, "SET pmf 1");
6572 } else {
6573 wpa_command(intf, "SET pmf 0");
6574 }
6575
6576 hs2_clear_credentials(intf);
6577 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
6578 wpa_command(intf, "SET access_network_type 15");
6579
6580 static_ip_file(0, NULL, NULL, NULL);
6581 kill_dhcp_client(dut, intf);
6582 clear_ip_addr(dut, intf);
6583
6584 dut->er_oper_performed = 0;
6585 dut->er_oper_bssid[0] = '\0';
6586
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07006587 if (dut->program == PROGRAM_LOC) {
6588 /* Disable Interworking by default */
6589 wpa_command(get_station_ifname(), "SET interworking 0");
6590 }
6591
Ashwini Patil00402582017-04-13 12:29:39 +05306592 if (dut->program == PROGRAM_MBO) {
6593 free(dut->non_pref_ch_list);
6594 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05306595 free(dut->btm_query_cand_list);
6596 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05306597 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05306598 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05306599 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05306600 wpa_command(intf, "SET roaming 1");
Ankita Bajaj1d974552018-09-18 16:56:44 +05306601 wpa_command(intf, "SET interworking 1");
Ashwini Patil00402582017-04-13 12:29:39 +05306602 }
6603
Jouni Malinen3c367e82017-06-23 17:01:47 +03006604 free(dut->rsne_override);
6605 dut->rsne_override = NULL;
6606
Jouni Malinen68143132017-09-02 02:34:08 +03006607 free(dut->sae_commit_override);
6608 dut->sae_commit_override = NULL;
6609
Jouni Malinend86e5822017-08-29 03:55:32 +03006610 dut->dpp_conf_id = -1;
Jouni Malinenb1dd21f2017-11-13 19:14:29 +02006611 free(dut->dpp_peer_uri);
6612 dut->dpp_peer_uri = NULL;
Jouni Malinen63d50412017-11-24 11:55:38 +02006613 dut->dpp_local_bootstrap = -1;
Jouni Malinen5011fb52017-12-05 21:00:15 +02006614 wpa_command(intf, "SET dpp_config_processing 2");
Jouni Malinend86e5822017-08-29 03:55:32 +03006615
Jouni Malinenfac9cad2017-10-10 18:35:55 +03006616 wpa_command(intf, "VENDOR_ELEM_REMOVE 13 *");
6617
vamsi krishnaa2799492017-12-05 14:28:01 +05306618 if (dut->program == PROGRAM_OCE) {
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306619 wpa_command(intf, "SET oce 1");
vamsi krishnaa2799492017-12-05 14:28:01 +05306620 wpa_command(intf, "SET disable_fils 0");
Ankita Bajaj1bde7942018-01-09 19:15:01 +05306621 wpa_command(intf, "FILS_HLP_REQ_FLUSH");
6622 dut->fils_hlp = 0;
6623#ifdef ANDROID
6624 hlp_thread_cleanup(dut);
6625#endif /* ANDROID */
vamsi krishnaa2799492017-12-05 14:28:01 +05306626 }
Ankita Bajaja2cb5672017-10-25 16:08:28 +05306627
Sunil Dutt076081f2018-02-05 19:45:50 +05306628#ifdef NL80211_SUPPORT
Sunil Dutt44595082018-02-12 19:41:45 +05306629 if (get_driver_type() == DRIVER_WCN &&
6630 dut->config_rsnie == 1) {
6631 dut->config_rsnie = 0;
6632 sta_config_rsnie(dut, 0);
Sunil Dutt076081f2018-02-05 19:45:50 +05306633 }
6634#endif /* NL80211_SUPPORT */
6635
Sunil Duttfebf8a82018-02-09 18:50:13 +05306636 if (dev_role && strcasecmp(dev_role, "STA-CFON") == 0) {
6637 dut->dev_role = DEVROLE_STA_CFON;
6638 return sta_cfon_reset_default(dut, conn, cmd);
6639 }
6640
Jouni Malinen439352d2018-09-13 03:42:23 +03006641 wpa_command(intf, "SET setband AUTO");
6642
Sunil Duttfebf8a82018-02-09 18:50:13 +05306643 if (dut->program != PROGRAM_VHT)
6644 return cmd_sta_p2p_reset(dut, conn, cmd);
6645
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08006646 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006647}
6648
6649
6650static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
6651 struct sigma_cmd *cmd)
6652{
6653 const char *program = get_param(cmd, "Program");
6654
6655 if (program == NULL)
6656 return -1;
6657#ifdef ANDROID_NAN
6658 if (strcasecmp(program, "NAN") == 0)
6659 return nan_cmd_sta_get_events(dut, conn, cmd);
6660#endif /* ANDROID_NAN */
6661 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6662 return 0;
6663}
6664
6665
Jouni Malinen82905202018-04-29 17:20:10 +03006666static int sta_exec_action_url(struct sigma_dut *dut, struct sigma_conn *conn,
6667 struct sigma_cmd *cmd)
6668{
6669 const char *url = get_param(cmd, "url");
6670 const char *method = get_param(cmd, "method");
6671 pid_t pid;
6672 int status;
6673
6674 if (!url || !method)
6675 return -1;
6676
6677 /* TODO: Add support for method,post */
6678 if (strcasecmp(method, "get") != 0) {
6679 send_resp(dut, conn, SIGMA_ERROR,
6680 "ErrorCode,Unsupported method");
6681 return 0;
6682 }
6683
6684 pid = fork();
6685 if (pid < 0) {
6686 perror("fork");
6687 return -1;
6688 }
6689
6690 if (pid == 0) {
6691 char * argv[5] = { "wget", "-O", "/dev/null",
6692 (char *) url, NULL };
6693
6694 execv("/usr/bin/wget", argv);
6695 perror("execv");
6696 exit(0);
6697 return -1;
6698 }
6699
6700 if (waitpid(pid, &status, 0) < 0) {
6701 perror("waitpid");
6702 return -1;
6703 }
6704
6705 if (WIFEXITED(status)) {
6706 const char *errmsg;
6707
6708 if (WEXITSTATUS(status) == 0)
6709 return 1;
6710 sigma_dut_print(dut, DUT_MSG_INFO, "wget exit status %d",
6711 WEXITSTATUS(status));
6712 switch (WEXITSTATUS(status)) {
6713 case 4:
6714 errmsg = "errmsg,Network failure";
6715 break;
6716 case 8:
6717 errmsg = "errmsg,Server issued an error response";
6718 break;
6719 default:
6720 errmsg = "errmsg,Unknown failure from wget";
6721 break;
6722 }
6723 send_resp(dut, conn, SIGMA_ERROR, errmsg);
6724 return 0;
6725 }
6726
6727 send_resp(dut, conn, SIGMA_ERROR, "errmsg,Unknown failure");
6728 return 0;
6729}
6730
6731
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006732static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
6733 struct sigma_cmd *cmd)
6734{
6735 const char *program = get_param(cmd, "Prog");
6736
Jouni Malinen82905202018-04-29 17:20:10 +03006737 if (program && !get_param(cmd, "interface"))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006738 return -1;
6739#ifdef ANDROID_NAN
Jouni Malinen82905202018-04-29 17:20:10 +03006740 if (program && strcasecmp(program, "NAN") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006741 return nan_cmd_sta_exec_action(dut, conn, cmd);
6742#endif /* ANDROID_NAN */
Jouni Malinen82905202018-04-29 17:20:10 +03006743
6744 if (program && strcasecmp(program, "Loc") == 0)
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006745 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinen82905202018-04-29 17:20:10 +03006746
6747 if (get_param(cmd, "url"))
6748 return sta_exec_action_url(dut, conn, cmd);
6749
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006750 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
6751 return 0;
6752}
6753
6754
6755static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
6756 struct sigma_cmd *cmd)
6757{
6758 const char *intf = get_param(cmd, "Interface");
6759 const char *val, *mcs32, *rate;
6760
6761 val = get_param(cmd, "GREENFIELD");
6762 if (val) {
6763 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
6764 /* Enable GD */
6765 send_resp(dut, conn, SIGMA_ERROR,
6766 "ErrorCode,GF not supported");
6767 return 0;
6768 }
6769 }
6770
6771 val = get_param(cmd, "SGI20");
6772 if (val) {
6773 switch (get_driver_type()) {
6774 case DRIVER_ATHEROS:
6775 ath_sta_set_sgi(dut, intf, val);
6776 break;
6777 default:
6778 send_resp(dut, conn, SIGMA_ERROR,
6779 "ErrorCode,SGI20 not supported");
6780 return 0;
6781 }
6782 }
6783
6784 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
6785 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
6786 if (mcs32 && rate) {
6787 /* TODO */
6788 send_resp(dut, conn, SIGMA_ERROR,
6789 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
6790 return 0;
6791 } else if (mcs32 && !rate) {
6792 /* TODO */
6793 send_resp(dut, conn, SIGMA_ERROR,
6794 "ErrorCode,MCS32 not supported");
6795 return 0;
6796 } else if (!mcs32 && rate) {
6797 switch (get_driver_type()) {
6798 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08006799 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006800 ath_sta_set_11nrates(dut, intf, rate);
6801 break;
6802 default:
6803 send_resp(dut, conn, SIGMA_ERROR,
6804 "ErrorCode,MCS32_FIXEDRATE not supported");
6805 return 0;
6806 }
6807 }
6808
6809 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
6810}
6811
6812
Arif Hussain7b47d2d2018-05-09 10:44:02 -07006813static void cmd_set_max_he_mcs(struct sigma_dut *dut, const char *intf,
6814 int mcs_config)
6815{
6816#ifdef NL80211_SUPPORT
6817 int ret;
6818
6819 switch (mcs_config) {
6820 case HE_80_MCS0_7:
6821 case HE_80_MCS0_9:
6822 case HE_80_MCS0_11:
6823 ret = sta_set_he_mcs(dut, intf, mcs_config);
6824 if (ret) {
6825 sigma_dut_print(dut, DUT_MSG_ERROR,
6826 "cmd_set_max_he_mcs: Setting of MCS:%d failed, ret:%d",
6827 mcs_config, ret);
6828 }
6829 break;
6830 default:
6831 sigma_dut_print(dut, DUT_MSG_ERROR,
6832 "cmd_set_max_he_mcs: Invalid mcs %d",
6833 mcs_config);
6834 break;
6835 }
6836#else /* NL80211_SUPPORT */
6837 sigma_dut_print(dut, DUT_MSG_ERROR,
6838 "max HE MCS cannot be changed without NL80211_SUPPORT defined");
6839#endif /* NL80211_SUPPORT */
6840}
6841
6842
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006843static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
6844 struct sigma_conn *conn,
6845 struct sigma_cmd *cmd)
6846{
6847 const char *intf = get_param(cmd, "Interface");
6848 const char *val;
Arif Hussaina37e9552018-06-20 17:05:59 -07006849 const char *program;
Arif Hussaind13d6952018-07-02 16:23:47 -07006850 char buf[60];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006851 int tkip = -1;
6852 int wep = -1;
6853
Arif Hussaina37e9552018-06-20 17:05:59 -07006854 program = get_param(cmd, "Program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006855 val = get_param(cmd, "SGI80");
6856 if (val) {
6857 int sgi80;
6858
6859 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6860 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
6861 if (system(buf) != 0) {
6862 sigma_dut_print(dut, DUT_MSG_ERROR,
6863 "iwpriv shortgi failed");
6864 }
6865 }
6866
6867 val = get_param(cmd, "TxBF");
6868 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07006869 switch (get_driver_type()) {
6870 case DRIVER_WCN:
6871 if (sta_set_tx_beamformee(dut, intf, 1)) {
6872 send_resp(dut, conn, SIGMA_ERROR,
6873 "ErrorCode,Failed to set TX beamformee enable");
6874 return 0;
6875 }
6876 break;
6877 case DRIVER_ATHEROS:
6878 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1",
6879 intf);
6880 if (system(buf) != 0) {
6881 send_resp(dut, conn, SIGMA_ERROR,
6882 "ErrorCode,Setting vhtsubfee failed");
6883 return 0;
6884 }
6885
6886 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1",
6887 intf);
6888 if (system(buf) != 0) {
6889 send_resp(dut, conn, SIGMA_ERROR,
6890 "ErrorCode,Setting vhtsubfer failed");
6891 return 0;
6892 }
6893 break;
6894 default:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006895 sigma_dut_print(dut, DUT_MSG_ERROR,
Kiran Kumar Lokerecb57d822018-07-06 16:37:42 -07006896 "Unsupported driver type");
6897 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006898 }
6899 }
6900
6901 val = get_param(cmd, "MU_TxBF");
6902 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
6903 switch (get_driver_type()) {
6904 case DRIVER_ATHEROS:
6905 ath_sta_set_txsp_stream(dut, intf, "1SS");
6906 ath_sta_set_rxsp_stream(dut, intf, "1SS");
Sunil Duttae9e5d12018-06-29 11:50:47 +05306907 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1",
6908 intf);
6909 if (system(buf) != 0) {
6910 sigma_dut_print(dut, DUT_MSG_ERROR,
6911 "iwpriv vhtmubfee failed");
6912 }
6913 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1",
6914 intf);
6915 if (system(buf) != 0) {
6916 sigma_dut_print(dut, DUT_MSG_ERROR,
6917 "iwpriv vhtmubfer failed");
6918 }
6919 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006920 case DRIVER_WCN:
6921 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
6922 send_resp(dut, conn, SIGMA_ERROR,
6923 "ErrorCode,Failed to set RX/TXSP_STREAM");
6924 return 0;
6925 }
Sunil Duttae9e5d12018-06-29 11:50:47 +05306926 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006927 default:
6928 sigma_dut_print(dut, DUT_MSG_ERROR,
6929 "Setting SP_STREAM not supported");
6930 break;
6931 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006932 }
6933
6934 val = get_param(cmd, "LDPC");
6935 if (val) {
6936 int ldpc;
6937
6938 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6939 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
6940 if (system(buf) != 0) {
6941 sigma_dut_print(dut, DUT_MSG_ERROR,
6942 "iwpriv ldpc failed");
6943 }
6944 }
6945
Amarnath Hullur Subramanyam7bae60e2018-01-31 03:46:50 -08006946 val = get_param(cmd, "BCC");
6947 if (val) {
6948 int bcc;
6949
6950 bcc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
6951 /* use LDPC iwpriv itself to set bcc coding, bcc coding
6952 * is mutually exclusive to bcc */
6953 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, !bcc);
6954 if (system(buf) != 0) {
6955 sigma_dut_print(dut, DUT_MSG_ERROR,
6956 "Enabling/Disabling of BCC failed");
6957 }
6958 }
6959
Arif Hussain7b47d2d2018-05-09 10:44:02 -07006960 val = get_param(cmd, "MaxHE-MCS_1SS_RxMapLTE80");
6961 if (val && dut->sta_nss == 1)
6962 cmd_set_max_he_mcs(dut, intf, atoi(val));
6963
6964 val = get_param(cmd, "MaxHE-MCS_2SS_RxMapLTE80");
6965 if (val && dut->sta_nss == 2)
6966 cmd_set_max_he_mcs(dut, intf, atoi(val));
6967
Arif Hussainac6c5112018-05-25 17:34:00 -07006968 val = get_param(cmd, "MCS_FixedRate");
6969 if (val) {
6970#ifdef NL80211_SUPPORT
6971 int mcs, ratecode = 0;
6972 enum he_mcs_config mcs_config;
6973 int ret;
6974
6975 ratecode = (0x07 & dut->sta_nss) << 5;
6976 mcs = atoi(val);
6977 /* Add the MCS to the ratecode */
6978 if (mcs >= 0 && mcs <= 11) {
6979 ratecode += mcs;
6980 if (dut->device_type == STA_testbed &&
6981 mcs > 7 && mcs <= 11) {
6982 if (mcs <= 9)
6983 mcs_config = HE_80_MCS0_9;
6984 else
6985 mcs_config = HE_80_MCS0_11;
6986 ret = sta_set_he_mcs(dut, intf, mcs_config);
6987 if (ret) {
6988 sigma_dut_print(dut, DUT_MSG_ERROR,
6989 "MCS_FixedRate: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
6990 mcs, mcs_config, ret);
6991 }
6992 }
6993 snprintf(buf, sizeof(buf),
6994 "iwpriv %s set_11ax_rate 0x%03x",
6995 intf, ratecode);
6996 if (system(buf) != 0) {
6997 sigma_dut_print(dut, DUT_MSG_ERROR,
6998 "MCS_FixedRate: iwpriv setting of 11ax rates 0x%03x failed",
6999 ratecode);
7000 }
7001 } else {
7002 sigma_dut_print(dut, DUT_MSG_ERROR,
7003 "MCS_FixedRate: HE MCS %d not supported",
7004 mcs);
7005 }
7006#else /* NL80211_SUPPORT */
7007 sigma_dut_print(dut, DUT_MSG_ERROR,
7008 "MCS_FixedRate cannot be changed without NL80211_SUPPORT defined");
7009#endif /* NL80211_SUPPORT */
7010 }
7011
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007012 val = get_param(cmd, "opt_md_notif_ie");
7013 if (val) {
7014 char *result = NULL;
7015 char delim[] = ";";
7016 char token[30];
7017 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307018 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007019
Peng Xub8fc5cc2017-05-10 17:27:28 -07007020 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307021 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007022
7023 /* Extract the NSS information */
7024 if (result) {
7025 value = atoi(result);
7026 switch (value) {
7027 case 1:
7028 config_val = 1;
7029 break;
7030 case 2:
7031 config_val = 3;
7032 break;
7033 case 3:
7034 config_val = 7;
7035 break;
7036 case 4:
7037 config_val = 15;
7038 break;
7039 default:
7040 config_val = 3;
7041 break;
7042 }
7043
7044 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
7045 intf, config_val);
7046 if (system(buf) != 0) {
7047 sigma_dut_print(dut, DUT_MSG_ERROR,
7048 "iwpriv rxchainmask failed");
7049 }
7050
7051 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
7052 intf, config_val);
7053 if (system(buf) != 0) {
7054 sigma_dut_print(dut, DUT_MSG_ERROR,
7055 "iwpriv txchainmask failed");
7056 }
7057 }
7058
7059 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307060 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007061 if (result) {
7062 value = atoi(result);
7063 switch (value) {
7064 case 20:
7065 config_val = 0;
7066 break;
7067 case 40:
7068 config_val = 1;
7069 break;
7070 case 80:
7071 config_val = 2;
7072 break;
7073 case 160:
7074 config_val = 3;
7075 break;
7076 default:
7077 config_val = 2;
7078 break;
7079 }
7080
7081 dut->chwidth = config_val;
7082
7083 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7084 intf, config_val);
7085 if (system(buf) != 0) {
7086 sigma_dut_print(dut, DUT_MSG_ERROR,
7087 "iwpriv chwidth failed");
7088 }
7089 }
7090
7091 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
7092 if (system(buf) != 0) {
7093 sigma_dut_print(dut, DUT_MSG_ERROR,
7094 "iwpriv opmode_notify failed");
7095 }
7096 }
7097
7098 val = get_param(cmd, "nss_mcs_cap");
7099 if (val) {
7100 int nss, mcs;
7101 char token[20];
7102 char *result = NULL;
7103 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307104 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007105
Peng Xub8fc5cc2017-05-10 17:27:28 -07007106 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307107 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307108 if (!result) {
7109 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007110 "NSS not specified");
7111 send_resp(dut, conn, SIGMA_ERROR,
7112 "errorCode,NSS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307113 return 0;
7114 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007115 nss = atoi(result);
7116
7117 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
7118 if (system(buf) != 0) {
7119 sigma_dut_print(dut, DUT_MSG_ERROR,
7120 "iwpriv nss failed");
7121 }
Arif Hussainac6c5112018-05-25 17:34:00 -07007122 dut->sta_nss = nss;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007123
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307124 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007125 if (result == NULL) {
7126 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007127 "MCS not specified");
7128 send_resp(dut, conn, SIGMA_ERROR,
7129 "errorCode,MCS not specified");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007130 return 0;
7131 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307132 result = strtok_r(result, "-", &saveptr);
7133 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307134 if (!result) {
7135 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007136 "MCS not specified");
7137 send_resp(dut, conn, SIGMA_ERROR,
7138 "errorCode,MCS not specified");
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05307139 return 0;
7140 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007141 mcs = atoi(result);
7142
Arif Hussaina37e9552018-06-20 17:05:59 -07007143 if (program && strcasecmp(program, "HE") == 0) {
7144#ifdef NL80211_SUPPORT
7145 enum he_mcs_config mcs_config;
7146 int ret;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007147
Arif Hussaina37e9552018-06-20 17:05:59 -07007148 if (mcs >= 0 && mcs <= 7) {
7149 mcs_config = HE_80_MCS0_7;
7150 } else if (mcs > 7 && mcs <= 9) {
7151 mcs_config = HE_80_MCS0_9;
7152 } else if (mcs > 9 && mcs <= 11) {
7153 mcs_config = HE_80_MCS0_11;
7154 } else {
7155 sigma_dut_print(dut, DUT_MSG_ERROR,
7156 "nss_mcs_cap: HE: Invalid mcs: %d",
7157 mcs);
7158 send_resp(dut, conn, SIGMA_ERROR,
7159 "errorCode,Invalid MCS");
7160 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007161 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007162
7163 ret = sta_set_he_mcs(dut, intf, mcs_config);
7164 if (ret) {
7165 sigma_dut_print(dut, DUT_MSG_ERROR,
7166 "nss_mcs_cap: HE: Setting of MCS failed, mcs_config: %d, ret: %d",
7167 mcs_config, ret);
7168 send_resp(dut, conn, SIGMA_ERROR,
7169 "errorCode,Failed to set MCS");
7170 return 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007171 }
Arif Hussaina37e9552018-06-20 17:05:59 -07007172#else /* NL80211_SUPPORT */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007173 sigma_dut_print(dut, DUT_MSG_ERROR,
Arif Hussaina37e9552018-06-20 17:05:59 -07007174 "nss_mcs_cap: HE: MCS cannot be changed without NL80211_SUPPORT defined");
7175#endif /* NL80211_SUPPORT */
7176 } else {
7177 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
7178 intf, mcs);
7179 if (system(buf) != 0) {
7180 sigma_dut_print(dut, DUT_MSG_ERROR,
7181 "iwpriv mcs failed");
7182 }
7183
7184 switch (nss) {
7185 case 1:
7186 switch (mcs) {
7187 case 7:
7188 vht_mcsmap = 0xfffc;
7189 break;
7190 case 8:
7191 vht_mcsmap = 0xfffd;
7192 break;
7193 case 9:
7194 vht_mcsmap = 0xfffe;
7195 break;
7196 default:
7197 vht_mcsmap = 0xfffe;
7198 break;
7199 }
7200 break;
7201 case 2:
7202 switch (mcs) {
7203 case 7:
7204 vht_mcsmap = 0xfff0;
7205 break;
7206 case 8:
7207 vht_mcsmap = 0xfff5;
7208 break;
7209 case 9:
7210 vht_mcsmap = 0xfffa;
7211 break;
7212 default:
7213 vht_mcsmap = 0xfffa;
7214 break;
7215 }
7216 break;
7217 case 3:
7218 switch (mcs) {
7219 case 7:
7220 vht_mcsmap = 0xffc0;
7221 break;
7222 case 8:
7223 vht_mcsmap = 0xffd5;
7224 break;
7225 case 9:
7226 vht_mcsmap = 0xffea;
7227 break;
7228 default:
7229 vht_mcsmap = 0xffea;
7230 break;
7231 }
7232 break;
7233 default:
7234 vht_mcsmap = 0xffea;
7235 break;
7236 }
7237 snprintf(buf, sizeof(buf),
7238 "iwpriv %s vht_mcsmap 0x%04x",
7239 intf, vht_mcsmap);
7240 if (system(buf) != 0) {
7241 sigma_dut_print(dut, DUT_MSG_ERROR,
7242 "iwpriv vht_mcsmap failed");
7243 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007244 }
7245 }
7246
7247 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
7248
7249 val = get_param(cmd, "Vht_tkip");
7250 if (val)
7251 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7252
7253 val = get_param(cmd, "Vht_wep");
7254 if (val)
7255 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
7256
7257 if (tkip != -1 || wep != -1) {
7258 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
7259 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
7260 intf);
7261 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
7262 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
7263 intf);
7264 } else {
7265 sigma_dut_print(dut, DUT_MSG_ERROR,
7266 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
7267 return 0;
7268 }
7269
7270 if (system(buf) != 0) {
7271 sigma_dut_print(dut, DUT_MSG_ERROR,
7272 "iwpriv htweptkip failed");
7273 }
7274 }
7275
Arif Hussain55f00da2018-07-03 08:28:26 -07007276 val = get_param(cmd, "txBandwidth");
7277 if (val) {
7278 switch (get_driver_type()) {
7279 case DRIVER_WCN:
7280 if (wcn_sta_set_width(dut, intf, val) < 0) {
7281 send_resp(dut, conn, SIGMA_ERROR,
7282 "ErrorCode,Failed to set txBandwidth");
7283 return 0;
7284 }
7285 break;
7286 case DRIVER_ATHEROS:
7287 if (ath_set_width(dut, conn, intf, val) < 0) {
7288 send_resp(dut, conn, SIGMA_ERROR,
7289 "ErrorCode,Failed to set txBandwidth");
7290 return 0;
7291 }
7292 break;
7293 default:
7294 sigma_dut_print(dut, DUT_MSG_ERROR,
7295 "Setting txBandwidth not supported");
7296 break;
7297 }
7298 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007299
Arif Hussain9765f7d2018-07-03 08:28:26 -07007300 val = get_param(cmd, "BeamformeeSTS");
7301 if (val) {
Kiran Kumar Lokerebc89d432018-07-10 12:20:13 -07007302 if (sta_set_tx_beamformee(dut, intf, 1)) {
7303 send_resp(dut, conn, SIGMA_ERROR,
7304 "ErrorCode,Failed to set TX beamformee enable");
7305 return 0;
7306 }
7307
Arif Hussain9765f7d2018-07-03 08:28:26 -07007308 if (sta_set_beamformee_sts(dut, intf, atoi(val))) {
7309 send_resp(dut, conn, SIGMA_ERROR,
7310 "ErrorCode,Failed to set BeamformeeSTS");
7311 return 0;
7312 }
7313 }
7314
Arif Hussain68d23f52018-07-11 13:39:08 -07007315 val = get_param(cmd, "Trig_MAC_Padding_Dur");
7316 if (val) {
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007317#ifdef NL80211_SUPPORT
7318 enum qca_wlan_he_mac_padding_dur set_val;
7319
7320 switch (atoi(val)) {
7321 case 16:
7322 set_val = QCA_WLAN_HE_16US_OF_PROCESS_TIME;
7323 break;
7324 case 8:
7325 set_val = QCA_WLAN_HE_8US_OF_PROCESS_TIME;
7326 break;
7327 default:
7328 set_val = QCA_WLAN_HE_NO_ADDITIONAL_PROCESS_TIME;
7329 break;
7330 }
7331 if (sta_set_mac_padding_duration(dut, intf, set_val)) {
Arif Hussain68d23f52018-07-11 13:39:08 -07007332 send_resp(dut, conn, SIGMA_ERROR,
7333 "ErrorCode,Failed to set MAC padding duration");
7334 return 0;
7335 }
Kiran Kumar Lokere55eb5582018-08-19 20:03:26 -07007336#else /* NL80211_SUPPORT */
7337 sigma_dut_print(dut, DUT_MSG_ERROR,
7338 "MAC padding duration cannot be changed without NL80211_SUPPORT defined");
7339#endif /* NL80211_SUPPORT */
Arif Hussain68d23f52018-07-11 13:39:08 -07007340 }
7341
Kiran Kumar Lokereb1012682018-08-08 17:48:32 -07007342 val = get_param(cmd, "MU_EDCA");
7343 if (val && (strcasecmp(val, "Override") == 0)) {
7344 if (sta_set_mu_edca_override(dut, intf, 1)) {
7345 send_resp(dut, conn, SIGMA_ERROR,
7346 "ErrorCode,Failed to set MU EDCA override");
7347 return 0;
7348 }
7349 }
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007350
Kiran Kumar Lokerede33e372018-08-29 16:26:24 -07007351 val = get_param(cmd, "OMControl");
7352 if (val) {
7353 int set_val = 1;
7354
7355 if (strcasecmp(val, "Enable") == 0)
7356 set_val = 1;
7357 else if (strcasecmp(val, "Disable") == 0)
7358 set_val = 0;
7359
7360 if (sta_set_om_ctrl_supp(dut, intf, set_val)) {
7361 send_resp(dut, conn, SIGMA_ERROR,
7362 "ErrorCode,Failed to set OM ctrl supp");
7363 return 0;
7364 }
7365 }
7366
Kiran Kumar Lokerec6581822018-08-01 16:18:34 -07007367 val = get_param(cmd, "ADDBAResp_BufSize");
7368 if (val) {
7369 int buf_size;
7370
7371 if (strcasecmp(val, "gt64") == 0)
7372 buf_size = 256;
7373 else
7374 buf_size = 64;
7375 if (get_driver_type() == DRIVER_WCN &&
7376 sta_set_addba_buf_size(dut, intf, buf_size)) {
7377 send_resp(dut, conn, SIGMA_ERROR,
7378 "ErrorCode,set addbaresp_buff_size failed");
7379 return 0;
7380 }
7381 }
7382
7383 val = get_param(cmd, "ADDBAReq_BufSize");
7384 if (val) {
7385 int buf_size;
7386
7387 if (strcasecmp(val, "gt64") == 0)
7388 buf_size = 256;
7389 else
7390 buf_size = 64;
7391 if (get_driver_type() == DRIVER_WCN &&
7392 sta_set_addba_buf_size(dut, intf, buf_size)) {
7393 send_resp(dut, conn, SIGMA_ERROR,
7394 "ErrorCode,set addbareq_buff_size failed");
7395 return 0;
7396 }
7397 }
7398
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007399 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7400}
7401
7402
7403static int sta_set_wireless_60g(struct sigma_dut *dut,
7404 struct sigma_conn *conn,
7405 struct sigma_cmd *cmd)
7406{
7407 const char *dev_role = get_param(cmd, "DevRole");
7408
7409 if (!dev_role) {
7410 send_resp(dut, conn, SIGMA_INVALID,
7411 "ErrorCode,DevRole not specified");
7412 return 0;
7413 }
7414
7415 if (strcasecmp(dev_role, "PCP") == 0)
7416 return sta_set_60g_pcp(dut, conn, cmd);
7417 if (strcasecmp(dev_role, "STA") == 0)
7418 return sta_set_60g_sta(dut, conn, cmd);
7419 send_resp(dut, conn, SIGMA_INVALID,
7420 "ErrorCode,DevRole not supported");
7421 return 0;
7422}
7423
7424
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307425static int sta_set_wireless_oce(struct sigma_dut *dut, struct sigma_conn *conn,
7426 struct sigma_cmd *cmd)
7427{
7428 int status;
7429 const char *intf = get_param(cmd, "Interface");
7430 const char *val = get_param(cmd, "DevRole");
7431
7432 if (val && strcasecmp(val, "STA-CFON") == 0) {
7433 status = sta_cfon_set_wireless(dut, conn, cmd);
7434 if (status)
7435 return status;
7436 }
7437 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
7438}
7439
7440
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007441static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
7442 struct sigma_cmd *cmd)
7443{
7444 const char *val;
7445
7446 val = get_param(cmd, "Program");
7447 if (val) {
7448 if (strcasecmp(val, "11n") == 0)
7449 return cmd_sta_set_11n(dut, conn, cmd);
Amarnath Hullur Subramanyam4f860292018-01-31 03:49:35 -08007450 if (strcasecmp(val, "VHT") == 0 || strcasecmp(val, "HE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007451 return cmd_sta_set_wireless_vht(dut, conn, cmd);
7452 if (strcasecmp(val, "60ghz") == 0)
7453 return sta_set_wireless_60g(dut, conn, cmd);
Ankita Bajaj0d5825b2017-10-25 16:20:17 +05307454 if (strcasecmp(val, "OCE") == 0)
7455 return sta_set_wireless_oce(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007456 send_resp(dut, conn, SIGMA_ERROR,
7457 "ErrorCode,Program value not supported");
7458 } else {
7459 send_resp(dut, conn, SIGMA_ERROR,
7460 "ErrorCode,Program argument not available");
7461 }
7462
7463 return 0;
7464}
7465
7466
7467static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
7468 int tid)
7469{
7470 char buf[100];
7471 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
7472
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05307473 if (tid < 0 ||
7474 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
7475 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
7476 return;
7477 }
7478
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007479 /*
7480 * Two ways to ensure that addba request with a
7481 * non zero TID could be sent out. EV 117296
7482 */
7483 snprintf(buf, sizeof(buf),
7484 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
7485 tid);
7486 if (system(buf) != 0) {
7487 sigma_dut_print(dut, DUT_MSG_ERROR,
7488 "Ping did not send out");
7489 }
7490
7491 snprintf(buf, sizeof(buf),
7492 "iwconfig %s | grep Access | awk '{print $6}' > %s",
7493 intf, VI_QOS_TMP_FILE);
7494 if (system(buf) != 0)
7495 return;
7496
7497 snprintf(buf, sizeof(buf),
7498 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
7499 intf, VI_QOS_TMP_FILE);
7500 if (system(buf) != 0)
7501 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
7502
7503 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
7504 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
7505 if (system(buf) != 0) {
7506 sigma_dut_print(dut, DUT_MSG_ERROR,
7507 "VI_QOS_TEMP_FILE generation error failed");
7508 }
7509 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7510 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7511 if (system(buf) != 0) {
7512 sigma_dut_print(dut, DUT_MSG_ERROR,
7513 "VI_QOS_FILE generation failed");
7514 }
7515
7516 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
7517 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
7518 if (system(buf) != 0) {
7519 sigma_dut_print(dut, DUT_MSG_ERROR,
7520 "VI_QOS_FILE generation failed");
7521 }
7522
7523 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
7524 if (system(buf) != 0) {
7525 }
7526}
7527
7528
7529static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7530 struct sigma_cmd *cmd)
7531{
7532 const char *intf = get_param(cmd, "Interface");
7533 const char *val;
7534 int tid = 0;
7535 char buf[100];
7536
7537 val = get_param(cmd, "TID");
7538 if (val) {
7539 tid = atoi(val);
7540 if (tid)
7541 ath_sta_inject_frame(dut, intf, tid);
7542 }
7543
7544 /* Command sequence for ADDBA request on Peregrine based devices */
7545 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
7546 if (system(buf) != 0) {
7547 sigma_dut_print(dut, DUT_MSG_ERROR,
7548 "iwpriv setaddbaoper failed");
7549 }
7550
7551 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
7552 if (system(buf) != 0) {
7553 sigma_dut_print(dut, DUT_MSG_ERROR,
7554 "wifitool senddelba failed");
7555 }
7556
7557 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
7558 if (system(buf) != 0) {
7559 sigma_dut_print(dut, DUT_MSG_ERROR,
7560 "wifitool sendaddba failed");
7561 }
7562
7563 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7564
7565 return 1;
7566}
7567
7568
Lior David9981b512017-01-20 13:16:40 +02007569#ifdef __linux__
7570
7571static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
7572 int agg_size)
7573{
7574 char dir[128], buf[128];
7575 FILE *f;
7576 regex_t re;
7577 regmatch_t m[2];
7578 int rc, ret = -1, vring_id, found;
7579
7580 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
7581 sigma_dut_print(dut, DUT_MSG_ERROR,
7582 "failed to get wil6210 debugfs dir");
7583 return -1;
7584 }
7585
7586 snprintf(buf, sizeof(buf), "%s/vrings", dir);
7587 f = fopen(buf, "r");
7588 if (!f) {
7589 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007590 /* newer wil6210 driver renamed file to "rings" */
7591 snprintf(buf, sizeof(buf), "%s/rings", dir);
7592 f = fopen(buf, "r");
7593 if (!f) {
7594 sigma_dut_print(dut, DUT_MSG_ERROR,
7595 "failed to open: %s", buf);
7596 return -1;
7597 }
Lior David9981b512017-01-20 13:16:40 +02007598 }
7599
Alexei Avshalom Lazar2af1d252018-11-13 14:10:13 +02007600 /* can be either VRING tx... or RING... */
7601 if (regcomp(&re, "RING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
Lior David9981b512017-01-20 13:16:40 +02007602 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
7603 goto out;
7604 }
7605
7606 /* find TX VRING for the mac address */
7607 found = 0;
7608 while (fgets(buf, sizeof(buf), f)) {
7609 if (strcasestr(buf, dest_mac)) {
7610 found = 1;
7611 break;
7612 }
7613 }
7614
7615 if (!found) {
7616 sigma_dut_print(dut, DUT_MSG_ERROR,
7617 "no TX VRING for %s", dest_mac);
7618 goto out;
7619 }
7620
7621 /* extract VRING ID, "VRING tx_<id> = {" */
7622 if (!fgets(buf, sizeof(buf), f)) {
7623 sigma_dut_print(dut, DUT_MSG_ERROR,
7624 "no VRING start line for %s", dest_mac);
7625 goto out;
7626 }
7627
7628 rc = regexec(&re, buf, 2, m, 0);
7629 regfree(&re);
7630 if (rc || m[1].rm_so < 0) {
7631 sigma_dut_print(dut, DUT_MSG_ERROR,
7632 "no VRING TX ID for %s", dest_mac);
7633 goto out;
7634 }
7635 buf[m[1].rm_eo] = 0;
7636 vring_id = atoi(&buf[m[1].rm_so]);
7637
7638 /* send the addba command */
7639 fclose(f);
7640 snprintf(buf, sizeof(buf), "%s/back", dir);
7641 f = fopen(buf, "w");
7642 if (!f) {
7643 sigma_dut_print(dut, DUT_MSG_ERROR,
7644 "failed to open: %s", buf);
7645 return -1;
7646 }
7647
7648 fprintf(f, "add %d %d\n", vring_id, agg_size);
7649
7650 ret = 0;
7651
7652out:
7653 fclose(f);
7654
7655 return ret;
7656}
7657
7658
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007659static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
7660 struct sigma_cmd *cmd)
7661{
7662 const char *val;
7663 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007664
7665 val = get_param(cmd, "TID");
7666 if (val) {
7667 tid = atoi(val);
7668 if (tid != 0) {
7669 sigma_dut_print(dut, DUT_MSG_ERROR,
7670 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
7671 tid);
7672 }
7673 }
7674
7675 val = get_param(cmd, "Dest_mac");
7676 if (!val) {
7677 sigma_dut_print(dut, DUT_MSG_ERROR,
7678 "Currently not supporting addba for 60G without Dest_mac");
7679 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
7680 }
7681
Lior David9981b512017-01-20 13:16:40 +02007682 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007683 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007684
7685 return 1;
7686}
7687
Lior David9981b512017-01-20 13:16:40 +02007688#endif /* __linux__ */
7689
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007690
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007691static int wcn_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7692 struct sigma_cmd *cmd)
7693{
7694#ifdef NL80211_SUPPORT
7695 const char *intf = get_param(cmd, "Interface");
7696 const char *val;
7697 int tid = -1;
7698 int bufsize = 64;
7699 struct nl_msg *msg;
7700 int ret = 0;
7701 struct nlattr *params;
7702 int ifindex;
7703
7704 val = get_param(cmd, "TID");
7705 if (val)
7706 tid = atoi(val);
7707
7708 if (tid == -1) {
7709 send_resp(dut, conn, SIGMA_ERROR,
7710 "ErrorCode,sta_send_addba tid invalid");
7711 return 0;
7712 }
7713
7714 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
7715
7716 ifindex = if_nametoindex(intf);
7717 if (ifindex == 0) {
7718 sigma_dut_print(dut, DUT_MSG_ERROR,
7719 "%s: Index for interface %s failed",
7720 __func__, intf);
7721 send_resp(dut, conn, SIGMA_ERROR,
7722 "ErrorCode,sta_send_addba interface invalid");
7723 return 0;
7724 }
7725
7726 if (!(msg = nl80211_drv_msg(dut, dut->nl_ctx, ifindex, 0,
7727 NL80211_CMD_VENDOR)) ||
7728 nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex) ||
7729 nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
7730 nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
7731 QCA_NL80211_VENDOR_SUBCMD_WIFI_TEST_CONFIGURATION) ||
7732 !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
7733 nla_put_u8(msg,
7734 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADD_DEL_BA_SESSION,
7735 QCA_WLAN_ADD_BA) ||
7736 nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_BA_TID,
7737 tid) ||
Kiran Kumar Lokere26e27582018-08-01 16:18:34 -07007738 nla_put_u16(msg,
7739 QCA_WLAN_VENDOR_ATTR_WIFI_TEST_CONFIG_ADDBA_BUFF_SIZE,
7740 bufsize)) {
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007741 sigma_dut_print(dut, DUT_MSG_ERROR,
7742 "%s: err in adding vendor_cmd and vendor_data",
7743 __func__);
7744 nlmsg_free(msg);
7745 send_resp(dut, conn, SIGMA_ERROR,
7746 "ErrorCode,sta_send_addba err in adding vendor_cmd and vendor_data");
7747 return 0;
7748 }
7749 nla_nest_end(msg, params);
7750
7751 ret = send_and_recv_msgs(dut, dut->nl_ctx, msg, NULL, NULL);
7752 if (ret) {
7753 sigma_dut_print(dut, DUT_MSG_ERROR,
7754 "%s: err in send_and_recv_msgs, ret=%d",
7755 __func__, ret);
Sunil Dutt30605592018-05-04 20:35:50 +05307756 if (ret == -EOPNOTSUPP)
7757 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007758 send_resp(dut, conn, SIGMA_ERROR,
7759 "ErrorCode,sta_send_addba err in send_and_recv_msgs");
7760 return 0;
7761 }
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007762#else /* NL80211_SUPPORT */
7763 sigma_dut_print(dut, DUT_MSG_ERROR,
7764 "sta_send_addba not supported without NL80211_SUPPORT defined");
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007765#endif /* NL80211_SUPPORT */
Sunil Dutt30605592018-05-04 20:35:50 +05307766
7767 return 1;
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007768}
7769
7770
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007771static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
7772 struct sigma_cmd *cmd)
7773{
7774 switch (get_driver_type()) {
7775 case DRIVER_ATHEROS:
7776 return ath_sta_send_addba(dut, conn, cmd);
Amarnath Hullur Subramanyama72c0162018-02-27 14:49:09 -08007777 case DRIVER_WCN:
7778 return wcn_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007779#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007780 case DRIVER_WIL6210:
7781 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02007782#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007783 default:
7784 /*
7785 * There is no driver specific implementation for other drivers.
7786 * Ignore the command and report COMPLETE since the following
7787 * throughput test operation will end up sending ADDBA anyway.
7788 */
7789 return 1;
7790 }
7791}
7792
7793
7794int inject_eth_frame(int s, const void *data, size_t len,
7795 unsigned short ethtype, char *dst, char *src)
7796{
7797 struct iovec iov[4] = {
7798 {
7799 .iov_base = dst,
7800 .iov_len = ETH_ALEN,
7801 },
7802 {
7803 .iov_base = src,
7804 .iov_len = ETH_ALEN,
7805 },
7806 {
7807 .iov_base = &ethtype,
7808 .iov_len = sizeof(unsigned short),
7809 },
7810 {
7811 .iov_base = (void *) data,
7812 .iov_len = len,
7813 }
7814 };
7815 struct msghdr msg = {
7816 .msg_name = NULL,
7817 .msg_namelen = 0,
7818 .msg_iov = iov,
7819 .msg_iovlen = 4,
7820 .msg_control = NULL,
7821 .msg_controllen = 0,
7822 .msg_flags = 0,
7823 };
7824
7825 return sendmsg(s, &msg, 0);
7826}
7827
7828#if defined(__linux__) || defined(__QNXNTO__)
7829
7830int inject_frame(int s, const void *data, size_t len, int encrypt)
7831{
7832#define IEEE80211_RADIOTAP_F_WEP 0x04
7833#define IEEE80211_RADIOTAP_F_FRAG 0x08
7834 unsigned char rtap_hdr[] = {
7835 0x00, 0x00, /* radiotap version */
7836 0x0e, 0x00, /* radiotap length */
7837 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
7838 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
7839 0x00, /* padding */
7840 0x00, 0x00, /* RX and TX flags to indicate that */
7841 0x00, 0x00, /* this is the injected frame directly */
7842 };
7843 struct iovec iov[2] = {
7844 {
7845 .iov_base = &rtap_hdr,
7846 .iov_len = sizeof(rtap_hdr),
7847 },
7848 {
7849 .iov_base = (void *) data,
7850 .iov_len = len,
7851 }
7852 };
7853 struct msghdr msg = {
7854 .msg_name = NULL,
7855 .msg_namelen = 0,
7856 .msg_iov = iov,
7857 .msg_iovlen = 2,
7858 .msg_control = NULL,
7859 .msg_controllen = 0,
7860 .msg_flags = 0,
7861 };
7862
7863 if (encrypt)
7864 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
7865
7866 return sendmsg(s, &msg, 0);
7867}
7868
7869
7870int open_monitor(const char *ifname)
7871{
7872#ifdef __QNXNTO__
7873 struct sockaddr_dl ll;
7874 int s;
7875
7876 memset(&ll, 0, sizeof(ll));
7877 ll.sdl_family = AF_LINK;
7878 ll.sdl_index = if_nametoindex(ifname);
7879 if (ll.sdl_index == 0) {
7880 perror("if_nametoindex");
7881 return -1;
7882 }
7883 s = socket(PF_INET, SOCK_RAW, 0);
7884#else /* __QNXNTO__ */
7885 struct sockaddr_ll ll;
7886 int s;
7887
7888 memset(&ll, 0, sizeof(ll));
7889 ll.sll_family = AF_PACKET;
7890 ll.sll_ifindex = if_nametoindex(ifname);
7891 if (ll.sll_ifindex == 0) {
7892 perror("if_nametoindex");
7893 return -1;
7894 }
7895 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
7896#endif /* __QNXNTO__ */
7897 if (s < 0) {
7898 perror("socket[PF_PACKET,SOCK_RAW]");
7899 return -1;
7900 }
7901
7902 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
7903 perror("monitor socket bind");
7904 close(s);
7905 return -1;
7906 }
7907
7908 return s;
7909}
7910
7911
7912static int hex2num(char c)
7913{
7914 if (c >= '0' && c <= '9')
7915 return c - '0';
7916 if (c >= 'a' && c <= 'f')
7917 return c - 'a' + 10;
7918 if (c >= 'A' && c <= 'F')
7919 return c - 'A' + 10;
7920 return -1;
7921}
7922
7923
7924int hwaddr_aton(const char *txt, unsigned char *addr)
7925{
7926 int i;
7927
7928 for (i = 0; i < 6; i++) {
7929 int a, b;
7930
7931 a = hex2num(*txt++);
7932 if (a < 0)
7933 return -1;
7934 b = hex2num(*txt++);
7935 if (b < 0)
7936 return -1;
7937 *addr++ = (a << 4) | b;
7938 if (i < 5 && *txt++ != ':')
7939 return -1;
7940 }
7941
7942 return 0;
7943}
7944
7945#endif /* defined(__linux__) || defined(__QNXNTO__) */
7946
7947enum send_frame_type {
7948 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
7949};
7950enum send_frame_protection {
7951 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
7952};
7953
7954
7955static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
7956 enum send_frame_type frame,
7957 enum send_frame_protection protected,
7958 const char *dest)
7959{
7960#ifdef __linux__
7961 unsigned char buf[1000], *pos;
7962 int s, res;
7963 char bssid[20], addr[20];
7964 char result[32], ssid[100];
7965 size_t ssid_len;
7966
7967 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
7968 sizeof(result)) < 0 ||
7969 strncmp(result, "COMPLETED", 9) != 0) {
7970 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
7971 return 0;
7972 }
7973
7974 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
7975 < 0) {
7976 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7977 "current BSSID");
7978 return 0;
7979 }
7980
7981 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
7982 < 0) {
7983 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7984 "own MAC address");
7985 return 0;
7986 }
7987
7988 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
7989 < 0) {
7990 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
7991 "current SSID");
7992 return 0;
7993 }
7994 ssid_len = strlen(ssid);
7995
7996 pos = buf;
7997
7998 /* Frame Control */
7999 switch (frame) {
8000 case DISASSOC:
8001 *pos++ = 0xa0;
8002 break;
8003 case DEAUTH:
8004 *pos++ = 0xc0;
8005 break;
8006 case SAQUERY:
8007 *pos++ = 0xd0;
8008 break;
8009 case AUTH:
8010 *pos++ = 0xb0;
8011 break;
8012 case ASSOCREQ:
8013 *pos++ = 0x00;
8014 break;
8015 case REASSOCREQ:
8016 *pos++ = 0x20;
8017 break;
8018 case DLS_REQ:
8019 *pos++ = 0xd0;
8020 break;
8021 }
8022
8023 if (protected == INCORRECT_KEY)
8024 *pos++ = 0x40; /* Set Protected field to 1 */
8025 else
8026 *pos++ = 0x00;
8027
8028 /* Duration */
8029 *pos++ = 0x00;
8030 *pos++ = 0x00;
8031
8032 /* addr1 = DA (current AP) */
8033 hwaddr_aton(bssid, pos);
8034 pos += 6;
8035 /* addr2 = SA (own address) */
8036 hwaddr_aton(addr, pos);
8037 pos += 6;
8038 /* addr3 = BSSID (current AP) */
8039 hwaddr_aton(bssid, pos);
8040 pos += 6;
8041
8042 /* Seq# (to be filled by driver/mac80211) */
8043 *pos++ = 0x00;
8044 *pos++ = 0x00;
8045
8046 if (protected == INCORRECT_KEY) {
8047 /* CCMP parameters */
8048 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
8049 pos += 8;
8050 }
8051
8052 if (protected == INCORRECT_KEY) {
8053 switch (frame) {
8054 case DEAUTH:
8055 /* Reason code (encrypted) */
8056 memcpy(pos, "\xa7\x39", 2);
8057 pos += 2;
8058 break;
8059 case DISASSOC:
8060 /* Reason code (encrypted) */
8061 memcpy(pos, "\xa7\x39", 2);
8062 pos += 2;
8063 break;
8064 case SAQUERY:
8065 /* Category|Action|TransID (encrypted) */
8066 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
8067 pos += 4;
8068 break;
8069 default:
8070 return -1;
8071 }
8072
8073 /* CCMP MIC */
8074 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
8075 pos += 8;
8076 } else {
8077 switch (frame) {
8078 case DEAUTH:
8079 /* reason code = 8 */
8080 *pos++ = 0x08;
8081 *pos++ = 0x00;
8082 break;
8083 case DISASSOC:
8084 /* reason code = 8 */
8085 *pos++ = 0x08;
8086 *pos++ = 0x00;
8087 break;
8088 case SAQUERY:
8089 /* Category - SA Query */
8090 *pos++ = 0x08;
8091 /* SA query Action - Request */
8092 *pos++ = 0x00;
8093 /* Transaction ID */
8094 *pos++ = 0x12;
8095 *pos++ = 0x34;
8096 break;
8097 case AUTH:
8098 /* Auth Alg (Open) */
8099 *pos++ = 0x00;
8100 *pos++ = 0x00;
8101 /* Seq# */
8102 *pos++ = 0x01;
8103 *pos++ = 0x00;
8104 /* Status code */
8105 *pos++ = 0x00;
8106 *pos++ = 0x00;
8107 break;
8108 case ASSOCREQ:
8109 /* Capability Information */
8110 *pos++ = 0x31;
8111 *pos++ = 0x04;
8112 /* Listen Interval */
8113 *pos++ = 0x0a;
8114 *pos++ = 0x00;
8115 /* SSID */
8116 *pos++ = 0x00;
8117 *pos++ = ssid_len;
8118 memcpy(pos, ssid, ssid_len);
8119 pos += ssid_len;
8120 /* Supported Rates */
8121 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8122 10);
8123 pos += 10;
8124 /* Extended Supported Rates */
8125 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8126 pos += 6;
8127 /* RSN */
8128 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8129 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8130 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8131 pos += 28;
8132 break;
8133 case REASSOCREQ:
8134 /* Capability Information */
8135 *pos++ = 0x31;
8136 *pos++ = 0x04;
8137 /* Listen Interval */
8138 *pos++ = 0x0a;
8139 *pos++ = 0x00;
8140 /* Current AP */
8141 hwaddr_aton(bssid, pos);
8142 pos += 6;
8143 /* SSID */
8144 *pos++ = 0x00;
8145 *pos++ = ssid_len;
8146 memcpy(pos, ssid, ssid_len);
8147 pos += ssid_len;
8148 /* Supported Rates */
8149 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
8150 10);
8151 pos += 10;
8152 /* Extended Supported Rates */
8153 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
8154 pos += 6;
8155 /* RSN */
8156 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
8157 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
8158 "\x00\x00\x00\x00\x0f\xac\x06", 28);
8159 pos += 28;
8160 break;
8161 case DLS_REQ:
8162 /* Category - DLS */
8163 *pos++ = 0x02;
8164 /* DLS Action - Request */
8165 *pos++ = 0x00;
8166 /* Destination MACAddress */
8167 if (dest)
8168 hwaddr_aton(dest, pos);
8169 else
8170 memset(pos, 0, 6);
8171 pos += 6;
8172 /* Source MACAddress */
8173 hwaddr_aton(addr, pos);
8174 pos += 6;
8175 /* Capability Information */
8176 *pos++ = 0x10; /* Privacy */
8177 *pos++ = 0x06; /* QoS */
8178 /* DLS Timeout Value */
8179 *pos++ = 0x00;
8180 *pos++ = 0x01;
8181 /* Supported rates */
8182 *pos++ = 0x01;
8183 *pos++ = 0x08;
8184 *pos++ = 0x0c; /* 6 Mbps */
8185 *pos++ = 0x12; /* 9 Mbps */
8186 *pos++ = 0x18; /* 12 Mbps */
8187 *pos++ = 0x24; /* 18 Mbps */
8188 *pos++ = 0x30; /* 24 Mbps */
8189 *pos++ = 0x48; /* 36 Mbps */
8190 *pos++ = 0x60; /* 48 Mbps */
8191 *pos++ = 0x6c; /* 54 Mbps */
8192 /* TODO: Extended Supported Rates */
8193 /* TODO: HT Capabilities */
8194 break;
8195 }
8196 }
8197
8198 s = open_monitor("sigmadut");
8199 if (s < 0) {
8200 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8201 "monitor socket");
8202 return 0;
8203 }
8204
8205 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
8206 if (res < 0) {
8207 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8208 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308209 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008210 return 0;
8211 }
8212 if (res < pos - buf) {
8213 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
8214 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308215 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008216 return 0;
8217 }
8218
8219 close(s);
8220
8221 return 1;
8222#else /* __linux__ */
8223 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
8224 "yet supported");
8225 return 0;
8226#endif /* __linux__ */
8227}
8228
8229
8230static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
8231 struct sigma_conn *conn,
8232 struct sigma_cmd *cmd)
8233{
8234 const char *intf = get_param(cmd, "Interface");
8235 const char *sta, *val;
8236 unsigned char addr[ETH_ALEN];
8237 char buf[100];
8238
8239 sta = get_param(cmd, "peer");
8240 if (sta == NULL)
8241 sta = get_param(cmd, "station");
8242 if (sta == NULL) {
8243 send_resp(dut, conn, SIGMA_ERROR,
8244 "ErrorCode,Missing peer address");
8245 return 0;
8246 }
8247 if (hwaddr_aton(sta, addr) < 0) {
8248 send_resp(dut, conn, SIGMA_ERROR,
8249 "ErrorCode,Invalid peer address");
8250 return 0;
8251 }
8252
8253 val = get_param(cmd, "type");
8254 if (val == NULL)
8255 return -1;
8256
8257 if (strcasecmp(val, "DISCOVERY") == 0) {
8258 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
8259 if (wpa_command(intf, buf) < 0) {
8260 send_resp(dut, conn, SIGMA_ERROR,
8261 "ErrorCode,Failed to send TDLS discovery");
8262 return 0;
8263 }
8264 return 1;
8265 }
8266
8267 if (strcasecmp(val, "SETUP") == 0) {
8268 int status = 0, timeout = 0;
8269
8270 val = get_param(cmd, "Status");
8271 if (val)
8272 status = atoi(val);
8273
8274 val = get_param(cmd, "Timeout");
8275 if (val)
8276 timeout = atoi(val);
8277
8278 if (status != 0 && status != 37) {
8279 send_resp(dut, conn, SIGMA_ERROR,
8280 "ErrorCode,Unsupported status value");
8281 return 0;
8282 }
8283
8284 if (timeout != 0 && timeout != 301) {
8285 send_resp(dut, conn, SIGMA_ERROR,
8286 "ErrorCode,Unsupported timeout value");
8287 return 0;
8288 }
8289
8290 if (status && timeout) {
8291 send_resp(dut, conn, SIGMA_ERROR,
8292 "ErrorCode,Unsupported timeout+status "
8293 "combination");
8294 return 0;
8295 }
8296
8297 if (status == 37 &&
8298 wpa_command(intf, "SET tdls_testing 0x200")) {
8299 send_resp(dut, conn, SIGMA_ERROR,
8300 "ErrorCode,Failed to enable "
8301 "decline setup response test mode");
8302 return 0;
8303 }
8304
8305 if (timeout == 301) {
8306 int res;
8307 if (dut->no_tpk_expiration)
8308 res = wpa_command(intf,
8309 "SET tdls_testing 0x108");
8310 else
8311 res = wpa_command(intf,
8312 "SET tdls_testing 0x8");
8313 if (res) {
8314 send_resp(dut, conn, SIGMA_ERROR,
8315 "ErrorCode,Failed to set short TPK "
8316 "lifetime");
8317 return 0;
8318 }
8319 }
8320
8321 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
8322 if (wpa_command(intf, buf) < 0) {
8323 send_resp(dut, conn, SIGMA_ERROR,
8324 "ErrorCode,Failed to send TDLS setup");
8325 return 0;
8326 }
8327 return 1;
8328 }
8329
8330 if (strcasecmp(val, "TEARDOWN") == 0) {
8331 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
8332 if (wpa_command(intf, buf) < 0) {
8333 send_resp(dut, conn, SIGMA_ERROR,
8334 "ErrorCode,Failed to send TDLS teardown");
8335 return 0;
8336 }
8337 return 1;
8338 }
8339
8340 send_resp(dut, conn, SIGMA_ERROR,
8341 "ErrorCode,Unsupported TDLS frame");
8342 return 0;
8343}
8344
8345
8346static int sta_ap_known(const char *ifname, const char *bssid)
8347{
8348 char buf[4096];
8349
Jouni Malinendd32f192018-09-15 02:55:19 +03008350 snprintf(buf, sizeof(buf), "BSS MASK=1 %s", bssid);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008351 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
8352 return 0;
8353 if (strncmp(buf, "id=", 3) != 0)
8354 return 0;
8355 return 1;
8356}
8357
8358
8359static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
8360 const char *bssid)
8361{
8362 int res;
8363 struct wpa_ctrl *ctrl;
8364 char buf[256];
8365
8366 if (sta_ap_known(ifname, bssid))
8367 return 0;
8368 sigma_dut_print(dut, DUT_MSG_DEBUG,
8369 "AP not in BSS table - start scan");
8370
8371 ctrl = open_wpa_mon(ifname);
8372 if (ctrl == NULL) {
8373 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8374 "wpa_supplicant monitor connection");
8375 return -1;
8376 }
8377
8378 if (wpa_command(ifname, "SCAN") < 0) {
8379 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
8380 wpa_ctrl_detach(ctrl);
8381 wpa_ctrl_close(ctrl);
8382 return -1;
8383 }
8384
8385 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
8386 buf, sizeof(buf));
8387
8388 wpa_ctrl_detach(ctrl);
8389 wpa_ctrl_close(ctrl);
8390
8391 if (res < 0) {
8392 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
8393 return -1;
8394 }
8395
8396 if (sta_ap_known(ifname, bssid))
8397 return 0;
8398 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
8399 return -1;
8400}
8401
8402
8403static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
8404 struct sigma_conn *conn,
8405 struct sigma_cmd *cmd,
8406 const char *intf)
8407{
8408 char buf[200];
8409
8410 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
8411 if (system(buf) != 0) {
8412 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
8413 "ndsend");
8414 return 0;
8415 }
8416
8417 return 1;
8418}
8419
8420
8421static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
8422 struct sigma_conn *conn,
8423 struct sigma_cmd *cmd,
8424 const char *intf)
8425{
8426 char buf[200];
8427 const char *ip = get_param(cmd, "SenderIP");
8428
Peng Xu26b356d2017-10-04 17:58:16 -07008429 if (!ip)
8430 return 0;
8431
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008432 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
8433 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8434 if (system(buf) == 0) {
8435 sigma_dut_print(dut, DUT_MSG_INFO,
8436 "Neighbor Solicitation got a response "
8437 "for %s@%s", ip, intf);
8438 }
8439
8440 return 1;
8441}
8442
8443
8444static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
8445 struct sigma_conn *conn,
8446 struct sigma_cmd *cmd,
8447 const char *ifname)
8448{
8449 char buf[200];
8450 const char *ip = get_param(cmd, "SenderIP");
8451
8452 if (ip == NULL) {
8453 send_resp(dut, conn, SIGMA_ERROR,
8454 "ErrorCode,Missing SenderIP parameter");
8455 return 0;
8456 }
8457 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
8458 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8459 if (system(buf) != 0) {
8460 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
8461 "for %s@%s", ip, ifname);
8462 }
8463
8464 return 1;
8465}
8466
8467
8468static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
8469 struct sigma_conn *conn,
8470 struct sigma_cmd *cmd,
8471 const char *ifname)
8472{
8473 char buf[200];
8474 char ip[16];
8475 int s;
Peng Xub3756882017-10-04 14:39:09 -07008476 struct ifreq ifr;
8477 struct sockaddr_in saddr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008478
8479 s = socket(PF_INET, SOCK_DGRAM, 0);
Peng Xub3756882017-10-04 14:39:09 -07008480 if (s < 0) {
8481 perror("socket");
8482 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008483 }
8484
Peng Xub3756882017-10-04 14:39:09 -07008485 memset(&ifr, 0, sizeof(ifr));
8486 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
8487 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
8488 sigma_dut_print(dut, DUT_MSG_INFO,
8489 "Failed to get %s IP address: %s",
8490 ifname, strerror(errno));
8491 close(s);
8492 return -1;
8493 }
8494 close(s);
8495
8496 memcpy(&saddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
8497 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
8498
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008499 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
8500 ip);
8501 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
8502 if (system(buf) != 0) {
8503 }
8504
8505 return 1;
8506}
8507
8508
8509static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
8510 struct sigma_conn *conn,
8511 struct sigma_cmd *cmd,
8512 const char *ifname)
8513{
8514 char buf[200], addr[20];
8515 char dst[ETH_ALEN], src[ETH_ALEN];
8516 short ethtype = htons(ETH_P_ARP);
8517 char *pos;
8518 int s, res;
8519 const char *val;
8520 struct sockaddr_in taddr;
8521
8522 val = get_param(cmd, "dest");
8523 if (val)
8524 hwaddr_aton(val, (unsigned char *) dst);
8525
8526 val = get_param(cmd, "DestIP");
8527 if (val)
8528 inet_aton(val, &taddr.sin_addr);
Peng Xu151c9e12017-10-04 14:39:09 -07008529 else
8530 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008531
8532 if (get_wpa_status(get_station_ifname(), "address", addr,
8533 sizeof(addr)) < 0)
8534 return -2;
8535 hwaddr_aton(addr, (unsigned char *) src);
8536
8537 pos = buf;
8538 *pos++ = 0x00;
8539 *pos++ = 0x01;
8540 *pos++ = 0x08;
8541 *pos++ = 0x00;
8542 *pos++ = 0x06;
8543 *pos++ = 0x04;
8544 *pos++ = 0x00;
8545 *pos++ = 0x02;
8546 memcpy(pos, src, ETH_ALEN);
8547 pos += ETH_ALEN;
8548 memcpy(pos, &taddr.sin_addr, 4);
8549 pos += 4;
8550 memcpy(pos, dst, ETH_ALEN);
8551 pos += ETH_ALEN;
8552 memcpy(pos, &taddr.sin_addr, 4);
8553 pos += 4;
8554
8555 s = open_monitor(get_station_ifname());
8556 if (s < 0) {
8557 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
8558 "monitor socket");
8559 return 0;
8560 }
8561
8562 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
8563 if (res < 0) {
8564 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
8565 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05308566 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008567 return 0;
8568 }
8569
8570 close(s);
8571
8572 return 1;
8573}
8574
8575
8576static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
8577 struct sigma_conn *conn,
8578 struct sigma_cmd *cmd,
8579 const char *intf, const char *dest)
8580{
8581 char buf[100];
8582
8583 if (if_nametoindex("sigmadut") == 0) {
8584 snprintf(buf, sizeof(buf),
8585 "iw dev %s interface add sigmadut type monitor",
8586 get_station_ifname());
8587 if (system(buf) != 0 ||
8588 if_nametoindex("sigmadut") == 0) {
8589 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
8590 "monitor interface with '%s'", buf);
8591 return -2;
8592 }
8593 }
8594
8595 if (system("ifconfig sigmadut up") != 0) {
8596 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
8597 "monitor interface up");
8598 return -2;
8599 }
8600
8601 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
8602}
8603
8604
8605static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
8606 struct sigma_conn *conn,
8607 struct sigma_cmd *cmd)
8608{
8609 const char *intf = get_param(cmd, "Interface");
8610 const char *dest = get_param(cmd, "Dest");
8611 const char *type = get_param(cmd, "FrameName");
8612 const char *val;
8613 char buf[200], *pos, *end;
8614 int count, count2;
8615
8616 if (type == NULL)
8617 type = get_param(cmd, "Type");
8618
8619 if (intf == NULL || dest == NULL || type == NULL)
8620 return -1;
8621
8622 if (strcasecmp(type, "NeighAdv") == 0)
8623 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
8624
8625 if (strcasecmp(type, "NeighSolicitReq") == 0)
8626 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
8627
8628 if (strcasecmp(type, "ARPProbe") == 0)
8629 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
8630
8631 if (strcasecmp(type, "ARPAnnounce") == 0)
8632 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
8633
8634 if (strcasecmp(type, "ARPReply") == 0)
8635 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
8636
8637 if (strcasecmp(type, "DLS-request") == 0 ||
8638 strcasecmp(type, "DLSrequest") == 0)
8639 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
8640 dest);
8641
8642 if (strcasecmp(type, "ANQPQuery") != 0 &&
8643 strcasecmp(type, "Query") != 0) {
8644 send_resp(dut, conn, SIGMA_ERROR,
8645 "ErrorCode,Unsupported HS 2.0 send frame type");
8646 return 0;
8647 }
8648
8649 if (sta_scan_ap(dut, intf, dest) < 0) {
8650 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
8651 "the requested AP");
8652 return 0;
8653 }
8654
8655 pos = buf;
8656 end = buf + sizeof(buf);
8657 count = 0;
8658 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
8659
8660 val = get_param(cmd, "ANQP_CAP_LIST");
8661 if (val && atoi(val)) {
8662 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
8663 count++;
8664 }
8665
8666 val = get_param(cmd, "VENUE_NAME");
8667 if (val && atoi(val)) {
8668 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
8669 count++;
8670 }
8671
8672 val = get_param(cmd, "NETWORK_AUTH_TYPE");
8673 if (val && atoi(val)) {
8674 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
8675 count++;
8676 }
8677
8678 val = get_param(cmd, "ROAMING_CONS");
8679 if (val && atoi(val)) {
8680 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
8681 count++;
8682 }
8683
8684 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
8685 if (val && atoi(val)) {
8686 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
8687 count++;
8688 }
8689
8690 val = get_param(cmd, "NAI_REALM_LIST");
8691 if (val && atoi(val)) {
8692 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
8693 count++;
8694 }
8695
8696 val = get_param(cmd, "3GPP_INFO");
8697 if (val && atoi(val)) {
8698 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
8699 count++;
8700 }
8701
8702 val = get_param(cmd, "DOMAIN_LIST");
8703 if (val && atoi(val)) {
8704 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
8705 count++;
8706 }
8707
Jouni Malinen34cf9532018-04-29 19:26:33 +03008708 val = get_param(cmd, "Venue_URL");
8709 if (val && atoi(val)) {
8710 pos += snprintf(pos, end - pos, "%s277", count > 0 ? "," : "");
8711 count++;
8712 }
8713
Jouni Malinend3bca5d2018-04-29 17:25:23 +03008714 val = get_param(cmd, "Advice_Of_Charge");
8715 if (val && atoi(val)) {
8716 pos += snprintf(pos, end - pos, "%s278", count > 0 ? "," : "");
8717 count++;
8718 }
8719
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008720 if (count && wpa_command(intf, buf)) {
8721 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
8722 return 0;
8723 }
8724
8725 pos = buf;
8726 end = buf + sizeof(buf);
8727 count2 = 0;
8728 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
8729
8730 val = get_param(cmd, "HS_CAP_LIST");
8731 if (val && atoi(val)) {
8732 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
8733 count2++;
8734 }
8735
8736 val = get_param(cmd, "OPER_NAME");
8737 if (val && atoi(val)) {
8738 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
8739 count2++;
8740 }
8741
8742 val = get_param(cmd, "WAN_METRICS");
8743 if (!val)
8744 val = get_param(cmd, "WAN_MAT");
8745 if (!val)
8746 val = get_param(cmd, "WAN_MET");
8747 if (val && atoi(val)) {
8748 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
8749 count2++;
8750 }
8751
8752 val = get_param(cmd, "CONNECTION_CAPABILITY");
8753 if (val && atoi(val)) {
8754 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
8755 count2++;
8756 }
8757
8758 val = get_param(cmd, "OP_CLASS");
8759 if (val && atoi(val)) {
8760 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
8761 count2++;
8762 }
8763
8764 val = get_param(cmd, "OSU_PROVIDER_LIST");
8765 if (val && atoi(val)) {
8766 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
8767 count2++;
8768 }
8769
Jouni Malinenf67afec2018-04-29 19:24:58 +03008770 val = get_param(cmd, "OPER_ICON_METADATA");
8771 if (!val)
8772 val = get_param(cmd, "OPERATOR_ICON_METADATA");
8773 if (val && atoi(val)) {
8774 pos += snprintf(pos, end - pos, "%s12", count2 > 0 ? "," : "");
8775 count2++;
8776 }
8777
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008778 if (count && count2) {
8779 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
8780 "second query");
8781 sleep(1);
8782 }
8783
8784 if (count2 && wpa_command(intf, buf)) {
8785 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
8786 "failed");
8787 return 0;
8788 }
8789
8790 val = get_param(cmd, "NAI_HOME_REALM_LIST");
8791 if (val) {
8792 if (count || count2) {
8793 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8794 "sending out second query");
8795 sleep(1);
8796 }
8797
8798 if (strcmp(val, "1") == 0)
8799 val = "mail.example.com";
8800 snprintf(buf, end - pos,
8801 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
8802 dest, val);
8803 if (wpa_command(intf, buf)) {
8804 send_resp(dut, conn, SIGMA_ERROR,
8805 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
8806 "failed");
8807 return 0;
8808 }
8809 }
8810
8811 val = get_param(cmd, "ICON_REQUEST");
8812 if (val) {
8813 if (count || count2) {
8814 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
8815 "sending out second query");
8816 sleep(1);
8817 }
8818
8819 snprintf(buf, end - pos,
8820 "HS20_ICON_REQUEST %s %s", dest, val);
8821 if (wpa_command(intf, buf)) {
8822 send_resp(dut, conn, SIGMA_ERROR,
8823 "ErrorCode,HS20_ICON_REQUEST failed");
8824 return 0;
8825 }
8826 }
8827
8828 return 1;
8829}
8830
8831
8832static int ath_sta_send_frame_vht(struct sigma_dut *dut,
8833 struct sigma_conn *conn,
8834 struct sigma_cmd *cmd)
8835{
8836 const char *val;
8837 char *ifname;
8838 char buf[100];
8839 int chwidth, nss;
8840
8841 val = get_param(cmd, "framename");
8842 if (!val)
8843 return -1;
8844 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
8845
8846 /* Command sequence to generate Op mode notification */
8847 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
8848 ifname = get_station_ifname();
8849
8850 /* Disable STBC */
8851 snprintf(buf, sizeof(buf),
8852 "iwpriv %s tx_stbc 0", ifname);
8853 if (system(buf) != 0) {
8854 sigma_dut_print(dut, DUT_MSG_ERROR,
8855 "iwpriv tx_stbc 0 failed!");
8856 }
8857
8858 /* Extract Channel width */
8859 val = get_param(cmd, "Channel_width");
8860 if (val) {
8861 switch (atoi(val)) {
8862 case 20:
8863 chwidth = 0;
8864 break;
8865 case 40:
8866 chwidth = 1;
8867 break;
8868 case 80:
8869 chwidth = 2;
8870 break;
8871 case 160:
8872 chwidth = 3;
8873 break;
8874 default:
8875 chwidth = 2;
8876 break;
8877 }
8878
8879 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
8880 ifname, chwidth);
8881 if (system(buf) != 0) {
8882 sigma_dut_print(dut, DUT_MSG_ERROR,
8883 "iwpriv chwidth failed!");
8884 }
8885 }
8886
8887 /* Extract NSS */
8888 val = get_param(cmd, "NSS");
8889 if (val) {
8890 switch (atoi(val)) {
8891 case 1:
8892 nss = 1;
8893 break;
8894 case 2:
8895 nss = 3;
8896 break;
8897 case 3:
8898 nss = 7;
8899 break;
8900 default:
8901 /* We do not support NSS > 3 */
8902 nss = 3;
8903 break;
8904 }
8905 snprintf(buf, sizeof(buf),
8906 "iwpriv %s rxchainmask %d", ifname, nss);
8907 if (system(buf) != 0) {
8908 sigma_dut_print(dut, DUT_MSG_ERROR,
8909 "iwpriv rxchainmask failed!");
8910 }
8911 }
8912
8913 /* Opmode notify */
8914 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
8915 if (system(buf) != 0) {
8916 sigma_dut_print(dut, DUT_MSG_ERROR,
8917 "iwpriv opmode_notify failed!");
8918 } else {
8919 sigma_dut_print(dut, DUT_MSG_INFO,
8920 "Sent out the notify frame!");
8921 }
8922 }
8923
8924 return 1;
8925}
8926
8927
8928static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
8929 struct sigma_conn *conn,
8930 struct sigma_cmd *cmd)
8931{
8932 switch (get_driver_type()) {
8933 case DRIVER_ATHEROS:
8934 return ath_sta_send_frame_vht(dut, conn, cmd);
8935 default:
8936 send_resp(dut, conn, SIGMA_ERROR,
8937 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
8938 return 0;
8939 }
8940}
8941
8942
Lior David0fe101e2017-03-09 16:09:50 +02008943#ifdef __linux__
8944int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
8945 struct sigma_cmd *cmd)
8946{
8947 const char *frame_name = get_param(cmd, "framename");
8948 const char *mac = get_param(cmd, "dest_mac");
8949
8950 if (!frame_name || !mac) {
8951 sigma_dut_print(dut, DUT_MSG_ERROR,
8952 "framename and dest_mac must be provided");
8953 return -1;
8954 }
8955
8956 if (strcasecmp(frame_name, "brp") == 0) {
8957 const char *l_rx = get_param(cmd, "L-RX");
8958 int l_rx_i;
8959
8960 if (!l_rx) {
8961 sigma_dut_print(dut, DUT_MSG_ERROR,
8962 "L-RX must be provided");
8963 return -1;
8964 }
8965 l_rx_i = atoi(l_rx);
8966
8967 sigma_dut_print(dut, DUT_MSG_INFO,
8968 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
8969 mac, l_rx);
8970 if (l_rx_i != 16) {
8971 sigma_dut_print(dut, DUT_MSG_ERROR,
8972 "unsupported L-RX: %s", l_rx);
8973 return -1;
8974 }
8975
8976 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
8977 return -1;
8978 } else if (strcasecmp(frame_name, "ssw") == 0) {
8979 sigma_dut_print(dut, DUT_MSG_INFO,
8980 "dev_send_frame: SLS, dest_mac %s", mac);
8981 if (wil6210_send_sls(dut, mac))
8982 return -1;
8983 } else {
8984 sigma_dut_print(dut, DUT_MSG_ERROR,
8985 "unsupported frame type: %s", frame_name);
8986 return -1;
8987 }
8988
8989 return 1;
8990}
8991#endif /* __linux__ */
8992
8993
8994static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
8995 struct sigma_conn *conn,
8996 struct sigma_cmd *cmd)
8997{
8998 switch (get_driver_type()) {
8999#ifdef __linux__
9000 case DRIVER_WIL6210:
9001 return wil6210_send_frame_60g(dut, conn, cmd);
9002#endif /* __linux__ */
9003 default:
9004 send_resp(dut, conn, SIGMA_ERROR,
9005 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
9006 return 0;
9007 }
9008}
9009
9010
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309011static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
9012 const char *intf, struct sigma_cmd *cmd)
9013{
9014 const char *val, *addr;
9015 char buf[100];
9016
9017 addr = get_param(cmd, "DestMac");
9018 if (!addr) {
9019 send_resp(dut, conn, SIGMA_INVALID,
9020 "ErrorCode,AP MAC address is missing");
9021 return 0;
9022 }
9023
9024 val = get_param(cmd, "ANQPQuery_ID");
9025 if (!val) {
9026 send_resp(dut, conn, SIGMA_INVALID,
9027 "ErrorCode,Missing ANQPQuery_ID");
9028 return 0;
9029 }
9030
9031 if (strcasecmp(val, "NeighborReportReq") == 0) {
9032 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
9033 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
9034 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
9035 } else {
9036 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
9037 val);
9038 send_resp(dut, conn, SIGMA_INVALID,
9039 "ErrorCode,Invalid ANQPQuery_ID");
9040 return 0;
9041 }
9042
Ashwini Patild174f2c2017-04-13 16:49:46 +05309043 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
9044 * (Address3 = Wildcard BSSID when sent to not-associated AP;
9045 * if associated, AP BSSID).
9046 */
9047 if (wpa_command(intf, "SET gas_address3 1") < 0) {
9048 send_resp(dut, conn, SIGMA_ERROR,
9049 "ErrorCode,Failed to set gas_address3");
9050 return 0;
9051 }
9052
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309053 if (wpa_command(intf, buf) < 0) {
9054 send_resp(dut, conn, SIGMA_ERROR,
9055 "ErrorCode,Failed to send ANQP query");
9056 return 0;
9057 }
9058
9059 return 1;
9060}
9061
9062
9063static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
9064 struct sigma_conn *conn,
9065 const char *intf,
9066 struct sigma_cmd *cmd)
9067{
9068 const char *val = get_param(cmd, "FrameName");
9069
9070 if (val && strcasecmp(val, "ANQPQuery") == 0)
9071 return mbo_send_anqp_query(dut, conn, intf, cmd);
9072
9073 return 2;
9074}
9075
9076
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009077int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
9078 struct sigma_cmd *cmd)
9079{
9080 const char *intf = get_param(cmd, "Interface");
9081 const char *val;
9082 enum send_frame_type frame;
9083 enum send_frame_protection protected;
9084 char buf[100];
9085 unsigned char addr[ETH_ALEN];
9086 int res;
9087
9088 val = get_param(cmd, "program");
9089 if (val == NULL)
9090 val = get_param(cmd, "frame");
9091 if (val && strcasecmp(val, "TDLS") == 0)
9092 return cmd_sta_send_frame_tdls(dut, conn, cmd);
9093 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009094 strcasecmp(val, "HS2-R2") == 0 ||
9095 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009096 return cmd_sta_send_frame_hs2(dut, conn, cmd);
9097 if (val && strcasecmp(val, "VHT") == 0)
9098 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07009099 if (val && strcasecmp(val, "LOC") == 0)
9100 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02009101 if (val && strcasecmp(val, "60GHz") == 0)
9102 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05309103 if (val && strcasecmp(val, "MBO") == 0) {
9104 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
9105 if (res != 2)
9106 return res;
9107 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009108
9109 val = get_param(cmd, "TD_DISC");
9110 if (val) {
9111 if (hwaddr_aton(val, addr) < 0)
9112 return -1;
9113 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
9114 if (wpa_command(intf, buf) < 0) {
9115 send_resp(dut, conn, SIGMA_ERROR,
9116 "ErrorCode,Failed to send TDLS discovery");
9117 return 0;
9118 }
9119 return 1;
9120 }
9121
9122 val = get_param(cmd, "TD_Setup");
9123 if (val) {
9124 if (hwaddr_aton(val, addr) < 0)
9125 return -1;
9126 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
9127 if (wpa_command(intf, buf) < 0) {
9128 send_resp(dut, conn, SIGMA_ERROR,
9129 "ErrorCode,Failed to start TDLS setup");
9130 return 0;
9131 }
9132 return 1;
9133 }
9134
9135 val = get_param(cmd, "TD_TearDown");
9136 if (val) {
9137 if (hwaddr_aton(val, addr) < 0)
9138 return -1;
9139 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
9140 if (wpa_command(intf, buf) < 0) {
9141 send_resp(dut, conn, SIGMA_ERROR,
9142 "ErrorCode,Failed to tear down TDLS link");
9143 return 0;
9144 }
9145 return 1;
9146 }
9147
9148 val = get_param(cmd, "TD_ChannelSwitch");
9149 if (val) {
9150 /* TODO */
9151 send_resp(dut, conn, SIGMA_ERROR,
9152 "ErrorCode,TD_ChannelSwitch not yet supported");
9153 return 0;
9154 }
9155
9156 val = get_param(cmd, "TD_NF");
9157 if (val) {
9158 /* TODO */
9159 send_resp(dut, conn, SIGMA_ERROR,
9160 "ErrorCode,TD_NF not yet supported");
9161 return 0;
9162 }
9163
9164 val = get_param(cmd, "PMFFrameType");
9165 if (val == NULL)
9166 val = get_param(cmd, "FrameName");
9167 if (val == NULL)
9168 val = get_param(cmd, "Type");
9169 if (val == NULL)
9170 return -1;
9171 if (strcasecmp(val, "disassoc") == 0)
9172 frame = DISASSOC;
9173 else if (strcasecmp(val, "deauth") == 0)
9174 frame = DEAUTH;
9175 else if (strcasecmp(val, "saquery") == 0)
9176 frame = SAQUERY;
9177 else if (strcasecmp(val, "auth") == 0)
9178 frame = AUTH;
9179 else if (strcasecmp(val, "assocreq") == 0)
9180 frame = ASSOCREQ;
9181 else if (strcasecmp(val, "reassocreq") == 0)
9182 frame = REASSOCREQ;
9183 else if (strcasecmp(val, "neigreq") == 0) {
9184 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
9185
9186 val = get_param(cmd, "ssid");
9187 if (val == NULL)
9188 return -1;
9189
9190 res = send_neighbor_request(dut, intf, val);
9191 if (res) {
9192 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9193 "Failed to send neighbor report request");
9194 return 0;
9195 }
9196
9197 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05309198 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
9199 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009200 sigma_dut_print(dut, DUT_MSG_DEBUG,
9201 "Got Transition Management Query");
9202
Ashwini Patil5acd7382017-04-13 15:55:04 +05309203 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009204 if (res) {
9205 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9206 "Failed to send Transition Management Query");
9207 return 0;
9208 }
9209
9210 return 1;
9211 } else {
9212 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9213 "PMFFrameType");
9214 return 0;
9215 }
9216
9217 val = get_param(cmd, "PMFProtected");
9218 if (val == NULL)
9219 val = get_param(cmd, "Protected");
9220 if (val == NULL)
9221 return -1;
9222 if (strcasecmp(val, "Correct-key") == 0 ||
9223 strcasecmp(val, "CorrectKey") == 0)
9224 protected = CORRECT_KEY;
9225 else if (strcasecmp(val, "IncorrectKey") == 0)
9226 protected = INCORRECT_KEY;
9227 else if (strcasecmp(val, "Unprotected") == 0)
9228 protected = UNPROTECTED;
9229 else {
9230 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9231 "PMFProtected");
9232 return 0;
9233 }
9234
9235 if (protected != UNPROTECTED &&
9236 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
9237 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
9238 "PMFProtected for auth/assocreq/reassocreq");
9239 return 0;
9240 }
9241
9242 if (if_nametoindex("sigmadut") == 0) {
9243 snprintf(buf, sizeof(buf),
9244 "iw dev %s interface add sigmadut type monitor",
9245 get_station_ifname());
9246 if (system(buf) != 0 ||
9247 if_nametoindex("sigmadut") == 0) {
9248 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
9249 "monitor interface with '%s'", buf);
9250 return -2;
9251 }
9252 }
9253
9254 if (system("ifconfig sigmadut up") != 0) {
9255 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
9256 "monitor interface up");
9257 return -2;
9258 }
9259
9260 return sta_inject_frame(dut, conn, frame, protected, NULL);
9261}
9262
9263
9264static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
9265 struct sigma_conn *conn,
9266 struct sigma_cmd *cmd,
9267 const char *ifname)
9268{
9269 char buf[200];
9270 const char *val;
9271
9272 val = get_param(cmd, "ClearARP");
9273 if (val && atoi(val) == 1) {
9274 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
9275 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9276 if (system(buf) != 0) {
9277 send_resp(dut, conn, SIGMA_ERROR,
9278 "errorCode,Failed to clear ARP cache");
9279 return 0;
9280 }
9281 }
9282
9283 return 1;
9284}
9285
9286
9287int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
9288 struct sigma_cmd *cmd)
9289{
9290 const char *intf = get_param(cmd, "Interface");
9291 const char *val;
9292
9293 if (intf == NULL)
9294 return -1;
9295
9296 val = get_param(cmd, "program");
9297 if (val && (strcasecmp(val, "HS2") == 0 ||
Jouni Malinen1f6ae642018-06-07 23:56:13 +03009298 strcasecmp(val, "HS2-R2") == 0 ||
9299 strcasecmp(val, "HS2-R3") == 0))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009300 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
9301
9302 return -1;
9303}
9304
9305
9306static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
9307 struct sigma_cmd *cmd)
9308{
9309 const char *intf = get_param(cmd, "Interface");
9310 const char *mac = get_param(cmd, "MAC");
9311
9312 if (intf == NULL || mac == NULL)
9313 return -1;
9314
9315 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
9316 "interface %s to %s", intf, mac);
9317
9318 if (dut->set_macaddr) {
9319 char buf[128];
9320 int res;
9321 if (strcasecmp(mac, "default") == 0) {
9322 res = snprintf(buf, sizeof(buf), "%s",
9323 dut->set_macaddr);
9324 dut->tmp_mac_addr = 0;
9325 } else {
9326 res = snprintf(buf, sizeof(buf), "%s %s",
9327 dut->set_macaddr, mac);
9328 dut->tmp_mac_addr = 1;
9329 }
9330 if (res < 0 || res >= (int) sizeof(buf))
9331 return -1;
9332 if (system(buf) != 0) {
9333 send_resp(dut, conn, SIGMA_ERROR,
9334 "errorCode,Failed to set MAC "
9335 "address");
9336 return 0;
9337 }
9338 return 1;
9339 }
9340
9341 if (strcasecmp(mac, "default") == 0)
9342 return 1;
9343
9344 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
9345 "command");
9346 return 0;
9347}
9348
9349
9350static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
9351 struct sigma_conn *conn, const char *intf,
9352 int val)
9353{
9354 char buf[200];
9355 int res;
9356
9357 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
9358 intf, val);
9359 if (res < 0 || res >= (int) sizeof(buf))
9360 return -1;
9361 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9362 if (system(buf) != 0) {
9363 send_resp(dut, conn, SIGMA_ERROR,
9364 "errorCode,Failed to configure offchannel mode");
9365 return 0;
9366 }
9367
9368 return 1;
9369}
9370
9371
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009372static int off_chan_val(enum sec_ch_offset off)
9373{
9374 switch (off) {
9375 case SEC_CH_NO:
9376 return 0;
9377 case SEC_CH_40ABOVE:
9378 return 40;
9379 case SEC_CH_40BELOW:
9380 return -40;
9381 }
9382
9383 return 0;
9384}
9385
9386
9387static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
9388 const char *intf, int off_ch_num,
9389 enum sec_ch_offset sec)
9390{
9391 char buf[200];
9392 int res;
9393
9394 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
9395 intf, off_ch_num);
9396 if (res < 0 || res >= (int) sizeof(buf))
9397 return -1;
9398 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9399 if (system(buf) != 0) {
9400 send_resp(dut, conn, SIGMA_ERROR,
9401 "errorCode,Failed to set offchan");
9402 return 0;
9403 }
9404
9405 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
9406 intf, off_chan_val(sec));
9407 if (res < 0 || res >= (int) sizeof(buf))
9408 return -1;
9409 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9410 if (system(buf) != 0) {
9411 send_resp(dut, conn, SIGMA_ERROR,
9412 "errorCode,Failed to set sec chan offset");
9413 return 0;
9414 }
9415
9416 return 1;
9417}
9418
9419
9420static int tdls_set_offchannel_offset(struct sigma_dut *dut,
9421 struct sigma_conn *conn,
9422 const char *intf, int off_ch_num,
9423 enum sec_ch_offset sec)
9424{
9425 char buf[200];
9426 int res;
9427
9428 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
9429 off_ch_num);
9430 if (res < 0 || res >= (int) sizeof(buf))
9431 return -1;
9432 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9433
9434 if (wpa_command(intf, buf) < 0) {
9435 send_resp(dut, conn, SIGMA_ERROR,
9436 "ErrorCode,Failed to set offchan");
9437 return 0;
9438 }
9439 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
9440 off_chan_val(sec));
9441 if (res < 0 || res >= (int) sizeof(buf))
9442 return -1;
9443
9444 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9445
9446 if (wpa_command(intf, buf) < 0) {
9447 send_resp(dut, conn, SIGMA_ERROR,
9448 "ErrorCode,Failed to set sec chan offset");
9449 return 0;
9450 }
9451
9452 return 1;
9453}
9454
9455
9456static int tdls_set_offchannel_mode(struct sigma_dut *dut,
9457 struct sigma_conn *conn,
9458 const char *intf, int val)
9459{
9460 char buf[200];
9461 int res;
9462
9463 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
9464 val);
9465 if (res < 0 || res >= (int) sizeof(buf))
9466 return -1;
9467 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
9468
9469 if (wpa_command(intf, buf) < 0) {
9470 send_resp(dut, conn, SIGMA_ERROR,
9471 "ErrorCode,Failed to configure offchannel mode");
9472 return 0;
9473 }
9474
9475 return 1;
9476}
9477
9478
9479static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
9480 struct sigma_conn *conn,
9481 struct sigma_cmd *cmd)
9482{
9483 const char *val;
9484 enum {
9485 CHSM_NOT_SET,
9486 CHSM_ENABLE,
9487 CHSM_DISABLE,
9488 CHSM_REJREQ,
9489 CHSM_UNSOLRESP
9490 } chsm = CHSM_NOT_SET;
9491 int off_ch_num = -1;
9492 enum sec_ch_offset sec_ch = SEC_CH_NO;
9493 int res;
9494
9495 val = get_param(cmd, "Uapsd");
9496 if (val) {
9497 char buf[100];
9498 if (strcasecmp(val, "Enable") == 0)
9499 snprintf(buf, sizeof(buf), "SET ps 99");
9500 else if (strcasecmp(val, "Disable") == 0)
9501 snprintf(buf, sizeof(buf), "SET ps 98");
9502 else {
9503 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
9504 "Unsupported uapsd parameter value");
9505 return 0;
9506 }
9507 if (wpa_command(intf, buf)) {
9508 send_resp(dut, conn, SIGMA_ERROR,
9509 "ErrorCode,Failed to change U-APSD "
9510 "powersave mode");
9511 return 0;
9512 }
9513 }
9514
9515 val = get_param(cmd, "TPKTIMER");
9516 if (val && strcasecmp(val, "DISABLE") == 0) {
9517 if (wpa_command(intf, "SET tdls_testing 0x100")) {
9518 send_resp(dut, conn, SIGMA_ERROR,
9519 "ErrorCode,Failed to enable no TPK "
9520 "expiration test mode");
9521 return 0;
9522 }
9523 dut->no_tpk_expiration = 1;
9524 }
9525
9526 val = get_param(cmd, "ChSwitchMode");
9527 if (val) {
9528 if (strcasecmp(val, "Enable") == 0 ||
9529 strcasecmp(val, "Initiate") == 0)
9530 chsm = CHSM_ENABLE;
9531 else if (strcasecmp(val, "Disable") == 0 ||
9532 strcasecmp(val, "passive") == 0)
9533 chsm = CHSM_DISABLE;
9534 else if (strcasecmp(val, "RejReq") == 0)
9535 chsm = CHSM_REJREQ;
9536 else if (strcasecmp(val, "UnSolResp") == 0)
9537 chsm = CHSM_UNSOLRESP;
9538 else {
9539 send_resp(dut, conn, SIGMA_ERROR,
9540 "ErrorCode,Unknown ChSwitchMode value");
9541 return 0;
9542 }
9543 }
9544
9545 val = get_param(cmd, "OffChNum");
9546 if (val) {
9547 off_ch_num = atoi(val);
9548 if (off_ch_num == 0) {
9549 send_resp(dut, conn, SIGMA_ERROR,
9550 "ErrorCode,Invalid OffChNum");
9551 return 0;
9552 }
9553 }
9554
9555 val = get_param(cmd, "SecChOffset");
9556 if (val) {
9557 if (strcmp(val, "20") == 0)
9558 sec_ch = SEC_CH_NO;
9559 else if (strcasecmp(val, "40above") == 0)
9560 sec_ch = SEC_CH_40ABOVE;
9561 else if (strcasecmp(val, "40below") == 0)
9562 sec_ch = SEC_CH_40BELOW;
9563 else {
9564 send_resp(dut, conn, SIGMA_ERROR,
9565 "ErrorCode,Unknown SecChOffset value");
9566 return 0;
9567 }
9568 }
9569
9570 if (chsm == CHSM_NOT_SET) {
9571 /* no offchannel changes requested */
9572 return 1;
9573 }
9574
9575 if (strcmp(intf, get_main_ifname()) != 0 &&
9576 strcmp(intf, get_station_ifname()) != 0) {
9577 send_resp(dut, conn, SIGMA_ERROR,
9578 "ErrorCode,Unknown interface");
9579 return 0;
9580 }
9581
9582 switch (chsm) {
9583 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03009584 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009585 break;
9586 case CHSM_ENABLE:
9587 if (off_ch_num < 0) {
9588 send_resp(dut, conn, SIGMA_ERROR,
9589 "ErrorCode,Missing OffChNum argument");
9590 return 0;
9591 }
9592 if (wifi_chip_type == DRIVER_WCN) {
9593 res = tdls_set_offchannel_offset(dut, conn, intf,
9594 off_ch_num, sec_ch);
9595 } else {
9596 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9597 sec_ch);
9598 }
9599 if (res != 1)
9600 return res;
9601 if (wifi_chip_type == DRIVER_WCN)
9602 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
9603 else
9604 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
9605 break;
9606 case CHSM_DISABLE:
9607 if (wifi_chip_type == DRIVER_WCN)
9608 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
9609 else
9610 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
9611 break;
9612 case CHSM_REJREQ:
9613 if (wifi_chip_type == DRIVER_WCN)
9614 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
9615 else
9616 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
9617 break;
9618 case CHSM_UNSOLRESP:
9619 if (off_ch_num < 0) {
9620 send_resp(dut, conn, SIGMA_ERROR,
9621 "ErrorCode,Missing OffChNum argument");
9622 return 0;
9623 }
9624 if (wifi_chip_type == DRIVER_WCN) {
9625 res = tdls_set_offchannel_offset(dut, conn, intf,
9626 off_ch_num, sec_ch);
9627 } else {
9628 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
9629 sec_ch);
9630 }
9631 if (res != 1)
9632 return res;
9633 if (wifi_chip_type == DRIVER_WCN)
9634 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
9635 else
9636 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
9637 break;
9638 }
9639
9640 return res;
9641}
9642
9643
9644static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9645 struct sigma_conn *conn,
9646 struct sigma_cmd *cmd)
9647{
9648 const char *val;
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309649 char *token = NULL, *result;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009650
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08009651 novap_reset(dut, intf);
9652
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009653 val = get_param(cmd, "nss_mcs_opt");
9654 if (val) {
9655 /* String (nss_operating_mode; mcs_operating_mode) */
9656 int nss, mcs;
9657 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309658 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009659
9660 token = strdup(val);
9661 if (!token)
9662 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309663 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309664 if (!result) {
9665 sigma_dut_print(dut, DUT_MSG_ERROR,
9666 "VHT NSS not specified");
9667 goto failed;
9668 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009669 if (strcasecmp(result, "def") != 0) {
9670 nss = atoi(result);
9671 if (nss == 4)
9672 ath_disable_txbf(dut, intf);
9673 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
9674 intf, nss);
9675 if (system(buf) != 0) {
9676 sigma_dut_print(dut, DUT_MSG_ERROR,
9677 "iwpriv nss failed");
9678 goto failed;
9679 }
9680 }
9681
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05309682 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05309683 if (!result) {
9684 sigma_dut_print(dut, DUT_MSG_ERROR,
9685 "VHT MCS not specified");
9686 goto failed;
9687 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009688 if (strcasecmp(result, "def") == 0) {
9689 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
9690 intf);
9691 if (system(buf) != 0) {
9692 sigma_dut_print(dut, DUT_MSG_ERROR,
9693 "iwpriv set11NRates failed");
9694 goto failed;
9695 }
9696
9697 } else {
9698 mcs = atoi(result);
9699 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
9700 intf, mcs);
9701 if (system(buf) != 0) {
9702 sigma_dut_print(dut, DUT_MSG_ERROR,
9703 "iwpriv vhtmcs failed");
9704 goto failed;
9705 }
9706 }
9707 /* Channel width gets messed up, fix this */
9708 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
9709 intf, dut->chwidth);
9710 if (system(buf) != 0) {
9711 sigma_dut_print(dut, DUT_MSG_ERROR,
9712 "iwpriv chwidth failed");
9713 }
9714 }
9715
Srikanth Marepalli5415acf2018-08-27 12:53:11 +05309716 free(token);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02009717 return 1;
9718failed:
9719 free(token);
9720 return 0;
9721}
9722
9723
9724static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
9725 struct sigma_conn *conn,
9726 struct sigma_cmd *cmd)
9727{
9728 switch (get_driver_type()) {
9729 case DRIVER_ATHEROS:
9730 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
9731 default:
9732 send_resp(dut, conn, SIGMA_ERROR,
9733 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
9734 return 0;
9735 }
9736}
9737
9738
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009739static int wcn_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9740 struct sigma_conn *conn,
9741 struct sigma_cmd *cmd)
9742{
9743 const char *val;
9744 char *token = NULL, *result;
9745 char buf[60];
9746
9747 val = get_param(cmd, "nss_mcs_opt");
9748 if (val) {
9749 /* String (nss_operating_mode; mcs_operating_mode) */
9750 int nss, mcs, ratecode;
9751 char *saveptr;
9752
9753 token = strdup(val);
9754 if (!token)
9755 return -2;
9756
9757 result = strtok_r(token, ";", &saveptr);
9758 if (!result) {
9759 sigma_dut_print(dut, DUT_MSG_ERROR,
9760 "HE NSS not specified");
9761 goto failed;
9762 }
9763 nss = 1;
9764 if (strcasecmp(result, "def") != 0)
9765 nss = atoi(result);
9766
9767 result = strtok_r(NULL, ";", &saveptr);
9768 if (!result) {
9769 sigma_dut_print(dut, DUT_MSG_ERROR,
9770 "HE MCS not specified");
9771 goto failed;
9772 }
9773 mcs = 7;
9774 if (strcasecmp(result, "def") != 0)
9775 mcs = atoi(result);
9776
Arif Hussain557bf412018-05-25 17:29:36 -07009777 ratecode = 0x20; /* for nss:1 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009778 if (nss == 2) {
Arif Hussain557bf412018-05-25 17:29:36 -07009779 ratecode = 0x40; /* for nss:2 MCS 0 */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009780 } else if (nss > 2) {
9781 sigma_dut_print(dut, DUT_MSG_ERROR,
9782 "HE NSS %d not supported", nss);
9783 goto failed;
9784 }
9785
Arif Hussain557bf412018-05-25 17:29:36 -07009786 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
9787 if (system(buf) != 0) {
9788 sigma_dut_print(dut, DUT_MSG_ERROR,
9789 "nss_mcs_opt: iwpriv %s nss %d failed",
9790 intf, nss);
9791 goto failed;
9792 }
Arif Hussainac6c5112018-05-25 17:34:00 -07009793 dut->sta_nss = nss;
Arif Hussain557bf412018-05-25 17:29:36 -07009794
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009795 /* Add the MCS to the ratecode */
9796 if (mcs >= 0 && mcs <= 11) {
9797 ratecode += mcs;
Arif Hussain557bf412018-05-25 17:29:36 -07009798#ifdef NL80211_SUPPORT
9799 if (dut->device_type == STA_testbed) {
9800 enum he_mcs_config mcs_config;
9801 int ret;
9802
9803 if (mcs <= 7)
9804 mcs_config = HE_80_MCS0_7;
9805 else if (mcs <= 9)
9806 mcs_config = HE_80_MCS0_9;
9807 else
9808 mcs_config = HE_80_MCS0_11;
9809 ret = sta_set_he_mcs(dut, intf, mcs_config);
9810 if (ret) {
9811 sigma_dut_print(dut, DUT_MSG_ERROR,
9812 "nss_mcs_opt: mcs setting failed, mcs:%d, mcs_config %d, ret:%d",
9813 mcs, mcs_config, ret);
9814 goto failed;
9815 }
9816 }
9817#endif /* NL80211_SUPPORT */
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009818 } else {
9819 sigma_dut_print(dut, DUT_MSG_ERROR,
9820 "HE MCS %d not supported", mcs);
9821 goto failed;
9822 }
9823 snprintf(buf, sizeof(buf), "iwpriv %s set_11ax_rate 0x%03x",
9824 intf, ratecode);
9825 if (system(buf) != 0) {
9826 sigma_dut_print(dut, DUT_MSG_ERROR,
9827 "iwpriv setting of 11ax rates failed");
9828 goto failed;
9829 }
9830 free(token);
9831 }
9832
9833 val = get_param(cmd, "GI");
9834 if (val) {
9835 if (strcmp(val, "0.8") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -07009836 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 9", intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009837 } else if (strcmp(val, "1.6") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -07009838 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 10",
9839 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009840 } else if (strcmp(val, "3.2") == 0) {
Kiran Kumar Lokereb8fec522018-05-01 14:26:00 -07009841 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 11",
9842 intf);
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009843 } else {
9844 send_resp(dut, conn, SIGMA_ERROR,
9845 "errorCode,GI value not supported");
9846 return 0;
9847 }
9848 if (system(buf) != 0) {
9849 send_resp(dut, conn, SIGMA_ERROR,
9850 "errorCode,Failed to set shortgi");
9851 return 0;
9852 }
9853 }
9854
Subhani Shaik8e7a3052018-04-24 14:03:00 -07009855 val = get_param(cmd, "LTF");
9856 if (val) {
9857#ifdef NL80211_SUPPORT
9858 if (strcmp(val, "3.2") == 0) {
9859 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_1X);
9860 } if (strcmp(val, "6.4") == 0) {
9861 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_2X);
9862 } else if (strcmp(val, "12.8") == 0) {
9863 sta_set_he_ltf(dut, intf, QCA_WLAN_HE_LTF_4X);
9864 } else {
9865 send_resp(dut, conn, SIGMA_ERROR,
9866 "errorCode, LTF value not supported");
9867 return 0;
9868 }
9869#else /* NL80211_SUPPORT */
9870 sigma_dut_print(dut, DUT_MSG_ERROR,
9871 "LTF cannot be set without NL80211_SUPPORT defined");
9872 return -2;
9873#endif /* NL80211_SUPPORT */
9874 }
9875
Kiran Kumar Lokere400d68f2018-08-29 18:45:11 -07009876 val = get_param(cmd, "TxSUPPDU");
9877 if (val) {
9878 int set_val = 1;
9879
9880 if (strcasecmp(val, "Enable") == 0)
9881 set_val = 1;
9882 else if (strcasecmp(val, "Disable") == 0)
9883 set_val = 0;
9884
9885 if (sta_set_tx_su_ppdu_cfg(dut, intf, set_val)) {
9886 send_resp(dut, conn, SIGMA_ERROR,
9887 "ErrorCode,Failed to set Tx SU PPDU config");
9888 return 0;
9889 }
9890 }
9891
Kiran Kumar Lokere29c1bb02018-10-08 17:41:02 -07009892 val = get_param(cmd, "OMCtrl_RxNSS");
9893 if (val) {
9894 /*
9895 * OMCtrl_RxNSS uses the IEEE 802.11 standard values for Nss,
9896 * i.e., 0 for 1Nss, 1 for Nss 2, etc. The driver checks for
9897 * the actual Nss value hence add 1 to the set value.
9898 */
9899 int set_val = atoi(val) + 1;
9900
9901 if (sta_set_he_om_ctrl_nss(dut, intf, set_val)) {
9902 send_resp(dut, conn, SIGMA_ERROR,
9903 "ErrorCode,Failed to set OM ctrl NSS config");
9904 return 0;
9905 }
9906 }
9907
9908 val = get_param(cmd, "OMCtrl_ChnlWidth");
9909 if (val) {
9910 int set_val = atoi(val);
9911
9912 if (sta_set_he_om_ctrl_bw(dut, intf,
9913 (enum qca_wlan_he_om_ctrl_ch_bw)
9914 set_val)) {
9915 send_resp(dut, conn, SIGMA_ERROR,
9916 "ErrorCode,Failed to set OM ctrl BW config");
9917 return 0;
9918 }
9919 }
9920
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -08009921 return 1;
9922
9923failed:
9924 free(token);
9925 return -2;
9926}
9927
9928
9929static int cmd_sta_set_rfeature_he(const char *intf, struct sigma_dut *dut,
9930 struct sigma_conn *conn,
9931 struct sigma_cmd *cmd)
9932{
9933 switch (get_driver_type()) {
9934 case DRIVER_WCN:
9935 return wcn_sta_set_rfeature_he(intf, dut, conn, cmd);
9936 default:
9937 send_resp(dut, conn, SIGMA_ERROR,
9938 "errorCode,Unsupported sta_set_rfeature(HE) with the current driver");
9939 return 0;
9940 }
9941}
9942
9943
Ashwini Patil5acd7382017-04-13 15:55:04 +05309944static int btm_query_candidate_list(struct sigma_dut *dut,
9945 struct sigma_conn *conn,
9946 struct sigma_cmd *cmd)
9947{
9948 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
9949 int len, ret;
9950 char buf[10];
9951
9952 /*
9953 * Neighbor Report elements format:
9954 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
9955 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
9956 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
9957 */
9958
9959 bssid = get_param(cmd, "Nebor_BSSID");
9960 if (!bssid) {
9961 send_resp(dut, conn, SIGMA_INVALID,
9962 "errorCode,Nebor_BSSID is missing");
9963 return 0;
9964 }
9965
9966 info = get_param(cmd, "Nebor_Bssid_Info");
9967 if (!info) {
9968 sigma_dut_print(dut, DUT_MSG_INFO,
9969 "Using default value for Nebor_Bssid_Info: %s",
9970 DEFAULT_NEIGHBOR_BSSID_INFO);
9971 info = DEFAULT_NEIGHBOR_BSSID_INFO;
9972 }
9973
9974 op_class = get_param(cmd, "Nebor_Op_Class");
9975 if (!op_class) {
9976 send_resp(dut, conn, SIGMA_INVALID,
9977 "errorCode,Nebor_Op_Class is missing");
9978 return 0;
9979 }
9980
9981 ch = get_param(cmd, "Nebor_Op_Ch");
9982 if (!ch) {
9983 send_resp(dut, conn, SIGMA_INVALID,
9984 "errorCode,Nebor_Op_Ch is missing");
9985 return 0;
9986 }
9987
9988 phy_type = get_param(cmd, "Nebor_Phy_Type");
9989 if (!phy_type) {
9990 sigma_dut_print(dut, DUT_MSG_INFO,
9991 "Using default value for Nebor_Phy_Type: %s",
9992 DEFAULT_NEIGHBOR_PHY_TYPE);
9993 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
9994 }
9995
9996 /* Parse optional subelements */
9997 buf[0] = '\0';
9998 pref = get_param(cmd, "Nebor_Pref");
9999 if (pref) {
10000 /* hexdump for preferrence subelement */
10001 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
10002 if (ret < 0 || ret >= (int) sizeof(buf)) {
10003 sigma_dut_print(dut, DUT_MSG_ERROR,
10004 "snprintf failed for optional subelement ret: %d",
10005 ret);
10006 send_resp(dut, conn, SIGMA_ERROR,
10007 "errorCode,snprintf failed for subelement");
10008 return 0;
10009 }
10010 }
10011
10012 if (!dut->btm_query_cand_list) {
10013 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
10014 if (!dut->btm_query_cand_list) {
10015 send_resp(dut, conn, SIGMA_ERROR,
10016 "errorCode,Failed to allocate memory for btm_query_cand_list");
10017 return 0;
10018 }
10019 }
10020
10021 len = strlen(dut->btm_query_cand_list);
10022 ret = snprintf(dut->btm_query_cand_list + len,
10023 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
10024 bssid, info, op_class, ch, phy_type, buf);
10025 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
10026 sigma_dut_print(dut, DUT_MSG_ERROR,
10027 "snprintf failed for neighbor report list ret: %d",
10028 ret);
10029 send_resp(dut, conn, SIGMA_ERROR,
10030 "errorCode,snprintf failed for neighbor report");
10031 free(dut->btm_query_cand_list);
10032 dut->btm_query_cand_list = NULL;
10033 return 0;
10034 }
10035
10036 return 1;
10037}
10038
10039
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010040static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
10041 struct sigma_cmd *cmd)
10042{
10043 const char *intf = get_param(cmd, "Interface");
10044 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010045 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010046
10047 if (intf == NULL || prog == NULL)
10048 return -1;
10049
Ashwini Patil5acd7382017-04-13 15:55:04 +053010050 /* BSS Transition candidate list for BTM query */
10051 val = get_param(cmd, "Nebor_BSSID");
10052 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
10053 return 0;
10054
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010055 if (strcasecmp(prog, "TDLS") == 0)
10056 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
10057
10058 if (strcasecmp(prog, "VHT") == 0)
10059 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
10060
Amarnath Hullur Subramanyam42c25a02018-01-31 04:02:27 -080010061 if (strcasecmp(prog, "HE") == 0)
10062 return cmd_sta_set_rfeature_he(intf, dut, conn, cmd);
10063
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010064 if (strcasecmp(prog, "MBO") == 0) {
10065 val = get_param(cmd, "Cellular_Data_Cap");
10066 if (val &&
10067 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
10068 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +053010069
10070 val = get_param(cmd, "Ch_Pref");
10071 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
10072 return 0;
10073
Ashwini Patil68d02cd2017-01-10 15:39:16 +053010074 return 1;
10075 }
10076
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010077 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
10078 return 0;
10079}
10080
10081
10082static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
10083 struct sigma_cmd *cmd)
10084{
10085 const char *intf = get_param(cmd, "Interface");
10086 const char *mode = get_param(cmd, "Mode");
10087 int res;
10088
10089 if (intf == NULL || mode == NULL)
10090 return -1;
10091
10092 if (strcasecmp(mode, "On") == 0)
10093 res = wpa_command(intf, "SET radio_disabled 0");
10094 else if (strcasecmp(mode, "Off") == 0)
10095 res = wpa_command(intf, "SET radio_disabled 1");
10096 else
10097 return -1;
10098
10099 if (res) {
10100 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10101 "radio mode");
10102 return 0;
10103 }
10104
10105 return 1;
10106}
10107
10108
10109static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
10110 struct sigma_cmd *cmd)
10111{
10112 const char *intf = get_param(cmd, "Interface");
10113 const char *mode = get_param(cmd, "Mode");
10114 int res;
10115
10116 if (intf == NULL || mode == NULL)
10117 return -1;
10118
10119 if (strcasecmp(mode, "On") == 0)
10120 res = set_ps(intf, dut, 1);
10121 else if (strcasecmp(mode, "Off") == 0)
10122 res = set_ps(intf, dut, 0);
10123 else
10124 return -1;
10125
10126 if (res) {
10127 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
10128 "power save mode");
10129 return 0;
10130 }
10131
10132 return 1;
10133}
10134
10135
10136static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
10137 struct sigma_cmd *cmd)
10138{
10139 const char *intf = get_param(cmd, "Interface");
10140 const char *val, *bssid;
10141 int res;
10142 char *buf;
10143 size_t buf_len;
10144
10145 val = get_param(cmd, "BSSID_FILTER");
10146 if (val == NULL)
10147 return -1;
10148
10149 bssid = get_param(cmd, "BSSID_List");
10150 if (atoi(val) == 0 || bssid == NULL) {
10151 /* Disable BSSID filter */
10152 if (wpa_command(intf, "SET bssid_filter ")) {
10153 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
10154 "to disable BSSID filter");
10155 return 0;
10156 }
10157
10158 return 1;
10159 }
10160
10161 buf_len = 100 + strlen(bssid);
10162 buf = malloc(buf_len);
10163 if (buf == NULL)
10164 return -1;
10165
10166 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
10167 res = wpa_command(intf, buf);
10168 free(buf);
10169 if (res) {
10170 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
10171 "BSSID filter");
10172 return 0;
10173 }
10174
10175 return 1;
10176}
10177
10178
10179static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
10180 struct sigma_cmd *cmd)
10181{
10182 const char *intf = get_param(cmd, "Interface");
10183 const char *val;
10184
10185 /* TODO: ARP */
10186
10187 val = get_param(cmd, "HS2_CACHE_PROFILE");
10188 if (val && strcasecmp(val, "All") == 0)
10189 hs2_clear_credentials(intf);
10190
10191 return 1;
10192}
10193
10194
10195static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
10196 struct sigma_cmd *cmd)
10197{
10198 const char *intf = get_param(cmd, "Interface");
10199 const char *key_type = get_param(cmd, "KeyType");
10200 char buf[100], resp[200];
10201
10202 if (key_type == NULL)
10203 return -1;
10204
10205 if (strcasecmp(key_type, "GTK") == 0) {
10206 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
10207 strncmp(buf, "FAIL", 4) == 0) {
10208 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10209 "not fetch current GTK");
10210 return 0;
10211 }
10212 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
10213 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10214 return 0;
10215 } else {
10216 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
10217 "KeyType");
10218 return 0;
10219 }
10220
10221 return 1;
10222}
10223
10224
10225static int hs2_set_policy(struct sigma_dut *dut)
10226{
10227#ifdef ANDROID
10228 system("ip rule del prio 23000");
10229 if (system("ip rule add from all lookup main prio 23000") != 0) {
10230 sigma_dut_print(dut, DUT_MSG_ERROR,
10231 "Failed to run:ip rule add from all lookup main prio");
10232 return -1;
10233 }
10234 if (system("ip route flush cache") != 0) {
10235 sigma_dut_print(dut, DUT_MSG_ERROR,
10236 "Failed to run ip route flush cache");
10237 return -1;
10238 }
10239 return 1;
10240#else /* ANDROID */
10241 return 0;
10242#endif /* ANDROID */
10243}
10244
10245
10246static int cmd_sta_hs2_associate(struct sigma_dut *dut,
10247 struct sigma_conn *conn,
10248 struct sigma_cmd *cmd)
10249{
10250 const char *intf = get_param(cmd, "Interface");
10251 const char *val = get_param(cmd, "Ignore_blacklist");
Jouni Malinen439352d2018-09-13 03:42:23 +030010252 const char *band = get_param(cmd, "Band");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010253 struct wpa_ctrl *ctrl;
10254 int res;
10255 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
10256 int tries = 0;
10257 int ignore_blacklist = 0;
10258 const char *events[] = {
10259 "CTRL-EVENT-CONNECTED",
10260 "INTERWORKING-BLACKLISTED",
10261 "INTERWORKING-NO-MATCH",
10262 NULL
10263 };
10264
10265 start_sta_mode(dut);
10266
Jouni Malinen439352d2018-09-13 03:42:23 +030010267 if (band) {
10268 if (strcmp(band, "2.4") == 0) {
10269 wpa_command(intf, "SET setband 2G");
10270 } else if (strcmp(band, "5") == 0) {
10271 wpa_command(intf, "SET setband 5G");
10272 } else {
10273 send_resp(dut, conn, SIGMA_ERROR,
10274 "errorCode,Unsupported band");
10275 return 0;
10276 }
10277 }
10278
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010279 blacklisted[0] = '\0';
10280 if (val && atoi(val))
10281 ignore_blacklist = 1;
10282
10283try_again:
10284 ctrl = open_wpa_mon(intf);
10285 if (ctrl == NULL) {
10286 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
10287 "wpa_supplicant monitor connection");
10288 return -2;
10289 }
10290
10291 tries++;
10292 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
10293 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
10294 "Interworking connection");
10295 wpa_ctrl_detach(ctrl);
10296 wpa_ctrl_close(ctrl);
10297 return 0;
10298 }
10299
10300 buf[0] = '\0';
10301 while (1) {
10302 char *pos;
10303 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
10304 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
10305 if (!pos)
10306 break;
10307 pos += 25;
10308 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
10309 pos);
10310 if (!blacklisted[0])
10311 memcpy(blacklisted, pos, strlen(pos) + 1);
10312 }
10313
10314 if (ignore_blacklist && blacklisted[0]) {
10315 char *end;
10316 end = strchr(blacklisted, ' ');
10317 if (end)
10318 *end = '\0';
10319 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
10320 blacklisted);
10321 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
10322 blacklisted);
10323 if (wpa_command(intf, buf)) {
10324 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
10325 wpa_ctrl_detach(ctrl);
10326 wpa_ctrl_close(ctrl);
10327 return 0;
10328 }
10329 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
10330 buf, sizeof(buf));
10331 }
10332
10333 wpa_ctrl_detach(ctrl);
10334 wpa_ctrl_close(ctrl);
10335
10336 if (res < 0) {
10337 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10338 "connect");
10339 return 0;
10340 }
10341
10342 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
10343 strstr(buf, "INTERWORKING-BLACKLISTED")) {
10344 if (tries < 2) {
10345 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
10346 goto try_again;
10347 }
10348 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
10349 "matching credentials found");
10350 return 0;
10351 }
10352
10353 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
10354 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
10355 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
10356 "get current BSSID/SSID");
10357 return 0;
10358 }
10359
10360 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
10361 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10362 hs2_set_policy(dut);
10363 return 0;
10364}
10365
10366
Jouni Malinenb639f1c2018-09-13 02:39:46 +030010367static int cmd_sta_hs2_venue_info(struct sigma_dut *dut,
10368 struct sigma_conn *conn,
10369 struct sigma_cmd *cmd)
10370{
10371 const char *intf = get_param(cmd, "Interface");
10372 const char *display = get_param(cmd, "Display");
10373 struct wpa_ctrl *ctrl;
10374 char buf[300], params[400], *pos;
10375 char bssid[20];
10376 int info_avail = 0;
10377 unsigned int old_timeout;
10378 int res;
10379
10380 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0) {
10381 send_resp(dut, conn, SIGMA_ERROR,
10382 "ErrorCode,Could not get current BSSID");
10383 return 0;
10384 }
10385 ctrl = open_wpa_mon(intf);
10386 if (!ctrl) {
10387 sigma_dut_print(dut, DUT_MSG_ERROR,
10388 "Failed to open wpa_supplicant monitor connection");
10389 return -2;
10390 }
10391
10392 snprintf(buf, sizeof(buf), "ANQP_GET %s 277", bssid);
10393 wpa_command(intf, buf);
10394
10395 res = get_wpa_cli_event(dut, ctrl, "GAS-QUERY-DONE", buf, sizeof(buf));
10396 if (res < 0) {
10397 send_resp(dut, conn, SIGMA_ERROR,
10398 "ErrorCode,Could not complete GAS query");
10399 goto fail;
10400 }
10401
10402 old_timeout = dut->default_timeout;
10403 dut->default_timeout = 2;
10404 res = get_wpa_cli_event(dut, ctrl, "RX-VENUE-URL", buf, sizeof(buf));
10405 dut->default_timeout = old_timeout;
10406 if (res < 0)
10407 goto done;
10408 pos = strchr(buf, ' ');
10409 if (!pos)
10410 goto done;
10411 pos++;
10412 pos = strchr(pos, ' ');
10413 if (!pos)
10414 goto done;
10415 pos++;
10416 info_avail = 1;
10417 snprintf(params, sizeof(params), "browser %s", pos);
10418
10419 if (display && strcasecmp(display, "Yes") == 0) {
10420 pid_t pid;
10421
10422 pid = fork();
10423 if (pid < 0) {
10424 perror("fork");
10425 return -1;
10426 }
10427
10428 if (pid == 0) {
10429 run_hs20_osu(dut, params);
10430 exit(0);
10431 }
10432 }
10433
10434done:
10435 snprintf(buf, sizeof(buf), "Info_available,%s",
10436 info_avail ? "Yes" : "No");
10437 send_resp(dut, conn, SIGMA_COMPLETE, buf);
10438fail:
10439 wpa_ctrl_detach(ctrl);
10440 wpa_ctrl_close(ctrl);
10441 return 0;
10442}
10443
10444
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010445static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
10446 struct sigma_conn *conn,
10447 const char *ifname,
10448 struct sigma_cmd *cmd)
10449{
10450 const char *val;
10451 int id;
10452
10453 id = add_cred(ifname);
10454 if (id < 0)
10455 return -2;
10456 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10457
10458 val = get_param(cmd, "prefer");
10459 if (val && atoi(val) > 0)
10460 set_cred(ifname, id, "priority", "1");
10461
10462 val = get_param(cmd, "REALM");
10463 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10464 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10465 "realm");
10466 return 0;
10467 }
10468
10469 val = get_param(cmd, "HOME_FQDN");
10470 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10471 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10472 "home_fqdn");
10473 return 0;
10474 }
10475
10476 val = get_param(cmd, "Username");
10477 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10478 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10479 "username");
10480 return 0;
10481 }
10482
10483 val = get_param(cmd, "Password");
10484 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
10485 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10486 "password");
10487 return 0;
10488 }
10489
10490 val = get_param(cmd, "ROOT_CA");
10491 if (val) {
10492 char fname[200];
10493 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10494#ifdef __linux__
10495 if (!file_exists(fname)) {
10496 char msg[300];
10497 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10498 "file (%s) not found", fname);
10499 send_resp(dut, conn, SIGMA_ERROR, msg);
10500 return 0;
10501 }
10502#endif /* __linux__ */
10503 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10504 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10505 "not set root CA");
10506 return 0;
10507 }
10508 }
10509
10510 return 1;
10511}
10512
10513
10514static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
10515{
10516 FILE *in, *out;
10517 char buf[500];
10518 int found = 0;
10519
10520 in = fopen("devdetail.xml", "r");
10521 if (in == NULL)
10522 return -1;
10523 out = fopen("devdetail.xml.tmp", "w");
10524 if (out == NULL) {
10525 fclose(in);
10526 return -1;
10527 }
10528
10529 while (fgets(buf, sizeof(buf), in)) {
10530 char *pos = strstr(buf, "<IMSI>");
10531 if (pos) {
10532 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
10533 imsi);
10534 pos += 6;
10535 *pos = '\0';
10536 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
10537 found++;
10538 } else {
10539 fprintf(out, "%s", buf);
10540 }
10541 }
10542
10543 fclose(out);
10544 fclose(in);
10545 if (found)
10546 rename("devdetail.xml.tmp", "devdetail.xml");
10547 else
10548 unlink("devdetail.xml.tmp");
10549
10550 return 0;
10551}
10552
10553
10554static int sta_add_credential_sim(struct sigma_dut *dut,
10555 struct sigma_conn *conn,
10556 const char *ifname, struct sigma_cmd *cmd)
10557{
10558 const char *val, *imsi = NULL;
10559 int id;
10560 char buf[200];
10561 int res;
10562 const char *pos;
10563 size_t mnc_len;
10564 char plmn_mcc[4];
10565 char plmn_mnc[4];
10566
10567 id = add_cred(ifname);
10568 if (id < 0)
10569 return -2;
10570 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10571
10572 val = get_param(cmd, "prefer");
10573 if (val && atoi(val) > 0)
10574 set_cred(ifname, id, "priority", "1");
10575
10576 val = get_param(cmd, "PLMN_MCC");
10577 if (val == NULL) {
10578 send_resp(dut, conn, SIGMA_ERROR,
10579 "errorCode,Missing PLMN_MCC");
10580 return 0;
10581 }
10582 if (strlen(val) != 3) {
10583 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
10584 return 0;
10585 }
10586 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
10587
10588 val = get_param(cmd, "PLMN_MNC");
10589 if (val == NULL) {
10590 send_resp(dut, conn, SIGMA_ERROR,
10591 "errorCode,Missing PLMN_MNC");
10592 return 0;
10593 }
10594 if (strlen(val) != 2 && strlen(val) != 3) {
10595 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
10596 return 0;
10597 }
10598 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
10599
10600 val = get_param(cmd, "IMSI");
10601 if (val == NULL) {
10602 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
10603 "IMSI");
10604 return 0;
10605 }
10606
10607 imsi = pos = val;
10608
10609 if (strncmp(plmn_mcc, pos, 3) != 0) {
10610 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
10611 return 0;
10612 }
10613 pos += 3;
10614
10615 mnc_len = strlen(plmn_mnc);
10616 if (mnc_len < 2) {
10617 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
10618 return 0;
10619 }
10620
10621 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
10622 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
10623 return 0;
10624 }
10625 pos += mnc_len;
10626
10627 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
10628 if (res < 0 || res >= (int) sizeof(buf))
10629 return -1;
10630 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
10631 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10632 "not set IMSI");
10633 return 0;
10634 }
10635
10636 val = get_param(cmd, "Password");
10637 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
10638 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10639 "not set password");
10640 return 0;
10641 }
10642
Jouni Malinenba630452018-06-22 11:49:59 +030010643 if (dut->program == PROGRAM_HS2_R2 || dut->program == PROGRAM_HS2_R3) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010644 /*
10645 * Set provisioning_sp for the test cases where SIM/USIM
10646 * provisioning is used.
10647 */
10648 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
10649 "wi-fi.org") < 0) {
10650 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10651 "not set provisioning_sp");
10652 return 0;
10653 }
10654
10655 update_devdetail_imsi(dut, imsi);
10656 }
10657
10658 return 1;
10659}
10660
10661
10662static int sta_add_credential_cert(struct sigma_dut *dut,
10663 struct sigma_conn *conn,
10664 const char *ifname,
10665 struct sigma_cmd *cmd)
10666{
10667 const char *val;
10668 int id;
10669
10670 id = add_cred(ifname);
10671 if (id < 0)
10672 return -2;
10673 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
10674
10675 val = get_param(cmd, "prefer");
10676 if (val && atoi(val) > 0)
10677 set_cred(ifname, id, "priority", "1");
10678
10679 val = get_param(cmd, "REALM");
10680 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
10681 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10682 "realm");
10683 return 0;
10684 }
10685
10686 val = get_param(cmd, "HOME_FQDN");
10687 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
10688 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10689 "home_fqdn");
10690 return 0;
10691 }
10692
10693 val = get_param(cmd, "Username");
10694 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
10695 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
10696 "username");
10697 return 0;
10698 }
10699
10700 val = get_param(cmd, "clientCertificate");
10701 if (val) {
10702 char fname[200];
10703 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10704#ifdef __linux__
10705 if (!file_exists(fname)) {
10706 char msg[300];
10707 snprintf(msg, sizeof(msg),
10708 "ErrorCode,clientCertificate "
10709 "file (%s) not found", fname);
10710 send_resp(dut, conn, SIGMA_ERROR, msg);
10711 return 0;
10712 }
10713#endif /* __linux__ */
10714 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
10715 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10716 "not set client_cert");
10717 return 0;
10718 }
10719 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
10720 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10721 "not set private_key");
10722 return 0;
10723 }
10724 }
10725
10726 val = get_param(cmd, "ROOT_CA");
10727 if (val) {
10728 char fname[200];
10729 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
10730#ifdef __linux__
10731 if (!file_exists(fname)) {
10732 char msg[300];
10733 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
10734 "file (%s) not found", fname);
10735 send_resp(dut, conn, SIGMA_ERROR, msg);
10736 return 0;
10737 }
10738#endif /* __linux__ */
10739 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
10740 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
10741 "not set root CA");
10742 return 0;
10743 }
10744 }
10745
10746 return 1;
10747}
10748
10749
10750static int cmd_sta_add_credential(struct sigma_dut *dut,
10751 struct sigma_conn *conn,
10752 struct sigma_cmd *cmd)
10753{
10754 const char *intf = get_param(cmd, "Interface");
10755 const char *type;
10756
10757 start_sta_mode(dut);
10758
10759 type = get_param(cmd, "Type");
10760 if (!type)
10761 return -1;
10762
10763 if (strcasecmp(type, "uname_pwd") == 0)
10764 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
10765
10766 if (strcasecmp(type, "sim") == 0)
10767 return sta_add_credential_sim(dut, conn, intf, cmd);
10768
10769 if (strcasecmp(type, "cert") == 0)
10770 return sta_add_credential_cert(dut, conn, intf, cmd);
10771
10772 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
10773 "type");
10774 return 0;
10775}
10776
10777
10778static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
10779 struct sigma_cmd *cmd)
10780{
10781 const char *intf = get_param(cmd, "Interface");
vamsi krishna89ad8c62017-09-19 12:51:18 +053010782 const char *val, *bssid, *ssid;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010783 char buf[100];
vamsi krishna89ad8c62017-09-19 12:51:18 +053010784 char ssid_hex[65];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010785 int res;
10786
10787 val = get_param(cmd, "HESSID");
10788 if (val) {
10789 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
10790 if (res < 0 || res >= (int) sizeof(buf))
10791 return -1;
10792 wpa_command(intf, buf);
10793 }
10794
10795 val = get_param(cmd, "ACCS_NET_TYPE");
10796 if (val) {
10797 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
10798 val);
10799 if (res < 0 || res >= (int) sizeof(buf))
10800 return -1;
10801 wpa_command(intf, buf);
10802 }
10803
vamsi krishna89ad8c62017-09-19 12:51:18 +053010804 bssid = get_param(cmd, "Bssid");
10805 ssid = get_param(cmd, "Ssid");
10806
10807 if (ssid) {
10808 if (2 * strlen(ssid) >= sizeof(ssid_hex)) {
10809 send_resp(dut, conn, SIGMA_ERROR,
10810 "ErrorCode,Too long SSID");
10811 return 0;
10812 }
10813 ascii2hexstr(ssid, ssid_hex);
10814 }
10815
10816 res = snprintf(buf, sizeof(buf), "SCAN%s%s%s%s",
10817 bssid ? " bssid=": "",
10818 bssid ? bssid : "",
10819 ssid ? " ssid " : "",
10820 ssid ? ssid_hex : "");
10821 if (res < 0 || res >= (int) sizeof(buf))
10822 return -1;
10823
10824 if (wpa_command(intf, buf)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010825 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
10826 "scan");
10827 return 0;
10828 }
10829
10830 return 1;
10831}
10832
10833
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020010834static int cmd_sta_scan_bss(struct sigma_dut *dut, struct sigma_conn *conn,
10835 struct sigma_cmd *cmd)
10836{
10837 const char *intf = get_param(cmd, "Interface");
10838 const char *bssid;
10839 char buf[4096], *pos;
10840 int freq, chan;
10841 char *ssid;
10842 char resp[100];
10843 int res;
10844 struct wpa_ctrl *ctrl;
10845
10846 bssid = get_param(cmd, "BSSID");
10847 if (!bssid) {
10848 send_resp(dut, conn, SIGMA_INVALID,
10849 "errorCode,BSSID argument is missing");
10850 return 0;
10851 }
10852
10853 ctrl = open_wpa_mon(intf);
10854 if (!ctrl) {
10855 sigma_dut_print(dut, DUT_MSG_ERROR,
10856 "Failed to open wpa_supplicant monitor connection");
10857 return -1;
10858 }
10859
10860 if (wpa_command(intf, "SCAN TYPE=ONLY")) {
10861 send_resp(dut, conn, SIGMA_ERROR,
10862 "errorCode,Could not start scan");
10863 wpa_ctrl_detach(ctrl);
10864 wpa_ctrl_close(ctrl);
10865 return 0;
10866 }
10867
10868 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
10869 buf, sizeof(buf));
10870
10871 wpa_ctrl_detach(ctrl);
10872 wpa_ctrl_close(ctrl);
10873
10874 if (res < 0) {
10875 send_resp(dut, conn, SIGMA_ERROR,
10876 "errorCode,Scan did not complete");
10877 return 0;
10878 }
10879
10880 snprintf(buf, sizeof(buf), "BSS %s", bssid);
10881 if (wpa_command_resp(intf, buf, buf, sizeof(buf)) < 0 ||
10882 strncmp(buf, "id=", 3) != 0) {
10883 send_resp(dut, conn, SIGMA_ERROR,
10884 "errorCode,Specified BSSID not found");
10885 return 0;
10886 }
10887
10888 pos = strstr(buf, "\nfreq=");
10889 if (!pos) {
10890 send_resp(dut, conn, SIGMA_ERROR,
10891 "errorCode,Channel not found");
10892 return 0;
10893 }
10894 freq = atoi(pos + 6);
10895 chan = freq_to_channel(freq);
10896
10897 pos = strstr(buf, "\nssid=");
10898 if (!pos) {
10899 send_resp(dut, conn, SIGMA_ERROR,
10900 "errorCode,SSID not found");
10901 return 0;
10902 }
10903 ssid = pos + 6;
10904 pos = strchr(ssid, '\n');
10905 if (pos)
10906 *pos = '\0';
10907 snprintf(resp, sizeof(resp), "ssid,%s,bsschannel,%d", ssid, chan);
10908 send_resp(dut, conn, SIGMA_COMPLETE, resp);
10909 return 0;
10910}
10911
10912
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010913static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
10914 struct sigma_cmd *cmd)
10915{
10916#ifdef __linux__
10917 struct timeval tv;
10918 struct tm tm;
10919 time_t t;
10920 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053010921 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010922
10923 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
10924
10925 memset(&tm, 0, sizeof(tm));
10926 val = get_param(cmd, "seconds");
10927 if (val)
10928 tm.tm_sec = atoi(val);
10929 val = get_param(cmd, "minutes");
10930 if (val)
10931 tm.tm_min = atoi(val);
10932 val = get_param(cmd, "hours");
10933 if (val)
10934 tm.tm_hour = atoi(val);
10935 val = get_param(cmd, "date");
10936 if (val)
10937 tm.tm_mday = atoi(val);
10938 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +053010939 if (val) {
10940 v = atoi(val);
10941 if (v < 1 || v > 12) {
10942 send_resp(dut, conn, SIGMA_INVALID,
10943 "errorCode,Invalid month");
10944 return 0;
10945 }
10946 tm.tm_mon = v - 1;
10947 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010948 val = get_param(cmd, "year");
10949 if (val) {
10950 int year = atoi(val);
10951#ifdef ANDROID
10952 if (year > 2035)
10953 year = 2035; /* years beyond 2035 not supported */
10954#endif /* ANDROID */
10955 tm.tm_year = year - 1900;
10956 }
10957 t = mktime(&tm);
10958 if (t == (time_t) -1) {
10959 send_resp(dut, conn, SIGMA_ERROR,
10960 "errorCode,Invalid date or time");
10961 return 0;
10962 }
10963
10964 memset(&tv, 0, sizeof(tv));
10965 tv.tv_sec = t;
10966
10967 if (settimeofday(&tv, NULL) < 0) {
10968 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
10969 strerror(errno));
10970 send_resp(dut, conn, SIGMA_ERROR,
10971 "errorCode,Failed to set time");
10972 return 0;
10973 }
10974
10975 return 1;
10976#endif /* __linux__ */
10977
10978 return -1;
10979}
10980
10981
10982static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
10983 struct sigma_cmd *cmd)
10984{
10985 const char *intf = get_param(cmd, "Interface");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010986 const char *name, *osu_ssid, *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010987 int prod_ess_assoc = 1;
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010988 char buf[300], bssid[100], ssid[100];
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010989 int res;
10990 struct wpa_ctrl *ctrl;
10991
10992 name = get_param(cmd, "osuFriendlyName");
Jouni Malinen4c8681c2018-09-12 23:28:11 +030010993 osu_ssid = get_param(cmd, "osu_ssid");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020010994
10995 val = get_param(cmd, "ProdESSAssoc");
10996 if (val)
10997 prod_ess_assoc = atoi(val);
10998
10999 kill_dhcp_client(dut, intf);
11000 if (start_dhcp_client(dut, intf) < 0)
11001 return -2;
11002
11003 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
11004 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11005 res = snprintf(buf, sizeof(buf),
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011006 "%s %s%s%s %s%s%s signup osu-ca.pem",
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011007 prod_ess_assoc ? "" : "-N",
11008 name ? "-O'" : "", name ? name : "",
Jouni Malinen4c8681c2018-09-12 23:28:11 +030011009 name ? "'" : "",
11010 osu_ssid ? "-o'" : "", osu_ssid ? osu_ssid : "",
11011 osu_ssid ? "'" : "");
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011012
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +053011013 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011014 if (run_hs20_osu(dut, buf) < 0) {
11015 FILE *f;
11016
11017 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
11018
11019 f = fopen("hs20-osu-client.res", "r");
11020 if (f) {
11021 char resp[400], res[300], *pos;
11022 if (!fgets(res, sizeof(res), f))
11023 res[0] = '\0';
11024 pos = strchr(res, '\n');
11025 if (pos)
11026 *pos = '\0';
11027 fclose(f);
11028 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
11029 res);
11030 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
11031 if (system(resp) != 0) {
11032 }
11033 snprintf(resp, sizeof(resp),
11034 "SSID,,BSSID,,failureReason,%s", res);
11035 send_resp(dut, conn, SIGMA_COMPLETE, resp);
11036 return 0;
11037 }
11038
11039 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11040 return 0;
11041 }
11042
11043 if (!prod_ess_assoc)
11044 goto report;
11045
11046 ctrl = open_wpa_mon(intf);
11047 if (ctrl == NULL) {
11048 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11049 "wpa_supplicant monitor connection");
11050 return -1;
11051 }
11052
11053 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
11054 buf, sizeof(buf));
11055
11056 wpa_ctrl_detach(ctrl);
11057 wpa_ctrl_close(ctrl);
11058
11059 if (res < 0) {
11060 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
11061 "network after OSU");
11062 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11063 return 0;
11064 }
11065
11066report:
11067 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
11068 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
11069 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
11070 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
11071 return 0;
11072 }
11073
11074 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
11075 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011076 return 0;
11077}
11078
11079
11080static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
11081 struct sigma_cmd *cmd)
11082{
11083 const char *val;
11084 int timeout = 120;
11085
11086 val = get_param(cmd, "PolicyUpdate");
11087 if (val == NULL || atoi(val) == 0)
11088 return 1; /* No operation requested */
11089
11090 val = get_param(cmd, "Timeout");
11091 if (val)
11092 timeout = atoi(val);
11093
11094 if (timeout) {
11095 /* TODO: time out the command and return
11096 * PolicyUpdateStatus,TIMEOUT if needed. */
11097 }
11098
11099 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
11100 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
11101 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
11102 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
11103 return 0;
11104 }
11105
11106 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
11107 return 0;
11108}
11109
11110
11111static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
11112 struct sigma_cmd *cmd)
11113{
11114 struct wpa_ctrl *ctrl;
11115 const char *intf = get_param(cmd, "Interface");
11116 const char *bssid = get_param(cmd, "Bssid");
11117 const char *ssid = get_param(cmd, "SSID");
11118 const char *security = get_param(cmd, "Security");
11119 const char *passphrase = get_param(cmd, "Passphrase");
11120 const char *pin = get_param(cmd, "PIN");
11121 char buf[1000];
11122 char ssid_hex[200], passphrase_hex[200];
11123 const char *keymgmt, *cipher;
11124
11125 if (intf == NULL)
11126 intf = get_main_ifname();
11127
11128 if (!bssid) {
11129 send_resp(dut, conn, SIGMA_ERROR,
11130 "ErrorCode,Missing Bssid argument");
11131 return 0;
11132 }
11133
11134 if (!ssid) {
11135 send_resp(dut, conn, SIGMA_ERROR,
11136 "ErrorCode,Missing SSID argument");
11137 return 0;
11138 }
11139
11140 if (!security) {
11141 send_resp(dut, conn, SIGMA_ERROR,
11142 "ErrorCode,Missing Security argument");
11143 return 0;
11144 }
11145
11146 if (!passphrase) {
11147 send_resp(dut, conn, SIGMA_ERROR,
11148 "ErrorCode,Missing Passphrase argument");
11149 return 0;
11150 }
11151
11152 if (!pin) {
11153 send_resp(dut, conn, SIGMA_ERROR,
11154 "ErrorCode,Missing PIN argument");
11155 return 0;
11156 }
11157
vamsi krishna8c9c1562017-05-12 15:51:46 +053011158 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
11159 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011160 send_resp(dut, conn, SIGMA_ERROR,
11161 "ErrorCode,Too long SSID/passphrase");
11162 return 0;
11163 }
11164
11165 ctrl = open_wpa_mon(intf);
11166 if (ctrl == NULL) {
11167 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11168 "wpa_supplicant monitor connection");
11169 return -2;
11170 }
11171
11172 if (strcasecmp(security, "wpa2-psk") == 0) {
11173 keymgmt = "WPA2PSK";
11174 cipher = "CCMP";
11175 } else {
11176 wpa_ctrl_detach(ctrl);
11177 wpa_ctrl_close(ctrl);
11178 send_resp(dut, conn, SIGMA_ERROR,
11179 "ErrorCode,Unsupported Security value");
11180 return 0;
11181 }
11182
11183 ascii2hexstr(ssid, ssid_hex);
11184 ascii2hexstr(passphrase, passphrase_hex);
11185 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
11186 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
11187
11188 if (wpa_command(intf, buf) < 0) {
11189 wpa_ctrl_detach(ctrl);
11190 wpa_ctrl_close(ctrl);
11191 send_resp(dut, conn, SIGMA_ERROR,
11192 "ErrorCode,Failed to start registrar");
11193 return 0;
11194 }
11195
11196 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
11197 dut->er_oper_performed = 1;
11198
11199 return wps_connection_event(dut, conn, ctrl, intf, 0);
11200}
11201
11202
11203static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
11204 struct sigma_conn *conn,
11205 struct sigma_cmd *cmd)
11206{
11207 struct wpa_ctrl *ctrl;
11208 const char *intf = get_param(cmd, "Interface");
11209 const char *bssid = get_param(cmd, "Bssid");
11210 char buf[100];
11211
11212 if (!bssid) {
11213 send_resp(dut, conn, SIGMA_ERROR,
11214 "ErrorCode,Missing Bssid argument");
11215 return 0;
11216 }
11217
11218 ctrl = open_wpa_mon(intf);
11219 if (ctrl == NULL) {
11220 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
11221 "wpa_supplicant monitor connection");
11222 return -2;
11223 }
11224
11225 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
11226
11227 if (wpa_command(intf, buf) < 0) {
11228 wpa_ctrl_detach(ctrl);
11229 wpa_ctrl_close(ctrl);
11230 send_resp(dut, conn, SIGMA_ERROR,
11231 "ErrorCode,Failed to start registrar");
11232 return 0;
11233 }
11234
11235 return wps_connection_event(dut, conn, ctrl, intf, 0);
11236}
11237
11238
vamsi krishna9b144002017-09-20 13:28:13 +053011239static int cmd_start_wps_registration(struct sigma_dut *dut,
11240 struct sigma_conn *conn,
11241 struct sigma_cmd *cmd)
11242{
11243 struct wpa_ctrl *ctrl;
11244 const char *intf = get_param(cmd, "Interface");
11245 const char *role, *method;
11246 int res;
11247 char buf[256];
11248 const char *events[] = {
11249 "CTRL-EVENT-CONNECTED",
11250 "WPS-OVERLAP-DETECTED",
11251 "WPS-TIMEOUT",
11252 "WPS-FAIL",
11253 NULL
11254 };
11255
11256 ctrl = open_wpa_mon(intf);
11257 if (!ctrl) {
11258 sigma_dut_print(dut, DUT_MSG_ERROR,
11259 "Failed to open wpa_supplicant monitor connection");
11260 return -2;
11261 }
11262
11263 role = get_param(cmd, "WpsRole");
11264 if (!role) {
11265 send_resp(dut, conn, SIGMA_INVALID,
11266 "ErrorCode,WpsRole not provided");
11267 goto fail;
11268 }
11269
11270 if (strcasecmp(role, "Enrollee") == 0) {
11271 method = get_param(cmd, "WpsConfigMethod");
11272 if (!method) {
11273 send_resp(dut, conn, SIGMA_INVALID,
11274 "ErrorCode,WpsConfigMethod not provided");
11275 goto fail;
11276 }
11277 if (strcasecmp(method, "PBC") == 0) {
11278 if (wpa_command(intf, "WPS_PBC") < 0) {
11279 send_resp(dut, conn, SIGMA_ERROR,
11280 "ErrorCode,Failed to enable PBC");
11281 goto fail;
11282 }
11283 } else {
11284 /* TODO: PIN method */
11285 send_resp(dut, conn, SIGMA_ERROR,
11286 "ErrorCode,Unsupported WpsConfigMethod value");
11287 goto fail;
11288 }
11289 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
11290 if (res < 0) {
11291 send_resp(dut, conn, SIGMA_ERROR,
11292 "ErrorCode,WPS connection did not complete");
11293 goto fail;
11294 }
11295 if (strstr(buf, "WPS-TIMEOUT")) {
11296 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,NoPeer");
11297 } else if (strstr(buf, "WPS-OVERLAP-DETECTED")) {
11298 send_resp(dut, conn, SIGMA_ERROR,
11299 "ErrorCode,OverlapSession");
11300 } else if (strstr(buf, "CTRL-EVENT-CONNECTED")) {
11301 send_resp(dut, conn, SIGMA_COMPLETE, "Successful");
11302 } else {
11303 send_resp(dut, conn, SIGMA_ERROR,
11304 "ErrorCode,WPS operation failed");
11305 }
11306 } else {
11307 /* TODO: Registrar role */
11308 send_resp(dut, conn, SIGMA_ERROR,
11309 "ErrorCode,Unsupported WpsRole value");
11310 }
11311
11312fail:
11313 wpa_ctrl_detach(ctrl);
11314 wpa_ctrl_close(ctrl);
11315 return 0;
11316}
11317
11318
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011319static int req_intf(struct sigma_cmd *cmd)
11320{
11321 return get_param(cmd, "interface") == NULL ? -1 : 0;
11322}
11323
11324
11325void sta_register_cmds(void)
11326{
11327 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
11328 cmd_sta_get_ip_config);
11329 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
11330 cmd_sta_set_ip_config);
11331 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
11332 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
11333 cmd_sta_get_mac_address);
11334 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
11335 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
11336 cmd_sta_verify_ip_connection);
11337 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
11338 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
11339 cmd_sta_set_encryption);
11340 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
11341 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
11342 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
11343 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
11344 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
11345 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
11346 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
11347 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
11348 cmd_sta_set_eapakaprime);
11349 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
11350 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
11351 /* TODO: sta_set_ibss */
11352 /* TODO: sta_set_mode */
11353 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
11354 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
11355 /* TODO: sta_up_load */
11356 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
11357 cmd_sta_preset_testparameters);
11358 /* TODO: sta_set_system */
11359 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
11360 /* TODO: sta_set_rifs_test */
11361 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
11362 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
11363 /* TODO: sta_send_coexist_mgmt */
11364 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
11365 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
11366 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
11367 sigma_dut_reg_cmd("sta_reset_default", req_intf,
11368 cmd_sta_reset_default);
11369 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
11370 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
11371 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
11372 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
11373 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
11374 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
11375 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
11376 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
11377 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
11378 cmd_sta_hs2_associate);
Jouni Malinenb639f1c2018-09-13 02:39:46 +030011379 sigma_dut_reg_cmd("sta_hs2_venue_info", req_intf,
11380 cmd_sta_hs2_venue_info);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011381 sigma_dut_reg_cmd("sta_add_credential", req_intf,
11382 cmd_sta_add_credential);
11383 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
Jouni Malinen5e5d43d2018-01-10 17:29:33 +020011384 sigma_dut_reg_cmd("sta_scan_bss", req_intf, cmd_sta_scan_bss);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011385 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
11386 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
11387 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
11388 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
11389 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
11390 cmd_sta_wps_connect_pw_token);
Jouni Malinen82905202018-04-29 17:20:10 +030011391 sigma_dut_reg_cmd("sta_exec_action", NULL, cmd_sta_exec_action);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011392 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
11393 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
vamsi krishna9b144002017-09-20 13:28:13 +053011394 sigma_dut_reg_cmd("start_wps_registration", req_intf,
11395 cmd_start_wps_registration);
Jouni Malinencd4e3c32015-10-29 12:39:56 +020011396}