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