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