blob: 4be4a0514084116d1222f9a6d3f781c4f31f20c3 [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.
4 * Copyright (c) 2011-2015, Qualcomm Atheros, Inc.
5 * All Rights Reserved.
6 * Licensed under the Clear BSD license. See README for more details.
7 */
8
9#include "sigma_dut.h"
10#include <sys/ioctl.h>
11#include <sys/stat.h>
12#ifdef __linux__
Lior Davidcc88b562017-01-03 18:52:09 +020013#include <regex.h>
14#include <dirent.h>
Jouni Malinencd4e3c32015-10-29 12:39:56 +020015#include <sys/time.h>
16#include <netpacket/packet.h>
17#include <linux/if_ether.h>
18#ifdef ANDROID
19#include <cutils/properties.h>
20#include <android/log.h>
21#include "keystore_get.h"
22#else /* ANDROID */
23#include <ifaddrs.h>
24#endif /* ANDROID */
25#include <netdb.h>
26#endif /* __linux__ */
27#ifdef __QNXNTO__
28#include <net/if_dl.h>
29#endif /* __QNXNTO__ */
30#include "wpa_ctrl.h"
31#include "wpa_helpers.h"
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -070032#include "miracast.h"
Jouni Malinencd4e3c32015-10-29 12:39:56 +020033
34/* Temporary files for sta_send_addba */
35#define VI_QOS_TMP_FILE "/tmp/vi-qos.tmp"
36#define VI_QOS_FILE "/tmp/vi-qos.txt"
37#define VI_QOS_REFFILE "/etc/vi-qos.txt"
38
39/*
40 * MTU for Ethernet need to take into account 8-byte SNAP header
41 * to be added when encapsulating Ethernet frame into 802.11
42 */
43#ifndef IEEE80211_MAX_DATA_LEN_DMG
44#define IEEE80211_MAX_DATA_LEN_DMG 7920
45#endif
46#ifndef IEEE80211_SNAP_LEN_DMG
47#define IEEE80211_SNAP_LEN_DMG 8
48#endif
49
Ashwini Patil00402582017-04-13 12:29:39 +053050#define NON_PREF_CH_LIST_SIZE 100
51
Jouni Malinencd4e3c32015-10-29 12:39:56 +020052extern char *sigma_wpas_ctrl;
53extern char *sigma_cert_path;
54extern enum driver_type wifi_chip_type;
55extern char *sigma_radio_ifname[];
56
Lior David0fe101e2017-03-09 16:09:50 +020057#ifdef __linux__
58#define WIL_WMI_MAX_PAYLOAD 248
59#define WIL_WMI_BF_TRIG_CMDID 0x83a
60
61struct wil_wmi_header {
62 uint8_t mid;
63 uint8_t reserved;
64 uint16_t cmd;
65 uint32_t ts;
66} __attribute__((packed));
67
68enum wil_wmi_bf_trig_type {
69 WIL_WMI_SLS,
70 WIL_WMI_BRP_RX,
71 WIL_WMI_BRP_TX,
72};
73
74struct wil_wmi_bf_trig_cmd {
75 /* enum wil_wmi_bf_trig_type */
76 uint32_t bf_type;
77 /* cid when type == WMI_BRP_RX */
78 uint32_t sta_id;
79 uint32_t reserved;
80 /* mac address when type = WIL_WMI_SLS */
81 uint8_t dest_mac[6];
82} __attribute__((packed));
83#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +020084
85#ifdef ANDROID
86
87static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname);
88
89#define ANDROID_KEYSTORE_GET 'g'
90#define ANDROID_KEYSTORE_GET_PUBKEY 'b'
91
92static int android_keystore_get(char cmd, const char *key, unsigned char *val)
93{
Jouni Malinencd4e3c32015-10-29 12:39:56 +020094 /* Android 4.3 changed keystore design, so need to use keystore_get() */
95#ifndef KEYSTORE_MESSAGE_SIZE
96#define KEYSTORE_MESSAGE_SIZE 65535
97#endif /* KEYSTORE_MESSAGE_SIZE */
98
99 ssize_t len;
100 uint8_t *value = NULL;
101
102 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
103 "keystore command '%c' key '%s' --> keystore_get",
104 cmd, key);
105
106 len = keystore_get(key, strlen(key), &value);
107 if (len < 0) {
108 __android_log_print(ANDROID_LOG_DEBUG, "sigma_dut",
109 "keystore_get() failed");
110 return -1;
111 }
112
113 if (len > KEYSTORE_MESSAGE_SIZE)
114 len = KEYSTORE_MESSAGE_SIZE;
115 memcpy(val, value, len);
116 free(value);
117 return len;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200118}
119#endif /* ANDROID */
120
121
122int set_ps(const char *intf, struct sigma_dut *dut, int enabled)
123{
124#ifdef __linux__
125 char buf[100];
126
127 if (wifi_chip_type == DRIVER_WCN) {
128 if (enabled) {
129 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 906");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530130 if (system(buf) != 0)
131 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200132 } else {
133 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 905");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530134 if (system(buf) != 0)
135 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200136 snprintf(buf, sizeof(buf), "iwpriv wlan0 dump 912");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530137 if (system(buf) != 0)
138 goto set_power_save;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200139 }
140
141 return 0;
142 }
143
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530144set_power_save:
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200145 snprintf(buf, sizeof(buf), "./iw dev %s set power_save %s",
146 intf, enabled ? "on" : "off");
147 if (system(buf) != 0) {
148 snprintf(buf, sizeof(buf), "iw dev %s set power_save %s",
149 intf, enabled ? "on" : "off");
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530150 if (system(buf) != 0) {
151 sigma_dut_print(dut, DUT_MSG_ERROR,
152 "Failed to set power save %s",
153 enabled ? "on" : "off");
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200154 return -1;
Pradeep Reddy POTTETI625b3702016-09-20 17:09:58 +0530155 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200156 }
157
158 return 0;
159#else /* __linux__ */
160 return -1;
161#endif /* __linux__ */
162}
163
164
Lior Davidcc88b562017-01-03 18:52:09 +0200165#ifdef __linux__
Lior David0fe101e2017-03-09 16:09:50 +0200166
Lior Davidcc88b562017-01-03 18:52:09 +0200167static int wil6210_get_debugfs_dir(struct sigma_dut *dut, char *path,
168 size_t len)
169{
170 DIR *dir, *wil_dir;
171 struct dirent *entry;
172 int ret = -1;
173 const char *root_path = "/sys/kernel/debug/ieee80211";
174
175 dir = opendir(root_path);
176 if (!dir)
177 return -2;
178
179 while ((entry = readdir(dir))) {
180 if (strcmp(entry->d_name, ".") == 0 ||
181 strcmp(entry->d_name, "..") == 0)
182 continue;
183
184 if (snprintf(path, len, "%s/%s/wil6210",
185 root_path, entry->d_name) >= (int) len) {
186 ret = -3;
187 break;
188 }
189
190 wil_dir = opendir(path);
191 if (wil_dir) {
192 closedir(wil_dir);
193 ret = 0;
194 break;
195 }
196 }
197
198 closedir(dir);
199 return ret;
200}
Lior David0fe101e2017-03-09 16:09:50 +0200201
202
203static int wil6210_wmi_send(struct sigma_dut *dut, uint16_t command,
204 void *payload, uint16_t length)
205{
206 struct {
207 struct wil_wmi_header hdr;
208 char payload[WIL_WMI_MAX_PAYLOAD];
209 } __attribute__((packed)) cmd;
210 char buf[128], fname[128];
211 size_t towrite, written;
212 FILE *f;
213
214 if (length > WIL_WMI_MAX_PAYLOAD) {
215 sigma_dut_print(dut, DUT_MSG_ERROR,
216 "payload too large(%u, max %u)",
217 length, WIL_WMI_MAX_PAYLOAD);
218 return -1;
219 }
220
221 memset(&cmd.hdr, 0, sizeof(cmd.hdr));
222 cmd.hdr.cmd = command;
223 memcpy(cmd.payload, payload, length);
224
225 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
226 sigma_dut_print(dut, DUT_MSG_ERROR,
227 "failed to get wil6210 debugfs dir");
228 return -1;
229 }
230
231 snprintf(fname, sizeof(fname), "%s/wmi_send", buf);
232 f = fopen(fname, "wb");
233 if (!f) {
234 sigma_dut_print(dut, DUT_MSG_ERROR,
235 "failed to open: %s", fname);
236 return -1;
237 }
238
239 towrite = sizeof(cmd.hdr) + length;
240 written = fwrite(&cmd, 1, towrite, f);
241 fclose(f);
242 if (written != towrite) {
243 sigma_dut_print(dut, DUT_MSG_ERROR,
244 "failed to send wmi %u", command);
245 return -1;
246 }
247
248 return 0;
249}
250
251
252static int wil6210_get_sta_info_field(struct sigma_dut *dut, const char *bssid,
253 const char *pattern, unsigned int *field)
254{
255 char buf[128], fname[128];
256 FILE *f;
257 regex_t re;
258 regmatch_t m[2];
259 int rc, ret = -1;
260
261 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
262 sigma_dut_print(dut, DUT_MSG_ERROR,
263 "failed to get wil6210 debugfs dir");
264 return -1;
265 }
266
267 snprintf(fname, sizeof(fname), "%s/stations", buf);
268 f = fopen(fname, "r");
269 if (!f) {
270 sigma_dut_print(dut, DUT_MSG_ERROR,
271 "failed to open: %s", fname);
272 return -1;
273 }
274
275 if (regcomp(&re, pattern, REG_EXTENDED)) {
276 sigma_dut_print(dut, DUT_MSG_ERROR,
277 "regcomp failed: %s", pattern);
278 goto out;
279 }
280
281 /*
282 * find the entry for the mac address
283 * line is of the form: [n] 11:22:33:44:55:66 state AID aid
284 */
285 while (fgets(buf, sizeof(buf), f)) {
286 if (strcasestr(buf, bssid)) {
287 /* extract the field (CID/AID/state) */
288 rc = regexec(&re, buf, 2, m, 0);
289 if (!rc && (m[1].rm_so >= 0)) {
290 buf[m[1].rm_eo] = 0;
291 *field = atoi(&buf[m[1].rm_so]);
292 ret = 0;
293 break;
294 }
295 }
296 }
297
298 regfree(&re);
299 if (ret)
300 sigma_dut_print(dut, DUT_MSG_ERROR,
301 "could not extract field");
302
303out:
304 fclose(f);
305
306 return ret;
307}
308
309
310static int wil6210_get_cid(struct sigma_dut *dut, const char *bssid,
311 unsigned int *cid)
312{
313 const char *pattern = "\\[([0-9]+)\\]";
314
315 return wil6210_get_sta_info_field(dut, bssid, pattern, cid);
316}
317
318
319static int wil6210_send_brp_rx(struct sigma_dut *dut, const char *mac,
320 int l_rx)
321{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700322 struct wil_wmi_bf_trig_cmd cmd;
Lior David0fe101e2017-03-09 16:09:50 +0200323 unsigned int cid;
324
Rakesh Sunki556237d2017-03-30 14:49:31 -0700325 memset(&cmd, 0, sizeof(cmd));
326
Lior David0fe101e2017-03-09 16:09:50 +0200327 if (wil6210_get_cid(dut, mac, &cid))
328 return -1;
329
330 cmd.bf_type = WIL_WMI_BRP_RX;
331 cmd.sta_id = cid;
332 /* training length (l_rx) is ignored, FW always uses length 16 */
333 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
334 &cmd, sizeof(cmd));
335}
336
337
338static int wil6210_send_sls(struct sigma_dut *dut, const char *mac)
339{
Rakesh Sunki556237d2017-03-30 14:49:31 -0700340 struct wil_wmi_bf_trig_cmd cmd;
341
342 memset(&cmd, 0, sizeof(cmd));
Lior David0fe101e2017-03-09 16:09:50 +0200343
344 if (parse_mac_address(dut, mac, (unsigned char *)&cmd.dest_mac))
345 return -1;
346
347 cmd.bf_type = WIL_WMI_SLS;
348 return wil6210_wmi_send(dut, WIL_WMI_BF_TRIG_CMDID,
349 &cmd, sizeof(cmd));
350}
351
Lior Davidcc88b562017-01-03 18:52:09 +0200352#endif /* __linux__ */
353
354
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200355static void static_ip_file(int proto, const char *addr, const char *mask,
356 const char *gw)
357{
358 if (proto) {
359 FILE *f = fopen("static-ip", "w");
360 if (f) {
361 fprintf(f, "%d %s %s %s\n", proto, addr,
362 mask ? mask : "N/A",
363 gw ? gw : "N/A");
364 fclose(f);
365 }
366 } else {
367 unlink("static-ip");
368 }
369}
370
371
372static int send_neighbor_request(struct sigma_dut *dut, const char *intf,
373 const char *ssid)
374{
375#ifdef __linux__
376 char buf[100];
377
378 snprintf(buf, sizeof(buf), "iwpriv %s neighbor %s",
379 intf, ssid);
380 sigma_dut_print(dut, DUT_MSG_INFO, "Request: %s", buf);
381
382 if (system(buf) != 0) {
383 sigma_dut_print(dut, DUT_MSG_ERROR,
384 "iwpriv neighbor request failed");
385 return -1;
386 }
387
388 sigma_dut_print(dut, DUT_MSG_INFO, "iwpriv neighbor request send");
389
390 return 0;
391#else /* __linux__ */
392 return -1;
393#endif /* __linux__ */
394}
395
396
397static int send_trans_mgmt_query(struct sigma_dut *dut, const char *intf,
398 const char *ssid)
399{
400 /*
401 * In the earlier builds we used WNM_QUERY and in later
402 * builds used WNM_BSS_QUERY.
403 */
404
405 if (wpa_command(intf, "WNM_BSS_QUERY 0") != 0) {
406 sigma_dut_print(dut, DUT_MSG_ERROR,
407 "transition management query failed");
408 return -1;
409 }
410
411 sigma_dut_print(dut, DUT_MSG_DEBUG,
412 "transition management query sent");
413
414 return 0;
415}
416
417
418int is_ip_addr(const char *str)
419{
420 const char *pos = str;
421 struct in_addr addr;
422
423 while (*pos) {
424 if (*pos != '.' && (*pos < '0' || *pos > '9'))
425 return 0;
426 pos++;
427 }
428
429 return inet_aton(str, &addr);
430}
431
432
433int is_ipv6_addr(const char *str)
434{
435 struct sockaddr_in6 addr;
436
437 return inet_pton(AF_INET6, str, &(addr.sin6_addr));
438}
439
440
441int get_ip_config(struct sigma_dut *dut, const char *ifname, char *buf,
442 size_t buf_len)
443{
444 char tmp[256], *pos, *pos2;
445 FILE *f;
446 char ip[16], mask[15], dns[16], sec_dns[16];
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530447 const char *str_ps;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200448 int is_dhcp = 0;
449 int s;
450#ifdef ANDROID
451 char prop[PROPERTY_VALUE_MAX];
452#endif /* ANDROID */
453
454 ip[0] = '\0';
455 mask[0] = '\0';
456 dns[0] = '\0';
457 sec_dns[0] = '\0';
458
459 s = socket(PF_INET, SOCK_DGRAM, 0);
460 if (s >= 0) {
461 struct ifreq ifr;
462 struct sockaddr_in saddr;
463
464 memset(&ifr, 0, sizeof(ifr));
465 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
466 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
467 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
468 "%s IP address: %s",
469 ifname, strerror(errno));
470 } else {
471 memcpy(&saddr, &ifr.ifr_addr,
472 sizeof(struct sockaddr_in));
473 strncpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
474 }
475
476 if (ioctl(s, SIOCGIFNETMASK, &ifr) == 0) {
477 memcpy(&saddr, &ifr.ifr_addr,
478 sizeof(struct sockaddr_in));
479 strncpy(mask, inet_ntoa(saddr.sin_addr), sizeof(mask));
480 }
481 close(s);
482 }
483
484#ifdef ANDROID
485 snprintf(tmp, sizeof(tmp), "dhcp.%s.pid", ifname);
486 if (property_get(tmp, prop, NULL) != 0 && atoi(prop) > 0) {
487 snprintf(tmp, sizeof(tmp), "dhcp.%s.result", ifname);
488 if (property_get(tmp, prop, NULL) != 0 &&
489 strcmp(prop, "ok") == 0) {
490 snprintf(tmp, sizeof(tmp), "dhcp.%s.ipaddress",
491 ifname);
492 if (property_get(tmp, prop, NULL) != 0 &&
493 strcmp(ip, prop) == 0)
494 is_dhcp = 1;
495 }
496 }
497
498 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns1", ifname);
499 if (property_get(tmp, prop, NULL) != 0) {
500 strncpy(dns, prop, sizeof(dns));
501 dns[sizeof(dns) - 1] = '\0';
502 } else {
503 if (property_get("net.dns1", prop, NULL) != 0) {
504 strncpy(dns, prop, sizeof(dns));
505 dns[sizeof(dns) - 1] = '\0';
506 }
507 }
508
509 snprintf(tmp, sizeof(tmp), "dhcp.%s.dns2", ifname);
510 if (property_get(tmp, prop, NULL) != 0) {
511 strncpy(sec_dns, prop, sizeof(sec_dns));
512 sec_dns[sizeof(sec_dns) - 1] = '\0';
513 }
514#else /* ANDROID */
515#ifdef __linux__
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530516 if (get_driver_type() == DRIVER_OPENWRT)
517 str_ps = "ps -w";
518 else
519 str_ps = "ps ax";
520 snprintf(tmp, sizeof(tmp),
521 "%s | grep dhclient | grep -v grep | grep -q %s",
522 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200523 if (system(tmp) == 0)
524 is_dhcp = 1;
525 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530526 snprintf(tmp, sizeof(tmp),
527 "%s | grep udhcpc | grep -v grep | grep -q %s",
528 str_ps, ifname);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200529 if (system(tmp) == 0)
530 is_dhcp = 1;
531 else {
Sarvepalli, Rajesh Babua76c6442016-03-18 20:34:26 +0530532 snprintf(tmp, sizeof(tmp),
533 "%s | grep dhcpcd | 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 }
538 }
539#endif /* __linux__ */
540
541 f = fopen("/etc/resolv.conf", "r");
542 if (f) {
543 while (fgets(tmp, sizeof(tmp), f)) {
544 if (strncmp(tmp, "nameserver", 10) != 0)
545 continue;
546 pos = tmp + 10;
547 while (*pos == ' ' || *pos == '\t')
548 pos++;
549 pos2 = pos;
550 while (*pos2) {
551 if (*pos2 == '\n' || *pos2 == '\r') {
552 *pos2 = '\0';
553 break;
554 }
555 pos2++;
556 }
557 if (!dns[0]) {
558 strncpy(dns, pos, sizeof(dns));
559 dns[sizeof(dns) - 1] = '\0';
560 } else if (!sec_dns[0]) {
561 strncpy(sec_dns, pos, sizeof(sec_dns));
562 sec_dns[sizeof(sec_dns) - 1] = '\0';
563 }
564 }
565 fclose(f);
566 }
567#endif /* ANDROID */
568
569 snprintf(buf, buf_len, "dhcp,%d,ip,%s,mask,%s,primary-dns,%s",
570 is_dhcp, ip, mask, dns);
571 buf[buf_len - 1] = '\0';
572
573 return 0;
574}
575
576
577
578
579int get_ipv6_config(struct sigma_dut *dut, const char *ifname, char *buf,
580 size_t buf_len)
581{
582#ifdef __linux__
583#ifdef ANDROID
584 char cmd[200], result[1000], *pos, *end;
585 FILE *f;
586 size_t len;
587
588 snprintf(cmd, sizeof(cmd), "ip addr show dev %s scope global", ifname);
589 f = popen(cmd, "r");
590 if (f == NULL)
591 return -1;
592 len = fread(result, 1, sizeof(result) - 1, f);
593 pclose(f);
594 if (len == 0)
595 return -1;
596 result[len] = '\0';
597 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s result: %s\n", cmd, result);
598
599 pos = strstr(result, "inet6 ");
600 if (pos == NULL)
601 return -1;
602 pos += 6;
603 end = strchr(pos, ' ');
604 if (end)
605 *end = '\0';
606 end = strchr(pos, '/');
607 if (end)
608 *end = '\0';
609 snprintf(buf, buf_len, "ip,%s", pos);
610 buf[buf_len - 1] = '\0';
611 return 0;
612#else /* ANDROID */
613 struct ifaddrs *ifaddr, *ifa;
614 int res, found = 0;
615 char host[NI_MAXHOST];
616
617 if (getifaddrs(&ifaddr) < 0) {
618 perror("getifaddrs");
619 return -1;
620 }
621
622 for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
623 if (strcasecmp(ifname, ifa->ifa_name) != 0)
624 continue;
625 if (ifa->ifa_addr == NULL ||
626 ifa->ifa_addr->sa_family != AF_INET6)
627 continue;
628
629 res = getnameinfo(ifa->ifa_addr, sizeof(struct sockaddr_in6),
630 host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
631 if (res != 0) {
632 sigma_dut_print(dut, DUT_MSG_DEBUG, "getnameinfo: %s",
633 gai_strerror(res));
634 continue;
635 }
636 if (strncmp(host, "fe80::", 6) == 0)
637 continue; /* skip link-local */
638
639 sigma_dut_print(dut, DUT_MSG_DEBUG, "ifaddr: %s", host);
640 found = 1;
641 break;
642 }
643
644 freeifaddrs(ifaddr);
645
646 if (found) {
647 char *pos;
648 pos = strchr(host, '%');
649 if (pos)
650 *pos = '\0';
651 snprintf(buf, buf_len, "ip,%s", host);
652 buf[buf_len - 1] = '\0';
653 return 0;
654 }
655
656#endif /* ANDROID */
657#endif /* __linux__ */
658 return -1;
659}
660
661
662static int cmd_sta_get_ip_config(struct sigma_dut *dut,
663 struct sigma_conn *conn,
664 struct sigma_cmd *cmd)
665{
666 const char *intf = get_param(cmd, "Interface");
667 const char *ifname;
668 char buf[200];
669 const char *val;
670 int type = 1;
671
672 if (intf == NULL)
673 return -1;
674
675 if (strcmp(intf, get_main_ifname()) == 0)
676 ifname = get_station_ifname();
677 else
678 ifname = intf;
679
680 /*
681 * UCC may assume the IP address to be available immediately after
682 * association without trying to run sta_get_ip_config multiple times.
683 * Sigma CAPI does not specify this command as a block command that
684 * would wait for the address to become available, but to pass tests
685 * more reliably, it looks like such a wait may be needed here.
686 */
687 if (wait_ip_addr(dut, ifname, 15) < 0) {
688 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get IP address "
689 "for sta_get_ip_config");
690 /*
691 * Try to continue anyway since many UCC tests do not really
692 * care about the return value from here..
693 */
694 }
695
696 val = get_param(cmd, "Type");
697 if (val)
698 type = atoi(val);
699 if (type == 2 || dut->last_set_ip_config_ipv6) {
700 int i;
701
702 /*
703 * Since we do not have proper wait for IPv6 addresses, use a
704 * fixed two second delay here as a workaround for UCC script
705 * assuming IPv6 address is available when this command returns.
706 * Some scripts did not use Type,2 properly for IPv6, so include
707 * also the cases where the previous sta_set_ip_config indicated
708 * use of IPv6.
709 */
710 sigma_dut_print(dut, DUT_MSG_INFO, "Wait up to extra ten seconds in sta_get_ip_config for IPv6 address");
711 for (i = 0; i < 10; i++) {
712 sleep(1);
713 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) == 0)
714 {
715 sigma_dut_print(dut, DUT_MSG_INFO, "Found IPv6 address");
716 send_resp(dut, conn, SIGMA_COMPLETE, buf);
717#ifdef ANDROID
718 sigma_dut_print(dut, DUT_MSG_INFO,
719 "Adding IPv6 rule on Android");
720 add_ipv6_rule(dut, intf);
721#endif /* ANDROID */
722
723 return 0;
724 }
725 }
726 }
727 if (type == 1) {
728 if (get_ip_config(dut, ifname, buf, sizeof(buf)) < 0)
729 return -2;
730 } else if (type == 2) {
731 if (get_ipv6_config(dut, ifname, buf, sizeof(buf)) < 0)
732 return -2;
733 } else {
734 send_resp(dut, conn, SIGMA_ERROR,
735 "errorCode,Unsupported address type");
736 return 0;
737 }
738
739 send_resp(dut, conn, SIGMA_COMPLETE, buf);
740 return 0;
741}
742
743
744static void kill_dhcp_client(struct sigma_dut *dut, const char *ifname)
745{
746#ifdef __linux__
747 char buf[200];
748 char path[128];
749 struct stat s;
750
751#ifdef ANDROID
752 snprintf(path, sizeof(path), "/data/misc/dhcp/dhcpcd-%s.pid", ifname);
753#else /* ANDROID */
754 snprintf(path, sizeof(path), "/var/run/dhclient-%s.pid", ifname);
755#endif /* ANDROID */
756 if (stat(path, &s) == 0) {
757 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
758 sigma_dut_print(dut, DUT_MSG_INFO,
759 "Kill previous DHCP client: %s", buf);
760 if (system(buf) != 0)
761 sigma_dut_print(dut, DUT_MSG_INFO,
762 "Failed to kill DHCP client");
763 unlink(path);
764 sleep(1);
765 } else {
766 snprintf(path, sizeof(path), "/var/run/dhcpcd-%s.pid", ifname);
767
768 if (stat(path, &s) == 0) {
769 snprintf(buf, sizeof(buf), "kill `cat %s`", path);
770 sigma_dut_print(dut, DUT_MSG_INFO,
771 "Kill previous DHCP client: %s", buf);
772 if (system(buf) != 0)
773 sigma_dut_print(dut, DUT_MSG_INFO,
774 "Failed to kill DHCP client");
775 unlink(path);
776 sleep(1);
777 }
778 }
779#endif /* __linux__ */
780}
781
782
783static int start_dhcp_client(struct sigma_dut *dut, const char *ifname)
784{
785#ifdef __linux__
786 char buf[200];
787
788#ifdef ANDROID
Purushottam Kushwaha46d64262016-08-23 17:57:53 +0530789 if (access("/system/bin/dhcpcd", F_OK) != -1) {
790 snprintf(buf, sizeof(buf),
791 "/system/bin/dhcpcd -b %s", ifname);
792 } else if (access("/system/bin/dhcptool", F_OK) != -1) {
793 snprintf(buf, sizeof(buf), "/system/bin/dhcptool %s &", ifname);
794 } else {
795 sigma_dut_print(dut, DUT_MSG_ERROR,
796 "DHCP client program missing");
797 return 0;
798 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200799#else /* ANDROID */
800 snprintf(buf, sizeof(buf),
801 "dhclient -nw -pf /var/run/dhclient-%s.pid %s",
802 ifname, ifname);
803#endif /* ANDROID */
804 sigma_dut_print(dut, DUT_MSG_INFO, "Start DHCP client: %s", buf);
805 if (system(buf) != 0) {
806 snprintf(buf, sizeof(buf), "dhcpcd -t 0 %s &", ifname);
807 if (system(buf) != 0) {
808 sigma_dut_print(dut, DUT_MSG_INFO,
809 "Failed to start DHCP client");
810#ifndef ANDROID
811 return -1;
812#endif /* ANDROID */
813 }
814 }
815#endif /* __linux__ */
816
817 return 0;
818}
819
820
821static int clear_ip_addr(struct sigma_dut *dut, const char *ifname)
822{
823#ifdef __linux__
824 char buf[200];
825
826 snprintf(buf, sizeof(buf), "ip addr flush dev %s", ifname);
827 if (system(buf) != 0) {
828 sigma_dut_print(dut, DUT_MSG_INFO,
829 "Failed to clear IP addresses");
830 return -1;
831 }
832#endif /* __linux__ */
833
834 return 0;
835}
836
837
838#ifdef ANDROID
839static int add_ipv6_rule(struct sigma_dut *dut, const char *ifname)
840{
841 char cmd[200], *result, *pos;
842 FILE *fp;
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530843 int tableid;
844 size_t len, result_len = 1000;
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200845
846 snprintf(cmd, sizeof(cmd), "ip -6 route list table all | grep %s",
847 ifname);
848 fp = popen(cmd, "r");
849 if (fp == NULL)
850 return -1;
851
852 result = malloc(result_len);
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530853 if (result == NULL) {
854 fclose(fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200855 return -1;
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +0530856 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200857
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530858 len = fread(result, 1, result_len - 1, fp);
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200859 fclose(fp);
860
861 if (len == 0) {
862 free(result);
863 return -1;
864 }
Pradeep Reddy POTTETIf58a1fe2016-10-13 17:22:03 +0530865 result[len] = '\0';
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200866
867 pos = strstr(result, "table ");
868 if (pos == NULL) {
869 free(result);
870 return -1;
871 }
872
873 pos += strlen("table ");
874 tableid = atoi(pos);
875 if (tableid != 0) {
876 if (system("ip -6 rule del prio 22000") != 0) {
877 /* ignore any error */
878 }
879 snprintf(cmd, sizeof(cmd),
880 "ip -6 rule add from all lookup %d prio 22000",
881 tableid);
882 if (system(cmd) != 0) {
883 sigma_dut_print(dut, DUT_MSG_INFO,
884 "Failed to run %s", cmd);
885 free(result);
886 return -1;
887 }
888 } else {
889 sigma_dut_print(dut, DUT_MSG_INFO,
890 "No Valid Table Id found %s", pos);
891 free(result);
892 return -1;
893 }
894 free(result);
895
896 return 0;
897}
898#endif /* ANDROID */
899
900
901static int cmd_sta_set_ip_config(struct sigma_dut *dut,
902 struct sigma_conn *conn,
903 struct sigma_cmd *cmd)
904{
905 const char *intf = get_param(cmd, "Interface");
906 const char *ifname;
907 char buf[200];
908 const char *val, *ip, *mask, *gw;
909 int type = 1;
910
911 if (intf == NULL)
912 return -1;
913
914 if (strcmp(intf, get_main_ifname()) == 0)
915 ifname = get_station_ifname();
916 else
917 ifname = intf;
918
919 if (if_nametoindex(ifname) == 0) {
920 send_resp(dut, conn, SIGMA_ERROR,
921 "ErrorCode,Unknown interface");
922 return 0;
923 }
924
925 val = get_param(cmd, "Type");
926 if (val) {
927 type = atoi(val);
928 if (type != 1 && type != 2) {
929 send_resp(dut, conn, SIGMA_ERROR,
930 "ErrorCode,Unsupported address type");
931 return 0;
932 }
933 }
934
935 dut->last_set_ip_config_ipv6 = 0;
936
937 val = get_param(cmd, "dhcp");
938 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "true") == 0)) {
939 static_ip_file(0, NULL, NULL, NULL);
940#ifdef __linux__
941 if (type == 2) {
942 dut->last_set_ip_config_ipv6 = 1;
943 sigma_dut_print(dut, DUT_MSG_INFO, "Using IPv6 "
944 "stateless address autoconfiguration");
945#ifdef ANDROID
946 /*
947 * This sleep is required as the assignment in case of
948 * Android is taking time and is done by the kernel.
949 * The subsequent ping for IPv6 is impacting HS20 test
950 * case.
951 */
952 sleep(2);
953 add_ipv6_rule(dut, intf);
954#endif /* ANDROID */
955 /* Assume this happens by default */
956 return 1;
957 }
958
959 kill_dhcp_client(dut, ifname);
960 if (start_dhcp_client(dut, ifname) < 0)
961 return -2;
962 return 1;
963#endif /* __linux__ */
964 return -2;
965 }
966
967 ip = get_param(cmd, "ip");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +0530968 if (!ip) {
969 send_resp(dut, conn, SIGMA_INVALID,
970 "ErrorCode,Missing IP address");
971 return 0;
972 }
973
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200974 mask = get_param(cmd, "mask");
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +0530975 if (!mask) {
976 send_resp(dut, conn, SIGMA_INVALID,
977 "ErrorCode,Missing subnet mask");
978 return 0;
979 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +0200980
981 if (type == 2) {
982 int net = atoi(mask);
983
984 if ((net < 0 && net > 64) || !is_ipv6_addr(ip))
985 return -1;
986
987 if (dut->no_ip_addr_set) {
988 snprintf(buf, sizeof(buf),
989 "sysctl net.ipv6.conf.%s.disable_ipv6=1",
990 ifname);
991 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
992 if (system(buf) != 0) {
993 sigma_dut_print(dut, DUT_MSG_DEBUG,
994 "Failed to disable IPv6 address before association");
995 }
996 } else {
997 snprintf(buf, sizeof(buf),
998 "ip -6 addr del %s/%s dev %s",
999 ip, mask, ifname);
1000 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1001 if (system(buf) != 0) {
1002 /*
1003 * This command may fail if the address being
1004 * deleted does not exist. Inaction here is
1005 * intentional.
1006 */
1007 }
1008
1009 snprintf(buf, sizeof(buf),
1010 "ip -6 addr add %s/%s dev %s",
1011 ip, mask, ifname);
1012 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
1013 if (system(buf) != 0) {
1014 send_resp(dut, conn, SIGMA_ERROR,
1015 "ErrorCode,Failed to set IPv6 address");
1016 return 0;
1017 }
1018 }
1019
1020 dut->last_set_ip_config_ipv6 = 1;
1021 static_ip_file(6, ip, mask, NULL);
1022 return 1;
1023 } else if (type == 1) {
Pradeep Reddy POTTETIb18c5652016-01-18 12:45:37 +05301024 if (!is_ip_addr(ip) || !is_ip_addr(mask))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001025 return -1;
1026 }
1027
1028 kill_dhcp_client(dut, ifname);
1029
1030 if (!dut->no_ip_addr_set) {
1031 snprintf(buf, sizeof(buf), "ifconfig %s %s netmask %s",
1032 ifname, ip, mask);
1033 if (system(buf) != 0) {
1034 send_resp(dut, conn, SIGMA_ERROR,
1035 "ErrorCode,Failed to set IP address");
1036 return 0;
1037 }
1038 }
1039
1040 gw = get_param(cmd, "defaultGateway");
1041 if (gw) {
1042 if (!is_ip_addr(gw))
1043 return -1;
1044 snprintf(buf, sizeof(buf), "route add default gw %s", gw);
1045 if (!dut->no_ip_addr_set && system(buf) != 0) {
1046 snprintf(buf, sizeof(buf), "ip ro re default via %s",
1047 gw);
1048 if (system(buf) != 0) {
1049 send_resp(dut, conn, SIGMA_ERROR,
1050 "ErrorCode,Failed "
1051 "to set default gateway");
1052 return 0;
1053 }
1054 }
1055 }
1056
1057 val = get_param(cmd, "primary-dns");
1058 if (val) {
1059 /* TODO */
1060 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored primary-dns %s "
1061 "setting", val);
1062 }
1063
1064 val = get_param(cmd, "secondary-dns");
1065 if (val) {
1066 /* TODO */
1067 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored secondary-dns %s "
1068 "setting", val);
1069 }
1070
1071 static_ip_file(4, ip, mask, gw);
1072
1073 return 1;
1074}
1075
1076
1077static int cmd_sta_get_info(struct sigma_dut *dut, struct sigma_conn *conn,
1078 struct sigma_cmd *cmd)
1079{
1080 /* const char *intf = get_param(cmd, "Interface"); */
1081 /* TODO: could report more details here */
1082 send_resp(dut, conn, SIGMA_COMPLETE, "vendor,Atheros");
1083 return 0;
1084}
1085
1086
1087static int cmd_sta_get_mac_address(struct sigma_dut *dut,
1088 struct sigma_conn *conn,
1089 struct sigma_cmd *cmd)
1090{
1091 /* const char *intf = get_param(cmd, "Interface"); */
1092 char addr[20], resp[50];
1093
1094 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
1095 < 0)
1096 return -2;
1097
1098 snprintf(resp, sizeof(resp), "mac,%s", addr);
1099 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1100 return 0;
1101}
1102
1103
1104static int cmd_sta_is_connected(struct sigma_dut *dut, struct sigma_conn *conn,
1105 struct sigma_cmd *cmd)
1106{
1107 /* const char *intf = get_param(cmd, "Interface"); */
1108 int connected = 0;
1109 char result[32];
1110 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
1111 sizeof(result)) < 0) {
1112 sigma_dut_print(dut, DUT_MSG_INFO, "Could not get interface "
1113 "%s status", get_station_ifname());
1114 return -2;
1115 }
1116
1117 sigma_dut_print(dut, DUT_MSG_DEBUG, "wpa_state=%s", result);
1118 if (strncmp(result, "COMPLETED", 9) == 0)
1119 connected = 1;
1120
1121 if (connected)
1122 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1123 else
1124 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1125
1126 return 0;
1127}
1128
1129
1130static int cmd_sta_verify_ip_connection(struct sigma_dut *dut,
1131 struct sigma_conn *conn,
1132 struct sigma_cmd *cmd)
1133{
1134 /* const char *intf = get_param(cmd, "Interface"); */
1135 const char *dst, *timeout;
1136 int wait_time = 90;
1137 char buf[100];
1138 int res;
1139
1140 dst = get_param(cmd, "destination");
1141 if (dst == NULL || !is_ip_addr(dst))
1142 return -1;
1143
1144 timeout = get_param(cmd, "timeout");
1145 if (timeout) {
1146 wait_time = atoi(timeout);
1147 if (wait_time < 1)
1148 wait_time = 1;
1149 }
1150
1151 /* TODO: force renewal of IP lease if DHCP is enabled */
1152
1153 snprintf(buf, sizeof(buf), "ping %s -c 3 -W %d", dst, wait_time);
1154 res = system(buf);
1155 sigma_dut_print(dut, DUT_MSG_DEBUG, "ping returned: %d", res);
1156 if (res == 0)
1157 send_resp(dut, conn, SIGMA_COMPLETE, "connected,1");
1158 else if (res == 256)
1159 send_resp(dut, conn, SIGMA_COMPLETE, "connected,0");
1160 else
1161 return -2;
1162
1163 return 0;
1164}
1165
1166
1167static int cmd_sta_get_bssid(struct sigma_dut *dut, struct sigma_conn *conn,
1168 struct sigma_cmd *cmd)
1169{
1170 /* const char *intf = get_param(cmd, "Interface"); */
1171 char bssid[20], resp[50];
1172
1173 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
1174 < 0)
1175 strncpy(bssid, "00:00:00:00:00:00", sizeof(bssid));
1176
1177 snprintf(resp, sizeof(resp), "bssid,%s", bssid);
1178 send_resp(dut, conn, SIGMA_COMPLETE, resp);
1179 return 0;
1180}
1181
1182
1183#ifdef __SAMSUNG__
1184static int add_use_network(const char *ifname)
1185{
1186 char buf[100];
1187
1188 snprintf(buf, sizeof(buf), "USE_NETWORK ON");
1189 wpa_command(ifname, buf);
1190 return 0;
1191}
1192#endif /* __SAMSUNG__ */
1193
1194
1195static int add_network_common(struct sigma_dut *dut, struct sigma_conn *conn,
1196 const char *ifname, struct sigma_cmd *cmd)
1197{
1198 const char *ssid = get_param(cmd, "ssid");
1199 int id;
1200 const char *val;
1201
1202 if (ssid == NULL)
1203 return -1;
1204
1205 start_sta_mode(dut);
1206
1207#ifdef __SAMSUNG__
1208 add_use_network(ifname);
1209#endif /* __SAMSUNG__ */
1210
1211 id = add_network(ifname);
1212 if (id < 0)
1213 return -2;
1214 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding network %d", id);
1215
1216 if (set_network_quoted(ifname, id, "ssid", ssid) < 0)
1217 return -2;
1218
1219 dut->infra_network_id = id;
1220 snprintf(dut->infra_ssid, sizeof(dut->infra_ssid), "%s", ssid);
1221
1222 val = get_param(cmd, "program");
1223 if (!val)
1224 val = get_param(cmd, "prog");
1225 if (val && strcasecmp(val, "hs2") == 0) {
1226 char buf[100];
1227 snprintf(buf, sizeof(buf), "ENABLE_NETWORK %d no-connect", id);
1228 wpa_command(ifname, buf);
1229
1230 val = get_param(cmd, "prefer");
1231 if (val && atoi(val) > 0)
1232 set_network(ifname, id, "priority", "1");
1233 }
1234
1235 return id;
1236}
1237
1238
1239static int cmd_sta_set_encryption(struct sigma_dut *dut,
1240 struct sigma_conn *conn,
1241 struct sigma_cmd *cmd)
1242{
1243 const char *intf = get_param(cmd, "Interface");
1244 const char *ssid = get_param(cmd, "ssid");
1245 const char *type = get_param(cmd, "encpType");
1246 const char *ifname;
1247 char buf[200];
1248 int id;
1249
1250 if (intf == NULL || ssid == NULL)
1251 return -1;
1252
1253 if (strcmp(intf, get_main_ifname()) == 0)
1254 ifname = get_station_ifname();
1255 else
1256 ifname = intf;
1257
1258 id = add_network_common(dut, conn, ifname, cmd);
1259 if (id < 0)
1260 return id;
1261
1262 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1263 return -2;
1264
1265 if (type && strcasecmp(type, "wep") == 0) {
1266 const char *val;
1267 int i;
1268
1269 val = get_param(cmd, "activeKey");
1270 if (val) {
1271 int keyid;
1272 keyid = atoi(val);
1273 if (keyid < 1 || keyid > 4)
1274 return -1;
1275 snprintf(buf, sizeof(buf), "%d", keyid - 1);
1276 if (set_network(ifname, id, "wep_tx_keyidx", buf) < 0)
1277 return -2;
1278 }
1279
1280 for (i = 0; i < 4; i++) {
1281 snprintf(buf, sizeof(buf), "key%d", i + 1);
1282 val = get_param(cmd, buf);
1283 if (val == NULL)
1284 continue;
1285 snprintf(buf, sizeof(buf), "wep_key%d", i);
1286 if (set_network(ifname, id, buf, val) < 0)
1287 return -2;
1288 }
1289 }
1290
1291 return 1;
1292}
1293
1294
1295static int set_wpa_common(struct sigma_dut *dut, struct sigma_conn *conn,
1296 const char *ifname, struct sigma_cmd *cmd)
1297{
1298 const char *val;
1299 int id;
1300
1301 id = add_network_common(dut, conn, ifname, cmd);
1302 if (id < 0)
1303 return id;
1304
1305 val = get_param(cmd, "keyMgmtType");
1306 if (val == NULL) {
1307 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1308 return 0;
1309 }
1310 if (strcasecmp(val, "wpa") == 0 ||
1311 strcasecmp(val, "wpa-psk") == 0) {
1312 if (set_network(ifname, id, "proto", "WPA") < 0)
1313 return -2;
1314 } else if (strcasecmp(val, "wpa2") == 0 ||
1315 strcasecmp(val, "wpa2-psk") == 0 ||
1316 strcasecmp(val, "wpa2-ft") == 0 ||
1317 strcasecmp(val, "wpa2-sha256") == 0) {
1318 if (set_network(ifname, id, "proto", "WPA2") < 0)
1319 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301320 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1321 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001322 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1323 return -2;
1324 } else {
1325 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1326 return 0;
1327 }
1328
1329 val = get_param(cmd, "encpType");
1330 if (val == NULL) {
1331 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing encpType");
1332 return 0;
1333 }
1334 if (strcasecmp(val, "tkip") == 0) {
1335 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1336 return -2;
1337 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1338 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1339 return -2;
1340 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1341 if (set_network(ifname, id, "pairwise", "CCMP TKIP") < 0)
1342 return -2;
1343 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1344 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1345 return -2;
1346 if (set_network(ifname, id, "group", "GCMP") < 0)
1347 return -2;
1348 } else {
1349 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized encpType value");
1350 return 0;
1351 }
1352
1353 dut->sta_pmf = STA_PMF_DISABLED;
1354 val = get_param(cmd, "PMF");
1355 if (val) {
1356 if (strcasecmp(val, "Required") == 0 ||
1357 strcasecmp(val, "Forced_Required") == 0) {
1358 dut->sta_pmf = STA_PMF_REQUIRED;
1359 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1360 return -2;
1361 } else if (strcasecmp(val, "Optional") == 0) {
1362 dut->sta_pmf = STA_PMF_OPTIONAL;
1363 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1364 return -2;
1365 } else if (strcasecmp(val, "Disabled") == 0 ||
1366 strcasecmp(val, "Forced_Disabled") == 0) {
1367 dut->sta_pmf = STA_PMF_DISABLED;
1368 } else {
1369 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1370 return 0;
1371 }
1372 }
1373
1374 return id;
1375}
1376
1377
1378static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1379 struct sigma_cmd *cmd)
1380{
1381 const char *intf = get_param(cmd, "Interface");
1382 const char *ifname, *val, *alg;
1383 int id;
1384
1385 if (intf == NULL)
1386 return -1;
1387
1388 if (strcmp(intf, get_main_ifname()) == 0)
1389 ifname = get_station_ifname();
1390 else
1391 ifname = intf;
1392
1393 id = set_wpa_common(dut, conn, ifname, cmd);
1394 if (id < 0)
1395 return id;
1396
1397 val = get_param(cmd, "keyMgmtType");
1398 alg = get_param(cmd, "micAlg");
1399
1400 if (alg && strcasecmp(alg, "SHA-256") == 0) {
1401 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1402 return -2;
1403 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1404 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1405 return -2;
1406 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1407 dut->sta_pmf == STA_PMF_REQUIRED) {
1408 if (set_network(ifname, id, "key_mgmt",
1409 "WPA-PSK WPA-PSK-SHA256") < 0)
1410 return -2;
1411 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1412 if (set_network(ifname, id, "key_mgmt",
1413 "WPA-PSK WPA-PSK-SHA256") < 0)
1414 return -2;
1415 } else {
1416 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1417 return -2;
1418 }
1419
1420 val = get_param(cmd, "passPhrase");
1421 if (val == NULL)
1422 return -1;
1423 if (set_network_quoted(ifname, id, "psk", val) < 0)
1424 return -2;
1425
1426 return 1;
1427}
1428
1429
1430static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301431 const char *ifname, int username_identity,
1432 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001433{
1434 const char *val, *alg;
1435 int id;
1436 char buf[200];
1437#ifdef ANDROID
1438 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1439 int length;
1440#endif /* ANDROID */
1441
1442 id = set_wpa_common(dut, conn, ifname, cmd);
1443 if (id < 0)
1444 return id;
1445
1446 val = get_param(cmd, "keyMgmtType");
1447 alg = get_param(cmd, "micAlg");
1448
1449 if (alg && strcasecmp(alg, "SHA-256") == 0) {
1450 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1451 return -2;
1452 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1453 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1454 return -2;
1455 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1456 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1457 return -2;
1458 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1459 dut->sta_pmf == STA_PMF_REQUIRED) {
1460 if (set_network(ifname, id, "key_mgmt",
1461 "WPA-EAP WPA-EAP-SHA256") < 0)
1462 return -2;
1463 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1464 if (set_network(ifname, id, "key_mgmt",
1465 "WPA-EAP WPA-EAP-SHA256") < 0)
1466 return -2;
1467 } else {
1468 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1469 return -2;
1470 }
1471
1472 val = get_param(cmd, "trustedRootCA");
1473 if (val) {
1474#ifdef ANDROID
1475 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1476 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1477 kvalue);
1478 if (length > 0) {
1479 sigma_dut_print(dut, DUT_MSG_INFO,
1480 "Use Android keystore [%s]", buf);
1481 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1482 val);
1483 goto ca_cert_selected;
1484 }
1485#endif /* ANDROID */
1486
1487 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1488#ifdef __linux__
1489 if (!file_exists(buf)) {
1490 char msg[300];
1491 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1492 "file (%s) not found", buf);
1493 send_resp(dut, conn, SIGMA_ERROR, msg);
1494 return -3;
1495 }
1496#endif /* __linux__ */
1497#ifdef ANDROID
1498ca_cert_selected:
1499#endif /* ANDROID */
1500 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1501 return -2;
1502 }
1503
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301504 if (username_identity) {
1505 val = get_param(cmd, "username");
1506 if (val) {
1507 if (set_network_quoted(ifname, id, "identity", val) < 0)
1508 return -2;
1509 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001510
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301511 val = get_param(cmd, "password");
1512 if (val) {
1513 if (set_network_quoted(ifname, id, "password", val) < 0)
1514 return -2;
1515 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001516 }
1517
1518 return id;
1519}
1520
1521
1522static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1523 struct sigma_cmd *cmd)
1524{
1525 const char *intf = get_param(cmd, "Interface");
1526 const char *ifname, *val;
1527 int id;
1528 char buf[200];
1529#ifdef ANDROID
1530 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1531 int length;
1532 int jb_or_newer = 0;
1533 char prop[PROPERTY_VALUE_MAX];
1534#endif /* ANDROID */
1535
1536 if (intf == NULL)
1537 return -1;
1538
1539 if (strcmp(intf, get_main_ifname()) == 0)
1540 ifname = get_station_ifname();
1541 else
1542 ifname = intf;
1543
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301544 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001545 if (id < 0)
1546 return id;
1547
1548 if (set_network(ifname, id, "eap", "TLS") < 0)
1549 return -2;
1550
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301551 if (!get_param(cmd, "username") &&
1552 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001553 "wifi-user@wifilabs.local") < 0)
1554 return -2;
1555
1556 val = get_param(cmd, "clientCertificate");
1557 if (val == NULL)
1558 return -1;
1559#ifdef ANDROID
1560 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1561 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1562 if (length < 0) {
1563 /*
1564 * JB started reporting keystore type mismatches, so retry with
1565 * the GET_PUBKEY command if the generic GET fails.
1566 */
1567 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1568 buf, kvalue);
1569 }
1570
1571 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1572 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1573 if (strncmp(prop, "4.0", 3) != 0)
1574 jb_or_newer = 1;
1575 } else
1576 jb_or_newer = 1; /* assume newer */
1577
1578 if (jb_or_newer && length > 0) {
1579 sigma_dut_print(dut, DUT_MSG_INFO,
1580 "Use Android keystore [%s]", buf);
1581 if (set_network(ifname, id, "engine", "1") < 0)
1582 return -2;
1583 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
1584 return -2;
1585 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1586 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
1587 return -2;
1588 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1589 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1590 return -2;
1591 return 1;
1592 } else if (length > 0) {
1593 sigma_dut_print(dut, DUT_MSG_INFO,
1594 "Use Android keystore [%s]", buf);
1595 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
1596 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1597 return -2;
1598 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1599 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1600 return -2;
1601 return 1;
1602 }
1603#endif /* ANDROID */
1604
1605 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1606#ifdef __linux__
1607 if (!file_exists(buf)) {
1608 char msg[300];
1609 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
1610 "(%s) not found", buf);
1611 send_resp(dut, conn, SIGMA_ERROR, msg);
1612 return -3;
1613 }
1614#endif /* __linux__ */
1615 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1616 return -2;
1617 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1618 return -2;
1619
1620 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
1621 return -2;
1622
1623 return 1;
1624}
1625
1626
1627static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
1628 struct sigma_cmd *cmd)
1629{
1630 const char *intf = get_param(cmd, "Interface");
1631 const char *ifname;
1632 int id;
1633
1634 if (intf == NULL)
1635 return -1;
1636
1637 if (strcmp(intf, get_main_ifname()) == 0)
1638 ifname = get_station_ifname();
1639 else
1640 ifname = intf;
1641
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301642 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001643 if (id < 0)
1644 return id;
1645
1646 if (set_network(ifname, id, "eap", "TTLS") < 0) {
1647 send_resp(dut, conn, SIGMA_ERROR,
1648 "errorCode,Failed to set TTLS method");
1649 return 0;
1650 }
1651
1652 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
1653 send_resp(dut, conn, SIGMA_ERROR,
1654 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
1655 return 0;
1656 }
1657
1658 return 1;
1659}
1660
1661
1662static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
1663 struct sigma_cmd *cmd)
1664{
1665 const char *intf = get_param(cmd, "Interface");
1666 const char *ifname;
1667 int id;
1668
1669 if (intf == NULL)
1670 return -1;
1671
1672 if (strcmp(intf, get_main_ifname()) == 0)
1673 ifname = get_station_ifname();
1674 else
1675 ifname = intf;
1676
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301677 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001678 if (id < 0)
1679 return id;
1680
1681 if (set_network(ifname, id, "eap", "SIM") < 0)
1682 return -2;
1683
1684 return 1;
1685}
1686
1687
1688static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
1689 struct sigma_cmd *cmd)
1690{
1691 const char *intf = get_param(cmd, "Interface");
1692 const char *ifname, *val;
1693 int id;
1694 char buf[100];
1695
1696 if (intf == NULL)
1697 return -1;
1698
1699 if (strcmp(intf, get_main_ifname()) == 0)
1700 ifname = get_station_ifname();
1701 else
1702 ifname = intf;
1703
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301704 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001705 if (id < 0)
1706 return id;
1707
1708 if (set_network(ifname, id, "eap", "PEAP") < 0)
1709 return -2;
1710
1711 val = get_param(cmd, "innerEAP");
1712 if (val) {
1713 if (strcasecmp(val, "MSCHAPv2") == 0) {
1714 if (set_network_quoted(ifname, id, "phase2",
1715 "auth=MSCHAPV2") < 0)
1716 return -2;
1717 } else if (strcasecmp(val, "GTC") == 0) {
1718 if (set_network_quoted(ifname, id, "phase2",
1719 "auth=GTC") < 0)
1720 return -2;
1721 } else
1722 return -1;
1723 }
1724
1725 val = get_param(cmd, "peapVersion");
1726 if (val) {
1727 int ver = atoi(val);
1728 if (ver < 0 || ver > 1)
1729 return -1;
1730 snprintf(buf, sizeof(buf), "peapver=%d", ver);
1731 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
1732 return -2;
1733 }
1734
1735 return 1;
1736}
1737
1738
1739static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
1740 struct sigma_cmd *cmd)
1741{
1742 const char *intf = get_param(cmd, "Interface");
1743 const char *ifname, *val;
1744 int id;
1745 char buf[100];
1746
1747 if (intf == NULL)
1748 return -1;
1749
1750 if (strcmp(intf, get_main_ifname()) == 0)
1751 ifname = get_station_ifname();
1752 else
1753 ifname = intf;
1754
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301755 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001756 if (id < 0)
1757 return id;
1758
1759 if (set_network(ifname, id, "eap", "FAST") < 0)
1760 return -2;
1761
1762 val = get_param(cmd, "innerEAP");
1763 if (val) {
1764 if (strcasecmp(val, "MSCHAPV2") == 0) {
1765 if (set_network_quoted(ifname, id, "phase2",
1766 "auth=MSCHAPV2") < 0)
1767 return -2;
1768 } else if (strcasecmp(val, "GTC") == 0) {
1769 if (set_network_quoted(ifname, id, "phase2",
1770 "auth=GTC") < 0)
1771 return -2;
1772 } else
1773 return -1;
1774 }
1775
1776 val = get_param(cmd, "validateServer");
1777 if (val) {
1778 /* TODO */
1779 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
1780 "validateServer=%s", val);
1781 }
1782
1783 val = get_param(cmd, "pacFile");
1784 if (val) {
1785 snprintf(buf, sizeof(buf), "blob://%s", val);
1786 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
1787 return -2;
1788 }
1789
1790 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
1791 0)
1792 return -2;
1793
1794 return 1;
1795}
1796
1797
1798static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
1799 struct sigma_cmd *cmd)
1800{
1801 const char *intf = get_param(cmd, "Interface");
1802 const char *ifname;
1803 int id;
1804
1805 if (intf == NULL)
1806 return -1;
1807
1808 if (strcmp(intf, get_main_ifname()) == 0)
1809 ifname = get_station_ifname();
1810 else
1811 ifname = intf;
1812
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301813 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001814 if (id < 0)
1815 return id;
1816
1817 if (set_network(ifname, id, "eap", "AKA") < 0)
1818 return -2;
1819
1820 return 1;
1821}
1822
1823
1824static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
1825 struct sigma_conn *conn,
1826 struct sigma_cmd *cmd)
1827{
1828 const char *intf = get_param(cmd, "Interface");
1829 const char *ifname;
1830 int id;
1831
1832 if (intf == NULL)
1833 return -1;
1834
1835 if (strcmp(intf, get_main_ifname()) == 0)
1836 ifname = get_station_ifname();
1837 else
1838 ifname = intf;
1839
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301840 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001841 if (id < 0)
1842 return id;
1843
1844 if (set_network(ifname, id, "eap", "AKA'") < 0)
1845 return -2;
1846
1847 return 1;
1848}
1849
1850
1851static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
1852 struct sigma_cmd *cmd)
1853{
1854 const char *intf = get_param(cmd, "Interface");
1855 const char *ifname;
1856 int id;
1857
1858 if (strcmp(intf, get_main_ifname()) == 0)
1859 ifname = get_station_ifname();
1860 else
1861 ifname = intf;
1862
1863 id = add_network_common(dut, conn, ifname, cmd);
1864 if (id < 0)
1865 return id;
1866
1867 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1868 return -2;
1869
1870 return 1;
1871}
1872
1873
1874static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
1875 struct sigma_cmd *cmd)
1876{
1877 const char *type = get_param(cmd, "Type");
1878
1879 if (type == NULL) {
1880 send_resp(dut, conn, SIGMA_ERROR,
1881 "ErrorCode,Missing Type argument");
1882 return 0;
1883 }
1884
1885 if (strcasecmp(type, "OPEN") == 0)
1886 return sta_set_open(dut, conn, cmd);
1887 if (strcasecmp(type, "PSK") == 0)
1888 return cmd_sta_set_psk(dut, conn, cmd);
1889 if (strcasecmp(type, "EAPTLS") == 0)
1890 return cmd_sta_set_eaptls(dut, conn, cmd);
1891 if (strcasecmp(type, "EAPTTLS") == 0)
1892 return cmd_sta_set_eapttls(dut, conn, cmd);
1893 if (strcasecmp(type, "EAPPEAP") == 0)
1894 return cmd_sta_set_peap(dut, conn, cmd);
1895 if (strcasecmp(type, "EAPSIM") == 0)
1896 return cmd_sta_set_eapsim(dut, conn, cmd);
1897 if (strcasecmp(type, "EAPFAST") == 0)
1898 return cmd_sta_set_eapfast(dut, conn, cmd);
1899 if (strcasecmp(type, "EAPAKA") == 0)
1900 return cmd_sta_set_eapaka(dut, conn, cmd);
1901 if (strcasecmp(type, "EAPAKAPRIME") == 0)
1902 return cmd_sta_set_eapakaprime(dut, conn, cmd);
1903
1904 send_resp(dut, conn, SIGMA_ERROR,
1905 "ErrorCode,Unsupported Type value");
1906 return 0;
1907}
1908
1909
1910int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
1911{
1912#ifdef __linux__
1913 /* special handling for ath6kl */
1914 char path[128], fname[128], *pos;
1915 ssize_t res;
1916 FILE *f;
1917
1918 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
1919 res = readlink(path, path, sizeof(path));
1920 if (res < 0)
1921 return 0; /* not ath6kl */
1922
1923 if (res >= (int) sizeof(path))
1924 res = sizeof(path) - 1;
1925 path[res] = '\0';
1926 pos = strrchr(path, '/');
1927 if (pos == NULL)
1928 pos = path;
1929 else
1930 pos++;
1931 snprintf(fname, sizeof(fname),
1932 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
1933 "create_qos", pos);
1934 if (!file_exists(fname))
1935 return 0; /* not ath6kl */
1936
1937 if (uapsd) {
1938 f = fopen(fname, "w");
1939 if (f == NULL)
1940 return -1;
1941
1942 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
1943 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
1944 "45000 200 56789000 56789000 5678900 0 0 9999999 "
1945 "20000 0\n");
1946 fclose(f);
1947 } else {
1948 snprintf(fname, sizeof(fname),
1949 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
1950 "delete_qos", pos);
1951
1952 f = fopen(fname, "w");
1953 if (f == NULL)
1954 return -1;
1955
1956 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
1957 fprintf(f, "2 4\n");
1958 fclose(f);
1959 }
1960#endif /* __linux__ */
1961
1962 return 0;
1963}
1964
1965
1966static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
1967 struct sigma_cmd *cmd)
1968{
1969 const char *intf = get_param(cmd, "Interface");
1970 /* const char *ssid = get_param(cmd, "ssid"); */
1971 const char *val;
1972 int max_sp_len = 4;
1973 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
1974 char buf[100];
1975 int ret1, ret2;
1976
1977 val = get_param(cmd, "maxSPLength");
1978 if (val) {
1979 max_sp_len = atoi(val);
1980 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
1981 max_sp_len != 4)
1982 return -1;
1983 }
1984
1985 val = get_param(cmd, "acBE");
1986 if (val)
1987 ac_be = atoi(val);
1988
1989 val = get_param(cmd, "acBK");
1990 if (val)
1991 ac_bk = atoi(val);
1992
1993 val = get_param(cmd, "acVI");
1994 if (val)
1995 ac_vi = atoi(val);
1996
1997 val = get_param(cmd, "acVO");
1998 if (val)
1999 ac_vo = atoi(val);
2000
2001 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2002
2003 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2004 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2005 ret1 = wpa_command(intf, buf);
2006
2007 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2008 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2009 ret2 = wpa_command(intf, buf);
2010
2011 if (ret1 && ret2) {
2012 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2013 "UAPSD parameters.");
2014 return -2;
2015 }
2016
2017 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2018 send_resp(dut, conn, SIGMA_ERROR,
2019 "ErrorCode,Failed to set ath6kl QoS parameters");
2020 return 0;
2021 }
2022
2023 return 1;
2024}
2025
2026
2027static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2028 struct sigma_cmd *cmd)
2029{
2030 char buf[1000];
2031 const char *intf = get_param(cmd, "Interface");
2032 const char *grp = get_param(cmd, "Group");
2033 const char *act = get_param(cmd, "Action");
2034 const char *tid = get_param(cmd, "Tid");
2035 const char *dir = get_param(cmd, "Direction");
2036 const char *psb = get_param(cmd, "Psb");
2037 const char *up = get_param(cmd, "Up");
2038 const char *fixed = get_param(cmd, "Fixed");
2039 const char *size = get_param(cmd, "Size");
2040 const char *msize = get_param(cmd, "Maxsize");
2041 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2042 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2043 const char *inact = get_param(cmd, "Inactivity");
2044 const char *sus = get_param(cmd, "Suspension");
2045 const char *mindr = get_param(cmd, "Mindatarate");
2046 const char *meandr = get_param(cmd, "Meandatarate");
2047 const char *peakdr = get_param(cmd, "Peakdatarate");
2048 const char *phyrate = get_param(cmd, "Phyrate");
2049 const char *burstsize = get_param(cmd, "Burstsize");
2050 const char *sba = get_param(cmd, "Sba");
2051 int direction;
2052 int handle;
2053 float sba_fv;
2054 int fixed_int;
2055 int psb_ts;
2056
2057 if (intf == NULL || grp == NULL || act == NULL )
2058 return -1;
2059
2060 if (strcasecmp(act, "addts") == 0) {
2061 if (tid == NULL || dir == NULL || psb == NULL ||
2062 up == NULL || fixed == NULL || size == NULL)
2063 return -1;
2064
2065 /*
2066 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2067 * possible values, but WMM-AC and V-E test scripts use "UP,
2068 * "DOWN", and "BIDI".
2069 */
2070 if (strcasecmp(dir, "uplink") == 0 ||
2071 strcasecmp(dir, "up") == 0) {
2072 direction = 0;
2073 } else if (strcasecmp(dir, "downlink") == 0 ||
2074 strcasecmp(dir, "down") == 0) {
2075 direction = 1;
2076 } else if (strcasecmp(dir, "bidi") == 0) {
2077 direction = 2;
2078 } else {
2079 sigma_dut_print(dut, DUT_MSG_ERROR,
2080 "Direction %s not supported", dir);
2081 return -1;
2082 }
2083
2084 if (strcasecmp(psb, "legacy") == 0) {
2085 psb_ts = 0;
2086 } else if (strcasecmp(psb, "uapsd") == 0) {
2087 psb_ts = 1;
2088 } else {
2089 sigma_dut_print(dut, DUT_MSG_ERROR,
2090 "PSB %s not supported", psb);
2091 return -1;
2092 }
2093
2094 if (atoi(tid) < 0 || atoi(tid) > 7) {
2095 sigma_dut_print(dut, DUT_MSG_ERROR,
2096 "TID %s not supported", tid);
2097 return -1;
2098 }
2099
2100 if (strcasecmp(fixed, "true") == 0) {
2101 fixed_int = 1;
2102 } else {
2103 fixed_int = 0;
2104 }
2105
2106 sba_fv = atof(sba);
2107
2108 dut->dialog_token++;
2109 handle = 7000 + dut->dialog_token;
2110
2111 /*
2112 * size: convert to hex
2113 * maxsi: convert to hex
2114 * mindr: convert to hex
2115 * meandr: convert to hex
2116 * peakdr: convert to hex
2117 * burstsize: convert to hex
2118 * phyrate: convert to hex
2119 * sba: convert to hex with modification
2120 * minsi: convert to integer
2121 * sus: convert to integer
2122 * inact: convert to integer
2123 * maxsi: convert to integer
2124 */
2125
2126 /*
2127 * The Nominal MSDU Size field is 2 octets long and contains an
2128 * unsigned integer that specifies the nominal size, in octets,
2129 * of MSDUs belonging to the traffic under this traffic
2130 * specification and is defined in Figure 16. If the Fixed
2131 * subfield is set to 1, then the size of the MSDU is fixed and
2132 * is indicated by the Size Subfield. If the Fixed subfield is
2133 * set to 0, then the size of the MSDU might not be fixed and
2134 * the Size indicates the nominal MSDU size.
2135 *
2136 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2137 * and specifies the excess allocation of time (and bandwidth)
2138 * over and above the stated rates required to transport an MSDU
2139 * belonging to the traffic in this TSPEC. This field is
2140 * represented as an unsigned binary number with an implicit
2141 * binary point after the leftmost 3 bits. For example, an SBA
2142 * of 1.75 is represented as 0x3800. This field is included to
2143 * account for retransmissions. As such, the value of this field
2144 * must be greater than unity.
2145 */
2146
2147 snprintf(buf, sizeof(buf),
2148 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2149 " 0x%X 0x%X 0x%X"
2150 " 0x%X 0x%X 0x%X"
2151 " 0x%X %d %d %d %d"
2152 " %d %d",
2153 intf, handle, tid, direction, psb_ts, up,
2154 (unsigned int) ((fixed_int << 15) | atoi(size)),
2155 msize ? atoi(msize) : 0,
2156 mindr ? atoi(mindr) : 0,
2157 meandr ? atoi(meandr) : 0,
2158 peakdr ? atoi(peakdr) : 0,
2159 burstsize ? atoi(burstsize) : 0,
2160 phyrate ? atoi(phyrate) : 0,
2161 sba ? ((unsigned int) (((int) sba_fv << 13) |
2162 (int)((sba_fv - (int) sba_fv) *
2163 8192))) : 0,
2164 minsi ? atoi(minsi) : 0,
2165 sus ? atoi(sus) : 0,
2166 0, 0,
2167 inact ? atoi(inact) : 0,
2168 maxsi ? atoi(maxsi) : 0);
2169
2170 if (system(buf) != 0) {
2171 sigma_dut_print(dut, DUT_MSG_ERROR,
2172 "iwpriv addtspec request failed");
2173 send_resp(dut, conn, SIGMA_ERROR,
2174 "errorCode,Failed to execute addTspec command");
2175 return 0;
2176 }
2177
2178 sigma_dut_print(dut, DUT_MSG_INFO,
2179 "iwpriv addtspec request send");
2180
2181 /* Mapping handle to a TID */
2182 dut->tid_to_handle[atoi(tid)] = handle;
2183 } else if (strcasecmp(act, "delts") == 0) {
2184 if (tid == NULL)
2185 return -1;
2186
2187 if (atoi(tid) < 0 || atoi(tid) > 7) {
2188 sigma_dut_print(dut, DUT_MSG_ERROR,
2189 "TID %s not supported", tid);
2190 send_resp(dut, conn, SIGMA_ERROR,
2191 "errorCode,Unsupported TID");
2192 return 0;
2193 }
2194
2195 handle = dut->tid_to_handle[atoi(tid)];
2196
2197 if (handle < 7000 || handle > 7255) {
2198 /* Invalid handle ie no mapping for that TID */
2199 sigma_dut_print(dut, DUT_MSG_ERROR,
2200 "handle-> %d not found", handle);
2201 }
2202
2203 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2204 intf, handle);
2205
2206 if (system(buf) != 0) {
2207 sigma_dut_print(dut, DUT_MSG_ERROR,
2208 "iwpriv deltspec request failed");
2209 send_resp(dut, conn, SIGMA_ERROR,
2210 "errorCode,Failed to execute delTspec command");
2211 return 0;
2212 }
2213
2214 sigma_dut_print(dut, DUT_MSG_INFO,
2215 "iwpriv deltspec request send");
2216
2217 dut->tid_to_handle[atoi(tid)] = 0;
2218 } else {
2219 sigma_dut_print(dut, DUT_MSG_ERROR,
2220 "Action type %s not supported", act);
2221 send_resp(dut, conn, SIGMA_ERROR,
2222 "errorCode,Unsupported Action");
2223 return 0;
2224 }
2225
2226 return 1;
2227}
2228
2229
2230static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2231 struct sigma_cmd *cmd)
2232{
2233 /* const char *intf = get_param(cmd, "Interface"); */
2234 const char *ssid = get_param(cmd, "ssid");
2235 const char *wps_param = get_param(cmd, "WPS");
2236 const char *bssid = get_param(cmd, "bssid");
2237 int wps = 0;
2238 char buf[100];
2239
2240 if (ssid == NULL)
2241 return -1;
2242
2243 if (wps_param &&
2244 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2245 wps = 1;
2246
2247 if (wps) {
2248 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2249 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2250 "parameters not yet set");
2251 return 0;
2252 }
2253 if (dut->wps_method == WFA_CS_WPS_PBC) {
2254 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2255 return -2;
2256 } else {
2257 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2258 dut->wps_pin);
2259 if (wpa_command(get_station_ifname(), buf) < 0)
2260 return -2;
2261 }
2262 } else {
2263 if (strcmp(ssid, dut->infra_ssid) != 0) {
2264 printf("No network parameters known for network "
2265 "(ssid='%s')", ssid);
2266 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2267 "No network parameters known for network");
2268 return 0;
2269 }
2270
2271 if (bssid &&
2272 set_network(get_station_ifname(), dut->infra_network_id,
2273 "bssid", bssid) < 0) {
2274 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2275 "Invalid bssid argument");
2276 return 0;
2277 }
2278
2279 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d",
2280 dut->infra_network_id);
2281 if (wpa_command(get_station_ifname(), buf) < 0) {
2282 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2283 "network id %d on %s",
2284 dut->infra_network_id,
2285 get_station_ifname());
2286 return -2;
2287 }
2288 }
2289
2290 return 1;
2291}
2292
2293
2294static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2295{
2296 char buf[500], cmd[200];
2297 int res;
2298
2299 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2300 * default path */
2301 res = snprintf(cmd, sizeof(cmd),
2302 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2303 file_exists("./hs20-osu-client") ?
2304 "./hs20-osu-client" : "hs20-osu-client",
2305 sigma_wpas_ctrl,
2306 dut->summary_log ? "-s " : "",
2307 dut->summary_log ? dut->summary_log : "");
2308 if (res < 0 || res >= (int) sizeof(cmd))
2309 return -1;
2310
2311 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2312 if (res < 0 || res >= (int) sizeof(buf))
2313 return -1;
2314 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2315
2316 if (system(buf) != 0) {
2317 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2318 return -1;
2319 }
2320 sigma_dut_print(dut, DUT_MSG_DEBUG,
2321 "Completed hs20-osu-client operation");
2322
2323 return 0;
2324}
2325
2326
2327static int download_ppsmo(struct sigma_dut *dut,
2328 struct sigma_conn *conn,
2329 const char *intf,
2330 struct sigma_cmd *cmd)
2331{
2332 const char *name, *path, *val;
2333 char url[500], buf[600], fbuf[100];
2334 char *fqdn = NULL;
2335
2336 name = get_param(cmd, "FileName");
2337 path = get_param(cmd, "FilePath");
2338 if (name == NULL || path == NULL)
2339 return -1;
2340
2341 if (strcasecmp(path, "VendorSpecific") == 0) {
2342 snprintf(url, sizeof(url), "PPS/%s", name);
2343 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2344 "from the device (%s)", url);
2345 if (!file_exists(url)) {
2346 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2347 "PPS MO file does not exist");
2348 return 0;
2349 }
2350 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2351 if (system(buf) != 0) {
2352 send_resp(dut, conn, SIGMA_ERROR,
2353 "errorCode,Failed to copy PPS MO");
2354 return 0;
2355 }
2356 } else if (strncasecmp(path, "http:", 5) != 0 &&
2357 strncasecmp(path, "https:", 6) != 0) {
2358 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2359 "Unsupported FilePath value");
2360 return 0;
2361 } else {
2362 snprintf(url, sizeof(url), "%s/%s", path, name);
2363 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2364 url);
2365 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2366 remove("pps-tnds.xml");
2367 if (system(buf) != 0) {
2368 send_resp(dut, conn, SIGMA_ERROR,
2369 "errorCode,Failed to download PPS MO");
2370 return 0;
2371 }
2372 }
2373
2374 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2375 send_resp(dut, conn, SIGMA_ERROR,
2376 "errorCode,Failed to parse downloaded PPSMO");
2377 return 0;
2378 }
2379 unlink("pps-tnds.xml");
2380
2381 val = get_param(cmd, "managementTreeURI");
2382 if (val) {
2383 const char *pos, *end;
2384 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2385 val);
2386 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2387 send_resp(dut, conn, SIGMA_ERROR,
2388 "errorCode,Invalid managementTreeURI prefix");
2389 return 0;
2390 }
2391 pos = val + 8;
2392 end = strchr(pos, '/');
2393 if (end == NULL ||
2394 strcmp(end, "/PerProviderSubscription") != 0) {
2395 send_resp(dut, conn, SIGMA_ERROR,
2396 "errorCode,Invalid managementTreeURI postfix");
2397 return 0;
2398 }
2399 if (end - pos >= (int) sizeof(fbuf)) {
2400 send_resp(dut, conn, SIGMA_ERROR,
2401 "errorCode,Too long FQDN in managementTreeURI");
2402 return 0;
2403 }
2404 memcpy(fbuf, pos, end - pos);
2405 fbuf[end - pos] = '\0';
2406 fqdn = fbuf;
2407 sigma_dut_print(dut, DUT_MSG_INFO,
2408 "FQDN from managementTreeURI: %s", fqdn);
2409 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
2410 FILE *f = fopen("pps-fqdn", "r");
2411 if (f) {
2412 if (fgets(fbuf, sizeof(fbuf), f)) {
2413 fbuf[sizeof(fbuf) - 1] = '\0';
2414 fqdn = fbuf;
2415 sigma_dut_print(dut, DUT_MSG_DEBUG,
2416 "Use FQDN %s", fqdn);
2417 }
2418 fclose(f);
2419 }
2420 }
2421
2422 if (fqdn == NULL) {
2423 send_resp(dut, conn, SIGMA_ERROR,
2424 "errorCode,No FQDN specified");
2425 return 0;
2426 }
2427
2428 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2429 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
2430 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2431
2432 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
2433 if (rename("pps.xml", buf) < 0) {
2434 send_resp(dut, conn, SIGMA_ERROR,
2435 "errorCode,Could not move PPS MO");
2436 return 0;
2437 }
2438
2439 if (strcasecmp(path, "VendorSpecific") == 0) {
2440 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
2441 fqdn);
2442 if (system(buf)) {
2443 send_resp(dut, conn, SIGMA_ERROR,
2444 "errorCode,Failed to copy OSU CA cert");
2445 return 0;
2446 }
2447
2448 snprintf(buf, sizeof(buf),
2449 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
2450 fqdn);
2451 if (system(buf)) {
2452 send_resp(dut, conn, SIGMA_ERROR,
2453 "errorCode,Failed to copy AAA CA cert");
2454 return 0;
2455 }
2456 } else {
2457 snprintf(buf, sizeof(buf),
2458 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
2459 fqdn, fqdn);
2460 if (run_hs20_osu(dut, buf) < 0) {
2461 send_resp(dut, conn, SIGMA_ERROR,
2462 "errorCode,Failed to download OSU CA cert");
2463 return 0;
2464 }
2465
2466 snprintf(buf, sizeof(buf),
2467 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
2468 fqdn, fqdn);
2469 if (run_hs20_osu(dut, buf) < 0) {
2470 sigma_dut_print(dut, DUT_MSG_INFO,
2471 "Failed to download AAA CA cert");
2472 }
2473 }
2474
2475 if (file_exists("next-client-cert.pem")) {
2476 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
2477 if (rename("next-client-cert.pem", buf) < 0) {
2478 send_resp(dut, conn, SIGMA_ERROR,
2479 "errorCode,Could not move client certificate");
2480 return 0;
2481 }
2482 }
2483
2484 if (file_exists("next-client-key.pem")) {
2485 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
2486 if (rename("next-client-key.pem", buf) < 0) {
2487 send_resp(dut, conn, SIGMA_ERROR,
2488 "errorCode,Could not move client key");
2489 return 0;
2490 }
2491 }
2492
2493 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
2494 if (run_hs20_osu(dut, buf) < 0) {
2495 send_resp(dut, conn, SIGMA_ERROR,
2496 "errorCode,Failed to configure credential from "
2497 "PPSMO");
2498 return 0;
2499 }
2500
2501 return 1;
2502}
2503
2504
2505static int download_cert(struct sigma_dut *dut,
2506 struct sigma_conn *conn,
2507 const char *intf,
2508 struct sigma_cmd *cmd)
2509{
2510 const char *name, *path;
2511 char url[500], buf[600];
2512
2513 name = get_param(cmd, "FileName");
2514 path = get_param(cmd, "FilePath");
2515 if (name == NULL || path == NULL)
2516 return -1;
2517
2518 if (strcasecmp(path, "VendorSpecific") == 0) {
2519 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
2520 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2521 "certificate from the device (%s)", url);
2522 if (!file_exists(url)) {
2523 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2524 "certificate file does not exist");
2525 return 0;
2526 }
2527 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
2528 if (system(buf) != 0) {
2529 send_resp(dut, conn, SIGMA_ERROR,
2530 "errorCode,Failed to copy client "
2531 "certificate");
2532 return 0;
2533 }
2534
2535 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
2536 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2537 "private key from the device (%s)", url);
2538 if (!file_exists(url)) {
2539 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2540 "private key file does not exist");
2541 return 0;
2542 }
2543 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
2544 if (system(buf) != 0) {
2545 send_resp(dut, conn, SIGMA_ERROR,
2546 "errorCode,Failed to copy client key");
2547 return 0;
2548 }
2549 } else if (strncasecmp(path, "http:", 5) != 0 &&
2550 strncasecmp(path, "https:", 6) != 0) {
2551 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2552 "Unsupported FilePath value");
2553 return 0;
2554 } else {
2555 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
2556 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
2557 "certificate/key from %s", url);
2558 snprintf(buf, sizeof(buf),
2559 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
2560 if (system(buf) != 0) {
2561 send_resp(dut, conn, SIGMA_ERROR,
2562 "errorCode,Failed to download client "
2563 "certificate");
2564 return 0;
2565 }
2566
2567 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
2568 {
2569 send_resp(dut, conn, SIGMA_ERROR,
2570 "errorCode,Failed to copy client key");
2571 return 0;
2572 }
2573 }
2574
2575 return 1;
2576}
2577
2578
2579static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
2580 struct sigma_conn *conn,
2581 const char *intf,
2582 struct sigma_cmd *cmd)
2583{
2584 const char *val;
2585
2586 val = get_param(cmd, "FileType");
2587 if (val && strcasecmp(val, "PPSMO") == 0)
2588 return download_ppsmo(dut, conn, intf, cmd);
2589 if (val && strcasecmp(val, "CERT") == 0)
2590 return download_cert(dut, conn, intf, cmd);
2591 if (val) {
2592 send_resp(dut, conn, SIGMA_ERROR,
2593 "ErrorCode,Unsupported FileType");
2594 return 0;
2595 }
2596
2597 return 1;
2598}
2599
2600
2601static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
2602 const char *val)
2603{
2604 int counter = 0;
2605 char token[50];
2606 char *result;
2607 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302608 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002609
2610 strncpy(token, val, sizeof(token));
2611 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302612 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002613 while (result) {
2614 if (strcmp(result, "disable") == 0) {
2615 snprintf(buf, sizeof(buf),
2616 "iwpriv %s noackpolicy %d 1 0",
2617 intf, counter);
2618 } else {
2619 snprintf(buf, sizeof(buf),
2620 "iwpriv %s noackpolicy %d 1 1",
2621 intf, counter);
2622 }
2623 if (system(buf) != 0) {
2624 sigma_dut_print(dut, DUT_MSG_ERROR,
2625 "iwpriv noackpolicy failed");
2626 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302627 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002628 counter++;
2629 }
2630}
2631
2632
2633static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
2634 const char *val)
2635{
2636 char buf[100];
2637
2638 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
2639 if (system(buf) != 0) {
2640 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
2641 }
2642}
2643
2644
2645static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
2646 const char *val)
2647{
2648 char buf[100];
2649
2650 if (strcasecmp(val, "off") == 0) {
2651 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
2652 if (system(buf) != 0) {
2653 sigma_dut_print(dut, DUT_MSG_ERROR,
2654 "Failed to turn off WMM");
2655 }
2656 }
2657}
2658
2659
2660static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
2661 const char *val)
2662{
2663 char buf[100];
2664 int sgi20;
2665
2666 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
2667
2668 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
2669 if (system(buf) != 0)
2670 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
2671}
2672
2673
2674static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
2675 const char *val)
2676{
2677 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05302678 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002679
2680 /* Disable Tx Beam forming when using a fixed rate */
2681 ath_disable_txbf(dut, intf);
2682
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05302683 v = atoi(val);
2684 if (v < 0 || v > 32) {
2685 sigma_dut_print(dut, DUT_MSG_ERROR,
2686 "Invalid Fixed MCS rate: %d", v);
2687 return;
2688 }
2689 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002690
2691 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
2692 intf, rate_code);
2693 if (system(buf) != 0) {
2694 sigma_dut_print(dut, DUT_MSG_ERROR,
2695 "iwpriv set11NRates failed");
2696 }
2697
2698 /* Channel width gets messed up, fix this */
2699 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
2700 if (system(buf) != 0)
2701 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
2702}
2703
2704
2705static void ath_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
2706 const char *val)
2707{
2708 char buf[60];
2709
2710 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
2711 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
2712 else
2713 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
2714
2715 if (system(buf) != 0)
2716 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
2717}
2718
2719
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07002720static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
2721 int ampdu)
2722{
2723 char buf[60];
2724
2725 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
2726 if (system(buf) != 0) {
2727 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
2728 return -1;
2729 }
2730
2731 return 0;
2732}
2733
2734
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002735static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
2736 const char *val)
2737{
2738 char buf[60];
2739
2740 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
2741 if (system(buf) != 0) {
2742 sigma_dut_print(dut, DUT_MSG_ERROR,
2743 "iwpriv tx_stbc failed");
2744 }
2745
2746 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
2747 if (system(buf) != 0) {
2748 sigma_dut_print(dut, DUT_MSG_ERROR,
2749 "iwpriv rx_stbc failed");
2750 }
2751}
2752
2753
2754static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
2755 const char *val)
2756{
2757 char buf[60];
2758
2759 if (strcmp(val, "80") == 0) {
2760 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
2761 } else if (strcmp(val, "40") == 0) {
2762 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
2763 } else if (strcmp(val, "20") == 0) {
2764 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
2765 } else if (strcasecmp(val, "Auto") == 0) {
2766 buf[0] = '\0';
2767 } else {
2768 sigma_dut_print(dut, DUT_MSG_ERROR,
2769 "WIDTH/CTS_WIDTH value not supported");
2770 return -1;
2771 }
2772
2773 if (buf[0] != '\0' && system(buf) != 0) {
2774 sigma_dut_print(dut, DUT_MSG_ERROR,
2775 "Failed to set WIDTH/CTS_WIDTH");
2776 return -1;
2777 }
2778
2779 return 0;
2780}
2781
2782
2783int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
2784 const char *intf, const char *val)
2785{
2786 char buf[60];
2787
2788 if (strcasecmp(val, "Auto") == 0) {
2789 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
2790 dut->chwidth = 0;
2791 } else if (strcasecmp(val, "20") == 0) {
2792 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
2793 dut->chwidth = 0;
2794 } else if (strcasecmp(val, "40") == 0) {
2795 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
2796 dut->chwidth = 1;
2797 } else if (strcasecmp(val, "80") == 0) {
2798 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
2799 dut->chwidth = 2;
2800 } else if (strcasecmp(val, "160") == 0) {
2801 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
2802 dut->chwidth = 3;
2803 } else {
2804 send_resp(dut, conn, SIGMA_ERROR,
2805 "ErrorCode,WIDTH not supported");
2806 return -1;
2807 }
2808
2809 if (system(buf) != 0) {
2810 sigma_dut_print(dut, DUT_MSG_ERROR,
2811 "iwpriv chwidth failed");
2812 }
2813
2814 return 0;
2815}
2816
2817
2818static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
2819 const char *val)
2820{
2821 char buf[60];
2822
2823 if (strcmp(val, "1SS") == 0) {
2824 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
2825 } else if (strcmp(val, "2SS") == 0) {
2826 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
2827 } else {
2828 sigma_dut_print(dut, DUT_MSG_ERROR,
2829 "SP_STREAM value not supported");
2830 return -1;
2831 }
2832
2833 if (system(buf) != 0) {
2834 sigma_dut_print(dut, DUT_MSG_ERROR,
2835 "Failed to set SP_STREAM");
2836 return -1;
2837 }
2838
2839 return 0;
2840}
2841
2842
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05302843static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
2844 const char *val)
2845{
2846 char buf[60];
2847
2848 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
2849 if (system(buf) != 0)
2850 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
2851
2852 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
2853 if (system(buf) != 0)
2854 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
2855}
2856
2857
Ashwini Patil68d02cd2017-01-10 15:39:16 +05302858static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
2859 struct sigma_conn *conn,
2860 const char *intf, int capa)
2861{
2862 char buf[32];
2863
2864 if (capa > 0 && capa < 4) {
2865 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
2866 if (wpa_command(intf, buf) < 0) {
2867 send_resp(dut, conn, SIGMA_ERROR,
2868 "ErrorCode, Failed to set cellular data capability");
2869 return 0;
2870 }
2871 return 1;
2872 }
2873
2874 sigma_dut_print(dut, DUT_MSG_ERROR,
2875 "Invalid Cellular data capability: %d", capa);
2876 send_resp(dut, conn, SIGMA_INVALID,
2877 "ErrorCode,Invalid cellular data capability");
2878 return 0;
2879}
2880
2881
Ashwini Patil00402582017-04-13 12:29:39 +05302882static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
2883 struct sigma_conn *conn,
2884 const char *intf,
2885 struct sigma_cmd *cmd)
2886{
2887 const char *ch, *pref, *op_class, *reason;
2888 char buf[120];
2889 int len, ret;
2890
2891 pref = get_param(cmd, "Ch_Pref");
2892 if (!pref)
2893 return 1;
2894
2895 if (strcasecmp(pref, "clear") == 0) {
2896 free(dut->non_pref_ch_list);
2897 dut->non_pref_ch_list = NULL;
2898 } else {
2899 op_class = get_param(cmd, "Ch_Op_Class");
2900 if (!op_class) {
2901 send_resp(dut, conn, SIGMA_INVALID,
2902 "ErrorCode,Ch_Op_Class not provided");
2903 return 0;
2904 }
2905
2906 ch = get_param(cmd, "Ch_Pref_Num");
2907 if (!ch) {
2908 send_resp(dut, conn, SIGMA_INVALID,
2909 "ErrorCode,Ch_Pref_Num not provided");
2910 return 0;
2911 }
2912
2913 reason = get_param(cmd, "Ch_Reason_Code");
2914 if (!reason) {
2915 send_resp(dut, conn, SIGMA_INVALID,
2916 "ErrorCode,Ch_Reason_Code not provided");
2917 return 0;
2918 }
2919
2920 if (!dut->non_pref_ch_list) {
2921 dut->non_pref_ch_list =
2922 calloc(1, NON_PREF_CH_LIST_SIZE);
2923 if (!dut->non_pref_ch_list) {
2924 send_resp(dut, conn, SIGMA_ERROR,
2925 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
2926 return 0;
2927 }
2928 }
2929 len = strlen(dut->non_pref_ch_list);
2930 ret = snprintf(dut->non_pref_ch_list + len,
2931 NON_PREF_CH_LIST_SIZE - len,
2932 " %s:%s:%s:%s", op_class, ch, pref, reason);
2933 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
2934 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
2935 dut->non_pref_ch_list);
2936 } else {
2937 sigma_dut_print(dut, DUT_MSG_ERROR,
2938 "snprintf failed for non_pref_list, ret = %d",
2939 ret);
2940 send_resp(dut, conn, SIGMA_ERROR,
2941 "ErrorCode,snprintf failed");
2942 free(dut->non_pref_ch_list);
2943 dut->non_pref_ch_list = NULL;
2944 return 0;
2945 }
2946 }
2947
2948 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
2949 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
2950 if (ret < 0 || ret >= (int) sizeof(buf)) {
2951 sigma_dut_print(dut, DUT_MSG_DEBUG,
2952 "snprintf failed for set non_pref_chan, ret: %d",
2953 ret);
2954 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
2955 return 0;
2956 }
2957
2958 if (wpa_command(intf, buf) < 0) {
2959 send_resp(dut, conn, SIGMA_ERROR,
2960 "ErrorCode,Failed to set non-preferred channel list");
2961 return 0;
2962 }
2963
2964 return 1;
2965}
2966
2967
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002968static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
2969 struct sigma_conn *conn,
2970 struct sigma_cmd *cmd)
2971{
2972 const char *intf = get_param(cmd, "Interface");
2973 const char *val;
2974
2975 val = get_param(cmd, "Program");
2976 if (val && strcasecmp(val, "HS2-R2") == 0) {
2977 if (intf == NULL)
2978 return -1;
2979 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
2980 cmd);
2981 }
2982
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07002983 if (val && strcasecmp(val, "LOC") == 0)
2984 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
2985
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002986#ifdef ANDROID_NAN
2987 if (val && strcasecmp(val, "NAN") == 0)
2988 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
2989#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07002990#ifdef MIRACAST
2991 if (val && (strcasecmp(val, "WFD") == 0 ||
2992 strcasecmp(val, "DisplayR2") == 0))
2993 return miracast_preset_testparameters(dut, conn, cmd);
2994#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002995
Ashwini Patil68d02cd2017-01-10 15:39:16 +05302996 if (val && strcasecmp(val, "MBO") == 0) {
2997 val = get_param(cmd, "Cellular_Data_Cap");
2998 if (val &&
2999 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3000 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303001
3002 val = get_param(cmd, "Ch_Pref");
3003 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3004 return 0;
3005
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303006 return 1;
3007 }
3008
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003009#if 0
3010 val = get_param(cmd, "Supplicant");
3011 if (val && strcasecmp(val, "Default") != 0) {
3012 send_resp(dut, conn, SIGMA_ERROR,
3013 "ErrorCode,Only default(Vendor) supplicant "
3014 "supported");
3015 return 0;
3016 }
3017#endif
3018
3019 val = get_param(cmd, "RTS");
3020 if (val) {
3021 switch (get_driver_type()) {
3022 case DRIVER_ATHEROS:
3023 ath_sta_set_rts(dut, intf, val);
3024 break;
3025 default:
3026#if 0
3027 send_resp(dut, conn, SIGMA_ERROR,
3028 "ErrorCode,Setting RTS not supported");
3029 return 0;
3030#else
3031 sigma_dut_print(dut, DUT_MSG_DEBUG,
3032 "Setting RTS not supported");
3033 break;
3034#endif
3035 }
3036 }
3037
3038#if 0
3039 val = get_param(cmd, "FRGMNT");
3040 if (val) {
3041 /* TODO */
3042 send_resp(dut, conn, SIGMA_ERROR,
3043 "ErrorCode,Setting FRGMNT not supported");
3044 return 0;
3045 }
3046#endif
3047
3048#if 0
3049 val = get_param(cmd, "Preamble");
3050 if (val) {
3051 /* TODO: Long/Short */
3052 send_resp(dut, conn, SIGMA_ERROR,
3053 "ErrorCode,Setting Preamble not supported");
3054 return 0;
3055 }
3056#endif
3057
3058 val = get_param(cmd, "Mode");
3059 if (val) {
3060 if (strcmp(val, "11b") == 0 ||
3061 strcmp(val, "11g") == 0 ||
3062 strcmp(val, "11a") == 0 ||
3063 strcmp(val, "11n") == 0 ||
3064 strcmp(val, "11ng") == 0 ||
3065 strcmp(val, "11nl") == 0 ||
3066 strcmp(val, "11nl(nabg)") == 0 ||
3067 strcmp(val, "AC") == 0 ||
3068 strcmp(val, "11AC") == 0 ||
3069 strcmp(val, "11ac") == 0 ||
3070 strcmp(val, "11na") == 0 ||
3071 strcmp(val, "11an") == 0) {
3072 /* STA supports all modes by default */
3073 } else {
3074 send_resp(dut, conn, SIGMA_ERROR,
3075 "ErrorCode,Setting Mode not supported");
3076 return 0;
3077 }
3078 }
3079
3080 val = get_param(cmd, "wmm");
3081 if (val) {
3082 switch (get_driver_type()) {
3083 case DRIVER_ATHEROS:
3084 ath_sta_set_wmm(dut, intf, val);
3085 break;
3086 default:
3087 sigma_dut_print(dut, DUT_MSG_DEBUG,
3088 "Setting wmm not supported");
3089 break;
3090 }
3091 }
3092
3093 val = get_param(cmd, "Powersave");
3094 if (val) {
3095 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3096 if (wpa_command(get_station_ifname(),
3097 "P2P_SET ps 0") < 0)
3098 return -2;
3099 /* Make sure test modes are disabled */
3100 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3101 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3102 } else if (strcmp(val, "1") == 0 ||
3103 strcasecmp(val, "PSPoll") == 0 ||
3104 strcasecmp(val, "on") == 0) {
3105 /* Disable default power save mode */
3106 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3107 /* Enable PS-Poll test mode */
3108 if (wpa_command(get_station_ifname(),
3109 "P2P_SET ps 97") < 0 ||
3110 wpa_command(get_station_ifname(),
3111 "P2P_SET ps 99") < 0)
3112 return -2;
3113 } else if (strcmp(val, "2") == 0 ||
3114 strcasecmp(val, "Fast") == 0) {
3115 /* TODO */
3116 send_resp(dut, conn, SIGMA_ERROR,
3117 "ErrorCode,Powersave=Fast not supported");
3118 return 0;
3119 } else if (strcmp(val, "3") == 0 ||
3120 strcasecmp(val, "PSNonPoll") == 0) {
3121 /* Make sure test modes are disabled */
3122 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3123 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3124
3125 /* Enable default power save mode */
3126 if (wpa_command(get_station_ifname(),
3127 "P2P_SET ps 1") < 0)
3128 return -2;
3129 } else
3130 return -1;
3131 }
3132
3133 val = get_param(cmd, "NoAck");
3134 if (val) {
3135 switch (get_driver_type()) {
3136 case DRIVER_ATHEROS:
3137 ath_sta_set_noack(dut, intf, val);
3138 break;
3139 default:
3140 send_resp(dut, conn, SIGMA_ERROR,
3141 "ErrorCode,Setting NoAck not supported");
3142 return 0;
3143 }
3144 }
3145
3146 val = get_param(cmd, "IgnoreChswitchProhibit");
3147 if (val) {
3148 /* TODO: Enabled/disabled */
3149 if (strcasecmp(val, "Enabled") == 0) {
3150 send_resp(dut, conn, SIGMA_ERROR,
3151 "ErrorCode,Enabling IgnoreChswitchProhibit "
3152 "not supported");
3153 return 0;
3154 }
3155 }
3156
3157 val = get_param(cmd, "TDLS");
3158 if (val) {
3159 if (strcasecmp(val, "Disabled") == 0) {
3160 if (wpa_command(intf, "SET tdls_disabled 1")) {
3161 send_resp(dut, conn, SIGMA_ERROR,
3162 "ErrorCode,Failed to disable TDLS");
3163 return 0;
3164 }
3165 } else if (strcasecmp(val, "Enabled") == 0) {
3166 if (wpa_command(intf, "SET tdls_disabled 0")) {
3167 send_resp(dut, conn, SIGMA_ERROR,
3168 "ErrorCode,Failed to enable TDLS");
3169 return 0;
3170 }
3171 } else {
3172 send_resp(dut, conn, SIGMA_ERROR,
3173 "ErrorCode,Unsupported TDLS value");
3174 return 0;
3175 }
3176 }
3177
3178 val = get_param(cmd, "TDLSmode");
3179 if (val) {
3180 if (strcasecmp(val, "Default") == 0) {
3181 wpa_command(intf, "SET tdls_testing 0");
3182 } else if (strcasecmp(val, "APProhibit") == 0) {
3183 if (wpa_command(intf, "SET tdls_testing 0x400")) {
3184 send_resp(dut, conn, SIGMA_ERROR,
3185 "ErrorCode,Failed to enable ignore "
3186 "APProhibit TDLS mode");
3187 return 0;
3188 }
3189 } else if (strcasecmp(val, "HiLoMac") == 0) {
3190 /* STA should respond with TDLS setup req for a TDLS
3191 * setup req */
3192 if (wpa_command(intf, "SET tdls_testing 0x80")) {
3193 send_resp(dut, conn, SIGMA_ERROR,
3194 "ErrorCode,Failed to enable HiLoMac "
3195 "TDLS mode");
3196 return 0;
3197 }
3198 } else if (strcasecmp(val, "WeakSecurity") == 0) {
3199 /*
3200 * Since all security modes are enabled by default when
3201 * Sigma control is used, there is no need to do
3202 * anything here.
3203 */
3204 } else if (strcasecmp(val, "ExistLink") == 0) {
3205 /*
3206 * Since we allow new TDLS Setup Request even if there
3207 * is an existing link, nothing needs to be done for
3208 * this.
3209 */
3210 } else {
3211 /* TODO:
3212 * ExistLink: STA should send TDLS setup req even if
3213 * direct link already exists
3214 */
3215 send_resp(dut, conn, SIGMA_ERROR,
3216 "ErrorCode,Unsupported TDLSmode value");
3217 return 0;
3218 }
3219 }
3220
3221 val = get_param(cmd, "FakePubKey");
3222 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
3223 send_resp(dut, conn, SIGMA_ERROR,
3224 "ErrorCode,Failed to enable FakePubKey");
3225 return 0;
3226 }
3227
3228 return 1;
3229}
3230
3231
3232static const char * ath_get_radio_name(const char *radio_name)
3233{
3234 if (radio_name == NULL)
3235 return "wifi0";
3236 if (strcmp(radio_name, "wifi1") == 0)
3237 return "wifi1";
3238 if (strcmp(radio_name, "wifi2") == 0)
3239 return "wifi2";
3240 return "wifi0";
3241}
3242
3243
3244static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
3245 const char *val)
3246{
3247 char buf[60];
3248 unsigned int vht_mcsmap = 0;
3249 int txchainmask = 0;
3250 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
3251
3252 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
3253 if (dut->testbed_flag_txsp == 1) {
3254 vht_mcsmap = 0xfffc;
3255 dut->testbed_flag_txsp = 0;
3256 } else {
3257 vht_mcsmap = 0xfffe;
3258 }
3259 txchainmask = 1;
3260 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
3261 if (dut->testbed_flag_txsp == 1) {
3262 vht_mcsmap = 0xfff0;
3263 dut->testbed_flag_txsp = 0;
3264 } else {
3265 vht_mcsmap = 0xfffa;
3266 }
3267 txchainmask = 3;
3268 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
3269 if (dut->testbed_flag_txsp == 1) {
3270 vht_mcsmap = 0xffc0;
3271 dut->testbed_flag_txsp = 0;
3272 } else {
3273 vht_mcsmap = 0xffea;
3274 }
3275 txchainmask = 7;
3276 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
3277 if (dut->testbed_flag_txsp == 1) {
3278 vht_mcsmap = 0xff00;
3279 dut->testbed_flag_txsp = 0;
3280 } else {
3281 vht_mcsmap = 0xffaa;
3282 }
3283 txchainmask = 15;
3284 } else {
3285 if (dut->testbed_flag_txsp == 1) {
3286 vht_mcsmap = 0xffc0;
3287 dut->testbed_flag_txsp = 0;
3288 } else {
3289 vht_mcsmap = 0xffea;
3290 }
3291 }
3292
3293 if (txchainmask) {
3294 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
3295 basedev, txchainmask);
3296 if (system(buf) != 0) {
3297 sigma_dut_print(dut, DUT_MSG_ERROR,
3298 "iwpriv txchainmask failed");
3299 }
3300 }
3301
3302 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
3303 intf, vht_mcsmap);
3304 if (system(buf) != 0) {
3305 sigma_dut_print(dut, DUT_MSG_ERROR,
3306 "iwpriv %s vht_mcsmap 0x%04x failed",
3307 intf, vht_mcsmap);
3308 }
3309}
3310
3311
3312static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
3313 const char *val)
3314{
3315 char buf[60];
3316 unsigned int vht_mcsmap = 0;
3317 int rxchainmask = 0;
3318 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
3319
3320 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
3321 if (dut->testbed_flag_rxsp == 1) {
3322 vht_mcsmap = 0xfffc;
3323 dut->testbed_flag_rxsp = 0;
3324 } else {
3325 vht_mcsmap = 0xfffe;
3326 }
3327 rxchainmask = 1;
3328 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
3329 if (dut->testbed_flag_rxsp == 1) {
3330 vht_mcsmap = 0xfff0;
3331 dut->testbed_flag_rxsp = 0;
3332 } else {
3333 vht_mcsmap = 0xfffa;
3334 }
3335 rxchainmask = 3;
3336 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
3337 if (dut->testbed_flag_rxsp == 1) {
3338 vht_mcsmap = 0xffc0;
3339 dut->testbed_flag_rxsp = 0;
3340 } else {
3341 vht_mcsmap = 0xffea;
3342 }
3343 rxchainmask = 7;
3344 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
3345 if (dut->testbed_flag_rxsp == 1) {
3346 vht_mcsmap = 0xff00;
3347 dut->testbed_flag_rxsp = 0;
3348 } else {
3349 vht_mcsmap = 0xffaa;
3350 }
3351 rxchainmask = 15;
3352 } else {
3353 if (dut->testbed_flag_rxsp == 1) {
3354 vht_mcsmap = 0xffc0;
3355 dut->testbed_flag_rxsp = 0;
3356 } else {
3357 vht_mcsmap = 0xffea;
3358 }
3359 }
3360
3361 if (rxchainmask) {
3362 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
3363 basedev, rxchainmask);
3364 if (system(buf) != 0) {
3365 sigma_dut_print(dut, DUT_MSG_ERROR,
3366 "iwpriv rxchainmask failed");
3367 }
3368 }
3369
3370 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
3371 intf, vht_mcsmap);
3372 if (system(buf) != 0) {
3373 sigma_dut_print(dut, DUT_MSG_ERROR,
3374 "iwpriv %s vht_mcsmap 0x%04x",
3375 intf, vht_mcsmap);
3376 }
3377}
3378
3379
3380void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
3381{
3382 if (strcasecmp(val, "enable") == 0) {
3383 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
3384 != 0) {
3385 sigma_dut_print(dut, DUT_MSG_ERROR,
3386 "Disable BB_VHTSIGB_CRC_CALC failed");
3387 }
3388
3389 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
3390 != 0) {
3391 sigma_dut_print(dut, DUT_MSG_ERROR,
3392 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
3393 }
3394 } else {
3395 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
3396 != 0) {
3397 sigma_dut_print(dut, DUT_MSG_ERROR,
3398 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
3399 }
3400
3401 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
3402 != 0) {
3403 sigma_dut_print(dut, DUT_MSG_ERROR,
3404 "Enable BB_VHTSIGB_CRC_CALC failed");
3405 }
3406 }
3407}
3408
3409
3410static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
3411 struct sigma_conn *conn,
3412 struct sigma_cmd *cmd)
3413{
3414 const char *val;
3415 int ampdu = -1;
3416 char buf[30];
3417
3418 val = get_param(cmd, "40_INTOLERANT");
3419 if (val) {
3420 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
3421 /* TODO: iwpriv ht40intol through wpa_supplicant */
3422 send_resp(dut, conn, SIGMA_ERROR,
3423 "ErrorCode,40_INTOLERANT not supported");
3424 return 0;
3425 }
3426 }
3427
3428 val = get_param(cmd, "ADDBA_REJECT");
3429 if (val) {
3430 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
3431 /* reject any ADDBA with status "decline" */
3432 ampdu = 0;
3433 } else {
3434 /* accept ADDBA */
3435 ampdu = 1;
3436 }
3437 }
3438
3439 val = get_param(cmd, "AMPDU");
3440 if (val) {
3441 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
3442 /* enable AMPDU Aggregation */
3443 if (ampdu == 0) {
3444 send_resp(dut, conn, SIGMA_ERROR,
3445 "ErrorCode,Mismatch in "
3446 "addba_reject/ampdu - "
3447 "not supported");
3448 return 0;
3449 }
3450 ampdu = 1;
3451 } else {
3452 /* disable AMPDU Aggregation */
3453 if (ampdu == 1) {
3454 send_resp(dut, conn, SIGMA_ERROR,
3455 "ErrorCode,Mismatch in "
3456 "addba_reject/ampdu - "
3457 "not supported");
3458 return 0;
3459 }
3460 ampdu = 0;
3461 }
3462 }
3463
3464 if (ampdu >= 0) {
3465 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
3466 ampdu ? "Enabling" : "Disabling");
3467 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003468 if (wpa_command(intf, buf) < 0 &&
3469 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003470 send_resp(dut, conn, SIGMA_ERROR,
3471 "ErrorCode,set aggr failed");
3472 return 0;
3473 }
3474 }
3475
3476 val = get_param(cmd, "AMSDU");
3477 if (val) {
3478 switch (get_driver_type()) {
3479 case DRIVER_ATHEROS:
3480 ath_sta_set_amsdu(dut, intf, val);
3481 break;
3482 default:
3483 if (strcmp(val, "1") == 0 ||
3484 strcasecmp(val, "Enable") == 0) {
3485 /* Enable AMSDU Aggregation */
3486 send_resp(dut, conn, SIGMA_ERROR,
3487 "ErrorCode,AMSDU aggregation not supported");
3488 return 0;
3489 }
3490 break;
3491 }
3492 }
3493
3494 val = get_param(cmd, "STBC_RX");
3495 if (val) {
3496 switch (get_driver_type()) {
3497 case DRIVER_ATHEROS:
3498 ath_sta_set_stbc(dut, intf, val);
3499 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303500 case DRIVER_WCN:
3501 wcn_sta_set_stbc(dut, intf, val);
3502 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003503 default:
3504 send_resp(dut, conn, SIGMA_ERROR,
3505 "ErrorCode,STBC_RX not supported");
3506 return 0;
3507 }
3508 }
3509
3510 val = get_param(cmd, "WIDTH");
3511 if (val) {
3512 switch (get_driver_type()) {
3513 case DRIVER_WCN:
3514 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
3515 send_resp(dut, conn, SIGMA_ERROR,
3516 "ErrorCode,Failed to set WIDTH");
3517 return 0;
3518 }
3519 break;
3520 case DRIVER_ATHEROS:
3521 if (ath_set_width(dut, conn, intf, val) < 0)
3522 return 0;
3523 break;
3524 default:
3525 sigma_dut_print(dut, DUT_MSG_ERROR,
3526 "Setting WIDTH not supported");
3527 break;
3528 }
3529 }
3530
3531 val = get_param(cmd, "SMPS");
3532 if (val) {
3533 /* TODO: Dynamic/0, Static/1, No Limit/2 */
3534 send_resp(dut, conn, SIGMA_ERROR,
3535 "ErrorCode,SMPS not supported");
3536 return 0;
3537 }
3538
3539 val = get_param(cmd, "TXSP_STREAM");
3540 if (val) {
3541 switch (get_driver_type()) {
3542 case DRIVER_WCN:
3543 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
3544 send_resp(dut, conn, SIGMA_ERROR,
3545 "ErrorCode,Failed to set TXSP_STREAM");
3546 return 0;
3547 }
3548 break;
3549 case DRIVER_ATHEROS:
3550 ath_sta_set_txsp_stream(dut, intf, val);
3551 break;
3552 default:
3553 sigma_dut_print(dut, DUT_MSG_ERROR,
3554 "Setting TXSP_STREAM not supported");
3555 break;
3556 }
3557 }
3558
3559 val = get_param(cmd, "RXSP_STREAM");
3560 if (val) {
3561 switch (get_driver_type()) {
3562 case DRIVER_WCN:
3563 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
3564 send_resp(dut, conn, SIGMA_ERROR,
3565 "ErrorCode,Failed to set RXSP_STREAM");
3566 return 0;
3567 }
3568 break;
3569 case DRIVER_ATHEROS:
3570 ath_sta_set_rxsp_stream(dut, intf, val);
3571 break;
3572 default:
3573 sigma_dut_print(dut, DUT_MSG_ERROR,
3574 "Setting RXSP_STREAM not supported");
3575 break;
3576 }
3577 }
3578
3579 val = get_param(cmd, "DYN_BW_SGNL");
3580 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08003581 switch (get_driver_type()) {
3582 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08003583 if (strcasecmp(val, "enable") == 0) {
3584 snprintf(buf, sizeof(buf),
3585 "iwpriv %s cwmenable 1", intf);
3586 if (system(buf) != 0) {
3587 sigma_dut_print(dut, DUT_MSG_ERROR,
3588 "iwpriv cwmenable 1 failed");
3589 return 0;
3590 }
3591 } else if (strcasecmp(val, "disable") == 0) {
3592 snprintf(buf, sizeof(buf),
3593 "iwpriv %s cwmenable 0", intf);
3594 if (system(buf) != 0) {
3595 sigma_dut_print(dut, DUT_MSG_ERROR,
3596 "iwpriv cwmenable 0 failed");
3597 return 0;
3598 }
3599 } else {
3600 sigma_dut_print(dut, DUT_MSG_ERROR,
3601 "Unsupported DYN_BW_SGL");
3602 }
3603
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003604 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3605 if (system(buf) != 0) {
3606 sigma_dut_print(dut, DUT_MSG_ERROR,
3607 "Failed to set cts_cbw in DYN_BW_SGNL");
3608 return 0;
3609 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08003610 break;
3611 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08003612 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08003613 ath_config_dyn_bw_sig(dut, intf, val);
3614 break;
3615 default:
3616 sigma_dut_print(dut, DUT_MSG_ERROR,
3617 "Failed to set DYN_BW_SGNL");
3618 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003619 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003620 }
3621
3622 val = get_param(cmd, "RTS_FORCE");
3623 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08003624 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003625 if (strcasecmp(val, "Enable") == 0) {
3626 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02003627 if (system(buf) != 0) {
3628 sigma_dut_print(dut, DUT_MSG_ERROR,
3629 "Failed to set RTS_FORCE 64");
3630 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08003631 snprintf(buf, sizeof(buf),
3632 "wifitool %s beeliner_fw_test 100 1", intf);
3633 if (system(buf) != 0) {
3634 sigma_dut_print(dut, DUT_MSG_ERROR,
3635 "wifitool beeliner_fw_test 100 1 failed");
3636 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003637 } else if (strcasecmp(val, "Disable") == 0) {
3638 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
3639 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02003640 if (system(buf) != 0) {
3641 sigma_dut_print(dut, DUT_MSG_ERROR,
3642 "Failed to set RTS_FORCE 2347");
3643 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003644 } else {
3645 send_resp(dut, conn, SIGMA_ERROR,
3646 "ErrorCode,RTS_FORCE value not supported");
3647 return 0;
3648 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003649 }
3650
3651 val = get_param(cmd, "CTS_WIDTH");
3652 if (val) {
3653 switch (get_driver_type()) {
3654 case DRIVER_WCN:
3655 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
3656 send_resp(dut, conn, SIGMA_ERROR,
3657 "ErrorCode,Failed to set CTS_WIDTH");
3658 return 0;
3659 }
3660 break;
3661 case DRIVER_ATHEROS:
3662 ath_set_cts_width(dut, intf, val);
3663 break;
3664 default:
3665 sigma_dut_print(dut, DUT_MSG_ERROR,
3666 "Setting CTS_WIDTH not supported");
3667 break;
3668 }
3669 }
3670
3671 val = get_param(cmd, "BW_SGNL");
3672 if (val) {
3673 if (strcasecmp(val, "Enable") == 0) {
3674 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
3675 intf);
3676 } else if (strcasecmp(val, "Disable") == 0) {
3677 /* TODO: Disable */
3678 buf[0] = '\0';
3679 } else {
3680 send_resp(dut, conn, SIGMA_ERROR,
3681 "ErrorCode,BW_SGNL value not supported");
3682 return 0;
3683 }
3684
3685 if (buf[0] != '\0' && system(buf) != 0) {
3686 sigma_dut_print(dut, DUT_MSG_ERROR,
3687 "Failed to set BW_SGNL");
3688 }
3689 }
3690
3691 val = get_param(cmd, "Band");
3692 if (val) {
3693 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
3694 /* STA supports all bands by default */
3695 } else {
3696 send_resp(dut, conn, SIGMA_ERROR,
3697 "ErrorCode,Unsupported Band");
3698 return 0;
3699 }
3700 }
3701
3702 val = get_param(cmd, "zero_crc");
3703 if (val) {
3704 switch (get_driver_type()) {
3705 case DRIVER_ATHEROS:
3706 ath_set_zero_crc(dut, val);
3707 break;
3708 default:
3709 break;
3710 }
3711 }
3712
3713 return 1;
3714}
3715
3716
3717static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
3718 struct sigma_cmd *cmd)
3719{
3720 const char *val;
3721 char buf[100];
3722
3723 val = get_param(cmd, "MSDUSize");
3724 if (val) {
3725 int mtu;
3726
3727 dut->amsdu_size = atoi(val);
3728 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
3729 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
3730 sigma_dut_print(dut, DUT_MSG_ERROR,
3731 "MSDUSize %d is above max %d or below min %d",
3732 dut->amsdu_size,
3733 IEEE80211_MAX_DATA_LEN_DMG,
3734 IEEE80211_SNAP_LEN_DMG);
3735 dut->amsdu_size = 0;
3736 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3737 }
3738
3739 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
3740 sigma_dut_print(dut, DUT_MSG_DEBUG,
3741 "Setting amsdu_size to %d", mtu);
3742 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
3743 get_station_ifname(), mtu);
3744
3745 if (system(buf) != 0) {
3746 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
3747 buf);
3748 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3749 }
3750 }
3751
3752 val = get_param(cmd, "BAckRcvBuf");
3753 if (val) {
3754 dut->back_rcv_buf = atoi(val);
3755 if (dut->back_rcv_buf == 0) {
3756 sigma_dut_print(dut, DUT_MSG_ERROR,
3757 "Failed to convert %s or value is 0",
3758 val);
3759 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3760 }
3761
3762 sigma_dut_print(dut, DUT_MSG_DEBUG,
3763 "Setting BAckRcvBuf to %s", val);
3764 }
3765
3766 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
3767}
3768
3769
3770static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
3771 struct sigma_cmd *cmd)
3772{
3773 int net_id;
3774 char *ifname;
3775 const char *val;
3776 char buf[100];
3777
3778 dut->mode = SIGMA_MODE_STATION;
3779 ifname = get_main_ifname();
3780 if (wpa_command(ifname, "PING") != 0) {
3781 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
3782 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3783 }
3784
3785 wpa_command(ifname, "FLUSH");
3786 net_id = add_network_common(dut, conn, ifname, cmd);
3787 if (net_id < 0) {
3788 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
3789 return net_id;
3790 }
3791
3792 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
3793 if (set_network(ifname, net_id, "mode", "2") < 0) {
3794 sigma_dut_print(dut, DUT_MSG_ERROR,
3795 "Failed to set supplicant network mode");
3796 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3797 }
3798
3799 sigma_dut_print(dut, DUT_MSG_DEBUG,
3800 "Supplicant set network with mode 2");
3801
3802 val = get_param(cmd, "Security");
3803 if (val && strcasecmp(val, "OPEN") == 0) {
3804 dut->ap_key_mgmt = AP_OPEN;
3805 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
3806 sigma_dut_print(dut, DUT_MSG_ERROR,
3807 "Failed to set supplicant to %s security",
3808 val);
3809 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3810 }
3811 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
3812 dut->ap_key_mgmt = AP_WPA2_PSK;
3813 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
3814 sigma_dut_print(dut, DUT_MSG_ERROR,
3815 "Failed to set supplicant to %s security",
3816 val);
3817 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3818 }
3819
3820 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
3821 sigma_dut_print(dut, DUT_MSG_ERROR,
3822 "Failed to set supplicant to proto RSN");
3823 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3824 }
3825 } else if (val) {
3826 sigma_dut_print(dut, DUT_MSG_ERROR,
3827 "Requested Security %s is not supported on 60GHz",
3828 val);
3829 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
3830 }
3831
3832 val = get_param(cmd, "Encrypt");
3833 if (val && strcasecmp(val, "AES-GCMP") == 0) {
3834 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
3835 sigma_dut_print(dut, DUT_MSG_ERROR,
3836 "Failed to set supplicant to pairwise GCMP");
3837 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3838 }
3839 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
3840 sigma_dut_print(dut, DUT_MSG_ERROR,
3841 "Failed to set supplicant to group GCMP");
3842 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3843 }
3844 } else if (val) {
3845 sigma_dut_print(dut, DUT_MSG_ERROR,
3846 "Requested Encrypt %s is not supported on 60 GHz",
3847 val);
3848 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
3849 }
3850
3851 val = get_param(cmd, "PSK");
3852 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
3853 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
3854 val);
3855 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3856 }
3857
3858 /* Convert 60G channel to freq */
3859 switch (dut->ap_channel) {
3860 case 1:
3861 val = "58320";
3862 break;
3863 case 2:
3864 val = "60480";
3865 break;
3866 case 3:
3867 val = "62640";
3868 break;
3869 default:
3870 sigma_dut_print(dut, DUT_MSG_ERROR,
3871 "Failed to configure channel %d. Not supported",
3872 dut->ap_channel);
3873 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3874 }
3875
3876 if (set_network(ifname, net_id, "frequency", val) < 0) {
3877 sigma_dut_print(dut, DUT_MSG_ERROR,
3878 "Failed to set supplicant network frequency");
3879 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3880 }
3881
3882 sigma_dut_print(dut, DUT_MSG_DEBUG,
3883 "Supplicant set network with frequency");
3884
3885 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
3886 if (wpa_command(ifname, buf) < 0) {
3887 sigma_dut_print(dut, DUT_MSG_INFO,
3888 "Failed to select network id %d on %s",
3889 net_id, ifname);
3890 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3891 }
3892
3893 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
3894
3895 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
3896}
3897
3898
Lior David67543f52017-01-03 19:04:22 +02003899static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
3900{
3901 char buf[128], fname[128];
3902 FILE *f;
3903
3904 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
3905 sigma_dut_print(dut, DUT_MSG_ERROR,
3906 "failed to get wil6210 debugfs dir");
3907 return -1;
3908 }
3909
3910 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
3911 f = fopen(fname, "w");
3912 if (!f) {
3913 sigma_dut_print(dut, DUT_MSG_ERROR,
3914 "failed to open: %s", fname);
3915 return -1;
3916 }
3917
3918 fprintf(f, "%d\n", abft_len);
3919 fclose(f);
3920
3921 return 0;
3922}
3923
3924
3925static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
3926 int abft_len)
3927{
3928 switch (get_driver_type()) {
3929 case DRIVER_WIL6210:
3930 return wil6210_set_abft_len(dut, abft_len);
3931 default:
3932 sigma_dut_print(dut, DUT_MSG_ERROR,
3933 "set abft_len not supported");
3934 return -1;
3935 }
3936}
3937
3938
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003939static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
3940 struct sigma_cmd *cmd)
3941{
3942 const char *val;
Lior David67543f52017-01-03 19:04:22 +02003943 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003944
3945 if (dut->dev_role != DEVROLE_PCP) {
3946 send_resp(dut, conn, SIGMA_INVALID,
3947 "ErrorCode,Invalid DevRole");
3948 return 0;
3949 }
3950
3951 val = get_param(cmd, "SSID");
3952 if (val) {
3953 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
3954 send_resp(dut, conn, SIGMA_INVALID,
3955 "ErrorCode,Invalid SSID");
3956 return -1;
3957 }
3958
3959 strncpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
3960 }
3961
3962 val = get_param(cmd, "CHANNEL");
3963 if (val) {
3964 const char *pos;
3965
3966 dut->ap_channel = atoi(val);
3967 pos = strchr(val, ';');
3968 if (pos) {
3969 pos++;
3970 dut->ap_channel_1 = atoi(pos);
3971 }
3972 }
3973
3974 switch (dut->ap_channel) {
3975 case 1:
3976 case 2:
3977 case 3:
3978 break;
3979 default:
3980 sigma_dut_print(dut, DUT_MSG_ERROR,
3981 "Channel %d is not supported", dut->ap_channel);
3982 send_resp(dut, conn, SIGMA_ERROR,
3983 "Requested channel is not supported");
3984 return -1;
3985 }
3986
3987 val = get_param(cmd, "BCNINT");
3988 if (val)
3989 dut->ap_bcnint = atoi(val);
3990
3991
3992 val = get_param(cmd, "ExtSchIE");
3993 if (val) {
3994 send_resp(dut, conn, SIGMA_ERROR,
3995 "ErrorCode,ExtSchIE is not supported yet");
3996 return -1;
3997 }
3998
3999 val = get_param(cmd, "AllocType");
4000 if (val) {
4001 send_resp(dut, conn, SIGMA_ERROR,
4002 "ErrorCode,AllocType is not supported yet");
4003 return -1;
4004 }
4005
4006 val = get_param(cmd, "PercentBI");
4007 if (val) {
4008 send_resp(dut, conn, SIGMA_ERROR,
4009 "ErrorCode,PercentBI is not supported yet");
4010 return -1;
4011 }
4012
4013 val = get_param(cmd, "CBAPOnly");
4014 if (val) {
4015 send_resp(dut, conn, SIGMA_ERROR,
4016 "ErrorCode,CBAPOnly is not supported yet");
4017 return -1;
4018 }
4019
4020 val = get_param(cmd, "AMPDU");
4021 if (val) {
4022 if (strcasecmp(val, "Enable") == 0)
4023 dut->ap_ampdu = 1;
4024 else if (strcasecmp(val, "Disable") == 0)
4025 dut->ap_ampdu = 2;
4026 else {
4027 send_resp(dut, conn, SIGMA_ERROR,
4028 "ErrorCode,AMPDU value is not Enable nor Disabled");
4029 return -1;
4030 }
4031 }
4032
4033 val = get_param(cmd, "AMSDU");
4034 if (val) {
4035 if (strcasecmp(val, "Enable") == 0)
4036 dut->ap_amsdu = 1;
4037 else if (strcasecmp(val, "Disable") == 0)
4038 dut->ap_amsdu = 2;
4039 }
4040
4041 val = get_param(cmd, "NumMSDU");
4042 if (val) {
4043 send_resp(dut, conn, SIGMA_ERROR,
4044 "ErrorCode, NumMSDU is not supported yet");
4045 return -1;
4046 }
4047
4048 val = get_param(cmd, "ABFTLRang");
4049 if (val) {
4050 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02004051 "ABFTLRang parameter %s", val);
4052 if (strcmp(val, "Gt1") == 0)
4053 abft_len = 2; /* 2 slots in this case */
4054 }
4055
4056 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
4057 send_resp(dut, conn, SIGMA_ERROR,
4058 "ErrorCode, Can't set ABFT length");
4059 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004060 }
4061
4062 if (sta_pcp_start(dut, conn, cmd) < 0) {
4063 send_resp(dut, conn, SIGMA_ERROR,
4064 "ErrorCode, Can't start PCP role");
4065 return -1;
4066 }
4067
4068 return sta_set_60g_common(dut, conn, cmd);
4069}
4070
4071
4072static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
4073 struct sigma_cmd *cmd)
4074{
4075 const char *val = get_param(cmd, "DiscoveryMode");
4076
4077 if (dut->dev_role != DEVROLE_STA) {
4078 send_resp(dut, conn, SIGMA_INVALID,
4079 "ErrorCode,Invalid DevRole");
4080 return 0;
4081 }
4082
4083 if (val) {
4084 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
4085 /* Ignore Discovery mode till Driver expose API. */
4086#if 0
4087 if (strcasecmp(val, "1") == 0) {
4088 send_resp(dut, conn, SIGMA_INVALID,
4089 "ErrorCode,DiscoveryMode 1 not supported");
4090 return 0;
4091 }
4092
4093 if (strcasecmp(val, "0") == 0) {
4094 /* OK */
4095 } else {
4096 send_resp(dut, conn, SIGMA_INVALID,
4097 "ErrorCode,DiscoveryMode not supported");
4098 return 0;
4099 }
4100#endif
4101 }
4102
4103 if (start_sta_mode(dut) != 0)
4104 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4105 return sta_set_60g_common(dut, conn, cmd);
4106}
4107
4108
4109static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
4110 struct sigma_cmd *cmd)
4111{
4112 const char *intf = get_param(cmd, "Interface");
4113 disconnect_station(dut);
4114 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
4115 * due to cached results. */
4116 wpa_command(intf, "SET ignore_old_scan_res 1");
4117 wpa_command(intf, "BSS_FLUSH");
4118 return 1;
4119}
4120
4121
4122static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
4123 struct sigma_cmd *cmd)
4124{
4125 const char *intf = get_param(cmd, "Interface");
4126 const char *bssid = get_param(cmd, "bssid");
4127 const char *val = get_param(cmd, "CHANNEL");
4128 struct wpa_ctrl *ctrl;
4129 char buf[100];
4130 int res;
4131 int chan = 0;
4132
4133 if (bssid == NULL) {
4134 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
4135 "argument");
4136 return 0;
4137 }
4138
4139 if (val)
4140 chan = atoi(val);
4141
4142 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
4143 /* The current network may be from sta_associate or
4144 * sta_hs2_associate
4145 */
4146 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
4147 0 ||
4148 set_network(intf, 0, "bssid", bssid) < 0)
4149 return -2;
4150 }
4151
4152 ctrl = open_wpa_mon(intf);
4153 if (ctrl == NULL) {
4154 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
4155 "wpa_supplicant monitor connection");
4156 return -1;
4157 }
4158
4159 if (wifi_chip_type == DRIVER_WCN) {
4160#ifdef ANDROID
4161 if (set_network(intf, dut->infra_network_id, "bssid", "any")
4162 < 0) {
4163 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
4164 "bssid to any during FASTREASSOC");
4165 return -2;
4166 }
4167 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
4168 bssid, chan);
4169 if (res > 0 && res < (int) sizeof(buf))
4170 res = wpa_command(intf, buf);
4171
4172 if (res < 0 || res >= (int) sizeof(buf)) {
4173 send_resp(dut, conn, SIGMA_ERROR,
4174 "errorCode,Failed to run DRIVER FASTREASSOC");
4175 wpa_ctrl_detach(ctrl);
4176 wpa_ctrl_close(ctrl);
4177 return 0;
4178 }
4179#else /* ANDROID */
4180 sigma_dut_print(dut, DUT_MSG_DEBUG,
4181 "Reassoc using iwpriv - skip chan=%d info",
4182 chan);
4183 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
4184 if (system(buf) != 0) {
4185 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
4186 wpa_ctrl_detach(ctrl);
4187 wpa_ctrl_close(ctrl);
4188 return 0;
4189 }
4190#endif /* ANDROID */
4191 sigma_dut_print(dut, DUT_MSG_INFO,
4192 "sta_reassoc: Run %s successful", buf);
4193 } else if (wpa_command(intf, "REASSOCIATE")) {
4194 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
4195 "request reassociation");
4196 wpa_ctrl_detach(ctrl);
4197 wpa_ctrl_close(ctrl);
4198 return 0;
4199 }
4200
4201 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
4202 buf, sizeof(buf));
4203
4204 wpa_ctrl_detach(ctrl);
4205 wpa_ctrl_close(ctrl);
4206
4207 if (res < 0) {
4208 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
4209 return -1;
4210 }
4211
4212 return 1;
4213}
4214
4215
4216static void hs2_clear_credentials(const char *intf)
4217{
4218 wpa_command(intf, "REMOVE_CRED all");
4219}
4220
4221
Lior Davidcc88b562017-01-03 18:52:09 +02004222#ifdef __linux__
4223static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
4224 unsigned int *aid)
4225{
Lior David0fe101e2017-03-09 16:09:50 +02004226 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02004227
Lior David0fe101e2017-03-09 16:09:50 +02004228 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02004229}
4230#endif /* __linux__ */
4231
4232
4233static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
4234 unsigned int *aid)
4235{
4236 switch (get_driver_type()) {
4237#ifdef __linux__
4238 case DRIVER_WIL6210:
4239 return wil6210_get_aid(dut, bssid, aid);
4240#endif /* __linux__ */
4241 default:
4242 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
4243 return -1;
4244 }
4245}
4246
4247
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004248static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
4249 struct sigma_cmd *cmd)
4250{
4251 char buf[MAX_CMD_LEN];
4252 char bss_list[MAX_CMD_LEN];
4253 const char *parameter = get_param(cmd, "Parameter");
4254
4255 if (parameter == NULL)
4256 return -1;
4257
Lior Davidcc88b562017-01-03 18:52:09 +02004258 if (strcasecmp(parameter, "AID") == 0) {
4259 unsigned int aid = 0;
4260 char bssid[20];
4261
4262 if (get_wpa_status(get_station_ifname(), "bssid",
4263 bssid, sizeof(bssid)) < 0) {
4264 sigma_dut_print(dut, DUT_MSG_ERROR,
4265 "could not get bssid");
4266 return -2;
4267 }
4268
4269 if (sta_get_aid_60g(dut, bssid, &aid))
4270 return -2;
4271
4272 snprintf(buf, sizeof(buf), "aid,%d", aid);
4273 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
4274 send_resp(dut, conn, SIGMA_COMPLETE, buf);
4275 return 0;
4276 }
4277
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004278 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
4279 char *bss_line;
4280 char *bss_id = NULL;
4281 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304282 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004283
4284 if (ifname == NULL) {
4285 sigma_dut_print(dut, DUT_MSG_INFO,
4286 "For get DiscoveredDevList need Interface name.");
4287 return -1;
4288 }
4289
4290 /*
4291 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
4292 * of BSSIDs in "bssid=<BSSID>\n"
4293 */
4294 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
4295 bss_list,
4296 sizeof(bss_list)) < 0) {
4297 sigma_dut_print(dut, DUT_MSG_ERROR,
4298 "Failed to get bss list");
4299 return -1;
4300 }
4301
4302 sigma_dut_print(dut, DUT_MSG_DEBUG,
4303 "bss list for ifname:%s is:%s",
4304 ifname, bss_list);
4305
4306 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304307 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004308 while (bss_line) {
4309 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
4310 bss_id) {
4311 int len;
4312
4313 len = snprintf(buf + strlen(buf),
4314 sizeof(buf) - strlen(buf),
4315 ",%s", bss_id);
4316 free(bss_id);
4317 bss_id = NULL;
4318 if (len < 0) {
4319 sigma_dut_print(dut,
4320 DUT_MSG_ERROR,
4321 "Failed to read BSSID");
4322 send_resp(dut, conn, SIGMA_ERROR,
4323 "ErrorCode,Failed to read BSS ID");
4324 return 0;
4325 }
4326
4327 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
4328 sigma_dut_print(dut,
4329 DUT_MSG_ERROR,
4330 "Response buf too small for list");
4331 send_resp(dut, conn,
4332 SIGMA_ERROR,
4333 "ErrorCode,Response buf too small for list");
4334 return 0;
4335 }
4336 }
4337
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304338 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004339 }
4340
4341 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
4342 buf);
4343 send_resp(dut, conn, SIGMA_COMPLETE, buf);
4344 return 0;
4345 }
4346
4347 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4348 return 0;
4349}
4350
4351
4352static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
4353 struct sigma_cmd *cmd)
4354{
4355 const char *program = get_param(cmd, "Program");
4356
4357 if (program == NULL)
4358 return -1;
4359
4360 if (strcasecmp(program, "P2PNFC") == 0)
4361 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
4362
4363 if (strcasecmp(program, "60ghz") == 0)
4364 return sta_get_parameter_60g(dut, conn, cmd);
4365
4366#ifdef ANDROID_NAN
4367 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07004368 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004369#endif /* ANDROID_NAN */
4370
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004371#ifdef MIRACAST
4372 if (strcasecmp(program, "WFD") == 0 ||
4373 strcasecmp(program, "DisplayR2") == 0)
4374 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
4375#endif /* MIRACAST */
4376
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004377 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4378 return 0;
4379}
4380
4381
4382static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
4383 const char *type)
4384{
4385 char buf[100];
4386
4387 if (dut->program == PROGRAM_VHT) {
4388 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4389 if (system(buf) != 0) {
4390 sigma_dut_print(dut, DUT_MSG_ERROR,
4391 "iwpriv %s chwidth failed", intf);
4392 }
4393
4394 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
4395 if (system(buf) != 0) {
4396 sigma_dut_print(dut, DUT_MSG_ERROR,
4397 "iwpriv %s mode 11ACVHT80 failed",
4398 intf);
4399 }
4400
4401 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
4402 if (system(buf) != 0) {
4403 sigma_dut_print(dut, DUT_MSG_ERROR,
4404 "iwpriv %s vhtmcs -1 failed", intf);
4405 }
4406 }
4407
4408 if (dut->program == PROGRAM_HT) {
4409 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4410 if (system(buf) != 0) {
4411 sigma_dut_print(dut, DUT_MSG_ERROR,
4412 "iwpriv %s chwidth failed", intf);
4413 }
4414
4415 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
4416 if (system(buf) != 0) {
4417 sigma_dut_print(dut, DUT_MSG_ERROR,
4418 "iwpriv %s mode 11naht40 failed",
4419 intf);
4420 }
4421
4422 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
4423 if (system(buf) != 0) {
4424 sigma_dut_print(dut, DUT_MSG_ERROR,
4425 "iwpriv set11NRates failed");
4426 }
4427 }
4428
4429 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
4430 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
4431 if (system(buf) != 0) {
4432 sigma_dut_print(dut, DUT_MSG_ERROR,
4433 "disabling powersave failed");
4434 }
4435
4436 /* Reset CTS width */
4437 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
4438 intf);
4439 if (system(buf) != 0) {
4440 sigma_dut_print(dut, DUT_MSG_ERROR,
4441 "wifitool %s beeliner_fw_test 54 0 failed",
4442 intf);
4443 }
4444
4445 /* Enable Dynamic Bandwidth signalling by default */
4446 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
4447 if (system(buf) != 0) {
4448 sigma_dut_print(dut, DUT_MSG_ERROR,
4449 "iwpriv %s cwmenable 1 failed", intf);
4450 }
4451
4452 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
4453 if (system(buf) != 0) {
4454 sigma_dut_print(dut, DUT_MSG_ERROR,
4455 "iwpriv rts failed");
4456 }
4457 }
4458
4459 if (type && strcasecmp(type, "Testbed") == 0) {
4460 dut->testbed_flag_txsp = 1;
4461 dut->testbed_flag_rxsp = 1;
4462 /* STA has to set spatial stream to 2 per Appendix H */
4463 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
4464 if (system(buf) != 0) {
4465 sigma_dut_print(dut, DUT_MSG_ERROR,
4466 "iwpriv vht_mcsmap failed");
4467 }
4468
4469 /* Disable LDPC per Appendix H */
4470 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
4471 if (system(buf) != 0) {
4472 sigma_dut_print(dut, DUT_MSG_ERROR,
4473 "iwpriv %s ldpc 0 failed", intf);
4474 }
4475
4476 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4477 if (system(buf) != 0) {
4478 sigma_dut_print(dut, DUT_MSG_ERROR,
4479 "iwpriv amsdu failed");
4480 }
4481
4482 /* TODO: Disable STBC 2x1 transmit and receive */
4483 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
4484 if (system(buf) != 0) {
4485 sigma_dut_print(dut, DUT_MSG_ERROR,
4486 "Disable tx_stbc 0 failed");
4487 }
4488
4489 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
4490 if (system(buf) != 0) {
4491 sigma_dut_print(dut, DUT_MSG_ERROR,
4492 "Disable rx_stbc 0 failed");
4493 }
4494
4495 /* STA has to disable Short GI per Appendix H */
4496 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
4497 if (system(buf) != 0) {
4498 sigma_dut_print(dut, DUT_MSG_ERROR,
4499 "iwpriv %s shortgi 0 failed", intf);
4500 }
4501 }
4502
4503 if (type && strcasecmp(type, "DUT") == 0) {
4504 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
4505 if (system(buf) != 0) {
4506 sigma_dut_print(dut, DUT_MSG_ERROR,
4507 "iwpriv %s nss 3 failed", intf);
4508 }
4509
4510 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
4511 if (system(buf) != 0) {
4512 sigma_dut_print(dut, DUT_MSG_ERROR,
4513 "iwpriv %s shortgi 1 failed", intf);
4514 }
4515 }
4516}
4517
4518
4519static int cmd_sta_reset_default(struct sigma_dut *dut,
4520 struct sigma_conn *conn,
4521 struct sigma_cmd *cmd)
4522{
4523 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
4524 struct sigma_cmd *cmd);
4525 const char *intf = get_param(cmd, "Interface");
4526 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004527 const char *program = get_param(cmd, "program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004528
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004529 if (!program)
4530 program = get_param(cmd, "prog");
4531 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004532 dut->device_type = STA_unknown;
4533 type = get_param(cmd, "type");
4534 if (type && strcasecmp(type, "Testbed") == 0)
4535 dut->device_type = STA_testbed;
4536 if (type && strcasecmp(type, "DUT") == 0)
4537 dut->device_type = STA_dut;
4538
4539 if (dut->program == PROGRAM_TDLS) {
4540 /* Clear TDLS testing mode */
4541 wpa_command(intf, "SET tdls_disabled 0");
4542 wpa_command(intf, "SET tdls_testing 0");
4543 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05304544 if (get_driver_type() == DRIVER_WCN) {
4545 /* Enable the WCN driver in TDLS Explicit trigger mode
4546 */
4547 wpa_command(intf, "SET tdls_external_control 0");
4548 wpa_command(intf, "SET tdls_trigger_control 0");
4549 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004550 }
4551
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004552#ifdef MIRACAST
4553 if (dut->program == PROGRAM_WFD ||
4554 dut->program == PROGRAM_DISPLAYR2)
4555 miracast_sta_reset_default(dut, conn, cmd);
4556#endif /* MIRACAST */
4557
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004558 switch (get_driver_type()) {
4559 case DRIVER_ATHEROS:
4560 sta_reset_default_ath(dut, intf, type);
4561 break;
4562 default:
4563 break;
4564 }
4565
4566#ifdef ANDROID_NAN
4567 if (dut->program == PROGRAM_NAN)
4568 nan_cmd_sta_reset_default(dut, conn, cmd);
4569#endif /* ANDROID_NAN */
4570
4571 if (dut->program == PROGRAM_HS2_R2) {
4572 unlink("SP/wi-fi.org/pps.xml");
4573 if (system("rm -r SP/*") != 0) {
4574 }
4575 unlink("next-client-cert.pem");
4576 unlink("next-client-key.pem");
4577 }
4578
4579 if (dut->program == PROGRAM_60GHZ) {
4580 const char *dev_role = get_param(cmd, "DevRole");
4581
4582 if (!dev_role) {
4583 send_resp(dut, conn, SIGMA_ERROR,
4584 "errorCode,Missing DevRole argument");
4585 return 0;
4586 }
4587
4588 if (strcasecmp(dev_role, "STA") == 0)
4589 dut->dev_role = DEVROLE_STA;
4590 else if (strcasecmp(dev_role, "PCP") == 0)
4591 dut->dev_role = DEVROLE_PCP;
4592 else {
4593 send_resp(dut, conn, SIGMA_ERROR,
4594 "errorCode,Unknown DevRole");
4595 return 0;
4596 }
4597
4598 if (dut->device_type == STA_unknown) {
4599 sigma_dut_print(dut, DUT_MSG_ERROR,
4600 "Device type is not STA testbed or DUT");
4601 send_resp(dut, conn, SIGMA_ERROR,
4602 "errorCode,Unknown device type");
4603 return 0;
4604 }
4605 }
4606
4607 wpa_command(intf, "WPS_ER_STOP");
4608 wpa_command(intf, "FLUSH");
4609 wpa_command(intf, "SET radio_disabled 0");
4610
4611 if (dut->tmp_mac_addr && dut->set_macaddr) {
4612 dut->tmp_mac_addr = 0;
4613 if (system(dut->set_macaddr) != 0) {
4614 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
4615 "temporary MAC address");
4616 }
4617 }
4618
4619 set_ps(intf, dut, 0);
4620
4621 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
4622 wpa_command(intf, "SET interworking 1");
4623 wpa_command(intf, "SET hs20 1");
4624 }
4625
4626 if (dut->program == PROGRAM_HS2_R2) {
4627 wpa_command(intf, "SET pmf 1");
4628 } else {
4629 wpa_command(intf, "SET pmf 0");
4630 }
4631
4632 hs2_clear_credentials(intf);
4633 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
4634 wpa_command(intf, "SET access_network_type 15");
4635
4636 static_ip_file(0, NULL, NULL, NULL);
4637 kill_dhcp_client(dut, intf);
4638 clear_ip_addr(dut, intf);
4639
4640 dut->er_oper_performed = 0;
4641 dut->er_oper_bssid[0] = '\0';
4642
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07004643 if (dut->program == PROGRAM_LOC) {
4644 /* Disable Interworking by default */
4645 wpa_command(get_station_ifname(), "SET interworking 0");
4646 }
4647
Ashwini Patil00402582017-04-13 12:29:39 +05304648 if (dut->program == PROGRAM_MBO) {
4649 free(dut->non_pref_ch_list);
4650 dut->non_pref_ch_list = NULL;
4651 }
4652
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08004653 if (dut->program != PROGRAM_VHT)
4654 return cmd_sta_p2p_reset(dut, conn, cmd);
4655 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004656}
4657
4658
4659static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
4660 struct sigma_cmd *cmd)
4661{
4662 const char *program = get_param(cmd, "Program");
4663
4664 if (program == NULL)
4665 return -1;
4666#ifdef ANDROID_NAN
4667 if (strcasecmp(program, "NAN") == 0)
4668 return nan_cmd_sta_get_events(dut, conn, cmd);
4669#endif /* ANDROID_NAN */
4670 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4671 return 0;
4672}
4673
4674
4675static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
4676 struct sigma_cmd *cmd)
4677{
4678 const char *program = get_param(cmd, "Prog");
4679
4680 if (program == NULL)
4681 return -1;
4682#ifdef ANDROID_NAN
4683 if (strcasecmp(program, "NAN") == 0)
4684 return nan_cmd_sta_exec_action(dut, conn, cmd);
4685#endif /* ANDROID_NAN */
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004686 if (strcasecmp(program, "Loc") == 0)
4687 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004688 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4689 return 0;
4690}
4691
4692
4693static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
4694 struct sigma_cmd *cmd)
4695{
4696 const char *intf = get_param(cmd, "Interface");
4697 const char *val, *mcs32, *rate;
4698
4699 val = get_param(cmd, "GREENFIELD");
4700 if (val) {
4701 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4702 /* Enable GD */
4703 send_resp(dut, conn, SIGMA_ERROR,
4704 "ErrorCode,GF not supported");
4705 return 0;
4706 }
4707 }
4708
4709 val = get_param(cmd, "SGI20");
4710 if (val) {
4711 switch (get_driver_type()) {
4712 case DRIVER_ATHEROS:
4713 ath_sta_set_sgi(dut, intf, val);
4714 break;
4715 default:
4716 send_resp(dut, conn, SIGMA_ERROR,
4717 "ErrorCode,SGI20 not supported");
4718 return 0;
4719 }
4720 }
4721
4722 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
4723 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
4724 if (mcs32 && rate) {
4725 /* TODO */
4726 send_resp(dut, conn, SIGMA_ERROR,
4727 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
4728 return 0;
4729 } else if (mcs32 && !rate) {
4730 /* TODO */
4731 send_resp(dut, conn, SIGMA_ERROR,
4732 "ErrorCode,MCS32 not supported");
4733 return 0;
4734 } else if (!mcs32 && rate) {
4735 switch (get_driver_type()) {
4736 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004737 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004738 ath_sta_set_11nrates(dut, intf, rate);
4739 break;
4740 default:
4741 send_resp(dut, conn, SIGMA_ERROR,
4742 "ErrorCode,MCS32_FIXEDRATE not supported");
4743 return 0;
4744 }
4745 }
4746
4747 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
4748}
4749
4750
4751static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
4752 struct sigma_conn *conn,
4753 struct sigma_cmd *cmd)
4754{
4755 const char *intf = get_param(cmd, "Interface");
4756 const char *val;
4757 char buf[30];
4758 int tkip = -1;
4759 int wep = -1;
4760
4761 val = get_param(cmd, "SGI80");
4762 if (val) {
4763 int sgi80;
4764
4765 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4766 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
4767 if (system(buf) != 0) {
4768 sigma_dut_print(dut, DUT_MSG_ERROR,
4769 "iwpriv shortgi failed");
4770 }
4771 }
4772
4773 val = get_param(cmd, "TxBF");
4774 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
4775 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
4776 if (system(buf) != 0) {
4777 sigma_dut_print(dut, DUT_MSG_ERROR,
4778 "iwpriv vhtsubfee failed");
4779 }
4780 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
4781 if (system(buf) != 0) {
4782 sigma_dut_print(dut, DUT_MSG_ERROR,
4783 "iwpriv vhtsubfer failed");
4784 }
4785 }
4786
4787 val = get_param(cmd, "MU_TxBF");
4788 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
4789 switch (get_driver_type()) {
4790 case DRIVER_ATHEROS:
4791 ath_sta_set_txsp_stream(dut, intf, "1SS");
4792 ath_sta_set_rxsp_stream(dut, intf, "1SS");
4793 case DRIVER_WCN:
4794 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
4795 send_resp(dut, conn, SIGMA_ERROR,
4796 "ErrorCode,Failed to set RX/TXSP_STREAM");
4797 return 0;
4798 }
4799 default:
4800 sigma_dut_print(dut, DUT_MSG_ERROR,
4801 "Setting SP_STREAM not supported");
4802 break;
4803 }
4804 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
4805 if (system(buf) != 0) {
4806 sigma_dut_print(dut, DUT_MSG_ERROR,
4807 "iwpriv vhtmubfee failed");
4808 }
4809 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
4810 if (system(buf) != 0) {
4811 sigma_dut_print(dut, DUT_MSG_ERROR,
4812 "iwpriv vhtmubfer failed");
4813 }
4814 }
4815
4816 val = get_param(cmd, "LDPC");
4817 if (val) {
4818 int ldpc;
4819
4820 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4821 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
4822 if (system(buf) != 0) {
4823 sigma_dut_print(dut, DUT_MSG_ERROR,
4824 "iwpriv ldpc failed");
4825 }
4826 }
4827
4828 val = get_param(cmd, "opt_md_notif_ie");
4829 if (val) {
4830 char *result = NULL;
4831 char delim[] = ";";
4832 char token[30];
4833 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304834 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004835
4836 strncpy(token, val, sizeof(token));
4837 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304838 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004839
4840 /* Extract the NSS information */
4841 if (result) {
4842 value = atoi(result);
4843 switch (value) {
4844 case 1:
4845 config_val = 1;
4846 break;
4847 case 2:
4848 config_val = 3;
4849 break;
4850 case 3:
4851 config_val = 7;
4852 break;
4853 case 4:
4854 config_val = 15;
4855 break;
4856 default:
4857 config_val = 3;
4858 break;
4859 }
4860
4861 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
4862 intf, config_val);
4863 if (system(buf) != 0) {
4864 sigma_dut_print(dut, DUT_MSG_ERROR,
4865 "iwpriv rxchainmask failed");
4866 }
4867
4868 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
4869 intf, config_val);
4870 if (system(buf) != 0) {
4871 sigma_dut_print(dut, DUT_MSG_ERROR,
4872 "iwpriv txchainmask failed");
4873 }
4874 }
4875
4876 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304877 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004878 if (result) {
4879 value = atoi(result);
4880 switch (value) {
4881 case 20:
4882 config_val = 0;
4883 break;
4884 case 40:
4885 config_val = 1;
4886 break;
4887 case 80:
4888 config_val = 2;
4889 break;
4890 case 160:
4891 config_val = 3;
4892 break;
4893 default:
4894 config_val = 2;
4895 break;
4896 }
4897
4898 dut->chwidth = config_val;
4899
4900 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
4901 intf, config_val);
4902 if (system(buf) != 0) {
4903 sigma_dut_print(dut, DUT_MSG_ERROR,
4904 "iwpriv chwidth failed");
4905 }
4906 }
4907
4908 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
4909 if (system(buf) != 0) {
4910 sigma_dut_print(dut, DUT_MSG_ERROR,
4911 "iwpriv opmode_notify failed");
4912 }
4913 }
4914
4915 val = get_param(cmd, "nss_mcs_cap");
4916 if (val) {
4917 int nss, mcs;
4918 char token[20];
4919 char *result = NULL;
4920 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304921 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004922
4923 strncpy(token, val, sizeof(token));
4924 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304925 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05304926 if (!result) {
4927 sigma_dut_print(dut, DUT_MSG_ERROR,
4928 "VHT NSS not specified");
4929 return 0;
4930 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004931 nss = atoi(result);
4932
4933 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
4934 if (system(buf) != 0) {
4935 sigma_dut_print(dut, DUT_MSG_ERROR,
4936 "iwpriv nss failed");
4937 }
4938
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304939 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004940 if (result == NULL) {
4941 sigma_dut_print(dut, DUT_MSG_ERROR,
4942 "VHTMCS NOT SPECIFIED!");
4943 return 0;
4944 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304945 result = strtok_r(result, "-", &saveptr);
4946 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05304947 if (!result) {
4948 sigma_dut_print(dut, DUT_MSG_ERROR,
4949 "VHT MCS not specified");
4950 return 0;
4951 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004952 mcs = atoi(result);
4953
4954 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
4955 if (system(buf) != 0) {
4956 sigma_dut_print(dut, DUT_MSG_ERROR,
4957 "iwpriv mcs failed");
4958 }
4959
4960 switch (nss) {
4961 case 1:
4962 switch (mcs) {
4963 case 7:
4964 vht_mcsmap = 0xfffc;
4965 break;
4966 case 8:
4967 vht_mcsmap = 0xfffd;
4968 break;
4969 case 9:
4970 vht_mcsmap = 0xfffe;
4971 break;
4972 default:
4973 vht_mcsmap = 0xfffe;
4974 break;
4975 }
4976 break;
4977 case 2:
4978 switch (mcs) {
4979 case 7:
4980 vht_mcsmap = 0xfff0;
4981 break;
4982 case 8:
4983 vht_mcsmap = 0xfff5;
4984 break;
4985 case 9:
4986 vht_mcsmap = 0xfffa;
4987 break;
4988 default:
4989 vht_mcsmap = 0xfffa;
4990 break;
4991 }
4992 break;
4993 case 3:
4994 switch (mcs) {
4995 case 7:
4996 vht_mcsmap = 0xffc0;
4997 break;
4998 case 8:
4999 vht_mcsmap = 0xffd5;
5000 break;
5001 case 9:
5002 vht_mcsmap = 0xffea;
5003 break;
5004 default:
5005 vht_mcsmap = 0xffea;
5006 break;
5007 }
5008 break;
5009 default:
5010 vht_mcsmap = 0xffea;
5011 break;
5012 }
5013 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
5014 intf, vht_mcsmap);
5015 if (system(buf) != 0) {
5016 sigma_dut_print(dut, DUT_MSG_ERROR,
5017 "iwpriv vht_mcsmap failed");
5018 }
5019 }
5020
5021 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
5022
5023 val = get_param(cmd, "Vht_tkip");
5024 if (val)
5025 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5026
5027 val = get_param(cmd, "Vht_wep");
5028 if (val)
5029 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5030
5031 if (tkip != -1 || wep != -1) {
5032 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
5033 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
5034 intf);
5035 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
5036 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
5037 intf);
5038 } else {
5039 sigma_dut_print(dut, DUT_MSG_ERROR,
5040 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
5041 return 0;
5042 }
5043
5044 if (system(buf) != 0) {
5045 sigma_dut_print(dut, DUT_MSG_ERROR,
5046 "iwpriv htweptkip failed");
5047 }
5048 }
5049
5050 val = get_param(cmd, "txBandwidth");
5051 if (val) {
5052 switch (get_driver_type()) {
5053 case DRIVER_ATHEROS:
5054 if (ath_set_width(dut, conn, intf, val) < 0) {
5055 send_resp(dut, conn, SIGMA_ERROR,
5056 "ErrorCode,Failed to set txBandwidth");
5057 return 0;
5058 }
5059 break;
5060 default:
5061 sigma_dut_print(dut, DUT_MSG_ERROR,
5062 "Setting txBandwidth not supported");
5063 break;
5064 }
5065 }
5066
5067 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
5068}
5069
5070
5071static int sta_set_wireless_60g(struct sigma_dut *dut,
5072 struct sigma_conn *conn,
5073 struct sigma_cmd *cmd)
5074{
5075 const char *dev_role = get_param(cmd, "DevRole");
5076
5077 if (!dev_role) {
5078 send_resp(dut, conn, SIGMA_INVALID,
5079 "ErrorCode,DevRole not specified");
5080 return 0;
5081 }
5082
5083 if (strcasecmp(dev_role, "PCP") == 0)
5084 return sta_set_60g_pcp(dut, conn, cmd);
5085 if (strcasecmp(dev_role, "STA") == 0)
5086 return sta_set_60g_sta(dut, conn, cmd);
5087 send_resp(dut, conn, SIGMA_INVALID,
5088 "ErrorCode,DevRole not supported");
5089 return 0;
5090}
5091
5092
5093static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
5094 struct sigma_cmd *cmd)
5095{
5096 const char *val;
5097
5098 val = get_param(cmd, "Program");
5099 if (val) {
5100 if (strcasecmp(val, "11n") == 0)
5101 return cmd_sta_set_11n(dut, conn, cmd);
5102 if (strcasecmp(val, "VHT") == 0)
5103 return cmd_sta_set_wireless_vht(dut, conn, cmd);
5104 if (strcasecmp(val, "60ghz") == 0)
5105 return sta_set_wireless_60g(dut, conn, cmd);
5106 send_resp(dut, conn, SIGMA_ERROR,
5107 "ErrorCode,Program value not supported");
5108 } else {
5109 send_resp(dut, conn, SIGMA_ERROR,
5110 "ErrorCode,Program argument not available");
5111 }
5112
5113 return 0;
5114}
5115
5116
5117static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
5118 int tid)
5119{
5120 char buf[100];
5121 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
5122
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05305123 if (tid < 0 ||
5124 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
5125 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
5126 return;
5127 }
5128
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005129 /*
5130 * Two ways to ensure that addba request with a
5131 * non zero TID could be sent out. EV 117296
5132 */
5133 snprintf(buf, sizeof(buf),
5134 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
5135 tid);
5136 if (system(buf) != 0) {
5137 sigma_dut_print(dut, DUT_MSG_ERROR,
5138 "Ping did not send out");
5139 }
5140
5141 snprintf(buf, sizeof(buf),
5142 "iwconfig %s | grep Access | awk '{print $6}' > %s",
5143 intf, VI_QOS_TMP_FILE);
5144 if (system(buf) != 0)
5145 return;
5146
5147 snprintf(buf, sizeof(buf),
5148 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
5149 intf, VI_QOS_TMP_FILE);
5150 if (system(buf) != 0)
5151 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
5152
5153 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
5154 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
5155 if (system(buf) != 0) {
5156 sigma_dut_print(dut, DUT_MSG_ERROR,
5157 "VI_QOS_TEMP_FILE generation error failed");
5158 }
5159 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
5160 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
5161 if (system(buf) != 0) {
5162 sigma_dut_print(dut, DUT_MSG_ERROR,
5163 "VI_QOS_FILE generation failed");
5164 }
5165
5166 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
5167 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
5168 if (system(buf) != 0) {
5169 sigma_dut_print(dut, DUT_MSG_ERROR,
5170 "VI_QOS_FILE generation failed");
5171 }
5172
5173 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
5174 if (system(buf) != 0) {
5175 }
5176}
5177
5178
5179static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
5180 struct sigma_cmd *cmd)
5181{
5182 const char *intf = get_param(cmd, "Interface");
5183 const char *val;
5184 int tid = 0;
5185 char buf[100];
5186
5187 val = get_param(cmd, "TID");
5188 if (val) {
5189 tid = atoi(val);
5190 if (tid)
5191 ath_sta_inject_frame(dut, intf, tid);
5192 }
5193
5194 /* Command sequence for ADDBA request on Peregrine based devices */
5195 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
5196 if (system(buf) != 0) {
5197 sigma_dut_print(dut, DUT_MSG_ERROR,
5198 "iwpriv setaddbaoper failed");
5199 }
5200
5201 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
5202 if (system(buf) != 0) {
5203 sigma_dut_print(dut, DUT_MSG_ERROR,
5204 "wifitool senddelba failed");
5205 }
5206
5207 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
5208 if (system(buf) != 0) {
5209 sigma_dut_print(dut, DUT_MSG_ERROR,
5210 "wifitool sendaddba failed");
5211 }
5212
5213 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
5214
5215 return 1;
5216}
5217
5218
Lior David9981b512017-01-20 13:16:40 +02005219#ifdef __linux__
5220
5221static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
5222 int agg_size)
5223{
5224 char dir[128], buf[128];
5225 FILE *f;
5226 regex_t re;
5227 regmatch_t m[2];
5228 int rc, ret = -1, vring_id, found;
5229
5230 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
5231 sigma_dut_print(dut, DUT_MSG_ERROR,
5232 "failed to get wil6210 debugfs dir");
5233 return -1;
5234 }
5235
5236 snprintf(buf, sizeof(buf), "%s/vrings", dir);
5237 f = fopen(buf, "r");
5238 if (!f) {
5239 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
5240 return -1;
5241 }
5242
5243 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
5244 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
5245 goto out;
5246 }
5247
5248 /* find TX VRING for the mac address */
5249 found = 0;
5250 while (fgets(buf, sizeof(buf), f)) {
5251 if (strcasestr(buf, dest_mac)) {
5252 found = 1;
5253 break;
5254 }
5255 }
5256
5257 if (!found) {
5258 sigma_dut_print(dut, DUT_MSG_ERROR,
5259 "no TX VRING for %s", dest_mac);
5260 goto out;
5261 }
5262
5263 /* extract VRING ID, "VRING tx_<id> = {" */
5264 if (!fgets(buf, sizeof(buf), f)) {
5265 sigma_dut_print(dut, DUT_MSG_ERROR,
5266 "no VRING start line for %s", dest_mac);
5267 goto out;
5268 }
5269
5270 rc = regexec(&re, buf, 2, m, 0);
5271 regfree(&re);
5272 if (rc || m[1].rm_so < 0) {
5273 sigma_dut_print(dut, DUT_MSG_ERROR,
5274 "no VRING TX ID for %s", dest_mac);
5275 goto out;
5276 }
5277 buf[m[1].rm_eo] = 0;
5278 vring_id = atoi(&buf[m[1].rm_so]);
5279
5280 /* send the addba command */
5281 fclose(f);
5282 snprintf(buf, sizeof(buf), "%s/back", dir);
5283 f = fopen(buf, "w");
5284 if (!f) {
5285 sigma_dut_print(dut, DUT_MSG_ERROR,
5286 "failed to open: %s", buf);
5287 return -1;
5288 }
5289
5290 fprintf(f, "add %d %d\n", vring_id, agg_size);
5291
5292 ret = 0;
5293
5294out:
5295 fclose(f);
5296
5297 return ret;
5298}
5299
5300
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005301static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5302 struct sigma_cmd *cmd)
5303{
5304 const char *val;
5305 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005306
5307 val = get_param(cmd, "TID");
5308 if (val) {
5309 tid = atoi(val);
5310 if (tid != 0) {
5311 sigma_dut_print(dut, DUT_MSG_ERROR,
5312 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
5313 tid);
5314 }
5315 }
5316
5317 val = get_param(cmd, "Dest_mac");
5318 if (!val) {
5319 sigma_dut_print(dut, DUT_MSG_ERROR,
5320 "Currently not supporting addba for 60G without Dest_mac");
5321 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5322 }
5323
Lior David9981b512017-01-20 13:16:40 +02005324 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005325 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005326
5327 return 1;
5328}
5329
Lior David9981b512017-01-20 13:16:40 +02005330#endif /* __linux__ */
5331
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005332
5333static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
5334 struct sigma_cmd *cmd)
5335{
5336 switch (get_driver_type()) {
5337 case DRIVER_ATHEROS:
5338 return ath_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02005339#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005340 case DRIVER_WIL6210:
5341 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02005342#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005343 default:
5344 /*
5345 * There is no driver specific implementation for other drivers.
5346 * Ignore the command and report COMPLETE since the following
5347 * throughput test operation will end up sending ADDBA anyway.
5348 */
5349 return 1;
5350 }
5351}
5352
5353
5354int inject_eth_frame(int s, const void *data, size_t len,
5355 unsigned short ethtype, char *dst, char *src)
5356{
5357 struct iovec iov[4] = {
5358 {
5359 .iov_base = dst,
5360 .iov_len = ETH_ALEN,
5361 },
5362 {
5363 .iov_base = src,
5364 .iov_len = ETH_ALEN,
5365 },
5366 {
5367 .iov_base = &ethtype,
5368 .iov_len = sizeof(unsigned short),
5369 },
5370 {
5371 .iov_base = (void *) data,
5372 .iov_len = len,
5373 }
5374 };
5375 struct msghdr msg = {
5376 .msg_name = NULL,
5377 .msg_namelen = 0,
5378 .msg_iov = iov,
5379 .msg_iovlen = 4,
5380 .msg_control = NULL,
5381 .msg_controllen = 0,
5382 .msg_flags = 0,
5383 };
5384
5385 return sendmsg(s, &msg, 0);
5386}
5387
5388#if defined(__linux__) || defined(__QNXNTO__)
5389
5390int inject_frame(int s, const void *data, size_t len, int encrypt)
5391{
5392#define IEEE80211_RADIOTAP_F_WEP 0x04
5393#define IEEE80211_RADIOTAP_F_FRAG 0x08
5394 unsigned char rtap_hdr[] = {
5395 0x00, 0x00, /* radiotap version */
5396 0x0e, 0x00, /* radiotap length */
5397 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
5398 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
5399 0x00, /* padding */
5400 0x00, 0x00, /* RX and TX flags to indicate that */
5401 0x00, 0x00, /* this is the injected frame directly */
5402 };
5403 struct iovec iov[2] = {
5404 {
5405 .iov_base = &rtap_hdr,
5406 .iov_len = sizeof(rtap_hdr),
5407 },
5408 {
5409 .iov_base = (void *) data,
5410 .iov_len = len,
5411 }
5412 };
5413 struct msghdr msg = {
5414 .msg_name = NULL,
5415 .msg_namelen = 0,
5416 .msg_iov = iov,
5417 .msg_iovlen = 2,
5418 .msg_control = NULL,
5419 .msg_controllen = 0,
5420 .msg_flags = 0,
5421 };
5422
5423 if (encrypt)
5424 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
5425
5426 return sendmsg(s, &msg, 0);
5427}
5428
5429
5430int open_monitor(const char *ifname)
5431{
5432#ifdef __QNXNTO__
5433 struct sockaddr_dl ll;
5434 int s;
5435
5436 memset(&ll, 0, sizeof(ll));
5437 ll.sdl_family = AF_LINK;
5438 ll.sdl_index = if_nametoindex(ifname);
5439 if (ll.sdl_index == 0) {
5440 perror("if_nametoindex");
5441 return -1;
5442 }
5443 s = socket(PF_INET, SOCK_RAW, 0);
5444#else /* __QNXNTO__ */
5445 struct sockaddr_ll ll;
5446 int s;
5447
5448 memset(&ll, 0, sizeof(ll));
5449 ll.sll_family = AF_PACKET;
5450 ll.sll_ifindex = if_nametoindex(ifname);
5451 if (ll.sll_ifindex == 0) {
5452 perror("if_nametoindex");
5453 return -1;
5454 }
5455 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
5456#endif /* __QNXNTO__ */
5457 if (s < 0) {
5458 perror("socket[PF_PACKET,SOCK_RAW]");
5459 return -1;
5460 }
5461
5462 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
5463 perror("monitor socket bind");
5464 close(s);
5465 return -1;
5466 }
5467
5468 return s;
5469}
5470
5471
5472static int hex2num(char c)
5473{
5474 if (c >= '0' && c <= '9')
5475 return c - '0';
5476 if (c >= 'a' && c <= 'f')
5477 return c - 'a' + 10;
5478 if (c >= 'A' && c <= 'F')
5479 return c - 'A' + 10;
5480 return -1;
5481}
5482
5483
5484int hwaddr_aton(const char *txt, unsigned char *addr)
5485{
5486 int i;
5487
5488 for (i = 0; i < 6; i++) {
5489 int a, b;
5490
5491 a = hex2num(*txt++);
5492 if (a < 0)
5493 return -1;
5494 b = hex2num(*txt++);
5495 if (b < 0)
5496 return -1;
5497 *addr++ = (a << 4) | b;
5498 if (i < 5 && *txt++ != ':')
5499 return -1;
5500 }
5501
5502 return 0;
5503}
5504
5505#endif /* defined(__linux__) || defined(__QNXNTO__) */
5506
5507enum send_frame_type {
5508 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
5509};
5510enum send_frame_protection {
5511 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
5512};
5513
5514
5515static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
5516 enum send_frame_type frame,
5517 enum send_frame_protection protected,
5518 const char *dest)
5519{
5520#ifdef __linux__
5521 unsigned char buf[1000], *pos;
5522 int s, res;
5523 char bssid[20], addr[20];
5524 char result[32], ssid[100];
5525 size_t ssid_len;
5526
5527 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5528 sizeof(result)) < 0 ||
5529 strncmp(result, "COMPLETED", 9) != 0) {
5530 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
5531 return 0;
5532 }
5533
5534 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
5535 < 0) {
5536 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
5537 "current BSSID");
5538 return 0;
5539 }
5540
5541 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
5542 < 0) {
5543 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
5544 "own MAC address");
5545 return 0;
5546 }
5547
5548 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
5549 < 0) {
5550 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
5551 "current SSID");
5552 return 0;
5553 }
5554 ssid_len = strlen(ssid);
5555
5556 pos = buf;
5557
5558 /* Frame Control */
5559 switch (frame) {
5560 case DISASSOC:
5561 *pos++ = 0xa0;
5562 break;
5563 case DEAUTH:
5564 *pos++ = 0xc0;
5565 break;
5566 case SAQUERY:
5567 *pos++ = 0xd0;
5568 break;
5569 case AUTH:
5570 *pos++ = 0xb0;
5571 break;
5572 case ASSOCREQ:
5573 *pos++ = 0x00;
5574 break;
5575 case REASSOCREQ:
5576 *pos++ = 0x20;
5577 break;
5578 case DLS_REQ:
5579 *pos++ = 0xd0;
5580 break;
5581 }
5582
5583 if (protected == INCORRECT_KEY)
5584 *pos++ = 0x40; /* Set Protected field to 1 */
5585 else
5586 *pos++ = 0x00;
5587
5588 /* Duration */
5589 *pos++ = 0x00;
5590 *pos++ = 0x00;
5591
5592 /* addr1 = DA (current AP) */
5593 hwaddr_aton(bssid, pos);
5594 pos += 6;
5595 /* addr2 = SA (own address) */
5596 hwaddr_aton(addr, pos);
5597 pos += 6;
5598 /* addr3 = BSSID (current AP) */
5599 hwaddr_aton(bssid, pos);
5600 pos += 6;
5601
5602 /* Seq# (to be filled by driver/mac80211) */
5603 *pos++ = 0x00;
5604 *pos++ = 0x00;
5605
5606 if (protected == INCORRECT_KEY) {
5607 /* CCMP parameters */
5608 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
5609 pos += 8;
5610 }
5611
5612 if (protected == INCORRECT_KEY) {
5613 switch (frame) {
5614 case DEAUTH:
5615 /* Reason code (encrypted) */
5616 memcpy(pos, "\xa7\x39", 2);
5617 pos += 2;
5618 break;
5619 case DISASSOC:
5620 /* Reason code (encrypted) */
5621 memcpy(pos, "\xa7\x39", 2);
5622 pos += 2;
5623 break;
5624 case SAQUERY:
5625 /* Category|Action|TransID (encrypted) */
5626 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
5627 pos += 4;
5628 break;
5629 default:
5630 return -1;
5631 }
5632
5633 /* CCMP MIC */
5634 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
5635 pos += 8;
5636 } else {
5637 switch (frame) {
5638 case DEAUTH:
5639 /* reason code = 8 */
5640 *pos++ = 0x08;
5641 *pos++ = 0x00;
5642 break;
5643 case DISASSOC:
5644 /* reason code = 8 */
5645 *pos++ = 0x08;
5646 *pos++ = 0x00;
5647 break;
5648 case SAQUERY:
5649 /* Category - SA Query */
5650 *pos++ = 0x08;
5651 /* SA query Action - Request */
5652 *pos++ = 0x00;
5653 /* Transaction ID */
5654 *pos++ = 0x12;
5655 *pos++ = 0x34;
5656 break;
5657 case AUTH:
5658 /* Auth Alg (Open) */
5659 *pos++ = 0x00;
5660 *pos++ = 0x00;
5661 /* Seq# */
5662 *pos++ = 0x01;
5663 *pos++ = 0x00;
5664 /* Status code */
5665 *pos++ = 0x00;
5666 *pos++ = 0x00;
5667 break;
5668 case ASSOCREQ:
5669 /* Capability Information */
5670 *pos++ = 0x31;
5671 *pos++ = 0x04;
5672 /* Listen Interval */
5673 *pos++ = 0x0a;
5674 *pos++ = 0x00;
5675 /* SSID */
5676 *pos++ = 0x00;
5677 *pos++ = ssid_len;
5678 memcpy(pos, ssid, ssid_len);
5679 pos += ssid_len;
5680 /* Supported Rates */
5681 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
5682 10);
5683 pos += 10;
5684 /* Extended Supported Rates */
5685 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
5686 pos += 6;
5687 /* RSN */
5688 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
5689 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
5690 "\x00\x00\x00\x00\x0f\xac\x06", 28);
5691 pos += 28;
5692 break;
5693 case REASSOCREQ:
5694 /* Capability Information */
5695 *pos++ = 0x31;
5696 *pos++ = 0x04;
5697 /* Listen Interval */
5698 *pos++ = 0x0a;
5699 *pos++ = 0x00;
5700 /* Current AP */
5701 hwaddr_aton(bssid, pos);
5702 pos += 6;
5703 /* SSID */
5704 *pos++ = 0x00;
5705 *pos++ = ssid_len;
5706 memcpy(pos, ssid, ssid_len);
5707 pos += ssid_len;
5708 /* Supported Rates */
5709 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
5710 10);
5711 pos += 10;
5712 /* Extended Supported Rates */
5713 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
5714 pos += 6;
5715 /* RSN */
5716 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
5717 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
5718 "\x00\x00\x00\x00\x0f\xac\x06", 28);
5719 pos += 28;
5720 break;
5721 case DLS_REQ:
5722 /* Category - DLS */
5723 *pos++ = 0x02;
5724 /* DLS Action - Request */
5725 *pos++ = 0x00;
5726 /* Destination MACAddress */
5727 if (dest)
5728 hwaddr_aton(dest, pos);
5729 else
5730 memset(pos, 0, 6);
5731 pos += 6;
5732 /* Source MACAddress */
5733 hwaddr_aton(addr, pos);
5734 pos += 6;
5735 /* Capability Information */
5736 *pos++ = 0x10; /* Privacy */
5737 *pos++ = 0x06; /* QoS */
5738 /* DLS Timeout Value */
5739 *pos++ = 0x00;
5740 *pos++ = 0x01;
5741 /* Supported rates */
5742 *pos++ = 0x01;
5743 *pos++ = 0x08;
5744 *pos++ = 0x0c; /* 6 Mbps */
5745 *pos++ = 0x12; /* 9 Mbps */
5746 *pos++ = 0x18; /* 12 Mbps */
5747 *pos++ = 0x24; /* 18 Mbps */
5748 *pos++ = 0x30; /* 24 Mbps */
5749 *pos++ = 0x48; /* 36 Mbps */
5750 *pos++ = 0x60; /* 48 Mbps */
5751 *pos++ = 0x6c; /* 54 Mbps */
5752 /* TODO: Extended Supported Rates */
5753 /* TODO: HT Capabilities */
5754 break;
5755 }
5756 }
5757
5758 s = open_monitor("sigmadut");
5759 if (s < 0) {
5760 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
5761 "monitor socket");
5762 return 0;
5763 }
5764
5765 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
5766 if (res < 0) {
5767 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5768 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305769 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005770 return 0;
5771 }
5772 if (res < pos - buf) {
5773 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
5774 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305775 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005776 return 0;
5777 }
5778
5779 close(s);
5780
5781 return 1;
5782#else /* __linux__ */
5783 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
5784 "yet supported");
5785 return 0;
5786#endif /* __linux__ */
5787}
5788
5789
5790static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
5791 struct sigma_conn *conn,
5792 struct sigma_cmd *cmd)
5793{
5794 const char *intf = get_param(cmd, "Interface");
5795 const char *sta, *val;
5796 unsigned char addr[ETH_ALEN];
5797 char buf[100];
5798
5799 sta = get_param(cmd, "peer");
5800 if (sta == NULL)
5801 sta = get_param(cmd, "station");
5802 if (sta == NULL) {
5803 send_resp(dut, conn, SIGMA_ERROR,
5804 "ErrorCode,Missing peer address");
5805 return 0;
5806 }
5807 if (hwaddr_aton(sta, addr) < 0) {
5808 send_resp(dut, conn, SIGMA_ERROR,
5809 "ErrorCode,Invalid peer address");
5810 return 0;
5811 }
5812
5813 val = get_param(cmd, "type");
5814 if (val == NULL)
5815 return -1;
5816
5817 if (strcasecmp(val, "DISCOVERY") == 0) {
5818 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
5819 if (wpa_command(intf, buf) < 0) {
5820 send_resp(dut, conn, SIGMA_ERROR,
5821 "ErrorCode,Failed to send TDLS discovery");
5822 return 0;
5823 }
5824 return 1;
5825 }
5826
5827 if (strcasecmp(val, "SETUP") == 0) {
5828 int status = 0, timeout = 0;
5829
5830 val = get_param(cmd, "Status");
5831 if (val)
5832 status = atoi(val);
5833
5834 val = get_param(cmd, "Timeout");
5835 if (val)
5836 timeout = atoi(val);
5837
5838 if (status != 0 && status != 37) {
5839 send_resp(dut, conn, SIGMA_ERROR,
5840 "ErrorCode,Unsupported status value");
5841 return 0;
5842 }
5843
5844 if (timeout != 0 && timeout != 301) {
5845 send_resp(dut, conn, SIGMA_ERROR,
5846 "ErrorCode,Unsupported timeout value");
5847 return 0;
5848 }
5849
5850 if (status && timeout) {
5851 send_resp(dut, conn, SIGMA_ERROR,
5852 "ErrorCode,Unsupported timeout+status "
5853 "combination");
5854 return 0;
5855 }
5856
5857 if (status == 37 &&
5858 wpa_command(intf, "SET tdls_testing 0x200")) {
5859 send_resp(dut, conn, SIGMA_ERROR,
5860 "ErrorCode,Failed to enable "
5861 "decline setup response test mode");
5862 return 0;
5863 }
5864
5865 if (timeout == 301) {
5866 int res;
5867 if (dut->no_tpk_expiration)
5868 res = wpa_command(intf,
5869 "SET tdls_testing 0x108");
5870 else
5871 res = wpa_command(intf,
5872 "SET tdls_testing 0x8");
5873 if (res) {
5874 send_resp(dut, conn, SIGMA_ERROR,
5875 "ErrorCode,Failed to set short TPK "
5876 "lifetime");
5877 return 0;
5878 }
5879 }
5880
5881 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
5882 if (wpa_command(intf, buf) < 0) {
5883 send_resp(dut, conn, SIGMA_ERROR,
5884 "ErrorCode,Failed to send TDLS setup");
5885 return 0;
5886 }
5887 return 1;
5888 }
5889
5890 if (strcasecmp(val, "TEARDOWN") == 0) {
5891 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
5892 if (wpa_command(intf, buf) < 0) {
5893 send_resp(dut, conn, SIGMA_ERROR,
5894 "ErrorCode,Failed to send TDLS teardown");
5895 return 0;
5896 }
5897 return 1;
5898 }
5899
5900 send_resp(dut, conn, SIGMA_ERROR,
5901 "ErrorCode,Unsupported TDLS frame");
5902 return 0;
5903}
5904
5905
5906static int sta_ap_known(const char *ifname, const char *bssid)
5907{
5908 char buf[4096];
5909
5910 snprintf(buf, sizeof(buf), "BSS %s", bssid);
5911 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
5912 return 0;
5913 if (strncmp(buf, "id=", 3) != 0)
5914 return 0;
5915 return 1;
5916}
5917
5918
5919static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
5920 const char *bssid)
5921{
5922 int res;
5923 struct wpa_ctrl *ctrl;
5924 char buf[256];
5925
5926 if (sta_ap_known(ifname, bssid))
5927 return 0;
5928 sigma_dut_print(dut, DUT_MSG_DEBUG,
5929 "AP not in BSS table - start scan");
5930
5931 ctrl = open_wpa_mon(ifname);
5932 if (ctrl == NULL) {
5933 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
5934 "wpa_supplicant monitor connection");
5935 return -1;
5936 }
5937
5938 if (wpa_command(ifname, "SCAN") < 0) {
5939 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
5940 wpa_ctrl_detach(ctrl);
5941 wpa_ctrl_close(ctrl);
5942 return -1;
5943 }
5944
5945 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
5946 buf, sizeof(buf));
5947
5948 wpa_ctrl_detach(ctrl);
5949 wpa_ctrl_close(ctrl);
5950
5951 if (res < 0) {
5952 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
5953 return -1;
5954 }
5955
5956 if (sta_ap_known(ifname, bssid))
5957 return 0;
5958 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
5959 return -1;
5960}
5961
5962
5963static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
5964 struct sigma_conn *conn,
5965 struct sigma_cmd *cmd,
5966 const char *intf)
5967{
5968 char buf[200];
5969
5970 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
5971 if (system(buf) != 0) {
5972 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
5973 "ndsend");
5974 return 0;
5975 }
5976
5977 return 1;
5978}
5979
5980
5981static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
5982 struct sigma_conn *conn,
5983 struct sigma_cmd *cmd,
5984 const char *intf)
5985{
5986 char buf[200];
5987 const char *ip = get_param(cmd, "SenderIP");
5988
5989 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
5990 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
5991 if (system(buf) == 0) {
5992 sigma_dut_print(dut, DUT_MSG_INFO,
5993 "Neighbor Solicitation got a response "
5994 "for %s@%s", ip, intf);
5995 }
5996
5997 return 1;
5998}
5999
6000
6001static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
6002 struct sigma_conn *conn,
6003 struct sigma_cmd *cmd,
6004 const char *ifname)
6005{
6006 char buf[200];
6007 const char *ip = get_param(cmd, "SenderIP");
6008
6009 if (ip == NULL) {
6010 send_resp(dut, conn, SIGMA_ERROR,
6011 "ErrorCode,Missing SenderIP parameter");
6012 return 0;
6013 }
6014 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
6015 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6016 if (system(buf) != 0) {
6017 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
6018 "for %s@%s", ip, ifname);
6019 }
6020
6021 return 1;
6022}
6023
6024
6025static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
6026 struct sigma_conn *conn,
6027 struct sigma_cmd *cmd,
6028 const char *ifname)
6029{
6030 char buf[200];
6031 char ip[16];
6032 int s;
6033
6034 s = socket(PF_INET, SOCK_DGRAM, 0);
6035 if (s >= 0) {
6036 struct ifreq ifr;
6037 struct sockaddr_in saddr;
6038
6039 memset(&ifr, 0, sizeof(ifr));
6040 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
6041 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
6042 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
6043 "%s IP address: %s",
6044 ifname, strerror(errno));
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306045 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006046 return -1;
6047 } else {
6048 memcpy(&saddr, &ifr.ifr_addr,
6049 sizeof(struct sockaddr_in));
6050 strncpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
6051 }
6052 close(s);
6053
6054 }
6055
6056 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
6057 ip);
6058 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6059 if (system(buf) != 0) {
6060 }
6061
6062 return 1;
6063}
6064
6065
6066static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
6067 struct sigma_conn *conn,
6068 struct sigma_cmd *cmd,
6069 const char *ifname)
6070{
6071 char buf[200], addr[20];
6072 char dst[ETH_ALEN], src[ETH_ALEN];
6073 short ethtype = htons(ETH_P_ARP);
6074 char *pos;
6075 int s, res;
6076 const char *val;
6077 struct sockaddr_in taddr;
6078
6079 val = get_param(cmd, "dest");
6080 if (val)
6081 hwaddr_aton(val, (unsigned char *) dst);
6082
6083 val = get_param(cmd, "DestIP");
6084 if (val)
6085 inet_aton(val, &taddr.sin_addr);
6086
6087 if (get_wpa_status(get_station_ifname(), "address", addr,
6088 sizeof(addr)) < 0)
6089 return -2;
6090 hwaddr_aton(addr, (unsigned char *) src);
6091
6092 pos = buf;
6093 *pos++ = 0x00;
6094 *pos++ = 0x01;
6095 *pos++ = 0x08;
6096 *pos++ = 0x00;
6097 *pos++ = 0x06;
6098 *pos++ = 0x04;
6099 *pos++ = 0x00;
6100 *pos++ = 0x02;
6101 memcpy(pos, src, ETH_ALEN);
6102 pos += ETH_ALEN;
6103 memcpy(pos, &taddr.sin_addr, 4);
6104 pos += 4;
6105 memcpy(pos, dst, ETH_ALEN);
6106 pos += ETH_ALEN;
6107 memcpy(pos, &taddr.sin_addr, 4);
6108 pos += 4;
6109
6110 s = open_monitor(get_station_ifname());
6111 if (s < 0) {
6112 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
6113 "monitor socket");
6114 return 0;
6115 }
6116
6117 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
6118 if (res < 0) {
6119 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6120 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306121 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006122 return 0;
6123 }
6124
6125 close(s);
6126
6127 return 1;
6128}
6129
6130
6131static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
6132 struct sigma_conn *conn,
6133 struct sigma_cmd *cmd,
6134 const char *intf, const char *dest)
6135{
6136 char buf[100];
6137
6138 if (if_nametoindex("sigmadut") == 0) {
6139 snprintf(buf, sizeof(buf),
6140 "iw dev %s interface add sigmadut type monitor",
6141 get_station_ifname());
6142 if (system(buf) != 0 ||
6143 if_nametoindex("sigmadut") == 0) {
6144 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
6145 "monitor interface with '%s'", buf);
6146 return -2;
6147 }
6148 }
6149
6150 if (system("ifconfig sigmadut up") != 0) {
6151 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6152 "monitor interface up");
6153 return -2;
6154 }
6155
6156 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
6157}
6158
6159
6160static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
6161 struct sigma_conn *conn,
6162 struct sigma_cmd *cmd)
6163{
6164 const char *intf = get_param(cmd, "Interface");
6165 const char *dest = get_param(cmd, "Dest");
6166 const char *type = get_param(cmd, "FrameName");
6167 const char *val;
6168 char buf[200], *pos, *end;
6169 int count, count2;
6170
6171 if (type == NULL)
6172 type = get_param(cmd, "Type");
6173
6174 if (intf == NULL || dest == NULL || type == NULL)
6175 return -1;
6176
6177 if (strcasecmp(type, "NeighAdv") == 0)
6178 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
6179
6180 if (strcasecmp(type, "NeighSolicitReq") == 0)
6181 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
6182
6183 if (strcasecmp(type, "ARPProbe") == 0)
6184 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
6185
6186 if (strcasecmp(type, "ARPAnnounce") == 0)
6187 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
6188
6189 if (strcasecmp(type, "ARPReply") == 0)
6190 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
6191
6192 if (strcasecmp(type, "DLS-request") == 0 ||
6193 strcasecmp(type, "DLSrequest") == 0)
6194 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
6195 dest);
6196
6197 if (strcasecmp(type, "ANQPQuery") != 0 &&
6198 strcasecmp(type, "Query") != 0) {
6199 send_resp(dut, conn, SIGMA_ERROR,
6200 "ErrorCode,Unsupported HS 2.0 send frame type");
6201 return 0;
6202 }
6203
6204 if (sta_scan_ap(dut, intf, dest) < 0) {
6205 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
6206 "the requested AP");
6207 return 0;
6208 }
6209
6210 pos = buf;
6211 end = buf + sizeof(buf);
6212 count = 0;
6213 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
6214
6215 val = get_param(cmd, "ANQP_CAP_LIST");
6216 if (val && atoi(val)) {
6217 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
6218 count++;
6219 }
6220
6221 val = get_param(cmd, "VENUE_NAME");
6222 if (val && atoi(val)) {
6223 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
6224 count++;
6225 }
6226
6227 val = get_param(cmd, "NETWORK_AUTH_TYPE");
6228 if (val && atoi(val)) {
6229 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
6230 count++;
6231 }
6232
6233 val = get_param(cmd, "ROAMING_CONS");
6234 if (val && atoi(val)) {
6235 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
6236 count++;
6237 }
6238
6239 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
6240 if (val && atoi(val)) {
6241 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
6242 count++;
6243 }
6244
6245 val = get_param(cmd, "NAI_REALM_LIST");
6246 if (val && atoi(val)) {
6247 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
6248 count++;
6249 }
6250
6251 val = get_param(cmd, "3GPP_INFO");
6252 if (val && atoi(val)) {
6253 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
6254 count++;
6255 }
6256
6257 val = get_param(cmd, "DOMAIN_LIST");
6258 if (val && atoi(val)) {
6259 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
6260 count++;
6261 }
6262
6263 if (count && wpa_command(intf, buf)) {
6264 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
6265 return 0;
6266 }
6267
6268 pos = buf;
6269 end = buf + sizeof(buf);
6270 count2 = 0;
6271 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
6272
6273 val = get_param(cmd, "HS_CAP_LIST");
6274 if (val && atoi(val)) {
6275 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
6276 count2++;
6277 }
6278
6279 val = get_param(cmd, "OPER_NAME");
6280 if (val && atoi(val)) {
6281 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
6282 count2++;
6283 }
6284
6285 val = get_param(cmd, "WAN_METRICS");
6286 if (!val)
6287 val = get_param(cmd, "WAN_MAT");
6288 if (!val)
6289 val = get_param(cmd, "WAN_MET");
6290 if (val && atoi(val)) {
6291 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
6292 count2++;
6293 }
6294
6295 val = get_param(cmd, "CONNECTION_CAPABILITY");
6296 if (val && atoi(val)) {
6297 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
6298 count2++;
6299 }
6300
6301 val = get_param(cmd, "OP_CLASS");
6302 if (val && atoi(val)) {
6303 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
6304 count2++;
6305 }
6306
6307 val = get_param(cmd, "OSU_PROVIDER_LIST");
6308 if (val && atoi(val)) {
6309 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
6310 count2++;
6311 }
6312
6313 if (count && count2) {
6314 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
6315 "second query");
6316 sleep(1);
6317 }
6318
6319 if (count2 && wpa_command(intf, buf)) {
6320 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
6321 "failed");
6322 return 0;
6323 }
6324
6325 val = get_param(cmd, "NAI_HOME_REALM_LIST");
6326 if (val) {
6327 if (count || count2) {
6328 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
6329 "sending out second query");
6330 sleep(1);
6331 }
6332
6333 if (strcmp(val, "1") == 0)
6334 val = "mail.example.com";
6335 snprintf(buf, end - pos,
6336 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
6337 dest, val);
6338 if (wpa_command(intf, buf)) {
6339 send_resp(dut, conn, SIGMA_ERROR,
6340 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
6341 "failed");
6342 return 0;
6343 }
6344 }
6345
6346 val = get_param(cmd, "ICON_REQUEST");
6347 if (val) {
6348 if (count || count2) {
6349 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
6350 "sending out second query");
6351 sleep(1);
6352 }
6353
6354 snprintf(buf, end - pos,
6355 "HS20_ICON_REQUEST %s %s", dest, val);
6356 if (wpa_command(intf, buf)) {
6357 send_resp(dut, conn, SIGMA_ERROR,
6358 "ErrorCode,HS20_ICON_REQUEST failed");
6359 return 0;
6360 }
6361 }
6362
6363 return 1;
6364}
6365
6366
6367static int ath_sta_send_frame_vht(struct sigma_dut *dut,
6368 struct sigma_conn *conn,
6369 struct sigma_cmd *cmd)
6370{
6371 const char *val;
6372 char *ifname;
6373 char buf[100];
6374 int chwidth, nss;
6375
6376 val = get_param(cmd, "framename");
6377 if (!val)
6378 return -1;
6379 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
6380
6381 /* Command sequence to generate Op mode notification */
6382 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
6383 ifname = get_station_ifname();
6384
6385 /* Disable STBC */
6386 snprintf(buf, sizeof(buf),
6387 "iwpriv %s tx_stbc 0", ifname);
6388 if (system(buf) != 0) {
6389 sigma_dut_print(dut, DUT_MSG_ERROR,
6390 "iwpriv tx_stbc 0 failed!");
6391 }
6392
6393 /* Extract Channel width */
6394 val = get_param(cmd, "Channel_width");
6395 if (val) {
6396 switch (atoi(val)) {
6397 case 20:
6398 chwidth = 0;
6399 break;
6400 case 40:
6401 chwidth = 1;
6402 break;
6403 case 80:
6404 chwidth = 2;
6405 break;
6406 case 160:
6407 chwidth = 3;
6408 break;
6409 default:
6410 chwidth = 2;
6411 break;
6412 }
6413
6414 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6415 ifname, chwidth);
6416 if (system(buf) != 0) {
6417 sigma_dut_print(dut, DUT_MSG_ERROR,
6418 "iwpriv chwidth failed!");
6419 }
6420 }
6421
6422 /* Extract NSS */
6423 val = get_param(cmd, "NSS");
6424 if (val) {
6425 switch (atoi(val)) {
6426 case 1:
6427 nss = 1;
6428 break;
6429 case 2:
6430 nss = 3;
6431 break;
6432 case 3:
6433 nss = 7;
6434 break;
6435 default:
6436 /* We do not support NSS > 3 */
6437 nss = 3;
6438 break;
6439 }
6440 snprintf(buf, sizeof(buf),
6441 "iwpriv %s rxchainmask %d", ifname, nss);
6442 if (system(buf) != 0) {
6443 sigma_dut_print(dut, DUT_MSG_ERROR,
6444 "iwpriv rxchainmask failed!");
6445 }
6446 }
6447
6448 /* Opmode notify */
6449 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
6450 if (system(buf) != 0) {
6451 sigma_dut_print(dut, DUT_MSG_ERROR,
6452 "iwpriv opmode_notify failed!");
6453 } else {
6454 sigma_dut_print(dut, DUT_MSG_INFO,
6455 "Sent out the notify frame!");
6456 }
6457 }
6458
6459 return 1;
6460}
6461
6462
6463static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
6464 struct sigma_conn *conn,
6465 struct sigma_cmd *cmd)
6466{
6467 switch (get_driver_type()) {
6468 case DRIVER_ATHEROS:
6469 return ath_sta_send_frame_vht(dut, conn, cmd);
6470 default:
6471 send_resp(dut, conn, SIGMA_ERROR,
6472 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
6473 return 0;
6474 }
6475}
6476
6477
Lior David0fe101e2017-03-09 16:09:50 +02006478#ifdef __linux__
6479int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6480 struct sigma_cmd *cmd)
6481{
6482 const char *frame_name = get_param(cmd, "framename");
6483 const char *mac = get_param(cmd, "dest_mac");
6484
6485 if (!frame_name || !mac) {
6486 sigma_dut_print(dut, DUT_MSG_ERROR,
6487 "framename and dest_mac must be provided");
6488 return -1;
6489 }
6490
6491 if (strcasecmp(frame_name, "brp") == 0) {
6492 const char *l_rx = get_param(cmd, "L-RX");
6493 int l_rx_i;
6494
6495 if (!l_rx) {
6496 sigma_dut_print(dut, DUT_MSG_ERROR,
6497 "L-RX must be provided");
6498 return -1;
6499 }
6500 l_rx_i = atoi(l_rx);
6501
6502 sigma_dut_print(dut, DUT_MSG_INFO,
6503 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
6504 mac, l_rx);
6505 if (l_rx_i != 16) {
6506 sigma_dut_print(dut, DUT_MSG_ERROR,
6507 "unsupported L-RX: %s", l_rx);
6508 return -1;
6509 }
6510
6511 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
6512 return -1;
6513 } else if (strcasecmp(frame_name, "ssw") == 0) {
6514 sigma_dut_print(dut, DUT_MSG_INFO,
6515 "dev_send_frame: SLS, dest_mac %s", mac);
6516 if (wil6210_send_sls(dut, mac))
6517 return -1;
6518 } else {
6519 sigma_dut_print(dut, DUT_MSG_ERROR,
6520 "unsupported frame type: %s", frame_name);
6521 return -1;
6522 }
6523
6524 return 1;
6525}
6526#endif /* __linux__ */
6527
6528
6529static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
6530 struct sigma_conn *conn,
6531 struct sigma_cmd *cmd)
6532{
6533 switch (get_driver_type()) {
6534#ifdef __linux__
6535 case DRIVER_WIL6210:
6536 return wil6210_send_frame_60g(dut, conn, cmd);
6537#endif /* __linux__ */
6538 default:
6539 send_resp(dut, conn, SIGMA_ERROR,
6540 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
6541 return 0;
6542 }
6543}
6544
6545
Ashwini Patildb59b3c2017-04-13 15:19:23 +05306546static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
6547 const char *intf, struct sigma_cmd *cmd)
6548{
6549 const char *val, *addr;
6550 char buf[100];
6551
6552 addr = get_param(cmd, "DestMac");
6553 if (!addr) {
6554 send_resp(dut, conn, SIGMA_INVALID,
6555 "ErrorCode,AP MAC address is missing");
6556 return 0;
6557 }
6558
6559 val = get_param(cmd, "ANQPQuery_ID");
6560 if (!val) {
6561 send_resp(dut, conn, SIGMA_INVALID,
6562 "ErrorCode,Missing ANQPQuery_ID");
6563 return 0;
6564 }
6565
6566 if (strcasecmp(val, "NeighborReportReq") == 0) {
6567 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
6568 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
6569 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
6570 } else {
6571 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
6572 val);
6573 send_resp(dut, conn, SIGMA_INVALID,
6574 "ErrorCode,Invalid ANQPQuery_ID");
6575 return 0;
6576 }
6577
6578 if (wpa_command(intf, buf) < 0) {
6579 send_resp(dut, conn, SIGMA_ERROR,
6580 "ErrorCode,Failed to send ANQP query");
6581 return 0;
6582 }
6583
6584 return 1;
6585}
6586
6587
6588static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
6589 struct sigma_conn *conn,
6590 const char *intf,
6591 struct sigma_cmd *cmd)
6592{
6593 const char *val = get_param(cmd, "FrameName");
6594
6595 if (val && strcasecmp(val, "ANQPQuery") == 0)
6596 return mbo_send_anqp_query(dut, conn, intf, cmd);
6597
6598 return 2;
6599}
6600
6601
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006602int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6603 struct sigma_cmd *cmd)
6604{
6605 const char *intf = get_param(cmd, "Interface");
6606 const char *val;
6607 enum send_frame_type frame;
6608 enum send_frame_protection protected;
6609 char buf[100];
6610 unsigned char addr[ETH_ALEN];
6611 int res;
6612
6613 val = get_param(cmd, "program");
6614 if (val == NULL)
6615 val = get_param(cmd, "frame");
6616 if (val && strcasecmp(val, "TDLS") == 0)
6617 return cmd_sta_send_frame_tdls(dut, conn, cmd);
6618 if (val && (strcasecmp(val, "HS2") == 0 ||
6619 strcasecmp(val, "HS2-R2") == 0))
6620 return cmd_sta_send_frame_hs2(dut, conn, cmd);
6621 if (val && strcasecmp(val, "VHT") == 0)
6622 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006623 if (val && strcasecmp(val, "LOC") == 0)
6624 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02006625 if (val && strcasecmp(val, "60GHz") == 0)
6626 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05306627 if (val && strcasecmp(val, "MBO") == 0) {
6628 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
6629 if (res != 2)
6630 return res;
6631 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006632
6633 val = get_param(cmd, "TD_DISC");
6634 if (val) {
6635 if (hwaddr_aton(val, addr) < 0)
6636 return -1;
6637 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
6638 if (wpa_command(intf, buf) < 0) {
6639 send_resp(dut, conn, SIGMA_ERROR,
6640 "ErrorCode,Failed to send TDLS discovery");
6641 return 0;
6642 }
6643 return 1;
6644 }
6645
6646 val = get_param(cmd, "TD_Setup");
6647 if (val) {
6648 if (hwaddr_aton(val, addr) < 0)
6649 return -1;
6650 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
6651 if (wpa_command(intf, buf) < 0) {
6652 send_resp(dut, conn, SIGMA_ERROR,
6653 "ErrorCode,Failed to start TDLS setup");
6654 return 0;
6655 }
6656 return 1;
6657 }
6658
6659 val = get_param(cmd, "TD_TearDown");
6660 if (val) {
6661 if (hwaddr_aton(val, addr) < 0)
6662 return -1;
6663 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
6664 if (wpa_command(intf, buf) < 0) {
6665 send_resp(dut, conn, SIGMA_ERROR,
6666 "ErrorCode,Failed to tear down TDLS link");
6667 return 0;
6668 }
6669 return 1;
6670 }
6671
6672 val = get_param(cmd, "TD_ChannelSwitch");
6673 if (val) {
6674 /* TODO */
6675 send_resp(dut, conn, SIGMA_ERROR,
6676 "ErrorCode,TD_ChannelSwitch not yet supported");
6677 return 0;
6678 }
6679
6680 val = get_param(cmd, "TD_NF");
6681 if (val) {
6682 /* TODO */
6683 send_resp(dut, conn, SIGMA_ERROR,
6684 "ErrorCode,TD_NF not yet supported");
6685 return 0;
6686 }
6687
6688 val = get_param(cmd, "PMFFrameType");
6689 if (val == NULL)
6690 val = get_param(cmd, "FrameName");
6691 if (val == NULL)
6692 val = get_param(cmd, "Type");
6693 if (val == NULL)
6694 return -1;
6695 if (strcasecmp(val, "disassoc") == 0)
6696 frame = DISASSOC;
6697 else if (strcasecmp(val, "deauth") == 0)
6698 frame = DEAUTH;
6699 else if (strcasecmp(val, "saquery") == 0)
6700 frame = SAQUERY;
6701 else if (strcasecmp(val, "auth") == 0)
6702 frame = AUTH;
6703 else if (strcasecmp(val, "assocreq") == 0)
6704 frame = ASSOCREQ;
6705 else if (strcasecmp(val, "reassocreq") == 0)
6706 frame = REASSOCREQ;
6707 else if (strcasecmp(val, "neigreq") == 0) {
6708 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
6709
6710 val = get_param(cmd, "ssid");
6711 if (val == NULL)
6712 return -1;
6713
6714 res = send_neighbor_request(dut, intf, val);
6715 if (res) {
6716 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
6717 "Failed to send neighbor report request");
6718 return 0;
6719 }
6720
6721 return 1;
6722 } else if (strcasecmp(val, "transmgmtquery") == 0) {
6723 sigma_dut_print(dut, DUT_MSG_DEBUG,
6724 "Got Transition Management Query");
6725
6726 val = get_param(cmd, "ssid");
6727 res = send_trans_mgmt_query(dut, intf, val);
6728 if (res) {
6729 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
6730 "Failed to send Transition Management Query");
6731 return 0;
6732 }
6733
6734 return 1;
6735 } else {
6736 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
6737 "PMFFrameType");
6738 return 0;
6739 }
6740
6741 val = get_param(cmd, "PMFProtected");
6742 if (val == NULL)
6743 val = get_param(cmd, "Protected");
6744 if (val == NULL)
6745 return -1;
6746 if (strcasecmp(val, "Correct-key") == 0 ||
6747 strcasecmp(val, "CorrectKey") == 0)
6748 protected = CORRECT_KEY;
6749 else if (strcasecmp(val, "IncorrectKey") == 0)
6750 protected = INCORRECT_KEY;
6751 else if (strcasecmp(val, "Unprotected") == 0)
6752 protected = UNPROTECTED;
6753 else {
6754 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
6755 "PMFProtected");
6756 return 0;
6757 }
6758
6759 if (protected != UNPROTECTED &&
6760 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
6761 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
6762 "PMFProtected for auth/assocreq/reassocreq");
6763 return 0;
6764 }
6765
6766 if (if_nametoindex("sigmadut") == 0) {
6767 snprintf(buf, sizeof(buf),
6768 "iw dev %s interface add sigmadut type monitor",
6769 get_station_ifname());
6770 if (system(buf) != 0 ||
6771 if_nametoindex("sigmadut") == 0) {
6772 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
6773 "monitor interface with '%s'", buf);
6774 return -2;
6775 }
6776 }
6777
6778 if (system("ifconfig sigmadut up") != 0) {
6779 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6780 "monitor interface up");
6781 return -2;
6782 }
6783
6784 return sta_inject_frame(dut, conn, frame, protected, NULL);
6785}
6786
6787
6788static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
6789 struct sigma_conn *conn,
6790 struct sigma_cmd *cmd,
6791 const char *ifname)
6792{
6793 char buf[200];
6794 const char *val;
6795
6796 val = get_param(cmd, "ClearARP");
6797 if (val && atoi(val) == 1) {
6798 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
6799 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6800 if (system(buf) != 0) {
6801 send_resp(dut, conn, SIGMA_ERROR,
6802 "errorCode,Failed to clear ARP cache");
6803 return 0;
6804 }
6805 }
6806
6807 return 1;
6808}
6809
6810
6811int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
6812 struct sigma_cmd *cmd)
6813{
6814 const char *intf = get_param(cmd, "Interface");
6815 const char *val;
6816
6817 if (intf == NULL)
6818 return -1;
6819
6820 val = get_param(cmd, "program");
6821 if (val && (strcasecmp(val, "HS2") == 0 ||
6822 strcasecmp(val, "HS2-R2") == 0))
6823 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
6824
6825 return -1;
6826}
6827
6828
6829static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
6830 struct sigma_cmd *cmd)
6831{
6832 const char *intf = get_param(cmd, "Interface");
6833 const char *mac = get_param(cmd, "MAC");
6834
6835 if (intf == NULL || mac == NULL)
6836 return -1;
6837
6838 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
6839 "interface %s to %s", intf, mac);
6840
6841 if (dut->set_macaddr) {
6842 char buf[128];
6843 int res;
6844 if (strcasecmp(mac, "default") == 0) {
6845 res = snprintf(buf, sizeof(buf), "%s",
6846 dut->set_macaddr);
6847 dut->tmp_mac_addr = 0;
6848 } else {
6849 res = snprintf(buf, sizeof(buf), "%s %s",
6850 dut->set_macaddr, mac);
6851 dut->tmp_mac_addr = 1;
6852 }
6853 if (res < 0 || res >= (int) sizeof(buf))
6854 return -1;
6855 if (system(buf) != 0) {
6856 send_resp(dut, conn, SIGMA_ERROR,
6857 "errorCode,Failed to set MAC "
6858 "address");
6859 return 0;
6860 }
6861 return 1;
6862 }
6863
6864 if (strcasecmp(mac, "default") == 0)
6865 return 1;
6866
6867 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
6868 "command");
6869 return 0;
6870}
6871
6872
6873static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
6874 struct sigma_conn *conn, const char *intf,
6875 int val)
6876{
6877 char buf[200];
6878 int res;
6879
6880 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
6881 intf, val);
6882 if (res < 0 || res >= (int) sizeof(buf))
6883 return -1;
6884 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6885 if (system(buf) != 0) {
6886 send_resp(dut, conn, SIGMA_ERROR,
6887 "errorCode,Failed to configure offchannel mode");
6888 return 0;
6889 }
6890
6891 return 1;
6892}
6893
6894
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006895static int off_chan_val(enum sec_ch_offset off)
6896{
6897 switch (off) {
6898 case SEC_CH_NO:
6899 return 0;
6900 case SEC_CH_40ABOVE:
6901 return 40;
6902 case SEC_CH_40BELOW:
6903 return -40;
6904 }
6905
6906 return 0;
6907}
6908
6909
6910static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
6911 const char *intf, int off_ch_num,
6912 enum sec_ch_offset sec)
6913{
6914 char buf[200];
6915 int res;
6916
6917 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
6918 intf, off_ch_num);
6919 if (res < 0 || res >= (int) sizeof(buf))
6920 return -1;
6921 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6922 if (system(buf) != 0) {
6923 send_resp(dut, conn, SIGMA_ERROR,
6924 "errorCode,Failed to set offchan");
6925 return 0;
6926 }
6927
6928 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
6929 intf, off_chan_val(sec));
6930 if (res < 0 || res >= (int) sizeof(buf))
6931 return -1;
6932 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6933 if (system(buf) != 0) {
6934 send_resp(dut, conn, SIGMA_ERROR,
6935 "errorCode,Failed to set sec chan offset");
6936 return 0;
6937 }
6938
6939 return 1;
6940}
6941
6942
6943static int tdls_set_offchannel_offset(struct sigma_dut *dut,
6944 struct sigma_conn *conn,
6945 const char *intf, int off_ch_num,
6946 enum sec_ch_offset sec)
6947{
6948 char buf[200];
6949 int res;
6950
6951 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
6952 off_ch_num);
6953 if (res < 0 || res >= (int) sizeof(buf))
6954 return -1;
6955 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6956
6957 if (wpa_command(intf, buf) < 0) {
6958 send_resp(dut, conn, SIGMA_ERROR,
6959 "ErrorCode,Failed to set offchan");
6960 return 0;
6961 }
6962 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
6963 off_chan_val(sec));
6964 if (res < 0 || res >= (int) sizeof(buf))
6965 return -1;
6966
6967 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6968
6969 if (wpa_command(intf, buf) < 0) {
6970 send_resp(dut, conn, SIGMA_ERROR,
6971 "ErrorCode,Failed to set sec chan offset");
6972 return 0;
6973 }
6974
6975 return 1;
6976}
6977
6978
6979static int tdls_set_offchannel_mode(struct sigma_dut *dut,
6980 struct sigma_conn *conn,
6981 const char *intf, int val)
6982{
6983 char buf[200];
6984 int res;
6985
6986 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
6987 val);
6988 if (res < 0 || res >= (int) sizeof(buf))
6989 return -1;
6990 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6991
6992 if (wpa_command(intf, buf) < 0) {
6993 send_resp(dut, conn, SIGMA_ERROR,
6994 "ErrorCode,Failed to configure offchannel mode");
6995 return 0;
6996 }
6997
6998 return 1;
6999}
7000
7001
7002static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
7003 struct sigma_conn *conn,
7004 struct sigma_cmd *cmd)
7005{
7006 const char *val;
7007 enum {
7008 CHSM_NOT_SET,
7009 CHSM_ENABLE,
7010 CHSM_DISABLE,
7011 CHSM_REJREQ,
7012 CHSM_UNSOLRESP
7013 } chsm = CHSM_NOT_SET;
7014 int off_ch_num = -1;
7015 enum sec_ch_offset sec_ch = SEC_CH_NO;
7016 int res;
7017
7018 val = get_param(cmd, "Uapsd");
7019 if (val) {
7020 char buf[100];
7021 if (strcasecmp(val, "Enable") == 0)
7022 snprintf(buf, sizeof(buf), "SET ps 99");
7023 else if (strcasecmp(val, "Disable") == 0)
7024 snprintf(buf, sizeof(buf), "SET ps 98");
7025 else {
7026 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7027 "Unsupported uapsd parameter value");
7028 return 0;
7029 }
7030 if (wpa_command(intf, buf)) {
7031 send_resp(dut, conn, SIGMA_ERROR,
7032 "ErrorCode,Failed to change U-APSD "
7033 "powersave mode");
7034 return 0;
7035 }
7036 }
7037
7038 val = get_param(cmd, "TPKTIMER");
7039 if (val && strcasecmp(val, "DISABLE") == 0) {
7040 if (wpa_command(intf, "SET tdls_testing 0x100")) {
7041 send_resp(dut, conn, SIGMA_ERROR,
7042 "ErrorCode,Failed to enable no TPK "
7043 "expiration test mode");
7044 return 0;
7045 }
7046 dut->no_tpk_expiration = 1;
7047 }
7048
7049 val = get_param(cmd, "ChSwitchMode");
7050 if (val) {
7051 if (strcasecmp(val, "Enable") == 0 ||
7052 strcasecmp(val, "Initiate") == 0)
7053 chsm = CHSM_ENABLE;
7054 else if (strcasecmp(val, "Disable") == 0 ||
7055 strcasecmp(val, "passive") == 0)
7056 chsm = CHSM_DISABLE;
7057 else if (strcasecmp(val, "RejReq") == 0)
7058 chsm = CHSM_REJREQ;
7059 else if (strcasecmp(val, "UnSolResp") == 0)
7060 chsm = CHSM_UNSOLRESP;
7061 else {
7062 send_resp(dut, conn, SIGMA_ERROR,
7063 "ErrorCode,Unknown ChSwitchMode value");
7064 return 0;
7065 }
7066 }
7067
7068 val = get_param(cmd, "OffChNum");
7069 if (val) {
7070 off_ch_num = atoi(val);
7071 if (off_ch_num == 0) {
7072 send_resp(dut, conn, SIGMA_ERROR,
7073 "ErrorCode,Invalid OffChNum");
7074 return 0;
7075 }
7076 }
7077
7078 val = get_param(cmd, "SecChOffset");
7079 if (val) {
7080 if (strcmp(val, "20") == 0)
7081 sec_ch = SEC_CH_NO;
7082 else if (strcasecmp(val, "40above") == 0)
7083 sec_ch = SEC_CH_40ABOVE;
7084 else if (strcasecmp(val, "40below") == 0)
7085 sec_ch = SEC_CH_40BELOW;
7086 else {
7087 send_resp(dut, conn, SIGMA_ERROR,
7088 "ErrorCode,Unknown SecChOffset value");
7089 return 0;
7090 }
7091 }
7092
7093 if (chsm == CHSM_NOT_SET) {
7094 /* no offchannel changes requested */
7095 return 1;
7096 }
7097
7098 if (strcmp(intf, get_main_ifname()) != 0 &&
7099 strcmp(intf, get_station_ifname()) != 0) {
7100 send_resp(dut, conn, SIGMA_ERROR,
7101 "ErrorCode,Unknown interface");
7102 return 0;
7103 }
7104
7105 switch (chsm) {
7106 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03007107 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007108 break;
7109 case CHSM_ENABLE:
7110 if (off_ch_num < 0) {
7111 send_resp(dut, conn, SIGMA_ERROR,
7112 "ErrorCode,Missing OffChNum argument");
7113 return 0;
7114 }
7115 if (wifi_chip_type == DRIVER_WCN) {
7116 res = tdls_set_offchannel_offset(dut, conn, intf,
7117 off_ch_num, sec_ch);
7118 } else {
7119 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
7120 sec_ch);
7121 }
7122 if (res != 1)
7123 return res;
7124 if (wifi_chip_type == DRIVER_WCN)
7125 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
7126 else
7127 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
7128 break;
7129 case CHSM_DISABLE:
7130 if (wifi_chip_type == DRIVER_WCN)
7131 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
7132 else
7133 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
7134 break;
7135 case CHSM_REJREQ:
7136 if (wifi_chip_type == DRIVER_WCN)
7137 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
7138 else
7139 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
7140 break;
7141 case CHSM_UNSOLRESP:
7142 if (off_ch_num < 0) {
7143 send_resp(dut, conn, SIGMA_ERROR,
7144 "ErrorCode,Missing OffChNum argument");
7145 return 0;
7146 }
7147 if (wifi_chip_type == DRIVER_WCN) {
7148 res = tdls_set_offchannel_offset(dut, conn, intf,
7149 off_ch_num, sec_ch);
7150 } else {
7151 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
7152 sec_ch);
7153 }
7154 if (res != 1)
7155 return res;
7156 if (wifi_chip_type == DRIVER_WCN)
7157 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
7158 else
7159 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
7160 break;
7161 }
7162
7163 return res;
7164}
7165
7166
7167static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
7168 struct sigma_conn *conn,
7169 struct sigma_cmd *cmd)
7170{
7171 const char *val;
7172 char *token, *result;
7173
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08007174 novap_reset(dut, intf);
7175
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007176 val = get_param(cmd, "nss_mcs_opt");
7177 if (val) {
7178 /* String (nss_operating_mode; mcs_operating_mode) */
7179 int nss, mcs;
7180 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307181 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007182
7183 token = strdup(val);
7184 if (!token)
7185 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307186 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05307187 if (!result) {
7188 sigma_dut_print(dut, DUT_MSG_ERROR,
7189 "VHT NSS not specified");
7190 goto failed;
7191 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007192 if (strcasecmp(result, "def") != 0) {
7193 nss = atoi(result);
7194 if (nss == 4)
7195 ath_disable_txbf(dut, intf);
7196 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
7197 intf, nss);
7198 if (system(buf) != 0) {
7199 sigma_dut_print(dut, DUT_MSG_ERROR,
7200 "iwpriv nss failed");
7201 goto failed;
7202 }
7203 }
7204
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307205 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05307206 if (!result) {
7207 sigma_dut_print(dut, DUT_MSG_ERROR,
7208 "VHT MCS not specified");
7209 goto failed;
7210 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007211 if (strcasecmp(result, "def") == 0) {
7212 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
7213 intf);
7214 if (system(buf) != 0) {
7215 sigma_dut_print(dut, DUT_MSG_ERROR,
7216 "iwpriv set11NRates failed");
7217 goto failed;
7218 }
7219
7220 } else {
7221 mcs = atoi(result);
7222 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
7223 intf, mcs);
7224 if (system(buf) != 0) {
7225 sigma_dut_print(dut, DUT_MSG_ERROR,
7226 "iwpriv vhtmcs failed");
7227 goto failed;
7228 }
7229 }
7230 /* Channel width gets messed up, fix this */
7231 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7232 intf, dut->chwidth);
7233 if (system(buf) != 0) {
7234 sigma_dut_print(dut, DUT_MSG_ERROR,
7235 "iwpriv chwidth failed");
7236 }
7237 }
7238
7239 return 1;
7240failed:
7241 free(token);
7242 return 0;
7243}
7244
7245
7246static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
7247 struct sigma_conn *conn,
7248 struct sigma_cmd *cmd)
7249{
7250 switch (get_driver_type()) {
7251 case DRIVER_ATHEROS:
7252 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
7253 default:
7254 send_resp(dut, conn, SIGMA_ERROR,
7255 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
7256 return 0;
7257 }
7258}
7259
7260
7261static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
7262 struct sigma_cmd *cmd)
7263{
7264 const char *intf = get_param(cmd, "Interface");
7265 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05307266 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007267
7268 if (intf == NULL || prog == NULL)
7269 return -1;
7270
7271 if (strcasecmp(prog, "TDLS") == 0)
7272 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
7273
7274 if (strcasecmp(prog, "VHT") == 0)
7275 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
7276
Ashwini Patil68d02cd2017-01-10 15:39:16 +05307277 if (strcasecmp(prog, "MBO") == 0) {
7278 val = get_param(cmd, "Cellular_Data_Cap");
7279 if (val &&
7280 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
7281 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05307282
7283 val = get_param(cmd, "Ch_Pref");
7284 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
7285 return 0;
7286
Ashwini Patil68d02cd2017-01-10 15:39:16 +05307287 return 1;
7288 }
7289
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007290 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
7291 return 0;
7292}
7293
7294
7295static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
7296 struct sigma_cmd *cmd)
7297{
7298 const char *intf = get_param(cmd, "Interface");
7299 const char *mode = get_param(cmd, "Mode");
7300 int res;
7301
7302 if (intf == NULL || mode == NULL)
7303 return -1;
7304
7305 if (strcasecmp(mode, "On") == 0)
7306 res = wpa_command(intf, "SET radio_disabled 0");
7307 else if (strcasecmp(mode, "Off") == 0)
7308 res = wpa_command(intf, "SET radio_disabled 1");
7309 else
7310 return -1;
7311
7312 if (res) {
7313 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
7314 "radio mode");
7315 return 0;
7316 }
7317
7318 return 1;
7319}
7320
7321
7322static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
7323 struct sigma_cmd *cmd)
7324{
7325 const char *intf = get_param(cmd, "Interface");
7326 const char *mode = get_param(cmd, "Mode");
7327 int res;
7328
7329 if (intf == NULL || mode == NULL)
7330 return -1;
7331
7332 if (strcasecmp(mode, "On") == 0)
7333 res = set_ps(intf, dut, 1);
7334 else if (strcasecmp(mode, "Off") == 0)
7335 res = set_ps(intf, dut, 0);
7336 else
7337 return -1;
7338
7339 if (res) {
7340 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
7341 "power save mode");
7342 return 0;
7343 }
7344
7345 return 1;
7346}
7347
7348
7349static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
7350 struct sigma_cmd *cmd)
7351{
7352 const char *intf = get_param(cmd, "Interface");
7353 const char *val, *bssid;
7354 int res;
7355 char *buf;
7356 size_t buf_len;
7357
7358 val = get_param(cmd, "BSSID_FILTER");
7359 if (val == NULL)
7360 return -1;
7361
7362 bssid = get_param(cmd, "BSSID_List");
7363 if (atoi(val) == 0 || bssid == NULL) {
7364 /* Disable BSSID filter */
7365 if (wpa_command(intf, "SET bssid_filter ")) {
7366 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
7367 "to disable BSSID filter");
7368 return 0;
7369 }
7370
7371 return 1;
7372 }
7373
7374 buf_len = 100 + strlen(bssid);
7375 buf = malloc(buf_len);
7376 if (buf == NULL)
7377 return -1;
7378
7379 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
7380 res = wpa_command(intf, buf);
7381 free(buf);
7382 if (res) {
7383 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
7384 "BSSID filter");
7385 return 0;
7386 }
7387
7388 return 1;
7389}
7390
7391
7392static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
7393 struct sigma_cmd *cmd)
7394{
7395 const char *intf = get_param(cmd, "Interface");
7396 const char *val;
7397
7398 /* TODO: ARP */
7399
7400 val = get_param(cmd, "HS2_CACHE_PROFILE");
7401 if (val && strcasecmp(val, "All") == 0)
7402 hs2_clear_credentials(intf);
7403
7404 return 1;
7405}
7406
7407
7408static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
7409 struct sigma_cmd *cmd)
7410{
7411 const char *intf = get_param(cmd, "Interface");
7412 const char *key_type = get_param(cmd, "KeyType");
7413 char buf[100], resp[200];
7414
7415 if (key_type == NULL)
7416 return -1;
7417
7418 if (strcasecmp(key_type, "GTK") == 0) {
7419 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
7420 strncmp(buf, "FAIL", 4) == 0) {
7421 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7422 "not fetch current GTK");
7423 return 0;
7424 }
7425 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
7426 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7427 return 0;
7428 } else {
7429 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7430 "KeyType");
7431 return 0;
7432 }
7433
7434 return 1;
7435}
7436
7437
7438static int hs2_set_policy(struct sigma_dut *dut)
7439{
7440#ifdef ANDROID
7441 system("ip rule del prio 23000");
7442 if (system("ip rule add from all lookup main prio 23000") != 0) {
7443 sigma_dut_print(dut, DUT_MSG_ERROR,
7444 "Failed to run:ip rule add from all lookup main prio");
7445 return -1;
7446 }
7447 if (system("ip route flush cache") != 0) {
7448 sigma_dut_print(dut, DUT_MSG_ERROR,
7449 "Failed to run ip route flush cache");
7450 return -1;
7451 }
7452 return 1;
7453#else /* ANDROID */
7454 return 0;
7455#endif /* ANDROID */
7456}
7457
7458
7459static int cmd_sta_hs2_associate(struct sigma_dut *dut,
7460 struct sigma_conn *conn,
7461 struct sigma_cmd *cmd)
7462{
7463 const char *intf = get_param(cmd, "Interface");
7464 const char *val = get_param(cmd, "Ignore_blacklist");
7465 struct wpa_ctrl *ctrl;
7466 int res;
7467 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
7468 int tries = 0;
7469 int ignore_blacklist = 0;
7470 const char *events[] = {
7471 "CTRL-EVENT-CONNECTED",
7472 "INTERWORKING-BLACKLISTED",
7473 "INTERWORKING-NO-MATCH",
7474 NULL
7475 };
7476
7477 start_sta_mode(dut);
7478
7479 blacklisted[0] = '\0';
7480 if (val && atoi(val))
7481 ignore_blacklist = 1;
7482
7483try_again:
7484 ctrl = open_wpa_mon(intf);
7485 if (ctrl == NULL) {
7486 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7487 "wpa_supplicant monitor connection");
7488 return -2;
7489 }
7490
7491 tries++;
7492 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
7493 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
7494 "Interworking connection");
7495 wpa_ctrl_detach(ctrl);
7496 wpa_ctrl_close(ctrl);
7497 return 0;
7498 }
7499
7500 buf[0] = '\0';
7501 while (1) {
7502 char *pos;
7503 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
7504 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
7505 if (!pos)
7506 break;
7507 pos += 25;
7508 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
7509 pos);
7510 if (!blacklisted[0])
7511 memcpy(blacklisted, pos, strlen(pos) + 1);
7512 }
7513
7514 if (ignore_blacklist && blacklisted[0]) {
7515 char *end;
7516 end = strchr(blacklisted, ' ');
7517 if (end)
7518 *end = '\0';
7519 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
7520 blacklisted);
7521 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
7522 blacklisted);
7523 if (wpa_command(intf, buf)) {
7524 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
7525 wpa_ctrl_detach(ctrl);
7526 wpa_ctrl_close(ctrl);
7527 return 0;
7528 }
7529 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7530 buf, sizeof(buf));
7531 }
7532
7533 wpa_ctrl_detach(ctrl);
7534 wpa_ctrl_close(ctrl);
7535
7536 if (res < 0) {
7537 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
7538 "connect");
7539 return 0;
7540 }
7541
7542 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
7543 strstr(buf, "INTERWORKING-BLACKLISTED")) {
7544 if (tries < 2) {
7545 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
7546 goto try_again;
7547 }
7548 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
7549 "matching credentials found");
7550 return 0;
7551 }
7552
7553 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
7554 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
7555 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
7556 "get current BSSID/SSID");
7557 return 0;
7558 }
7559
7560 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
7561 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7562 hs2_set_policy(dut);
7563 return 0;
7564}
7565
7566
7567static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
7568 struct sigma_conn *conn,
7569 const char *ifname,
7570 struct sigma_cmd *cmd)
7571{
7572 const char *val;
7573 int id;
7574
7575 id = add_cred(ifname);
7576 if (id < 0)
7577 return -2;
7578 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
7579
7580 val = get_param(cmd, "prefer");
7581 if (val && atoi(val) > 0)
7582 set_cred(ifname, id, "priority", "1");
7583
7584 val = get_param(cmd, "REALM");
7585 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
7586 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7587 "realm");
7588 return 0;
7589 }
7590
7591 val = get_param(cmd, "HOME_FQDN");
7592 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
7593 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7594 "home_fqdn");
7595 return 0;
7596 }
7597
7598 val = get_param(cmd, "Username");
7599 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
7600 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7601 "username");
7602 return 0;
7603 }
7604
7605 val = get_param(cmd, "Password");
7606 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
7607 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7608 "password");
7609 return 0;
7610 }
7611
7612 val = get_param(cmd, "ROOT_CA");
7613 if (val) {
7614 char fname[200];
7615 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
7616#ifdef __linux__
7617 if (!file_exists(fname)) {
7618 char msg[300];
7619 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
7620 "file (%s) not found", fname);
7621 send_resp(dut, conn, SIGMA_ERROR, msg);
7622 return 0;
7623 }
7624#endif /* __linux__ */
7625 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
7626 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7627 "not set root CA");
7628 return 0;
7629 }
7630 }
7631
7632 return 1;
7633}
7634
7635
7636static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
7637{
7638 FILE *in, *out;
7639 char buf[500];
7640 int found = 0;
7641
7642 in = fopen("devdetail.xml", "r");
7643 if (in == NULL)
7644 return -1;
7645 out = fopen("devdetail.xml.tmp", "w");
7646 if (out == NULL) {
7647 fclose(in);
7648 return -1;
7649 }
7650
7651 while (fgets(buf, sizeof(buf), in)) {
7652 char *pos = strstr(buf, "<IMSI>");
7653 if (pos) {
7654 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
7655 imsi);
7656 pos += 6;
7657 *pos = '\0';
7658 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
7659 found++;
7660 } else {
7661 fprintf(out, "%s", buf);
7662 }
7663 }
7664
7665 fclose(out);
7666 fclose(in);
7667 if (found)
7668 rename("devdetail.xml.tmp", "devdetail.xml");
7669 else
7670 unlink("devdetail.xml.tmp");
7671
7672 return 0;
7673}
7674
7675
7676static int sta_add_credential_sim(struct sigma_dut *dut,
7677 struct sigma_conn *conn,
7678 const char *ifname, struct sigma_cmd *cmd)
7679{
7680 const char *val, *imsi = NULL;
7681 int id;
7682 char buf[200];
7683 int res;
7684 const char *pos;
7685 size_t mnc_len;
7686 char plmn_mcc[4];
7687 char plmn_mnc[4];
7688
7689 id = add_cred(ifname);
7690 if (id < 0)
7691 return -2;
7692 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
7693
7694 val = get_param(cmd, "prefer");
7695 if (val && atoi(val) > 0)
7696 set_cred(ifname, id, "priority", "1");
7697
7698 val = get_param(cmd, "PLMN_MCC");
7699 if (val == NULL) {
7700 send_resp(dut, conn, SIGMA_ERROR,
7701 "errorCode,Missing PLMN_MCC");
7702 return 0;
7703 }
7704 if (strlen(val) != 3) {
7705 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
7706 return 0;
7707 }
7708 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
7709
7710 val = get_param(cmd, "PLMN_MNC");
7711 if (val == NULL) {
7712 send_resp(dut, conn, SIGMA_ERROR,
7713 "errorCode,Missing PLMN_MNC");
7714 return 0;
7715 }
7716 if (strlen(val) != 2 && strlen(val) != 3) {
7717 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
7718 return 0;
7719 }
7720 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
7721
7722 val = get_param(cmd, "IMSI");
7723 if (val == NULL) {
7724 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
7725 "IMSI");
7726 return 0;
7727 }
7728
7729 imsi = pos = val;
7730
7731 if (strncmp(plmn_mcc, pos, 3) != 0) {
7732 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
7733 return 0;
7734 }
7735 pos += 3;
7736
7737 mnc_len = strlen(plmn_mnc);
7738 if (mnc_len < 2) {
7739 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
7740 return 0;
7741 }
7742
7743 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
7744 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
7745 return 0;
7746 }
7747 pos += mnc_len;
7748
7749 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
7750 if (res < 0 || res >= (int) sizeof(buf))
7751 return -1;
7752 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
7753 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7754 "not set IMSI");
7755 return 0;
7756 }
7757
7758 val = get_param(cmd, "Password");
7759 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
7760 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7761 "not set password");
7762 return 0;
7763 }
7764
7765 if (dut->program == PROGRAM_HS2_R2) {
7766 /*
7767 * Set provisioning_sp for the test cases where SIM/USIM
7768 * provisioning is used.
7769 */
7770 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
7771 "wi-fi.org") < 0) {
7772 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7773 "not set provisioning_sp");
7774 return 0;
7775 }
7776
7777 update_devdetail_imsi(dut, imsi);
7778 }
7779
7780 return 1;
7781}
7782
7783
7784static int sta_add_credential_cert(struct sigma_dut *dut,
7785 struct sigma_conn *conn,
7786 const char *ifname,
7787 struct sigma_cmd *cmd)
7788{
7789 const char *val;
7790 int id;
7791
7792 id = add_cred(ifname);
7793 if (id < 0)
7794 return -2;
7795 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
7796
7797 val = get_param(cmd, "prefer");
7798 if (val && atoi(val) > 0)
7799 set_cred(ifname, id, "priority", "1");
7800
7801 val = get_param(cmd, "REALM");
7802 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
7803 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7804 "realm");
7805 return 0;
7806 }
7807
7808 val = get_param(cmd, "HOME_FQDN");
7809 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
7810 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7811 "home_fqdn");
7812 return 0;
7813 }
7814
7815 val = get_param(cmd, "Username");
7816 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
7817 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7818 "username");
7819 return 0;
7820 }
7821
7822 val = get_param(cmd, "clientCertificate");
7823 if (val) {
7824 char fname[200];
7825 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
7826#ifdef __linux__
7827 if (!file_exists(fname)) {
7828 char msg[300];
7829 snprintf(msg, sizeof(msg),
7830 "ErrorCode,clientCertificate "
7831 "file (%s) not found", fname);
7832 send_resp(dut, conn, SIGMA_ERROR, msg);
7833 return 0;
7834 }
7835#endif /* __linux__ */
7836 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
7837 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7838 "not set client_cert");
7839 return 0;
7840 }
7841 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
7842 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7843 "not set private_key");
7844 return 0;
7845 }
7846 }
7847
7848 val = get_param(cmd, "ROOT_CA");
7849 if (val) {
7850 char fname[200];
7851 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
7852#ifdef __linux__
7853 if (!file_exists(fname)) {
7854 char msg[300];
7855 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
7856 "file (%s) not found", fname);
7857 send_resp(dut, conn, SIGMA_ERROR, msg);
7858 return 0;
7859 }
7860#endif /* __linux__ */
7861 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
7862 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7863 "not set root CA");
7864 return 0;
7865 }
7866 }
7867
7868 return 1;
7869}
7870
7871
7872static int cmd_sta_add_credential(struct sigma_dut *dut,
7873 struct sigma_conn *conn,
7874 struct sigma_cmd *cmd)
7875{
7876 const char *intf = get_param(cmd, "Interface");
7877 const char *type;
7878
7879 start_sta_mode(dut);
7880
7881 type = get_param(cmd, "Type");
7882 if (!type)
7883 return -1;
7884
7885 if (strcasecmp(type, "uname_pwd") == 0)
7886 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
7887
7888 if (strcasecmp(type, "sim") == 0)
7889 return sta_add_credential_sim(dut, conn, intf, cmd);
7890
7891 if (strcasecmp(type, "cert") == 0)
7892 return sta_add_credential_cert(dut, conn, intf, cmd);
7893
7894 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
7895 "type");
7896 return 0;
7897}
7898
7899
7900static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
7901 struct sigma_cmd *cmd)
7902{
7903 const char *intf = get_param(cmd, "Interface");
7904 const char *val;
7905 char buf[100];
7906 int res;
7907
7908 val = get_param(cmd, "HESSID");
7909 if (val) {
7910 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
7911 if (res < 0 || res >= (int) sizeof(buf))
7912 return -1;
7913 wpa_command(intf, buf);
7914 }
7915
7916 val = get_param(cmd, "ACCS_NET_TYPE");
7917 if (val) {
7918 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
7919 val);
7920 if (res < 0 || res >= (int) sizeof(buf))
7921 return -1;
7922 wpa_command(intf, buf);
7923 }
7924
7925 if (wpa_command(intf, "SCAN")) {
7926 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
7927 "scan");
7928 return 0;
7929 }
7930
7931 return 1;
7932}
7933
7934
7935static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
7936 struct sigma_cmd *cmd)
7937{
7938#ifdef __linux__
7939 struct timeval tv;
7940 struct tm tm;
7941 time_t t;
7942 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05307943 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007944
7945 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
7946
7947 memset(&tm, 0, sizeof(tm));
7948 val = get_param(cmd, "seconds");
7949 if (val)
7950 tm.tm_sec = atoi(val);
7951 val = get_param(cmd, "minutes");
7952 if (val)
7953 tm.tm_min = atoi(val);
7954 val = get_param(cmd, "hours");
7955 if (val)
7956 tm.tm_hour = atoi(val);
7957 val = get_param(cmd, "date");
7958 if (val)
7959 tm.tm_mday = atoi(val);
7960 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05307961 if (val) {
7962 v = atoi(val);
7963 if (v < 1 || v > 12) {
7964 send_resp(dut, conn, SIGMA_INVALID,
7965 "errorCode,Invalid month");
7966 return 0;
7967 }
7968 tm.tm_mon = v - 1;
7969 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007970 val = get_param(cmd, "year");
7971 if (val) {
7972 int year = atoi(val);
7973#ifdef ANDROID
7974 if (year > 2035)
7975 year = 2035; /* years beyond 2035 not supported */
7976#endif /* ANDROID */
7977 tm.tm_year = year - 1900;
7978 }
7979 t = mktime(&tm);
7980 if (t == (time_t) -1) {
7981 send_resp(dut, conn, SIGMA_ERROR,
7982 "errorCode,Invalid date or time");
7983 return 0;
7984 }
7985
7986 memset(&tv, 0, sizeof(tv));
7987 tv.tv_sec = t;
7988
7989 if (settimeofday(&tv, NULL) < 0) {
7990 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
7991 strerror(errno));
7992 send_resp(dut, conn, SIGMA_ERROR,
7993 "errorCode,Failed to set time");
7994 return 0;
7995 }
7996
7997 return 1;
7998#endif /* __linux__ */
7999
8000 return -1;
8001}
8002
8003
8004static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
8005 struct sigma_cmd *cmd)
8006{
8007 const char *intf = get_param(cmd, "Interface");
8008 const char *name, *val;
8009 int prod_ess_assoc = 1;
8010 char buf[200], bssid[100], ssid[100];
8011 int res;
8012 struct wpa_ctrl *ctrl;
8013
8014 name = get_param(cmd, "osuFriendlyName");
8015
8016 val = get_param(cmd, "ProdESSAssoc");
8017 if (val)
8018 prod_ess_assoc = atoi(val);
8019
8020 kill_dhcp_client(dut, intf);
8021 if (start_dhcp_client(dut, intf) < 0)
8022 return -2;
8023
8024 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
8025 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
8026 res = snprintf(buf, sizeof(buf),
8027 "%s %s%s%s signup osu-ca.pem",
8028 prod_ess_assoc ? "" : "-N",
8029 name ? "-O'" : "", name ? name : "",
8030 name ? "'" : "");
8031
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05308032 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008033 if (run_hs20_osu(dut, buf) < 0) {
8034 FILE *f;
8035
8036 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
8037
8038 f = fopen("hs20-osu-client.res", "r");
8039 if (f) {
8040 char resp[400], res[300], *pos;
8041 if (!fgets(res, sizeof(res), f))
8042 res[0] = '\0';
8043 pos = strchr(res, '\n');
8044 if (pos)
8045 *pos = '\0';
8046 fclose(f);
8047 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
8048 res);
8049 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
8050 if (system(resp) != 0) {
8051 }
8052 snprintf(resp, sizeof(resp),
8053 "SSID,,BSSID,,failureReason,%s", res);
8054 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8055 return 0;
8056 }
8057
8058 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
8059 return 0;
8060 }
8061
8062 if (!prod_ess_assoc)
8063 goto report;
8064
8065 ctrl = open_wpa_mon(intf);
8066 if (ctrl == NULL) {
8067 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8068 "wpa_supplicant monitor connection");
8069 return -1;
8070 }
8071
8072 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
8073 buf, sizeof(buf));
8074
8075 wpa_ctrl_detach(ctrl);
8076 wpa_ctrl_close(ctrl);
8077
8078 if (res < 0) {
8079 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
8080 "network after OSU");
8081 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
8082 return 0;
8083 }
8084
8085report:
8086 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
8087 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
8088 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
8089 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
8090 return 0;
8091 }
8092
8093 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
8094 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008095 return 0;
8096}
8097
8098
8099static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
8100 struct sigma_cmd *cmd)
8101{
8102 const char *val;
8103 int timeout = 120;
8104
8105 val = get_param(cmd, "PolicyUpdate");
8106 if (val == NULL || atoi(val) == 0)
8107 return 1; /* No operation requested */
8108
8109 val = get_param(cmd, "Timeout");
8110 if (val)
8111 timeout = atoi(val);
8112
8113 if (timeout) {
8114 /* TODO: time out the command and return
8115 * PolicyUpdateStatus,TIMEOUT if needed. */
8116 }
8117
8118 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
8119 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
8120 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
8121 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
8122 return 0;
8123 }
8124
8125 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
8126 return 0;
8127}
8128
8129
8130static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
8131 struct sigma_cmd *cmd)
8132{
8133 struct wpa_ctrl *ctrl;
8134 const char *intf = get_param(cmd, "Interface");
8135 const char *bssid = get_param(cmd, "Bssid");
8136 const char *ssid = get_param(cmd, "SSID");
8137 const char *security = get_param(cmd, "Security");
8138 const char *passphrase = get_param(cmd, "Passphrase");
8139 const char *pin = get_param(cmd, "PIN");
8140 char buf[1000];
8141 char ssid_hex[200], passphrase_hex[200];
8142 const char *keymgmt, *cipher;
8143
8144 if (intf == NULL)
8145 intf = get_main_ifname();
8146
8147 if (!bssid) {
8148 send_resp(dut, conn, SIGMA_ERROR,
8149 "ErrorCode,Missing Bssid argument");
8150 return 0;
8151 }
8152
8153 if (!ssid) {
8154 send_resp(dut, conn, SIGMA_ERROR,
8155 "ErrorCode,Missing SSID argument");
8156 return 0;
8157 }
8158
8159 if (!security) {
8160 send_resp(dut, conn, SIGMA_ERROR,
8161 "ErrorCode,Missing Security argument");
8162 return 0;
8163 }
8164
8165 if (!passphrase) {
8166 send_resp(dut, conn, SIGMA_ERROR,
8167 "ErrorCode,Missing Passphrase argument");
8168 return 0;
8169 }
8170
8171 if (!pin) {
8172 send_resp(dut, conn, SIGMA_ERROR,
8173 "ErrorCode,Missing PIN argument");
8174 return 0;
8175 }
8176
8177 if (strlen(ssid) >= 2 * sizeof(ssid_hex) ||
8178 strlen(passphrase) >= 2 * sizeof(passphrase_hex)) {
8179 send_resp(dut, conn, SIGMA_ERROR,
8180 "ErrorCode,Too long SSID/passphrase");
8181 return 0;
8182 }
8183
8184 ctrl = open_wpa_mon(intf);
8185 if (ctrl == NULL) {
8186 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8187 "wpa_supplicant monitor connection");
8188 return -2;
8189 }
8190
8191 if (strcasecmp(security, "wpa2-psk") == 0) {
8192 keymgmt = "WPA2PSK";
8193 cipher = "CCMP";
8194 } else {
8195 wpa_ctrl_detach(ctrl);
8196 wpa_ctrl_close(ctrl);
8197 send_resp(dut, conn, SIGMA_ERROR,
8198 "ErrorCode,Unsupported Security value");
8199 return 0;
8200 }
8201
8202 ascii2hexstr(ssid, ssid_hex);
8203 ascii2hexstr(passphrase, passphrase_hex);
8204 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
8205 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
8206
8207 if (wpa_command(intf, buf) < 0) {
8208 wpa_ctrl_detach(ctrl);
8209 wpa_ctrl_close(ctrl);
8210 send_resp(dut, conn, SIGMA_ERROR,
8211 "ErrorCode,Failed to start registrar");
8212 return 0;
8213 }
8214
8215 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
8216 dut->er_oper_performed = 1;
8217
8218 return wps_connection_event(dut, conn, ctrl, intf, 0);
8219}
8220
8221
8222static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
8223 struct sigma_conn *conn,
8224 struct sigma_cmd *cmd)
8225{
8226 struct wpa_ctrl *ctrl;
8227 const char *intf = get_param(cmd, "Interface");
8228 const char *bssid = get_param(cmd, "Bssid");
8229 char buf[100];
8230
8231 if (!bssid) {
8232 send_resp(dut, conn, SIGMA_ERROR,
8233 "ErrorCode,Missing Bssid argument");
8234 return 0;
8235 }
8236
8237 ctrl = open_wpa_mon(intf);
8238 if (ctrl == NULL) {
8239 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8240 "wpa_supplicant monitor connection");
8241 return -2;
8242 }
8243
8244 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
8245
8246 if (wpa_command(intf, buf) < 0) {
8247 wpa_ctrl_detach(ctrl);
8248 wpa_ctrl_close(ctrl);
8249 send_resp(dut, conn, SIGMA_ERROR,
8250 "ErrorCode,Failed to start registrar");
8251 return 0;
8252 }
8253
8254 return wps_connection_event(dut, conn, ctrl, intf, 0);
8255}
8256
8257
8258static int req_intf(struct sigma_cmd *cmd)
8259{
8260 return get_param(cmd, "interface") == NULL ? -1 : 0;
8261}
8262
8263
8264void sta_register_cmds(void)
8265{
8266 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
8267 cmd_sta_get_ip_config);
8268 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
8269 cmd_sta_set_ip_config);
8270 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
8271 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
8272 cmd_sta_get_mac_address);
8273 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
8274 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
8275 cmd_sta_verify_ip_connection);
8276 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
8277 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
8278 cmd_sta_set_encryption);
8279 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
8280 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
8281 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
8282 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
8283 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
8284 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
8285 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
8286 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
8287 cmd_sta_set_eapakaprime);
8288 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
8289 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
8290 /* TODO: sta_set_ibss */
8291 /* TODO: sta_set_mode */
8292 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
8293 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
8294 /* TODO: sta_up_load */
8295 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
8296 cmd_sta_preset_testparameters);
8297 /* TODO: sta_set_system */
8298 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
8299 /* TODO: sta_set_rifs_test */
8300 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
8301 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
8302 /* TODO: sta_send_coexist_mgmt */
8303 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
8304 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
8305 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
8306 sigma_dut_reg_cmd("sta_reset_default", req_intf,
8307 cmd_sta_reset_default);
8308 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
8309 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
8310 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
8311 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
8312 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
8313 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
8314 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
8315 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
8316 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
8317 cmd_sta_hs2_associate);
8318 sigma_dut_reg_cmd("sta_add_credential", req_intf,
8319 cmd_sta_add_credential);
8320 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
8321 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
8322 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
8323 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
8324 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
8325 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
8326 cmd_sta_wps_connect_pw_token);
8327 sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action);
8328 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
8329 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
8330}