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