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