blob: 92475aaf6f94fd6e9a4f8d5a9586b0d03e4cce2b [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;
1311
1312 id = add_network_common(dut, conn, ifname, cmd);
1313 if (id < 0)
1314 return id;
1315
1316 val = get_param(cmd, "keyMgmtType");
1317 if (val == NULL) {
1318 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing keyMgmtType");
1319 return 0;
1320 }
1321 if (strcasecmp(val, "wpa") == 0 ||
1322 strcasecmp(val, "wpa-psk") == 0) {
1323 if (set_network(ifname, id, "proto", "WPA") < 0)
1324 return -2;
1325 } else if (strcasecmp(val, "wpa2") == 0 ||
1326 strcasecmp(val, "wpa2-psk") == 0 ||
1327 strcasecmp(val, "wpa2-ft") == 0 ||
1328 strcasecmp(val, "wpa2-sha256") == 0) {
1329 if (set_network(ifname, id, "proto", "WPA2") < 0)
1330 return -2;
Pradeep Reddy POTTETI6d04b3b2016-11-15 14:51:26 +05301331 } else if (strcasecmp(val, "wpa2-wpa-psk") == 0 ||
1332 strcasecmp(val, "wpa2-wpa-ent") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001333 if (set_network(ifname, id, "proto", "WPA WPA2") < 0)
1334 return -2;
1335 } else {
1336 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized keyMgmtType value");
1337 return 0;
1338 }
1339
1340 val = get_param(cmd, "encpType");
1341 if (val == NULL) {
1342 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Missing encpType");
1343 return 0;
1344 }
1345 if (strcasecmp(val, "tkip") == 0) {
1346 if (set_network(ifname, id, "pairwise", "TKIP") < 0)
1347 return -2;
1348 } else if (strcasecmp(val, "aes-ccmp") == 0) {
1349 if (set_network(ifname, id, "pairwise", "CCMP") < 0)
1350 return -2;
1351 } else if (strcasecmp(val, "aes-ccmp-tkip") == 0) {
1352 if (set_network(ifname, id, "pairwise", "CCMP TKIP") < 0)
1353 return -2;
1354 } else if (strcasecmp(val, "aes-gcmp") == 0) {
1355 if (set_network(ifname, id, "pairwise", "GCMP") < 0)
1356 return -2;
1357 if (set_network(ifname, id, "group", "GCMP") < 0)
1358 return -2;
1359 } else {
1360 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized encpType value");
1361 return 0;
1362 }
1363
1364 dut->sta_pmf = STA_PMF_DISABLED;
1365 val = get_param(cmd, "PMF");
1366 if (val) {
1367 if (strcasecmp(val, "Required") == 0 ||
1368 strcasecmp(val, "Forced_Required") == 0) {
1369 dut->sta_pmf = STA_PMF_REQUIRED;
1370 if (set_network(ifname, id, "ieee80211w", "2") < 0)
1371 return -2;
1372 } else if (strcasecmp(val, "Optional") == 0) {
1373 dut->sta_pmf = STA_PMF_OPTIONAL;
1374 if (set_network(ifname, id, "ieee80211w", "1") < 0)
1375 return -2;
1376 } else if (strcasecmp(val, "Disabled") == 0 ||
1377 strcasecmp(val, "Forced_Disabled") == 0) {
1378 dut->sta_pmf = STA_PMF_DISABLED;
1379 } else {
1380 send_resp(dut, conn, SIGMA_INVALID, "errorCode,Unrecognized PMF value");
1381 return 0;
1382 }
1383 }
1384
1385 return id;
1386}
1387
1388
1389static int cmd_sta_set_psk(struct sigma_dut *dut, struct sigma_conn *conn,
1390 struct sigma_cmd *cmd)
1391{
1392 const char *intf = get_param(cmd, "Interface");
Jouni Malinen992a81e2017-08-22 13:57:47 +03001393 const char *type = get_param(cmd, "Type");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001394 const char *ifname, *val, *alg;
1395 int id;
1396
1397 if (intf == NULL)
1398 return -1;
1399
1400 if (strcmp(intf, get_main_ifname()) == 0)
1401 ifname = get_station_ifname();
1402 else
1403 ifname = intf;
1404
1405 id = set_wpa_common(dut, conn, ifname, cmd);
1406 if (id < 0)
1407 return id;
1408
1409 val = get_param(cmd, "keyMgmtType");
1410 alg = get_param(cmd, "micAlg");
1411
Jouni Malinen992a81e2017-08-22 13:57:47 +03001412 if (type && strcasecmp(type, "SAE") == 0) {
1413 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1414 if (set_network(ifname, id, "key_mgmt", "FT-SAE") < 0)
1415 return -2;
1416 } else {
1417 if (set_network(ifname, id, "key_mgmt", "SAE") < 0)
1418 return -2;
1419 }
1420 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1421 sigma_dut_print(dut, DUT_MSG_ERROR,
1422 "Failed to clear sae_groups to default");
1423 return -2;
1424 }
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001425 } else if (type && strcasecmp(type, "PSK-SAE") == 0) {
1426 if (val && strcasecmp(val, "wpa2-ft") == 0) {
1427 if (set_network(ifname, id, "key_mgmt",
1428 "FT-SAE FT-PSK") < 0)
1429 return -2;
1430 } else {
1431 if (set_network(ifname, id, "key_mgmt",
1432 "SAE WPA-PSK") < 0)
1433 return -2;
1434 }
1435 if (wpa_command(ifname, "SET sae_groups ") != 0) {
1436 sigma_dut_print(dut, DUT_MSG_ERROR,
1437 "Failed to clear sae_groups to default");
1438 return -2;
1439 }
Jouni Malinen992a81e2017-08-22 13:57:47 +03001440 } else if (alg && strcasecmp(alg, "SHA-256") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001441 if (set_network(ifname, id, "key_mgmt", "WPA-PSK-SHA256") < 0)
1442 return -2;
1443 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1444 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1445 return -2;
Ashwini Patil6dbf7b02017-03-20 13:42:11 +05301446 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1447 if (set_network(ifname, id, "key_mgmt", "FT-PSK") < 0)
1448 return -2;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001449 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1450 dut->sta_pmf == STA_PMF_REQUIRED) {
1451 if (set_network(ifname, id, "key_mgmt",
1452 "WPA-PSK WPA-PSK-SHA256") < 0)
1453 return -2;
1454 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1455 if (set_network(ifname, id, "key_mgmt",
1456 "WPA-PSK WPA-PSK-SHA256") < 0)
1457 return -2;
1458 } else {
1459 if (set_network(ifname, id, "key_mgmt", "WPA-PSK") < 0)
1460 return -2;
1461 }
1462
1463 val = get_param(cmd, "passPhrase");
1464 if (val == NULL)
1465 return -1;
1466 if (set_network_quoted(ifname, id, "psk", val) < 0)
1467 return -2;
1468
Jouni Malinen992a81e2017-08-22 13:57:47 +03001469 val = get_param(cmd, "ECGroupID");
1470 if (val) {
1471 char buf[50];
1472
1473 snprintf(buf, sizeof(buf), "SET sae_groups %u", atoi(val));
1474 if (wpa_command(ifname, buf) != 0) {
1475 sigma_dut_print(dut, DUT_MSG_ERROR,
1476 "Failed to clear sae_groups");
1477 return -2;
1478 }
1479 }
1480
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001481 return 1;
1482}
1483
1484
1485static int set_eap_common(struct sigma_dut *dut, struct sigma_conn *conn,
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301486 const char *ifname, int username_identity,
1487 struct sigma_cmd *cmd)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001488{
1489 const char *val, *alg;
1490 int id;
1491 char buf[200];
1492#ifdef ANDROID
1493 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1494 int length;
1495#endif /* ANDROID */
1496
1497 id = set_wpa_common(dut, conn, ifname, cmd);
1498 if (id < 0)
1499 return id;
1500
1501 val = get_param(cmd, "keyMgmtType");
1502 alg = get_param(cmd, "micAlg");
1503
1504 if (alg && strcasecmp(alg, "SHA-256") == 0) {
1505 if (set_network(ifname, id, "key_mgmt", "WPA-EAP-SHA256") < 0)
1506 return -2;
1507 } else if (alg && strcasecmp(alg, "SHA-1") == 0) {
1508 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1509 return -2;
1510 } else if (val && strcasecmp(val, "wpa2-ft") == 0) {
1511 if (set_network(ifname, id, "key_mgmt", "FT-EAP") < 0)
1512 return -2;
1513 } else if ((val && strcasecmp(val, "wpa2-sha256") == 0) ||
1514 dut->sta_pmf == STA_PMF_REQUIRED) {
1515 if (set_network(ifname, id, "key_mgmt",
1516 "WPA-EAP WPA-EAP-SHA256") < 0)
1517 return -2;
1518 } else if (dut->sta_pmf == STA_PMF_OPTIONAL) {
1519 if (set_network(ifname, id, "key_mgmt",
1520 "WPA-EAP WPA-EAP-SHA256") < 0)
1521 return -2;
1522 } else {
1523 if (set_network(ifname, id, "key_mgmt", "WPA-EAP") < 0)
1524 return -2;
1525 }
1526
1527 val = get_param(cmd, "trustedRootCA");
1528 if (val) {
1529#ifdef ANDROID
1530 snprintf(buf, sizeof(buf), "CACERT_%s", val);
1531 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf,
1532 kvalue);
1533 if (length > 0) {
1534 sigma_dut_print(dut, DUT_MSG_INFO,
1535 "Use Android keystore [%s]", buf);
1536 snprintf(buf, sizeof(buf), "keystore://CACERT_%s",
1537 val);
1538 goto ca_cert_selected;
1539 }
1540#endif /* ANDROID */
1541
1542 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1543#ifdef __linux__
1544 if (!file_exists(buf)) {
1545 char msg[300];
1546 snprintf(msg, sizeof(msg), "ErrorCode,trustedRootCA "
1547 "file (%s) not found", buf);
1548 send_resp(dut, conn, SIGMA_ERROR, msg);
1549 return -3;
1550 }
1551#endif /* __linux__ */
1552#ifdef ANDROID
1553ca_cert_selected:
1554#endif /* ANDROID */
1555 if (set_network_quoted(ifname, id, "ca_cert", buf) < 0)
1556 return -2;
1557 }
1558
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301559 if (username_identity) {
1560 val = get_param(cmd, "username");
1561 if (val) {
1562 if (set_network_quoted(ifname, id, "identity", val) < 0)
1563 return -2;
1564 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001565
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301566 val = get_param(cmd, "password");
1567 if (val) {
1568 if (set_network_quoted(ifname, id, "password", val) < 0)
1569 return -2;
1570 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001571 }
1572
1573 return id;
1574}
1575
1576
1577static int cmd_sta_set_eaptls(struct sigma_dut *dut, struct sigma_conn *conn,
1578 struct sigma_cmd *cmd)
1579{
1580 const char *intf = get_param(cmd, "Interface");
1581 const char *ifname, *val;
1582 int id;
1583 char buf[200];
1584#ifdef ANDROID
1585 unsigned char kvalue[KEYSTORE_MESSAGE_SIZE];
1586 int length;
1587 int jb_or_newer = 0;
1588 char prop[PROPERTY_VALUE_MAX];
1589#endif /* ANDROID */
1590
1591 if (intf == NULL)
1592 return -1;
1593
1594 if (strcmp(intf, get_main_ifname()) == 0)
1595 ifname = get_station_ifname();
1596 else
1597 ifname = intf;
1598
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301599 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001600 if (id < 0)
1601 return id;
1602
1603 if (set_network(ifname, id, "eap", "TLS") < 0)
1604 return -2;
1605
Pradeep Reddy POTTETI9f6c2132016-05-05 16:28:19 +05301606 if (!get_param(cmd, "username") &&
1607 set_network_quoted(ifname, id, "identity",
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001608 "wifi-user@wifilabs.local") < 0)
1609 return -2;
1610
1611 val = get_param(cmd, "clientCertificate");
1612 if (val == NULL)
1613 return -1;
1614#ifdef ANDROID
1615 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1616 length = android_keystore_get(ANDROID_KEYSTORE_GET, buf, kvalue);
1617 if (length < 0) {
1618 /*
1619 * JB started reporting keystore type mismatches, so retry with
1620 * the GET_PUBKEY command if the generic GET fails.
1621 */
1622 length = android_keystore_get(ANDROID_KEYSTORE_GET_PUBKEY,
1623 buf, kvalue);
1624 }
1625
1626 if (property_get("ro.build.version.release", prop, NULL) != 0) {
1627 sigma_dut_print(dut, DUT_MSG_DEBUG, "Android release %s", prop);
1628 if (strncmp(prop, "4.0", 3) != 0)
1629 jb_or_newer = 1;
1630 } else
1631 jb_or_newer = 1; /* assume newer */
1632
1633 if (jb_or_newer && length > 0) {
1634 sigma_dut_print(dut, DUT_MSG_INFO,
1635 "Use Android keystore [%s]", buf);
1636 if (set_network(ifname, id, "engine", "1") < 0)
1637 return -2;
1638 if (set_network_quoted(ifname, id, "engine_id", "keystore") < 0)
1639 return -2;
1640 snprintf(buf, sizeof(buf), "USRPKEY_%s", val);
1641 if (set_network_quoted(ifname, id, "key_id", buf) < 0)
1642 return -2;
1643 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1644 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1645 return -2;
1646 return 1;
1647 } else if (length > 0) {
1648 sigma_dut_print(dut, DUT_MSG_INFO,
1649 "Use Android keystore [%s]", buf);
1650 snprintf(buf, sizeof(buf), "keystore://USRPKEY_%s", val);
1651 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1652 return -2;
1653 snprintf(buf, sizeof(buf), "keystore://USRCERT_%s", val);
1654 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1655 return -2;
1656 return 1;
1657 }
1658#endif /* ANDROID */
1659
1660 snprintf(buf, sizeof(buf), "%s/%s", sigma_cert_path, val);
1661#ifdef __linux__
1662 if (!file_exists(buf)) {
1663 char msg[300];
1664 snprintf(msg, sizeof(msg), "ErrorCode,clientCertificate file "
1665 "(%s) not found", buf);
1666 send_resp(dut, conn, SIGMA_ERROR, msg);
1667 return -3;
1668 }
1669#endif /* __linux__ */
1670 if (set_network_quoted(ifname, id, "private_key", buf) < 0)
1671 return -2;
1672 if (set_network_quoted(ifname, id, "client_cert", buf) < 0)
1673 return -2;
1674
1675 if (set_network_quoted(ifname, id, "private_key_passwd", "wifi") < 0)
1676 return -2;
1677
1678 return 1;
1679}
1680
1681
1682static int cmd_sta_set_eapttls(struct sigma_dut *dut, struct sigma_conn *conn,
1683 struct sigma_cmd *cmd)
1684{
1685 const char *intf = get_param(cmd, "Interface");
1686 const char *ifname;
1687 int id;
1688
1689 if (intf == NULL)
1690 return -1;
1691
1692 if (strcmp(intf, get_main_ifname()) == 0)
1693 ifname = get_station_ifname();
1694 else
1695 ifname = intf;
1696
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301697 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001698 if (id < 0)
1699 return id;
1700
1701 if (set_network(ifname, id, "eap", "TTLS") < 0) {
1702 send_resp(dut, conn, SIGMA_ERROR,
1703 "errorCode,Failed to set TTLS method");
1704 return 0;
1705 }
1706
1707 if (set_network_quoted(ifname, id, "phase2", "auth=MSCHAPV2") < 0) {
1708 send_resp(dut, conn, SIGMA_ERROR,
1709 "errorCode,Failed to set MSCHAPv2 for TTLS Phase 2");
1710 return 0;
1711 }
1712
1713 return 1;
1714}
1715
1716
1717static int cmd_sta_set_eapsim(struct sigma_dut *dut, struct sigma_conn *conn,
1718 struct sigma_cmd *cmd)
1719{
1720 const char *intf = get_param(cmd, "Interface");
1721 const char *ifname;
1722 int id;
1723
1724 if (intf == NULL)
1725 return -1;
1726
1727 if (strcmp(intf, get_main_ifname()) == 0)
1728 ifname = get_station_ifname();
1729 else
1730 ifname = intf;
1731
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301732 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001733 if (id < 0)
1734 return id;
1735
1736 if (set_network(ifname, id, "eap", "SIM") < 0)
1737 return -2;
1738
1739 return 1;
1740}
1741
1742
1743static int cmd_sta_set_peap(struct sigma_dut *dut, struct sigma_conn *conn,
1744 struct sigma_cmd *cmd)
1745{
1746 const char *intf = get_param(cmd, "Interface");
1747 const char *ifname, *val;
1748 int id;
1749 char buf[100];
1750
1751 if (intf == NULL)
1752 return -1;
1753
1754 if (strcmp(intf, get_main_ifname()) == 0)
1755 ifname = get_station_ifname();
1756 else
1757 ifname = intf;
1758
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301759 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001760 if (id < 0)
1761 return id;
1762
1763 if (set_network(ifname, id, "eap", "PEAP") < 0)
1764 return -2;
1765
1766 val = get_param(cmd, "innerEAP");
1767 if (val) {
1768 if (strcasecmp(val, "MSCHAPv2") == 0) {
1769 if (set_network_quoted(ifname, id, "phase2",
1770 "auth=MSCHAPV2") < 0)
1771 return -2;
1772 } else if (strcasecmp(val, "GTC") == 0) {
1773 if (set_network_quoted(ifname, id, "phase2",
1774 "auth=GTC") < 0)
1775 return -2;
1776 } else
1777 return -1;
1778 }
1779
1780 val = get_param(cmd, "peapVersion");
1781 if (val) {
1782 int ver = atoi(val);
1783 if (ver < 0 || ver > 1)
1784 return -1;
1785 snprintf(buf, sizeof(buf), "peapver=%d", ver);
1786 if (set_network_quoted(ifname, id, "phase1", buf) < 0)
1787 return -2;
1788 }
1789
1790 return 1;
1791}
1792
1793
1794static int cmd_sta_set_eapfast(struct sigma_dut *dut, struct sigma_conn *conn,
1795 struct sigma_cmd *cmd)
1796{
1797 const char *intf = get_param(cmd, "Interface");
1798 const char *ifname, *val;
1799 int id;
1800 char buf[100];
1801
1802 if (intf == NULL)
1803 return -1;
1804
1805 if (strcmp(intf, get_main_ifname()) == 0)
1806 ifname = get_station_ifname();
1807 else
1808 ifname = intf;
1809
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301810 id = set_eap_common(dut, conn, ifname, 1, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001811 if (id < 0)
1812 return id;
1813
1814 if (set_network(ifname, id, "eap", "FAST") < 0)
1815 return -2;
1816
1817 val = get_param(cmd, "innerEAP");
1818 if (val) {
1819 if (strcasecmp(val, "MSCHAPV2") == 0) {
1820 if (set_network_quoted(ifname, id, "phase2",
1821 "auth=MSCHAPV2") < 0)
1822 return -2;
1823 } else if (strcasecmp(val, "GTC") == 0) {
1824 if (set_network_quoted(ifname, id, "phase2",
1825 "auth=GTC") < 0)
1826 return -2;
1827 } else
1828 return -1;
1829 }
1830
1831 val = get_param(cmd, "validateServer");
1832 if (val) {
1833 /* TODO */
1834 sigma_dut_print(dut, DUT_MSG_INFO, "Ignored EAP-FAST "
1835 "validateServer=%s", val);
1836 }
1837
1838 val = get_param(cmd, "pacFile");
1839 if (val) {
1840 snprintf(buf, sizeof(buf), "blob://%s", val);
1841 if (set_network_quoted(ifname, id, "pac_file", buf) < 0)
1842 return -2;
1843 }
1844
1845 if (set_network_quoted(ifname, id, "phase1", "fast_provisioning=2") <
1846 0)
1847 return -2;
1848
1849 return 1;
1850}
1851
1852
1853static int cmd_sta_set_eapaka(struct sigma_dut *dut, struct sigma_conn *conn,
1854 struct sigma_cmd *cmd)
1855{
1856 const char *intf = get_param(cmd, "Interface");
1857 const char *ifname;
1858 int id;
1859
1860 if (intf == NULL)
1861 return -1;
1862
1863 if (strcmp(intf, get_main_ifname()) == 0)
1864 ifname = get_station_ifname();
1865 else
1866 ifname = intf;
1867
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301868 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001869 if (id < 0)
1870 return id;
1871
1872 if (set_network(ifname, id, "eap", "AKA") < 0)
1873 return -2;
1874
1875 return 1;
1876}
1877
1878
1879static int cmd_sta_set_eapakaprime(struct sigma_dut *dut,
1880 struct sigma_conn *conn,
1881 struct sigma_cmd *cmd)
1882{
1883 const char *intf = get_param(cmd, "Interface");
1884 const char *ifname;
1885 int id;
1886
1887 if (intf == NULL)
1888 return -1;
1889
1890 if (strcmp(intf, get_main_ifname()) == 0)
1891 ifname = get_station_ifname();
1892 else
1893 ifname = intf;
1894
Bala Krishna Bhamidipati73d7af02016-03-24 12:27:56 +05301895 id = set_eap_common(dut, conn, ifname, !dut->sim_no_username, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001896 if (id < 0)
1897 return id;
1898
1899 if (set_network(ifname, id, "eap", "AKA'") < 0)
1900 return -2;
1901
1902 return 1;
1903}
1904
1905
1906static int sta_set_open(struct sigma_dut *dut, struct sigma_conn *conn,
1907 struct sigma_cmd *cmd)
1908{
1909 const char *intf = get_param(cmd, "Interface");
1910 const char *ifname;
1911 int id;
1912
1913 if (strcmp(intf, get_main_ifname()) == 0)
1914 ifname = get_station_ifname();
1915 else
1916 ifname = intf;
1917
1918 id = add_network_common(dut, conn, ifname, cmd);
1919 if (id < 0)
1920 return id;
1921
1922 if (set_network(ifname, id, "key_mgmt", "NONE") < 0)
1923 return -2;
1924
1925 return 1;
1926}
1927
1928
1929static int cmd_sta_set_security(struct sigma_dut *dut, struct sigma_conn *conn,
1930 struct sigma_cmd *cmd)
1931{
1932 const char *type = get_param(cmd, "Type");
1933
1934 if (type == NULL) {
1935 send_resp(dut, conn, SIGMA_ERROR,
1936 "ErrorCode,Missing Type argument");
1937 return 0;
1938 }
1939
1940 if (strcasecmp(type, "OPEN") == 0)
1941 return sta_set_open(dut, conn, cmd);
Jouni Malinen992a81e2017-08-22 13:57:47 +03001942 if (strcasecmp(type, "PSK") == 0 ||
Jouni Malinen0ab50f42017-08-31 01:34:59 +03001943 strcasecmp(type, "PSK-SAE") == 0 ||
Jouni Malinen992a81e2017-08-22 13:57:47 +03001944 strcasecmp(type, "SAE") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02001945 return cmd_sta_set_psk(dut, conn, cmd);
1946 if (strcasecmp(type, "EAPTLS") == 0)
1947 return cmd_sta_set_eaptls(dut, conn, cmd);
1948 if (strcasecmp(type, "EAPTTLS") == 0)
1949 return cmd_sta_set_eapttls(dut, conn, cmd);
1950 if (strcasecmp(type, "EAPPEAP") == 0)
1951 return cmd_sta_set_peap(dut, conn, cmd);
1952 if (strcasecmp(type, "EAPSIM") == 0)
1953 return cmd_sta_set_eapsim(dut, conn, cmd);
1954 if (strcasecmp(type, "EAPFAST") == 0)
1955 return cmd_sta_set_eapfast(dut, conn, cmd);
1956 if (strcasecmp(type, "EAPAKA") == 0)
1957 return cmd_sta_set_eapaka(dut, conn, cmd);
1958 if (strcasecmp(type, "EAPAKAPRIME") == 0)
1959 return cmd_sta_set_eapakaprime(dut, conn, cmd);
1960
1961 send_resp(dut, conn, SIGMA_ERROR,
1962 "ErrorCode,Unsupported Type value");
1963 return 0;
1964}
1965
1966
1967int ath6kl_client_uapsd(struct sigma_dut *dut, const char *intf, int uapsd)
1968{
1969#ifdef __linux__
1970 /* special handling for ath6kl */
1971 char path[128], fname[128], *pos;
1972 ssize_t res;
1973 FILE *f;
1974
1975 snprintf(path, sizeof(path), "/sys/class/net/%s/phy80211", intf);
1976 res = readlink(path, path, sizeof(path));
1977 if (res < 0)
1978 return 0; /* not ath6kl */
1979
1980 if (res >= (int) sizeof(path))
1981 res = sizeof(path) - 1;
1982 path[res] = '\0';
1983 pos = strrchr(path, '/');
1984 if (pos == NULL)
1985 pos = path;
1986 else
1987 pos++;
1988 snprintf(fname, sizeof(fname),
1989 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
1990 "create_qos", pos);
1991 if (!file_exists(fname))
1992 return 0; /* not ath6kl */
1993
1994 if (uapsd) {
1995 f = fopen(fname, "w");
1996 if (f == NULL)
1997 return -1;
1998
1999 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl create_qos");
2000 fprintf(f, "4 2 2 1 2 9999999 9999999 9999999 7777777 0 4 "
2001 "45000 200 56789000 56789000 5678900 0 0 9999999 "
2002 "20000 0\n");
2003 fclose(f);
2004 } else {
2005 snprintf(fname, sizeof(fname),
2006 "/sys/kernel/debug/ieee80211/%s/ath6kl/"
2007 "delete_qos", pos);
2008
2009 f = fopen(fname, "w");
2010 if (f == NULL)
2011 return -1;
2012
2013 sigma_dut_print(dut, DUT_MSG_DEBUG, "Use ath6kl delete_qos");
2014 fprintf(f, "2 4\n");
2015 fclose(f);
2016 }
2017#endif /* __linux__ */
2018
2019 return 0;
2020}
2021
2022
2023static int cmd_sta_set_uapsd(struct sigma_dut *dut, struct sigma_conn *conn,
2024 struct sigma_cmd *cmd)
2025{
2026 const char *intf = get_param(cmd, "Interface");
2027 /* const char *ssid = get_param(cmd, "ssid"); */
2028 const char *val;
2029 int max_sp_len = 4;
2030 int ac_be = 1, ac_bk = 1, ac_vi = 1, ac_vo = 1;
2031 char buf[100];
2032 int ret1, ret2;
2033
2034 val = get_param(cmd, "maxSPLength");
2035 if (val) {
2036 max_sp_len = atoi(val);
2037 if (max_sp_len != 0 && max_sp_len != 1 && max_sp_len != 2 &&
2038 max_sp_len != 4)
2039 return -1;
2040 }
2041
2042 val = get_param(cmd, "acBE");
2043 if (val)
2044 ac_be = atoi(val);
2045
2046 val = get_param(cmd, "acBK");
2047 if (val)
2048 ac_bk = atoi(val);
2049
2050 val = get_param(cmd, "acVI");
2051 if (val)
2052 ac_vi = atoi(val);
2053
2054 val = get_param(cmd, "acVO");
2055 if (val)
2056 ac_vo = atoi(val);
2057
2058 dut->client_uapsd = ac_be || ac_bk || ac_vi || ac_vo;
2059
2060 snprintf(buf, sizeof(buf), "P2P_SET client_apsd %d,%d,%d,%d;%d",
2061 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2062 ret1 = wpa_command(intf, buf);
2063
2064 snprintf(buf, sizeof(buf), "SET uapsd %d,%d,%d,%d;%d",
2065 ac_be, ac_bk, ac_vi, ac_vo, max_sp_len);
2066 ret2 = wpa_command(intf, buf);
2067
2068 if (ret1 && ret2) {
2069 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to set client mode "
2070 "UAPSD parameters.");
2071 return -2;
2072 }
2073
2074 if (ath6kl_client_uapsd(dut, intf, dut->client_uapsd) < 0) {
2075 send_resp(dut, conn, SIGMA_ERROR,
2076 "ErrorCode,Failed to set ath6kl QoS parameters");
2077 return 0;
2078 }
2079
2080 return 1;
2081}
2082
2083
2084static int cmd_sta_set_wmm(struct sigma_dut *dut, struct sigma_conn *conn,
2085 struct sigma_cmd *cmd)
2086{
2087 char buf[1000];
2088 const char *intf = get_param(cmd, "Interface");
2089 const char *grp = get_param(cmd, "Group");
2090 const char *act = get_param(cmd, "Action");
2091 const char *tid = get_param(cmd, "Tid");
2092 const char *dir = get_param(cmd, "Direction");
2093 const char *psb = get_param(cmd, "Psb");
2094 const char *up = get_param(cmd, "Up");
2095 const char *fixed = get_param(cmd, "Fixed");
2096 const char *size = get_param(cmd, "Size");
2097 const char *msize = get_param(cmd, "Maxsize");
2098 const char *minsi = get_param(cmd, "Min_srvc_intrvl");
2099 const char *maxsi = get_param(cmd, "Max_srvc_intrvl");
2100 const char *inact = get_param(cmd, "Inactivity");
2101 const char *sus = get_param(cmd, "Suspension");
2102 const char *mindr = get_param(cmd, "Mindatarate");
2103 const char *meandr = get_param(cmd, "Meandatarate");
2104 const char *peakdr = get_param(cmd, "Peakdatarate");
2105 const char *phyrate = get_param(cmd, "Phyrate");
2106 const char *burstsize = get_param(cmd, "Burstsize");
2107 const char *sba = get_param(cmd, "Sba");
2108 int direction;
2109 int handle;
2110 float sba_fv;
2111 int fixed_int;
2112 int psb_ts;
2113
2114 if (intf == NULL || grp == NULL || act == NULL )
2115 return -1;
2116
2117 if (strcasecmp(act, "addts") == 0) {
2118 if (tid == NULL || dir == NULL || psb == NULL ||
2119 up == NULL || fixed == NULL || size == NULL)
2120 return -1;
2121
2122 /*
2123 * Note: Sigma CAPI spec lists uplink, downlink, and bidi as the
2124 * possible values, but WMM-AC and V-E test scripts use "UP,
2125 * "DOWN", and "BIDI".
2126 */
2127 if (strcasecmp(dir, "uplink") == 0 ||
2128 strcasecmp(dir, "up") == 0) {
2129 direction = 0;
2130 } else if (strcasecmp(dir, "downlink") == 0 ||
2131 strcasecmp(dir, "down") == 0) {
2132 direction = 1;
2133 } else if (strcasecmp(dir, "bidi") == 0) {
2134 direction = 2;
2135 } else {
2136 sigma_dut_print(dut, DUT_MSG_ERROR,
2137 "Direction %s not supported", dir);
2138 return -1;
2139 }
2140
2141 if (strcasecmp(psb, "legacy") == 0) {
2142 psb_ts = 0;
2143 } else if (strcasecmp(psb, "uapsd") == 0) {
2144 psb_ts = 1;
2145 } else {
2146 sigma_dut_print(dut, DUT_MSG_ERROR,
2147 "PSB %s not supported", psb);
2148 return -1;
2149 }
2150
2151 if (atoi(tid) < 0 || atoi(tid) > 7) {
2152 sigma_dut_print(dut, DUT_MSG_ERROR,
2153 "TID %s not supported", tid);
2154 return -1;
2155 }
2156
2157 if (strcasecmp(fixed, "true") == 0) {
2158 fixed_int = 1;
2159 } else {
2160 fixed_int = 0;
2161 }
2162
2163 sba_fv = atof(sba);
2164
2165 dut->dialog_token++;
2166 handle = 7000 + dut->dialog_token;
2167
2168 /*
2169 * size: convert to hex
2170 * maxsi: convert to hex
2171 * mindr: convert to hex
2172 * meandr: convert to hex
2173 * peakdr: convert to hex
2174 * burstsize: convert to hex
2175 * phyrate: convert to hex
2176 * sba: convert to hex with modification
2177 * minsi: convert to integer
2178 * sus: convert to integer
2179 * inact: convert to integer
2180 * maxsi: convert to integer
2181 */
2182
2183 /*
2184 * The Nominal MSDU Size field is 2 octets long and contains an
2185 * unsigned integer that specifies the nominal size, in octets,
2186 * of MSDUs belonging to the traffic under this traffic
2187 * specification and is defined in Figure 16. If the Fixed
2188 * subfield is set to 1, then the size of the MSDU is fixed and
2189 * is indicated by the Size Subfield. If the Fixed subfield is
2190 * set to 0, then the size of the MSDU might not be fixed and
2191 * the Size indicates the nominal MSDU size.
2192 *
2193 * The Surplus Bandwidth Allowance Factor field is 2 octets long
2194 * and specifies the excess allocation of time (and bandwidth)
2195 * over and above the stated rates required to transport an MSDU
2196 * belonging to the traffic in this TSPEC. This field is
2197 * represented as an unsigned binary number with an implicit
2198 * binary point after the leftmost 3 bits. For example, an SBA
2199 * of 1.75 is represented as 0x3800. This field is included to
2200 * account for retransmissions. As such, the value of this field
2201 * must be greater than unity.
2202 */
2203
2204 snprintf(buf, sizeof(buf),
2205 "iwpriv %s addTspec %d %s %d %d %s 0x%X"
2206 " 0x%X 0x%X 0x%X"
2207 " 0x%X 0x%X 0x%X"
2208 " 0x%X %d %d %d %d"
2209 " %d %d",
2210 intf, handle, tid, direction, psb_ts, up,
2211 (unsigned int) ((fixed_int << 15) | atoi(size)),
2212 msize ? atoi(msize) : 0,
2213 mindr ? atoi(mindr) : 0,
2214 meandr ? atoi(meandr) : 0,
2215 peakdr ? atoi(peakdr) : 0,
2216 burstsize ? atoi(burstsize) : 0,
2217 phyrate ? atoi(phyrate) : 0,
2218 sba ? ((unsigned int) (((int) sba_fv << 13) |
2219 (int)((sba_fv - (int) sba_fv) *
2220 8192))) : 0,
2221 minsi ? atoi(minsi) : 0,
2222 sus ? atoi(sus) : 0,
2223 0, 0,
2224 inact ? atoi(inact) : 0,
2225 maxsi ? atoi(maxsi) : 0);
2226
2227 if (system(buf) != 0) {
2228 sigma_dut_print(dut, DUT_MSG_ERROR,
2229 "iwpriv addtspec request failed");
2230 send_resp(dut, conn, SIGMA_ERROR,
2231 "errorCode,Failed to execute addTspec command");
2232 return 0;
2233 }
2234
2235 sigma_dut_print(dut, DUT_MSG_INFO,
2236 "iwpriv addtspec request send");
2237
2238 /* Mapping handle to a TID */
2239 dut->tid_to_handle[atoi(tid)] = handle;
2240 } else if (strcasecmp(act, "delts") == 0) {
2241 if (tid == NULL)
2242 return -1;
2243
2244 if (atoi(tid) < 0 || atoi(tid) > 7) {
2245 sigma_dut_print(dut, DUT_MSG_ERROR,
2246 "TID %s not supported", tid);
2247 send_resp(dut, conn, SIGMA_ERROR,
2248 "errorCode,Unsupported TID");
2249 return 0;
2250 }
2251
2252 handle = dut->tid_to_handle[atoi(tid)];
2253
2254 if (handle < 7000 || handle > 7255) {
2255 /* Invalid handle ie no mapping for that TID */
2256 sigma_dut_print(dut, DUT_MSG_ERROR,
2257 "handle-> %d not found", handle);
2258 }
2259
2260 snprintf(buf, sizeof(buf), "iwpriv %s delTspec %d",
2261 intf, handle);
2262
2263 if (system(buf) != 0) {
2264 sigma_dut_print(dut, DUT_MSG_ERROR,
2265 "iwpriv deltspec request failed");
2266 send_resp(dut, conn, SIGMA_ERROR,
2267 "errorCode,Failed to execute delTspec command");
2268 return 0;
2269 }
2270
2271 sigma_dut_print(dut, DUT_MSG_INFO,
2272 "iwpriv deltspec request send");
2273
2274 dut->tid_to_handle[atoi(tid)] = 0;
2275 } else {
2276 sigma_dut_print(dut, DUT_MSG_ERROR,
2277 "Action type %s not supported", act);
2278 send_resp(dut, conn, SIGMA_ERROR,
2279 "errorCode,Unsupported Action");
2280 return 0;
2281 }
2282
2283 return 1;
2284}
2285
2286
2287static int cmd_sta_associate(struct sigma_dut *dut, struct sigma_conn *conn,
2288 struct sigma_cmd *cmd)
2289{
2290 /* const char *intf = get_param(cmd, "Interface"); */
2291 const char *ssid = get_param(cmd, "ssid");
2292 const char *wps_param = get_param(cmd, "WPS");
2293 const char *bssid = get_param(cmd, "bssid");
Jouni Malinen46a19b62017-06-23 14:31:27 +03002294 const char *chan = get_param(cmd, "channel");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002295 int wps = 0;
Jouni Malinen3c367e82017-06-23 17:01:47 +03002296 char buf[1000], extra[50];
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002297
2298 if (ssid == NULL)
2299 return -1;
2300
Jouni Malinen3c367e82017-06-23 17:01:47 +03002301 if (dut->rsne_override) {
2302 snprintf(buf, sizeof(buf), "TEST_ASSOC_IE %s",
2303 dut->rsne_override);
2304 if (wpa_command(get_station_ifname(), buf) < 0) {
2305 send_resp(dut, conn, SIGMA_ERROR,
2306 "ErrorCode,Failed to set DEV_CONFIGURE_IE RSNE override");
2307 return 0;
2308 }
2309 }
2310
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002311 if (wps_param &&
2312 (strcmp(wps_param, "1") == 0 || strcasecmp(wps_param, "On") == 0))
2313 wps = 1;
2314
2315 if (wps) {
2316 if (dut->wps_method == WFA_CS_WPS_NOT_READY) {
2317 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,WPS "
2318 "parameters not yet set");
2319 return 0;
2320 }
2321 if (dut->wps_method == WFA_CS_WPS_PBC) {
2322 if (wpa_command(get_station_ifname(), "WPS_PBC") < 0)
2323 return -2;
2324 } else {
2325 snprintf(buf, sizeof(buf), "WPS_PIN any %s",
2326 dut->wps_pin);
2327 if (wpa_command(get_station_ifname(), buf) < 0)
2328 return -2;
2329 }
2330 } else {
2331 if (strcmp(ssid, dut->infra_ssid) != 0) {
2332 printf("No network parameters known for network "
2333 "(ssid='%s')", ssid);
2334 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2335 "No network parameters known for network");
2336 return 0;
2337 }
2338
2339 if (bssid &&
2340 set_network(get_station_ifname(), dut->infra_network_id,
2341 "bssid", bssid) < 0) {
2342 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2343 "Invalid bssid argument");
2344 return 0;
2345 }
2346
Jouni Malinen46a19b62017-06-23 14:31:27 +03002347 extra[0] = '\0';
2348 if (chan)
2349 snprintf(extra, sizeof(extra), " freq=%u",
2350 channel_to_freq(atoi(chan)));
2351 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d%s",
2352 dut->infra_network_id, extra);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002353 if (wpa_command(get_station_ifname(), buf) < 0) {
2354 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to select "
2355 "network id %d on %s",
2356 dut->infra_network_id,
2357 get_station_ifname());
2358 return -2;
2359 }
2360 }
2361
2362 return 1;
2363}
2364
2365
2366static int run_hs20_osu(struct sigma_dut *dut, const char *params)
2367{
2368 char buf[500], cmd[200];
2369 int res;
2370
2371 /* Use hs20-osu-client file at the current dir, if found; otherwise use
2372 * default path */
2373 res = snprintf(cmd, sizeof(cmd),
2374 "%s -w \"%s\" -r hs20-osu-client.res %s%s -dddKt -f Logs/hs20-osu-client.txt",
2375 file_exists("./hs20-osu-client") ?
2376 "./hs20-osu-client" : "hs20-osu-client",
2377 sigma_wpas_ctrl,
2378 dut->summary_log ? "-s " : "",
2379 dut->summary_log ? dut->summary_log : "");
2380 if (res < 0 || res >= (int) sizeof(cmd))
2381 return -1;
2382
2383 res = snprintf(buf, sizeof(buf), "%s %s", cmd, params);
2384 if (res < 0 || res >= (int) sizeof(buf))
2385 return -1;
2386 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
2387
2388 if (system(buf) != 0) {
2389 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to run: %s", buf);
2390 return -1;
2391 }
2392 sigma_dut_print(dut, DUT_MSG_DEBUG,
2393 "Completed hs20-osu-client operation");
2394
2395 return 0;
2396}
2397
2398
2399static int download_ppsmo(struct sigma_dut *dut,
2400 struct sigma_conn *conn,
2401 const char *intf,
2402 struct sigma_cmd *cmd)
2403{
2404 const char *name, *path, *val;
2405 char url[500], buf[600], fbuf[100];
2406 char *fqdn = NULL;
2407
2408 name = get_param(cmd, "FileName");
2409 path = get_param(cmd, "FilePath");
2410 if (name == NULL || path == NULL)
2411 return -1;
2412
2413 if (strcasecmp(path, "VendorSpecific") == 0) {
2414 snprintf(url, sizeof(url), "PPS/%s", name);
2415 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured PPS MO "
2416 "from the device (%s)", url);
2417 if (!file_exists(url)) {
2418 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2419 "PPS MO file does not exist");
2420 return 0;
2421 }
2422 snprintf(buf, sizeof(buf), "cp %s pps-tnds.xml", url);
2423 if (system(buf) != 0) {
2424 send_resp(dut, conn, SIGMA_ERROR,
2425 "errorCode,Failed to copy PPS MO");
2426 return 0;
2427 }
2428 } else if (strncasecmp(path, "http:", 5) != 0 &&
2429 strncasecmp(path, "https:", 6) != 0) {
2430 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2431 "Unsupported FilePath value");
2432 return 0;
2433 } else {
2434 snprintf(url, sizeof(url), "%s/%s", path, name);
2435 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading PPS MO from %s",
2436 url);
2437 snprintf(buf, sizeof(buf), "wget -T 10 -t 3 -O pps-tnds.xml '%s'", url);
2438 remove("pps-tnds.xml");
2439 if (system(buf) != 0) {
2440 send_resp(dut, conn, SIGMA_ERROR,
2441 "errorCode,Failed to download PPS MO");
2442 return 0;
2443 }
2444 }
2445
2446 if (run_hs20_osu(dut, "from_tnds pps-tnds.xml pps.xml") < 0) {
2447 send_resp(dut, conn, SIGMA_ERROR,
2448 "errorCode,Failed to parse downloaded PPSMO");
2449 return 0;
2450 }
2451 unlink("pps-tnds.xml");
2452
2453 val = get_param(cmd, "managementTreeURI");
2454 if (val) {
2455 const char *pos, *end;
2456 sigma_dut_print(dut, DUT_MSG_DEBUG, "managementTreeURI: %s",
2457 val);
2458 if (strncmp(val, "./Wi-Fi/", 8) != 0) {
2459 send_resp(dut, conn, SIGMA_ERROR,
2460 "errorCode,Invalid managementTreeURI prefix");
2461 return 0;
2462 }
2463 pos = val + 8;
2464 end = strchr(pos, '/');
2465 if (end == NULL ||
2466 strcmp(end, "/PerProviderSubscription") != 0) {
2467 send_resp(dut, conn, SIGMA_ERROR,
2468 "errorCode,Invalid managementTreeURI postfix");
2469 return 0;
2470 }
2471 if (end - pos >= (int) sizeof(fbuf)) {
2472 send_resp(dut, conn, SIGMA_ERROR,
2473 "errorCode,Too long FQDN in managementTreeURI");
2474 return 0;
2475 }
2476 memcpy(fbuf, pos, end - pos);
2477 fbuf[end - pos] = '\0';
2478 fqdn = fbuf;
2479 sigma_dut_print(dut, DUT_MSG_INFO,
2480 "FQDN from managementTreeURI: %s", fqdn);
2481 } else if (run_hs20_osu(dut, "get_fqdn pps.xml") == 0) {
2482 FILE *f = fopen("pps-fqdn", "r");
2483 if (f) {
2484 if (fgets(fbuf, sizeof(fbuf), f)) {
2485 fbuf[sizeof(fbuf) - 1] = '\0';
2486 fqdn = fbuf;
2487 sigma_dut_print(dut, DUT_MSG_DEBUG,
2488 "Use FQDN %s", fqdn);
2489 }
2490 fclose(f);
2491 }
2492 }
2493
2494 if (fqdn == NULL) {
2495 send_resp(dut, conn, SIGMA_ERROR,
2496 "errorCode,No FQDN specified");
2497 return 0;
2498 }
2499
2500 mkdir("SP", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2501 snprintf(buf, sizeof(buf), "SP/%s", fqdn);
2502 mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
2503
2504 snprintf(buf, sizeof(buf), "SP/%s/pps.xml", fqdn);
2505 if (rename("pps.xml", buf) < 0) {
2506 send_resp(dut, conn, SIGMA_ERROR,
2507 "errorCode,Could not move PPS MO");
2508 return 0;
2509 }
2510
2511 if (strcasecmp(path, "VendorSpecific") == 0) {
2512 snprintf(buf, sizeof(buf), "cp Certs/ca.pem SP/%s/ca.pem",
2513 fqdn);
2514 if (system(buf)) {
2515 send_resp(dut, conn, SIGMA_ERROR,
2516 "errorCode,Failed to copy OSU CA cert");
2517 return 0;
2518 }
2519
2520 snprintf(buf, sizeof(buf),
2521 "cp Certs/aaa-ca.pem SP/%s/aaa-ca.pem",
2522 fqdn);
2523 if (system(buf)) {
2524 send_resp(dut, conn, SIGMA_ERROR,
2525 "errorCode,Failed to copy AAA CA cert");
2526 return 0;
2527 }
2528 } else {
2529 snprintf(buf, sizeof(buf),
2530 "dl_osu_ca SP/%s/pps.xml SP/%s/ca.pem",
2531 fqdn, fqdn);
2532 if (run_hs20_osu(dut, buf) < 0) {
2533 send_resp(dut, conn, SIGMA_ERROR,
2534 "errorCode,Failed to download OSU CA cert");
2535 return 0;
2536 }
2537
2538 snprintf(buf, sizeof(buf),
2539 "dl_aaa_ca SP/%s/pps.xml SP/%s/aaa-ca.pem",
2540 fqdn, fqdn);
2541 if (run_hs20_osu(dut, buf) < 0) {
2542 sigma_dut_print(dut, DUT_MSG_INFO,
2543 "Failed to download AAA CA cert");
2544 }
2545 }
2546
2547 if (file_exists("next-client-cert.pem")) {
2548 snprintf(buf, sizeof(buf), "SP/%s/client-cert.pem", fqdn);
2549 if (rename("next-client-cert.pem", buf) < 0) {
2550 send_resp(dut, conn, SIGMA_ERROR,
2551 "errorCode,Could not move client certificate");
2552 return 0;
2553 }
2554 }
2555
2556 if (file_exists("next-client-key.pem")) {
2557 snprintf(buf, sizeof(buf), "SP/%s/client-key.pem", fqdn);
2558 if (rename("next-client-key.pem", buf) < 0) {
2559 send_resp(dut, conn, SIGMA_ERROR,
2560 "errorCode,Could not move client key");
2561 return 0;
2562 }
2563 }
2564
2565 snprintf(buf, sizeof(buf), "set_pps SP/%s/pps.xml", fqdn);
2566 if (run_hs20_osu(dut, buf) < 0) {
2567 send_resp(dut, conn, SIGMA_ERROR,
2568 "errorCode,Failed to configure credential from "
2569 "PPSMO");
2570 return 0;
2571 }
2572
2573 return 1;
2574}
2575
2576
2577static int download_cert(struct sigma_dut *dut,
2578 struct sigma_conn *conn,
2579 const char *intf,
2580 struct sigma_cmd *cmd)
2581{
2582 const char *name, *path;
2583 char url[500], buf[600];
2584
2585 name = get_param(cmd, "FileName");
2586 path = get_param(cmd, "FilePath");
2587 if (name == NULL || path == NULL)
2588 return -1;
2589
2590 if (strcasecmp(path, "VendorSpecific") == 0) {
2591 snprintf(url, sizeof(url), "Certs/%s-cert.pem", name);
2592 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2593 "certificate from the device (%s)", url);
2594 if (!file_exists(url)) {
2595 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2596 "certificate file does not exist");
2597 return 0;
2598 }
2599 snprintf(buf, sizeof(buf), "cp %s next-client-cert.pem", url);
2600 if (system(buf) != 0) {
2601 send_resp(dut, conn, SIGMA_ERROR,
2602 "errorCode,Failed to copy client "
2603 "certificate");
2604 return 0;
2605 }
2606
2607 snprintf(url, sizeof(url), "Certs/%s-key.pem", name);
2608 sigma_dut_print(dut, DUT_MSG_INFO, "Use pre-configured client "
2609 "private key from the device (%s)", url);
2610 if (!file_exists(url)) {
2611 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Requested "
2612 "private key file does not exist");
2613 return 0;
2614 }
2615 snprintf(buf, sizeof(buf), "cp %s next-client-key.pem", url);
2616 if (system(buf) != 0) {
2617 send_resp(dut, conn, SIGMA_ERROR,
2618 "errorCode,Failed to copy client key");
2619 return 0;
2620 }
2621 } else if (strncasecmp(path, "http:", 5) != 0 &&
2622 strncasecmp(path, "https:", 6) != 0) {
2623 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,"
2624 "Unsupported FilePath value");
2625 return 0;
2626 } else {
2627 snprintf(url, sizeof(url), "%s/%s.pem", path, name);
2628 sigma_dut_print(dut, DUT_MSG_INFO, "Downloading client "
2629 "certificate/key from %s", url);
2630 snprintf(buf, sizeof(buf),
2631 "wget -T 10 -t 3 -O next-client-cert.pem '%s'", url);
2632 if (system(buf) != 0) {
2633 send_resp(dut, conn, SIGMA_ERROR,
2634 "errorCode,Failed to download client "
2635 "certificate");
2636 return 0;
2637 }
2638
2639 if (system("cp next-client-cert.pem next-client-key.pem") != 0)
2640 {
2641 send_resp(dut, conn, SIGMA_ERROR,
2642 "errorCode,Failed to copy client key");
2643 return 0;
2644 }
2645 }
2646
2647 return 1;
2648}
2649
2650
2651static int cmd_sta_preset_testparameters_hs2_r2(struct sigma_dut *dut,
2652 struct sigma_conn *conn,
2653 const char *intf,
2654 struct sigma_cmd *cmd)
2655{
2656 const char *val;
2657
2658 val = get_param(cmd, "FileType");
2659 if (val && strcasecmp(val, "PPSMO") == 0)
2660 return download_ppsmo(dut, conn, intf, cmd);
2661 if (val && strcasecmp(val, "CERT") == 0)
2662 return download_cert(dut, conn, intf, cmd);
2663 if (val) {
2664 send_resp(dut, conn, SIGMA_ERROR,
2665 "ErrorCode,Unsupported FileType");
2666 return 0;
2667 }
2668
2669 return 1;
2670}
2671
2672
2673static void ath_sta_set_noack(struct sigma_dut *dut, const char *intf,
2674 const char *val)
2675{
2676 int counter = 0;
2677 char token[50];
2678 char *result;
2679 char buf[100];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302680 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002681
Peng Xub8fc5cc2017-05-10 17:27:28 -07002682 strlcpy(token, val, sizeof(token));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002683 token[sizeof(token) - 1] = '\0';
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302684 result = strtok_r(token, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002685 while (result) {
2686 if (strcmp(result, "disable") == 0) {
2687 snprintf(buf, sizeof(buf),
2688 "iwpriv %s noackpolicy %d 1 0",
2689 intf, counter);
2690 } else {
2691 snprintf(buf, sizeof(buf),
2692 "iwpriv %s noackpolicy %d 1 1",
2693 intf, counter);
2694 }
2695 if (system(buf) != 0) {
2696 sigma_dut_print(dut, DUT_MSG_ERROR,
2697 "iwpriv noackpolicy failed");
2698 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05302699 result = strtok_r(NULL, ":", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002700 counter++;
2701 }
2702}
2703
2704
2705static void ath_sta_set_rts(struct sigma_dut *dut, const char *intf,
2706 const char *val)
2707{
2708 char buf[100];
2709
2710 snprintf(buf, sizeof(buf), "iwconfig %s rts %s", intf, val);
2711 if (system(buf) != 0) {
2712 sigma_dut_print(dut, DUT_MSG_ERROR, "iwconfig RTS failed");
2713 }
2714}
2715
2716
2717static void ath_sta_set_wmm(struct sigma_dut *dut, const char *intf,
2718 const char *val)
2719{
2720 char buf[100];
2721
2722 if (strcasecmp(val, "off") == 0) {
2723 snprintf(buf, sizeof(buf), "iwpriv %s wmm 0", intf);
2724 if (system(buf) != 0) {
2725 sigma_dut_print(dut, DUT_MSG_ERROR,
2726 "Failed to turn off WMM");
2727 }
2728 }
2729}
2730
2731
2732static void ath_sta_set_sgi(struct sigma_dut *dut, const char *intf,
2733 const char *val)
2734{
2735 char buf[100];
2736 int sgi20;
2737
2738 sgi20 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
2739
2740 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi20);
2741 if (system(buf) != 0)
2742 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv shortgi failed");
2743}
2744
2745
2746static void ath_sta_set_11nrates(struct sigma_dut *dut, const char *intf,
2747 const char *val)
2748{
2749 char buf[100];
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05302750 int rate_code, v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002751
2752 /* Disable Tx Beam forming when using a fixed rate */
2753 ath_disable_txbf(dut, intf);
2754
Pradeep Reddy POTTETI67376b72016-10-25 20:08:17 +05302755 v = atoi(val);
2756 if (v < 0 || v > 32) {
2757 sigma_dut_print(dut, DUT_MSG_ERROR,
2758 "Invalid Fixed MCS rate: %d", v);
2759 return;
2760 }
2761 rate_code = 0x80 + v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002762
2763 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0x%x",
2764 intf, rate_code);
2765 if (system(buf) != 0) {
2766 sigma_dut_print(dut, DUT_MSG_ERROR,
2767 "iwpriv set11NRates failed");
2768 }
2769
2770 /* Channel width gets messed up, fix this */
2771 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d", intf, dut->chwidth);
2772 if (system(buf) != 0)
2773 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv chwidth failed");
2774}
2775
2776
2777static void ath_sta_set_amsdu(struct sigma_dut *dut, const char *intf,
2778 const char *val)
2779{
2780 char buf[60];
2781
2782 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)
2783 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 2", intf);
2784 else
2785 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
2786
2787 if (system(buf) != 0)
2788 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv amsdu failed");
2789}
2790
2791
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07002792static int iwpriv_sta_set_ampdu(struct sigma_dut *dut, const char *intf,
2793 int ampdu)
2794{
2795 char buf[60];
2796
2797 snprintf(buf, sizeof(buf), "iwpriv %s ampdu %d", intf, ampdu);
2798 if (system(buf) != 0) {
2799 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv ampdu failed");
2800 return -1;
2801 }
2802
2803 return 0;
2804}
2805
2806
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002807static void ath_sta_set_stbc(struct sigma_dut *dut, const char *intf,
2808 const char *val)
2809{
2810 char buf[60];
2811
2812 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
2813 if (system(buf) != 0) {
2814 sigma_dut_print(dut, DUT_MSG_ERROR,
2815 "iwpriv tx_stbc failed");
2816 }
2817
2818 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
2819 if (system(buf) != 0) {
2820 sigma_dut_print(dut, DUT_MSG_ERROR,
2821 "iwpriv rx_stbc failed");
2822 }
2823}
2824
2825
2826static int wcn_sta_set_cts_width(struct sigma_dut *dut, const char *intf,
2827 const char *val)
2828{
2829 char buf[60];
2830
Peng Xucc317ed2017-05-18 16:44:37 -07002831 if (strcmp(val, "160") == 0) {
2832 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 5", intf);
2833 } else if (strcmp(val, "80") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02002834 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
2835 } else if (strcmp(val, "40") == 0) {
2836 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 2", intf);
2837 } else if (strcmp(val, "20") == 0) {
2838 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 1", intf);
2839 } else if (strcasecmp(val, "Auto") == 0) {
2840 buf[0] = '\0';
2841 } else {
2842 sigma_dut_print(dut, DUT_MSG_ERROR,
2843 "WIDTH/CTS_WIDTH value not supported");
2844 return -1;
2845 }
2846
2847 if (buf[0] != '\0' && system(buf) != 0) {
2848 sigma_dut_print(dut, DUT_MSG_ERROR,
2849 "Failed to set WIDTH/CTS_WIDTH");
2850 return -1;
2851 }
2852
2853 return 0;
2854}
2855
2856
2857int ath_set_width(struct sigma_dut *dut, struct sigma_conn *conn,
2858 const char *intf, const char *val)
2859{
2860 char buf[60];
2861
2862 if (strcasecmp(val, "Auto") == 0) {
2863 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
2864 dut->chwidth = 0;
2865 } else if (strcasecmp(val, "20") == 0) {
2866 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
2867 dut->chwidth = 0;
2868 } else if (strcasecmp(val, "40") == 0) {
2869 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 1", intf);
2870 dut->chwidth = 1;
2871 } else if (strcasecmp(val, "80") == 0) {
2872 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
2873 dut->chwidth = 2;
2874 } else if (strcasecmp(val, "160") == 0) {
2875 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 3", intf);
2876 dut->chwidth = 3;
2877 } else {
2878 send_resp(dut, conn, SIGMA_ERROR,
2879 "ErrorCode,WIDTH not supported");
2880 return -1;
2881 }
2882
2883 if (system(buf) != 0) {
2884 sigma_dut_print(dut, DUT_MSG_ERROR,
2885 "iwpriv chwidth failed");
2886 }
2887
2888 return 0;
2889}
2890
2891
2892static int wcn_sta_set_sp_stream(struct sigma_dut *dut, const char *intf,
2893 const char *val)
2894{
2895 char buf[60];
2896
2897 if (strcmp(val, "1SS") == 0) {
2898 snprintf(buf, sizeof(buf), "iwpriv %s nss 1", intf);
2899 } else if (strcmp(val, "2SS") == 0) {
2900 snprintf(buf, sizeof(buf), "iwpriv %s nss 2", intf);
2901 } else {
2902 sigma_dut_print(dut, DUT_MSG_ERROR,
2903 "SP_STREAM value not supported");
2904 return -1;
2905 }
2906
2907 if (system(buf) != 0) {
2908 sigma_dut_print(dut, DUT_MSG_ERROR,
2909 "Failed to set SP_STREAM");
2910 return -1;
2911 }
2912
2913 return 0;
2914}
2915
2916
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05302917static void wcn_sta_set_stbc(struct sigma_dut *dut, const char *intf,
2918 const char *val)
2919{
2920 char buf[60];
2921
2922 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc %s", intf, val);
2923 if (system(buf) != 0)
2924 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv tx_stbc failed");
2925
2926 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc %s", intf, val);
2927 if (system(buf) != 0)
2928 sigma_dut_print(dut, DUT_MSG_ERROR, "iwpriv rx_stbc failed");
2929}
2930
2931
Ashwini Patil68d02cd2017-01-10 15:39:16 +05302932static int mbo_set_cellular_data_capa(struct sigma_dut *dut,
2933 struct sigma_conn *conn,
2934 const char *intf, int capa)
2935{
2936 char buf[32];
2937
2938 if (capa > 0 && capa < 4) {
2939 snprintf(buf, sizeof(buf), "SET mbo_cell_capa %d", capa);
2940 if (wpa_command(intf, buf) < 0) {
2941 send_resp(dut, conn, SIGMA_ERROR,
2942 "ErrorCode, Failed to set cellular data capability");
2943 return 0;
2944 }
2945 return 1;
2946 }
2947
2948 sigma_dut_print(dut, DUT_MSG_ERROR,
2949 "Invalid Cellular data capability: %d", capa);
2950 send_resp(dut, conn, SIGMA_INVALID,
2951 "ErrorCode,Invalid cellular data capability");
2952 return 0;
2953}
2954
2955
Ashwini Patil9183fdb2017-04-13 16:58:25 +05302956static int mbo_set_roaming(struct sigma_dut *dut, struct sigma_conn *conn,
2957 const char *intf, const char *val)
2958{
2959 if (strcasecmp(val, "Disable") == 0) {
2960 if (wpa_command(intf, "SET roaming 0") < 0) {
2961 send_resp(dut, conn, SIGMA_ERROR,
2962 "ErrorCode,Failed to disable roaming");
2963 return 0;
2964 }
2965 return 1;
2966 }
2967
2968 if (strcasecmp(val, "Enable") == 0) {
2969 if (wpa_command(intf, "SET roaming 1") < 0) {
2970 send_resp(dut, conn, SIGMA_ERROR,
2971 "ErrorCode,Failed to enable roaming");
2972 return 0;
2973 }
2974 return 1;
2975 }
2976
2977 sigma_dut_print(dut, DUT_MSG_ERROR,
2978 "Invalid value provided for roaming: %s", val);
2979 send_resp(dut, conn, SIGMA_INVALID,
2980 "ErrorCode,Unknown value provided for Roaming");
2981 return 0;
2982}
2983
2984
Ashwini Patila75de5a2017-04-13 16:35:05 +05302985static int mbo_set_assoc_disallow(struct sigma_dut *dut,
2986 struct sigma_conn *conn,
2987 const char *intf, const char *val)
2988{
2989 if (strcasecmp(val, "Disable") == 0) {
2990 if (wpa_command(intf, "SET ignore_assoc_disallow 1") < 0) {
2991 send_resp(dut, conn, SIGMA_ERROR,
2992 "ErrorCode,Failed to disable Assoc_disallow");
2993 return 0;
2994 }
2995 return 1;
2996 }
2997
2998 if (strcasecmp(val, "Enable") == 0) {
2999 if (wpa_command(intf, "SET ignore_assoc_disallow 0") < 0) {
3000 send_resp(dut, conn, SIGMA_ERROR,
3001 "ErrorCode,Failed to enable Assoc_disallow");
3002 return 0;
3003 }
3004 return 1;
3005 }
3006
3007 sigma_dut_print(dut, DUT_MSG_ERROR,
3008 "Invalid value provided for Assoc_disallow: %s", val);
3009 send_resp(dut, conn, SIGMA_INVALID,
3010 "ErrorCode,Unknown value provided for Assoc_disallow");
3011 return 0;
3012}
3013
3014
Ashwini Patilc63161e2017-04-13 16:30:23 +05303015static int mbo_set_bss_trans_req(struct sigma_dut *dut, struct sigma_conn *conn,
3016 const char *intf, const char *val)
3017{
3018 if (strcasecmp(val, "Reject") == 0) {
3019 if (wpa_command(intf, "SET reject_btm_req_reason 1") < 0) {
3020 send_resp(dut, conn, SIGMA_ERROR,
3021 "ErrorCode,Failed to Reject BTM Request");
3022 return 0;
3023 }
3024 return 1;
3025 }
3026
3027 if (strcasecmp(val, "Accept") == 0) {
3028 if (wpa_command(intf, "SET reject_btm_req_reason 0") < 0) {
3029 send_resp(dut, conn, SIGMA_ERROR,
3030 "ErrorCode,Failed to Accept BTM Request");
3031 return 0;
3032 }
3033 return 1;
3034 }
3035
3036 sigma_dut_print(dut, DUT_MSG_ERROR,
3037 "Invalid value provided for BSS_Transition: %s", val);
3038 send_resp(dut, conn, SIGMA_INVALID,
3039 "ErrorCode,Unknown value provided for BSS_Transition");
3040 return 0;
3041}
3042
3043
Ashwini Patil00402582017-04-13 12:29:39 +05303044static int mbo_set_non_pref_ch_list(struct sigma_dut *dut,
3045 struct sigma_conn *conn,
3046 const char *intf,
3047 struct sigma_cmd *cmd)
3048{
3049 const char *ch, *pref, *op_class, *reason;
3050 char buf[120];
3051 int len, ret;
3052
3053 pref = get_param(cmd, "Ch_Pref");
3054 if (!pref)
3055 return 1;
3056
3057 if (strcasecmp(pref, "clear") == 0) {
3058 free(dut->non_pref_ch_list);
3059 dut->non_pref_ch_list = NULL;
3060 } else {
3061 op_class = get_param(cmd, "Ch_Op_Class");
3062 if (!op_class) {
3063 send_resp(dut, conn, SIGMA_INVALID,
3064 "ErrorCode,Ch_Op_Class not provided");
3065 return 0;
3066 }
3067
3068 ch = get_param(cmd, "Ch_Pref_Num");
3069 if (!ch) {
3070 send_resp(dut, conn, SIGMA_INVALID,
3071 "ErrorCode,Ch_Pref_Num not provided");
3072 return 0;
3073 }
3074
3075 reason = get_param(cmd, "Ch_Reason_Code");
3076 if (!reason) {
3077 send_resp(dut, conn, SIGMA_INVALID,
3078 "ErrorCode,Ch_Reason_Code not provided");
3079 return 0;
3080 }
3081
3082 if (!dut->non_pref_ch_list) {
3083 dut->non_pref_ch_list =
3084 calloc(1, NON_PREF_CH_LIST_SIZE);
3085 if (!dut->non_pref_ch_list) {
3086 send_resp(dut, conn, SIGMA_ERROR,
3087 "ErrorCode,Failed to allocate memory for non_pref_ch_list");
3088 return 0;
3089 }
3090 }
3091 len = strlen(dut->non_pref_ch_list);
3092 ret = snprintf(dut->non_pref_ch_list + len,
3093 NON_PREF_CH_LIST_SIZE - len,
3094 " %s:%s:%s:%s", op_class, ch, pref, reason);
3095 if (ret > 0 && ret < NON_PREF_CH_LIST_SIZE - len) {
3096 sigma_dut_print(dut, DUT_MSG_DEBUG, "non_pref_list: %s",
3097 dut->non_pref_ch_list);
3098 } else {
3099 sigma_dut_print(dut, DUT_MSG_ERROR,
3100 "snprintf failed for non_pref_list, ret = %d",
3101 ret);
3102 send_resp(dut, conn, SIGMA_ERROR,
3103 "ErrorCode,snprintf failed");
3104 free(dut->non_pref_ch_list);
3105 dut->non_pref_ch_list = NULL;
3106 return 0;
3107 }
3108 }
3109
3110 ret = snprintf(buf, sizeof(buf), "SET non_pref_chan%s",
3111 dut->non_pref_ch_list ? dut->non_pref_ch_list : " ");
3112 if (ret < 0 || ret >= (int) sizeof(buf)) {
3113 sigma_dut_print(dut, DUT_MSG_DEBUG,
3114 "snprintf failed for set non_pref_chan, ret: %d",
3115 ret);
3116 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,snprint failed");
3117 return 0;
3118 }
3119
3120 if (wpa_command(intf, buf) < 0) {
3121 send_resp(dut, conn, SIGMA_ERROR,
3122 "ErrorCode,Failed to set non-preferred channel list");
3123 return 0;
3124 }
3125
3126 return 1;
3127}
3128
3129
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003130static int cmd_sta_preset_testparameters(struct sigma_dut *dut,
3131 struct sigma_conn *conn,
3132 struct sigma_cmd *cmd)
3133{
3134 const char *intf = get_param(cmd, "Interface");
3135 const char *val;
3136
3137 val = get_param(cmd, "Program");
Peng Xue9fa7952017-05-09 15:59:49 -07003138 if (val && strcasecmp(val, "HS2-R2") == 0)
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003139 return cmd_sta_preset_testparameters_hs2_r2(dut, conn, intf,
3140 cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003141
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07003142 if (val && strcasecmp(val, "LOC") == 0)
3143 return loc_cmd_sta_preset_testparameters(dut, conn, cmd);
3144
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003145#ifdef ANDROID_NAN
3146 if (val && strcasecmp(val, "NAN") == 0)
3147 return nan_cmd_sta_preset_testparameters(dut, conn, cmd);
3148#endif /* ANDROID_NAN */
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07003149#ifdef MIRACAST
3150 if (val && (strcasecmp(val, "WFD") == 0 ||
3151 strcasecmp(val, "DisplayR2") == 0))
3152 return miracast_preset_testparameters(dut, conn, cmd);
3153#endif /* MIRACAST */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003154
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303155 if (val && strcasecmp(val, "MBO") == 0) {
3156 val = get_param(cmd, "Cellular_Data_Cap");
3157 if (val &&
3158 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
3159 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05303160
3161 val = get_param(cmd, "Ch_Pref");
3162 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
3163 return 0;
3164
Ashwini Patilc63161e2017-04-13 16:30:23 +05303165 val = get_param(cmd, "BSS_Transition");
3166 if (val && mbo_set_bss_trans_req(dut, conn, intf, val) == 0)
3167 return 0;
3168
Ashwini Patila75de5a2017-04-13 16:35:05 +05303169 val = get_param(cmd, "Assoc_Disallow");
3170 if (val && mbo_set_assoc_disallow(dut, conn, intf, val) == 0)
3171 return 0;
3172
Ashwini Patil9183fdb2017-04-13 16:58:25 +05303173 val = get_param(cmd, "Roaming");
3174 if (val && mbo_set_roaming(dut, conn, intf, val) == 0)
3175 return 0;
3176
Ashwini Patil68d02cd2017-01-10 15:39:16 +05303177 return 1;
3178 }
3179
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003180#if 0
3181 val = get_param(cmd, "Supplicant");
3182 if (val && strcasecmp(val, "Default") != 0) {
3183 send_resp(dut, conn, SIGMA_ERROR,
3184 "ErrorCode,Only default(Vendor) supplicant "
3185 "supported");
3186 return 0;
3187 }
3188#endif
3189
3190 val = get_param(cmd, "RTS");
3191 if (val) {
3192 switch (get_driver_type()) {
3193 case DRIVER_ATHEROS:
3194 ath_sta_set_rts(dut, intf, val);
3195 break;
3196 default:
3197#if 0
3198 send_resp(dut, conn, SIGMA_ERROR,
3199 "ErrorCode,Setting RTS not supported");
3200 return 0;
3201#else
3202 sigma_dut_print(dut, DUT_MSG_DEBUG,
3203 "Setting RTS not supported");
3204 break;
3205#endif
3206 }
3207 }
3208
3209#if 0
3210 val = get_param(cmd, "FRGMNT");
3211 if (val) {
3212 /* TODO */
3213 send_resp(dut, conn, SIGMA_ERROR,
3214 "ErrorCode,Setting FRGMNT not supported");
3215 return 0;
3216 }
3217#endif
3218
3219#if 0
3220 val = get_param(cmd, "Preamble");
3221 if (val) {
3222 /* TODO: Long/Short */
3223 send_resp(dut, conn, SIGMA_ERROR,
3224 "ErrorCode,Setting Preamble not supported");
3225 return 0;
3226 }
3227#endif
3228
3229 val = get_param(cmd, "Mode");
3230 if (val) {
3231 if (strcmp(val, "11b") == 0 ||
3232 strcmp(val, "11g") == 0 ||
3233 strcmp(val, "11a") == 0 ||
3234 strcmp(val, "11n") == 0 ||
3235 strcmp(val, "11ng") == 0 ||
3236 strcmp(val, "11nl") == 0 ||
3237 strcmp(val, "11nl(nabg)") == 0 ||
3238 strcmp(val, "AC") == 0 ||
3239 strcmp(val, "11AC") == 0 ||
3240 strcmp(val, "11ac") == 0 ||
3241 strcmp(val, "11na") == 0 ||
3242 strcmp(val, "11an") == 0) {
3243 /* STA supports all modes by default */
3244 } else {
3245 send_resp(dut, conn, SIGMA_ERROR,
3246 "ErrorCode,Setting Mode not supported");
3247 return 0;
3248 }
3249 }
3250
3251 val = get_param(cmd, "wmm");
3252 if (val) {
3253 switch (get_driver_type()) {
3254 case DRIVER_ATHEROS:
3255 ath_sta_set_wmm(dut, intf, val);
3256 break;
3257 default:
3258 sigma_dut_print(dut, DUT_MSG_DEBUG,
3259 "Setting wmm not supported");
3260 break;
3261 }
3262 }
3263
3264 val = get_param(cmd, "Powersave");
3265 if (val) {
3266 if (strcmp(val, "0") == 0 || strcasecmp(val, "off") == 0) {
3267 if (wpa_command(get_station_ifname(),
3268 "P2P_SET ps 0") < 0)
3269 return -2;
3270 /* Make sure test modes are disabled */
3271 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3272 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3273 } else if (strcmp(val, "1") == 0 ||
3274 strcasecmp(val, "PSPoll") == 0 ||
3275 strcasecmp(val, "on") == 0) {
3276 /* Disable default power save mode */
3277 wpa_command(get_station_ifname(), "P2P_SET ps 0");
3278 /* Enable PS-Poll test mode */
3279 if (wpa_command(get_station_ifname(),
3280 "P2P_SET ps 97") < 0 ||
3281 wpa_command(get_station_ifname(),
3282 "P2P_SET ps 99") < 0)
3283 return -2;
3284 } else if (strcmp(val, "2") == 0 ||
3285 strcasecmp(val, "Fast") == 0) {
3286 /* TODO */
3287 send_resp(dut, conn, SIGMA_ERROR,
3288 "ErrorCode,Powersave=Fast not supported");
3289 return 0;
3290 } else if (strcmp(val, "3") == 0 ||
3291 strcasecmp(val, "PSNonPoll") == 0) {
3292 /* Make sure test modes are disabled */
3293 wpa_command(get_station_ifname(), "P2P_SET ps 98");
3294 wpa_command(get_station_ifname(), "P2P_SET ps 96");
3295
3296 /* Enable default power save mode */
3297 if (wpa_command(get_station_ifname(),
3298 "P2P_SET ps 1") < 0)
3299 return -2;
3300 } else
3301 return -1;
3302 }
3303
3304 val = get_param(cmd, "NoAck");
3305 if (val) {
3306 switch (get_driver_type()) {
3307 case DRIVER_ATHEROS:
3308 ath_sta_set_noack(dut, intf, val);
3309 break;
3310 default:
3311 send_resp(dut, conn, SIGMA_ERROR,
3312 "ErrorCode,Setting NoAck not supported");
3313 return 0;
3314 }
3315 }
3316
3317 val = get_param(cmd, "IgnoreChswitchProhibit");
3318 if (val) {
3319 /* TODO: Enabled/disabled */
3320 if (strcasecmp(val, "Enabled") == 0) {
3321 send_resp(dut, conn, SIGMA_ERROR,
3322 "ErrorCode,Enabling IgnoreChswitchProhibit "
3323 "not supported");
3324 return 0;
3325 }
3326 }
3327
3328 val = get_param(cmd, "TDLS");
3329 if (val) {
3330 if (strcasecmp(val, "Disabled") == 0) {
3331 if (wpa_command(intf, "SET tdls_disabled 1")) {
3332 send_resp(dut, conn, SIGMA_ERROR,
3333 "ErrorCode,Failed to disable TDLS");
3334 return 0;
3335 }
3336 } else if (strcasecmp(val, "Enabled") == 0) {
3337 if (wpa_command(intf, "SET tdls_disabled 0")) {
3338 send_resp(dut, conn, SIGMA_ERROR,
3339 "ErrorCode,Failed to enable TDLS");
3340 return 0;
3341 }
3342 } else {
3343 send_resp(dut, conn, SIGMA_ERROR,
3344 "ErrorCode,Unsupported TDLS value");
3345 return 0;
3346 }
3347 }
3348
3349 val = get_param(cmd, "TDLSmode");
3350 if (val) {
3351 if (strcasecmp(val, "Default") == 0) {
3352 wpa_command(intf, "SET tdls_testing 0");
3353 } else if (strcasecmp(val, "APProhibit") == 0) {
3354 if (wpa_command(intf, "SET tdls_testing 0x400")) {
3355 send_resp(dut, conn, SIGMA_ERROR,
3356 "ErrorCode,Failed to enable ignore "
3357 "APProhibit TDLS mode");
3358 return 0;
3359 }
3360 } else if (strcasecmp(val, "HiLoMac") == 0) {
3361 /* STA should respond with TDLS setup req for a TDLS
3362 * setup req */
3363 if (wpa_command(intf, "SET tdls_testing 0x80")) {
3364 send_resp(dut, conn, SIGMA_ERROR,
3365 "ErrorCode,Failed to enable HiLoMac "
3366 "TDLS mode");
3367 return 0;
3368 }
3369 } else if (strcasecmp(val, "WeakSecurity") == 0) {
3370 /*
3371 * Since all security modes are enabled by default when
3372 * Sigma control is used, there is no need to do
3373 * anything here.
3374 */
3375 } else if (strcasecmp(val, "ExistLink") == 0) {
3376 /*
3377 * Since we allow new TDLS Setup Request even if there
3378 * is an existing link, nothing needs to be done for
3379 * this.
3380 */
3381 } else {
3382 /* TODO:
3383 * ExistLink: STA should send TDLS setup req even if
3384 * direct link already exists
3385 */
3386 send_resp(dut, conn, SIGMA_ERROR,
3387 "ErrorCode,Unsupported TDLSmode value");
3388 return 0;
3389 }
3390 }
3391
3392 val = get_param(cmd, "FakePubKey");
3393 if (val && atoi(val) && wpa_command(intf, "SET wps_corrupt_pkhash 1")) {
3394 send_resp(dut, conn, SIGMA_ERROR,
3395 "ErrorCode,Failed to enable FakePubKey");
3396 return 0;
3397 }
3398
3399 return 1;
3400}
3401
3402
3403static const char * ath_get_radio_name(const char *radio_name)
3404{
3405 if (radio_name == NULL)
3406 return "wifi0";
3407 if (strcmp(radio_name, "wifi1") == 0)
3408 return "wifi1";
3409 if (strcmp(radio_name, "wifi2") == 0)
3410 return "wifi2";
3411 return "wifi0";
3412}
3413
3414
3415static void ath_sta_set_txsp_stream(struct sigma_dut *dut, const char *intf,
3416 const char *val)
3417{
3418 char buf[60];
3419 unsigned int vht_mcsmap = 0;
3420 int txchainmask = 0;
3421 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
3422
3423 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
3424 if (dut->testbed_flag_txsp == 1) {
3425 vht_mcsmap = 0xfffc;
3426 dut->testbed_flag_txsp = 0;
3427 } else {
3428 vht_mcsmap = 0xfffe;
3429 }
3430 txchainmask = 1;
3431 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
3432 if (dut->testbed_flag_txsp == 1) {
3433 vht_mcsmap = 0xfff0;
3434 dut->testbed_flag_txsp = 0;
3435 } else {
3436 vht_mcsmap = 0xfffa;
3437 }
3438 txchainmask = 3;
3439 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
3440 if (dut->testbed_flag_txsp == 1) {
3441 vht_mcsmap = 0xffc0;
3442 dut->testbed_flag_txsp = 0;
3443 } else {
3444 vht_mcsmap = 0xffea;
3445 }
3446 txchainmask = 7;
3447 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
3448 if (dut->testbed_flag_txsp == 1) {
3449 vht_mcsmap = 0xff00;
3450 dut->testbed_flag_txsp = 0;
3451 } else {
3452 vht_mcsmap = 0xffaa;
3453 }
3454 txchainmask = 15;
3455 } else {
3456 if (dut->testbed_flag_txsp == 1) {
3457 vht_mcsmap = 0xffc0;
3458 dut->testbed_flag_txsp = 0;
3459 } else {
3460 vht_mcsmap = 0xffea;
3461 }
3462 }
3463
3464 if (txchainmask) {
3465 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
3466 basedev, txchainmask);
3467 if (system(buf) != 0) {
3468 sigma_dut_print(dut, DUT_MSG_ERROR,
3469 "iwpriv txchainmask failed");
3470 }
3471 }
3472
3473 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
3474 intf, vht_mcsmap);
3475 if (system(buf) != 0) {
3476 sigma_dut_print(dut, DUT_MSG_ERROR,
3477 "iwpriv %s vht_mcsmap 0x%04x failed",
3478 intf, vht_mcsmap);
3479 }
3480}
3481
3482
3483static void ath_sta_set_rxsp_stream(struct sigma_dut *dut, const char *intf,
3484 const char *val)
3485{
3486 char buf[60];
3487 unsigned int vht_mcsmap = 0;
3488 int rxchainmask = 0;
3489 const char *basedev = ath_get_radio_name(sigma_radio_ifname[0]);
3490
3491 if (strcasecmp(val, "1") == 0 || strcasecmp(val, "1SS") == 0) {
3492 if (dut->testbed_flag_rxsp == 1) {
3493 vht_mcsmap = 0xfffc;
3494 dut->testbed_flag_rxsp = 0;
3495 } else {
3496 vht_mcsmap = 0xfffe;
3497 }
3498 rxchainmask = 1;
3499 } else if (strcasecmp(val, "2") == 0 || strcasecmp(val, "2SS") == 0) {
3500 if (dut->testbed_flag_rxsp == 1) {
3501 vht_mcsmap = 0xfff0;
3502 dut->testbed_flag_rxsp = 0;
3503 } else {
3504 vht_mcsmap = 0xfffa;
3505 }
3506 rxchainmask = 3;
3507 } else if (strcasecmp(val, "3") == 0 || strcasecmp(val, "3SS") == 0) {
3508 if (dut->testbed_flag_rxsp == 1) {
3509 vht_mcsmap = 0xffc0;
3510 dut->testbed_flag_rxsp = 0;
3511 } else {
3512 vht_mcsmap = 0xffea;
3513 }
3514 rxchainmask = 7;
3515 } else if (strcasecmp(val, "4") == 0 || strcasecmp(val, "4SS") == 0) {
3516 if (dut->testbed_flag_rxsp == 1) {
3517 vht_mcsmap = 0xff00;
3518 dut->testbed_flag_rxsp = 0;
3519 } else {
3520 vht_mcsmap = 0xffaa;
3521 }
3522 rxchainmask = 15;
3523 } else {
3524 if (dut->testbed_flag_rxsp == 1) {
3525 vht_mcsmap = 0xffc0;
3526 dut->testbed_flag_rxsp = 0;
3527 } else {
3528 vht_mcsmap = 0xffea;
3529 }
3530 }
3531
3532 if (rxchainmask) {
3533 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
3534 basedev, rxchainmask);
3535 if (system(buf) != 0) {
3536 sigma_dut_print(dut, DUT_MSG_ERROR,
3537 "iwpriv rxchainmask failed");
3538 }
3539 }
3540
3541 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
3542 intf, vht_mcsmap);
3543 if (system(buf) != 0) {
3544 sigma_dut_print(dut, DUT_MSG_ERROR,
3545 "iwpriv %s vht_mcsmap 0x%04x",
3546 intf, vht_mcsmap);
3547 }
3548}
3549
3550
3551void ath_set_zero_crc(struct sigma_dut *dut, const char *val)
3552{
3553 if (strcasecmp(val, "enable") == 0) {
3554 if (system("athdiag --set --address=0x2a204 --and=0xbfffffff")
3555 != 0) {
3556 sigma_dut_print(dut, DUT_MSG_ERROR,
3557 "Disable BB_VHTSIGB_CRC_CALC failed");
3558 }
3559
3560 if (system("athdiag --set --address=0x2a204 --or=0x80000000")
3561 != 0) {
3562 sigma_dut_print(dut, DUT_MSG_ERROR,
3563 "Enable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
3564 }
3565 } else {
3566 if (system("athdiag --set --address=0x2a204 --and=0x7fffffff")
3567 != 0) {
3568 sigma_dut_print(dut, DUT_MSG_ERROR,
3569 "Disable FORCE_VHT_SIGB_CRC_VALUE_ZERO failed");
3570 }
3571
3572 if (system("athdiag --set --address=0x2a204 --or=0x40000000")
3573 != 0) {
3574 sigma_dut_print(dut, DUT_MSG_ERROR,
3575 "Enable BB_VHTSIGB_CRC_CALC failed");
3576 }
3577 }
3578}
3579
3580
3581static int cmd_sta_set_wireless_common(const char *intf, struct sigma_dut *dut,
3582 struct sigma_conn *conn,
3583 struct sigma_cmd *cmd)
3584{
3585 const char *val;
3586 int ampdu = -1;
3587 char buf[30];
3588
3589 val = get_param(cmd, "40_INTOLERANT");
3590 if (val) {
3591 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
3592 /* TODO: iwpriv ht40intol through wpa_supplicant */
3593 send_resp(dut, conn, SIGMA_ERROR,
3594 "ErrorCode,40_INTOLERANT not supported");
3595 return 0;
3596 }
3597 }
3598
3599 val = get_param(cmd, "ADDBA_REJECT");
3600 if (val) {
3601 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
3602 /* reject any ADDBA with status "decline" */
3603 ampdu = 0;
3604 } else {
3605 /* accept ADDBA */
3606 ampdu = 1;
3607 }
3608 }
3609
3610 val = get_param(cmd, "AMPDU");
3611 if (val) {
3612 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
3613 /* enable AMPDU Aggregation */
3614 if (ampdu == 0) {
3615 send_resp(dut, conn, SIGMA_ERROR,
3616 "ErrorCode,Mismatch in "
3617 "addba_reject/ampdu - "
3618 "not supported");
3619 return 0;
3620 }
3621 ampdu = 1;
3622 } else {
3623 /* disable AMPDU Aggregation */
3624 if (ampdu == 1) {
3625 send_resp(dut, conn, SIGMA_ERROR,
3626 "ErrorCode,Mismatch in "
3627 "addba_reject/ampdu - "
3628 "not supported");
3629 return 0;
3630 }
3631 ampdu = 0;
3632 }
3633 }
3634
3635 if (ampdu >= 0) {
3636 sigma_dut_print(dut, DUT_MSG_DEBUG, "%s A-MPDU aggregation",
3637 ampdu ? "Enabling" : "Disabling");
3638 snprintf(buf, sizeof(buf), "SET ampdu %d", ampdu);
Deepak Dhamdhere80356cb2016-03-28 16:48:32 -07003639 if (wpa_command(intf, buf) < 0 &&
3640 iwpriv_sta_set_ampdu(dut, intf, ampdu) < 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003641 send_resp(dut, conn, SIGMA_ERROR,
3642 "ErrorCode,set aggr failed");
3643 return 0;
3644 }
3645 }
3646
3647 val = get_param(cmd, "AMSDU");
3648 if (val) {
3649 switch (get_driver_type()) {
3650 case DRIVER_ATHEROS:
3651 ath_sta_set_amsdu(dut, intf, val);
3652 break;
3653 default:
3654 if (strcmp(val, "1") == 0 ||
3655 strcasecmp(val, "Enable") == 0) {
3656 /* Enable AMSDU Aggregation */
3657 send_resp(dut, conn, SIGMA_ERROR,
3658 "ErrorCode,AMSDU aggregation not supported");
3659 return 0;
3660 }
3661 break;
3662 }
3663 }
3664
3665 val = get_param(cmd, "STBC_RX");
3666 if (val) {
3667 switch (get_driver_type()) {
3668 case DRIVER_ATHEROS:
3669 ath_sta_set_stbc(dut, intf, val);
3670 break;
Pradeep Reddy POTTETI4a1f6b32016-11-23 13:15:21 +05303671 case DRIVER_WCN:
3672 wcn_sta_set_stbc(dut, intf, val);
3673 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003674 default:
3675 send_resp(dut, conn, SIGMA_ERROR,
3676 "ErrorCode,STBC_RX not supported");
3677 return 0;
3678 }
3679 }
3680
3681 val = get_param(cmd, "WIDTH");
3682 if (val) {
3683 switch (get_driver_type()) {
3684 case DRIVER_WCN:
3685 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
3686 send_resp(dut, conn, SIGMA_ERROR,
3687 "ErrorCode,Failed to set WIDTH");
3688 return 0;
3689 }
3690 break;
3691 case DRIVER_ATHEROS:
3692 if (ath_set_width(dut, conn, intf, val) < 0)
3693 return 0;
3694 break;
3695 default:
3696 sigma_dut_print(dut, DUT_MSG_ERROR,
3697 "Setting WIDTH not supported");
3698 break;
3699 }
3700 }
3701
3702 val = get_param(cmd, "SMPS");
3703 if (val) {
3704 /* TODO: Dynamic/0, Static/1, No Limit/2 */
3705 send_resp(dut, conn, SIGMA_ERROR,
3706 "ErrorCode,SMPS not supported");
3707 return 0;
3708 }
3709
3710 val = get_param(cmd, "TXSP_STREAM");
3711 if (val) {
3712 switch (get_driver_type()) {
3713 case DRIVER_WCN:
3714 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
3715 send_resp(dut, conn, SIGMA_ERROR,
3716 "ErrorCode,Failed to set TXSP_STREAM");
3717 return 0;
3718 }
3719 break;
3720 case DRIVER_ATHEROS:
3721 ath_sta_set_txsp_stream(dut, intf, val);
3722 break;
3723 default:
3724 sigma_dut_print(dut, DUT_MSG_ERROR,
3725 "Setting TXSP_STREAM not supported");
3726 break;
3727 }
3728 }
3729
3730 val = get_param(cmd, "RXSP_STREAM");
3731 if (val) {
3732 switch (get_driver_type()) {
3733 case DRIVER_WCN:
3734 if (wcn_sta_set_sp_stream(dut, intf, val) < 0) {
3735 send_resp(dut, conn, SIGMA_ERROR,
3736 "ErrorCode,Failed to set RXSP_STREAM");
3737 return 0;
3738 }
3739 break;
3740 case DRIVER_ATHEROS:
3741 ath_sta_set_rxsp_stream(dut, intf, val);
3742 break;
3743 default:
3744 sigma_dut_print(dut, DUT_MSG_ERROR,
3745 "Setting RXSP_STREAM not supported");
3746 break;
3747 }
3748 }
3749
3750 val = get_param(cmd, "DYN_BW_SGNL");
3751 if (val) {
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08003752 switch (get_driver_type()) {
3753 case DRIVER_WCN:
Peng Xuc59afd32016-11-21 15:01:11 -08003754 if (strcasecmp(val, "enable") == 0) {
3755 snprintf(buf, sizeof(buf),
3756 "iwpriv %s cwmenable 1", intf);
3757 if (system(buf) != 0) {
3758 sigma_dut_print(dut, DUT_MSG_ERROR,
3759 "iwpriv cwmenable 1 failed");
3760 return 0;
3761 }
3762 } else if (strcasecmp(val, "disable") == 0) {
3763 snprintf(buf, sizeof(buf),
3764 "iwpriv %s cwmenable 0", intf);
3765 if (system(buf) != 0) {
3766 sigma_dut_print(dut, DUT_MSG_ERROR,
3767 "iwpriv cwmenable 0 failed");
3768 return 0;
3769 }
3770 } else {
3771 sigma_dut_print(dut, DUT_MSG_ERROR,
3772 "Unsupported DYN_BW_SGL");
3773 }
3774
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003775 snprintf(buf, sizeof(buf), "iwpriv %s cts_cbw 3", intf);
3776 if (system(buf) != 0) {
3777 sigma_dut_print(dut, DUT_MSG_ERROR,
3778 "Failed to set cts_cbw in DYN_BW_SGNL");
3779 return 0;
3780 }
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08003781 break;
3782 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08003783 novap_reset(dut, intf);
Priyadharshini Gowthaman818afef2015-11-09 13:28:15 -08003784 ath_config_dyn_bw_sig(dut, intf, val);
3785 break;
3786 default:
3787 sigma_dut_print(dut, DUT_MSG_ERROR,
3788 "Failed to set DYN_BW_SGNL");
3789 break;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003790 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003791 }
3792
3793 val = get_param(cmd, "RTS_FORCE");
3794 if (val) {
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08003795 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003796 if (strcasecmp(val, "Enable") == 0) {
3797 snprintf(buf, sizeof(buf), "iwconfig %s rts 64", intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02003798 if (system(buf) != 0) {
3799 sigma_dut_print(dut, DUT_MSG_ERROR,
3800 "Failed to set RTS_FORCE 64");
3801 }
priyadharshini gowthaman270870e2015-12-09 10:10:23 -08003802 snprintf(buf, sizeof(buf),
3803 "wifitool %s beeliner_fw_test 100 1", intf);
3804 if (system(buf) != 0) {
3805 sigma_dut_print(dut, DUT_MSG_ERROR,
3806 "wifitool beeliner_fw_test 100 1 failed");
3807 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003808 } else if (strcasecmp(val, "Disable") == 0) {
3809 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347",
3810 intf);
Priyadharshini Gowthamanabdb2122015-11-17 11:52:19 +02003811 if (system(buf) != 0) {
3812 sigma_dut_print(dut, DUT_MSG_ERROR,
3813 "Failed to set RTS_FORCE 2347");
3814 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003815 } else {
3816 send_resp(dut, conn, SIGMA_ERROR,
3817 "ErrorCode,RTS_FORCE value not supported");
3818 return 0;
3819 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02003820 }
3821
3822 val = get_param(cmd, "CTS_WIDTH");
3823 if (val) {
3824 switch (get_driver_type()) {
3825 case DRIVER_WCN:
3826 if (wcn_sta_set_cts_width(dut, intf, val) < 0) {
3827 send_resp(dut, conn, SIGMA_ERROR,
3828 "ErrorCode,Failed to set CTS_WIDTH");
3829 return 0;
3830 }
3831 break;
3832 case DRIVER_ATHEROS:
3833 ath_set_cts_width(dut, intf, val);
3834 break;
3835 default:
3836 sigma_dut_print(dut, DUT_MSG_ERROR,
3837 "Setting CTS_WIDTH not supported");
3838 break;
3839 }
3840 }
3841
3842 val = get_param(cmd, "BW_SGNL");
3843 if (val) {
3844 if (strcasecmp(val, "Enable") == 0) {
3845 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1",
3846 intf);
3847 } else if (strcasecmp(val, "Disable") == 0) {
3848 /* TODO: Disable */
3849 buf[0] = '\0';
3850 } else {
3851 send_resp(dut, conn, SIGMA_ERROR,
3852 "ErrorCode,BW_SGNL value not supported");
3853 return 0;
3854 }
3855
3856 if (buf[0] != '\0' && system(buf) != 0) {
3857 sigma_dut_print(dut, DUT_MSG_ERROR,
3858 "Failed to set BW_SGNL");
3859 }
3860 }
3861
3862 val = get_param(cmd, "Band");
3863 if (val) {
3864 if (strcmp(val, "2.4") == 0 || strcmp(val, "5") == 0) {
3865 /* STA supports all bands by default */
3866 } else {
3867 send_resp(dut, conn, SIGMA_ERROR,
3868 "ErrorCode,Unsupported Band");
3869 return 0;
3870 }
3871 }
3872
3873 val = get_param(cmd, "zero_crc");
3874 if (val) {
3875 switch (get_driver_type()) {
3876 case DRIVER_ATHEROS:
3877 ath_set_zero_crc(dut, val);
3878 break;
3879 default:
3880 break;
3881 }
3882 }
3883
3884 return 1;
3885}
3886
3887
3888static int sta_set_60g_common(struct sigma_dut *dut, struct sigma_conn *conn,
3889 struct sigma_cmd *cmd)
3890{
3891 const char *val;
3892 char buf[100];
3893
3894 val = get_param(cmd, "MSDUSize");
3895 if (val) {
3896 int mtu;
3897
3898 dut->amsdu_size = atoi(val);
3899 if (dut->amsdu_size > IEEE80211_MAX_DATA_LEN_DMG ||
3900 dut->amsdu_size < IEEE80211_SNAP_LEN_DMG) {
3901 sigma_dut_print(dut, DUT_MSG_ERROR,
3902 "MSDUSize %d is above max %d or below min %d",
3903 dut->amsdu_size,
3904 IEEE80211_MAX_DATA_LEN_DMG,
3905 IEEE80211_SNAP_LEN_DMG);
3906 dut->amsdu_size = 0;
3907 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3908 }
3909
3910 mtu = dut->amsdu_size - IEEE80211_SNAP_LEN_DMG;
3911 sigma_dut_print(dut, DUT_MSG_DEBUG,
3912 "Setting amsdu_size to %d", mtu);
3913 snprintf(buf, sizeof(buf), "ifconfig %s mtu %d",
3914 get_station_ifname(), mtu);
3915
3916 if (system(buf) != 0) {
3917 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set %s",
3918 buf);
3919 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3920 }
3921 }
3922
3923 val = get_param(cmd, "BAckRcvBuf");
3924 if (val) {
3925 dut->back_rcv_buf = atoi(val);
3926 if (dut->back_rcv_buf == 0) {
3927 sigma_dut_print(dut, DUT_MSG_ERROR,
3928 "Failed to convert %s or value is 0",
3929 val);
3930 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3931 }
3932
3933 sigma_dut_print(dut, DUT_MSG_DEBUG,
3934 "Setting BAckRcvBuf to %s", val);
3935 }
3936
3937 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
3938}
3939
3940
3941static int sta_pcp_start(struct sigma_dut *dut, struct sigma_conn *conn,
3942 struct sigma_cmd *cmd)
3943{
3944 int net_id;
3945 char *ifname;
3946 const char *val;
3947 char buf[100];
3948
3949 dut->mode = SIGMA_MODE_STATION;
3950 ifname = get_main_ifname();
3951 if (wpa_command(ifname, "PING") != 0) {
3952 sigma_dut_print(dut, DUT_MSG_ERROR, "Supplicant not running");
3953 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3954 }
3955
3956 wpa_command(ifname, "FLUSH");
3957 net_id = add_network_common(dut, conn, ifname, cmd);
3958 if (net_id < 0) {
3959 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add network");
3960 return net_id;
3961 }
3962
3963 /* TODO: mode=2 for the AP; in the future, replace for mode PCP */
3964 if (set_network(ifname, net_id, "mode", "2") < 0) {
3965 sigma_dut_print(dut, DUT_MSG_ERROR,
3966 "Failed to set supplicant network mode");
3967 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3968 }
3969
3970 sigma_dut_print(dut, DUT_MSG_DEBUG,
3971 "Supplicant set network with mode 2");
3972
3973 val = get_param(cmd, "Security");
3974 if (val && strcasecmp(val, "OPEN") == 0) {
3975 dut->ap_key_mgmt = AP_OPEN;
3976 if (set_network(ifname, net_id, "key_mgmt", "NONE") < 0) {
3977 sigma_dut_print(dut, DUT_MSG_ERROR,
3978 "Failed to set supplicant to %s security",
3979 val);
3980 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3981 }
3982 } else if (val && strcasecmp(val, "WPA2-PSK") == 0) {
3983 dut->ap_key_mgmt = AP_WPA2_PSK;
3984 if (set_network(ifname, net_id, "key_mgmt", "WPA-PSK") < 0) {
3985 sigma_dut_print(dut, DUT_MSG_ERROR,
3986 "Failed to set supplicant to %s security",
3987 val);
3988 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3989 }
3990
3991 if (set_network(ifname, net_id, "proto", "RSN") < 0) {
3992 sigma_dut_print(dut, DUT_MSG_ERROR,
3993 "Failed to set supplicant to proto RSN");
3994 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
3995 }
3996 } else if (val) {
3997 sigma_dut_print(dut, DUT_MSG_ERROR,
3998 "Requested Security %s is not supported on 60GHz",
3999 val);
4000 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4001 }
4002
4003 val = get_param(cmd, "Encrypt");
4004 if (val && strcasecmp(val, "AES-GCMP") == 0) {
4005 if (set_network(ifname, net_id, "pairwise", "GCMP") < 0) {
4006 sigma_dut_print(dut, DUT_MSG_ERROR,
4007 "Failed to set supplicant to pairwise GCMP");
4008 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4009 }
4010 if (set_network(ifname, net_id, "group", "GCMP") < 0) {
4011 sigma_dut_print(dut, DUT_MSG_ERROR,
4012 "Failed to set supplicant to group GCMP");
4013 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4014 }
4015 } else if (val) {
4016 sigma_dut_print(dut, DUT_MSG_ERROR,
4017 "Requested Encrypt %s is not supported on 60 GHz",
4018 val);
4019 return SIGMA_DUT_INVALID_CALLER_SEND_STATUS;
4020 }
4021
4022 val = get_param(cmd, "PSK");
4023 if (val && set_network_quoted(ifname, net_id, "psk", val) < 0) {
4024 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set psk %s",
4025 val);
4026 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4027 }
4028
4029 /* Convert 60G channel to freq */
4030 switch (dut->ap_channel) {
4031 case 1:
4032 val = "58320";
4033 break;
4034 case 2:
4035 val = "60480";
4036 break;
4037 case 3:
4038 val = "62640";
4039 break;
4040 default:
4041 sigma_dut_print(dut, DUT_MSG_ERROR,
4042 "Failed to configure channel %d. Not supported",
4043 dut->ap_channel);
4044 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4045 }
4046
4047 if (set_network(ifname, net_id, "frequency", val) < 0) {
4048 sigma_dut_print(dut, DUT_MSG_ERROR,
4049 "Failed to set supplicant network frequency");
4050 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4051 }
4052
4053 sigma_dut_print(dut, DUT_MSG_DEBUG,
4054 "Supplicant set network with frequency");
4055
4056 snprintf(buf, sizeof(buf), "SELECT_NETWORK %d", net_id);
4057 if (wpa_command(ifname, buf) < 0) {
4058 sigma_dut_print(dut, DUT_MSG_INFO,
4059 "Failed to select network id %d on %s",
4060 net_id, ifname);
4061 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4062 }
4063
4064 sigma_dut_print(dut, DUT_MSG_DEBUG, "Selected network");
4065
4066 return SIGMA_DUT_SUCCESS_CALLER_SEND_STATUS;
4067}
4068
4069
Lior David67543f52017-01-03 19:04:22 +02004070static int wil6210_set_abft_len(struct sigma_dut *dut, int abft_len)
4071{
4072 char buf[128], fname[128];
4073 FILE *f;
4074
4075 if (wil6210_get_debugfs_dir(dut, buf, sizeof(buf))) {
4076 sigma_dut_print(dut, DUT_MSG_ERROR,
4077 "failed to get wil6210 debugfs dir");
4078 return -1;
4079 }
4080
4081 snprintf(fname, sizeof(fname), "%s/abft_len", buf);
4082 f = fopen(fname, "w");
4083 if (!f) {
4084 sigma_dut_print(dut, DUT_MSG_ERROR,
4085 "failed to open: %s", fname);
4086 return -1;
4087 }
4088
4089 fprintf(f, "%d\n", abft_len);
4090 fclose(f);
4091
4092 return 0;
4093}
4094
4095
4096static int sta_set_60g_abft_len(struct sigma_dut *dut, struct sigma_conn *conn,
4097 int abft_len)
4098{
4099 switch (get_driver_type()) {
4100 case DRIVER_WIL6210:
4101 return wil6210_set_abft_len(dut, abft_len);
4102 default:
4103 sigma_dut_print(dut, DUT_MSG_ERROR,
4104 "set abft_len not supported");
4105 return -1;
4106 }
4107}
4108
4109
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004110static int sta_set_60g_pcp(struct sigma_dut *dut, struct sigma_conn *conn,
4111 struct sigma_cmd *cmd)
4112{
4113 const char *val;
Lior David67543f52017-01-03 19:04:22 +02004114 unsigned int abft_len = 1; /* default is one slot */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004115
4116 if (dut->dev_role != DEVROLE_PCP) {
4117 send_resp(dut, conn, SIGMA_INVALID,
4118 "ErrorCode,Invalid DevRole");
4119 return 0;
4120 }
4121
4122 val = get_param(cmd, "SSID");
4123 if (val) {
4124 if (strlen(val) > sizeof(dut->ap_ssid) - 1) {
4125 send_resp(dut, conn, SIGMA_INVALID,
4126 "ErrorCode,Invalid SSID");
4127 return -1;
4128 }
4129
Peng Xub8fc5cc2017-05-10 17:27:28 -07004130 strlcpy(dut->ap_ssid, val, sizeof(dut->ap_ssid));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004131 }
4132
4133 val = get_param(cmd, "CHANNEL");
4134 if (val) {
4135 const char *pos;
4136
4137 dut->ap_channel = atoi(val);
4138 pos = strchr(val, ';');
4139 if (pos) {
4140 pos++;
4141 dut->ap_channel_1 = atoi(pos);
4142 }
4143 }
4144
4145 switch (dut->ap_channel) {
4146 case 1:
4147 case 2:
4148 case 3:
4149 break;
4150 default:
4151 sigma_dut_print(dut, DUT_MSG_ERROR,
4152 "Channel %d is not supported", dut->ap_channel);
4153 send_resp(dut, conn, SIGMA_ERROR,
4154 "Requested channel is not supported");
4155 return -1;
4156 }
4157
4158 val = get_param(cmd, "BCNINT");
4159 if (val)
4160 dut->ap_bcnint = atoi(val);
4161
4162
4163 val = get_param(cmd, "ExtSchIE");
4164 if (val) {
4165 send_resp(dut, conn, SIGMA_ERROR,
4166 "ErrorCode,ExtSchIE is not supported yet");
4167 return -1;
4168 }
4169
4170 val = get_param(cmd, "AllocType");
4171 if (val) {
4172 send_resp(dut, conn, SIGMA_ERROR,
4173 "ErrorCode,AllocType is not supported yet");
4174 return -1;
4175 }
4176
4177 val = get_param(cmd, "PercentBI");
4178 if (val) {
4179 send_resp(dut, conn, SIGMA_ERROR,
4180 "ErrorCode,PercentBI is not supported yet");
4181 return -1;
4182 }
4183
4184 val = get_param(cmd, "CBAPOnly");
4185 if (val) {
4186 send_resp(dut, conn, SIGMA_ERROR,
4187 "ErrorCode,CBAPOnly is not supported yet");
4188 return -1;
4189 }
4190
4191 val = get_param(cmd, "AMPDU");
4192 if (val) {
4193 if (strcasecmp(val, "Enable") == 0)
4194 dut->ap_ampdu = 1;
4195 else if (strcasecmp(val, "Disable") == 0)
4196 dut->ap_ampdu = 2;
4197 else {
4198 send_resp(dut, conn, SIGMA_ERROR,
4199 "ErrorCode,AMPDU value is not Enable nor Disabled");
4200 return -1;
4201 }
4202 }
4203
4204 val = get_param(cmd, "AMSDU");
4205 if (val) {
4206 if (strcasecmp(val, "Enable") == 0)
4207 dut->ap_amsdu = 1;
4208 else if (strcasecmp(val, "Disable") == 0)
4209 dut->ap_amsdu = 2;
4210 }
4211
4212 val = get_param(cmd, "NumMSDU");
4213 if (val) {
4214 send_resp(dut, conn, SIGMA_ERROR,
4215 "ErrorCode, NumMSDU is not supported yet");
4216 return -1;
4217 }
4218
4219 val = get_param(cmd, "ABFTLRang");
4220 if (val) {
4221 sigma_dut_print(dut, DUT_MSG_DEBUG,
Lior David67543f52017-01-03 19:04:22 +02004222 "ABFTLRang parameter %s", val);
4223 if (strcmp(val, "Gt1") == 0)
4224 abft_len = 2; /* 2 slots in this case */
4225 }
4226
4227 if (sta_set_60g_abft_len(dut, conn, abft_len)) {
4228 send_resp(dut, conn, SIGMA_ERROR,
4229 "ErrorCode, Can't set ABFT length");
4230 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004231 }
4232
4233 if (sta_pcp_start(dut, conn, cmd) < 0) {
4234 send_resp(dut, conn, SIGMA_ERROR,
4235 "ErrorCode, Can't start PCP role");
4236 return -1;
4237 }
4238
4239 return sta_set_60g_common(dut, conn, cmd);
4240}
4241
4242
4243static int sta_set_60g_sta(struct sigma_dut *dut, struct sigma_conn *conn,
4244 struct sigma_cmd *cmd)
4245{
4246 const char *val = get_param(cmd, "DiscoveryMode");
4247
4248 if (dut->dev_role != DEVROLE_STA) {
4249 send_resp(dut, conn, SIGMA_INVALID,
4250 "ErrorCode,Invalid DevRole");
4251 return 0;
4252 }
4253
4254 if (val) {
4255 sigma_dut_print(dut, DUT_MSG_DEBUG, "Discovery: %s", val);
4256 /* Ignore Discovery mode till Driver expose API. */
4257#if 0
4258 if (strcasecmp(val, "1") == 0) {
4259 send_resp(dut, conn, SIGMA_INVALID,
4260 "ErrorCode,DiscoveryMode 1 not supported");
4261 return 0;
4262 }
4263
4264 if (strcasecmp(val, "0") == 0) {
4265 /* OK */
4266 } else {
4267 send_resp(dut, conn, SIGMA_INVALID,
4268 "ErrorCode,DiscoveryMode not supported");
4269 return 0;
4270 }
4271#endif
4272 }
4273
4274 if (start_sta_mode(dut) != 0)
4275 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
4276 return sta_set_60g_common(dut, conn, cmd);
4277}
4278
4279
4280static int cmd_sta_disconnect(struct sigma_dut *dut, struct sigma_conn *conn,
4281 struct sigma_cmd *cmd)
4282{
4283 const char *intf = get_param(cmd, "Interface");
4284 disconnect_station(dut);
4285 /* Try to ignore old scan results to avoid HS 2.0R2 test case failures
4286 * due to cached results. */
4287 wpa_command(intf, "SET ignore_old_scan_res 1");
4288 wpa_command(intf, "BSS_FLUSH");
4289 return 1;
4290}
4291
4292
4293static int cmd_sta_reassoc(struct sigma_dut *dut, struct sigma_conn *conn,
4294 struct sigma_cmd *cmd)
4295{
4296 const char *intf = get_param(cmd, "Interface");
4297 const char *bssid = get_param(cmd, "bssid");
4298 const char *val = get_param(cmd, "CHANNEL");
4299 struct wpa_ctrl *ctrl;
4300 char buf[100];
4301 int res;
4302 int chan = 0;
Ashwini Patil467efef2017-05-25 12:18:27 +05304303 int status = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004304
4305 if (bssid == NULL) {
4306 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing bssid "
4307 "argument");
4308 return 0;
4309 }
4310
4311 if (val)
4312 chan = atoi(val);
4313
4314 if (wifi_chip_type != DRIVER_WCN && wifi_chip_type != DRIVER_AR6003) {
4315 /* The current network may be from sta_associate or
4316 * sta_hs2_associate
4317 */
4318 if (set_network(intf, dut->infra_network_id, "bssid", bssid) <
4319 0 ||
4320 set_network(intf, 0, "bssid", bssid) < 0)
4321 return -2;
4322 }
4323
4324 ctrl = open_wpa_mon(intf);
4325 if (ctrl == NULL) {
4326 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
4327 "wpa_supplicant monitor connection");
4328 return -1;
4329 }
4330
4331 if (wifi_chip_type == DRIVER_WCN) {
4332#ifdef ANDROID
Ashwini Patil4c8158f2017-05-25 12:49:21 +05304333 if (chan) {
4334 unsigned int freq;
4335
4336 freq = channel_to_freq(chan);
4337 if (!freq) {
4338 sigma_dut_print(dut, DUT_MSG_ERROR,
4339 "Invalid channel number provided: %d",
4340 chan);
4341 send_resp(dut, conn, SIGMA_INVALID,
4342 "ErrorCode,Invalid channel number");
4343 goto close_mon_conn;
4344 }
4345 res = snprintf(buf, sizeof(buf),
4346 "SCAN TYPE=ONLY freq=%d", freq);
4347 } else {
4348 res = snprintf(buf, sizeof(buf), "SCAN TYPE=ONLY");
4349 }
4350 if (res < 0 || res >= (int) sizeof(buf)) {
4351 send_resp(dut, conn, SIGMA_ERROR,
4352 "ErrorCode,snprintf failed");
4353 goto close_mon_conn;
4354 }
4355 if (wpa_command(intf, buf) < 0) {
4356 sigma_dut_print(dut, DUT_MSG_INFO,
4357 "Failed to start scan");
4358 send_resp(dut, conn, SIGMA_ERROR,
4359 "ErrorCode,scan failed");
4360 goto close_mon_conn;
4361 }
4362
4363 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
4364 buf, sizeof(buf));
4365 if (res < 0) {
4366 sigma_dut_print(dut, DUT_MSG_INFO,
4367 "Scan did not complete");
4368 send_resp(dut, conn, SIGMA_ERROR,
4369 "ErrorCode,scan did not complete");
4370 goto close_mon_conn;
4371 }
4372
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004373 if (set_network(intf, dut->infra_network_id, "bssid", "any")
4374 < 0) {
4375 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
4376 "bssid to any during FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05304377 status = -2;
4378 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004379 }
4380 res = snprintf(buf, sizeof(buf), "DRIVER FASTREASSOC %s %d",
4381 bssid, chan);
4382 if (res > 0 && res < (int) sizeof(buf))
4383 res = wpa_command(intf, buf);
4384
4385 if (res < 0 || res >= (int) sizeof(buf)) {
4386 send_resp(dut, conn, SIGMA_ERROR,
4387 "errorCode,Failed to run DRIVER FASTREASSOC");
Ashwini Patil467efef2017-05-25 12:18:27 +05304388 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004389 }
4390#else /* ANDROID */
4391 sigma_dut_print(dut, DUT_MSG_DEBUG,
4392 "Reassoc using iwpriv - skip chan=%d info",
4393 chan);
4394 snprintf(buf, sizeof(buf), "iwpriv %s reassoc", intf);
4395 if (system(buf) != 0) {
4396 sigma_dut_print(dut, DUT_MSG_ERROR, "%s failed", buf);
Ashwini Patil467efef2017-05-25 12:18:27 +05304397 status = -2;
4398 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004399 }
4400#endif /* ANDROID */
4401 sigma_dut_print(dut, DUT_MSG_INFO,
4402 "sta_reassoc: Run %s successful", buf);
4403 } else if (wpa_command(intf, "REASSOCIATE")) {
4404 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
4405 "request reassociation");
Ashwini Patil467efef2017-05-25 12:18:27 +05304406 goto close_mon_conn;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004407 }
4408
4409 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
4410 buf, sizeof(buf));
Ashwini Patil467efef2017-05-25 12:18:27 +05304411 if (res < 0) {
4412 sigma_dut_print(dut, DUT_MSG_INFO, "Connection did not complete");
4413 status = -1;
4414 goto close_mon_conn;
4415 }
4416 status = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004417
Ashwini Patil467efef2017-05-25 12:18:27 +05304418close_mon_conn:
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004419 wpa_ctrl_detach(ctrl);
4420 wpa_ctrl_close(ctrl);
Ashwini Patil467efef2017-05-25 12:18:27 +05304421 return status;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004422}
4423
4424
4425static void hs2_clear_credentials(const char *intf)
4426{
4427 wpa_command(intf, "REMOVE_CRED all");
4428}
4429
4430
Lior Davidcc88b562017-01-03 18:52:09 +02004431#ifdef __linux__
4432static int wil6210_get_aid(struct sigma_dut *dut, const char *bssid,
4433 unsigned int *aid)
4434{
Lior David0fe101e2017-03-09 16:09:50 +02004435 const char *pattern = "AID[ \t]+([0-9]+)";
Lior Davidcc88b562017-01-03 18:52:09 +02004436
Lior David0fe101e2017-03-09 16:09:50 +02004437 return wil6210_get_sta_info_field(dut, bssid, pattern, aid);
Lior Davidcc88b562017-01-03 18:52:09 +02004438}
4439#endif /* __linux__ */
4440
4441
4442static int sta_get_aid_60g(struct sigma_dut *dut, const char *bssid,
4443 unsigned int *aid)
4444{
4445 switch (get_driver_type()) {
4446#ifdef __linux__
4447 case DRIVER_WIL6210:
4448 return wil6210_get_aid(dut, bssid, aid);
4449#endif /* __linux__ */
4450 default:
4451 sigma_dut_print(dut, DUT_MSG_ERROR, "get AID not supported");
4452 return -1;
4453 }
4454}
4455
4456
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004457static int sta_get_parameter_60g(struct sigma_dut *dut, struct sigma_conn *conn,
4458 struct sigma_cmd *cmd)
4459{
4460 char buf[MAX_CMD_LEN];
4461 char bss_list[MAX_CMD_LEN];
4462 const char *parameter = get_param(cmd, "Parameter");
4463
4464 if (parameter == NULL)
4465 return -1;
4466
Lior Davidcc88b562017-01-03 18:52:09 +02004467 if (strcasecmp(parameter, "AID") == 0) {
4468 unsigned int aid = 0;
4469 char bssid[20];
4470
4471 if (get_wpa_status(get_station_ifname(), "bssid",
4472 bssid, sizeof(bssid)) < 0) {
4473 sigma_dut_print(dut, DUT_MSG_ERROR,
4474 "could not get bssid");
4475 return -2;
4476 }
4477
4478 if (sta_get_aid_60g(dut, bssid, &aid))
4479 return -2;
4480
4481 snprintf(buf, sizeof(buf), "aid,%d", aid);
4482 sigma_dut_print(dut, DUT_MSG_INFO, "%s", buf);
4483 send_resp(dut, conn, SIGMA_COMPLETE, buf);
4484 return 0;
4485 }
4486
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004487 if (strcasecmp(parameter, "DiscoveredDevList") == 0) {
4488 char *bss_line;
4489 char *bss_id = NULL;
4490 const char *ifname = get_param(cmd, "Interface");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304491 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004492
4493 if (ifname == NULL) {
4494 sigma_dut_print(dut, DUT_MSG_INFO,
4495 "For get DiscoveredDevList need Interface name.");
4496 return -1;
4497 }
4498
4499 /*
4500 * Use "BSS RANGE=ALL MASK=0x2" which provides a list
4501 * of BSSIDs in "bssid=<BSSID>\n"
4502 */
4503 if (wpa_command_resp(ifname, "BSS RANGE=ALL MASK=0x2",
4504 bss_list,
4505 sizeof(bss_list)) < 0) {
4506 sigma_dut_print(dut, DUT_MSG_ERROR,
4507 "Failed to get bss list");
4508 return -1;
4509 }
4510
4511 sigma_dut_print(dut, DUT_MSG_DEBUG,
4512 "bss list for ifname:%s is:%s",
4513 ifname, bss_list);
4514
4515 snprintf(buf, sizeof(buf), "DeviceList");
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304516 bss_line = strtok_r(bss_list, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004517 while (bss_line) {
4518 if (sscanf(bss_line, "bssid=%ms", &bss_id) > 0 &&
4519 bss_id) {
4520 int len;
4521
4522 len = snprintf(buf + strlen(buf),
4523 sizeof(buf) - strlen(buf),
4524 ",%s", bss_id);
4525 free(bss_id);
4526 bss_id = NULL;
4527 if (len < 0) {
4528 sigma_dut_print(dut,
4529 DUT_MSG_ERROR,
4530 "Failed to read BSSID");
4531 send_resp(dut, conn, SIGMA_ERROR,
4532 "ErrorCode,Failed to read BSS ID");
4533 return 0;
4534 }
4535
4536 if ((size_t) len >= sizeof(buf) - strlen(buf)) {
4537 sigma_dut_print(dut,
4538 DUT_MSG_ERROR,
4539 "Response buf too small for list");
4540 send_resp(dut, conn,
4541 SIGMA_ERROR,
4542 "ErrorCode,Response buf too small for list");
4543 return 0;
4544 }
4545 }
4546
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05304547 bss_line = strtok_r(NULL, "\n", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004548 }
4549
4550 sigma_dut_print(dut, DUT_MSG_INFO, "DiscoveredDevList is %s",
4551 buf);
4552 send_resp(dut, conn, SIGMA_COMPLETE, buf);
4553 return 0;
4554 }
4555
4556 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4557 return 0;
4558}
4559
4560
4561static int cmd_sta_get_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
4562 struct sigma_cmd *cmd)
4563{
4564 const char *program = get_param(cmd, "Program");
4565
4566 if (program == NULL)
4567 return -1;
4568
4569 if (strcasecmp(program, "P2PNFC") == 0)
4570 return p2p_cmd_sta_get_parameter(dut, conn, cmd);
4571
4572 if (strcasecmp(program, "60ghz") == 0)
4573 return sta_get_parameter_60g(dut, conn, cmd);
4574
4575#ifdef ANDROID_NAN
4576 if (strcasecmp(program, "NAN") == 0)
Amarnath Hullur Subramanyam1854ec62016-08-11 19:29:35 -07004577 return nan_cmd_sta_get_parameter(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004578#endif /* ANDROID_NAN */
4579
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004580#ifdef MIRACAST
4581 if (strcasecmp(program, "WFD") == 0 ||
4582 strcasecmp(program, "DisplayR2") == 0)
4583 return miracast_cmd_sta_get_parameter(dut, conn, cmd);
4584#endif /* MIRACAST */
4585
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004586 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4587 return 0;
4588}
4589
4590
4591static void sta_reset_default_ath(struct sigma_dut *dut, const char *intf,
4592 const char *type)
4593{
4594 char buf[100];
4595
4596 if (dut->program == PROGRAM_VHT) {
4597 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 2", intf);
4598 if (system(buf) != 0) {
4599 sigma_dut_print(dut, DUT_MSG_ERROR,
4600 "iwpriv %s chwidth failed", intf);
4601 }
4602
4603 snprintf(buf, sizeof(buf), "iwpriv %s mode 11ACVHT80", intf);
4604 if (system(buf) != 0) {
4605 sigma_dut_print(dut, DUT_MSG_ERROR,
4606 "iwpriv %s mode 11ACVHT80 failed",
4607 intf);
4608 }
4609
4610 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs -1", intf);
4611 if (system(buf) != 0) {
4612 sigma_dut_print(dut, DUT_MSG_ERROR,
4613 "iwpriv %s vhtmcs -1 failed", intf);
4614 }
4615 }
4616
4617 if (dut->program == PROGRAM_HT) {
4618 snprintf(buf, sizeof(buf), "iwpriv %s chwidth 0", intf);
4619 if (system(buf) != 0) {
4620 sigma_dut_print(dut, DUT_MSG_ERROR,
4621 "iwpriv %s chwidth failed", intf);
4622 }
4623
4624 snprintf(buf, sizeof(buf), "iwpriv %s mode 11naht40", intf);
4625 if (system(buf) != 0) {
4626 sigma_dut_print(dut, DUT_MSG_ERROR,
4627 "iwpriv %s mode 11naht40 failed",
4628 intf);
4629 }
4630
4631 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0", intf);
4632 if (system(buf) != 0) {
4633 sigma_dut_print(dut, DUT_MSG_ERROR,
4634 "iwpriv set11NRates failed");
4635 }
4636 }
4637
4638 if (dut->program == PROGRAM_VHT || dut->program == PROGRAM_HT) {
4639 snprintf(buf, sizeof(buf), "iwpriv %s powersave 0", intf);
4640 if (system(buf) != 0) {
4641 sigma_dut_print(dut, DUT_MSG_ERROR,
4642 "disabling powersave failed");
4643 }
4644
4645 /* Reset CTS width */
4646 snprintf(buf, sizeof(buf), "wifitool %s beeliner_fw_test 54 0",
4647 intf);
4648 if (system(buf) != 0) {
4649 sigma_dut_print(dut, DUT_MSG_ERROR,
4650 "wifitool %s beeliner_fw_test 54 0 failed",
4651 intf);
4652 }
4653
4654 /* Enable Dynamic Bandwidth signalling by default */
4655 snprintf(buf, sizeof(buf), "iwpriv %s cwmenable 1", intf);
4656 if (system(buf) != 0) {
4657 sigma_dut_print(dut, DUT_MSG_ERROR,
4658 "iwpriv %s cwmenable 1 failed", intf);
4659 }
4660
4661 snprintf(buf, sizeof(buf), "iwconfig %s rts 2347", intf);
4662 if (system(buf) != 0) {
4663 sigma_dut_print(dut, DUT_MSG_ERROR,
4664 "iwpriv rts failed");
4665 }
4666 }
4667
4668 if (type && strcasecmp(type, "Testbed") == 0) {
4669 dut->testbed_flag_txsp = 1;
4670 dut->testbed_flag_rxsp = 1;
4671 /* STA has to set spatial stream to 2 per Appendix H */
4672 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0xfff0", intf);
4673 if (system(buf) != 0) {
4674 sigma_dut_print(dut, DUT_MSG_ERROR,
4675 "iwpriv vht_mcsmap failed");
4676 }
4677
4678 /* Disable LDPC per Appendix H */
4679 snprintf(buf, sizeof(buf), "iwpriv %s ldpc 0", intf);
4680 if (system(buf) != 0) {
4681 sigma_dut_print(dut, DUT_MSG_ERROR,
4682 "iwpriv %s ldpc 0 failed", intf);
4683 }
4684
4685 snprintf(buf, sizeof(buf), "iwpriv %s amsdu 1", intf);
4686 if (system(buf) != 0) {
4687 sigma_dut_print(dut, DUT_MSG_ERROR,
4688 "iwpriv amsdu failed");
4689 }
4690
4691 /* TODO: Disable STBC 2x1 transmit and receive */
4692 snprintf(buf, sizeof(buf), "iwpriv %s tx_stbc 0", intf);
4693 if (system(buf) != 0) {
4694 sigma_dut_print(dut, DUT_MSG_ERROR,
4695 "Disable tx_stbc 0 failed");
4696 }
4697
4698 snprintf(buf, sizeof(buf), "iwpriv %s rx_stbc 0", intf);
4699 if (system(buf) != 0) {
4700 sigma_dut_print(dut, DUT_MSG_ERROR,
4701 "Disable rx_stbc 0 failed");
4702 }
4703
4704 /* STA has to disable Short GI per Appendix H */
4705 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 0", intf);
4706 if (system(buf) != 0) {
4707 sigma_dut_print(dut, DUT_MSG_ERROR,
4708 "iwpriv %s shortgi 0 failed", intf);
4709 }
4710 }
4711
4712 if (type && strcasecmp(type, "DUT") == 0) {
4713 snprintf(buf, sizeof(buf), "iwpriv %s nss 3", intf);
4714 if (system(buf) != 0) {
4715 sigma_dut_print(dut, DUT_MSG_ERROR,
4716 "iwpriv %s nss 3 failed", intf);
4717 }
4718
4719 snprintf(buf, sizeof(buf), "iwpriv %s shortgi 1", intf);
4720 if (system(buf) != 0) {
4721 sigma_dut_print(dut, DUT_MSG_ERROR,
4722 "iwpriv %s shortgi 1 failed", intf);
4723 }
4724 }
4725}
4726
4727
4728static int cmd_sta_reset_default(struct sigma_dut *dut,
4729 struct sigma_conn *conn,
4730 struct sigma_cmd *cmd)
4731{
4732 int cmd_sta_p2p_reset(struct sigma_dut *dut, struct sigma_conn *conn,
4733 struct sigma_cmd *cmd);
4734 const char *intf = get_param(cmd, "Interface");
4735 const char *type;
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004736 const char *program = get_param(cmd, "program");
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004737
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004738 if (!program)
4739 program = get_param(cmd, "prog");
4740 dut->program = sigma_program_to_enum(program);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004741 dut->device_type = STA_unknown;
4742 type = get_param(cmd, "type");
4743 if (type && strcasecmp(type, "Testbed") == 0)
4744 dut->device_type = STA_testbed;
4745 if (type && strcasecmp(type, "DUT") == 0)
4746 dut->device_type = STA_dut;
4747
4748 if (dut->program == PROGRAM_TDLS) {
4749 /* Clear TDLS testing mode */
4750 wpa_command(intf, "SET tdls_disabled 0");
4751 wpa_command(intf, "SET tdls_testing 0");
4752 dut->no_tpk_expiration = 0;
Pradeep Reddy POTTETI8ce2a232016-10-28 12:17:32 +05304753 if (get_driver_type() == DRIVER_WCN) {
4754 /* Enable the WCN driver in TDLS Explicit trigger mode
4755 */
4756 wpa_command(intf, "SET tdls_external_control 0");
4757 wpa_command(intf, "SET tdls_trigger_control 0");
4758 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004759 }
4760
Amarnath Hullur Subramanyam9c381f52017-03-17 00:04:41 -07004761#ifdef MIRACAST
4762 if (dut->program == PROGRAM_WFD ||
4763 dut->program == PROGRAM_DISPLAYR2)
4764 miracast_sta_reset_default(dut, conn, cmd);
4765#endif /* MIRACAST */
4766
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004767 switch (get_driver_type()) {
4768 case DRIVER_ATHEROS:
4769 sta_reset_default_ath(dut, intf, type);
4770 break;
4771 default:
4772 break;
4773 }
4774
4775#ifdef ANDROID_NAN
4776 if (dut->program == PROGRAM_NAN)
4777 nan_cmd_sta_reset_default(dut, conn, cmd);
4778#endif /* ANDROID_NAN */
4779
4780 if (dut->program == PROGRAM_HS2_R2) {
4781 unlink("SP/wi-fi.org/pps.xml");
4782 if (system("rm -r SP/*") != 0) {
4783 }
4784 unlink("next-client-cert.pem");
4785 unlink("next-client-key.pem");
4786 }
4787
4788 if (dut->program == PROGRAM_60GHZ) {
4789 const char *dev_role = get_param(cmd, "DevRole");
4790
4791 if (!dev_role) {
4792 send_resp(dut, conn, SIGMA_ERROR,
4793 "errorCode,Missing DevRole argument");
4794 return 0;
4795 }
4796
4797 if (strcasecmp(dev_role, "STA") == 0)
4798 dut->dev_role = DEVROLE_STA;
4799 else if (strcasecmp(dev_role, "PCP") == 0)
4800 dut->dev_role = DEVROLE_PCP;
4801 else {
4802 send_resp(dut, conn, SIGMA_ERROR,
4803 "errorCode,Unknown DevRole");
4804 return 0;
4805 }
4806
4807 if (dut->device_type == STA_unknown) {
4808 sigma_dut_print(dut, DUT_MSG_ERROR,
4809 "Device type is not STA testbed or DUT");
4810 send_resp(dut, conn, SIGMA_ERROR,
4811 "errorCode,Unknown device type");
4812 return 0;
4813 }
4814 }
4815
4816 wpa_command(intf, "WPS_ER_STOP");
4817 wpa_command(intf, "FLUSH");
4818 wpa_command(intf, "SET radio_disabled 0");
4819
4820 if (dut->tmp_mac_addr && dut->set_macaddr) {
4821 dut->tmp_mac_addr = 0;
4822 if (system(dut->set_macaddr) != 0) {
4823 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to clear "
4824 "temporary MAC address");
4825 }
4826 }
4827
4828 set_ps(intf, dut, 0);
4829
4830 if (dut->program == PROGRAM_HS2 || dut->program == PROGRAM_HS2_R2) {
4831 wpa_command(intf, "SET interworking 1");
4832 wpa_command(intf, "SET hs20 1");
4833 }
4834
4835 if (dut->program == PROGRAM_HS2_R2) {
4836 wpa_command(intf, "SET pmf 1");
4837 } else {
4838 wpa_command(intf, "SET pmf 0");
4839 }
4840
4841 hs2_clear_credentials(intf);
4842 wpa_command(intf, "SET hessid 00:00:00:00:00:00");
4843 wpa_command(intf, "SET access_network_type 15");
4844
4845 static_ip_file(0, NULL, NULL, NULL);
4846 kill_dhcp_client(dut, intf);
4847 clear_ip_addr(dut, intf);
4848
4849 dut->er_oper_performed = 0;
4850 dut->er_oper_bssid[0] = '\0';
4851
priyadharshini gowthamanad6cbba2016-10-04 10:39:58 -07004852 if (dut->program == PROGRAM_LOC) {
4853 /* Disable Interworking by default */
4854 wpa_command(get_station_ifname(), "SET interworking 0");
4855 }
4856
Ashwini Patil00402582017-04-13 12:29:39 +05304857 if (dut->program == PROGRAM_MBO) {
4858 free(dut->non_pref_ch_list);
4859 dut->non_pref_ch_list = NULL;
Ashwini Patil5acd7382017-04-13 15:55:04 +05304860 free(dut->btm_query_cand_list);
4861 dut->btm_query_cand_list = NULL;
Ashwini Patilc63161e2017-04-13 16:30:23 +05304862 wpa_command(intf, "SET reject_btm_req_reason 0");
Ashwini Patila75de5a2017-04-13 16:35:05 +05304863 wpa_command(intf, "SET ignore_assoc_disallow 0");
Ashwini Patild174f2c2017-04-13 16:49:46 +05304864 wpa_command(intf, "SET gas_address3 0");
Ashwini Patil9183fdb2017-04-13 16:58:25 +05304865 wpa_command(intf, "SET roaming 1");
Ashwini Patil00402582017-04-13 12:29:39 +05304866 }
4867
Jouni Malinen3c367e82017-06-23 17:01:47 +03004868 free(dut->rsne_override);
4869 dut->rsne_override = NULL;
4870
Priyadharshini Gowthamana7dfd492015-11-09 14:34:08 -08004871 if (dut->program != PROGRAM_VHT)
4872 return cmd_sta_p2p_reset(dut, conn, cmd);
4873 return 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004874}
4875
4876
4877static int cmd_sta_get_events(struct sigma_dut *dut, struct sigma_conn *conn,
4878 struct sigma_cmd *cmd)
4879{
4880 const char *program = get_param(cmd, "Program");
4881
4882 if (program == NULL)
4883 return -1;
4884#ifdef ANDROID_NAN
4885 if (strcasecmp(program, "NAN") == 0)
4886 return nan_cmd_sta_get_events(dut, conn, cmd);
4887#endif /* ANDROID_NAN */
4888 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4889 return 0;
4890}
4891
4892
4893static int cmd_sta_exec_action(struct sigma_dut *dut, struct sigma_conn *conn,
4894 struct sigma_cmd *cmd)
4895{
4896 const char *program = get_param(cmd, "Prog");
4897
4898 if (program == NULL)
4899 return -1;
4900#ifdef ANDROID_NAN
4901 if (strcasecmp(program, "NAN") == 0)
4902 return nan_cmd_sta_exec_action(dut, conn, cmd);
4903#endif /* ANDROID_NAN */
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07004904 if (strcasecmp(program, "Loc") == 0)
4905 return loc_cmd_sta_exec_action(dut, conn, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004906 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported parameter");
4907 return 0;
4908}
4909
4910
4911static int cmd_sta_set_11n(struct sigma_dut *dut, struct sigma_conn *conn,
4912 struct sigma_cmd *cmd)
4913{
4914 const char *intf = get_param(cmd, "Interface");
4915 const char *val, *mcs32, *rate;
4916
4917 val = get_param(cmd, "GREENFIELD");
4918 if (val) {
4919 if (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0) {
4920 /* Enable GD */
4921 send_resp(dut, conn, SIGMA_ERROR,
4922 "ErrorCode,GF not supported");
4923 return 0;
4924 }
4925 }
4926
4927 val = get_param(cmd, "SGI20");
4928 if (val) {
4929 switch (get_driver_type()) {
4930 case DRIVER_ATHEROS:
4931 ath_sta_set_sgi(dut, intf, val);
4932 break;
4933 default:
4934 send_resp(dut, conn, SIGMA_ERROR,
4935 "ErrorCode,SGI20 not supported");
4936 return 0;
4937 }
4938 }
4939
4940 mcs32 = get_param(cmd, "MCS32"); /* HT Duplicate Mode Enable/Disable */
4941 rate = get_param(cmd, "MCS_FIXEDRATE"); /* Fixed MCS rate (0..31) */
4942 if (mcs32 && rate) {
4943 /* TODO */
4944 send_resp(dut, conn, SIGMA_ERROR,
4945 "ErrorCode,MCS32,MCS_FIXEDRATE not supported");
4946 return 0;
4947 } else if (mcs32 && !rate) {
4948 /* TODO */
4949 send_resp(dut, conn, SIGMA_ERROR,
4950 "ErrorCode,MCS32 not supported");
4951 return 0;
4952 } else if (!mcs32 && rate) {
4953 switch (get_driver_type()) {
4954 case DRIVER_ATHEROS:
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08004955 novap_reset(dut, intf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02004956 ath_sta_set_11nrates(dut, intf, rate);
4957 break;
4958 default:
4959 send_resp(dut, conn, SIGMA_ERROR,
4960 "ErrorCode,MCS32_FIXEDRATE not supported");
4961 return 0;
4962 }
4963 }
4964
4965 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
4966}
4967
4968
4969static int cmd_sta_set_wireless_vht(struct sigma_dut *dut,
4970 struct sigma_conn *conn,
4971 struct sigma_cmd *cmd)
4972{
4973 const char *intf = get_param(cmd, "Interface");
4974 const char *val;
4975 char buf[30];
4976 int tkip = -1;
4977 int wep = -1;
4978
4979 val = get_param(cmd, "SGI80");
4980 if (val) {
4981 int sgi80;
4982
4983 sgi80 = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
4984 snprintf(buf, sizeof(buf), "iwpriv %s shortgi %d", intf, sgi80);
4985 if (system(buf) != 0) {
4986 sigma_dut_print(dut, DUT_MSG_ERROR,
4987 "iwpriv shortgi failed");
4988 }
4989 }
4990
4991 val = get_param(cmd, "TxBF");
4992 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
4993 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfee 1", intf);
4994 if (system(buf) != 0) {
4995 sigma_dut_print(dut, DUT_MSG_ERROR,
4996 "iwpriv vhtsubfee failed");
4997 }
4998 snprintf(buf, sizeof(buf), "iwpriv %s vhtsubfer 1", intf);
4999 if (system(buf) != 0) {
5000 sigma_dut_print(dut, DUT_MSG_ERROR,
5001 "iwpriv vhtsubfer failed");
5002 }
5003 }
5004
5005 val = get_param(cmd, "MU_TxBF");
5006 if (val && (strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0)) {
5007 switch (get_driver_type()) {
5008 case DRIVER_ATHEROS:
5009 ath_sta_set_txsp_stream(dut, intf, "1SS");
5010 ath_sta_set_rxsp_stream(dut, intf, "1SS");
5011 case DRIVER_WCN:
5012 if (wcn_sta_set_sp_stream(dut, intf, "1SS") < 0) {
5013 send_resp(dut, conn, SIGMA_ERROR,
5014 "ErrorCode,Failed to set RX/TXSP_STREAM");
5015 return 0;
5016 }
5017 default:
5018 sigma_dut_print(dut, DUT_MSG_ERROR,
5019 "Setting SP_STREAM not supported");
5020 break;
5021 }
5022 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfee 1", intf);
5023 if (system(buf) != 0) {
5024 sigma_dut_print(dut, DUT_MSG_ERROR,
5025 "iwpriv vhtmubfee failed");
5026 }
5027 snprintf(buf, sizeof(buf), "iwpriv %s vhtmubfer 1", intf);
5028 if (system(buf) != 0) {
5029 sigma_dut_print(dut, DUT_MSG_ERROR,
5030 "iwpriv vhtmubfer failed");
5031 }
5032 }
5033
5034 val = get_param(cmd, "LDPC");
5035 if (val) {
5036 int ldpc;
5037
5038 ldpc = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5039 snprintf(buf, sizeof(buf), "iwpriv %s ldpc %d", intf, ldpc);
5040 if (system(buf) != 0) {
5041 sigma_dut_print(dut, DUT_MSG_ERROR,
5042 "iwpriv ldpc failed");
5043 }
5044 }
5045
5046 val = get_param(cmd, "opt_md_notif_ie");
5047 if (val) {
5048 char *result = NULL;
5049 char delim[] = ";";
5050 char token[30];
5051 int value, config_val = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305052 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005053
Peng Xub8fc5cc2017-05-10 17:27:28 -07005054 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305055 result = strtok_r(token, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005056
5057 /* Extract the NSS information */
5058 if (result) {
5059 value = atoi(result);
5060 switch (value) {
5061 case 1:
5062 config_val = 1;
5063 break;
5064 case 2:
5065 config_val = 3;
5066 break;
5067 case 3:
5068 config_val = 7;
5069 break;
5070 case 4:
5071 config_val = 15;
5072 break;
5073 default:
5074 config_val = 3;
5075 break;
5076 }
5077
5078 snprintf(buf, sizeof(buf), "iwpriv %s rxchainmask %d",
5079 intf, config_val);
5080 if (system(buf) != 0) {
5081 sigma_dut_print(dut, DUT_MSG_ERROR,
5082 "iwpriv rxchainmask failed");
5083 }
5084
5085 snprintf(buf, sizeof(buf), "iwpriv %s txchainmask %d",
5086 intf, config_val);
5087 if (system(buf) != 0) {
5088 sigma_dut_print(dut, DUT_MSG_ERROR,
5089 "iwpriv txchainmask failed");
5090 }
5091 }
5092
5093 /* Extract the channel width information */
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305094 result = strtok_r(NULL, delim, &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005095 if (result) {
5096 value = atoi(result);
5097 switch (value) {
5098 case 20:
5099 config_val = 0;
5100 break;
5101 case 40:
5102 config_val = 1;
5103 break;
5104 case 80:
5105 config_val = 2;
5106 break;
5107 case 160:
5108 config_val = 3;
5109 break;
5110 default:
5111 config_val = 2;
5112 break;
5113 }
5114
5115 dut->chwidth = config_val;
5116
5117 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
5118 intf, config_val);
5119 if (system(buf) != 0) {
5120 sigma_dut_print(dut, DUT_MSG_ERROR,
5121 "iwpriv chwidth failed");
5122 }
5123 }
5124
5125 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", intf);
5126 if (system(buf) != 0) {
5127 sigma_dut_print(dut, DUT_MSG_ERROR,
5128 "iwpriv opmode_notify failed");
5129 }
5130 }
5131
5132 val = get_param(cmd, "nss_mcs_cap");
5133 if (val) {
5134 int nss, mcs;
5135 char token[20];
5136 char *result = NULL;
5137 unsigned int vht_mcsmap = 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305138 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005139
Peng Xub8fc5cc2017-05-10 17:27:28 -07005140 strlcpy(token, val, sizeof(token));
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305141 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05305142 if (!result) {
5143 sigma_dut_print(dut, DUT_MSG_ERROR,
5144 "VHT NSS not specified");
5145 return 0;
5146 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005147 nss = atoi(result);
5148
5149 snprintf(buf, sizeof(buf), "iwpriv %s nss %d", intf, nss);
5150 if (system(buf) != 0) {
5151 sigma_dut_print(dut, DUT_MSG_ERROR,
5152 "iwpriv nss failed");
5153 }
5154
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305155 result = strtok_r(NULL, ";", &saveptr);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005156 if (result == NULL) {
5157 sigma_dut_print(dut, DUT_MSG_ERROR,
5158 "VHTMCS NOT SPECIFIED!");
5159 return 0;
5160 }
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05305161 result = strtok_r(result, "-", &saveptr);
5162 result = strtok_r(NULL, "-", &saveptr);
Pradeep Reddy POTTETIcd649a22016-01-29 12:55:59 +05305163 if (!result) {
5164 sigma_dut_print(dut, DUT_MSG_ERROR,
5165 "VHT MCS not specified");
5166 return 0;
5167 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005168 mcs = atoi(result);
5169
5170 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d", intf, mcs);
5171 if (system(buf) != 0) {
5172 sigma_dut_print(dut, DUT_MSG_ERROR,
5173 "iwpriv mcs failed");
5174 }
5175
5176 switch (nss) {
5177 case 1:
5178 switch (mcs) {
5179 case 7:
5180 vht_mcsmap = 0xfffc;
5181 break;
5182 case 8:
5183 vht_mcsmap = 0xfffd;
5184 break;
5185 case 9:
5186 vht_mcsmap = 0xfffe;
5187 break;
5188 default:
5189 vht_mcsmap = 0xfffe;
5190 break;
5191 }
5192 break;
5193 case 2:
5194 switch (mcs) {
5195 case 7:
5196 vht_mcsmap = 0xfff0;
5197 break;
5198 case 8:
5199 vht_mcsmap = 0xfff5;
5200 break;
5201 case 9:
5202 vht_mcsmap = 0xfffa;
5203 break;
5204 default:
5205 vht_mcsmap = 0xfffa;
5206 break;
5207 }
5208 break;
5209 case 3:
5210 switch (mcs) {
5211 case 7:
5212 vht_mcsmap = 0xffc0;
5213 break;
5214 case 8:
5215 vht_mcsmap = 0xffd5;
5216 break;
5217 case 9:
5218 vht_mcsmap = 0xffea;
5219 break;
5220 default:
5221 vht_mcsmap = 0xffea;
5222 break;
5223 }
5224 break;
5225 default:
5226 vht_mcsmap = 0xffea;
5227 break;
5228 }
5229 snprintf(buf, sizeof(buf), "iwpriv %s vht_mcsmap 0x%04x",
5230 intf, vht_mcsmap);
5231 if (system(buf) != 0) {
5232 sigma_dut_print(dut, DUT_MSG_ERROR,
5233 "iwpriv vht_mcsmap failed");
5234 }
5235 }
5236
5237 /* UNSUPPORTED: val = get_param(cmd, "Tx_lgi_rate"); */
5238
5239 val = get_param(cmd, "Vht_tkip");
5240 if (val)
5241 tkip = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5242
5243 val = get_param(cmd, "Vht_wep");
5244 if (val)
5245 wep = strcmp(val, "1") == 0 || strcasecmp(val, "Enable") == 0;
5246
5247 if (tkip != -1 || wep != -1) {
5248 if ((tkip == 1 && wep != 0) || (wep == 1 && tkip != 0)) {
5249 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 1",
5250 intf);
5251 } else if ((tkip == 0 && wep != 1) || (wep == 0 && tkip != 1)) {
5252 snprintf(buf, sizeof(buf), "iwpriv %s htweptkip 0",
5253 intf);
5254 } else {
5255 sigma_dut_print(dut, DUT_MSG_ERROR,
5256 "ErrorCode,mixed mode of VHT TKIP/WEP not supported");
5257 return 0;
5258 }
5259
5260 if (system(buf) != 0) {
5261 sigma_dut_print(dut, DUT_MSG_ERROR,
5262 "iwpriv htweptkip failed");
5263 }
5264 }
5265
5266 val = get_param(cmd, "txBandwidth");
5267 if (val) {
5268 switch (get_driver_type()) {
5269 case DRIVER_ATHEROS:
5270 if (ath_set_width(dut, conn, intf, val) < 0) {
5271 send_resp(dut, conn, SIGMA_ERROR,
5272 "ErrorCode,Failed to set txBandwidth");
5273 return 0;
5274 }
5275 break;
5276 default:
5277 sigma_dut_print(dut, DUT_MSG_ERROR,
5278 "Setting txBandwidth not supported");
5279 break;
5280 }
5281 }
5282
5283 return cmd_sta_set_wireless_common(intf, dut, conn, cmd);
5284}
5285
5286
5287static int sta_set_wireless_60g(struct sigma_dut *dut,
5288 struct sigma_conn *conn,
5289 struct sigma_cmd *cmd)
5290{
5291 const char *dev_role = get_param(cmd, "DevRole");
5292
5293 if (!dev_role) {
5294 send_resp(dut, conn, SIGMA_INVALID,
5295 "ErrorCode,DevRole not specified");
5296 return 0;
5297 }
5298
5299 if (strcasecmp(dev_role, "PCP") == 0)
5300 return sta_set_60g_pcp(dut, conn, cmd);
5301 if (strcasecmp(dev_role, "STA") == 0)
5302 return sta_set_60g_sta(dut, conn, cmd);
5303 send_resp(dut, conn, SIGMA_INVALID,
5304 "ErrorCode,DevRole not supported");
5305 return 0;
5306}
5307
5308
5309static int cmd_sta_set_wireless(struct sigma_dut *dut, struct sigma_conn *conn,
5310 struct sigma_cmd *cmd)
5311{
5312 const char *val;
5313
5314 val = get_param(cmd, "Program");
5315 if (val) {
5316 if (strcasecmp(val, "11n") == 0)
5317 return cmd_sta_set_11n(dut, conn, cmd);
5318 if (strcasecmp(val, "VHT") == 0)
5319 return cmd_sta_set_wireless_vht(dut, conn, cmd);
5320 if (strcasecmp(val, "60ghz") == 0)
5321 return sta_set_wireless_60g(dut, conn, cmd);
5322 send_resp(dut, conn, SIGMA_ERROR,
5323 "ErrorCode,Program value not supported");
5324 } else {
5325 send_resp(dut, conn, SIGMA_ERROR,
5326 "ErrorCode,Program argument not available");
5327 }
5328
5329 return 0;
5330}
5331
5332
5333static void ath_sta_inject_frame(struct sigma_dut *dut, const char *intf,
5334 int tid)
5335{
5336 char buf[100];
5337 int tid_to_dscp [] = { 0x00, 0x20, 0x40, 0x60, 0x80, 0xa0, 0xc0, 0xe0 };
5338
Pradeep Reddy POTTETId31d1322016-10-13 17:22:03 +05305339 if (tid < 0 ||
5340 tid >= (int) (sizeof(tid_to_dscp) / sizeof(tid_to_dscp[0]))) {
5341 sigma_dut_print(dut, DUT_MSG_ERROR, "Unsupported TID: %d", tid);
5342 return;
5343 }
5344
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005345 /*
5346 * Two ways to ensure that addba request with a
5347 * non zero TID could be sent out. EV 117296
5348 */
5349 snprintf(buf, sizeof(buf),
5350 "ping -c 8 -Q %d `arp -a | grep wlan0 | awk '{print $2}' | tr -d '()'`",
5351 tid);
5352 if (system(buf) != 0) {
5353 sigma_dut_print(dut, DUT_MSG_ERROR,
5354 "Ping did not send out");
5355 }
5356
5357 snprintf(buf, sizeof(buf),
5358 "iwconfig %s | grep Access | awk '{print $6}' > %s",
5359 intf, VI_QOS_TMP_FILE);
5360 if (system(buf) != 0)
5361 return;
5362
5363 snprintf(buf, sizeof(buf),
5364 "ifconfig %s | grep HWaddr | cut -b 39-56 >> %s",
5365 intf, VI_QOS_TMP_FILE);
5366 if (system(buf) != 0)
5367 sigma_dut_print(dut, DUT_MSG_ERROR, "HWaddr matching failed");
5368
5369 snprintf(buf,sizeof(buf), "sed -n '3,$p' %s >> %s",
5370 VI_QOS_REFFILE, VI_QOS_TMP_FILE);
5371 if (system(buf) != 0) {
5372 sigma_dut_print(dut, DUT_MSG_ERROR,
5373 "VI_QOS_TEMP_FILE generation error failed");
5374 }
5375 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
5376 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
5377 if (system(buf) != 0) {
5378 sigma_dut_print(dut, DUT_MSG_ERROR,
5379 "VI_QOS_FILE generation failed");
5380 }
5381
5382 snprintf(buf, sizeof(buf), "sed '5 c %x' %s > %s",
5383 tid_to_dscp[tid], VI_QOS_TMP_FILE, VI_QOS_FILE);
5384 if (system(buf) != 0) {
5385 sigma_dut_print(dut, DUT_MSG_ERROR,
5386 "VI_QOS_FILE generation failed");
5387 }
5388
5389 snprintf(buf, sizeof(buf), "ethinject %s %s", intf, VI_QOS_FILE);
5390 if (system(buf) != 0) {
5391 }
5392}
5393
5394
5395static int ath_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
5396 struct sigma_cmd *cmd)
5397{
5398 const char *intf = get_param(cmd, "Interface");
5399 const char *val;
5400 int tid = 0;
5401 char buf[100];
5402
5403 val = get_param(cmd, "TID");
5404 if (val) {
5405 tid = atoi(val);
5406 if (tid)
5407 ath_sta_inject_frame(dut, intf, tid);
5408 }
5409
5410 /* Command sequence for ADDBA request on Peregrine based devices */
5411 snprintf(buf, sizeof(buf), "iwpriv %s setaddbaoper 1", intf);
5412 if (system(buf) != 0) {
5413 sigma_dut_print(dut, DUT_MSG_ERROR,
5414 "iwpriv setaddbaoper failed");
5415 }
5416
5417 snprintf(buf, sizeof(buf), "wifitool %s senddelba 1 %d 1 4", intf, tid);
5418 if (system(buf) != 0) {
5419 sigma_dut_print(dut, DUT_MSG_ERROR,
5420 "wifitool senddelba failed");
5421 }
5422
5423 snprintf(buf, sizeof(buf), "wifitool %s sendaddba 1 %d 64", intf, tid);
5424 if (system(buf) != 0) {
5425 sigma_dut_print(dut, DUT_MSG_ERROR,
5426 "wifitool sendaddba failed");
5427 }
5428
5429 /* UNSUPPORTED: val = get_param(cmd, "Dest_mac"); */
5430
5431 return 1;
5432}
5433
5434
Lior David9981b512017-01-20 13:16:40 +02005435#ifdef __linux__
5436
5437static int wil6210_send_addba(struct sigma_dut *dut, const char *dest_mac,
5438 int agg_size)
5439{
5440 char dir[128], buf[128];
5441 FILE *f;
5442 regex_t re;
5443 regmatch_t m[2];
5444 int rc, ret = -1, vring_id, found;
5445
5446 if (wil6210_get_debugfs_dir(dut, dir, sizeof(dir))) {
5447 sigma_dut_print(dut, DUT_MSG_ERROR,
5448 "failed to get wil6210 debugfs dir");
5449 return -1;
5450 }
5451
5452 snprintf(buf, sizeof(buf), "%s/vrings", dir);
5453 f = fopen(buf, "r");
5454 if (!f) {
5455 sigma_dut_print(dut, DUT_MSG_ERROR, "failed to open: %s", buf);
5456 return -1;
5457 }
5458
5459 if (regcomp(&re, "VRING tx_[ \t]*([0-9]+)", REG_EXTENDED)) {
5460 sigma_dut_print(dut, DUT_MSG_ERROR, "regcomp failed");
5461 goto out;
5462 }
5463
5464 /* find TX VRING for the mac address */
5465 found = 0;
5466 while (fgets(buf, sizeof(buf), f)) {
5467 if (strcasestr(buf, dest_mac)) {
5468 found = 1;
5469 break;
5470 }
5471 }
5472
5473 if (!found) {
5474 sigma_dut_print(dut, DUT_MSG_ERROR,
5475 "no TX VRING for %s", dest_mac);
5476 goto out;
5477 }
5478
5479 /* extract VRING ID, "VRING tx_<id> = {" */
5480 if (!fgets(buf, sizeof(buf), f)) {
5481 sigma_dut_print(dut, DUT_MSG_ERROR,
5482 "no VRING start line for %s", dest_mac);
5483 goto out;
5484 }
5485
5486 rc = regexec(&re, buf, 2, m, 0);
5487 regfree(&re);
5488 if (rc || m[1].rm_so < 0) {
5489 sigma_dut_print(dut, DUT_MSG_ERROR,
5490 "no VRING TX ID for %s", dest_mac);
5491 goto out;
5492 }
5493 buf[m[1].rm_eo] = 0;
5494 vring_id = atoi(&buf[m[1].rm_so]);
5495
5496 /* send the addba command */
5497 fclose(f);
5498 snprintf(buf, sizeof(buf), "%s/back", dir);
5499 f = fopen(buf, "w");
5500 if (!f) {
5501 sigma_dut_print(dut, DUT_MSG_ERROR,
5502 "failed to open: %s", buf);
5503 return -1;
5504 }
5505
5506 fprintf(f, "add %d %d\n", vring_id, agg_size);
5507
5508 ret = 0;
5509
5510out:
5511 fclose(f);
5512
5513 return ret;
5514}
5515
5516
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005517static int send_addba_60g(struct sigma_dut *dut, struct sigma_conn *conn,
5518 struct sigma_cmd *cmd)
5519{
5520 const char *val;
5521 int tid = 0;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005522
5523 val = get_param(cmd, "TID");
5524 if (val) {
5525 tid = atoi(val);
5526 if (tid != 0) {
5527 sigma_dut_print(dut, DUT_MSG_ERROR,
5528 "Ignore TID %d for send_addba use TID 0 for 60g since only 0 required on TX",
5529 tid);
5530 }
5531 }
5532
5533 val = get_param(cmd, "Dest_mac");
5534 if (!val) {
5535 sigma_dut_print(dut, DUT_MSG_ERROR,
5536 "Currently not supporting addba for 60G without Dest_mac");
5537 return SIGMA_DUT_ERROR_CALLER_SEND_STATUS;
5538 }
5539
Lior David9981b512017-01-20 13:16:40 +02005540 if (wil6210_send_addba(dut, val, dut->back_rcv_buf))
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005541 return -1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005542
5543 return 1;
5544}
5545
Lior David9981b512017-01-20 13:16:40 +02005546#endif /* __linux__ */
5547
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005548
5549static int cmd_sta_send_addba(struct sigma_dut *dut, struct sigma_conn *conn,
5550 struct sigma_cmd *cmd)
5551{
5552 switch (get_driver_type()) {
5553 case DRIVER_ATHEROS:
5554 return ath_sta_send_addba(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02005555#ifdef __linux__
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005556 case DRIVER_WIL6210:
5557 return send_addba_60g(dut, conn, cmd);
Lior David9981b512017-01-20 13:16:40 +02005558#endif /* __linux__ */
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005559 default:
5560 /*
5561 * There is no driver specific implementation for other drivers.
5562 * Ignore the command and report COMPLETE since the following
5563 * throughput test operation will end up sending ADDBA anyway.
5564 */
5565 return 1;
5566 }
5567}
5568
5569
5570int inject_eth_frame(int s, const void *data, size_t len,
5571 unsigned short ethtype, char *dst, char *src)
5572{
5573 struct iovec iov[4] = {
5574 {
5575 .iov_base = dst,
5576 .iov_len = ETH_ALEN,
5577 },
5578 {
5579 .iov_base = src,
5580 .iov_len = ETH_ALEN,
5581 },
5582 {
5583 .iov_base = &ethtype,
5584 .iov_len = sizeof(unsigned short),
5585 },
5586 {
5587 .iov_base = (void *) data,
5588 .iov_len = len,
5589 }
5590 };
5591 struct msghdr msg = {
5592 .msg_name = NULL,
5593 .msg_namelen = 0,
5594 .msg_iov = iov,
5595 .msg_iovlen = 4,
5596 .msg_control = NULL,
5597 .msg_controllen = 0,
5598 .msg_flags = 0,
5599 };
5600
5601 return sendmsg(s, &msg, 0);
5602}
5603
5604#if defined(__linux__) || defined(__QNXNTO__)
5605
5606int inject_frame(int s, const void *data, size_t len, int encrypt)
5607{
5608#define IEEE80211_RADIOTAP_F_WEP 0x04
5609#define IEEE80211_RADIOTAP_F_FRAG 0x08
5610 unsigned char rtap_hdr[] = {
5611 0x00, 0x00, /* radiotap version */
5612 0x0e, 0x00, /* radiotap length */
5613 0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
5614 IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
5615 0x00, /* padding */
5616 0x00, 0x00, /* RX and TX flags to indicate that */
5617 0x00, 0x00, /* this is the injected frame directly */
5618 };
5619 struct iovec iov[2] = {
5620 {
5621 .iov_base = &rtap_hdr,
5622 .iov_len = sizeof(rtap_hdr),
5623 },
5624 {
5625 .iov_base = (void *) data,
5626 .iov_len = len,
5627 }
5628 };
5629 struct msghdr msg = {
5630 .msg_name = NULL,
5631 .msg_namelen = 0,
5632 .msg_iov = iov,
5633 .msg_iovlen = 2,
5634 .msg_control = NULL,
5635 .msg_controllen = 0,
5636 .msg_flags = 0,
5637 };
5638
5639 if (encrypt)
5640 rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
5641
5642 return sendmsg(s, &msg, 0);
5643}
5644
5645
5646int open_monitor(const char *ifname)
5647{
5648#ifdef __QNXNTO__
5649 struct sockaddr_dl ll;
5650 int s;
5651
5652 memset(&ll, 0, sizeof(ll));
5653 ll.sdl_family = AF_LINK;
5654 ll.sdl_index = if_nametoindex(ifname);
5655 if (ll.sdl_index == 0) {
5656 perror("if_nametoindex");
5657 return -1;
5658 }
5659 s = socket(PF_INET, SOCK_RAW, 0);
5660#else /* __QNXNTO__ */
5661 struct sockaddr_ll ll;
5662 int s;
5663
5664 memset(&ll, 0, sizeof(ll));
5665 ll.sll_family = AF_PACKET;
5666 ll.sll_ifindex = if_nametoindex(ifname);
5667 if (ll.sll_ifindex == 0) {
5668 perror("if_nametoindex");
5669 return -1;
5670 }
5671 s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
5672#endif /* __QNXNTO__ */
5673 if (s < 0) {
5674 perror("socket[PF_PACKET,SOCK_RAW]");
5675 return -1;
5676 }
5677
5678 if (bind(s, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
5679 perror("monitor socket bind");
5680 close(s);
5681 return -1;
5682 }
5683
5684 return s;
5685}
5686
5687
5688static int hex2num(char c)
5689{
5690 if (c >= '0' && c <= '9')
5691 return c - '0';
5692 if (c >= 'a' && c <= 'f')
5693 return c - 'a' + 10;
5694 if (c >= 'A' && c <= 'F')
5695 return c - 'A' + 10;
5696 return -1;
5697}
5698
5699
5700int hwaddr_aton(const char *txt, unsigned char *addr)
5701{
5702 int i;
5703
5704 for (i = 0; i < 6; i++) {
5705 int a, b;
5706
5707 a = hex2num(*txt++);
5708 if (a < 0)
5709 return -1;
5710 b = hex2num(*txt++);
5711 if (b < 0)
5712 return -1;
5713 *addr++ = (a << 4) | b;
5714 if (i < 5 && *txt++ != ':')
5715 return -1;
5716 }
5717
5718 return 0;
5719}
5720
5721#endif /* defined(__linux__) || defined(__QNXNTO__) */
5722
5723enum send_frame_type {
5724 DISASSOC, DEAUTH, SAQUERY, AUTH, ASSOCREQ, REASSOCREQ, DLS_REQ
5725};
5726enum send_frame_protection {
5727 CORRECT_KEY, INCORRECT_KEY, UNPROTECTED
5728};
5729
5730
5731static int sta_inject_frame(struct sigma_dut *dut, struct sigma_conn *conn,
5732 enum send_frame_type frame,
5733 enum send_frame_protection protected,
5734 const char *dest)
5735{
5736#ifdef __linux__
5737 unsigned char buf[1000], *pos;
5738 int s, res;
5739 char bssid[20], addr[20];
5740 char result[32], ssid[100];
5741 size_t ssid_len;
5742
5743 if (get_wpa_status(get_station_ifname(), "wpa_state", result,
5744 sizeof(result)) < 0 ||
5745 strncmp(result, "COMPLETED", 9) != 0) {
5746 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Not connected");
5747 return 0;
5748 }
5749
5750 if (get_wpa_status(get_station_ifname(), "bssid", bssid, sizeof(bssid))
5751 < 0) {
5752 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
5753 "current BSSID");
5754 return 0;
5755 }
5756
5757 if (get_wpa_status(get_station_ifname(), "address", addr, sizeof(addr))
5758 < 0) {
5759 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
5760 "own MAC address");
5761 return 0;
5762 }
5763
5764 if (get_wpa_status(get_station_ifname(), "ssid", ssid, sizeof(ssid))
5765 < 0) {
5766 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not get "
5767 "current SSID");
5768 return 0;
5769 }
5770 ssid_len = strlen(ssid);
5771
5772 pos = buf;
5773
5774 /* Frame Control */
5775 switch (frame) {
5776 case DISASSOC:
5777 *pos++ = 0xa0;
5778 break;
5779 case DEAUTH:
5780 *pos++ = 0xc0;
5781 break;
5782 case SAQUERY:
5783 *pos++ = 0xd0;
5784 break;
5785 case AUTH:
5786 *pos++ = 0xb0;
5787 break;
5788 case ASSOCREQ:
5789 *pos++ = 0x00;
5790 break;
5791 case REASSOCREQ:
5792 *pos++ = 0x20;
5793 break;
5794 case DLS_REQ:
5795 *pos++ = 0xd0;
5796 break;
5797 }
5798
5799 if (protected == INCORRECT_KEY)
5800 *pos++ = 0x40; /* Set Protected field to 1 */
5801 else
5802 *pos++ = 0x00;
5803
5804 /* Duration */
5805 *pos++ = 0x00;
5806 *pos++ = 0x00;
5807
5808 /* addr1 = DA (current AP) */
5809 hwaddr_aton(bssid, pos);
5810 pos += 6;
5811 /* addr2 = SA (own address) */
5812 hwaddr_aton(addr, pos);
5813 pos += 6;
5814 /* addr3 = BSSID (current AP) */
5815 hwaddr_aton(bssid, pos);
5816 pos += 6;
5817
5818 /* Seq# (to be filled by driver/mac80211) */
5819 *pos++ = 0x00;
5820 *pos++ = 0x00;
5821
5822 if (protected == INCORRECT_KEY) {
5823 /* CCMP parameters */
5824 memcpy(pos, "\x61\x01\x00\x20\x00\x10\x00\x00", 8);
5825 pos += 8;
5826 }
5827
5828 if (protected == INCORRECT_KEY) {
5829 switch (frame) {
5830 case DEAUTH:
5831 /* Reason code (encrypted) */
5832 memcpy(pos, "\xa7\x39", 2);
5833 pos += 2;
5834 break;
5835 case DISASSOC:
5836 /* Reason code (encrypted) */
5837 memcpy(pos, "\xa7\x39", 2);
5838 pos += 2;
5839 break;
5840 case SAQUERY:
5841 /* Category|Action|TransID (encrypted) */
5842 memcpy(pos, "\x6f\xbd\xe9\x4d", 4);
5843 pos += 4;
5844 break;
5845 default:
5846 return -1;
5847 }
5848
5849 /* CCMP MIC */
5850 memcpy(pos, "\xc8\xd8\x3b\x06\x5d\xb7\x25\x68", 8);
5851 pos += 8;
5852 } else {
5853 switch (frame) {
5854 case DEAUTH:
5855 /* reason code = 8 */
5856 *pos++ = 0x08;
5857 *pos++ = 0x00;
5858 break;
5859 case DISASSOC:
5860 /* reason code = 8 */
5861 *pos++ = 0x08;
5862 *pos++ = 0x00;
5863 break;
5864 case SAQUERY:
5865 /* Category - SA Query */
5866 *pos++ = 0x08;
5867 /* SA query Action - Request */
5868 *pos++ = 0x00;
5869 /* Transaction ID */
5870 *pos++ = 0x12;
5871 *pos++ = 0x34;
5872 break;
5873 case AUTH:
5874 /* Auth Alg (Open) */
5875 *pos++ = 0x00;
5876 *pos++ = 0x00;
5877 /* Seq# */
5878 *pos++ = 0x01;
5879 *pos++ = 0x00;
5880 /* Status code */
5881 *pos++ = 0x00;
5882 *pos++ = 0x00;
5883 break;
5884 case ASSOCREQ:
5885 /* Capability Information */
5886 *pos++ = 0x31;
5887 *pos++ = 0x04;
5888 /* Listen Interval */
5889 *pos++ = 0x0a;
5890 *pos++ = 0x00;
5891 /* SSID */
5892 *pos++ = 0x00;
5893 *pos++ = ssid_len;
5894 memcpy(pos, ssid, ssid_len);
5895 pos += ssid_len;
5896 /* Supported Rates */
5897 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
5898 10);
5899 pos += 10;
5900 /* Extended Supported Rates */
5901 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
5902 pos += 6;
5903 /* RSN */
5904 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
5905 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
5906 "\x00\x00\x00\x00\x0f\xac\x06", 28);
5907 pos += 28;
5908 break;
5909 case REASSOCREQ:
5910 /* Capability Information */
5911 *pos++ = 0x31;
5912 *pos++ = 0x04;
5913 /* Listen Interval */
5914 *pos++ = 0x0a;
5915 *pos++ = 0x00;
5916 /* Current AP */
5917 hwaddr_aton(bssid, pos);
5918 pos += 6;
5919 /* SSID */
5920 *pos++ = 0x00;
5921 *pos++ = ssid_len;
5922 memcpy(pos, ssid, ssid_len);
5923 pos += ssid_len;
5924 /* Supported Rates */
5925 memcpy(pos, "\x01\x08\x02\x04\x0b\x16\x0c\x12\x18\x24",
5926 10);
5927 pos += 10;
5928 /* Extended Supported Rates */
5929 memcpy(pos, "\x32\x04\x30\x48\x60\x6c", 6);
5930 pos += 6;
5931 /* RSN */
5932 memcpy(pos, "\x30\x1a\x01\x00\x00\x0f\xac\x04\x01\x00"
5933 "\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\xc0"
5934 "\x00\x00\x00\x00\x0f\xac\x06", 28);
5935 pos += 28;
5936 break;
5937 case DLS_REQ:
5938 /* Category - DLS */
5939 *pos++ = 0x02;
5940 /* DLS Action - Request */
5941 *pos++ = 0x00;
5942 /* Destination MACAddress */
5943 if (dest)
5944 hwaddr_aton(dest, pos);
5945 else
5946 memset(pos, 0, 6);
5947 pos += 6;
5948 /* Source MACAddress */
5949 hwaddr_aton(addr, pos);
5950 pos += 6;
5951 /* Capability Information */
5952 *pos++ = 0x10; /* Privacy */
5953 *pos++ = 0x06; /* QoS */
5954 /* DLS Timeout Value */
5955 *pos++ = 0x00;
5956 *pos++ = 0x01;
5957 /* Supported rates */
5958 *pos++ = 0x01;
5959 *pos++ = 0x08;
5960 *pos++ = 0x0c; /* 6 Mbps */
5961 *pos++ = 0x12; /* 9 Mbps */
5962 *pos++ = 0x18; /* 12 Mbps */
5963 *pos++ = 0x24; /* 18 Mbps */
5964 *pos++ = 0x30; /* 24 Mbps */
5965 *pos++ = 0x48; /* 36 Mbps */
5966 *pos++ = 0x60; /* 48 Mbps */
5967 *pos++ = 0x6c; /* 54 Mbps */
5968 /* TODO: Extended Supported Rates */
5969 /* TODO: HT Capabilities */
5970 break;
5971 }
5972 }
5973
5974 s = open_monitor("sigmadut");
5975 if (s < 0) {
5976 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
5977 "monitor socket");
5978 return 0;
5979 }
5980
5981 res = inject_frame(s, buf, pos - buf, protected == CORRECT_KEY);
5982 if (res < 0) {
5983 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
5984 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305985 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005986 return 0;
5987 }
5988 if (res < pos - buf) {
5989 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Only partial "
5990 "frame sent");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05305991 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02005992 return 0;
5993 }
5994
5995 close(s);
5996
5997 return 1;
5998#else /* __linux__ */
5999 send_resp(dut, conn, SIGMA_ERROR, "errorCode,sta_send_frame not "
6000 "yet supported");
6001 return 0;
6002#endif /* __linux__ */
6003}
6004
6005
6006static int cmd_sta_send_frame_tdls(struct sigma_dut *dut,
6007 struct sigma_conn *conn,
6008 struct sigma_cmd *cmd)
6009{
6010 const char *intf = get_param(cmd, "Interface");
6011 const char *sta, *val;
6012 unsigned char addr[ETH_ALEN];
6013 char buf[100];
6014
6015 sta = get_param(cmd, "peer");
6016 if (sta == NULL)
6017 sta = get_param(cmd, "station");
6018 if (sta == NULL) {
6019 send_resp(dut, conn, SIGMA_ERROR,
6020 "ErrorCode,Missing peer address");
6021 return 0;
6022 }
6023 if (hwaddr_aton(sta, addr) < 0) {
6024 send_resp(dut, conn, SIGMA_ERROR,
6025 "ErrorCode,Invalid peer address");
6026 return 0;
6027 }
6028
6029 val = get_param(cmd, "type");
6030 if (val == NULL)
6031 return -1;
6032
6033 if (strcasecmp(val, "DISCOVERY") == 0) {
6034 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", sta);
6035 if (wpa_command(intf, buf) < 0) {
6036 send_resp(dut, conn, SIGMA_ERROR,
6037 "ErrorCode,Failed to send TDLS discovery");
6038 return 0;
6039 }
6040 return 1;
6041 }
6042
6043 if (strcasecmp(val, "SETUP") == 0) {
6044 int status = 0, timeout = 0;
6045
6046 val = get_param(cmd, "Status");
6047 if (val)
6048 status = atoi(val);
6049
6050 val = get_param(cmd, "Timeout");
6051 if (val)
6052 timeout = atoi(val);
6053
6054 if (status != 0 && status != 37) {
6055 send_resp(dut, conn, SIGMA_ERROR,
6056 "ErrorCode,Unsupported status value");
6057 return 0;
6058 }
6059
6060 if (timeout != 0 && timeout != 301) {
6061 send_resp(dut, conn, SIGMA_ERROR,
6062 "ErrorCode,Unsupported timeout value");
6063 return 0;
6064 }
6065
6066 if (status && timeout) {
6067 send_resp(dut, conn, SIGMA_ERROR,
6068 "ErrorCode,Unsupported timeout+status "
6069 "combination");
6070 return 0;
6071 }
6072
6073 if (status == 37 &&
6074 wpa_command(intf, "SET tdls_testing 0x200")) {
6075 send_resp(dut, conn, SIGMA_ERROR,
6076 "ErrorCode,Failed to enable "
6077 "decline setup response test mode");
6078 return 0;
6079 }
6080
6081 if (timeout == 301) {
6082 int res;
6083 if (dut->no_tpk_expiration)
6084 res = wpa_command(intf,
6085 "SET tdls_testing 0x108");
6086 else
6087 res = wpa_command(intf,
6088 "SET tdls_testing 0x8");
6089 if (res) {
6090 send_resp(dut, conn, SIGMA_ERROR,
6091 "ErrorCode,Failed to set short TPK "
6092 "lifetime");
6093 return 0;
6094 }
6095 }
6096
6097 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", sta);
6098 if (wpa_command(intf, buf) < 0) {
6099 send_resp(dut, conn, SIGMA_ERROR,
6100 "ErrorCode,Failed to send TDLS setup");
6101 return 0;
6102 }
6103 return 1;
6104 }
6105
6106 if (strcasecmp(val, "TEARDOWN") == 0) {
6107 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", sta);
6108 if (wpa_command(intf, buf) < 0) {
6109 send_resp(dut, conn, SIGMA_ERROR,
6110 "ErrorCode,Failed to send TDLS teardown");
6111 return 0;
6112 }
6113 return 1;
6114 }
6115
6116 send_resp(dut, conn, SIGMA_ERROR,
6117 "ErrorCode,Unsupported TDLS frame");
6118 return 0;
6119}
6120
6121
6122static int sta_ap_known(const char *ifname, const char *bssid)
6123{
6124 char buf[4096];
6125
6126 snprintf(buf, sizeof(buf), "BSS %s", bssid);
6127 if (wpa_command_resp(ifname, buf, buf, sizeof(buf)) < 0)
6128 return 0;
6129 if (strncmp(buf, "id=", 3) != 0)
6130 return 0;
6131 return 1;
6132}
6133
6134
6135static int sta_scan_ap(struct sigma_dut *dut, const char *ifname,
6136 const char *bssid)
6137{
6138 int res;
6139 struct wpa_ctrl *ctrl;
6140 char buf[256];
6141
6142 if (sta_ap_known(ifname, bssid))
6143 return 0;
6144 sigma_dut_print(dut, DUT_MSG_DEBUG,
6145 "AP not in BSS table - start scan");
6146
6147 ctrl = open_wpa_mon(ifname);
6148 if (ctrl == NULL) {
6149 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
6150 "wpa_supplicant monitor connection");
6151 return -1;
6152 }
6153
6154 if (wpa_command(ifname, "SCAN") < 0) {
6155 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to start scan");
6156 wpa_ctrl_detach(ctrl);
6157 wpa_ctrl_close(ctrl);
6158 return -1;
6159 }
6160
6161 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-SCAN-RESULTS",
6162 buf, sizeof(buf));
6163
6164 wpa_ctrl_detach(ctrl);
6165 wpa_ctrl_close(ctrl);
6166
6167 if (res < 0) {
6168 sigma_dut_print(dut, DUT_MSG_INFO, "Scan did not complete");
6169 return -1;
6170 }
6171
6172 if (sta_ap_known(ifname, bssid))
6173 return 0;
6174 sigma_dut_print(dut, DUT_MSG_INFO, "AP not in BSS table");
6175 return -1;
6176}
6177
6178
6179static int cmd_sta_send_frame_hs2_neighadv(struct sigma_dut *dut,
6180 struct sigma_conn *conn,
6181 struct sigma_cmd *cmd,
6182 const char *intf)
6183{
6184 char buf[200];
6185
6186 snprintf(buf, sizeof(buf), "ndsend 2001:DB8::1 %s", intf);
6187 if (system(buf) != 0) {
6188 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Failed to run "
6189 "ndsend");
6190 return 0;
6191 }
6192
6193 return 1;
6194}
6195
6196
6197static int cmd_sta_send_frame_hs2_neighsolreq(struct sigma_dut *dut,
6198 struct sigma_conn *conn,
6199 struct sigma_cmd *cmd,
6200 const char *intf)
6201{
6202 char buf[200];
6203 const char *ip = get_param(cmd, "SenderIP");
6204
6205 snprintf(buf, sizeof(buf), "ndisc6 -nm %s %s -r 4", ip, intf);
6206 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6207 if (system(buf) == 0) {
6208 sigma_dut_print(dut, DUT_MSG_INFO,
6209 "Neighbor Solicitation got a response "
6210 "for %s@%s", ip, intf);
6211 }
6212
6213 return 1;
6214}
6215
6216
6217static int cmd_sta_send_frame_hs2_arpprobe(struct sigma_dut *dut,
6218 struct sigma_conn *conn,
6219 struct sigma_cmd *cmd,
6220 const char *ifname)
6221{
6222 char buf[200];
6223 const char *ip = get_param(cmd, "SenderIP");
6224
6225 if (ip == NULL) {
6226 send_resp(dut, conn, SIGMA_ERROR,
6227 "ErrorCode,Missing SenderIP parameter");
6228 return 0;
6229 }
6230 snprintf(buf, sizeof(buf), "arping -I %s -D %s -c 4", ifname, ip);
6231 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6232 if (system(buf) != 0) {
6233 sigma_dut_print(dut, DUT_MSG_INFO, "arping DAD got a response "
6234 "for %s@%s", ip, ifname);
6235 }
6236
6237 return 1;
6238}
6239
6240
6241static int cmd_sta_send_frame_hs2_arpannounce(struct sigma_dut *dut,
6242 struct sigma_conn *conn,
6243 struct sigma_cmd *cmd,
6244 const char *ifname)
6245{
6246 char buf[200];
6247 char ip[16];
6248 int s;
6249
6250 s = socket(PF_INET, SOCK_DGRAM, 0);
6251 if (s >= 0) {
6252 struct ifreq ifr;
6253 struct sockaddr_in saddr;
6254
6255 memset(&ifr, 0, sizeof(ifr));
Peng Xub8fc5cc2017-05-10 17:27:28 -07006256 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006257 if (ioctl(s, SIOCGIFADDR, &ifr) < 0) {
6258 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get "
6259 "%s IP address: %s",
6260 ifname, strerror(errno));
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306261 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006262 return -1;
6263 } else {
6264 memcpy(&saddr, &ifr.ifr_addr,
6265 sizeof(struct sockaddr_in));
Peng Xub8fc5cc2017-05-10 17:27:28 -07006266 strlcpy(ip, inet_ntoa(saddr.sin_addr), sizeof(ip));
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006267 }
6268 close(s);
6269
6270 }
6271
6272 snprintf(buf, sizeof(buf), "arping -I %s -s %s %s -c 4", ifname, ip,
6273 ip);
6274 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
6275 if (system(buf) != 0) {
6276 }
6277
6278 return 1;
6279}
6280
6281
6282static int cmd_sta_send_frame_hs2_arpreply(struct sigma_dut *dut,
6283 struct sigma_conn *conn,
6284 struct sigma_cmd *cmd,
6285 const char *ifname)
6286{
6287 char buf[200], addr[20];
6288 char dst[ETH_ALEN], src[ETH_ALEN];
6289 short ethtype = htons(ETH_P_ARP);
6290 char *pos;
6291 int s, res;
6292 const char *val;
6293 struct sockaddr_in taddr;
6294
6295 val = get_param(cmd, "dest");
6296 if (val)
6297 hwaddr_aton(val, (unsigned char *) dst);
6298
6299 val = get_param(cmd, "DestIP");
6300 if (val)
6301 inet_aton(val, &taddr.sin_addr);
6302
6303 if (get_wpa_status(get_station_ifname(), "address", addr,
6304 sizeof(addr)) < 0)
6305 return -2;
6306 hwaddr_aton(addr, (unsigned char *) src);
6307
6308 pos = buf;
6309 *pos++ = 0x00;
6310 *pos++ = 0x01;
6311 *pos++ = 0x08;
6312 *pos++ = 0x00;
6313 *pos++ = 0x06;
6314 *pos++ = 0x04;
6315 *pos++ = 0x00;
6316 *pos++ = 0x02;
6317 memcpy(pos, src, ETH_ALEN);
6318 pos += ETH_ALEN;
6319 memcpy(pos, &taddr.sin_addr, 4);
6320 pos += 4;
6321 memcpy(pos, dst, ETH_ALEN);
6322 pos += ETH_ALEN;
6323 memcpy(pos, &taddr.sin_addr, 4);
6324 pos += 4;
6325
6326 s = open_monitor(get_station_ifname());
6327 if (s < 0) {
6328 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to open "
6329 "monitor socket");
6330 return 0;
6331 }
6332
6333 res = inject_eth_frame(s, buf, pos - buf, ethtype, dst, src);
6334 if (res < 0) {
6335 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to "
6336 "inject frame");
Pradeep Reddy POTTETI673d85c2016-07-26 19:08:07 +05306337 close(s);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006338 return 0;
6339 }
6340
6341 close(s);
6342
6343 return 1;
6344}
6345
6346
6347static int cmd_sta_send_frame_hs2_dls_req(struct sigma_dut *dut,
6348 struct sigma_conn *conn,
6349 struct sigma_cmd *cmd,
6350 const char *intf, const char *dest)
6351{
6352 char buf[100];
6353
6354 if (if_nametoindex("sigmadut") == 0) {
6355 snprintf(buf, sizeof(buf),
6356 "iw dev %s interface add sigmadut type monitor",
6357 get_station_ifname());
6358 if (system(buf) != 0 ||
6359 if_nametoindex("sigmadut") == 0) {
6360 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
6361 "monitor interface with '%s'", buf);
6362 return -2;
6363 }
6364 }
6365
6366 if (system("ifconfig sigmadut up") != 0) {
6367 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
6368 "monitor interface up");
6369 return -2;
6370 }
6371
6372 return sta_inject_frame(dut, conn, DLS_REQ, UNPROTECTED, dest);
6373}
6374
6375
6376static int cmd_sta_send_frame_hs2(struct sigma_dut *dut,
6377 struct sigma_conn *conn,
6378 struct sigma_cmd *cmd)
6379{
6380 const char *intf = get_param(cmd, "Interface");
6381 const char *dest = get_param(cmd, "Dest");
6382 const char *type = get_param(cmd, "FrameName");
6383 const char *val;
6384 char buf[200], *pos, *end;
6385 int count, count2;
6386
6387 if (type == NULL)
6388 type = get_param(cmd, "Type");
6389
6390 if (intf == NULL || dest == NULL || type == NULL)
6391 return -1;
6392
6393 if (strcasecmp(type, "NeighAdv") == 0)
6394 return cmd_sta_send_frame_hs2_neighadv(dut, conn, cmd, intf);
6395
6396 if (strcasecmp(type, "NeighSolicitReq") == 0)
6397 return cmd_sta_send_frame_hs2_neighsolreq(dut, conn, cmd, intf);
6398
6399 if (strcasecmp(type, "ARPProbe") == 0)
6400 return cmd_sta_send_frame_hs2_arpprobe(dut, conn, cmd, intf);
6401
6402 if (strcasecmp(type, "ARPAnnounce") == 0)
6403 return cmd_sta_send_frame_hs2_arpannounce(dut, conn, cmd, intf);
6404
6405 if (strcasecmp(type, "ARPReply") == 0)
6406 return cmd_sta_send_frame_hs2_arpreply(dut, conn, cmd, intf);
6407
6408 if (strcasecmp(type, "DLS-request") == 0 ||
6409 strcasecmp(type, "DLSrequest") == 0)
6410 return cmd_sta_send_frame_hs2_dls_req(dut, conn, cmd, intf,
6411 dest);
6412
6413 if (strcasecmp(type, "ANQPQuery") != 0 &&
6414 strcasecmp(type, "Query") != 0) {
6415 send_resp(dut, conn, SIGMA_ERROR,
6416 "ErrorCode,Unsupported HS 2.0 send frame type");
6417 return 0;
6418 }
6419
6420 if (sta_scan_ap(dut, intf, dest) < 0) {
6421 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not find "
6422 "the requested AP");
6423 return 0;
6424 }
6425
6426 pos = buf;
6427 end = buf + sizeof(buf);
6428 count = 0;
6429 pos += snprintf(pos, end - pos, "ANQP_GET %s ", dest);
6430
6431 val = get_param(cmd, "ANQP_CAP_LIST");
6432 if (val && atoi(val)) {
6433 pos += snprintf(pos, end - pos, "%s257", count > 0 ? "," : "");
6434 count++;
6435 }
6436
6437 val = get_param(cmd, "VENUE_NAME");
6438 if (val && atoi(val)) {
6439 pos += snprintf(pos, end - pos, "%s258", count > 0 ? "," : "");
6440 count++;
6441 }
6442
6443 val = get_param(cmd, "NETWORK_AUTH_TYPE");
6444 if (val && atoi(val)) {
6445 pos += snprintf(pos, end - pos, "%s260", count > 0 ? "," : "");
6446 count++;
6447 }
6448
6449 val = get_param(cmd, "ROAMING_CONS");
6450 if (val && atoi(val)) {
6451 pos += snprintf(pos, end - pos, "%s261", count > 0 ? "," : "");
6452 count++;
6453 }
6454
6455 val = get_param(cmd, "IP_ADDR_TYPE_AVAILABILITY");
6456 if (val && atoi(val)) {
6457 pos += snprintf(pos, end - pos, "%s262", count > 0 ? "," : "");
6458 count++;
6459 }
6460
6461 val = get_param(cmd, "NAI_REALM_LIST");
6462 if (val && atoi(val)) {
6463 pos += snprintf(pos, end - pos, "%s263", count > 0 ? "," : "");
6464 count++;
6465 }
6466
6467 val = get_param(cmd, "3GPP_INFO");
6468 if (val && atoi(val)) {
6469 pos += snprintf(pos, end - pos, "%s264", count > 0 ? "," : "");
6470 count++;
6471 }
6472
6473 val = get_param(cmd, "DOMAIN_LIST");
6474 if (val && atoi(val)) {
6475 pos += snprintf(pos, end - pos, "%s268", count > 0 ? "," : "");
6476 count++;
6477 }
6478
6479 if (count && wpa_command(intf, buf)) {
6480 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,ANQP_GET failed");
6481 return 0;
6482 }
6483
6484 pos = buf;
6485 end = buf + sizeof(buf);
6486 count2 = 0;
6487 pos += snprintf(pos, end - pos, "HS20_ANQP_GET %s ", dest);
6488
6489 val = get_param(cmd, "HS_CAP_LIST");
6490 if (val && atoi(val)) {
6491 pos += snprintf(pos, end - pos, "%s2", count2 > 0 ? "," : "");
6492 count2++;
6493 }
6494
6495 val = get_param(cmd, "OPER_NAME");
6496 if (val && atoi(val)) {
6497 pos += snprintf(pos, end - pos, "%s3", count2 > 0 ? "," : "");
6498 count2++;
6499 }
6500
6501 val = get_param(cmd, "WAN_METRICS");
6502 if (!val)
6503 val = get_param(cmd, "WAN_MAT");
6504 if (!val)
6505 val = get_param(cmd, "WAN_MET");
6506 if (val && atoi(val)) {
6507 pos += snprintf(pos, end - pos, "%s4", count2 > 0 ? "," : "");
6508 count2++;
6509 }
6510
6511 val = get_param(cmd, "CONNECTION_CAPABILITY");
6512 if (val && atoi(val)) {
6513 pos += snprintf(pos, end - pos, "%s5", count2 > 0 ? "," : "");
6514 count2++;
6515 }
6516
6517 val = get_param(cmd, "OP_CLASS");
6518 if (val && atoi(val)) {
6519 pos += snprintf(pos, end - pos, "%s7", count2 > 0 ? "," : "");
6520 count2++;
6521 }
6522
6523 val = get_param(cmd, "OSU_PROVIDER_LIST");
6524 if (val && atoi(val)) {
6525 pos += snprintf(pos, end - pos, "%s8", count2 > 0 ? "," : "");
6526 count2++;
6527 }
6528
6529 if (count && count2) {
6530 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before sending out "
6531 "second query");
6532 sleep(1);
6533 }
6534
6535 if (count2 && wpa_command(intf, buf)) {
6536 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,HS20_ANQP_GET "
6537 "failed");
6538 return 0;
6539 }
6540
6541 val = get_param(cmd, "NAI_HOME_REALM_LIST");
6542 if (val) {
6543 if (count || count2) {
6544 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
6545 "sending out second query");
6546 sleep(1);
6547 }
6548
6549 if (strcmp(val, "1") == 0)
6550 val = "mail.example.com";
6551 snprintf(buf, end - pos,
6552 "HS20_GET_NAI_HOME_REALM_LIST %s realm=%s",
6553 dest, val);
6554 if (wpa_command(intf, buf)) {
6555 send_resp(dut, conn, SIGMA_ERROR,
6556 "ErrorCode,HS20_GET_NAI_HOME_REALM_LIST "
6557 "failed");
6558 return 0;
6559 }
6560 }
6561
6562 val = get_param(cmd, "ICON_REQUEST");
6563 if (val) {
6564 if (count || count2) {
6565 sigma_dut_print(dut, DUT_MSG_DEBUG, "Wait before "
6566 "sending out second query");
6567 sleep(1);
6568 }
6569
6570 snprintf(buf, end - pos,
6571 "HS20_ICON_REQUEST %s %s", dest, val);
6572 if (wpa_command(intf, buf)) {
6573 send_resp(dut, conn, SIGMA_ERROR,
6574 "ErrorCode,HS20_ICON_REQUEST failed");
6575 return 0;
6576 }
6577 }
6578
6579 return 1;
6580}
6581
6582
6583static int ath_sta_send_frame_vht(struct sigma_dut *dut,
6584 struct sigma_conn *conn,
6585 struct sigma_cmd *cmd)
6586{
6587 const char *val;
6588 char *ifname;
6589 char buf[100];
6590 int chwidth, nss;
6591
6592 val = get_param(cmd, "framename");
6593 if (!val)
6594 return -1;
6595 sigma_dut_print(dut, DUT_MSG_DEBUG, "framename is %s", val);
6596
6597 /* Command sequence to generate Op mode notification */
6598 if (val && strcasecmp(val, "Op_md_notif_frm") == 0) {
6599 ifname = get_station_ifname();
6600
6601 /* Disable STBC */
6602 snprintf(buf, sizeof(buf),
6603 "iwpriv %s tx_stbc 0", ifname);
6604 if (system(buf) != 0) {
6605 sigma_dut_print(dut, DUT_MSG_ERROR,
6606 "iwpriv tx_stbc 0 failed!");
6607 }
6608
6609 /* Extract Channel width */
6610 val = get_param(cmd, "Channel_width");
6611 if (val) {
6612 switch (atoi(val)) {
6613 case 20:
6614 chwidth = 0;
6615 break;
6616 case 40:
6617 chwidth = 1;
6618 break;
6619 case 80:
6620 chwidth = 2;
6621 break;
6622 case 160:
6623 chwidth = 3;
6624 break;
6625 default:
6626 chwidth = 2;
6627 break;
6628 }
6629
6630 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
6631 ifname, chwidth);
6632 if (system(buf) != 0) {
6633 sigma_dut_print(dut, DUT_MSG_ERROR,
6634 "iwpriv chwidth failed!");
6635 }
6636 }
6637
6638 /* Extract NSS */
6639 val = get_param(cmd, "NSS");
6640 if (val) {
6641 switch (atoi(val)) {
6642 case 1:
6643 nss = 1;
6644 break;
6645 case 2:
6646 nss = 3;
6647 break;
6648 case 3:
6649 nss = 7;
6650 break;
6651 default:
6652 /* We do not support NSS > 3 */
6653 nss = 3;
6654 break;
6655 }
6656 snprintf(buf, sizeof(buf),
6657 "iwpriv %s rxchainmask %d", ifname, nss);
6658 if (system(buf) != 0) {
6659 sigma_dut_print(dut, DUT_MSG_ERROR,
6660 "iwpriv rxchainmask failed!");
6661 }
6662 }
6663
6664 /* Opmode notify */
6665 snprintf(buf, sizeof(buf), "iwpriv %s opmode_notify 1", ifname);
6666 if (system(buf) != 0) {
6667 sigma_dut_print(dut, DUT_MSG_ERROR,
6668 "iwpriv opmode_notify failed!");
6669 } else {
6670 sigma_dut_print(dut, DUT_MSG_INFO,
6671 "Sent out the notify frame!");
6672 }
6673 }
6674
6675 return 1;
6676}
6677
6678
6679static int cmd_sta_send_frame_vht(struct sigma_dut *dut,
6680 struct sigma_conn *conn,
6681 struct sigma_cmd *cmd)
6682{
6683 switch (get_driver_type()) {
6684 case DRIVER_ATHEROS:
6685 return ath_sta_send_frame_vht(dut, conn, cmd);
6686 default:
6687 send_resp(dut, conn, SIGMA_ERROR,
6688 "errorCode,Unsupported sta_set_frame(VHT) with the current driver");
6689 return 0;
6690 }
6691}
6692
6693
Lior David0fe101e2017-03-09 16:09:50 +02006694#ifdef __linux__
6695int wil6210_send_frame_60g(struct sigma_dut *dut, struct sigma_conn *conn,
6696 struct sigma_cmd *cmd)
6697{
6698 const char *frame_name = get_param(cmd, "framename");
6699 const char *mac = get_param(cmd, "dest_mac");
6700
6701 if (!frame_name || !mac) {
6702 sigma_dut_print(dut, DUT_MSG_ERROR,
6703 "framename and dest_mac must be provided");
6704 return -1;
6705 }
6706
6707 if (strcasecmp(frame_name, "brp") == 0) {
6708 const char *l_rx = get_param(cmd, "L-RX");
6709 int l_rx_i;
6710
6711 if (!l_rx) {
6712 sigma_dut_print(dut, DUT_MSG_ERROR,
6713 "L-RX must be provided");
6714 return -1;
6715 }
6716 l_rx_i = atoi(l_rx);
6717
6718 sigma_dut_print(dut, DUT_MSG_INFO,
6719 "dev_send_frame: BRP-RX, dest_mac %s, L-RX %s",
6720 mac, l_rx);
6721 if (l_rx_i != 16) {
6722 sigma_dut_print(dut, DUT_MSG_ERROR,
6723 "unsupported L-RX: %s", l_rx);
6724 return -1;
6725 }
6726
6727 if (wil6210_send_brp_rx(dut, mac, l_rx_i))
6728 return -1;
6729 } else if (strcasecmp(frame_name, "ssw") == 0) {
6730 sigma_dut_print(dut, DUT_MSG_INFO,
6731 "dev_send_frame: SLS, dest_mac %s", mac);
6732 if (wil6210_send_sls(dut, mac))
6733 return -1;
6734 } else {
6735 sigma_dut_print(dut, DUT_MSG_ERROR,
6736 "unsupported frame type: %s", frame_name);
6737 return -1;
6738 }
6739
6740 return 1;
6741}
6742#endif /* __linux__ */
6743
6744
6745static int cmd_sta_send_frame_60g(struct sigma_dut *dut,
6746 struct sigma_conn *conn,
6747 struct sigma_cmd *cmd)
6748{
6749 switch (get_driver_type()) {
6750#ifdef __linux__
6751 case DRIVER_WIL6210:
6752 return wil6210_send_frame_60g(dut, conn, cmd);
6753#endif /* __linux__ */
6754 default:
6755 send_resp(dut, conn, SIGMA_ERROR,
6756 "errorCode,Unsupported sta_set_frame(60G) with the current driver");
6757 return 0;
6758 }
6759}
6760
6761
Ashwini Patildb59b3c2017-04-13 15:19:23 +05306762static int mbo_send_anqp_query(struct sigma_dut *dut, struct sigma_conn *conn,
6763 const char *intf, struct sigma_cmd *cmd)
6764{
6765 const char *val, *addr;
6766 char buf[100];
6767
6768 addr = get_param(cmd, "DestMac");
6769 if (!addr) {
6770 send_resp(dut, conn, SIGMA_INVALID,
6771 "ErrorCode,AP MAC address is missing");
6772 return 0;
6773 }
6774
6775 val = get_param(cmd, "ANQPQuery_ID");
6776 if (!val) {
6777 send_resp(dut, conn, SIGMA_INVALID,
6778 "ErrorCode,Missing ANQPQuery_ID");
6779 return 0;
6780 }
6781
6782 if (strcasecmp(val, "NeighborReportReq") == 0) {
6783 snprintf(buf, sizeof(buf), "ANQP_GET %s 272", addr);
6784 } else if (strcasecmp(val, "QueryListWithCellPref") == 0) {
6785 snprintf(buf, sizeof(buf), "ANQP_GET %s 272,mbo:2", addr);
6786 } else {
6787 sigma_dut_print(dut, DUT_MSG_ERROR, "Invalid ANQPQuery_ID: %s",
6788 val);
6789 send_resp(dut, conn, SIGMA_INVALID,
6790 "ErrorCode,Invalid ANQPQuery_ID");
6791 return 0;
6792 }
6793
Ashwini Patild174f2c2017-04-13 16:49:46 +05306794 /* Set gas_address3 field to IEEE 802.11-2012 standard compliant form
6795 * (Address3 = Wildcard BSSID when sent to not-associated AP;
6796 * if associated, AP BSSID).
6797 */
6798 if (wpa_command(intf, "SET gas_address3 1") < 0) {
6799 send_resp(dut, conn, SIGMA_ERROR,
6800 "ErrorCode,Failed to set gas_address3");
6801 return 0;
6802 }
6803
Ashwini Patildb59b3c2017-04-13 15:19:23 +05306804 if (wpa_command(intf, buf) < 0) {
6805 send_resp(dut, conn, SIGMA_ERROR,
6806 "ErrorCode,Failed to send ANQP query");
6807 return 0;
6808 }
6809
6810 return 1;
6811}
6812
6813
6814static int mbo_cmd_sta_send_frame(struct sigma_dut *dut,
6815 struct sigma_conn *conn,
6816 const char *intf,
6817 struct sigma_cmd *cmd)
6818{
6819 const char *val = get_param(cmd, "FrameName");
6820
6821 if (val && strcasecmp(val, "ANQPQuery") == 0)
6822 return mbo_send_anqp_query(dut, conn, intf, cmd);
6823
6824 return 2;
6825}
6826
6827
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006828int cmd_sta_send_frame(struct sigma_dut *dut, struct sigma_conn *conn,
6829 struct sigma_cmd *cmd)
6830{
6831 const char *intf = get_param(cmd, "Interface");
6832 const char *val;
6833 enum send_frame_type frame;
6834 enum send_frame_protection protected;
6835 char buf[100];
6836 unsigned char addr[ETH_ALEN];
6837 int res;
6838
6839 val = get_param(cmd, "program");
6840 if (val == NULL)
6841 val = get_param(cmd, "frame");
6842 if (val && strcasecmp(val, "TDLS") == 0)
6843 return cmd_sta_send_frame_tdls(dut, conn, cmd);
6844 if (val && (strcasecmp(val, "HS2") == 0 ||
6845 strcasecmp(val, "HS2-R2") == 0))
6846 return cmd_sta_send_frame_hs2(dut, conn, cmd);
6847 if (val && strcasecmp(val, "VHT") == 0)
6848 return cmd_sta_send_frame_vht(dut, conn, cmd);
priyadharshini gowthamand66913a2016-07-29 15:11:17 -07006849 if (val && strcasecmp(val, "LOC") == 0)
6850 return loc_cmd_sta_send_frame(dut, conn, cmd);
Lior David0fe101e2017-03-09 16:09:50 +02006851 if (val && strcasecmp(val, "60GHz") == 0)
6852 return cmd_sta_send_frame_60g(dut, conn, cmd);
Ashwini Patildb59b3c2017-04-13 15:19:23 +05306853 if (val && strcasecmp(val, "MBO") == 0) {
6854 res = mbo_cmd_sta_send_frame(dut, conn, intf, cmd);
6855 if (res != 2)
6856 return res;
6857 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006858
6859 val = get_param(cmd, "TD_DISC");
6860 if (val) {
6861 if (hwaddr_aton(val, addr) < 0)
6862 return -1;
6863 snprintf(buf, sizeof(buf), "TDLS_DISCOVER %s", val);
6864 if (wpa_command(intf, buf) < 0) {
6865 send_resp(dut, conn, SIGMA_ERROR,
6866 "ErrorCode,Failed to send TDLS discovery");
6867 return 0;
6868 }
6869 return 1;
6870 }
6871
6872 val = get_param(cmd, "TD_Setup");
6873 if (val) {
6874 if (hwaddr_aton(val, addr) < 0)
6875 return -1;
6876 snprintf(buf, sizeof(buf), "TDLS_SETUP %s", val);
6877 if (wpa_command(intf, buf) < 0) {
6878 send_resp(dut, conn, SIGMA_ERROR,
6879 "ErrorCode,Failed to start TDLS setup");
6880 return 0;
6881 }
6882 return 1;
6883 }
6884
6885 val = get_param(cmd, "TD_TearDown");
6886 if (val) {
6887 if (hwaddr_aton(val, addr) < 0)
6888 return -1;
6889 snprintf(buf, sizeof(buf), "TDLS_TEARDOWN %s", val);
6890 if (wpa_command(intf, buf) < 0) {
6891 send_resp(dut, conn, SIGMA_ERROR,
6892 "ErrorCode,Failed to tear down TDLS link");
6893 return 0;
6894 }
6895 return 1;
6896 }
6897
6898 val = get_param(cmd, "TD_ChannelSwitch");
6899 if (val) {
6900 /* TODO */
6901 send_resp(dut, conn, SIGMA_ERROR,
6902 "ErrorCode,TD_ChannelSwitch not yet supported");
6903 return 0;
6904 }
6905
6906 val = get_param(cmd, "TD_NF");
6907 if (val) {
6908 /* TODO */
6909 send_resp(dut, conn, SIGMA_ERROR,
6910 "ErrorCode,TD_NF not yet supported");
6911 return 0;
6912 }
6913
6914 val = get_param(cmd, "PMFFrameType");
6915 if (val == NULL)
6916 val = get_param(cmd, "FrameName");
6917 if (val == NULL)
6918 val = get_param(cmd, "Type");
6919 if (val == NULL)
6920 return -1;
6921 if (strcasecmp(val, "disassoc") == 0)
6922 frame = DISASSOC;
6923 else if (strcasecmp(val, "deauth") == 0)
6924 frame = DEAUTH;
6925 else if (strcasecmp(val, "saquery") == 0)
6926 frame = SAQUERY;
6927 else if (strcasecmp(val, "auth") == 0)
6928 frame = AUTH;
6929 else if (strcasecmp(val, "assocreq") == 0)
6930 frame = ASSOCREQ;
6931 else if (strcasecmp(val, "reassocreq") == 0)
6932 frame = REASSOCREQ;
6933 else if (strcasecmp(val, "neigreq") == 0) {
6934 sigma_dut_print(dut, DUT_MSG_INFO, "Got neighbor request");
6935
6936 val = get_param(cmd, "ssid");
6937 if (val == NULL)
6938 return -1;
6939
6940 res = send_neighbor_request(dut, intf, val);
6941 if (res) {
6942 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
6943 "Failed to send neighbor report request");
6944 return 0;
6945 }
6946
6947 return 1;
Ashwini Patil5acd7382017-04-13 15:55:04 +05306948 } else if (strcasecmp(val, "transmgmtquery") == 0 ||
6949 strcasecmp(val, "BTMQuery") == 0) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006950 sigma_dut_print(dut, DUT_MSG_DEBUG,
6951 "Got Transition Management Query");
6952
Ashwini Patil5acd7382017-04-13 15:55:04 +05306953 res = send_trans_mgmt_query(dut, intf, cmd);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02006954 if (res) {
6955 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
6956 "Failed to send Transition Management Query");
6957 return 0;
6958 }
6959
6960 return 1;
6961 } else {
6962 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
6963 "PMFFrameType");
6964 return 0;
6965 }
6966
6967 val = get_param(cmd, "PMFProtected");
6968 if (val == NULL)
6969 val = get_param(cmd, "Protected");
6970 if (val == NULL)
6971 return -1;
6972 if (strcasecmp(val, "Correct-key") == 0 ||
6973 strcasecmp(val, "CorrectKey") == 0)
6974 protected = CORRECT_KEY;
6975 else if (strcasecmp(val, "IncorrectKey") == 0)
6976 protected = INCORRECT_KEY;
6977 else if (strcasecmp(val, "Unprotected") == 0)
6978 protected = UNPROTECTED;
6979 else {
6980 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
6981 "PMFProtected");
6982 return 0;
6983 }
6984
6985 if (protected != UNPROTECTED &&
6986 (frame == AUTH || frame == ASSOCREQ || frame == REASSOCREQ)) {
6987 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Impossible "
6988 "PMFProtected for auth/assocreq/reassocreq");
6989 return 0;
6990 }
6991
6992 if (if_nametoindex("sigmadut") == 0) {
6993 snprintf(buf, sizeof(buf),
6994 "iw dev %s interface add sigmadut type monitor",
6995 get_station_ifname());
6996 if (system(buf) != 0 ||
6997 if_nametoindex("sigmadut") == 0) {
6998 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to add "
6999 "monitor interface with '%s'", buf);
7000 return -2;
7001 }
7002 }
7003
7004 if (system("ifconfig sigmadut up") != 0) {
7005 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to set "
7006 "monitor interface up");
7007 return -2;
7008 }
7009
7010 return sta_inject_frame(dut, conn, frame, protected, NULL);
7011}
7012
7013
7014static int cmd_sta_set_parameter_hs2(struct sigma_dut *dut,
7015 struct sigma_conn *conn,
7016 struct sigma_cmd *cmd,
7017 const char *ifname)
7018{
7019 char buf[200];
7020 const char *val;
7021
7022 val = get_param(cmd, "ClearARP");
7023 if (val && atoi(val) == 1) {
7024 snprintf(buf, sizeof(buf), "ip neigh flush dev %s", ifname);
7025 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7026 if (system(buf) != 0) {
7027 send_resp(dut, conn, SIGMA_ERROR,
7028 "errorCode,Failed to clear ARP cache");
7029 return 0;
7030 }
7031 }
7032
7033 return 1;
7034}
7035
7036
7037int cmd_sta_set_parameter(struct sigma_dut *dut, struct sigma_conn *conn,
7038 struct sigma_cmd *cmd)
7039{
7040 const char *intf = get_param(cmd, "Interface");
7041 const char *val;
7042
7043 if (intf == NULL)
7044 return -1;
7045
7046 val = get_param(cmd, "program");
7047 if (val && (strcasecmp(val, "HS2") == 0 ||
7048 strcasecmp(val, "HS2-R2") == 0))
7049 return cmd_sta_set_parameter_hs2(dut, conn, cmd, intf);
7050
7051 return -1;
7052}
7053
7054
7055static int cmd_sta_set_macaddr(struct sigma_dut *dut, struct sigma_conn *conn,
7056 struct sigma_cmd *cmd)
7057{
7058 const char *intf = get_param(cmd, "Interface");
7059 const char *mac = get_param(cmd, "MAC");
7060
7061 if (intf == NULL || mac == NULL)
7062 return -1;
7063
7064 sigma_dut_print(dut, DUT_MSG_INFO, "Change local MAC address for "
7065 "interface %s to %s", intf, mac);
7066
7067 if (dut->set_macaddr) {
7068 char buf[128];
7069 int res;
7070 if (strcasecmp(mac, "default") == 0) {
7071 res = snprintf(buf, sizeof(buf), "%s",
7072 dut->set_macaddr);
7073 dut->tmp_mac_addr = 0;
7074 } else {
7075 res = snprintf(buf, sizeof(buf), "%s %s",
7076 dut->set_macaddr, mac);
7077 dut->tmp_mac_addr = 1;
7078 }
7079 if (res < 0 || res >= (int) sizeof(buf))
7080 return -1;
7081 if (system(buf) != 0) {
7082 send_resp(dut, conn, SIGMA_ERROR,
7083 "errorCode,Failed to set MAC "
7084 "address");
7085 return 0;
7086 }
7087 return 1;
7088 }
7089
7090 if (strcasecmp(mac, "default") == 0)
7091 return 1;
7092
7093 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7094 "command");
7095 return 0;
7096}
7097
7098
7099static int iwpriv_tdlsoffchnmode(struct sigma_dut *dut,
7100 struct sigma_conn *conn, const char *intf,
7101 int val)
7102{
7103 char buf[200];
7104 int res;
7105
7106 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchnmode %d",
7107 intf, val);
7108 if (res < 0 || res >= (int) sizeof(buf))
7109 return -1;
7110 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7111 if (system(buf) != 0) {
7112 send_resp(dut, conn, SIGMA_ERROR,
7113 "errorCode,Failed to configure offchannel mode");
7114 return 0;
7115 }
7116
7117 return 1;
7118}
7119
7120
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007121static int off_chan_val(enum sec_ch_offset off)
7122{
7123 switch (off) {
7124 case SEC_CH_NO:
7125 return 0;
7126 case SEC_CH_40ABOVE:
7127 return 40;
7128 case SEC_CH_40BELOW:
7129 return -40;
7130 }
7131
7132 return 0;
7133}
7134
7135
7136static int iwpriv_set_offchan(struct sigma_dut *dut, struct sigma_conn *conn,
7137 const char *intf, int off_ch_num,
7138 enum sec_ch_offset sec)
7139{
7140 char buf[200];
7141 int res;
7142
7143 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsoffchan %d",
7144 intf, off_ch_num);
7145 if (res < 0 || res >= (int) sizeof(buf))
7146 return -1;
7147 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7148 if (system(buf) != 0) {
7149 send_resp(dut, conn, SIGMA_ERROR,
7150 "errorCode,Failed to set offchan");
7151 return 0;
7152 }
7153
7154 res = snprintf(buf, sizeof(buf), "iwpriv %s tdlsecchnoffst %d",
7155 intf, off_chan_val(sec));
7156 if (res < 0 || res >= (int) sizeof(buf))
7157 return -1;
7158 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7159 if (system(buf) != 0) {
7160 send_resp(dut, conn, SIGMA_ERROR,
7161 "errorCode,Failed to set sec chan offset");
7162 return 0;
7163 }
7164
7165 return 1;
7166}
7167
7168
7169static int tdls_set_offchannel_offset(struct sigma_dut *dut,
7170 struct sigma_conn *conn,
7171 const char *intf, int off_ch_num,
7172 enum sec_ch_offset sec)
7173{
7174 char buf[200];
7175 int res;
7176
7177 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNEL %d",
7178 off_ch_num);
7179 if (res < 0 || res >= (int) sizeof(buf))
7180 return -1;
7181 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7182
7183 if (wpa_command(intf, buf) < 0) {
7184 send_resp(dut, conn, SIGMA_ERROR,
7185 "ErrorCode,Failed to set offchan");
7186 return 0;
7187 }
7188 res = snprintf(buf, sizeof(buf), "DRIVER TDLSSECONDARYCHANNELOFFSET %d",
7189 off_chan_val(sec));
7190 if (res < 0 || res >= (int) sizeof(buf))
7191 return -1;
7192
7193 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7194
7195 if (wpa_command(intf, buf) < 0) {
7196 send_resp(dut, conn, SIGMA_ERROR,
7197 "ErrorCode,Failed to set sec chan offset");
7198 return 0;
7199 }
7200
7201 return 1;
7202}
7203
7204
7205static int tdls_set_offchannel_mode(struct sigma_dut *dut,
7206 struct sigma_conn *conn,
7207 const char *intf, int val)
7208{
7209 char buf[200];
7210 int res;
7211
7212 res = snprintf(buf, sizeof(buf), "DRIVER TDLSOFFCHANNELMODE %d",
7213 val);
7214 if (res < 0 || res >= (int) sizeof(buf))
7215 return -1;
7216 sigma_dut_print(dut, DUT_MSG_DEBUG, "Run: %s", buf);
7217
7218 if (wpa_command(intf, buf) < 0) {
7219 send_resp(dut, conn, SIGMA_ERROR,
7220 "ErrorCode,Failed to configure offchannel mode");
7221 return 0;
7222 }
7223
7224 return 1;
7225}
7226
7227
7228static int cmd_sta_set_rfeature_tdls(const char *intf, struct sigma_dut *dut,
7229 struct sigma_conn *conn,
7230 struct sigma_cmd *cmd)
7231{
7232 const char *val;
7233 enum {
7234 CHSM_NOT_SET,
7235 CHSM_ENABLE,
7236 CHSM_DISABLE,
7237 CHSM_REJREQ,
7238 CHSM_UNSOLRESP
7239 } chsm = CHSM_NOT_SET;
7240 int off_ch_num = -1;
7241 enum sec_ch_offset sec_ch = SEC_CH_NO;
7242 int res;
7243
7244 val = get_param(cmd, "Uapsd");
7245 if (val) {
7246 char buf[100];
7247 if (strcasecmp(val, "Enable") == 0)
7248 snprintf(buf, sizeof(buf), "SET ps 99");
7249 else if (strcasecmp(val, "Disable") == 0)
7250 snprintf(buf, sizeof(buf), "SET ps 98");
7251 else {
7252 send_resp(dut, conn, SIGMA_ERROR, "errorCode,"
7253 "Unsupported uapsd parameter value");
7254 return 0;
7255 }
7256 if (wpa_command(intf, buf)) {
7257 send_resp(dut, conn, SIGMA_ERROR,
7258 "ErrorCode,Failed to change U-APSD "
7259 "powersave mode");
7260 return 0;
7261 }
7262 }
7263
7264 val = get_param(cmd, "TPKTIMER");
7265 if (val && strcasecmp(val, "DISABLE") == 0) {
7266 if (wpa_command(intf, "SET tdls_testing 0x100")) {
7267 send_resp(dut, conn, SIGMA_ERROR,
7268 "ErrorCode,Failed to enable no TPK "
7269 "expiration test mode");
7270 return 0;
7271 }
7272 dut->no_tpk_expiration = 1;
7273 }
7274
7275 val = get_param(cmd, "ChSwitchMode");
7276 if (val) {
7277 if (strcasecmp(val, "Enable") == 0 ||
7278 strcasecmp(val, "Initiate") == 0)
7279 chsm = CHSM_ENABLE;
7280 else if (strcasecmp(val, "Disable") == 0 ||
7281 strcasecmp(val, "passive") == 0)
7282 chsm = CHSM_DISABLE;
7283 else if (strcasecmp(val, "RejReq") == 0)
7284 chsm = CHSM_REJREQ;
7285 else if (strcasecmp(val, "UnSolResp") == 0)
7286 chsm = CHSM_UNSOLRESP;
7287 else {
7288 send_resp(dut, conn, SIGMA_ERROR,
7289 "ErrorCode,Unknown ChSwitchMode value");
7290 return 0;
7291 }
7292 }
7293
7294 val = get_param(cmd, "OffChNum");
7295 if (val) {
7296 off_ch_num = atoi(val);
7297 if (off_ch_num == 0) {
7298 send_resp(dut, conn, SIGMA_ERROR,
7299 "ErrorCode,Invalid OffChNum");
7300 return 0;
7301 }
7302 }
7303
7304 val = get_param(cmd, "SecChOffset");
7305 if (val) {
7306 if (strcmp(val, "20") == 0)
7307 sec_ch = SEC_CH_NO;
7308 else if (strcasecmp(val, "40above") == 0)
7309 sec_ch = SEC_CH_40ABOVE;
7310 else if (strcasecmp(val, "40below") == 0)
7311 sec_ch = SEC_CH_40BELOW;
7312 else {
7313 send_resp(dut, conn, SIGMA_ERROR,
7314 "ErrorCode,Unknown SecChOffset value");
7315 return 0;
7316 }
7317 }
7318
7319 if (chsm == CHSM_NOT_SET) {
7320 /* no offchannel changes requested */
7321 return 1;
7322 }
7323
7324 if (strcmp(intf, get_main_ifname()) != 0 &&
7325 strcmp(intf, get_station_ifname()) != 0) {
7326 send_resp(dut, conn, SIGMA_ERROR,
7327 "ErrorCode,Unknown interface");
7328 return 0;
7329 }
7330
7331 switch (chsm) {
7332 case CHSM_NOT_SET:
Jouni Malinen280f5ba2016-08-29 21:33:10 +03007333 res = 1;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007334 break;
7335 case CHSM_ENABLE:
7336 if (off_ch_num < 0) {
7337 send_resp(dut, conn, SIGMA_ERROR,
7338 "ErrorCode,Missing OffChNum argument");
7339 return 0;
7340 }
7341 if (wifi_chip_type == DRIVER_WCN) {
7342 res = tdls_set_offchannel_offset(dut, conn, intf,
7343 off_ch_num, sec_ch);
7344 } else {
7345 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
7346 sec_ch);
7347 }
7348 if (res != 1)
7349 return res;
7350 if (wifi_chip_type == DRIVER_WCN)
7351 res = tdls_set_offchannel_mode(dut, conn, intf, 1);
7352 else
7353 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 1);
7354 break;
7355 case CHSM_DISABLE:
7356 if (wifi_chip_type == DRIVER_WCN)
7357 res = tdls_set_offchannel_mode(dut, conn, intf, 2);
7358 else
7359 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 2);
7360 break;
7361 case CHSM_REJREQ:
7362 if (wifi_chip_type == DRIVER_WCN)
7363 res = tdls_set_offchannel_mode(dut, conn, intf, 3);
7364 else
7365 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 3);
7366 break;
7367 case CHSM_UNSOLRESP:
7368 if (off_ch_num < 0) {
7369 send_resp(dut, conn, SIGMA_ERROR,
7370 "ErrorCode,Missing OffChNum argument");
7371 return 0;
7372 }
7373 if (wifi_chip_type == DRIVER_WCN) {
7374 res = tdls_set_offchannel_offset(dut, conn, intf,
7375 off_ch_num, sec_ch);
7376 } else {
7377 res = iwpriv_set_offchan(dut, conn, intf, off_ch_num,
7378 sec_ch);
7379 }
7380 if (res != 1)
7381 return res;
7382 if (wifi_chip_type == DRIVER_WCN)
7383 res = tdls_set_offchannel_mode(dut, conn, intf, 4);
7384 else
7385 res = iwpriv_tdlsoffchnmode(dut, conn, intf, 4);
7386 break;
7387 }
7388
7389 return res;
7390}
7391
7392
7393static int ath_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
7394 struct sigma_conn *conn,
7395 struct sigma_cmd *cmd)
7396{
7397 const char *val;
7398 char *token, *result;
7399
priyadharshini gowthamane5e25172015-12-08 14:53:48 -08007400 novap_reset(dut, intf);
7401
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007402 val = get_param(cmd, "nss_mcs_opt");
7403 if (val) {
7404 /* String (nss_operating_mode; mcs_operating_mode) */
7405 int nss, mcs;
7406 char buf[50];
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307407 char *saveptr;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007408
7409 token = strdup(val);
7410 if (!token)
7411 return 0;
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307412 result = strtok_r(token, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05307413 if (!result) {
7414 sigma_dut_print(dut, DUT_MSG_ERROR,
7415 "VHT NSS not specified");
7416 goto failed;
7417 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007418 if (strcasecmp(result, "def") != 0) {
7419 nss = atoi(result);
7420 if (nss == 4)
7421 ath_disable_txbf(dut, intf);
7422 snprintf(buf, sizeof(buf), "iwpriv %s nss %d",
7423 intf, nss);
7424 if (system(buf) != 0) {
7425 sigma_dut_print(dut, DUT_MSG_ERROR,
7426 "iwpriv nss failed");
7427 goto failed;
7428 }
7429 }
7430
Pradeep Reddy POTTETIdbf7d712016-04-28 18:42:07 +05307431 result = strtok_r(NULL, ";", &saveptr);
Pradeep Reddy POTTETI41b8c542016-06-15 16:09:46 +05307432 if (!result) {
7433 sigma_dut_print(dut, DUT_MSG_ERROR,
7434 "VHT MCS not specified");
7435 goto failed;
7436 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007437 if (strcasecmp(result, "def") == 0) {
7438 snprintf(buf, sizeof(buf), "iwpriv %s set11NRates 0",
7439 intf);
7440 if (system(buf) != 0) {
7441 sigma_dut_print(dut, DUT_MSG_ERROR,
7442 "iwpriv set11NRates failed");
7443 goto failed;
7444 }
7445
7446 } else {
7447 mcs = atoi(result);
7448 snprintf(buf, sizeof(buf), "iwpriv %s vhtmcs %d",
7449 intf, mcs);
7450 if (system(buf) != 0) {
7451 sigma_dut_print(dut, DUT_MSG_ERROR,
7452 "iwpriv vhtmcs failed");
7453 goto failed;
7454 }
7455 }
7456 /* Channel width gets messed up, fix this */
7457 snprintf(buf, sizeof(buf), "iwpriv %s chwidth %d",
7458 intf, dut->chwidth);
7459 if (system(buf) != 0) {
7460 sigma_dut_print(dut, DUT_MSG_ERROR,
7461 "iwpriv chwidth failed");
7462 }
7463 }
7464
7465 return 1;
7466failed:
7467 free(token);
7468 return 0;
7469}
7470
7471
7472static int cmd_sta_set_rfeature_vht(const char *intf, struct sigma_dut *dut,
7473 struct sigma_conn *conn,
7474 struct sigma_cmd *cmd)
7475{
7476 switch (get_driver_type()) {
7477 case DRIVER_ATHEROS:
7478 return ath_sta_set_rfeature_vht(intf, dut, conn, cmd);
7479 default:
7480 send_resp(dut, conn, SIGMA_ERROR,
7481 "errorCode,Unsupported sta_set_rfeature(VHT) with the current driver");
7482 return 0;
7483 }
7484}
7485
7486
Ashwini Patil5acd7382017-04-13 15:55:04 +05307487static int btm_query_candidate_list(struct sigma_dut *dut,
7488 struct sigma_conn *conn,
7489 struct sigma_cmd *cmd)
7490{
7491 const char *bssid, *info, *op_class, *ch, *phy_type, *pref;
7492 int len, ret;
7493 char buf[10];
7494
7495 /*
7496 * Neighbor Report elements format:
7497 * neighbor=<BSSID>,<BSSID Information>,<Operating Class>,
7498 * <Channel Number>,<PHY Type>[,<hexdump of Optional Subelements>]
7499 * eg: neighbor=aa:bb:cc:dd:ee:ff,17,81,6,1,030101
7500 */
7501
7502 bssid = get_param(cmd, "Nebor_BSSID");
7503 if (!bssid) {
7504 send_resp(dut, conn, SIGMA_INVALID,
7505 "errorCode,Nebor_BSSID is missing");
7506 return 0;
7507 }
7508
7509 info = get_param(cmd, "Nebor_Bssid_Info");
7510 if (!info) {
7511 sigma_dut_print(dut, DUT_MSG_INFO,
7512 "Using default value for Nebor_Bssid_Info: %s",
7513 DEFAULT_NEIGHBOR_BSSID_INFO);
7514 info = DEFAULT_NEIGHBOR_BSSID_INFO;
7515 }
7516
7517 op_class = get_param(cmd, "Nebor_Op_Class");
7518 if (!op_class) {
7519 send_resp(dut, conn, SIGMA_INVALID,
7520 "errorCode,Nebor_Op_Class is missing");
7521 return 0;
7522 }
7523
7524 ch = get_param(cmd, "Nebor_Op_Ch");
7525 if (!ch) {
7526 send_resp(dut, conn, SIGMA_INVALID,
7527 "errorCode,Nebor_Op_Ch is missing");
7528 return 0;
7529 }
7530
7531 phy_type = get_param(cmd, "Nebor_Phy_Type");
7532 if (!phy_type) {
7533 sigma_dut_print(dut, DUT_MSG_INFO,
7534 "Using default value for Nebor_Phy_Type: %s",
7535 DEFAULT_NEIGHBOR_PHY_TYPE);
7536 phy_type = DEFAULT_NEIGHBOR_PHY_TYPE;
7537 }
7538
7539 /* Parse optional subelements */
7540 buf[0] = '\0';
7541 pref = get_param(cmd, "Nebor_Pref");
7542 if (pref) {
7543 /* hexdump for preferrence subelement */
7544 ret = snprintf(buf, sizeof(buf), ",0301%02x", atoi(pref));
7545 if (ret < 0 || ret >= (int) sizeof(buf)) {
7546 sigma_dut_print(dut, DUT_MSG_ERROR,
7547 "snprintf failed for optional subelement ret: %d",
7548 ret);
7549 send_resp(dut, conn, SIGMA_ERROR,
7550 "errorCode,snprintf failed for subelement");
7551 return 0;
7552 }
7553 }
7554
7555 if (!dut->btm_query_cand_list) {
7556 dut->btm_query_cand_list = calloc(1, NEIGHBOR_REPORT_SIZE);
7557 if (!dut->btm_query_cand_list) {
7558 send_resp(dut, conn, SIGMA_ERROR,
7559 "errorCode,Failed to allocate memory for btm_query_cand_list");
7560 return 0;
7561 }
7562 }
7563
7564 len = strlen(dut->btm_query_cand_list);
7565 ret = snprintf(dut->btm_query_cand_list + len,
7566 NEIGHBOR_REPORT_SIZE - len, " neighbor=%s,%s,%s,%s,%s%s",
7567 bssid, info, op_class, ch, phy_type, buf);
7568 if (ret < 0 || ret >= NEIGHBOR_REPORT_SIZE - len) {
7569 sigma_dut_print(dut, DUT_MSG_ERROR,
7570 "snprintf failed for neighbor report list ret: %d",
7571 ret);
7572 send_resp(dut, conn, SIGMA_ERROR,
7573 "errorCode,snprintf failed for neighbor report");
7574 free(dut->btm_query_cand_list);
7575 dut->btm_query_cand_list = NULL;
7576 return 0;
7577 }
7578
7579 return 1;
7580}
7581
7582
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007583static int cmd_sta_set_rfeature(struct sigma_dut *dut, struct sigma_conn *conn,
7584 struct sigma_cmd *cmd)
7585{
7586 const char *intf = get_param(cmd, "Interface");
7587 const char *prog = get_param(cmd, "Prog");
Ashwini Patil68d02cd2017-01-10 15:39:16 +05307588 const char *val;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007589
7590 if (intf == NULL || prog == NULL)
7591 return -1;
7592
Ashwini Patil5acd7382017-04-13 15:55:04 +05307593 /* BSS Transition candidate list for BTM query */
7594 val = get_param(cmd, "Nebor_BSSID");
7595 if (val && btm_query_candidate_list(dut, conn, cmd) == 0)
7596 return 0;
7597
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007598 if (strcasecmp(prog, "TDLS") == 0)
7599 return cmd_sta_set_rfeature_tdls(intf, dut, conn, cmd);
7600
7601 if (strcasecmp(prog, "VHT") == 0)
7602 return cmd_sta_set_rfeature_vht(intf, dut, conn, cmd);
7603
Ashwini Patil68d02cd2017-01-10 15:39:16 +05307604 if (strcasecmp(prog, "MBO") == 0) {
7605 val = get_param(cmd, "Cellular_Data_Cap");
7606 if (val &&
7607 mbo_set_cellular_data_capa(dut, conn, intf, atoi(val)) == 0)
7608 return 0;
Ashwini Patil00402582017-04-13 12:29:39 +05307609
7610 val = get_param(cmd, "Ch_Pref");
7611 if (val && mbo_set_non_pref_ch_list(dut, conn, intf, cmd) == 0)
7612 return 0;
7613
Ashwini Patil68d02cd2017-01-10 15:39:16 +05307614 return 1;
7615 }
7616
Jouni Malinencd4e3c32015-10-29 12:39:56 +02007617 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported Prog");
7618 return 0;
7619}
7620
7621
7622static int cmd_sta_set_radio(struct sigma_dut *dut, struct sigma_conn *conn,
7623 struct sigma_cmd *cmd)
7624{
7625 const char *intf = get_param(cmd, "Interface");
7626 const char *mode = get_param(cmd, "Mode");
7627 int res;
7628
7629 if (intf == NULL || mode == NULL)
7630 return -1;
7631
7632 if (strcasecmp(mode, "On") == 0)
7633 res = wpa_command(intf, "SET radio_disabled 0");
7634 else if (strcasecmp(mode, "Off") == 0)
7635 res = wpa_command(intf, "SET radio_disabled 1");
7636 else
7637 return -1;
7638
7639 if (res) {
7640 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
7641 "radio mode");
7642 return 0;
7643 }
7644
7645 return 1;
7646}
7647
7648
7649static int cmd_sta_set_pwrsave(struct sigma_dut *dut, struct sigma_conn *conn,
7650 struct sigma_cmd *cmd)
7651{
7652 const char *intf = get_param(cmd, "Interface");
7653 const char *mode = get_param(cmd, "Mode");
7654 int res;
7655
7656 if (intf == NULL || mode == NULL)
7657 return -1;
7658
7659 if (strcasecmp(mode, "On") == 0)
7660 res = set_ps(intf, dut, 1);
7661 else if (strcasecmp(mode, "Off") == 0)
7662 res = set_ps(intf, dut, 0);
7663 else
7664 return -1;
7665
7666 if (res) {
7667 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to change "
7668 "power save mode");
7669 return 0;
7670 }
7671
7672 return 1;
7673}
7674
7675
7676static int cmd_sta_bssid_pool(struct sigma_dut *dut, struct sigma_conn *conn,
7677 struct sigma_cmd *cmd)
7678{
7679 const char *intf = get_param(cmd, "Interface");
7680 const char *val, *bssid;
7681 int res;
7682 char *buf;
7683 size_t buf_len;
7684
7685 val = get_param(cmd, "BSSID_FILTER");
7686 if (val == NULL)
7687 return -1;
7688
7689 bssid = get_param(cmd, "BSSID_List");
7690 if (atoi(val) == 0 || bssid == NULL) {
7691 /* Disable BSSID filter */
7692 if (wpa_command(intf, "SET bssid_filter ")) {
7693 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed "
7694 "to disable BSSID filter");
7695 return 0;
7696 }
7697
7698 return 1;
7699 }
7700
7701 buf_len = 100 + strlen(bssid);
7702 buf = malloc(buf_len);
7703 if (buf == NULL)
7704 return -1;
7705
7706 snprintf(buf, buf_len, "SET bssid_filter %s", bssid);
7707 res = wpa_command(intf, buf);
7708 free(buf);
7709 if (res) {
7710 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to enable "
7711 "BSSID filter");
7712 return 0;
7713 }
7714
7715 return 1;
7716}
7717
7718
7719static int cmd_sta_reset_parm(struct sigma_dut *dut, struct sigma_conn *conn,
7720 struct sigma_cmd *cmd)
7721{
7722 const char *intf = get_param(cmd, "Interface");
7723 const char *val;
7724
7725 /* TODO: ARP */
7726
7727 val = get_param(cmd, "HS2_CACHE_PROFILE");
7728 if (val && strcasecmp(val, "All") == 0)
7729 hs2_clear_credentials(intf);
7730
7731 return 1;
7732}
7733
7734
7735static int cmd_sta_get_key(struct sigma_dut *dut, struct sigma_conn *conn,
7736 struct sigma_cmd *cmd)
7737{
7738 const char *intf = get_param(cmd, "Interface");
7739 const char *key_type = get_param(cmd, "KeyType");
7740 char buf[100], resp[200];
7741
7742 if (key_type == NULL)
7743 return -1;
7744
7745 if (strcasecmp(key_type, "GTK") == 0) {
7746 if (wpa_command_resp(intf, "GET gtk", buf, sizeof(buf)) < 0 ||
7747 strncmp(buf, "FAIL", 4) == 0) {
7748 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7749 "not fetch current GTK");
7750 return 0;
7751 }
7752 snprintf(resp, sizeof(resp), "KeyValue,%s", buf);
7753 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7754 return 0;
7755 } else {
7756 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Unsupported "
7757 "KeyType");
7758 return 0;
7759 }
7760
7761 return 1;
7762}
7763
7764
7765static int hs2_set_policy(struct sigma_dut *dut)
7766{
7767#ifdef ANDROID
7768 system("ip rule del prio 23000");
7769 if (system("ip rule add from all lookup main prio 23000") != 0) {
7770 sigma_dut_print(dut, DUT_MSG_ERROR,
7771 "Failed to run:ip rule add from all lookup main prio");
7772 return -1;
7773 }
7774 if (system("ip route flush cache") != 0) {
7775 sigma_dut_print(dut, DUT_MSG_ERROR,
7776 "Failed to run ip route flush cache");
7777 return -1;
7778 }
7779 return 1;
7780#else /* ANDROID */
7781 return 0;
7782#endif /* ANDROID */
7783}
7784
7785
7786static int cmd_sta_hs2_associate(struct sigma_dut *dut,
7787 struct sigma_conn *conn,
7788 struct sigma_cmd *cmd)
7789{
7790 const char *intf = get_param(cmd, "Interface");
7791 const char *val = get_param(cmd, "Ignore_blacklist");
7792 struct wpa_ctrl *ctrl;
7793 int res;
7794 char bssid[20], ssid[40], resp[100], buf[100], blacklisted[100];
7795 int tries = 0;
7796 int ignore_blacklist = 0;
7797 const char *events[] = {
7798 "CTRL-EVENT-CONNECTED",
7799 "INTERWORKING-BLACKLISTED",
7800 "INTERWORKING-NO-MATCH",
7801 NULL
7802 };
7803
7804 start_sta_mode(dut);
7805
7806 blacklisted[0] = '\0';
7807 if (val && atoi(val))
7808 ignore_blacklist = 1;
7809
7810try_again:
7811 ctrl = open_wpa_mon(intf);
7812 if (ctrl == NULL) {
7813 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
7814 "wpa_supplicant monitor connection");
7815 return -2;
7816 }
7817
7818 tries++;
7819 if (wpa_command(intf, "INTERWORKING_SELECT auto")) {
7820 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start "
7821 "Interworking connection");
7822 wpa_ctrl_detach(ctrl);
7823 wpa_ctrl_close(ctrl);
7824 return 0;
7825 }
7826
7827 buf[0] = '\0';
7828 while (1) {
7829 char *pos;
7830 res = get_wpa_cli_events(dut, ctrl, events, buf, sizeof(buf));
7831 pos = strstr(buf, "INTERWORKING-BLACKLISTED");
7832 if (!pos)
7833 break;
7834 pos += 25;
7835 sigma_dut_print(dut, DUT_MSG_DEBUG, "Found blacklisted AP: %s",
7836 pos);
7837 if (!blacklisted[0])
7838 memcpy(blacklisted, pos, strlen(pos) + 1);
7839 }
7840
7841 if (ignore_blacklist && blacklisted[0]) {
7842 char *end;
7843 end = strchr(blacklisted, ' ');
7844 if (end)
7845 *end = '\0';
7846 sigma_dut_print(dut, DUT_MSG_DEBUG, "Try to connect to a blacklisted network: %s",
7847 blacklisted);
7848 snprintf(buf, sizeof(buf), "INTERWORKING_CONNECT %s",
7849 blacklisted);
7850 if (wpa_command(intf, buf)) {
7851 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Failed to start Interworking connection to blacklisted network");
7852 wpa_ctrl_detach(ctrl);
7853 wpa_ctrl_close(ctrl);
7854 return 0;
7855 }
7856 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
7857 buf, sizeof(buf));
7858 }
7859
7860 wpa_ctrl_detach(ctrl);
7861 wpa_ctrl_close(ctrl);
7862
7863 if (res < 0) {
7864 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
7865 "connect");
7866 return 0;
7867 }
7868
7869 if (strstr(buf, "INTERWORKING-NO-MATCH") ||
7870 strstr(buf, "INTERWORKING-BLACKLISTED")) {
7871 if (tries < 2) {
7872 sigma_dut_print(dut, DUT_MSG_INFO, "No match found - try again to verify no APs were missed in the scan");
7873 goto try_again;
7874 }
7875 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,No network with "
7876 "matching credentials found");
7877 return 0;
7878 }
7879
7880 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
7881 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
7882 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Could not "
7883 "get current BSSID/SSID");
7884 return 0;
7885 }
7886
7887 snprintf(resp, sizeof(resp), "SSID,%s,BSSID,%s", ssid, bssid);
7888 send_resp(dut, conn, SIGMA_COMPLETE, resp);
7889 hs2_set_policy(dut);
7890 return 0;
7891}
7892
7893
7894static int sta_add_credential_uname_pwd(struct sigma_dut *dut,
7895 struct sigma_conn *conn,
7896 const char *ifname,
7897 struct sigma_cmd *cmd)
7898{
7899 const char *val;
7900 int id;
7901
7902 id = add_cred(ifname);
7903 if (id < 0)
7904 return -2;
7905 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
7906
7907 val = get_param(cmd, "prefer");
7908 if (val && atoi(val) > 0)
7909 set_cred(ifname, id, "priority", "1");
7910
7911 val = get_param(cmd, "REALM");
7912 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
7913 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7914 "realm");
7915 return 0;
7916 }
7917
7918 val = get_param(cmd, "HOME_FQDN");
7919 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
7920 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7921 "home_fqdn");
7922 return 0;
7923 }
7924
7925 val = get_param(cmd, "Username");
7926 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
7927 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7928 "username");
7929 return 0;
7930 }
7931
7932 val = get_param(cmd, "Password");
7933 if (val && set_cred_quoted(ifname, id, "password", val) < 0) {
7934 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
7935 "password");
7936 return 0;
7937 }
7938
7939 val = get_param(cmd, "ROOT_CA");
7940 if (val) {
7941 char fname[200];
7942 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
7943#ifdef __linux__
7944 if (!file_exists(fname)) {
7945 char msg[300];
7946 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
7947 "file (%s) not found", fname);
7948 send_resp(dut, conn, SIGMA_ERROR, msg);
7949 return 0;
7950 }
7951#endif /* __linux__ */
7952 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
7953 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
7954 "not set root CA");
7955 return 0;
7956 }
7957 }
7958
7959 return 1;
7960}
7961
7962
7963static int update_devdetail_imsi(struct sigma_dut *dut, const char *imsi)
7964{
7965 FILE *in, *out;
7966 char buf[500];
7967 int found = 0;
7968
7969 in = fopen("devdetail.xml", "r");
7970 if (in == NULL)
7971 return -1;
7972 out = fopen("devdetail.xml.tmp", "w");
7973 if (out == NULL) {
7974 fclose(in);
7975 return -1;
7976 }
7977
7978 while (fgets(buf, sizeof(buf), in)) {
7979 char *pos = strstr(buf, "<IMSI>");
7980 if (pos) {
7981 sigma_dut_print(dut, DUT_MSG_INFO, "Updated DevDetail IMSI to %s",
7982 imsi);
7983 pos += 6;
7984 *pos = '\0';
7985 fprintf(out, "%s%s</IMSI>\n", buf, imsi);
7986 found++;
7987 } else {
7988 fprintf(out, "%s", buf);
7989 }
7990 }
7991
7992 fclose(out);
7993 fclose(in);
7994 if (found)
7995 rename("devdetail.xml.tmp", "devdetail.xml");
7996 else
7997 unlink("devdetail.xml.tmp");
7998
7999 return 0;
8000}
8001
8002
8003static int sta_add_credential_sim(struct sigma_dut *dut,
8004 struct sigma_conn *conn,
8005 const char *ifname, struct sigma_cmd *cmd)
8006{
8007 const char *val, *imsi = NULL;
8008 int id;
8009 char buf[200];
8010 int res;
8011 const char *pos;
8012 size_t mnc_len;
8013 char plmn_mcc[4];
8014 char plmn_mnc[4];
8015
8016 id = add_cred(ifname);
8017 if (id < 0)
8018 return -2;
8019 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8020
8021 val = get_param(cmd, "prefer");
8022 if (val && atoi(val) > 0)
8023 set_cred(ifname, id, "priority", "1");
8024
8025 val = get_param(cmd, "PLMN_MCC");
8026 if (val == NULL) {
8027 send_resp(dut, conn, SIGMA_ERROR,
8028 "errorCode,Missing PLMN_MCC");
8029 return 0;
8030 }
8031 if (strlen(val) != 3) {
8032 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MCC");
8033 return 0;
8034 }
8035 snprintf(plmn_mcc, sizeof(plmn_mcc), "%s", val);
8036
8037 val = get_param(cmd, "PLMN_MNC");
8038 if (val == NULL) {
8039 send_resp(dut, conn, SIGMA_ERROR,
8040 "errorCode,Missing PLMN_MNC");
8041 return 0;
8042 }
8043 if (strlen(val) != 2 && strlen(val) != 3) {
8044 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Invalid MNC");
8045 return 0;
8046 }
8047 snprintf(plmn_mnc, sizeof(plmn_mnc), "%s", val);
8048
8049 val = get_param(cmd, "IMSI");
8050 if (val == NULL) {
8051 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Missing SIM "
8052 "IMSI");
8053 return 0;
8054 }
8055
8056 imsi = pos = val;
8057
8058 if (strncmp(plmn_mcc, pos, 3) != 0) {
8059 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MCC mismatch");
8060 return 0;
8061 }
8062 pos += 3;
8063
8064 mnc_len = strlen(plmn_mnc);
8065 if (mnc_len < 2) {
8066 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC not set");
8067 return 0;
8068 }
8069
8070 if (strncmp(plmn_mnc, pos, mnc_len) != 0) {
8071 send_resp(dut, conn, SIGMA_ERROR, "errorCode,MNC mismatch");
8072 return 0;
8073 }
8074 pos += mnc_len;
8075
8076 res = snprintf(buf, sizeof(buf), "%s%s-%s",plmn_mcc, plmn_mnc, pos);
8077 if (res < 0 || res >= (int) sizeof(buf))
8078 return -1;
8079 if (set_cred_quoted(ifname, id, "imsi", buf) < 0) {
8080 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8081 "not set IMSI");
8082 return 0;
8083 }
8084
8085 val = get_param(cmd, "Password");
8086 if (val && set_cred_quoted(ifname, id, "milenage", val) < 0) {
8087 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8088 "not set password");
8089 return 0;
8090 }
8091
8092 if (dut->program == PROGRAM_HS2_R2) {
8093 /*
8094 * Set provisioning_sp for the test cases where SIM/USIM
8095 * provisioning is used.
8096 */
8097 if (val && set_cred_quoted(ifname, id, "provisioning_sp",
8098 "wi-fi.org") < 0) {
8099 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8100 "not set provisioning_sp");
8101 return 0;
8102 }
8103
8104 update_devdetail_imsi(dut, imsi);
8105 }
8106
8107 return 1;
8108}
8109
8110
8111static int sta_add_credential_cert(struct sigma_dut *dut,
8112 struct sigma_conn *conn,
8113 const char *ifname,
8114 struct sigma_cmd *cmd)
8115{
8116 const char *val;
8117 int id;
8118
8119 id = add_cred(ifname);
8120 if (id < 0)
8121 return -2;
8122 sigma_dut_print(dut, DUT_MSG_DEBUG, "Adding credential %d", id);
8123
8124 val = get_param(cmd, "prefer");
8125 if (val && atoi(val) > 0)
8126 set_cred(ifname, id, "priority", "1");
8127
8128 val = get_param(cmd, "REALM");
8129 if (val && set_cred_quoted(ifname, id, "realm", val) < 0) {
8130 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8131 "realm");
8132 return 0;
8133 }
8134
8135 val = get_param(cmd, "HOME_FQDN");
8136 if (val && set_cred_quoted(ifname, id, "domain", val) < 0) {
8137 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8138 "home_fqdn");
8139 return 0;
8140 }
8141
8142 val = get_param(cmd, "Username");
8143 if (val && set_cred_quoted(ifname, id, "username", val) < 0) {
8144 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not set "
8145 "username");
8146 return 0;
8147 }
8148
8149 val = get_param(cmd, "clientCertificate");
8150 if (val) {
8151 char fname[200];
8152 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
8153#ifdef __linux__
8154 if (!file_exists(fname)) {
8155 char msg[300];
8156 snprintf(msg, sizeof(msg),
8157 "ErrorCode,clientCertificate "
8158 "file (%s) not found", fname);
8159 send_resp(dut, conn, SIGMA_ERROR, msg);
8160 return 0;
8161 }
8162#endif /* __linux__ */
8163 if (set_cred_quoted(ifname, id, "client_cert", fname) < 0) {
8164 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8165 "not set client_cert");
8166 return 0;
8167 }
8168 if (set_cred_quoted(ifname, id, "private_key", fname) < 0) {
8169 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8170 "not set private_key");
8171 return 0;
8172 }
8173 }
8174
8175 val = get_param(cmd, "ROOT_CA");
8176 if (val) {
8177 char fname[200];
8178 snprintf(fname, sizeof(fname), "%s/%s", sigma_cert_path, val);
8179#ifdef __linux__
8180 if (!file_exists(fname)) {
8181 char msg[300];
8182 snprintf(msg, sizeof(msg), "ErrorCode,ROOT_CA "
8183 "file (%s) not found", fname);
8184 send_resp(dut, conn, SIGMA_ERROR, msg);
8185 return 0;
8186 }
8187#endif /* __linux__ */
8188 if (set_cred_quoted(ifname, id, "ca_cert", fname) < 0) {
8189 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could "
8190 "not set root CA");
8191 return 0;
8192 }
8193 }
8194
8195 return 1;
8196}
8197
8198
8199static int cmd_sta_add_credential(struct sigma_dut *dut,
8200 struct sigma_conn *conn,
8201 struct sigma_cmd *cmd)
8202{
8203 const char *intf = get_param(cmd, "Interface");
8204 const char *type;
8205
8206 start_sta_mode(dut);
8207
8208 type = get_param(cmd, "Type");
8209 if (!type)
8210 return -1;
8211
8212 if (strcasecmp(type, "uname_pwd") == 0)
8213 return sta_add_credential_uname_pwd(dut, conn, intf, cmd);
8214
8215 if (strcasecmp(type, "sim") == 0)
8216 return sta_add_credential_sim(dut, conn, intf, cmd);
8217
8218 if (strcasecmp(type, "cert") == 0)
8219 return sta_add_credential_cert(dut, conn, intf, cmd);
8220
8221 send_resp(dut, conn, SIGMA_ERROR, "ErrorCode,Unsupported credential "
8222 "type");
8223 return 0;
8224}
8225
8226
8227static int cmd_sta_scan(struct sigma_dut *dut, struct sigma_conn *conn,
8228 struct sigma_cmd *cmd)
8229{
8230 const char *intf = get_param(cmd, "Interface");
8231 const char *val;
8232 char buf[100];
8233 int res;
8234
8235 val = get_param(cmd, "HESSID");
8236 if (val) {
8237 res = snprintf(buf, sizeof(buf), "SET hessid %s", val);
8238 if (res < 0 || res >= (int) sizeof(buf))
8239 return -1;
8240 wpa_command(intf, buf);
8241 }
8242
8243 val = get_param(cmd, "ACCS_NET_TYPE");
8244 if (val) {
8245 res = snprintf(buf, sizeof(buf), "SET access_network_type %s",
8246 val);
8247 if (res < 0 || res >= (int) sizeof(buf))
8248 return -1;
8249 wpa_command(intf, buf);
8250 }
8251
8252 if (wpa_command(intf, "SCAN")) {
8253 send_resp(dut, conn, SIGMA_ERROR, "errorCode,Could not start "
8254 "scan");
8255 return 0;
8256 }
8257
8258 return 1;
8259}
8260
8261
8262static int cmd_sta_set_systime(struct sigma_dut *dut, struct sigma_conn *conn,
8263 struct sigma_cmd *cmd)
8264{
8265#ifdef __linux__
8266 struct timeval tv;
8267 struct tm tm;
8268 time_t t;
8269 const char *val;
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05308270 int v;
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008271
8272 wpa_command(get_station_ifname(), "PMKSA_FLUSH");
8273
8274 memset(&tm, 0, sizeof(tm));
8275 val = get_param(cmd, "seconds");
8276 if (val)
8277 tm.tm_sec = atoi(val);
8278 val = get_param(cmd, "minutes");
8279 if (val)
8280 tm.tm_min = atoi(val);
8281 val = get_param(cmd, "hours");
8282 if (val)
8283 tm.tm_hour = atoi(val);
8284 val = get_param(cmd, "date");
8285 if (val)
8286 tm.tm_mday = atoi(val);
8287 val = get_param(cmd, "month");
Pradeep Reddy POTTETI429c69e2016-10-13 17:22:03 +05308288 if (val) {
8289 v = atoi(val);
8290 if (v < 1 || v > 12) {
8291 send_resp(dut, conn, SIGMA_INVALID,
8292 "errorCode,Invalid month");
8293 return 0;
8294 }
8295 tm.tm_mon = v - 1;
8296 }
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008297 val = get_param(cmd, "year");
8298 if (val) {
8299 int year = atoi(val);
8300#ifdef ANDROID
8301 if (year > 2035)
8302 year = 2035; /* years beyond 2035 not supported */
8303#endif /* ANDROID */
8304 tm.tm_year = year - 1900;
8305 }
8306 t = mktime(&tm);
8307 if (t == (time_t) -1) {
8308 send_resp(dut, conn, SIGMA_ERROR,
8309 "errorCode,Invalid date or time");
8310 return 0;
8311 }
8312
8313 memset(&tv, 0, sizeof(tv));
8314 tv.tv_sec = t;
8315
8316 if (settimeofday(&tv, NULL) < 0) {
8317 sigma_dut_print(dut, DUT_MSG_INFO, "settimeofday failed: %s",
8318 strerror(errno));
8319 send_resp(dut, conn, SIGMA_ERROR,
8320 "errorCode,Failed to set time");
8321 return 0;
8322 }
8323
8324 return 1;
8325#endif /* __linux__ */
8326
8327 return -1;
8328}
8329
8330
8331static int cmd_sta_osu(struct sigma_dut *dut, struct sigma_conn *conn,
8332 struct sigma_cmd *cmd)
8333{
8334 const char *intf = get_param(cmd, "Interface");
8335 const char *name, *val;
8336 int prod_ess_assoc = 1;
8337 char buf[200], bssid[100], ssid[100];
8338 int res;
8339 struct wpa_ctrl *ctrl;
8340
8341 name = get_param(cmd, "osuFriendlyName");
8342
8343 val = get_param(cmd, "ProdESSAssoc");
8344 if (val)
8345 prod_ess_assoc = atoi(val);
8346
8347 kill_dhcp_client(dut, intf);
8348 if (start_dhcp_client(dut, intf) < 0)
8349 return -2;
8350
8351 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger OSU");
8352 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
8353 res = snprintf(buf, sizeof(buf),
8354 "%s %s%s%s signup osu-ca.pem",
8355 prod_ess_assoc ? "" : "-N",
8356 name ? "-O'" : "", name ? name : "",
8357 name ? "'" : "");
8358
Kanchanapally, Vidyullatha12b66762015-12-31 16:46:42 +05308359 hs2_set_policy(dut);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008360 if (run_hs20_osu(dut, buf) < 0) {
8361 FILE *f;
8362
8363 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to complete OSU");
8364
8365 f = fopen("hs20-osu-client.res", "r");
8366 if (f) {
8367 char resp[400], res[300], *pos;
8368 if (!fgets(res, sizeof(res), f))
8369 res[0] = '\0';
8370 pos = strchr(res, '\n');
8371 if (pos)
8372 *pos = '\0';
8373 fclose(f);
8374 sigma_dut_summary(dut, "hs20-osu-client provisioning failed: %s",
8375 res);
8376 snprintf(resp, sizeof(resp), "notify-send '%s'", res);
8377 if (system(resp) != 0) {
8378 }
8379 snprintf(resp, sizeof(resp),
8380 "SSID,,BSSID,,failureReason,%s", res);
8381 send_resp(dut, conn, SIGMA_COMPLETE, resp);
8382 return 0;
8383 }
8384
8385 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
8386 return 0;
8387 }
8388
8389 if (!prod_ess_assoc)
8390 goto report;
8391
8392 ctrl = open_wpa_mon(intf);
8393 if (ctrl == NULL) {
8394 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8395 "wpa_supplicant monitor connection");
8396 return -1;
8397 }
8398
8399 res = get_wpa_cli_event(dut, ctrl, "CTRL-EVENT-CONNECTED",
8400 buf, sizeof(buf));
8401
8402 wpa_ctrl_detach(ctrl);
8403 wpa_ctrl_close(ctrl);
8404
8405 if (res < 0) {
8406 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to connect to "
8407 "network after OSU");
8408 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
8409 return 0;
8410 }
8411
8412report:
8413 if (get_wpa_status(intf, "bssid", bssid, sizeof(bssid)) < 0 ||
8414 get_wpa_status(intf, "ssid", ssid, sizeof(ssid)) < 0) {
8415 sigma_dut_print(dut, DUT_MSG_INFO, "Failed to get BSSID/SSID");
8416 send_resp(dut, conn, SIGMA_COMPLETE, "SSID,,BSSID,");
8417 return 0;
8418 }
8419
8420 snprintf(buf, sizeof(buf), "SSID,%s,BSSID,%s", ssid, bssid);
8421 send_resp(dut, conn, SIGMA_COMPLETE, buf);
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008422 return 0;
8423}
8424
8425
8426static int cmd_sta_policy_update(struct sigma_dut *dut, struct sigma_conn *conn,
8427 struct sigma_cmd *cmd)
8428{
8429 const char *val;
8430 int timeout = 120;
8431
8432 val = get_param(cmd, "PolicyUpdate");
8433 if (val == NULL || atoi(val) == 0)
8434 return 1; /* No operation requested */
8435
8436 val = get_param(cmd, "Timeout");
8437 if (val)
8438 timeout = atoi(val);
8439
8440 if (timeout) {
8441 /* TODO: time out the command and return
8442 * PolicyUpdateStatus,TIMEOUT if needed. */
8443 }
8444
8445 sigma_dut_print(dut, DUT_MSG_DEBUG, "Trigger policy update");
8446 mkdir("Logs", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
8447 if (run_hs20_osu(dut, "pol_upd fqdn=wi-fi.org") < 0) {
8448 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,FAIL");
8449 return 0;
8450 }
8451
8452 send_resp(dut, conn, SIGMA_COMPLETE, "PolicyUpdateStatus,SUCCESS");
8453 return 0;
8454}
8455
8456
8457static int cmd_sta_er_config(struct sigma_dut *dut, struct sigma_conn *conn,
8458 struct sigma_cmd *cmd)
8459{
8460 struct wpa_ctrl *ctrl;
8461 const char *intf = get_param(cmd, "Interface");
8462 const char *bssid = get_param(cmd, "Bssid");
8463 const char *ssid = get_param(cmd, "SSID");
8464 const char *security = get_param(cmd, "Security");
8465 const char *passphrase = get_param(cmd, "Passphrase");
8466 const char *pin = get_param(cmd, "PIN");
8467 char buf[1000];
8468 char ssid_hex[200], passphrase_hex[200];
8469 const char *keymgmt, *cipher;
8470
8471 if (intf == NULL)
8472 intf = get_main_ifname();
8473
8474 if (!bssid) {
8475 send_resp(dut, conn, SIGMA_ERROR,
8476 "ErrorCode,Missing Bssid argument");
8477 return 0;
8478 }
8479
8480 if (!ssid) {
8481 send_resp(dut, conn, SIGMA_ERROR,
8482 "ErrorCode,Missing SSID argument");
8483 return 0;
8484 }
8485
8486 if (!security) {
8487 send_resp(dut, conn, SIGMA_ERROR,
8488 "ErrorCode,Missing Security argument");
8489 return 0;
8490 }
8491
8492 if (!passphrase) {
8493 send_resp(dut, conn, SIGMA_ERROR,
8494 "ErrorCode,Missing Passphrase argument");
8495 return 0;
8496 }
8497
8498 if (!pin) {
8499 send_resp(dut, conn, SIGMA_ERROR,
8500 "ErrorCode,Missing PIN argument");
8501 return 0;
8502 }
8503
vamsi krishna8c9c1562017-05-12 15:51:46 +05308504 if (2 * strlen(ssid) >= sizeof(ssid_hex) ||
8505 2 * strlen(passphrase) >= sizeof(passphrase_hex)) {
Jouni Malinencd4e3c32015-10-29 12:39:56 +02008506 send_resp(dut, conn, SIGMA_ERROR,
8507 "ErrorCode,Too long SSID/passphrase");
8508 return 0;
8509 }
8510
8511 ctrl = open_wpa_mon(intf);
8512 if (ctrl == NULL) {
8513 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8514 "wpa_supplicant monitor connection");
8515 return -2;
8516 }
8517
8518 if (strcasecmp(security, "wpa2-psk") == 0) {
8519 keymgmt = "WPA2PSK";
8520 cipher = "CCMP";
8521 } else {
8522 wpa_ctrl_detach(ctrl);
8523 wpa_ctrl_close(ctrl);
8524 send_resp(dut, conn, SIGMA_ERROR,
8525 "ErrorCode,Unsupported Security value");
8526 return 0;
8527 }
8528
8529 ascii2hexstr(ssid, ssid_hex);
8530 ascii2hexstr(passphrase, passphrase_hex);
8531 snprintf(buf, sizeof(buf), "WPS_REG %s %s %s %s %s %s",
8532 bssid, pin, ssid_hex, keymgmt, cipher, passphrase_hex);
8533
8534 if (wpa_command(intf, buf) < 0) {
8535 wpa_ctrl_detach(ctrl);
8536 wpa_ctrl_close(ctrl);
8537 send_resp(dut, conn, SIGMA_ERROR,
8538 "ErrorCode,Failed to start registrar");
8539 return 0;
8540 }
8541
8542 snprintf(dut->er_oper_bssid, sizeof(dut->er_oper_bssid), "%s", bssid);
8543 dut->er_oper_performed = 1;
8544
8545 return wps_connection_event(dut, conn, ctrl, intf, 0);
8546}
8547
8548
8549static int cmd_sta_wps_connect_pw_token(struct sigma_dut *dut,
8550 struct sigma_conn *conn,
8551 struct sigma_cmd *cmd)
8552{
8553 struct wpa_ctrl *ctrl;
8554 const char *intf = get_param(cmd, "Interface");
8555 const char *bssid = get_param(cmd, "Bssid");
8556 char buf[100];
8557
8558 if (!bssid) {
8559 send_resp(dut, conn, SIGMA_ERROR,
8560 "ErrorCode,Missing Bssid argument");
8561 return 0;
8562 }
8563
8564 ctrl = open_wpa_mon(intf);
8565 if (ctrl == NULL) {
8566 sigma_dut_print(dut, DUT_MSG_ERROR, "Failed to open "
8567 "wpa_supplicant monitor connection");
8568 return -2;
8569 }
8570
8571 snprintf(buf, sizeof(buf), "WPS_NFC %s", bssid);
8572
8573 if (wpa_command(intf, buf) < 0) {
8574 wpa_ctrl_detach(ctrl);
8575 wpa_ctrl_close(ctrl);
8576 send_resp(dut, conn, SIGMA_ERROR,
8577 "ErrorCode,Failed to start registrar");
8578 return 0;
8579 }
8580
8581 return wps_connection_event(dut, conn, ctrl, intf, 0);
8582}
8583
8584
8585static int req_intf(struct sigma_cmd *cmd)
8586{
8587 return get_param(cmd, "interface") == NULL ? -1 : 0;
8588}
8589
8590
8591void sta_register_cmds(void)
8592{
8593 sigma_dut_reg_cmd("sta_get_ip_config", req_intf,
8594 cmd_sta_get_ip_config);
8595 sigma_dut_reg_cmd("sta_set_ip_config", req_intf,
8596 cmd_sta_set_ip_config);
8597 sigma_dut_reg_cmd("sta_get_info", req_intf, cmd_sta_get_info);
8598 sigma_dut_reg_cmd("sta_get_mac_address", req_intf,
8599 cmd_sta_get_mac_address);
8600 sigma_dut_reg_cmd("sta_is_connected", req_intf, cmd_sta_is_connected);
8601 sigma_dut_reg_cmd("sta_verify_ip_connection", req_intf,
8602 cmd_sta_verify_ip_connection);
8603 sigma_dut_reg_cmd("sta_get_bssid", req_intf, cmd_sta_get_bssid);
8604 sigma_dut_reg_cmd("sta_set_encryption", req_intf,
8605 cmd_sta_set_encryption);
8606 sigma_dut_reg_cmd("sta_set_psk", req_intf, cmd_sta_set_psk);
8607 sigma_dut_reg_cmd("sta_set_eaptls", req_intf, cmd_sta_set_eaptls);
8608 sigma_dut_reg_cmd("sta_set_eapttls", req_intf, cmd_sta_set_eapttls);
8609 sigma_dut_reg_cmd("sta_set_eapsim", req_intf, cmd_sta_set_eapsim);
8610 sigma_dut_reg_cmd("sta_set_peap", req_intf, cmd_sta_set_peap);
8611 sigma_dut_reg_cmd("sta_set_eapfast", req_intf, cmd_sta_set_eapfast);
8612 sigma_dut_reg_cmd("sta_set_eapaka", req_intf, cmd_sta_set_eapaka);
8613 sigma_dut_reg_cmd("sta_set_eapakaprime", req_intf,
8614 cmd_sta_set_eapakaprime);
8615 sigma_dut_reg_cmd("sta_set_security", req_intf, cmd_sta_set_security);
8616 sigma_dut_reg_cmd("sta_set_uapsd", req_intf, cmd_sta_set_uapsd);
8617 /* TODO: sta_set_ibss */
8618 /* TODO: sta_set_mode */
8619 sigma_dut_reg_cmd("sta_set_wmm", req_intf, cmd_sta_set_wmm);
8620 sigma_dut_reg_cmd("sta_associate", req_intf, cmd_sta_associate);
8621 /* TODO: sta_up_load */
8622 sigma_dut_reg_cmd("sta_preset_testparameters", req_intf,
8623 cmd_sta_preset_testparameters);
8624 /* TODO: sta_set_system */
8625 sigma_dut_reg_cmd("sta_set_11n", req_intf, cmd_sta_set_11n);
8626 /* TODO: sta_set_rifs_test */
8627 sigma_dut_reg_cmd("sta_set_wireless", req_intf, cmd_sta_set_wireless);
8628 sigma_dut_reg_cmd("sta_send_addba", req_intf, cmd_sta_send_addba);
8629 /* TODO: sta_send_coexist_mgmt */
8630 sigma_dut_reg_cmd("sta_disconnect", req_intf, cmd_sta_disconnect);
8631 sigma_dut_reg_cmd("sta_reassoc", req_intf, cmd_sta_reassoc);
8632 sigma_dut_reg_cmd("sta_reassociate", req_intf, cmd_sta_reassoc);
8633 sigma_dut_reg_cmd("sta_reset_default", req_intf,
8634 cmd_sta_reset_default);
8635 sigma_dut_reg_cmd("sta_send_frame", req_intf, cmd_sta_send_frame);
8636 sigma_dut_reg_cmd("sta_set_macaddr", req_intf, cmd_sta_set_macaddr);
8637 sigma_dut_reg_cmd("sta_set_rfeature", req_intf, cmd_sta_set_rfeature);
8638 sigma_dut_reg_cmd("sta_set_radio", req_intf, cmd_sta_set_radio);
8639 sigma_dut_reg_cmd("sta_set_pwrsave", req_intf, cmd_sta_set_pwrsave);
8640 sigma_dut_reg_cmd("sta_bssid_pool", req_intf, cmd_sta_bssid_pool);
8641 sigma_dut_reg_cmd("sta_reset_parm", req_intf, cmd_sta_reset_parm);
8642 sigma_dut_reg_cmd("sta_get_key", req_intf, cmd_sta_get_key);
8643 sigma_dut_reg_cmd("sta_hs2_associate", req_intf,
8644 cmd_sta_hs2_associate);
8645 sigma_dut_reg_cmd("sta_add_credential", req_intf,
8646 cmd_sta_add_credential);
8647 sigma_dut_reg_cmd("sta_scan", req_intf, cmd_sta_scan);
8648 sigma_dut_reg_cmd("sta_set_systime", NULL, cmd_sta_set_systime);
8649 sigma_dut_reg_cmd("sta_osu", req_intf, cmd_sta_osu);
8650 sigma_dut_reg_cmd("sta_policy_update", req_intf, cmd_sta_policy_update);
8651 sigma_dut_reg_cmd("sta_er_config", NULL, cmd_sta_er_config);
8652 sigma_dut_reg_cmd("sta_wps_connect_pw_token", req_intf,
8653 cmd_sta_wps_connect_pw_token);
8654 sigma_dut_reg_cmd("sta_exec_action", req_intf, cmd_sta_exec_action);
8655 sigma_dut_reg_cmd("sta_get_events", req_intf, cmd_sta_get_events);
8656 sigma_dut_reg_cmd("sta_get_parameter", req_intf, cmd_sta_get_parameter);
8657}