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